Thursday, January 29. 2009Decoding Waledac's RegistryOk, just a quick blog on this... If you've looked at the registry keys created by Waledac you've surely seen the RList key. This key contains a rather large blob of data. Turns out that this is where the bootstrap IP list is stored in order to keep it current over reboots. The data contained within this block of data is obviously not plaintext. Turns out the data is encrypted using our favorite crypto algo: AES. The transform for this data is very, very simple. Simply applying AES to the data puts the data back into plaintext of a BZip2 file, then un-BZip2 to get the data out. The un-BZip'd plaintext is the same format as the .php data received by the node during an update. Waledac LOVES XML. Once decoded, the XML looks like this: <lm> The above data came directly from one of my node's registry after being decoded. The AES key can be one of two hardcoded values contained within the binary making this data easy to recover. greg. Wednesday, January 28. 2009Talking with WaledacI figured since others were sharing more, I'd share more too Over the weekend I was able to breakdown all of the packets used by Waledac for communication. The communication between nodes is rather simplistic, but potentially expandable. I'm not going to put a lot of pretty text around my notes, just my notes. Please do enjoy. If you have questions, drop me a line. greg. XML Format for versions 28+ (maybe earlier, but havent checked) All Request Packets have the following standard header added at the start <lm> Reply Packets have the following standard headers added at the start
0 : "getkey" Command Number: 00 (aliased on the wire as 0xFF) Request Format: {standard request header} Command Number: 01 Request Format: {standard header} NOTE: The reply is basically ignored. Command Number: 02 Request Format: {standard request header} NOTE: "n="command"" format: <dns_zone> and <dns_host> are handled by the CDnsPlugin. Known "label" values: "lynx" (version 31) and "mirabella_site" (version 28) Command Number: 03 Request Format: {standard request header}
Command Number: 04 Request Format: {standard request header} NOTE: Command Number: 05 Request Format: {standard request header} NOTE: Command Number: 06 Request Format: {standard request header} NOTE: Command Number: 07 Request Format: {standard request header} Note: The reply is basically ignored. Node Update Packets: Request Format: none. Simple empty GET request to a .php script (i.e. /index.php) or...
"X-Request-Kind-Code: servers" <---- for repeaters or the header: "X-Request-Kind-Code: nodes" <---- for spammers followed by the bot's node list converted to XML (see example in Reply Format section), BZip2'd and compressed with AES (using Key 1 or Key 2. default is key 1). Reply Format: <lm> NOTE: This type of reply do not contain the normal 5 byte header like the command packets have. Additionally, this data is NOT BZip'd after being decoded if the reply was to /index.php, but it is BZip'd if a request to /. Saturday, January 24. 2009Waledac's Communcation Protocol
Around Xmas of this past year (2008) the Waledac trojan really sprang to focus. Many researchers, myself included, have likened the trojan to the now dark Storm bot. Waledac shares many similarities to Storm in the way communications are handled, spam is sent, etc. The details of this are well publicized so google will show you the way. What many researchers did not know was the way the data was traveling across the network. The basic format of a Waledac data exchange looks like this: POST /llveaamncz.png HTTP/1.0
Referer: Mozilla Accept: */* Content-Type: application/x-www-form-urlencoded User-Agent: Mozilla Host: xz.y.x.x Content-Length: 317 Pragma: no-cache a=AgAAANNpvPXwbiby6EtaZNszVV6nuKqqhcVLqnhso4DolBU-GjkaaU1r1HA2X1EHMUqfSaFpB-YGWYHxB8Q82WQagJzJWgoDEezx4-vc_pnCMUb75jr4kb4jsqWYWSX9xT_Di3w5LDS4f9-fzzEJF85OiNvBWPQCl3CbZRIxaFr73pRCfnvZrUSwissNv3HbfrvwHd0KkvBnHv40yQ4ZlGwPQDWSATlBFlTNBbI4fqSDV5wKfzirb_kXRW3Yn4Q-ZtDDFzTcj6g6Xq-TK6oeMj8WtpRCfrfdloDX9sJ9gHsksoArXA&b=AAAAAA HTTP/1.1 200 OK Server: nginx/0.6.34 Date: Mon, 19 Jan 2009 22:11:48 GMT Content-Type: text/html Connection: close X-Powered-By: PHP/5.2.8 AgAAAUoKNmr3RcU00DZic-18qqACaDxVXTahwKgk42DBL3fpMxLsud5GfRxwMtczeWltVkYqT8etqa_OssVU16MrXBfV9Gk2EPbKI2bua3aqll25EursbNT61Zgc-Tqzgn8E3wwgQFVi_tFb-VKHU4QDTwZytQl_vmKnwlLfI2V4ACtpwButN7b42QSekMO2YYEpF3l0NWUi4KEuOOpExrE8VPCE9TBTKtfqxwPa447hMaLkRhQcwBNyP575YBlxozfXjOlRDAMPuLOckdBjHxRB7MeyB71dgmIKyTmUT4Em4oMxBduw7_XT2tGVL00QcES91QsRSA1IAuCPWoGPXEcXOlz9RFHqpTtl5Hkn8gjlTIOs2Da26LPEjxg_cxCvhvmfRQ_viUsCblqRHp4ccwNY3heb98lW321pb-6P7jAKuPn2hHGKZgtWcqrDUEyUh34c92M The first reply comes from a spammer node (a bot that is behind a firewall). The familiar a= &b= tags look very much like Storm. And like Storm, the data is Base64 encoded.... well, sorta. Turns out to make Base64 decoding annoying, the author(s) of Waledac made some simple substitutions, but very minor ones. To un-Base64 the data, the _ character must be replaced with / and the - character must be replaced with +. Also, the data is not exactly in Base64 block size. Therefore if the data being encoded ends with =, the = is stripped. Making the replacements and padding the string size with = will allow the string in a= to be Base64 decoded. Once decoded, the data takes the following form: The command type identifies what type of request or reply is being made and as a result, which key is used to decompress the AES encrypted payload. The DWORD size field identifies how big the decrypted payload will be. To decrypt the AES payload there are really only two keys which matters. For type 0xFF one key is used (which can be found in the binary). For the other commands a key handed down by the botmaster is used. The reason 0xFF uses a hardcoded key is that this command is known as “getkey” and the purpose of this command is to pass up to the botmaster the node’s public key/certificate. The botmaster will then encrypt the AES key to use for the other command types using that public key. It is then up to the bot to use the private key to decrypt the key. This, in theory, prevents researchers from being able to spy on or spoof command types 1-7. This can be defeated given a particular flaw I found in the system. Before anyone asks, no, I will not yet give out the way to recover the dynamic AES key. I still need this for my research and I don’t want people polluting the data. Do you not remember what happened when researchers started looking at storm? Once the AES payload has been decrypted, the data is still not yet accessible for plaintext. It turns out that the author(s) of Waledac wanted to save a little bandwidth and BZip2 compressed the payload. The solution to this, as you might imagine, is to simply un-BZip2 the data. Once you have decompressed the data, you will find that the payload is a XML data structure. Therefore, Waledac uses XML for command and control communication. This makes understanding what is happening in a particular decoded packet trivial. And for that I thank them. To get an idea of what this XML looks like, the request sent from the node above decodes into the following text: (note that I added the newlines and tabs. The XML sent is a single string) <v>31</v> <i>234 {omitted the rest of this} 9</i> <r>0</r> <props> <p n="label">lynx</p> <p n="time_init">Tue Jan 20 01:40:51 2009</p> <p n="time_now">Tue Jan 20 01:41:45 2009</p> <p n="time_sys">Tue Jan 20 01:41:45 2009</p> <p n="time_ticks">2338031</p> </props> </lm> As you can see from the output, it is pretty straightforward. <t> represents the name of the command, <v> is the version of the bot making the request (or botmaster if it is a reply), <i> is the hash ID of the node, <r> is 1 if the bot is a repeater (e.g. “proxy”, unfirewalled) or 0 if it is a spammer (firewalled). The <props> section is where attributes unique to each command are stored. The format is always <p n=”…”>…</p>. I will post the meaning of these at a later date. The XML always starts with the <lm> tag.
UPDATE [20090128]: Felix Leder and Tillmann Werner pointed out something I had not thought of. While the base64 modifications are annoying, they may very well serve a more valuable (to the bot developers) purpose. It turns out / and + are reserved characters in the world of URL strings when using application/x-www-form-urlencoded and therefore they must be changed or escaped. Given that Waledac does a lot of URL parameter passing in Base64, adjusting these reserved characters would allow for less problems. This may very well be why the changes are made and are not a direct result of trying to annoy researchers. Thanks for pointing this out guys! <lm><t>notify</t> Saturday, November 22. 2008I hate the iPhone... but I hate Apple moreI'll admit it, I was one of those people standing outside the Apple store whenever the new iPhone 3-oh-my-god-why-won't-this-piece-of-shit-work-G came out. I was happy to have a shiny new iPhone in my hands. I immediately took it home and selected every single icon I could find. I played with it for a few days and then i tried to make a phone call. Since that fateful day, i've had nothing but a horrible, horrible experience with the iphone. god forbid i want to make a phone call and if i'm lucky enough to get the call to actually go through, i better say my piece quickly because i'm going to get my call dropped. I live downtown in a city that has a LOT of AT&T coverage. I get 4 out of 5 bars at any given time and more often than not I get 5 out of 5. But i can't get this damn thing to keep my call running for any length of time. When the miracle of the 2.1 OS came out, I immediately upgraded because i was told this would fix the phone issue. It didnt. What it did do was keep me from getting my emails for 2 months until the software decided that it was finally ok to start receiving emails again. I called Apple's tech support many, many times and was told to do the same things over and over and over and over... and over. My mother told me once that the definition of insanity is repeating the same actions over and over and expecting a new outcome each time. Therefore, Apple is insane. So the 2.2 OS came out and again, I'm being told that this will fix the evil phone problem, that my phone calls will last longer than 5 minutes and that when i hit the send button my phone will not immediately say "call failed." I've upgraded. And now I can't get on the internet via my iphone. I can't checked my email, I can't get the www.apple.com website, I can't even check the fucking weather! Apple's solution... reinstall your firmware. WHAT? That is the same answer they gave me after the email issues with the 2.1 upgrade. At least this time they aren't telling me call Microsoft because my email comes from an exchange server. I hate Apple. They are a pretenious as hell and I hate how smug they are about their miracle products. Their products are ok at best. Sure, the Mac OS doesn't have the same stability issues as Windows 98. Neither does XP. I am by no means a fan of Vista, so don't think I'm smoking from the Microsoft bong. Apple makes some pretty little products, but they have performed an Epic Fail with their iPhone. Thanks to a 2 year contract, they have the majority of their subscribers by the short and curlies. Luckily, I make enough money (even in today's economy) that once I find a better device I will happily tell Apple and AT&T to go fuck themselves. Unlike the iPhone, I'm going to do my research before i jump to my next phone. Thursday, May 1. 2008Kraken WireShark PluginFor those of you who saw Michael Ligh's blog entry on the Kraken work he and I did, you are probably wondering where the plugin code is. I have released the wireshark plugin here in my Code section of the site. I should warn you about the plugin... I'm not a plugin writer. This is literally my second attempt at it. It may very well crash your WireShark under some situations. Just keep that in mind. If your version of wireshark is 0.99.8, you should be fine. If you are running 1.0.0, you should be fine too (however, the Protocol tab will say UDP instead of Kraken.. i'm not sure why that is). Feel free to use this as you see fit. However, if you use any of the code, make sure you reference BOTH this website [nnl-labs.com] and Michael Ligh's [mnin.org] website! enjoy. greg. Wednesday, March 12. 2008When addressing goes horribly, horribly wrong...From time to time you come across that special kind of IDA database where the things you take for granted are simply not how they should be. I was recently working on a binary that started out something like this... call $+5pop ebxadd ebx, 014350hThen later on in the function all the variable references take the form of mov eax, [ebx-01212h]As you might have guessed IDA doesn't particularly care much for this. My xfer tables are nearly bare. Obviously one could go about manually calculating the location of all these variables, but I'm lazy.. ok, not really lazy, perhaps unmotivated. So I wrote a quick and dirty IDC script to calculate these offset locations and store the results in a comment beside the operand. The script is extremely simple in that very little error checking is done. The basic logic of the script is to identify the first call $+5, the pop <reg>, and add <reg>, <offset> signature in the function. From this, the script can identify which register is being used for the offset and then find each line of code that uses this register in a [<reg>+<displacement] configuration. For each line found, a comment is created that will contain either the address that is being referenced or if a name exists for that address, the label of the address. It wouldn't take much effort to modify this function to run through all functions in a binary and perform this same operation for each of those functions. But for now, this suits my needs. greg. Sunday, March 9. 2008Helpful CHICKEN IDC ScriptsOn my code page are two new IDC scripts that will be helpful to anyone trying to groom a CHICKEN idb. The first script will take the heavy lifting off a reverse engineer when constructing variable names to associate with the symbol strings. The script will not be able to handle situations where the symbol system starts with a non-printable character (for symbols with the "##...#" labeling), but it will indicate where these manual touch up points are. When dealing with several hundred symbols, this script will save a reverse engineer hours. The second script will setup the basic structures and enums used with CHICKEN applications. While not exactly necessary when grooming a CHICKEN database, these items are extremely helpful. greg. Saturday, March 8. 2008Why Did CHICKEN Cross the... oh nevermind
Remember back in your college AI class when the professor made you use Lisp to program your AI experiments? Or maybe you were in a programming language class and you had to use Lisp. Remember the pain and suffering imposed by the use of ( and )))))))))))))))))))? I do.. and as such I've always had a particular dislike for Lisp and any other languages like Lisp... namely, Scheme.
I was working on a project recently that required me to reverse engineer a particular binary responsible for handling a key piece of data manipulation for the system under review. So I loaded the binary up in IDA and gdb and off I went to see what was under the hood. No sooner than I traced the one and only call from the main(...) did it occur to me that something was very, very wrong. Of the nearly 1000 functions in the binary, about 99.5% of them ended in either or call eax+4 and then the function would end. That's it, just end. Not a retn in sight. So obviously this was frustrating. Moreover, the eax in question was the result of some obscure function call that passed a variable that never seemed to be assigned a value. So how the hell was I supposed to trace this program? Or more importantly, how the hell did it even execute? As a reverse engineer with years of x86 experience, there are certain things I expect to see in a function.. a stack, a jmp, a call to a defined function, a function that returns. You know, the basics. So what was going on with this program? Digging around a bit more I found that this program called a library named chicken. Seriously, it calls a library called chicken. Digging around the web lead me to the source of this mysterious library... www.call-with-current-continuation.org. As it turns out the binary I was reversing wasn't originally written in C or assembly or even Fortran for that matter.. it was written in Scheme (a dialect of Lisp). My blood immediately turned cold. My hard feelings toward the language of the ( and )))) had come back to haunt me. So not only did I feel that the language was evil in its original form, but this compiled version did nothing more than to strengthen my dislike of it. Well, I had to reverse this part of the system.. I had no choice in that matter. How the hell was I going to do this? The program was used as a CGI script so I could execute it through the web and watch how it interacted. That was an option, but I'm old school in that I love doing static analysis. I love it! Give me a binary, ask me how it works down to the level of how the structures are defined and leave me alone for a while, and I'll come back to you with a report on the insane details of the program. Its what I do, it's what I enjoy. But static analysis was out of the question it looked like, so with gdb fired up and ready to go, I ran the program single stepping all the way. This painful process only deepened my hatred of Scheme and this bastardized compiled version of it. I quickly realized that single stepping through this program would be a waste of my time and the few remaining threads of sanity I had were quickly being eroded by this program. Time for a different technique.... A few weeks passed and a lot of research was done. I read the website for CHICKEN, I read the wiki on CHICKEN. I learned a lot, I forgot even more. I found a paper on the wiki that described the process by which Scheme is changed to C by CHICKEN and then compiled. You heard me, CHICKEN takes Scheme code, converts it to C and then compiles it (typically with gcc). In this paper they gave two examples of how the conversion works, neither of them were easy to follow for someone who didn't understand Scheme (which, I will admit, I still don't). But the paper did give me enough insight into what is happened to start making some educated guesses. As it turns out, CHICKEN converts Scheme into C by changing the way the program is executed. Instead of a standard stack being used to hold local variables for a function and return addresses for functions to, well, return to, CHICKEN converts the Scheme code into "continuous passing style" ... in a nutshell this means that each function simply calls the next function and passes along a data block for local variables the function will use and a data block to be used (at some point in the future) to call after that. There is a lot more to it, trust me.. but that'll give you an idea. This was great... I was looking at a program that malware authors would send back saying "um, yeah, even we don't make programs that hard to follow." And the web, the web was useless when it came to trying to find resources for reverse engineering CHICKEN applications. But never fear... long story (and this was a long story) short, I come to you with a paper on how to reverse engineer CHICKEN applications.. ta-da (this is where the trumpets would start sounding). After a few long weeks of reversing, researching and experimenting, I have finally figured out how to read CHICKEN applications. I can't convert them back to Scheme (and really, why would anyone want to?) but I can now give you the information you need to reverse these horrible little programs yourself. I hope my suffering can help you in the future. As a friend of mine said when I told him I was writing a paper on this topic once told me "I'm sure the other 3 guys on the Internet trying to reverse CHICKEN will thank you." greg. The paper to date: Reverse Engineering CHICKEN with IDA Friday, February 29. 2008Everybody has one... so why shouldn't I?
This is the start of the NNL-lab website/blog. ... more a website tho. I have nothing else to say... but I'm working on it.
(Page 1 of 1, totaling 9 entries)
|
Calendar
QuicksearchBlog AdministrationOther Pages Here and ThereFeel free to explore other pages on this site .. or even other sites.
|
|||||||||||||||||||||||||||||||||||||||||||||||||