conpot icon indicating copy to clipboard operation
conpot copied to clipboard

Replace pycrypto with cryptography

Open glaslos opened this issue 4 years ago • 10 comments

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

glaslos avatar Nov 04 '20 01:11 glaslos

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

AlvinKuruvilla avatar Nov 11 '20 14:11 AlvinKuruvilla

@AlvinKuruvilla the only use is here

glaslos avatar Nov 11 '20 14:11 glaslos

Thanks, I will take a look

AlvinKuruvilla avatar Nov 11 '20 14:11 AlvinKuruvilla

@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

AlvinKuruvilla avatar Nov 11 '20 16:11 AlvinKuruvilla

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

glaslos avatar Nov 13 '20 10:11 glaslos

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

NishantPuri99 avatar Jan 10 '21 18:01 NishantPuri99

Sure, go ahead.

glaslos avatar Jan 10 '21 23:01 glaslos

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

NishantPuri99 avatar Jan 11 '21 05:01 NishantPuri99

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?

CypherpunkSamurai avatar Dec 08 '21 18:12 CypherpunkSamurai

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

glaslos avatar Feb 20 '22 13:02 glaslos

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.

CelticLite avatar Mar 28 '23 22:03 CelticLite

Absolutely 😊

glaslos avatar Mar 29 '23 05:03 glaslos

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

CelticLite avatar Mar 29 '23 14:03 CelticLite

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

glaslos avatar Mar 29 '23 14:03 glaslos

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

CelticLite avatar Mar 29 '23 15:03 CelticLite

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

glaslos avatar Jul 24 '23 13:07 glaslos