cd ../../Reversing Malware

Reversing iBank Trojan [Injection Phase]

6 minutes read

SHA1: FA40B39B5E3755A3AB58634DBF0BAF4B0E0E3659

I’ve got the sample from ANY.RUN, the creation date of the sample is 2011 but it has been uploaded on VirusTotal just recently. After initial analysis, I’ve found that it’s a variant of banking trojan iBank

1

NOTE: My recommendation is to open IDA FREE/Pro or any other your favorite disassembler or debugger (x32dbg) inside a VM and analyze the sample with me

On ANY.RUN we see WHAT the malware does, it injects Explorer.exe, Explorer.exe itself injects windanr.exe, dwm.exe and taskhost.exe, it also tries to download key.bin file from different sources, at this point none of them works.

2

It’s WHAT the malware does, let’s see HOW it does this.

NOTE: I've renamed functions after analysis

3

At 0x0E22D30 it calls disable_CaHIPS to turn off CA HIPS via sending the corresponding request to the KmxAgent device:

4

At 0x0E22D35 it calls disableWindowsDefender to disable Windows Defender, you can read more about this method here

5

After that, it sends the control message to ____AVP.Root window, according to VirusBulletin article, it’s there to block Kaspersky Anti-Virus

6

disableAOutpostFirewall function uses Agnitum Outpost firewall vulnerability and tries to disable the firewall.

7

At AVG_mov_config_file it renames dfncfg.dat to dfmcfg.dat and at zero_AVG_confg_ it removes content of C:\ProgramData\PrevxCSI\csidb.csi.\AVG9\dfncfg.dat file, I think it tries to disable AVG anti-virus

At COM_Firewall_add it uses the COM object to initialize Windows Firewall with Advanced Security API (FirewallAPI.dll), the API contains functions to manage Windows Firewall settings.

8

It Checks if the firewall is enabled and if so, adds itself to the authorized applications list, if you wish you can find more about this method here:

9

If current user is a member of the Administrators group it adds the task to Task Scheduler using COM interface and exits, you can find more about COM interface of Task Scheduler here:

10

10_task

If the user is not the admin, it uses Run key for persistence and injects into Explorer.exe, otherwise injects into WinLogon.exe. To ensure that only one instance of malware runs, it uses GlobalAddAtomA/GlobalFindAtomA instead of Mutex

11

If the user is admin and path of the malware does not contain AppPatch string, it calls AppPatch_t function. At AppPatch_t it receives the volume serial number of the root directory (in my VM, it’s C:/), xors it with numbers from 0 to 0xFF, and uses change_values_encrypt__ function to further modify values, the result is applies as the filename to check if it exists under Windows Defender directory

12_vol_number

12_weird_path

It copies the malware to AppPatch/{RandomName}.exe and uses this name to generate data for 30dfa5f0 key (30dfa5f0 is volume serial number for my VM) under HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon

13

It sets the creation time of the malware equal to the NTFS.sys file s creation time.

14

If the user is admin it gets SE_DEBUG_PRIVILEGE privilege and injects into winlogon.exe

15

The getProc function is very simple: it receives a process name and returns the process handle:

16

InjectProc is also very simple, there are our old friends: VirtualAllocEx, WriteProcessMemory, more about process injections here, it uses CreateRemoteThread to execute code inside another process, in our case, it’s winlogon.exe (or explorer.exe if the user is not admin)

17

PE_file is inside the malware, you can dump it from memory or extract from the file, you can use the Rip button from Exeinfo PE

18

Interesting about the injected file (which is .dll by the way), is that it does not have imported functions, which means it somehow gets function addresses.

It uses PEB structure of the process to get the base address of ntdll module.

19

It uses getFuncAddr function to get the address of the desired function, getFuncAddr receives two arguments: the base address of the module, and the hash of the function name

21

Pseudocode of the getFuncAddr is below, it parses export table of the module and compares the hash of export name with the second argument:

20

The sample uses getKernelBase (0x10001000) to get the address of kernelbase module:

22

So, it has everything it needs to do whatever it wants.

What it does is very similar to the previous stage, but in this case, it allocates memory inside itself and copies the content of another PE file there.

23

It parses import table of the second PE, and gets all necessary functions addresses, it builds import table:

24

After that it jumps recently mapped PE via call esi:

25

The second PE is also embedded into original PE

26

I think the second PE have trojan capabilities, but it’s outside of the initial injection phase:

27

Any feedback would be greatly appreciated.

Twitter: @_qaz_qaz

Discuss on Reddit