SlideShare a Scribd company logo
Efficient Bytecode Analysis:
Linespeed Shellcode Detection
Georg Wicherski
Security Researcher
Anatomy of a Shellcode

• Little piece of Bytecode that gets jumped to in an exploit
  – Direct overwrite of EIP on the stack
  – Sprayed on the Heap and called as a function pointer
  – Allocated by small ROP payload and jumped to by last gadget
      • Minus Zynamics Google, they do ROPperies


• Usually some requirements because it is delivered inline
  – Null byte free, because it terminates a C-String
  – rn free, because it often is a delimiter in network protocols
  – ...



            Decoder Stub               Encoded Shellcode
Shellcode Decoder Structure

  jmp getpc                   ; jump to GetPC

  start:                      ; GetPC 2: ebp = EIP
    pop ebp
    push 42                   ; load counter = 42
    pop ecx
    push 23                   ; load key = 23
    pop edx

  decrypt:
    xor byte [ebp+ecx], dl    ; unxor one byte
    loop decrypt              ; repeat until ecx = 0
  jmp payload

  getpc:
    call start                ; GetPC 1: push EIP to stack
  payload:
GetPC Sequences

• call $+5, pop r32
  – Push return address for function call onto stack
  – Use stack access to read back the return address

• fnop, fnstenv [esp+0x0c], pop r32
  – Use a floating point instruction, address will be stored in floating point
    control aread
  – Save floating point control area on stack
  – Read back the instruction address from stack


• Structured Exception Handling
  – Windows specific, trigger an exception
  – Get address of exception instruction in exception handler
Existing Detection Approaches

• Static / Statistical Approaches
   – e.g. Markov Chains for Bytecode (Alme & Elser, Caro 2009)
       • Trained with shellcode / non-shellcode data
       • Measures likelyhood of certain instructions following each other
   – Can only detect the decoder and therefore tend to be either false positive
     or false negative prone (weighting, training data, ...)

• GetPC Sequences + Backtracking + Emulation (libemu)
   – Identify possible GetPC sequences in data
   – Build up tree of possible starting locations by disassembling “backwards”
       • A problem on its own on the x86 CISC architecture
   – Software x86 emulation to weed out (the many) false positives
libscizzle

• Identification of possible GetPC sequences
   – A little less strict than libemu in terms of triggering combinations


• Brute force possible starting location around sequence
   – Efficient emulation allows this performance wise


• Use efficient sandboxed hardware execution for verification
   – No, this is not virtualization, no VT involved
   – Yes, it is secure, so we do not get owned (trivially)




       http://code.mwcollect.org/projects/libscizzle
x86 Segmentation vs. Paging


     Segment           Virtual   Physical
Code Execution / “Emulation”

• Disassemble guest code
   – Stop on any privileged or (potentially)
     execution flow modifying instruction
   – This is roughly equivalent to “basic
     blocks”
   – Segment register access is considered
     a privileged instruction ;)

• Execute one basic block at a time
  within the guest segment
• Emulate all other instructions
   – Conditional jumps, calls, ...
   – Abort analysis on any privileged
     instructions

• Exception: backwards short jumps
Evaluation: Performance

$ ./libscizzle-test < urandom.bin
[*] Filtering / scanning over 32.0 MiB of data took 105 ms.
[*] Verifying 700 shellcode candidate offsets...
[*] Verification over 32.0 MiB of data took 217 ms.
[*] Everything over 32.0 MiB of data took 322 ms.


• 99.38 Mib / sec, 795 MiB / sec on my presentation laptop, single core
• About 1000x faster than libemu, a lot faster than Markov Chains

• This is fast enough to do it inline at GigaBit speed on a commodity
  server, think IPS
• Real world data has usually better properties than purely random data
Evaluation: Success Rate

• False Positives: none.
   – If it is detected, it resembles valid
     shellcode
   – Random data might resemble valid
     shellcode but this is a philosophical
     problem then, highly unlikely.

• False Negatives: none so far
   – Tested on a lot of public shellcodes
     (tricky Metasploit ones,
     egghunters)
   – Used during CTFs for testing
     libscizzle, detected everything
        • DefCon, ruCTFe, ...

• Manual evasion possible
Questions?




             Thanks for your attention!

More Related Content

PDF
Dynamic Instrumentation- OpenEBS Golang Meetup July 2017
PDF
Make Your Own Developement Board @ 2014.4.21 JuluOSDev
PPTX
grsecurity and PaX
PDF
High-Performance Networking Using eBPF, XDP, and io_uring
PPTX
The Silence of the Canaries
PDF
The Simple Scheduler in Embedded System @ OSDC.TW 2014
PPT
PDF
Get Lower Latency and Higher Throughput for Java Applications
Dynamic Instrumentation- OpenEBS Golang Meetup July 2017
Make Your Own Developement Board @ 2014.4.21 JuluOSDev
grsecurity and PaX
High-Performance Networking Using eBPF, XDP, and io_uring
The Silence of the Canaries
The Simple Scheduler in Embedded System @ OSDC.TW 2014
Get Lower Latency and Higher Throughput for Java Applications

What's hot (20)

PDF
OSNoise Tracer: Who Is Stealing My CPU Time?
PPTX
Onnc intro
ODP
Linux kernel tracing superpowers in the cloud
PDF
Using eBPF to Measure the k8s Cluster Health
PDF
Translation Cache Policies for Dynamic Binary Translation
PPT
Concurrency bug identification through kernel panic log (english)
PPTX
Dead Lock Analysis of spin_lock() in Linux Kernel (english)
PDF
Whoops! I Rewrote It in Rust
PDF
Continuous Performance Regression Testing with JfrUnit
PDF
Linux kernel debugging
PDF
Crimson: Ceph for the Age of NVMe and Persistent Memory
PDF
RISC-V on Edge: Porting EVE and Alpine Linux to RISC-V
PPTX
Demo
PDF
LAS16-101: Efficient kernel backporting
PDF
OSv Unikernel — Optimizing Guest OS to Run Stateless and Serverless Apps in t...
PDF
Continuous Go Profiling & Observability
PPTX
Evented Ruby VS Node.js
PPTX
Designing Tracing Tools
PDF
from Binary to Binary: How Qemu Works
PDF
IPv4aaS tutorial and hands-on
OSNoise Tracer: Who Is Stealing My CPU Time?
Onnc intro
Linux kernel tracing superpowers in the cloud
Using eBPF to Measure the k8s Cluster Health
Translation Cache Policies for Dynamic Binary Translation
Concurrency bug identification through kernel panic log (english)
Dead Lock Analysis of spin_lock() in Linux Kernel (english)
Whoops! I Rewrote It in Rust
Continuous Performance Regression Testing with JfrUnit
Linux kernel debugging
Crimson: Ceph for the Age of NVMe and Persistent Memory
RISC-V on Edge: Porting EVE and Alpine Linux to RISC-V
Demo
LAS16-101: Efficient kernel backporting
OSv Unikernel — Optimizing Guest OS to Run Stateless and Serverless Apps in t...
Continuous Go Profiling & Observability
Evented Ruby VS Node.js
Designing Tracing Tools
from Binary to Binary: How Qemu Works
IPv4aaS tutorial and hands-on
Ad

Viewers also liked (20)

PDF
Anatomy of A Shell Code, Reverse engineering
ODP
Design and implementation_of_shellcodes
PDF
Linux Shellcode disassembling
PPTX
07 - Bypassing ASLR, or why X^W matters
PDF
Shellcode and heapspray detection in phoneyc
PPTX
05 - Bypassing DEP, or why ASLR matters
PPTX
Java Shellcode Execution
PPTX
Exploit Research and Development Megaprimer: Unicode Based Exploit Development
PDF
Rooting Your Internals: Inter-Protocol Exploitation, custom shellcode and BeEF
PDF
Talking about exploit writing
PPTX
Anton Dorfman. Shellcode Mastering.
PDF
Shellcode Analysis - Basic and Concept
PDF
Hacking school computers for fun profit and better grades short
PPTX
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
PPTX
Exploit Research and Development Megaprimer: Win32 Egghunter
PDF
One Shellcode to Rule Them All: Cross-Platform Exploitation
PPT
Software Exploits
PDF
Shellcode injection
PPT
Writing Metasploit Plugins
PDF
Rooting your internals - Exploiting Internal Network Vulns via the Browser Us...
Anatomy of A Shell Code, Reverse engineering
Design and implementation_of_shellcodes
Linux Shellcode disassembling
07 - Bypassing ASLR, or why X^W matters
Shellcode and heapspray detection in phoneyc
05 - Bypassing DEP, or why ASLR matters
Java Shellcode Execution
Exploit Research and Development Megaprimer: Unicode Based Exploit Development
Rooting Your Internals: Inter-Protocol Exploitation, custom shellcode and BeEF
Talking about exploit writing
Anton Dorfman. Shellcode Mastering.
Shellcode Analysis - Basic and Concept
Hacking school computers for fun profit and better grades short
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
Exploit Research and Development Megaprimer: Win32 Egghunter
One Shellcode to Rule Them All: Cross-Platform Exploitation
Software Exploits
Shellcode injection
Writing Metasploit Plugins
Rooting your internals - Exploiting Internal Network Vulns via the Browser Us...
Ad

Similar to Efficient Bytecode Analysis: Linespeed Shellcode Detection (20)

PDF
Dive into exploit development
PPTX
Anatomy of a Buffer Overflow Attack
PDF
Shellcodes for ARM: Your Pills Don't Work on Me, x86
PDF
A CTF Hackers Toolbox
PPTX
ETCSS: Into the Mind of a Hacker
PDF
2011-03 Developing Windows Exploits
PDF
Shellcode Disassembling - Reverse Engineering
PDF
Fuzzing: Finding Your Own Bugs and 0days! at Arab Security Conference
PDF
Defcon 27 - Writing custom backdoor payloads with C#
PDF
Fuzzing - Part 1
PPTX
Steelcon 2014 - Process Injection with Python
PDF
DARPA CGC and DEFCON CTF: Automatic Attack and Defense Technique
PDF
[若渴計畫] Challenges and Solutions of Window Remote Shellcode
PDF
My old security advisories on HMI/SCADA and industrial software released betw...
PDF
Sourcefire Vulnerability Research Team Labs
PDF
Sergi Álvarez + Roi Martín - radare2: From forensics to bindiffing [RootedCON...
PPTX
EhTrace -- RoP Hooks
PPTX
Adventures in Asymmetric Warfare
PDF
stackconf 2021 | Fuzzing: Finding Your Own Bugs and 0days!
PDF
Higher Level Malware
Dive into exploit development
Anatomy of a Buffer Overflow Attack
Shellcodes for ARM: Your Pills Don't Work on Me, x86
A CTF Hackers Toolbox
ETCSS: Into the Mind of a Hacker
2011-03 Developing Windows Exploits
Shellcode Disassembling - Reverse Engineering
Fuzzing: Finding Your Own Bugs and 0days! at Arab Security Conference
Defcon 27 - Writing custom backdoor payloads with C#
Fuzzing - Part 1
Steelcon 2014 - Process Injection with Python
DARPA CGC and DEFCON CTF: Automatic Attack and Defense Technique
[若渴計畫] Challenges and Solutions of Window Remote Shellcode
My old security advisories on HMI/SCADA and industrial software released betw...
Sourcefire Vulnerability Research Team Labs
Sergi Álvarez + Roi Martín - radare2: From forensics to bindiffing [RootedCON...
EhTrace -- RoP Hooks
Adventures in Asymmetric Warfare
stackconf 2021 | Fuzzing: Finding Your Own Bugs and 0days!
Higher Level Malware

Recently uploaded (20)

PDF
Encapsulation theory and applications.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
KodekX | Application Modernization Development
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Cloud computing and distributed systems.
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Empathic Computing: Creating Shared Understanding
PDF
cuic standard and advanced reporting.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
A Presentation on Artificial Intelligence
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Electronic commerce courselecture one. Pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
Encapsulation theory and applications.pdf
The AUB Centre for AI in Media Proposal.docx
KodekX | Application Modernization Development
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Digital-Transformation-Roadmap-for-Companies.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Cloud computing and distributed systems.
Per capita expenditure prediction using model stacking based on satellite ima...
Empathic Computing: Creating Shared Understanding
cuic standard and advanced reporting.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Spectral efficient network and resource selection model in 5G networks
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
NewMind AI Weekly Chronicles - August'25 Week I
A Presentation on Artificial Intelligence
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Electronic commerce courselecture one. Pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
The Rise and Fall of 3GPP – Time for a Sabbatical?

Efficient Bytecode Analysis: Linespeed Shellcode Detection

  • 1. Efficient Bytecode Analysis: Linespeed Shellcode Detection Georg Wicherski Security Researcher
  • 2. Anatomy of a Shellcode • Little piece of Bytecode that gets jumped to in an exploit – Direct overwrite of EIP on the stack – Sprayed on the Heap and called as a function pointer – Allocated by small ROP payload and jumped to by last gadget • Minus Zynamics Google, they do ROPperies • Usually some requirements because it is delivered inline – Null byte free, because it terminates a C-String – rn free, because it often is a delimiter in network protocols – ... Decoder Stub Encoded Shellcode
  • 3. Shellcode Decoder Structure jmp getpc ; jump to GetPC start: ; GetPC 2: ebp = EIP pop ebp push 42 ; load counter = 42 pop ecx push 23 ; load key = 23 pop edx decrypt: xor byte [ebp+ecx], dl ; unxor one byte loop decrypt ; repeat until ecx = 0 jmp payload getpc: call start ; GetPC 1: push EIP to stack payload:
  • 4. GetPC Sequences • call $+5, pop r32 – Push return address for function call onto stack – Use stack access to read back the return address • fnop, fnstenv [esp+0x0c], pop r32 – Use a floating point instruction, address will be stored in floating point control aread – Save floating point control area on stack – Read back the instruction address from stack • Structured Exception Handling – Windows specific, trigger an exception – Get address of exception instruction in exception handler
  • 5. Existing Detection Approaches • Static / Statistical Approaches – e.g. Markov Chains for Bytecode (Alme & Elser, Caro 2009) • Trained with shellcode / non-shellcode data • Measures likelyhood of certain instructions following each other – Can only detect the decoder and therefore tend to be either false positive or false negative prone (weighting, training data, ...) • GetPC Sequences + Backtracking + Emulation (libemu) – Identify possible GetPC sequences in data – Build up tree of possible starting locations by disassembling “backwards” • A problem on its own on the x86 CISC architecture – Software x86 emulation to weed out (the many) false positives
  • 6. libscizzle • Identification of possible GetPC sequences – A little less strict than libemu in terms of triggering combinations • Brute force possible starting location around sequence – Efficient emulation allows this performance wise • Use efficient sandboxed hardware execution for verification – No, this is not virtualization, no VT involved – Yes, it is secure, so we do not get owned (trivially) http://code.mwcollect.org/projects/libscizzle
  • 7. x86 Segmentation vs. Paging Segment Virtual Physical
  • 8. Code Execution / “Emulation” • Disassemble guest code – Stop on any privileged or (potentially) execution flow modifying instruction – This is roughly equivalent to “basic blocks” – Segment register access is considered a privileged instruction ;) • Execute one basic block at a time within the guest segment • Emulate all other instructions – Conditional jumps, calls, ... – Abort analysis on any privileged instructions • Exception: backwards short jumps
  • 9. Evaluation: Performance $ ./libscizzle-test < urandom.bin [*] Filtering / scanning over 32.0 MiB of data took 105 ms. [*] Verifying 700 shellcode candidate offsets... [*] Verification over 32.0 MiB of data took 217 ms. [*] Everything over 32.0 MiB of data took 322 ms. • 99.38 Mib / sec, 795 MiB / sec on my presentation laptop, single core • About 1000x faster than libemu, a lot faster than Markov Chains • This is fast enough to do it inline at GigaBit speed on a commodity server, think IPS • Real world data has usually better properties than purely random data
  • 10. Evaluation: Success Rate • False Positives: none. – If it is detected, it resembles valid shellcode – Random data might resemble valid shellcode but this is a philosophical problem then, highly unlikely. • False Negatives: none so far – Tested on a lot of public shellcodes (tricky Metasploit ones, egghunters) – Used during CTFs for testing libscizzle, detected everything • DefCon, ruCTFe, ... • Manual evasion possible
  • 11. Questions? Thanks for your attention!