Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: encrypt() cannot be called after decrypt() #5

Open
AgeOfMarcus opened this issue Aug 5, 2018 · 4 comments
Open

TypeError: encrypt() cannot be called after decrypt() #5

AgeOfMarcus opened this issue Aug 5, 2018 · 4 comments

Comments

@AgeOfMarcus
Copy link

When running the server, and trying to connect with the client to localhost, I get the following result when a command is sent/received:

Traceback (most recent call last): File "./reverse_dns_shell_client.py", line 168, in <module> main() File "./reverse_dns_shell_client.py", line 164, in main start(opts.host) File "./reverse_dns_shell_client.py", line 133, in start stdoutput = runCmd(cmd) File "./reverse_dns_shell_client.py", line 105, in runCmd output = processOutput(stdoutput) File "./reverse_dns_shell_client.py", line 76, in processOutput eStdoutput = encrypt(stdoutput) File "./reverse_dns_shell_client.py", line 34, in encrypt encoded = EncodeAES(cipher, string) File "./reverse_dns_shell_client.py", line 27, in <lambda> EncodeAES = lambda c, s: base64.b64encode(c.encrypt(pad(s))) File "/usr/local/lib/python2.7/dist-packages/Crypto/Cipher/_mode_cbc.py", line 157, in encrypt raise TypeError("encrypt() cannot be called after decrypt()") TypeError: encrypt() cannot be called after decrypt()

@isGt93
Copy link

isGt93 commented May 20, 2022

I had the same problem, how did you solve it?

@elefr3n
Copy link

elefr3n commented Sep 9, 2022

I had the same problem, how did you solve it?

Apparently how the script uses the crypto object is not compatible with pycryptodome, I SOLVED IT editing the client and server encrypt() and decrypt() functions with "return string", namely without encrypt/decrypt the values. I know is not the best way because now communication is in text plain, but it's working.

@ahhh
Copy link
Owner

ahhh commented Apr 25, 2023

Hmmm late to the party but we should probably update the crypto libs if the basic encrypt / decrypt isn't working... For the record this was a POC I don't use this in production or on pentests, so if someone wants to take the lead on updating it I'm all for it

@Malshift
Copy link

Malshift commented Jul 17, 2023

Move the cipher object into the decrypt and encrypt functions. ✌️

# encrypt with AES, encode with base64
EncodeAES = lambda c, s: base64.b64encode(c.encrypt(pad(s)))
DecodeAES = lambda c, e: c.decrypt(base64.b64decode(e)).rstrip(PADDING)

def encrypt(string):
  cipher = AES.new(secret, AES.MODE_CBC, iv)
  encoded = EncodeAES(cipher, string)
  return encoded

def decrypt(string):
  cipher = AES.new(secret, AES.MODE_CBC, iv)
  decoded = DecodeAES(cipher, string)
  return decoded

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants