fox-it / OpenSSH-Network-Parser

Project to decrypt and parse SSH traffic
60 stars 18 forks source link

Support for other cipher modes #1

Open c3c opened 3 years ago

c3c commented 3 years ago

Hi,

Cool project - I'm now trying to get this to work for other SSH clients but am running into some issues. The default of a popular Windows-based client is to use AES256-CTR (if the server supports it too).

I was able to recover the required key material (key/IV). Just like for GCM mode, there is a counter to keep track of. However, the library currently doesn't support the CTR counter (I think a similar issue exists e.g. for CBC mode). By generating a bunch of IVs close to the value from memory, I got the library to recognize the correct key/IV.

Now the next issue is that there's no CTREncryption class (the BasicEncryption class doesn't seem to work for it). Would it be possible to add CTR support?

PS: I had some trouble with the default setup.py of this repo. The version of libnids in the ubuntu repos seems incompatible with the one required by pynids.

Grts

jellever commented 3 years ago

Hi,

Cool!

Hmm.. Do you know how the IV is modified for the CTR cipher mode? For the GCM cipher mode I try to brute force the possible correct IV's, reference: https://github.com/fox-it/OpenSSH-Network-Parser/blob/main/openssh_network_parser/protocols/ssh/state.py#L423

Reading this (https://www.researchgate.net/publication/331990205_Decrypting_Live_SSH_Traffic_in_Virtual_Environments) I think the IV is also incremented for CTR for each outgoing frame?

Regarding adding support for CTR, the BasicEncryption class should work for AES256-CTR.. Most of the crypto code is from AsyncSSH https://github.com/ronf/asyncssh.

I know, the official pyids pypi package is broken, the package actually misses the binary libnids files in the package. This is why setup.py references the GitHub project (https://github.com/MITRECND/pynids/tarball/master#egg=pynids-0.6.2) to install pynids from, which does work.

Regards, J