question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Shellcode emulation issue

See original GitHub issue

While attempting to build Speakeasy support in Thug [1] I spotted a potential shellcode emulation issue. Still had no time to investigate it (will do soon) but just wanted to point it out.

While analyzing a local sample I got these results

$ thug -l samples/exploits/22196.html
[2020-09-10 17:06:24] <object classid="clsid:77829F14-D911-40FF-A2F0-D11DB8D6D0BC" id="pwnage">
</object>
[2020-09-10 17:06:24] ActiveXObject: 77829F14-D911-40FF-A2F0-D11DB8D6D0BC
[2020-09-10 17:06:24] [NCTAudioFile2 ActiveX] Overflow in SetFormatLikeSample
[2020-09-10 17:06:24] [EXPLOIT Classifier] URL: samples/exploits/22196.html (Rule: CVE-2007-0018, Classification: )
[2020-09-10 17:06:24] [Shellcode Profile] 
UINT WINAPI WinExec (
     LPCSTR lpCmdLine = 0x4181a1 =>
           = "calc.exe";
     UINT uCmdShow = 0;
) =  0x20;
void ExitThread (
     DWORD dwExitCode = 0;
) =  0x0;

The shellcode profile is generated by libemu/pylibemu in this case. When attempting to analyze the exact same shellcode with Speakeasy I get

{'arch': 'x86',
 'emu_version': '1.4.5',
 'emulation_total_runtime': 0.008,
 'entry_points': [{'apihash': 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
                   'apis': [],
                   'dynamic_code_segments': [],
                   'ep_args': ['0x41420000',
                               '0x41421000',
                               '0x41422000',
                               '0x41423000'],
                   'ep_type': 'shellcode',
                   'error': {'address': '0x2019',
                             'instr': 'retf 0x7cff',
                             'interrupt_num': 13,
                             'pc': '0x2019',
                             'regs': {'eax': '0x00000000',
                                      'ebp': '0x01204000',
                                      'ebx': '0x00000000',
                                      'ecx': '0x00001418',
                                      'edi': '0x00000000',
                                      'edx': '0x00000000',
                                      'eip': '0x00002019',
                                      'esi': '0xfeedf000',
                                      'esp': '0x01203fe8'},
                             'stack': ['sp+0x00: 0x41420000 -> '
                                       'emu.shellcode_arg_0.0x41420000',
                                       'sp+0x04: 0x41421000 -> '
                                       'emu.shellcode_arg_1.0x41421000',
                                       'sp+0x08: 0x41422000 -> '
                                       'emu.shellcode_arg_2.0x41422000',
                                       'sp+0x0c: 0x41423000 -> '
                                       'emu.shellcode_arg_3.0x41423000',
                                       'sp+0x10: 0xfeedf000',
                                       'sp+0x14: 0x00007000 -> '
                                       'emu.struct.ETHREAD.0x7000'],
                             'type': 'unhandled_interrupt'},
                   'ret_val': '0x0',
                   'start_addr': '0x1000'}],
 'mem_tag': 'emu.shellcode.4d546f0ac5350b72622f4bb0a39920e735935d92dccc83fde5393ce8b6ec6e51',
 'os_run': 'windows.6_1',
 'path': None,
 'report_version': '1.1.0',
 'sha256': '4d546f0ac5350b72622f4bb0a39920e735935d92dccc83fde5393ce8b6ec6e51',
 'size': 4662,
 'strings': {'in_memory': {'ansi': [], 'unicode': []},
             'static': {'ansi': ['AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA^',
                                 'IIIIIIIIIIIIIIIIIQZ7jJXP0B1ABkBAZB2BA2AA0AAX8BBPuzIYlm81T7pePUPLKG55lLKQlC5RXs1jOLKBoUHnkaOQ0TAzKsyLKUdNkwqZN4qiPLYnLK4o044VgjajjFmdAO2ZKl4Uk1D4dFd0uKUNkaOEtEQzKpfnkvlbkNkSo5LuQjKNkeLnkVaXkk9QLDdc4iS7AIPu4nkQPDpk5YPrXdLNkaPflNkPpELnMLKCXwxjKEYlKmPLpS0S0uPLK3XElcofQHvu0QFlIL8ncO0akRpbHXoxNm0u0bHNxinNjDNpWkOKWU3rAPl0cFNCUT8e5C0J'],
                        'unicode': []}},
 'timestamp': 1599750384}

Let me point out this does not happen for every Thug local exploit sample but just a few of them.

[1] https://github.com/buffer/thug

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
buffercommented, Dec 9, 2020

Yes, that shellcode was generated using Metasploit. Attaching you a potentially useful Python script. Using the option -s you can select a shellcode to emulate (the example I posted was generated by running python sctest.py -s 1). Already commented out the code that performs shellcode analysis with pylibemu. Feel free to uncomment if you are interested in comparing the results.

sctest.py.zip

0reactions
buffercommented, Dec 10, 2020

Thanks for taking care of it. I performed a couple of tests and can confirm the patch fixes the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Shellcode emulation issue - mandiant/speakeasy - GitHub
While attempting to build Speakeasy support in Thug [1] I spotted a potential shellcode emulation issue. Still had no time to investigate it ......
Read more >
Emulate Shellcode with Radare2 - SANS Institute
Emulate Shellcode with Radare2. This article breaks down how to emulate 32-bit ARM shellcode on an x86_64 Ubuntu system. September 30, 2022.
Read more >
Reversing a NSIS dropper using quick and dirty shellcode ...
We will statically unpack and emulate a malicious NSIS installer ... we are looking at is a solid LZMA archive, so unpacking it...
Read more >
Shellcode Detection and Emulation with Libemu
Call GetPC: we can detect the current program counter by issuing the call and pop assembly instructions. First we issue a short call...
Read more >
Emulation of Malicious Shellcode With Speakeasy | Mandiant
In the first part of this blog series, we will show the effectiveness of emulation with one of the more common samples of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found