Книга: Practical Malware Analysis: The Hands-On Guide to Dissecting Malicious Software
Назад: Lab 16-1 Solutions
Дальше: Lab 16-3 Solutions

question hinted that strncmp is used. If we load the program into IDA Pro, we see strncmp in the main function at 0x40123A. Let’s load the program into OllyDbg and set a breakpoint at 0x40123A.

After we load Lab16-02.exe into OllyDbg, it immediately terminates without pausing the program. We suspect something is amiss, so we check the PE file structure. shows the PE header section names in PEview.

.

Double-click the TLS callback function at 0x401060 to navigate directly to the function and see if there is any anti-debugging functionality. shows the TLS callback code.

displays the options for the PhantOm plug-in.) If you’re using the PhantOm plug-in, check the Load Driver and Hide OllyDbg Windows boxes to protect against this technique.

Now load the program into OllyDbg, set a breakpoint at the strncmp call at 0x40123A, and add a command-line argument of abcd in OllyDbg before clicking the play button. When you click play, the strncmp function appears to compare abcd to bzqrp@ss; however, strncmp checks only the first 4 bytes of the bzqrp@ss string. We conclude that the password must be bzqr, but if we try that password on the command line outside a debugger, we receive the incorrect password error message. We dig deeper into the code to determine if something else is going on.

We begin by properly labeling the encoded string in the listing. The second parameter passed on the stack to strncmp is byte_408030 (a global variable), which we know to be a byte array of size 4. We change this into a 4-byte array and rename it encoded_password.

Next, we see CreateThread called just before the call to strncmp in the main function. To look at the code in the thread created by this call, double-click the parameter labeled StartAddress. This function appears to be a decoding routine since it contains many logical and shift operations on encoded_password. Examining the decoding routine closely, we see the BeingDebugged flag accessed, as shown in at and .

.

.

(sub_401020) is called. We check the cross-reference and see that sub_401020 is called from the TLS callback, as shown in (in bold).

starts by comparing arg_4 to the number 2. Recall from our earlier discussion that arg_4 to the TLS callback is used to determine when the TLS callback is made: 1 is used for when the process is starting up, 2 for when a thread is starting up, and 3 when the process is being terminated. Therefore, this TLS callback was called again when the CreateThread executed and caused the OutputDebugStringA to execute.

sss
sss

© RuTLib.com 2015-2018