Lab 9: Functions
Overview
The purpose of this lab is to become familiar identifying the various components of functions.
Getting Started
You will need to load the malware into IDA Pro. To go to an address press G.
Exercise Part 1: Dexter
For this exercise examine the dexter malware (found at
c:\malware\dexter\dexter.exe) There is a function that starts at 0x401700.
Question 1.1
In the function prologue identify:
- The number of parameters, local variables on the stack, and registers used
- The addresses and instructions used to save the old frame pointer, and allocate a new frame pointer
- The address and instructions used to allocate space on the stack for local variables
- The addresses and instructions used to save registers used in the function
Answer
- There are two parameters, two local variables on the stack, and one
variable stored in a register (
EBX) - The
push ebpat address0x401700is used to save the old frame pointer, and themov ebp, espat address0x401701is used to allocate a new one. - The
sub esp, 8at address00401703 - The
push ebxat address0x401706
Question 1.2
Identify the addresses of the body of the function
Answer
0x401707 through 0x4017BC
Question 1.3
In the function epilogue identify:
- The addresses of the instructions used to restore registers
- The addresses and instructions used to deallocate any stack variables
- The addresses and instructions used to restore the frame pointer
Answer
- The
pop ebxat address0x4017C7 - The
mov esp, ebpat address0x4017C8 - The
pop ebpat address0x4017CA
Part 2: NetWiredRC
For this exercise examine the netwiredrc malware (found at
c:\malware\netwiredrc\netwiredrc.exe) There is a function that starts at
address 0x004036A6.
Question 2.1
In the function prologue identify:
- The number of parameters, local variables on the stack, and registers used
- The addresses and instructions used to save the old frame pointer, and allocate a new frame pointer
- The address and instructions used to allocate space on the stack for local variables
- The addresses and instructions used to save registers used in the function
Answer
- There are three parameters, 17 local variables on the stack, and three variables stored in registers.
- The
push ebpat address0x4036A6is used to save the old frame pointer, and themov ebp, espat address0x4036AAis used to allocate a new one. - The
sub esp, 34Chat address0x401703. - The
push edi,push esi, andpush ebxinstructions at addresses0x4036AE,0x4036AF, and0x4036B0respectively.
Question 2.2
Identify the addresses of the body of the function
Answer
0x4036A7 through 0x40386C. Note that the function prologue code is
interspersed with some of the body of the function.
Question 2.3
In the function epilogue identify:
- The addresses of the instructions used to restore registers
- The addresses and instructions used to deallocate any stack variables
- The addresses and instructions used to restore the frame pointer
Answer
- The
pop ebx,pop esi, andpop ediinstructions at addresses0x403872,0x403873, and0x403874respectively. - The
lea esp, [ebp-0Ch]at address0x40386F. - The
pop ebpat address0x403875.
Exercise Part 3: Wannacry
For this exercise examine the wannacry malware (found at
c:\malware\wannacry\wannacry.exe) There is a function that starts at address
0x401225.
Hint
Not all of the items to identify will be separate instructions. Some instructions will have multiple purposes.
Question 3.1
In the function prologue identify:
- The number of parameters, local variables on the stack, and registers used
- The addresses and instructions used to save the old frame pointer, and allocate a new frame pointer
- The address and instructions used to allocate space on the stack for local variables
- The addresses and instructions used to save registers used in the function
Answer
- There is one parameter, four local variables on the stack, and three variables in registers.
- The
push ebpat address0x401225is used to save the old frame pointer, and themov ebp, espat address0x401226is used to allocate a new one. - The
sub esp, 198hat address0x401228. - The
push ebx,push esi, andpush ediinstructions at addresses0x401234,0x401235, and0x401236respectively.
Question 3.2
Identify the addresses of the body of the function
Answer
0x40122E through 0x4012EF. Note that the function prologue code is
interspersed with some of the body of the function.
Question 3.3
In the function epilogue identify:
- The addresses of the instructions used to restore registers
- The addresses and instructions used to deallocate any stack variables
- The addresses and instructions used to restore the frame pointer
Answer
- The
pop edi,pop esi, andpop ebxinstructions at addresses0x4012F8,0x4012F9, and0x4012FArespectively. - The
leaveat address0x4012FB - The
leaveat address0x4012FB
Note: the leave instruction essentially does a
mov esp, ebp, followed by a pop ebp, and as such
fullfills both the deallocation and restoration purposes.