After finally solving B007l3G CRYP70, we are again presented with another variant. The description reads as follows:-
Plain text
1
2
3
4
5
As you continue your pentest of MEGACORP, you make your way to an
admin-only subnet of the network. There, you find yet another custom
crypto implementation. You also previously found this zip file on a
user's desktop. Solving this may be the last step to gaining full
access to the company's network
Lets first begin with by checking some stuff like we did in B007l3G CRYP70 with the encryption service
Plain text
1
2
3
4
5
6
7
Please enter the secret key to encrypt the data with: a
Please enter the data that you would like to encrypt: a
Your encrypted message is: w4I=
Please enter the secret key to encrypt the data with: b
Please enter the data that you would like to encrypt: a
Your encrypted message is: w4M=
Notice the encrypted message appears to be base64 encoded.
Lets check the decoded values
Hehe, we start getting a hint already, changing the key by 1, encryption changes by 1. There is probably something Very Linear about the encryption.
To help with encryption process, I created a small helper function encryptwhich calls encrypt on the server and return the ord values of base64 decoded string.
frompwnimportremotefrombase64importb64decodeasd64frombase64importb64encodease64HOST,PORT="95.216.233.106",60246withopen('password.txt','r')aspassword_file:password=d64(password_file.read().strip()).decode()withopen('ciphertext.txt','r')asciphertext_file:ct=d64(ciphertext_file.read().strip()).decode()withopen('plaintext.txt','r')asplaintext_file:pt=plaintext_file.read().strip()REM=remote(HOST,PORT)print(REM.recvline())print(REM.recvline())defencrypt(pt,key):REM.recvuntil(b'data with:')REM.sendline(key)REM.sendline(pt)data=REM.recvuntil(b'\n\n')encrypted=data.split(b'message is: ')[-1].strip()return[ord(i)foriind64(encrypted).decode()]
key is repeated if plaintext is longer than the key
The encryption is changed only by 1 on varying either key or plaintext by 1
The key, plaintext and ciphertext are related just by an addition modulo 256
So, all we need to do now is to figure out what the provided files mean.
Let us try checking the key with which ciphertext.txt and plaintext.txt are related.