Re:How We Decoded Some Nasty Multi-Level Encoded Malware
by JonnieCache on Tuesday December 10, 2013 @05:23AM
(#6879922)
This is roughly what I was imagining doing in my head when I brashly wrote "obviously bruteforce." Hooray! Apparently I've still got it, at least to some small extent.
Thanks for your writeup!
Why does define work so well? Chance?
Re:How We Decoded Some Nasty Multi-Level Encoded Malware
by alexkus on Tuesday December 10, 2013 @05:38AM
(#6879951)
Not sure, "define" only appears 10 times but "function" appears 19 times. It's probably because 'e' is more popular in the code and "define" has two of them. Looking at the decrypted code there are much better strings to try; "function_exists" gives the right key first time too.
It could have been made a lot harder by using comments at the end of each line to pad the code with extra characters to equal out the frequency distribution and make this kind of frequency analysis impossible.
Re:How We Decoded Some Nasty Multi-Level Encoded Malware
by JonnieCache on Tuesday December 10, 2013 @06:00AM
(#6880021)
Could I make it even worse using ruby's unicode support?
eg this kind of nonsense:
π = Math::PI
alias λ proc
● = λ {|r| π*r**2}
puts ●.call 5
# 78.53981633974483
Re:How We Decoded Some Nasty Multi-Level Encoded Malware
by alexkus on Tuesday December 10, 2013 @06:35AM
(#6880119)
Oh yes, although too many "alias" commands will mean that it's possible to search for the known plaintext of 'alias'. But the more non-ascii bytes there are the more it will put off my analysis which dependeds on isprint().
(It's better if you give it a longer string, if I give it "function " with the trailing space then it gets 9/12 as the most popular, 2/12 as second most popular and the remaining one as the third most popular. There are even better choices, see below, but I chose to go with this as it helps show how to continue with non-perfect information).
Next I knocked up a quick program to allow me to try different keys to decrypt it, it prints out the code in blocks of the appropriate keylength so it's easy to see if a specific character position is correct or not. The program takes various commands from stdin (k = print key, S = set key, s = set individual key character, p = print in keylength sized blocks, P = print entire decrypted block):-
Getting there, but still a way off. There are a few strings like COIKOE[#n]= which could be COOKIE, so we fiddle with the 3rd column and see some interesting things in the output:- Neither of the other two choices for column 4 produce the right string, but it's simple enough to find the ciphertext and find what is needed to make elseof -> elseif, COOKOE -> COOKIE and systcm -> system. It's k:- We carry on doing this based on more clues like this (it gets easier and easier!) and we end up with:- And printing out the entire decrypted buffer without extra linebreaks every 12 chars gives:- Interestingly, trying known plaintext of "define" gives us the entire key as the most probably choice first time:-