radareorg / radare2

UNIX-like reverse engineering framework and command-line toolset
https://www.radare.org/
GNU Lesser General Public License v3.0
20.6k stars 3k forks source link

More algorithm for rahash2 -E and a dedicated r2 command #4254

Closed Maijin closed 7 years ago

Maijin commented 8 years ago

Hey, I think could be cool to add more useful crypto within r2 especially for malware analysis, here are some common one that can be found in pycrypto. See https://github.com/radare/radare2/commit/3f5aa46bd5177f18a6e784c45e0ec3da9c1eb266 to know where/how to implement them

It needs to be able to do that on file as well and Also a command to do that within r2 could be neat

More related stuff here to do ! https://github.com/radare/radare2/issues/4280

radare commented 8 years ago

Which command do u like for doing this from r2? Maybe like wo?

On 07 Mar 2016, at 14:16, Maijin notifications@github.com wrote:

Hey, I think could be cool to add more useful crypto within r2 especially for malware analysis, here are some common one that can be found in pycrypto. See 3f5aa46 to know where/how to implement them

ARC2 ARC4 #4229 Blowfish XOR (with a string and not with just a byte like in rax2) CAST DES DES3 PKCS1_OAEP PKCS1_v1_5 Also a command to do that within r2 could be neat

Command for crypto — Reply to this email directly or view it on GitHub.

radare commented 8 years ago

Can you find small and simple c implementations for all those algorithms?

On 07 Mar 2016, at 14:16, Maijin notifications@github.com wrote:

Hey, I think could be cool to add more useful crypto within r2 especially for malware analysis, here are some common one that can be found in pycrypto. See 3f5aa46 to know where/how to implement them

ARC2 ARC4 #4229 Blowfish XOR (with a string and not with just a byte like in rax2) CAST DES DES3 PKCS1_OAEP PKCS1_v1_5 Also a command to do that within r2 could be neat

Command for crypto — Reply to this email directly or view it on GitHub.

Maijin commented 8 years ago

Yeah wo family command would be ok Here is the pycrypto repo with C code https://github.com/dlitz/pycrypto/tree/master/src

lionaneesh commented 8 years ago

I'll work on implementing RC2.

PankajKataria commented 8 years ago

I am working on XOR

oddcoder commented 8 years ago

cool guys :+1

kishorbhat commented 8 years ago

This sounds fun! I'd like to work on Blowfish.

Note: as per issues filed there, the pycrypto library is no longer actively maintained (see this). Apparently development and other projects have moved to pycryptodome, which has everything pycrypto has and more.

PankajKataria commented 8 years ago

for XOR encryption what can we do if the input contains null bytes. The rahash2.c will not pass the full string to the encryption plugin like for example : "rahash2 -S key -E XOR -s hello' world\n' " will give correct output but "rahash2 -S key -E XOR -s hello' world\n' | rahash2 -S key -E XOR -s - " will give 'h' as output as because in the output of the encryption there will be a null byte (ie e(xor)e )

radare commented 8 years ago

I would prefer the lowercase name here: xor

On 07 Mar 2016, at 22:08, Pankaj Kataria notifications@github.com wrote:

for XOR encryption what can we do if the input contains null bytes. The rahash2.c will not pass the full string to the encryption plugin like for example : "rahash2 -S key -E XOR -s hello' world\n' " will give correct output but "rahash2 -S key -E XOR -s hello' world\n' | rahash2 -S key -E XOR -s - will give 'h' as output as because in the output of the encryption there will be a null byte (ie e(xor)e )

— Reply to this email directly or view it on GitHub.

chinmaydd commented 8 years ago

I plan to work on implementing DES.

Maijin commented 8 years ago

I have added in the issue:

Ability for rahash2 -E to handle file like rahash2 -S key -E rc4 file.exe for example

condret commented 8 years ago

we allready have DES, but it is broken

Maijin commented 8 years ago

Here https://github.com/radare/radare2/blob/master/libr/util/des.c

PankajKataria commented 8 years ago

Should we consider the case of only one file provided, If not then please suggest suitable format to separate the output. Currently, I am printing newlines after every encrypted file.

Maijin commented 8 years ago

@PankajKataria What u mean? Like decrypting/encrypting several file like rahash2 -S key -E rc4 file.exe file2.exe and so on?

PankajKataria commented 8 years ago

@Maijin Yup

Maijin commented 8 years ago

AES is not done/not working in fact feel free to do add support for that as well :)

l4l commented 8 years ago

I'm going to fix aes algo

radare commented 8 years ago

Cool!

Maybe @condret can point you to the issues he was having and the eay to integrated in esil. But for now just focus on implementing it for rahash2

Thanks

On 18 Mar 2016, at 22:47, Evgeny notifications@github.com wrote:

I'm going to fix aes algo

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub

l4l commented 8 years ago

I've done with most of the work for implementation here but there is still critical bug(s) that I still cannot find. So I really will be glad to receive any help with it

radare commented 8 years ago

can you describe the bug? :P

On 22 Mar 2016, at 19:50, Evgeny notifications@github.com wrote:

I've done most of the work for implementation here https://github.com/l4l/radare2/commit/e27f953e6920a9cba12e6f929a6429d071e702fd but there is still critical bug(s) that I still cannot find. So I really will be glad to receive any help with it

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/radare/radare2/issues/4254#issuecomment-199959835

l4l commented 8 years ago

Some buffer overflow. Logs: gdb, asan Command like `rahash2 -E aes-ecb -S 32*'1' -s 256*'A'

radare commented 8 years ago

use valgrind, this is a clear buffer overflow at radare2/libr/crypto/crypto.c:120

On 22 Mar 2016, at 20:35, Evgeny notifications@github.com wrote:

Some wierd buffer overflow. Logs: gdb http://pastebin.com/sHj9YBKC, asan http://pastebin.com/7gifQDc6 — You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/radare/radare2/issues/4254#issuecomment-199979516

ninjahacker commented 8 years ago

Modes should be written separately from the cipher algorithms so they can be reused easily. CBC is CBC is CBC. It doesn't matter whether it is AES-CBC or Blowfish-CBC. This way as new things get added, you automatically have all the modes for it. It's also just bad to write the same code 100x. You should be able to do something like (obviously with better naming and thinking of the arguments):

do_cbc_encrypt(aes, iv, input, output, length) do_cbc_decrypt(blowfish, iv, input, output, length)

etc...

Maijin commented 8 years ago

Feel free to change the stuff :P But having all of those basics would be already cool prior doing fancy stuff...

ninjahacker commented 8 years ago

I haven't looked at the code to see how it was structured yet, but I just wanted to make a note of it since I see CBC listed. It's going to be harder to change later if you don't plan ahead for it. Especially if people start wanting ofb, cfb, xts, and whatever popular thing will spring up next month. And malware authors like to be all trendy and use the fancy new modes, right?

Maijin commented 8 years ago

RAT still used rot13, arc4, xor, aes-cbc a lot so definitely not fancy.

ninjahacker commented 8 years ago

I was trying to be funny... :(

Maijin commented 8 years ago

:?

radare commented 8 years ago

ping

wargio commented 7 years ago

there is no 3DES yet.

Maijin commented 7 years ago

See hxxps://github.com/radare/radare2/issues/6946