SlideShare a Scribd company logo
1 of 75
REVERSE
ENGINEERING
從不想付錢到上生物課
HUNG-
MAO
ME?
0x0nePunch
rafaelchen@protonmail.com
pwn的苦力
CTF中不會飛的菜鳥
在AxxR擔任過白痴滲透.....咳
SD中耍廢了兩年
AIS3中拖了KAIBRO的後腿
以前的黑歷史
逆逆逆逆向行駛
前言
▸ 這一陣子打了不少CTF,真的是受了
不小的打擊呀.......
▸ 首先是HITCON CTF……..
▸ KANXUE的CTF也不是普通虐心
RRRRR
▸ 所以我想說的是........
現在的黑歷史
星巴克到底賺不賺呀?
我想加盟www
SYLLABUS
▸What’s逆向工程?
▸逆向工程可以幫助我們幹什麼壞事?
▸不想付錢
▸上生物課
▸這棵大樹怎麼種?
考慮到普羅大眾不喜
歡組語,今天就不放
實作囉!
Dear Mao Mao
WHAT’S 逆向工程
▸一種反向推導的過程,在這裡我們常指從一個執行檔獲取她
的組合語言更甚至是source code的技術。
▸這門技術對分析檔案非常重要。
▸初階段,你怎麼去逆逆並不重要,因為我們有神器........
▸重要的是,你要看懂神器留給你的東西!
In other hands,
我們的神器可以幫助我們從
exe反匯編得到組合語言。
也可以從組合語言去推測
source code應該長什麼樣
子。
這裡要注意!匯編跟編譯是
完全不同的東西!聽到別人
講錯可以偷笑他一下XDDD
黑人問號?!那裡冒出個.o檔又是啥鬼?鏈結?!
因此,基礎很重要
▸你還記得C/C++ㄇ ?
▸你還記得組合語言ㄇ ?
▸真是個嚴肅又令人難過的話題XD
我相信拉瑪一定會一些了
所以不會都可以去問他!
我們快進入正題好ㄅ好
▸ok呀
逆向工程怎麼分
▸靜態分析
▸動態分析
靜態分析
▸直接逆一波給你看
▸就給你一張論文了,下禮拜報告www
▸推測
▸Run
動態分析
▸直接跑一波給你追
▸我真ㄉ很愛很愛動態分析啦
(常常懶得看paper
▸不是推測,我常拿來驗證
▸但是隨著題目寫多了......南打都 ˋ ˊ
▸Run
逆向工程
我絕不幹壞事
破解軟件?!
▸逆向工程可以拿來分析執行檔
▸拿來看一波軟件的內部架構
▸抓他ㄉ漏洞
▸搞壞它ㄉ流程
打補丁是合法的,破解是非法的,我們可是在打補丁呦!!
咱們先看ㄍ基礎中的基礎
▸如何更改執行檔視窗的名字
▸外表看似簡單的過程
卻是藏著大道理ㄉ
破解姿勢 啟動!
▸跑一波軟件,看看要改的視窗到底長啥樣
▸Ollydbg
▸EP
初學者定位都會從功能函式定位,猜也要猜出main function應
該長什麼樣子
▸還能幹嘛?開始追啊!
每次都這樣搞是要多累啦 = =
當然是騙你的呀! 告訴你一些小撇步
▸上面是
code執行之 “ㄛ~原來你在這裡呦 = =”
▸直接找相關字串
▸直接找API
(關於API一些介紹稍後插播
怕你姿勢散掉www
怎麼打補丁
▸怎麼改字串?
把那個位置的字串改掉
—-> 在修改對應的ASCII時要小心Unicode的字串必須以null
byte做結尾! F9看我開秀
把那個字串的位置改掉
—-> 會有ㄍpush 位置的指令把字串的位置送給messagebox
▸保存到執行檔中
右鍵->保存到執行檔->save
Be careful!!
Keep my size!!
push~~push~~~STACK
CALLING CONVENTION
https://msdn.microsoft.com/zh-tw/library/windows/desktop/ms645505(v=vs.85).aspx
最有名的就是你了!SUBLIME
▸是否覺得sublime的購買視窗很煩ㄋ
沒關係~爸爸買給你
▸ 這邊順便帶大家看看神器
▸ 以及驗證流程
SUBLIME是啥咖
▸0x1: thanks for purchasing
▸0x2: that license key not appear to be valid
▸0x3: that key are no longer valid
▸0x4: Fuck you bad guy!
▸這裡的練習其實跟基礎那ㄍ很像
▸Patching 的工具可以用ollydbg, radare舉凡動態皆可
▸Patching完要嘛重新包成執行檔,要嘛鏡像檔
啊這麼簡單ㄛ?
▸不同的軟件驗證機制也會不同
▸網路驗證
重啟驗證......
SOR啦 ><
▸What’s your trouble snapshot? www
▸註冊機搞起
所以
孩子們!!我們不能亂玩破解呦
應該沒有人聽到這裡臉已經白成一片了吧?
!
很好!沒有~
那我們先休息一下吧
高中的生物課
真的很恐怖
ㄇ
病毒分析
▸前一陣子,玩過病毒分析.......
▸一樣用神器去做分析
不過, 這個生物課的神器真的非常多
▸在這堂生物課,我對逆向工程的認識整個刷新
不好意思!其實我只是想配合生物課,其實我想講的是.........
惡意軟件
Adware
Backdoor
Reverse Shell
Trojan
Botnet
Browser Hijacker
Downloader Malware
Info Stealing Malware
KeyLogger
Launcher Malware
Ransomware
Rootkit
Bootkit
Scareware
Spam Sending Malware
Virus
Worm
惡意軟體分析 HELP?
▸我們可以拿到:
1. Host-based signatures -> 主機特徵碼
2. Network-based signatures -> 網路特徵碼
分析的時候應有的態度:
惡意軟件程式碼可能成千上萬
我們應該在關鍵的點做分析
並且從不同的角度配合不同的工具
對惡意軟體的靜態分析
▸讀paper不見得那麼無趣嘛
▸Hashing,strings,引用函式庫
▸以上,我們透過得到一些他的特徵,去猜測他的行為
HASHING
▸ Md5,sha-1等加密值算是惡意軟件的
一種標誌
▸ 可以透過hash calculator得到
▸ Tools: md5deep, winmd5
▸ Website: VirusTotal
會有一大堆前人留下的分析資料
STRINGS
▸ 可以看到軟件中有哪些字串
字串:ASCII or Unicode
Bbbbbut~ 我們才不需要管他ㄋ
▸ So,我們用它來推測!!!!!
這真的很好玩(我覺得><
CTF (XDDD), demo
▸ 有時,好像沒那麼給力..........ㄇ
Packed and obfuscated
前面提到的殼
-> 解決方式:PEiD
可是PEiD被BOF攻擊過zzzzzz
看圖說故事囉!
OpenProcess
Kernel32.dll: search/write FS
advapi32.dll: with permission(?
system32wupdmgr.exe: It is victim!!
winexec: execute
writefile: write
▸www.malwareanalysisbook.com/updater.exe
分析
▸從VirusTotal我們可以看到他是個downloader
▸從string我們可以看到它跟權限有關。
load數據:load,find,sizeof
寫數據:create,write
寫入系統目錄
網路位置
執行下載文件
這可能是一款鍵盤側錄器.....
▸Kernel32: process, file operation
▸User32:user interface
▸SetWindowsHookEX: !!
▸RegisterHotKey
▸GDI32
▸Advapi: registry -> DNA born with opening computer
那你說的殼怎辦?
▸假如我發現了這個殼,當然會有解殼器囉!
這裡是題外話,聽不懂沒關係,可是觀念很重要!
引用函式庫 (這邊特指動態連
結
▸ 小複習:在程式run時才會load進來
▸ Tool: DependencyWalker
Kernel32.dll:管理記憶體,檔案,硬體~
Ntdll.dll:間接得被稱作kernel32,一種介面~
Advapi32.dll:提供連結高階核心如service manager和registry的權限
User32.dll:使用者介面,使用者回饋
Gdi32.dll:圖形化介面
WSock32.dll/Ws2_32.dll:網路,socket(你們正熟ㄉ
Wininet.dll:能實現如FTP/HTTP/NTP等協定
▸ Window API
查MSDN的官方文件就知道功能
配合strings找到的結果就更有價值 基礎請見下頁.......
HOOK
▸Message Hook
▸Event Driven
▸按下按鍵 v
OS判斷哪裡發生事件
並從OS事件隊列中取出消息
並貼加到應用程式事件隊列 v
應用程式監聽自身隊
列
————————————————————————
-> callback
再告訴你一點八卦
▸Window是向前相容的,API也是
▸suffix API v.s. API ?
▸找不到那個API(差了一兩個字母)有時是因為....
▸API v.s. APIA v.s. APIW ?
Wide character
OK~到這邊我們已經具備看圖說故事的技能囉
這圖片好像要背ㄛPE<—————— —————->Header
IMAGE DOS
HEADER
IMAGE OPTIONAL
HEADER
IMAGE FILE
HEADER
IMAGE SECTION
HEADER
別緊張啦 這東西也不是無中生有WWWW
▸Tools: PEview
我的排泄系統好像很活絡ㄋ
你呢?
讓我喘一下唄
對惡意軟體的動態分析
▸比起靜態分析更能讓我們看到功能性
▸這部分要探討兩個東西
1. 你要怎麼run惡意軟件 2. 怎麼看到惡意軟件的反應
▸Run?
rundll.exe, sandbox
▸ Response?
ProcMon,Process Explorer,Regshot,ApateDNS,INETSim
最後,就是總所皆知的WwwwwiiiireeeeSSShhhaarrrrkkk
RUN?
SANDBOX
▸Sandbox是一個概稱,
Norman,GFI,Anubis,Joe,Threatexpert.....都有提供
▸優點:這種線上服務大都會幫我們產生報告(來交差)
e.g. Signatures
▸缺點:有些惡意軟體需要命令行交互
除此之外,沙箱很重要的一點是->慎選分析時間
RUNDLL.EXE
▸如何執行惡意dll
▸Window下特有的執行平台 ^
▸C:> rundll.exe dll, export argument
C:> rundll.exe dll, install
C:> runnel.exe dll, #3
▸不知道這邊在幹嘛嗎?我們回到peview那頁!
Export argument就像對dll下的命令
注意ordinal這件事
POKEMON?
PROCMON
▸ FileMon:幫助我們捕捉到惡意軟體對檔案系統的更動
▸ RegMon:幫助我們捕捉到惡意軟體對註冊表的更動
▸ 其實我第一次在xp上玩這套軟體時失敗
注意:新版的procmon已不在支援xp!!
PROCESS
EXPLORER
▸ 一樣是一套進程檢視軟體
▸ 左方以樹狀呈現process
▸ 有幾個特異功能 v
▸ 按右鍵!殺個進城!
▸ 顏色呈現狀態!
▸ 看看右邊的verify.....
▸ String comparison
▸ 如圖 >. 快速鎖定!
判定惡意軟件的最快手段......
REGISTRY
▸ 先來看看 註冊表是啥?
▸ 表中記錄著使用者設定檔,電腦安裝哪些程式,所有文件檔案的類型屬性
..........blablablah
▸ 開始 > regedit (試試怎麼樣呀
▸ e.g.
NoSetFolders=dword:1 從開始的設定中移除資料夾
▸ win98時甚至是用RegDone來判定註冊的www
▸ Reference: https://goo.gl/sKgPhJ
註冊表就像電腦的
DNA一樣~
I forget who said that, maybe Mao
Mao!
有句話說得很好
REGSHOT
▸ 為了守護我們的註冊表而存在
幾次比較後的結果會顯示在terminal中
MUTEX LIST
▸進程互斥~
▸MSDN: For example, to prevent 2 threads from writing to
shared memory, each threads waits for ownership of a
mutex object before executing the code that accesses the
memory. After writing to memory, the thread release it.
▸e.g. 避免攻擊第二次
APATEDNS. V.S. INETSIM V.S.
WIRESHARK
▸有些malware會做網路反應
▸ApateDNS能夠作出虛假的DNS回應
port: UDP 53
三個網路介面,不demo,我的電腦會爆掉wwwwwwww
來點新東西
▸反射性PE殼 e.g. Amber
▸https://github.com/EgeBalci/Amber
▸大大地降低檢測率
原本51/66的mimikatz居然...
AMBER
技術細節
▸機器學習,大數據正夯
▸改變惡意軟件傳到系統的方式
ㄧ。 改為無文件執行->payload
二。 模仿PE加載器,減少使用API
聽起來好有趣
我想要種這棵大樹> <
逆向工程到底可以幹嘛
▸不付錢,因為我沒錢
▸乖乖上生物課
▸遊戲安全!!!!!!!!!
▸物聯網安全…..
▸總之想dump偷看人家身體都行啦
▸打CTF wwwwww
基礎真的很重要
▸這不是廢話ㄛ~
▸貼個技能樹給你看看
感覺要背一大堆東西?!不
對,這東西吃的是經驗,只
要熟練,自然會變成你的
菜雞茂茂說:
結論
話說社團的大家來張合照好否呀
~~~親~~~
感謝聆聽
有什麼問題盡量問!!
晚上會拿冠軍別問我好了ZZZ
其實我的電腦中有某台虛擬機
養著一大堆病毒XDXDDXDXDDXDXD

More Related Content

Featured

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 

Featured (20)

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 

逆向工程從不想付錢到上生物課