mushorg / conpot

ICS/SCADA honeypot
GNU General Public License v2.0
1.21k stars 410 forks source link

Replace pycrypto with cryptography #523

Closed glaslos closed 1 year ago

glaslos commented 3 years ago

Pycrypto is deprecated and also lacks a wheel. Replace with https://cryptography.io/en/latest/hazmat/primitives/symmetric-encryption.html

AlvinKuruvilla commented 3 years ago

I want to take a stab at this do you think you could list the files that use pycrypto? Just so it be easier for me and any other people who want to assist

glaslos commented 3 years ago

@AlvinKuruvilla the only use is here

AlvinKuruvilla commented 3 years ago

Thanks, I will take a look

AlvinKuruvilla commented 3 years ago

@glaslos I'm having an issue with the decrypt() function in pycrypto and I wanted to see if you had any suggestions

So in the code currently this is how a new AES cipher is made: decrypter = AES.new(self.aeskey, AES.MODE_CBC, iv)

I believe I have matched that functionality with: backend = default_backend() cipher = Cipher(algorithms.AES(self.aeskey), modes.CBC(iv), backend=backend) Which returns a Cipher Object (which a least for the time being I am assuming is analogous to AESCipher

My problem lies with this code snippet where it is calling decrypt() on the AESCipher object decrypted = decrypter.decrypt( struct.pack("%dB" % len(payload[16:]), *payload[16:]) ) I have been searching around and I'm unable to find an implementation of this decrypt function in the Github repo. The decrypt function as called here returns bytes

When using the cryptography module's decryptor function, however, it returns a CipherContext object but the subsequent lines expect bytes. Do you think it is as simple as casting the entire function call to bytes and adding in the same pass parameter that the pycrypto decrypt() function is taking in now?

Something like this?

decryptor = bytes(cipher.decryptor( struct.pack("%dB" % len(payload[16:]), *payload[16:]) ))

Sorry for the long-winded explanation, I was just trying to be thorough

glaslos commented 3 years ago

@AlvinKuruvilla did you try the example? https://cryptography.io/en/latest/hazmat/primitives/symmetric-encryption.html#cryptography.hazmat.primitives.ciphers.Cipher

NishantPuri99 commented 3 years ago

I have a fair knowledge of Python, may I try this one out?

glaslos commented 3 years ago

Sure, go ahead.

NishantPuri99 commented 3 years ago

Thanks @glaslos I'll get working with this in a few days

CypherpunkSamurai commented 2 years ago

Hello, I wanted to help contribute to this project and I happen to look upon this issue.

Pycrypto is deprecated and also lacks a wheel. Replace with https://cryptography.io/en/latest/hazmat/primitives/symmetric-encryption.html

I will try replacing pycrypto with cryptography, also can we use (should I try using) pycryptodome instead as a second option?

glaslos commented 2 years ago

@CypherpunkSamurai have you had a chance to give this a try?

CelticLite commented 1 year ago

Hey @glaslos, it looks like this issue has not been handled. Any chance I could open a PR with the fix? I have the code changes complete locally.

glaslos commented 1 year ago

Absolutely 😊

CelticLite commented 1 year ago

It looks like I do not have permissions to push a new branch to the repo: remote: Permission to mushorg/conpot.git denied to CelticLite. I followed the guide here: https://conpot.readthedocs.io/en/latest/development/guidelines.html

glaslos commented 1 year ago

Yes, you need to make a fork and then create the PR from your for to this repo. No worries, GitHub will guide you :)

CelticLite commented 1 year ago

PR is up and ready for review: https://github.com/mushorg/conpot/pull/582

glaslos commented 1 year ago

Closed with https://github.com/mushorg/conpot/pull/582 Thank you for your contribution!