Wednesday, January 24, 2024

Emulating Shellcodes - Chapter 2

 Lets check different  Cobalt Strike shellcodes and stages in the shellcodes emulator SCEMU.




This stages are fully emulated well and can get the IOC and the behavior of the shellcode.

But lets see another first stage big shellcode with c runtime embedded in a second stage.


In this case is loading tons of API using GetProcAddress at the beginning, then some encode/decode pointer and tls get/set values to store an address. And ends up crashing because is jumping an address that seems more code than address 0x9090f1eb.

Here there are two types of allocations:


Lets spawn a console on -c 3307548 and see if some of this allocations has the next stage.

The "m" command show all the memory maps but the "ma" show only the allocations done by the shellcode.



Dumping memory with "md" we see that there is data, and dissasembling this address with "d" we see the prolog of a function.

So we have second stage unpacked in alloc_e40064


With "mdd" we do a memory dump to disk we found the size in previous screenshot,  and we can do  some static reversing of stage2 in radare/ghidra/ida

In radare we can verify that the extracted is the next stage:


I usually do correlation between the emulation and ghidra, to understand the algorithms.

If wee look further we can realize that the emulator called a function on the stage2, we can see the change of code base address and  is calling the allocated buffer in 0x4f...



And this  stage2 perform several API calls let's check it in ghidra.


We can see in the emulator that enters in the IF block, and what are the (*DAT_...)() calls

Before a crash lets continue to the SEH pointer, in this case is the way, and the exception routine checks IsDebuggerPresent() which is not any debugger pressent for sure, so eax = 0;



So lets say yes and continue the emulation.


Both IsDebuggerPresent() and UnHandledExceptionFilter() can be used to detect a debugger, but the emulator return what has to return to not be detected. 

Nevertheless the shellcode detects something and terminates the process.

Lets trace the branches to understand the logic:


target/release/scemu -f shellcodes/unsuported_cs.bin -vv | egrep '(\*\*|j|cmp|test)'



Continuing the emulation it's setting the SEH  pointer to previous stage:


Lets see from the console where is pointing the SEH chain item:


to be continued ...


https://github.com/sha0coder/scemu






Related links
  1. Pentest Automation Tools
  2. Hack App
  3. New Hacker Tools
  4. Easy Hack Tools
  5. Hack Tools For Ubuntu
  6. Pentest Box Tools Download
  7. Pentest Tools Github
  8. Nsa Hack Tools
  9. Pentest Tools Free
  10. Hacking Tools Usb
  11. Pentest Tools Linux
  12. How To Install Pentest Tools In Ubuntu
  13. Hacking Tools For Beginners
  14. Hacker Tools Windows
  15. Pentest Tools Tcp Port Scanner
  16. Pentest Tools Framework
  17. Hack Tools
  18. New Hacker Tools
  19. Game Hacking
  20. Hacker Tools Github
  21. Hacker Tools
  22. Pentest Automation Tools
  23. Pentest Tools Download
  24. Hacker Tools Free Download
  25. Hack Tools Online
  26. Pentest Reporting Tools
  27. Hack Tool Apk
  28. Pentest Tools For Windows
  29. Hacking Tools Name
  30. Hack Tools Pc
  31. Pentest Tools
  32. Usb Pentest Tools
  33. Pentest Tools Kali Linux
  34. Hackrf Tools
  35. What Is Hacking Tools
  36. Hack Tool Apk No Root
  37. Nsa Hack Tools
  38. Hacking Tools Free Download
  39. Hack Tools
  40. Install Pentest Tools Ubuntu
  41. Hack Tools
  42. Hackers Toolbox
  43. Hack Apps
  44. Hacking Tools Name
  45. Pentest Tools Find Subdomains
  46. Hacker Techniques Tools And Incident Handling
  47. Blackhat Hacker Tools
  48. How To Hack
  49. Hacking Tools Hardware
  50. Best Hacking Tools 2019
  51. Hacker Tools For Ios
  52. Usb Pentest Tools
  53. Android Hack Tools Github
  54. Pentest Tools Review
  55. Pentest Tools Kali Linux
  56. Hacking Tools Hardware
  57. Hack Website Online Tool
  58. World No 1 Hacker Software
  59. Hacking Tools For Beginners
  60. World No 1 Hacker Software
  61. Pentest Tools Online
  62. Hacking Tools Pc
  63. Pentest Box Tools Download
  64. Hack Tools For Ubuntu
  65. What Is Hacking Tools
  66. Free Pentest Tools For Windows
  67. Best Hacking Tools 2019
  68. Hack And Tools
  69. Hacker Tools For Mac
  70. Pentest Tools For Windows
  71. Hacking Tools Github
  72. Hacking Tools Software
  73. Hack Tools Online
  74. Pentest Tools Alternative
  75. Android Hack Tools Github
  76. Hacker Tools Mac
  77. Pentest Reporting Tools
  78. Pentest Tools Open Source
  79. Pentest Tools Online
  80. Hacker Tools Mac
  81. Easy Hack Tools
  82. Pentest Tools Free
  83. Pentest Tools Alternative
  84. Hackrf Tools
  85. Best Pentesting Tools 2018
  86. Hacker
  87. Hack Tool Apk No Root
  88. World No 1 Hacker Software
  89. Hacking Tools Download
  90. Hacker Tools Apk Download
  91. Hacker Hardware Tools
  92. Black Hat Hacker Tools
  93. Hacking Tools Windows
  94. Hacking Tools Usb
  95. Hacker Tools Hardware
  96. Ethical Hacker Tools
  97. Bluetooth Hacking Tools Kali
  98. Hack Tools 2019
  99. Hacking Tools For Mac
  100. Hackrf Tools