SlideShare a Scribd company logo
Remote Code Execution
in restricted Windows
environments
Foto ponente
Borja Merino Febrero
borja.merino@protonmail.com
[0x00000001]> Let's get some context
REF: https://blog.rapid7.com/2015/03/25/stageless-meterpreter-payloads/ (OJ Reeves)
[0x00000002]> What is a Stager?
• Shellcode responsible for fetching and executing the next Stage (malware/implant,
intermediate stage).
• They arise as a need due to the nature of certain exploits (space restrictions).
However, they can be very useful even when we have the option to use a stageless
approach ("Data Contraception“, “Profiling”).
• They are usually hand-made to take the less space possible and to be used by a
greater number of exploits. Compiling from languages such as C is another viable
option, however, some issues have to be resolved: : PIC (Position-independent
code), WinAPI resolution, stack strings, removing unneeded code, etc. *
• Frameworks like Metasploit implement a large number of stagers that we can use to
run our own payloads/implants
REF: http://www.exploit-monday.com/2013/08/writing-optimized-windows-shellcode-in-c.html
[0x00000003]> Pazuzu (reusing stagers for your implants)
REF: https://github.com/BorjaMerino/Pazuzu
[0x00000004]> Amber (reusing stagers for your implants)
REF: https://github.com/EgeBalci/Amber (Ege Balcı)
Memory Mapping
File
[0x00000005]> Stager skeleton
https://github.com/rsmudge/metasploit-loader/blob/master/src/main.c (Raphael Mudge) Shellcode/windows/x86/src/block/block_recv.asm (Metasploit)
[0x00000006]> Other useful uses
Intermediate stage that
checks if the objective is
a potencial victim and if
it meets certain criteria
(domain?, language?,
country? virtualized?,
sandbox?)
Stager as a persistence
method to recover and
execute the implant in
memory (no disk
artifacts)
REF: http://phrack.org/issues/62/8.html (the grugq)
[0x00000007]> Stager building
REF: https://www.sekoia.fr/blog/microsoft-edge-binary-injection-mitigation-overview/
*
[0x00000008]> HTTP / HTTPS Transports
*
WinINet
• Oriented to desktop applications
• Sometimes WinINet is filtered by endpoint protection products
WinHTTP
• Oriented to services (used by BITS and Windows Update)
• Allows SSL validation/Certificate Pinning (Useful to avoid MiTM attacks)
• Require “Keep-alive” (this is a problem with proxys HTTP 1.0). If there is enough
room we can fallback to WinINet
REF: https://github.com/rapid7/metasploit-framework/wiki/The-ins-and-outs-of-HTTP-and-HTTPS-communications-in-Meterpreter-and-Metasploit-Stagers
[0x00000009]> No protocol limitations: Modbus Stager
REF: https://www.shelliscoming.com/2016/12/modbus-stager-using-plcs-as.html
*
< 500 bytes
[0x0000000A]> No protocol limitations: Modbus Stager
REF: https://www.shelliscoming.com/2016/12/modbus-stager-using-plcs-as.html
[0x0000000B]> Drawbacks of “universal” stagers
REF: http://phrack.org/issues/62/7.html
Useful Stagers:
• Reverse Hop HTTP
• Reverse TCP All Ports
• DNS TXT Record Payload
Option: Socket hunting
• Manual search
• Rebinding ports *
• Brute-force socket handles
• FindTag (need recv() length argument)
• FindPort (No PAT/NAT Immune)
• Out-Of-Band Data *
• Socket's lifetime *
IMP! Just useful when the process owns the socket (some services like DCOM, SMB, etc. are proxied through
a central service and there is no socket to steal)
[0x0000000C]> Handles Table
REF: https://blogs.technet.microsoft.com/markrussinovich/2009/09/29/pushing-the-limits-of-windows-handles/
[0x0000000D]> APT1 Owned (Malware.lu CERT)
REF: https://malware.lu/assets/files/articles/RAP002_APT1_Technical_backstage.1.0.pdf
[0x0000000E]> Veritas Backup Exploit (H.D. Moore)
REF: https://github.com/rapid7/metasploit-framework/blob/master/modules/exploits/windows/backupexec/name_service.rb
[0x0000000F]> Microsoft IIS 4.0/5.0 Exploit (Yuange)
https://www.exploit-db.com/exploits/21371
REF: https://cybersecpolitics.blogspot.com/2018/04/stealing-socket-for-policy-and-profit.html
[0x00000010]> Socket Hunting (manual approach)
Windows Preview quite useful!
- TTD (Time Travel Debugging)
- Taint Analysis
- Code-Flow / Coverage
REF: https://github.com/microsoft/WinDbg-Samples
[0x00000011]> Shellcode based on socket's lifetime
REF: https://www.shelliscoming.com/2018/06/windows-reuse-shellcode-based-on.html
[0x00000012]> Shellcode based on Out Of Band data
REF: https://www.shelliscoming.com/2019/03/one-way-shellcode-for-firewall-evasion.html
https://bbs.eviloctal.com/thread-10143-1-8.html (Linux exploit: Autor bkbll)
TCP allows to send "OOB" data in the same
channel as a way to indicate that some
information in the stream should be processed as
soon as possible by the recipient peer
[0x00000013]> One-Way VS reverse shell
Standard
Reverse Shell
One-Way
Stager
[0x00000014]> Rebinding approach
REF: https://web.archive.org/web/20161107193740/http://www.lsd-pl.net/winasm-slides.pdf
[0x00000015]> Rebind Port + ACL Shellcode
REF: https://www.shelliscoming.com/2019/11/retro-shellcoding-for-current-threats.html
https://wj32.org/wp/2009/01/24/howto-get-the-command-line-of-processes/
Process ’’Forking’’
[0x00000016]> ACL Shellcode
REF: https://www.shelliscoming.com/2014/07/ip-knock-shellcode-spoofed-ip-as.html
[0x00000017]> One-Way-Shellcodes drawbacks
• Sometimes the socket is not owned by the process.
• Brute-force socket handles it's not a very reliable method
(it doesn’t work in practice with many exploits).
• Sometimes even if you get the socket handle your payload
randomly die (i.e.: another thread tries to do something in your
socket).
• Most of the shellcodes are exploit specific (not universal).
• They require a lot of effort and time.
Non serious experiment: Stager hunter (Honeypot with Frida)
Collection of papers/talks and techniques in Windows:
https://github.com/BorjaMerino/Windows-One-Way-Stagers
Remote code execution in restricted windows environments
Remote code execution in restricted windows environments

More Related Content

PDF
Upping the APT hunting game: learn the best YARA practices from Kaspersky
PDF
Windows attacks - AT is the new black
PDF
64 Methods for Mimikatz Execution
PDF
Red Team Framework
PDF
Goroutines and Channels in practice
PPTX
Adversary Emulation using CALDERA
PDF
Finding attacks with these 6 events
PDF
Penetration testing
Upping the APT hunting game: learn the best YARA practices from Kaspersky
Windows attacks - AT is the new black
64 Methods for Mimikatz Execution
Red Team Framework
Goroutines and Channels in practice
Adversary Emulation using CALDERA
Finding attacks with these 6 events
Penetration testing

What's hot (20)

PDF
Threat Hunting Report
PDF
Hunting Lateral Movement in Windows Infrastructure
PDF
Log Analysis
PDF
IBM MQ - Comparing Distributed and z/OS platforms
PDF
Introduction to Perf
PDF
PHDays 2018 Threat Hunting Hands-On Lab
PDF
Hunting for Privilege Escalation in Windows Environment
PPTX
Derbycon - Passing the Torch
PPTX
Threat Hunting with Splunk
PDF
ReCertifying Active Directory
PPTX
Recon with Nmap
PPTX
Adversary Emulation and Its Importance for Improving Security Posture in Orga...
PPTX
Abusing Microsoft Kerberos - Sorry you guys don't get it
PDF
MITRE ATT&CKcon 2018: Building an Atomic Testing Program, Brian Beyer, Red Ca...
PPTX
Here Be Dragons: The Unexplored Land of Active Directory ACLs
PDF
Pentesting like a grandmaster BSides London 2013
PDF
Red vs Blue- Modern Atice Directory Attacks, Detection & Protection by Sean M...
PDF
MITRE ATT&CK Updates: State of the ATT&CK (ATT&CKcon 4.0 Edition)
PDF
Threat hunting 101 by Sandeep Singh
Threat Hunting Report
Hunting Lateral Movement in Windows Infrastructure
Log Analysis
IBM MQ - Comparing Distributed and z/OS platforms
Introduction to Perf
PHDays 2018 Threat Hunting Hands-On Lab
Hunting for Privilege Escalation in Windows Environment
Derbycon - Passing the Torch
Threat Hunting with Splunk
ReCertifying Active Directory
Recon with Nmap
Adversary Emulation and Its Importance for Improving Security Posture in Orga...
Abusing Microsoft Kerberos - Sorry you guys don't get it
MITRE ATT&CKcon 2018: Building an Atomic Testing Program, Brian Beyer, Red Ca...
Here Be Dragons: The Unexplored Land of Active Directory ACLs
Pentesting like a grandmaster BSides London 2013
Red vs Blue- Modern Atice Directory Attacks, Detection & Protection by Sean M...
MITRE ATT&CK Updates: State of the ATT&CK (ATT&CKcon 4.0 Edition)
Threat hunting 101 by Sandeep Singh
Ad

Similar to Remote code execution in restricted windows environments (20)

PDF
[若渴計畫] Challenges and Solutions of Window Remote Shellcode
PPTX
Pushing Data from S7-1200 to Cloud
PDF
DEF CON 27 - DANIEL ROMERO and MARIO RIVAS - why you should fear your mundane...
PPTX
Buffer overflows
PPT
.NET Debugging Tips and Techniques
PPT
.Net Debugging Techniques
PDF
Iot Conference Berlin M2M,IoT, device management: one protocol to rule them all?
PDF
Hacking Highly Secured Enterprise Environments by Zoltan Balazs
PDF
Hunting and Exploiting Bugs in Kernel Drivers - DefCamp 2012
PDF
DotDotPwn Fuzzer - Black Hat 2011 (Arsenal)
PDF
Embedded. What Why How
PDF
Crash dump analysis - experience sharing
PPTX
Advanced SOHO Router Exploitation XCON
PPTX
Security research over Windows #defcon china
PDF
Web (dis)assembly
PDF
3-Way Scripts as a Practical Platform for Secure Distributed Code in Clouds
PDF
FPC for the Masses (SANSFire Edition)
PDF
DEFCON 22: Bypass firewalls, application white lists, secure remote desktops ...
PDF
Intrusion Techniques
PPTX
Using hypervisor and container technology to increase datacenter security pos...
[若渴計畫] Challenges and Solutions of Window Remote Shellcode
Pushing Data from S7-1200 to Cloud
DEF CON 27 - DANIEL ROMERO and MARIO RIVAS - why you should fear your mundane...
Buffer overflows
.NET Debugging Tips and Techniques
.Net Debugging Techniques
Iot Conference Berlin M2M,IoT, device management: one protocol to rule them all?
Hacking Highly Secured Enterprise Environments by Zoltan Balazs
Hunting and Exploiting Bugs in Kernel Drivers - DefCamp 2012
DotDotPwn Fuzzer - Black Hat 2011 (Arsenal)
Embedded. What Why How
Crash dump analysis - experience sharing
Advanced SOHO Router Exploitation XCON
Security research over Windows #defcon china
Web (dis)assembly
3-Way Scripts as a Practical Platform for Secure Distributed Code in Clouds
FPC for the Masses (SANSFire Edition)
DEFCON 22: Bypass firewalls, application white lists, secure remote desktops ...
Intrusion Techniques
Using hypervisor and container technology to increase datacenter security pos...
Ad

Recently uploaded (20)

PDF
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
PPTX
international classification of diseases ICD-10 review PPT.pptx
PDF
Cloud-Scale Log Monitoring _ Datadog.pdf
PPTX
522797556-Unit-2-Temperature-measurement-1-1.pptx
PPTX
Power Point - Lesson 3_2.pptx grad school presentation
PPTX
Job_Card_System_Styled_lorem_ipsum_.pptx
PPTX
Introduction to Information and Communication Technology
PPTX
artificial intelligence overview of it and more
PDF
Sims 4 Historia para lo sims 4 para jugar
PDF
Slides PDF The World Game (s) Eco Economic Epochs.pdf
PDF
RPKI Status Update, presented by Makito Lay at IDNOG 10
PDF
Testing WebRTC applications at scale.pdf
PPTX
E -tech empowerment technologies PowerPoint
PDF
FINAL CALL-6th International Conference on Networks & IOT (NeTIOT 2025)
PPTX
Module 1 - Cyber Law and Ethics 101.pptx
PDF
Unit-1 introduction to cyber security discuss about how to secure a system
PPTX
Internet___Basics___Styled_ presentation
PDF
WebRTC in SignalWire - troubleshooting media negotiation
PPTX
PptxGenJS_Demo_Chart_20250317130215833.pptx
PPTX
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
international classification of diseases ICD-10 review PPT.pptx
Cloud-Scale Log Monitoring _ Datadog.pdf
522797556-Unit-2-Temperature-measurement-1-1.pptx
Power Point - Lesson 3_2.pptx grad school presentation
Job_Card_System_Styled_lorem_ipsum_.pptx
Introduction to Information and Communication Technology
artificial intelligence overview of it and more
Sims 4 Historia para lo sims 4 para jugar
Slides PDF The World Game (s) Eco Economic Epochs.pdf
RPKI Status Update, presented by Makito Lay at IDNOG 10
Testing WebRTC applications at scale.pdf
E -tech empowerment technologies PowerPoint
FINAL CALL-6th International Conference on Networks & IOT (NeTIOT 2025)
Module 1 - Cyber Law and Ethics 101.pptx
Unit-1 introduction to cyber security discuss about how to secure a system
Internet___Basics___Styled_ presentation
WebRTC in SignalWire - troubleshooting media negotiation
PptxGenJS_Demo_Chart_20250317130215833.pptx
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION

Remote code execution in restricted windows environments

  • 1. Remote Code Execution in restricted Windows environments
  • 2. Foto ponente Borja Merino Febrero borja.merino@protonmail.com
  • 3. [0x00000001]> Let's get some context REF: https://blog.rapid7.com/2015/03/25/stageless-meterpreter-payloads/ (OJ Reeves)
  • 4. [0x00000002]> What is a Stager? • Shellcode responsible for fetching and executing the next Stage (malware/implant, intermediate stage). • They arise as a need due to the nature of certain exploits (space restrictions). However, they can be very useful even when we have the option to use a stageless approach ("Data Contraception“, “Profiling”). • They are usually hand-made to take the less space possible and to be used by a greater number of exploits. Compiling from languages such as C is another viable option, however, some issues have to be resolved: : PIC (Position-independent code), WinAPI resolution, stack strings, removing unneeded code, etc. * • Frameworks like Metasploit implement a large number of stagers that we can use to run our own payloads/implants REF: http://www.exploit-monday.com/2013/08/writing-optimized-windows-shellcode-in-c.html
  • 5. [0x00000003]> Pazuzu (reusing stagers for your implants) REF: https://github.com/BorjaMerino/Pazuzu
  • 6. [0x00000004]> Amber (reusing stagers for your implants) REF: https://github.com/EgeBalci/Amber (Ege Balcı) Memory Mapping File
  • 7. [0x00000005]> Stager skeleton https://github.com/rsmudge/metasploit-loader/blob/master/src/main.c (Raphael Mudge) Shellcode/windows/x86/src/block/block_recv.asm (Metasploit)
  • 8. [0x00000006]> Other useful uses Intermediate stage that checks if the objective is a potencial victim and if it meets certain criteria (domain?, language?, country? virtualized?, sandbox?) Stager as a persistence method to recover and execute the implant in memory (no disk artifacts) REF: http://phrack.org/issues/62/8.html (the grugq)
  • 9. [0x00000007]> Stager building REF: https://www.sekoia.fr/blog/microsoft-edge-binary-injection-mitigation-overview/ *
  • 10. [0x00000008]> HTTP / HTTPS Transports * WinINet • Oriented to desktop applications • Sometimes WinINet is filtered by endpoint protection products WinHTTP • Oriented to services (used by BITS and Windows Update) • Allows SSL validation/Certificate Pinning (Useful to avoid MiTM attacks) • Require “Keep-alive” (this is a problem with proxys HTTP 1.0). If there is enough room we can fallback to WinINet REF: https://github.com/rapid7/metasploit-framework/wiki/The-ins-and-outs-of-HTTP-and-HTTPS-communications-in-Meterpreter-and-Metasploit-Stagers
  • 11. [0x00000009]> No protocol limitations: Modbus Stager REF: https://www.shelliscoming.com/2016/12/modbus-stager-using-plcs-as.html * < 500 bytes
  • 12. [0x0000000A]> No protocol limitations: Modbus Stager REF: https://www.shelliscoming.com/2016/12/modbus-stager-using-plcs-as.html
  • 13. [0x0000000B]> Drawbacks of “universal” stagers REF: http://phrack.org/issues/62/7.html Useful Stagers: • Reverse Hop HTTP • Reverse TCP All Ports • DNS TXT Record Payload Option: Socket hunting • Manual search • Rebinding ports * • Brute-force socket handles • FindTag (need recv() length argument) • FindPort (No PAT/NAT Immune) • Out-Of-Band Data * • Socket's lifetime * IMP! Just useful when the process owns the socket (some services like DCOM, SMB, etc. are proxied through a central service and there is no socket to steal)
  • 14. [0x0000000C]> Handles Table REF: https://blogs.technet.microsoft.com/markrussinovich/2009/09/29/pushing-the-limits-of-windows-handles/
  • 15. [0x0000000D]> APT1 Owned (Malware.lu CERT) REF: https://malware.lu/assets/files/articles/RAP002_APT1_Technical_backstage.1.0.pdf
  • 16. [0x0000000E]> Veritas Backup Exploit (H.D. Moore) REF: https://github.com/rapid7/metasploit-framework/blob/master/modules/exploits/windows/backupexec/name_service.rb
  • 17. [0x0000000F]> Microsoft IIS 4.0/5.0 Exploit (Yuange) https://www.exploit-db.com/exploits/21371 REF: https://cybersecpolitics.blogspot.com/2018/04/stealing-socket-for-policy-and-profit.html
  • 18. [0x00000010]> Socket Hunting (manual approach) Windows Preview quite useful! - TTD (Time Travel Debugging) - Taint Analysis - Code-Flow / Coverage REF: https://github.com/microsoft/WinDbg-Samples
  • 19. [0x00000011]> Shellcode based on socket's lifetime REF: https://www.shelliscoming.com/2018/06/windows-reuse-shellcode-based-on.html
  • 20. [0x00000012]> Shellcode based on Out Of Band data REF: https://www.shelliscoming.com/2019/03/one-way-shellcode-for-firewall-evasion.html https://bbs.eviloctal.com/thread-10143-1-8.html (Linux exploit: Autor bkbll) TCP allows to send "OOB" data in the same channel as a way to indicate that some information in the stream should be processed as soon as possible by the recipient peer
  • 21. [0x00000013]> One-Way VS reverse shell Standard Reverse Shell One-Way Stager
  • 22. [0x00000014]> Rebinding approach REF: https://web.archive.org/web/20161107193740/http://www.lsd-pl.net/winasm-slides.pdf
  • 23. [0x00000015]> Rebind Port + ACL Shellcode REF: https://www.shelliscoming.com/2019/11/retro-shellcoding-for-current-threats.html https://wj32.org/wp/2009/01/24/howto-get-the-command-line-of-processes/ Process ’’Forking’’
  • 24. [0x00000016]> ACL Shellcode REF: https://www.shelliscoming.com/2014/07/ip-knock-shellcode-spoofed-ip-as.html
  • 25. [0x00000017]> One-Way-Shellcodes drawbacks • Sometimes the socket is not owned by the process. • Brute-force socket handles it's not a very reliable method (it doesn’t work in practice with many exploits). • Sometimes even if you get the socket handle your payload randomly die (i.e.: another thread tries to do something in your socket). • Most of the shellcodes are exploit specific (not universal). • They require a lot of effort and time. Non serious experiment: Stager hunter (Honeypot with Frida) Collection of papers/talks and techniques in Windows: https://github.com/BorjaMerino/Windows-One-Way-Stagers