Skip to content

Commit

Permalink
removed usage of pycrypto and using cryptography instead (#582)
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticLite authored Jul 24, 2023
1 parent f0e6925 commit 26c67d1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
16 changes: 7 additions & 9 deletions conpot/protocols/ipmi/fakesession.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import random
import hmac
import hashlib
from Crypto.Cipher import AES
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -122,10 +122,9 @@ def _ipmi20(self, rawdata):
payload = data[16 : 16 + psize]
if encryption_bit:
iv = rawdata[16:32]
decrypter = AES.new(self.aeskey, AES.MODE_CBC, iv)
decrypted = decrypter.decrypt(
struct.pack("%dB" % len(payload[16:]), *payload[16:])
)
cipher = Cipher(algorithms.AES(self.aeskey), modes.CBC(iv))
decryptor = cipher.decryptor()
decrypted = decryptor.update(struct.pack("%dB" % len(payload[16:]), *payload[16:])) + decryptor.finalize()
payload = struct.unpack("%dB" % len(decrypted), decrypted)
padsize = payload[-1] + 1
payload = list(payload[:-padsize])
Expand Down Expand Up @@ -315,10 +314,9 @@ def send_payload(
iv = os.urandom(16)
message += list(struct.unpack("16B", iv))
payloadtocrypt = self._aespad(payload)
crypter = AES.new(self.aeskey, AES.MODE_CBC, iv)
crypted = crypter.encrypt(
struct.pack("%dB" % len(payloadtocrypt), *payloadtocrypt)
)
cipher = Cipher(algorithms.AES(self.aeskey), modes.CBC(iv))
encryptor = cipher.encryptor()
crypted = encryptor.update(struct.pack("%dB" % len(payloadtocrypt), *payloadtocrypt)) + encryptor.finalize()
crypted = list(struct.unpack("%dB" % len(crypted), crypted))
message += crypted
else:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ tftpy
# some freezegun versions broken
freezegun!=0.3.13
pytest
pycrypto
cryptography
sphinx_rtd_theme
psutil

0 comments on commit 26c67d1

Please sign in to comment.