07 Lecture
07 Lecture
1. Introducing DEP
2. The History of DEP
3. Bypassing DEP with ROP
4. Stack Pivoting
1. Introducing DEP
2. The History of DEP
3. Bypassing DEP with ROP
4. Stack Pivoting
1. Introducing DEP
2. The History of DEP
3. Bypassing DEP with ROP
4. Stack Pivoting
• Gadget
• A sequence of meaningful instructions typically followed
by a return instruction
• Usually multiple gadgets are chained together to
compute malicious actions like shellcode does
• These chains are called ROP Chains
pop ebx
pop eax
ret
ROP chain
exit(0) - ROP chain
xor eax, eax
ret
xor ebx, ebx
ret
inc eax
ret
int 0x80
ROP chain
exit(0) - ROP chain
xor eax, eax
ret
xor ebx, ebx
ret
inc eax
ret
int 0x80
ROP chain
exit(0) - ROP chain
xor eax, eax
ret
xor ebx, ebx
ret
inc eax
ret
int 0x80
ROP chain
exit(0) - ROP chain
xor eax, eax
ret
xor ebx, ebx
ret
inc eax
ret
int 0x80
ROP chain
exit(0) - ROP chain
xor eax, eax
ret
xor ebx, ebx
ret
inc eax
ret
int 0x80
ROP chain
exit(0) - ROP chain
xor eax, eax
ret
xor ebx, ebx
ret
inc eax
ret
int 0x80
ROP chain
exit(0) - ROP chain
xor eax, eax
ret
xor ebx, ebx
ret
inc eax
ret
int 0x80
ROP chain
exit(0) - ROP chain
xor eax, eax
ret
xor ebx, ebx
ret
inc eax
ret
int 0x80
ROP chain
exit(0) - ROP chain
xor eax, eax
ret
xor ebx, ebx
ret
inc eax
ret
int 0x80
exits ...
• With that said, writing ROP can be difficult and you will
usually have to get creative with what gadgets you find
• $ asm
• easy way to get the bytes for gadgets you’re looking for
• $ gdbpeda
• searchmem, find raw bytes in an executing program
• ropsearch, a crappy rop gadget finder
• python
def q(addr):
return struct.pack(“I”, addr)
MBE - 03/10/15 DEP & ROP 41
Lecture Overview
1. Introducing DEP
2. The History of DEP
3. Bypassing DEP with ROP
4. Stack Pivoting
• What can you do when you only have one gadget worth of
execution?
• Answer: Stack Pivoting
• You can always pad your ROP Chains with ROP NOPs which
are simply gadgets that point to ret’s
0x08045430: ret
system()
0xb7e65190: push ebx
0xb7e65191: sub esp, 8
0xb7e65194: mov eax, DWORD PTR
[esp+0x10]
...
0x08045430: ret
system()
0xb7e65190: push ebx
0xb7e65191: sub esp, 8
0xb7e65194: mov eax, DWORD PTR
[esp+0x10]
...
0x08045430: ret
system()
0xb7e65190: push ebx
0xb7e65191: sub esp, 8
0xb7e65194: mov eax, DWORD PTR
[esp+0x10]
...
0x08045430: ret
system()
0xb7e65190: push ebx
0xb7e65191: sub esp, 8
0xb7e65194: mov eax, DWORD PTR
[esp+0x10]
...
system()
0xb7e65190: push ebx
0xb7e65191: sub esp, 8
0xb7e65194: mov eax, DWORD PTR [esp+0x10]
...
0x08045430: ret
system()
0xb7e65190: push ebx
0xb7e65191: sub esp, 8
0xb7e65194: mov eax, DWORD PTR
[esp+0x10]
...
0x08045430: ret
system()
0xb7e65190: push ebx
0xb7e65191: sub esp, 8
0xb7e65194: mov eax, DWORD PTR
[esp+0x10]
...
0x08045430: ret
system()
0xb7e65190: push ebx
0xb7e65191: sub esp, 8
0xb7e65194: mov eax, DWORD PTR
[esp+0x10]
...
0x08045430: ret
system()
0xb7e65190: push ebx
0xb7e65191: sub esp, 8
0xb7e65194: mov eax, DWORD PTR
[esp+0x10]
...
0x08045430: ret
system()
0xb7e65190: push ebx
0xb7e65191: sub esp, 8
0xb7e65194: mov eax, DWORD PTR
[esp+0x10]
...
0x08045430: ret
system()
0xb7e65190: push ebx
0xb7e65191: sub esp, 8
0xb7e65194: mov eax, DWORD PTR
[esp+0x10]
...
0x08045430: ret
system()
0xb7e65190: push ebx
0xb7e65191: sub esp, 8
0xb7e65194: mov eax, DWORD PTR
[esp+0x10]
...
w0w_u_g0t_th3_fl4g_such_h4ck3r
0x08045430:
ret
system()
0xb7e65190: push ebx
0xb7e65191: sub esp, 8
0xb7e65194: mov eax, DWORD PTR
[esp+0x10]
...