明翰恶意软件分析笔记V0.1(持续更新)
文章目錄
- 惡意軟件分析
- 惡意軟件能做什么
- 惡意代碼類型
- 1. 基礎靜態(tài)分析
- 反病毒引擎掃描【工具】
- 惡意代碼的指紋
- `查找字符串【工具】`
- 加殼
- PEiD【工具】
- PE文件格式
- 文件頭 PE header
- `DLL文件結構`
- DLL表
- 分節(jié)(Section)
- `.text(代碼段)`
- .rdata(數(shù)據(jù)段)
- `.data(數(shù)據(jù)段)`
- .idata(數(shù)據(jù)段)
- .edata(數(shù)據(jù)段)
- .rsrc
- .reloc
- 未整理
- PE View【工具】
- PE Studio【工具】
- PE Viewer【工具】
- Resource Hacker【工具】
- 鏈接庫與函數(shù)
- `DLL文件`
- 靜態(tài)、運行時、動態(tài)
- Dependency Walker【工具】
- 導入函數(shù)
- 導出函數(shù)
- 2. 基礎動態(tài)分析
- 沙盒
- 運行惡意代碼
- Process Monitor【工具】
- Process Explorer【工具】
- Regshot
- 模擬網(wǎng)絡
- 網(wǎng)絡監(jiān)聽
- Isolated Network Environments
- Isolated Internet Topology
- Isolated Network
- Router VM
- VMs to provide copies of Internet Serviecs
- 未整理
- 3. 高級靜態(tài)分析
- 機器碼
- 操作碼 opcode
- 機器碼指令的類型
- x86體系結構
- CISC架構
- CPU
- `寄存器`
- `通用寄存器`
- 標志寄存器
- 指令指針
- `指令`
- 操作碼和字節(jié)序
- `操作數(shù)Operand`
- `常見指令`
- `賦值指令`
- 運算指令
- 條件指令
- 分支指令
- 重復指令
- 其他指令
- 匯編語言
- 數(shù)組
- 輸入輸出系統(tǒng)IO
- `內(nèi)存RAM`
- `棧`
- `棧相關指令`
- `函數(shù)調(diào)用`
- 棧的布局
- 反匯編Disassembly
- Ghidra(工具)
- IDA pro(工具)
- 快捷鍵
- `交叉引用xref`
- 分析函數(shù)
- Windows
- `PEB`
- 注冊表Registry
- Windows API
- 句柄Handle
- C語言
- 主函數(shù)
- C語言函數(shù)
- 對抗反匯編
- ShellCode
- 4. 高級動態(tài)分析
- 名詞解釋
- Manifest
- 軟件
- 普通軟件
- `Sysinternals`
- UPX
- 惡意軟件
- WannaCry
- `Cobalt Strike`
- SolarWinds
- Solorigate(Sunburst)
- Teardrop
- RainDrop
- 一些資料
- 一些文件
- exe
- dll
- 常見Windows函數(shù)
- 網(wǎng)絡
- 導出函數(shù)
- 常見CMD命令
- 其他資料
- 基礎靜態(tài)分析
- 基本動態(tài)分析
- 高級靜態(tài)分析
- 反抗反匯編
- `一些常見指令`
- Practical Malware Analysis紙質(zhì)書
惡意軟件分析
易攻難守,
惡意代碼很的很少,
防御代碼寫的多。
有的惡意軟件,刪了之后還會自己重新安裝。
分析惡意軟件可能需要花很長的時間,
可能持續(xù)1個月。
惡意軟件可能有多個部分,不止一個文件,
內(nèi)部文件可以轉(zhuǎn)移。
你可以只能發(fā)現(xiàn)第2部分,卻發(fā)現(xiàn)不了第1部分,
第2部分被清除后,第1部分可能會重新初始化第2部分。
惡意軟件可以嵌入正常軟件組件中,并被傳播。
惡意軟件的組件可以休眠一段時間,不運行,不被發(fā)現(xiàn),
需要被特定的前置所觸發(fā)、引發(fā)。
域名可以隨機生成嗎?怎么弄?
用隨機域名來增加跟蹤的難度,
起一些與正常軟件&文件相似的名字來迷惑用戶,
看日志時容易忽略。
可能會觸發(fā)給一個DNS服務發(fā)請求,
可能得到IP地址和值,拿值后觸發(fā)惡意軟件的其他部分去通過HTTPS和內(nèi)置地址去下載一些東西。
檢查本機的DNS網(wǎng)絡記錄,
如果有定點往1個高仿的域名發(fā)請求,
可能就是中了惡意軟件。
可以把一些惡意文件隱藏在系統(tǒng)文件夾中。
所有的惡意軟件分析的順序和步驟都是一樣的。
不要把惡意軟件放到一個文件夾里,
然后就不管了,
可能會被誤點擊。
把相關文件放進壓縮包并設置一個簡單密碼,
不會被殺毒軟件掃描到以及誤操作。
一些常規(guī)軟件也可以用于攻擊,
這節(jié)課主要是在windows上進行的。
我們會用拿到一些分析軟件,有一些基于Linux的,
有一些是基于Windows的。
Analysing the malware to understand what it does, how it got onto the system, what has it changed (what does it done ), what’s its purpose, who put it there? how it works, how to identify it, and how to defeat or eliminate it
有C,C++,匯編的經(jīng)驗會更好。
匯編需要能看懂和理解基礎框架,
我們有工具,你不需要看的很流利,
惡意軟件的作者可能會做一些加密,迷惑,
阻止我們?nèi)シ治鋈ラ喿x。
還可能偵測到你用特定的軟件,
那惡意軟件就不啟動、退出、或休眠。
最后我們要去看在windows上,
X86、AMD64的機器碼。
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-edWQLpTQ-1630045248945)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p418)]
惡意軟件能做什么
創(chuàng)建、修改、刪除文件,包括刪除自己,
對注冊表的新增或修改,
可以把注冊表里加一些東西,
讓系統(tǒng)再調(diào)用正常文件時也把惡意文件調(diào)用。
自身形態(tài)千變?nèi)f化
計算機病毒可以導致硬件故障,
例如伊朗核設施被入侵后導致離心機出現(xiàn)問題等。
國家之間經(jīng)常進行這種網(wǎng)絡攻擊去癱瘓對方的系統(tǒng)。
病毒可以從一個電腦復制到另一臺電腦,
會刪文件,破壞硬盤等等。
惡意代碼經(jīng)常使用一些合法的dll或程序庫來幫助自己完成目標。
惡意代碼類型
先猜它是什么類型,能做什么,
然后去驗證自己的猜想,可以加速分析過程。
一個惡意軟件會橫跨多個類型,可能會有鍵盤記錄器來收集密碼,同時發(fā)垃圾郵件+自我傳播。
有些病毒是大眾的,
有些病毒是專門為你而做的。
像勒索軟件這樣一般是大眾傳播,盡量多的感染更多的機器,比較簡單,容易被殺毒軟件查殺,
但特制惡意軟件會更復雜,更難搞,殺毒軟件無法幫你防御這種特制的東西。
-
木馬
會偽裝成某個東西的軟件,你從網(wǎng)上下載游戲、或PDF,可能會下載到你不想要的東西。 -
計算機病毒,蠕蟲
Worm or virus,自我復制,感染其他計算機, -
垃圾郵件
Spam-sending malware,在被害者的主機上發(fā)送大量垃圾郵件,賣這個發(fā)送服務可以賺錢。 -
間諜軟件
Information-stealing malware,監(jiān)視用戶的一舉一動,包括記錄各種賬號密碼等信息、尤其是郵箱、銀行卡信用卡等,將這些敏感信息發(fā)送給攻擊者。可以使用:sniffers, password hash grabbers, and keyloggers。 -
勒索軟件
Scareware,恐嚇受害者,并勒索他們購買。也可能是加密你所有的文件讓你支付比特幣,也可能是告訴你你瀏覽了惡意網(wǎng)站讓你支付罰款等。 -
僵尸網(wǎng)絡
Botnet,取自機器人robot的后半部分和網(wǎng)絡network的前半部分。因此,僵尸網(wǎng)絡的表面意思是由機器人組成的網(wǎng)絡。允許控制者訪問系統(tǒng),執(zhí)行命令從控制命令服務器中。 -
下載器
Downloader,只用來下載和安裝其他惡意代碼,獲得系統(tǒng)訪問后,先安裝這個。 -
啟動器
Launcher,用來啟動其他惡意代碼,用一些非傳統(tǒng)手段來保證隱秘性。 -
內(nèi)核套件
Rootkit,嵌入進系統(tǒng),它的功能是在安裝目標上隱藏自身及指定的文件、進程和網(wǎng)絡鏈接等信息,比較多見到的是Rootkit一般都和木馬、后門等其他惡意程序結合使用。持久并毫無察覺地駐留在目標計算機中,對系統(tǒng)進行操縱、并通過隱秘渠道收集數(shù)據(jù)的程序。Rootkit的三要素就是:隱藏、操縱、收集數(shù)據(jù)。“Rootkit”中root術語來自于unix領域。由于unix主機系統(tǒng)管理員賬號為root賬號,該賬號擁有最小的安全限制,完全控制主機并擁有了管理員權限被稱為“root”了這臺電腦。然而能夠“root”一臺主機并不意味著能持續(xù)地控制它,因為管理員完全可能發(fā)現(xiàn)了主機遭受入侵并采取清理措施。因此Rootkit的初始含義就在于“能維持root權限的一套工具”。
簡單地說,Rootkit是一種特殊的惡意軟件,它的功能是在安裝目標上隱藏自身及指定的文件、進程和網(wǎng)絡鏈接等信息,比較多見到的是Rootkit一般都和木馬、后門等其他惡意程序結合使用。Rootkit通過加載特殊的驅(qū)動,修改系統(tǒng)內(nèi)核,進而達到隱藏信息的目的。rootkit介紹Rootkit是一種奇特的程序,它具有隱身功能:無論靜止時(作為文件存在),還是活動時,(作為進程存在),都不會被察覺。換句話說,這種程序可能一直存在于我們的計算機中,但我們卻渾然不知,這一功能正是許多人夢寐以求的——不論是計算機黑客,還是計算機取證人員。黑客可以在入侵后置入Rootkit,秘密地窺探敏感信息,或等待時機,伺機而動;取證人員也可以利用Rootkit實時監(jiān)控嫌疑人員的不法行為,它不僅能搜集證據(jù),還有利于及時采取行動!
Rootkit 的目的在于隱藏自己以及不被其他軟件發(fā)現(xiàn)。它可以通過阻止用戶識別和刪除攻擊者的軟件來達到這個目的。Rootkit 幾乎可以隱藏任何軟件,包括文件服務器、鍵盤記錄器、Botnet 和 Remailer。許多 Rootkit 甚至可以隱藏大型的文件集合并允許攻擊者在您的計算機上保存許多文件,而您無法看到這些文件。
Rootkit攻擊方式多針對類似敏感數(shù)據(jù)剽竊這樣的環(huán)節(jié),那么某企業(yè)或政府組織“中央服務器”一類設備自然是植入Rootkit的首選目標,可這樣的主機設備往往防護嚴密,不能輕易得手。我們知道數(shù)據(jù)并不是靜止的存放在服務器中,它往往在機構的網(wǎng)絡中流動。機構中級別較高的人員常會擁有對這些設備數(shù)據(jù)的讀寫權限,但他們所擁有的個人電腦的防護級別卻通常比中央服務器要低,這就會給剽竊數(shù)據(jù)的黑客以可趁之機——將Rootkit程序植入相關人員的個人電腦,并默默的安家,不時地傳回重要數(shù)據(jù)。 -
后門
Backdoor,后門是指繞過安全控制而獲取對程序或系統(tǒng)訪問權的方法。后門的最主要目的就是方便以后再次秘密進入或者控制系統(tǒng),執(zhí)行命令。主機上的后門來源主要有以下幾種:
攻擊者利用欺騙的手段,通過發(fā)送電子郵件或者文件,并誘使主機的操作員打開或運行藏有木馬程序的郵件或文件,這些木馬程序就會在主機上創(chuàng)建一個后門。攻擊者攻陷一臺主機,獲得其控制權后,在主機上建立后門,比如安裝木馬程序,以便下一次入侵時使用。還有一種后門是軟件開發(fā)過程中引入的。在軟件的開發(fā)階段,程序員常會在軟件內(nèi)創(chuàng)建后門以方便測試或者修改程序中的缺陷,但在軟件發(fā)布時,后門被有意或者無意忽視了,沒有被刪除,那么這個軟件天生就存在后門,安裝該軟件的主機就不可避免的引入了后門。大多數(shù)后門設法躲過日志,大多數(shù)情況下即使入侵者正在使用系統(tǒng)也無法顯示他已在線。后門的引入無疑會形成重大安全風險。知道后門的人,日后可以對系統(tǒng)進行隱蔽的訪問和控制,而且后門也容易被入侵者當成漏洞進行攻擊。
1. 基礎靜態(tài)分析
Basic analysis, just looking at the ‘properties’ of the malware.
分析目標文件的程序指令與結構來確定其功能是什么。
Static Analysis — Looking at the Malware ‘a(chǎn)t Rest’
不會去運行惡意程序,而是把程序放到一個特定的分析軟件中,展示可運行文件的不同部分。
基礎靜態(tài)分析會有報告生成,
給動態(tài)分析留下線索,
理清思路,留下邏輯框架。
通過基本靜態(tài)分析可以簡單快速地判斷出某個文件是否是惡意的,但對待高端的惡意代碼往往無效。
先分析一下正常軟件,再分析一下惡意軟件,
看看有什么顯著的區(qū)別。
反病毒引擎掃描【工具】
VirusTotal,是一個提供免費的可疑文件分析服務的網(wǎng)站。
對一個文件進行多種反病毒引擎掃描是有必要的,因為大家用的特征庫都不一樣。
https://www.virustotal.com
惡意代碼作者可以很輕易的修改自己的代碼,
躲過殺毒軟件的特征引擎掃描。
一些特定的惡意代碼并不在殺毒軟件的特征庫中,沒辦法被察覺到。
一些新型惡意代碼會繞過檢驗。
Imports
看引入了哪些函數(shù)哪些windows的API
可以看到文件的hash
https://www.virustotal.com/gui/file/cc695909a072cb8c1da4dbb69385737465f59c31c12c0253a97516d4cf34105c/details
https://www.virustotal.com/gui/file/be1a5327e00826b456c8e8188e5a45e343d2d730320cc46fdc96347e472e5d12/details
Name顯示曾經(jīng)使用過的名字,
惡意軟件會經(jīng)常改名字,
不要用文件名來判斷,
用文件的哈希值來判斷。
惡意代碼的指紋
使用哈希來識別惡意代碼,
文件哈希:對整個文件的內(nèi)容運行一個算法,
并根據(jù)內(nèi)容生成一個"唯一"的數(shù)字(哈希值),
用來唯一標識文件。
256位長,可能會發(fā)生哈希碰撞,
2個文件的哈希完全一致,比較少見。
可以用這個VirusTotal軟件看哈希,
也可以用系統(tǒng)命令
shasum -a 256 /Users/yangminghan/Downloads/tools/Discord.dmg
MD5與SHA-1算法比較常見。
可以拿這個哈希值當標簽,或與他人共享,幫助他們識別代碼,或在線搜索,看這個惡意代碼是否被破解。
查找字符串【工具】
從文件中的字符串列表,函數(shù),
文件頭信息中發(fā)掘有用信息。
定義在程序中的字符串可以發(fā)現(xiàn)這個軟件主要是負責做什么的,與操作系統(tǒng)的哪部分進行通信,可以猜出這個軟件要做什么,例如調(diào)用了Windows API的XXX鉤子,有可能是用來記錄日志的。
可以通過軟件分析文件里的字符串,
通過字符串來判斷出目標軟件的目的。
Windows同時使用ASCII和Unicode字符,
因此需要尋找這兩種類型的字符串。
可以用程序(名字叫strings)來找到這些字符串。
https://docs.microsoft.com/en-gb/sysinternals/downloads/strings
? Looking at strings can reveal various things about the program
? Filenames
? Registry Keys
? Network addresses
? Error messages (these can be very helpful)
? Names of functions called…
也可能查出一些沒有意義的字符串,忽略就好,
如果一個字符串很短又不是一個單詞的話,
可以忽略掉。
通過錯誤信息就能猜出大概要實現(xiàn)什么功能,
例如郵件錯誤,
就知道作者想發(fā)郵件并且是用windows自己的郵件服務。
在使用strings軟件時,可以設置一些參數(shù)去指定一些功能讓你更方便查找信息,可以把信息導出成文本文件。
strings -n 5 C:\Windows\System32\kbd101a.dll
加殼
惡意代碼作者會經(jīng)常使用加殼、加密、模糊化(可以用其他程序模擬解密過程,詳細看視頻)技術讓他們的代碼更難以檢測或分析,就沒有或很難找到字符串信息。
正常文件的字符串會很多,
加殼后的文件會被壓縮,字符串會很少,
可以證明如果字符串很少的軟件,大部分是惡意的。
加殼代碼一般會包含LoadLibrary(),GetProcAddress()函數(shù),
用來加載和使用其他函數(shù)功能。
作者拿到原始文件后進行壓縮,
導致文件內(nèi)的字符串等信息都不可見,
之后往文件開頭加入一段機器碼,
stub,文件仍然是可執(zhí)行的。
運行程序時,會先運行一小段脫殼代碼用來解壓,
stub里的代碼負責解壓文件,
把文件恢復正常大小后再去運行。
黑客可以對EXE和DLL文件加殼。
PEiD【工具】
使用PEiD去是否文件被加殼,
以及檢查加殼器的類型,編譯器類型。
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-BfGuXidL-1630045248948)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p424)]
識別出加殼器,UPX加殼工具非常流行。
當文件被加殼后,你必須進行脫殼才能繼續(xù)分析。
UPX的脫殼比較簡單,下載upx.sourceforge.net,運行命令:upx -d xxx.exe
e.g. by using UPXPacker https://upx.github.io
注意,很多PEiD插件會在沒有警告的情況下去運行惡意代碼,因此一定要在虛擬機上進行,并且用最新版。
PEiD(PE Identifier)是一款著名的查殼工具,其功能強大,幾乎可以偵測出所有的殼,其數(shù)量已超過470種PE文檔的加殼類型和簽名。
好像只能用于32位文件。
Can use the program PEiD to detect if a file has been packed or not.
You can use PEiD to detect the type of packer or compiler employed to build an application, which makes analyzing the packed file much easier.
Development and support for PEiD has been discontinued since April 2011, but it’s still the best tool available for packer and compiler detection.
In many cases, it will also identify which packer was used to pack the file.
PE文件格式
可移植的可執(zhí)行文件,PE(Portable Executable)文件格式是Windows操作系統(tǒng)上運行的可執(zhí)行文件的總稱,包括可執(zhí)行文件、對象代碼、和DDL所使用的標準格式,
常見的有DLL,EXE,OCX,SYS(驅(qū)動程序),VXD,VDM等。
PE文件格式是一種數(shù)據(jù)結構,包含為Windows操作系統(tǒng)加載器管理可執(zhí)行代碼所必要的信息。
文件格式可以揭示出很多關于程序功能的信息。
PE文件以文件頭開始,其中包括代碼信息,應用程序類型,所需的代碼庫與空間要求,這些信息非常有價值。
可移植性(Portable)是指在任何機器(Intel 386 、MIPS 、Alpha 、Power PC 等)上的Microsoft Windows操作系統(tǒng)都可以使用相同的可執(zhí)行文件格式,指該文件格式的通用性,使得程序加載器以及程序開發(fā)工具不需要針對每一個新的操作系統(tǒng)重寫。
Portable是指對于不同的Windows版本和不同的CPU類型上PE文件的格式是一樣的,當然CPU不一樣了,CPU指令的二進制編碼是不一樣的。
只是文件中各種東西的布局是一樣的。
PE文件使用的是一個平面地址空間,所有代碼和數(shù)據(jù)都合并在一起,組成一個很大的結構。
PE是一種用于可執(zhí)行文件、目標文件和動態(tài)鏈接庫的文件格式,主要使用在32位和64位的Windows操作系統(tǒng)上。
PE文件格式封裝了Windows操作系統(tǒng)加載可執(zhí)行程序代碼時所必需的一些信息。這些信息包括動態(tài)鏈接庫、API導入和導出表、資源管理數(shù)據(jù)和線程局部存儲數(shù)據(jù)。
PE(“portable executable”,可移植的可執(zhí)行文件)文件格式,是微軟WindwosNT,Windows95和Win32子集中的可執(zhí)行的二進制文件的格式;在WindowsNT中,驅(qū)動程序也是這種格式。它還能被應用于各種目標文件和庫文件中。
PE文件格式結構:
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-EN9xQAhG-1630045248951)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p422)]
簡化結構:
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-FVpYfTn0-1630045248953)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p423)]
https://baike.baidu.com/item/PE%E6%A0%BC%E5%BC%8F/9812617?fr=aladdin
https://blog.csdn.net/shitdbg/article/details/49734495
https://blog.csdn.net/qq_30145355/article/details/78859214
https://blog.csdn.net/evileagle/article/details/11693499
https://blog.csdn.net/weixin_34375054/article/details/85566610?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.control
https://blog.csdn.net/rivershan/article/details/15783?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3.control
https://blog.csdn.net/rivershan/article/details/15783?utm_medium=distribute.pc_relevant.none-task-blog-searchFromBaidu-6.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-searchFromBaidu-6.control
https://blog.csdn.net/HackerJLY/article/details/3257207?utm_medium=distribute.pc_relevant.none-task-blog-searchFromBaidu-12.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-searchFromBaidu-12.control
https://wiki.osdev.org/PE
https://blog.csdn.net/lvzhuyiyi4/article/details/8059072?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-2&spm=1001.2101.3001.4242
文件頭 PE header
PE files begin with a header that includes information about the code, the type of application, required library functions, and space requirements. The information in the PE header is of great value to the malware analyst.
https://blog.csdn.net/StriveScript/article/details/6279488
https://www.77169.net/html/271468.html
https://www.sohu.com/a/278839463_653604
https://www.y4f.net/71203.html
https://bbs.pediy.com/thread-21932.htm
https://zhuanlan.zhihu.com/p/31967907
https://www.cnblogs.com/mfm11111/archive/2009/04/18/1438474.html
https://www.cnblogs.com/mfm11111/archive/2009/04/18/1438848.html
https://www.4hou.com/posts/5QnB
https://www.cnblogs.com/qintangtao/archive/2013/01/11/2857179.html
https://my.oschina.net/u/4293620/blog/3809007
https://www.hetianlab.com/expc.do?ec=ECID172.19.104.182015051313294800001
PE文件頭比只查看導入函數(shù)提供更多的有價值的信息,
PE文件格式包含一個PE文件頭,
后面跟著一系列的分節(jié),
文件頭中包含了有關文件本身的元數(shù)據(jù),
之后每個分節(jié)都包含著有用信息。
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-5SNmBTL0-1630045248954)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p433)]
Dos MZ Head與Dos stub和稱Dos文件頭,
PE文件的第一個字節(jié)起始于MS-Dos頭部,
被稱作IMAGE_DOS_HEADER,
緊隨Dos stub的是PE文件頭(PE header),
PE Header是PE相關結構NT映像頭(IMAGE_NT_HEADERS)的簡稱,
其中包含了許多PE裝載器用到的重要字段。
PE頭表示為結構體IMAGE_NT_HEADERS,
其中IMAGE_NT_HEADERS中包含著另外兩個結構體:
1.IMAGE_FILE_HEADER,包含一些底層的硬件物理信息,不是特別常用。
2.IMAGE_OPTIONAL_HEADER32,包含了關于PE文件邏輯分布的信息,這個結構體是PE中最大的結構體,其中比較重要的幾項:
PE裝載器準備運行的PE文件的第一個指令的RVA。
若您要改變整個執(zhí)行的流程,
可以將該值指定到新的RVA,
這樣新RVA處的指令首先被執(zhí)行。
代碼段的開始地址,表示程序中的Code Section從何開始。Code Section通常在Data Section之前,在PE表頭之后。微軟鏈接器所產(chǎn)生的exes中,此值通常為0x1000。Borland 的TLINK32則通常指定此值為0x10000。因為預設情況下TLINK時以64k為對齊粒度的,而MS用的是4k。A pointer to the beginning of the code section, relative to the image base.
在X86系統(tǒng)中,
每個內(nèi)存頁的大小是4KB,即0X1000個字節(jié)。
一些基礎:
內(nèi)存中使用VA(Virtual Address,虛擬地址)來表示位置。文件加載到內(nèi)存時,情況就會發(fā)生變化(節(jié)區(qū)大小、位置等)。
在運行一個可執(zhí)行文件時,將它裝載入內(nèi)存中,主要就是將一個PE文件的某一部分映射到地址空間中。這樣,PE文件的數(shù)據(jù)結構在磁盤和內(nèi)存中就是一樣的了(windows加載器遍歷PE文件并決定文件的哪一部分被映射)。
文件偏移地址(或物理地址):當PE文件存儲在磁盤上時,各個數(shù)據(jù)的地址。一般我們用16進制編輯工具打開后顯示的就是。
虛擬地址:由于Windows運行在保護模式下,所以程序訪問存儲器所使用的邏輯地址就是虛擬地址,簡稱VA,又稱為內(nèi)存偏移地址。
虛擬地址為什么一定要轉(zhuǎn)化為物理地址的原因:
計算機中的物理內(nèi)存是字節(jié)的線性數(shù)組,每字節(jié)具有一個唯一的物理地址;程序中的地址是由兩部分構成的邏輯地址。這種邏輯地址并不能直接用于訪問物理內(nèi)存,而需要使用地址變換機制將它變換或映射到物理內(nèi)存地址上。內(nèi)存管理機制即用于將這種邏輯地址轉(zhuǎn)換成物理內(nèi)存地址。那么我們要修改時,就需要將物理地址映射到虛擬地址了。
基地址,程序運行時,被映射到程序指定內(nèi)存處。內(nèi)存處的起始地址就是基地址。
相對虛擬地址(RVA):是指相對于基地址的偏移量。RVA 代表相對虛擬地址。簡言之,RVA是虛擬空間中到參考點的一段距離。我打賭您肯定熟悉文件偏移量: RVA就是類似文件偏移量的東西。當然它是相對虛擬空間里的一個地址,而不是文件頭部。
RELATIVE VIRTUAL ADDRESS
? This works, but slightly complicated by the fact that the addresses are all
stored in memory as Relative Virtual Addresses
? Need to add the address of the base of the DLL onto them before using
them
? To both the name pointers and the address of the function
? If disassembling shell code, keep an eye out for techniques like this…
為什么PE文件格式要用到RVA呢? 這是為了減少PE裝載器的負擔。因為每個模塊多有可能被重載到任何虛擬地址空間,如果讓PE裝載器修正每個重定位項,這肯定是個夢魘。相反,如果所有重定位項都使用RVA,那么PE裝載器就不必操心那些東西了: 它只要將整個模塊重定位到新的起始VA。這就象相對路徑和絕對路徑的概念: RVA類似相對路徑,VA就象絕對路徑。
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-AIrGUFsW-1630045248955)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p484)]
ImageBase:
是程序被載入到內(nèi)存的地址
The preferred address of the first byte of the image when it is loaded in memory. This value is a multiple of 64K bytes. The default value for DLLs is 0x10000000. The default value for applications is 0x00400000, except on Windows CE where it is 0x00010000.
ImageBase包含了什么?
Where the program has been compiled to be loaded to. Contains the address to load the program.
什么是Image?
映像,加載到內(nèi)存中的PE文件。
ImageBase是映像的基地址,這個基地址是建議,對于DLL來說,如果無法加載到這個地址,系統(tǒng)會自動為其選擇地址。
Assuming the program is not relocated when loaded, where will the program start executing code?
The memory location where the first instruction will be placed can be found using the following formula: EP (Memory) = AddressOfEntryPoint + ImageBase
A說法
基地址,PE文件的優(yōu)先裝載地址。比如,如果該值是400000h,PE裝載器將嘗試把文件裝到虛擬地址空間的400000h處。"優(yōu)先"表示若該地址區(qū)域已被其他模塊占用,那PE裝載器會選用其他空閑地址。
B說法
ImageBase是程序在虛擬空間中被裝載的位置,exe加載到內(nèi)存的時候,所在的地址???
C說法
ImageBase是程序載入內(nèi)存的初始地址,也就就整個PE文件的最前面入口地址,通過這個地址可以定位到PE的任何結構數(shù)據(jù)???
D說法
指出文件的優(yōu)先裝入地址。也就是說當文件被執(zhí)行時,如果可能的話,Windows優(yōu)先將文件裝入到由ImageBase字段指定的地址中,只有指定的地址已 經(jīng)被模塊使用時,文件才被裝入到地址中。鏈接器產(chǎn)生可執(zhí)行文件的時候?qū)@個地址來生成機器碼,所以當文件被裝入這個地址時不需要進行重定位操 作,裝入的速度最快,如果文件被裝載到**地址的話,將不得不進行重定位操作,這樣就要慢一點。
對于EXE文件來說,由于每個文件總是使用獨立的 虛擬地址空間,優(yōu)先裝入地址不可能被模塊占據(jù),所以EXE總是能夠按照這個地址裝入,這也意味著EXE文件不再需要重定位信息。對于DLL文件來說, 由于多個DLL文件全部使用宿主EXE文件的地址空間,不能保證優(yōu)先裝入地址沒有被的DLL使用,所以DLL文件中必須包含重定位信息以防萬一。因 此,在前面介紹的 IMAGE_FILE_HEADER 結構的 Characteristics 字段中,DLL 文件對應的 IMAGE_FILE_RELOCS_STRIPPED 位總是為0,而EXE文件的這個標志位總是為1。
在鏈接的時候,可以通過對link.exe指定/base:address選項來自定義優(yōu)先裝入地址,如果不指定這個選項的話,一般EXE文件的默認優(yōu)先裝入地址被定為00400000h,而DLL文件的默認優(yōu)先裝入地址被定為10000000h。
E說法
提供整個二進制文件包括所有頭的優(yōu)先(線性)載入地址(‘ImageBase’,“映象文件基址”)。這是一個文件已被鏈接器重定位后的地址(總是64KB的倍數(shù))。如果二進制文件事實上能被載入這個地址,那么加載器就不用再重定位文件了,也就節(jié)省了一些載入時間。
優(yōu)先載入地址在另一個映象文件已被先載入那個地址(“地址沖突”,在當你載入好幾個全部按照鏈接器的缺省值重定位的DLL文件時經(jīng)常發(fā)生)時,或者該內(nèi)存已被用于其它目的(堆棧、malloc()、未初始化數(shù)據(jù)、或不管是什么)時,就不能用了。在這些情況下,映象文件必須被載人其它的地址,并且需要重定位(參見下面的“重定位目錄”)。如果是一個DLL文件,這么做還會產(chǎn)生其它問題,因為此時的“綁定輸入”已不再有效,所以使用DLL的二進制文件必須被修正----參見下面的“輸入目錄”一節(jié)。
F說法
當PE文件被裝載到內(nèi)存空間中去時,ImageBase指出文件的優(yōu)先裝入地址。執(zhí)行PE文件時,PE裝載器先創(chuàng)建進程,再將文件載入內(nèi)存,然后把EIP寄存器的值設置為ImageBase + AddressOfEntryPoint。
AddressOfEntryPoint(RVA)
程序入口,程序最先被執(zhí)行的代碼起始地址,文件被執(zhí)行時的入口地址,如果在一個可執(zhí)行文件上附加了一段代碼并想讓這段代碼首先被執(zhí)行,那么只需要將這個入口地址指向附加的代碼就可以。
對于exe這個地址可以理解為WinMain,對于dll個地址可以理解為DllMain,如果是驅(qū)動程序,可以理解為DriverEntry。當然,實際上入口點并非是WinMain,DllMain和DriverEntry,在這些函數(shù)之前還有一系列初始化要完成。
程序在內(nèi)存中展開的真正入口:
標準PE頭后0x10 AddressOfEntryPoint + 標準PE頭后0x1C ImageBase
DLL文件結構
? Once we’ve found the address where the DLL has been loaded
? Can then parse the PE file format (in memory) to find the address of
any functions of interest
? PE has several tables we need to consult
? Main table of interest is the Export Address Table
? Contains the address of each function
? But it is indexed by ordinals — need to find the ordinal for the function of interest
Ordinal is just a number
Export table might not necessarily start at ordinal 1 — need to consult the base ordinal details
https://docs.microsoft.com/en-us/windows/win32/debug/pe-format
DLL表
? Another table is the Export Name Pointer Table — list of the names of functions
? Can search this to find the function name (manually!)
? But the index into this table is not the ordinal
? Fortunately, there is another table we can use — Export Ordinal Table
? Can use the index of the name in the Export Name Pointer Table
? To find the ordinal in the Export Ordinal Table
? Then use that ordinal in the Export Address Table to find the address
Remember you don’t know where strcmp is so you’ll need to provide your own…
Can be done quickly by reading longwords and comparing with constants in m/code
e.g. the constant 0x50746547 would match the first four bytes of GetProcAddress
This section records the exports of the image (yes, EXEs can export things). This takes the form of:
The export address table: an array of length N holding the addresses of the exported functions/data (the addresses are stored relative to the image base). Indexes into this table are called ordinals.
The export name pointer table: an array of length M holding pointers to strings that represent the name of an export. This array is lexically ordered by name, to allow binary searches for a given export.
The export ordinal table: a parallel array of length M holding the ordinal of the corresponding name in the export name pointer table.
http://blog.omega-prime.co.uk/2011/07/04/everything-you-never-wanted-to-know-about-dlls/
A piece of code is being delivered by an exploit (such as a buffer overflow) to a remote machine, explain how the exploit might make use of the Portable Exe- cutable header structure of DLLs to call Windows API functions.
Code will need to find the address of Windows API manually by walking the PE file format
? Can find the start of a DLL, by using the PEB to find the DLLs.
? Once the correct DLL has been found, we can use the PE file format to find
? Export Name Pointer Table to find the name of function
? Map offset of the function in name in the Export name table to ordinal in Export ordinal Table
? Then use the ordinal to find address of function in the Export Address Table
? Call the address to execute function
訪問DLL有2種形式:
in the standard fashion (using LoadLibrary)
manually via the Process Environment Block
分節(jié)(Section)
PE文件格式把可執(zhí)行文件分成若干個數(shù)據(jù)節(jié)(section ),不同的資源被存放在不同的節(jié)中。
一個典型的PE文件中包含的節(jié)如下。
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-5b3wemqf-1630045248956)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p428)]
.text(代碼段)
一般來說,這是唯一可以讓CPU執(zhí)行指令的section,
也是唯一包含代碼的section。
由編譯器產(chǎn)生,存放著二進制的機器代碼,
也是我們反匯編和調(diào)試的對象。
默認的代碼區(qū)塊,它的內(nèi)容全是指令代碼,
鏈接器把所有目標文件的text塊連接成一個大的.text塊,
使用Borland C++,
編譯器產(chǎn)生的代碼存放在CODE的區(qū)域里。
可讀、可執(zhí)行
.rdata(數(shù)據(jù)段)
通常包含導入導出函數(shù)信息,
與Dependency Walker和PEview所獲得的信息是相同的,
還可以存儲程序所使用的其他只讀數(shù)據(jù)。
資源數(shù)據(jù)段,程序用到什么資源數(shù)據(jù)都在這里(包括自己打包的,還有開發(fā)工具打包的)
默認只讀數(shù)據(jù)區(qū)塊,但程序中很少用到該塊中的數(shù)據(jù),一般兩種情況用到,一是MS 的鏈接器產(chǎn)生EXE文件中用于存放調(diào)試目錄,二是用于存放說明字符串,如果程序的DEF文件中指定了DESCRIPTION,字符串就會出現(xiàn)在rdata中
.data(數(shù)據(jù)段)
包含了程序的全局數(shù)據(jù),本地數(shù)據(jù)并不存儲在這里。
存放初始化的數(shù)據(jù)塊,
如宏定義、全局變量、全局常量、靜態(tài)變量等。
默認的讀/寫數(shù)據(jù)塊
有些文件中還會包含.idata和.edata節(jié),
來存儲導入導出信息。
.idata(數(shù)據(jù)段)
.idata包含可執(zhí)行文件所使用的外來的DLL函數(shù)、文件、數(shù)據(jù)等信息,即輸入表。
導入函數(shù)的代碼段,存放外部函數(shù)地址。(當然還有 edata,導出函數(shù)代碼段,但不常用)
將.idata區(qū)塊合并成另一個區(qū)塊已成為一種慣例,
典型的是.rdata區(qū)塊,默認的,
鏈接器只在創(chuàng)建一個Release模式的可執(zhí)行文件時才能將idata合并到另外一個區(qū)塊中。
.edata(數(shù)據(jù)段)
輸出表,當創(chuàng)建一個輸出API或數(shù)據(jù)的可執(zhí)行文件時,
連接器會創(chuàng)建一個.EXP文件,這個.EXP文件包含一個.edata區(qū)塊,其會被加載到可執(zhí)行文件中,
經(jīng)常被合并到.text或.rdata區(qū)塊中
.rsrc
存放可執(zhí)行文件所使用的的資源,這些內(nèi)容并不是可執(zhí)行的,比如圖標、圖片、菜單項、字符串等。
字符串可以存儲在.rsrc,或中程序中。
在.rsrc中經(jīng)常存儲的字符串是為了提供多語言支持的。
包括模塊的全部資源,這個區(qū)塊是只讀的,
無論如何不應該把它命名為.rsrc以外的名字,
也不能合并到其他的區(qū)塊里。
.reloc
可執(zhí)行文件的基址重定位,基址重定位一般僅Dll需要的
Contains information for relocation of library files
未整理
.bss
未初始化的數(shù)據(jù),很少在用,取而代之的是執(zhí)行文件的.data區(qū)塊的的VirtualSize被擴展大的空間里用來裝未初始化的數(shù)據(jù).
.crt
用于C++ 運行時(CRT)所添加的數(shù)據(jù)
.tls
TLS的意思是線程局部存儲器,用于支持通過_declspec(thread)聲明的線程局部存儲變量的數(shù)據(jù),這包括數(shù)據(jù)的初始化值,也包括運行時所需要的額外變量
.sdata
相對于全局指針的可被定位的 短的讀寫數(shù)據(jù)
.pdata
異常表,包含CPU特定的IAMGE_RUNTIME_FUNTION_ENTRY結構數(shù)組,DataDirectory中的IMAGE_DIRECTORY_ENTRY_EXCEPTION指向它.
.didat
延遲裝入輸入數(shù)據(jù),在非Release模式下可以找到
PE View【工具】
使用PE View可以查看PE文件格式中的PE頭和section信息。
Windows使用PE格式來存儲文件和程序,
通過PE View,可以看到程序的文件結構,
都是人類能看得懂的東西,而不是一堆16進制數(shù)據(jù)。
里面的信息是可以被篡改的,不一定100%正確。
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-ooXrFCfL-1630045248958)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p429)]
IMAGE_NT_HEADERS(可以看Section數(shù)量,后面可以看每個section的詳細內(nèi)容,時間,64還是32位文件等)
1顯示PE文件頭信息,
前面的IMAGE_DOS_HEADER與MS-DOS-Stub Program沒有價值,
不用看。Signature不用看。
2顯示關于文件的基本信息。
3顯示編譯時間,這里可以作假,很老的編譯時間意味著古老的攻擊,也許殺毒軟件可以cover的住。但Delphi程序的編譯時間統(tǒng)一為1992-6-19。
IMAGE_OPTIONAL_HEADER(可選映像頭)包含:
程序執(zhí)行入口,AddressOfEntryPoint。
指出文件被執(zhí)行時的16進制的入口地址,
這是一個RVA地址,
如果在一個可執(zhí)行文件上附加了一段代碼并想讓這段代碼首先被執(zhí)行,
那么只需要將這個入口地址指向附加的代碼就可以了。
Subsystem,子系統(tǒng),指出是控制臺程序是IMAGE_SUBSYSTEM_WINDOWS_CUI還是圖形界面程序IMAGE_SUBSYSTEM_WINDOWS_GUI。
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-Ac6t8Xid-1630045248961)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p430)]
IMAGE_SECTION_HEADER,
節(jié)名稱發(fā)生變化是可以的,理論上都是一致的。
1的虛擬大小表示在加載過程中需要分配多少空間給1個section。
2的原始數(shù)據(jù)大小表示在磁盤上這個section的大小規(guī)模,
這2個值應該是相等,表示硬盤與內(nèi)存相同,
有小差別是正常。
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-O0NzLUEs-1630045248963)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p431)]
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-Uo39UpZu-1630045248964)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p432)]
查看SECTION .rdata,[IMPORT/EXPORT]Address Table表示導入導出函數(shù)列表
PE Studio【工具】
非教材
PeStudio是一款驗證應用程序的免費工具,
適用于開發(fā)者、測試員和維護、分析人員。
列出某一個應用程序使用的所有DLL庫,字符串等信息。
驗證應用程序是否過時,并存在潛在安全風險。
可以直觀顯示被標記為黑名單的導入導出函數(shù)。
PE Viewer【工具】
非教材
Resource Hacker【工具】
老師沒提過,如果有用到需要再看那本書,在1.8.2章節(jié)
用于分析.rsrc節(jié),資源相關。
鏈接庫與函數(shù)
關于可執(zhí)行文件,
我們能收集到的最有用的信息之一是它所導入的函數(shù)列表。
在PE文件頭中找到的信息可以看到鏈接了哪些庫。
DLL文件
一般來說,DLL文件沒法自已獨立運行,
需要被EXE程序調(diào)用。
DLL(Dynamic Link Library)文件,又叫動態(tài)鏈接庫文件。
靜態(tài)庫和動態(tài)庫的區(qū)別是:
靜態(tài)庫在程序的鏈接階段被復制到了程序中;
動態(tài)庫在鏈接階段沒有被復制到程序中,
而是程序在運行時由系統(tǒng)動態(tài)加載到內(nèi)存中供程序調(diào)用。
使用動態(tài)庫的優(yōu)點是系統(tǒng)只需載入一次動態(tài)庫,
不同的程序可以得到內(nèi)存中相同的動態(tài)庫的副本,
因此節(jié)省了很多內(nèi)存,
而且使用動態(tài)庫也便于模塊化更新程序。
DLL和EXE文件一樣,
其中包含的也是程序的二進制執(zhí)行代碼和程序所需的資源(比如圖標、對話框、字符串等),可是為什么要把代碼放在DLL里面,而不是做成EXE呢?
其實DLL中的代碼是以API函數(shù)形式出現(xiàn)的,通俗地說,DLL中包含的程序代碼都被做成了一個個小模塊,
應用程序通過按下所需DLL中特定的按鈕,
來調(diào)用DLL中這個按鈕所代表的功能。
在使用“記事本”等程序時,如果要保存文件或打開文件,就會彈出通用文件對話框,讓我們選擇文件位置。
這就是調(diào)用了系統(tǒng)底層DLL中的通用對話框界面。
Windows系統(tǒng)使用DLL文件來實現(xiàn)操作系統(tǒng)的[方法/函數(shù)/功能],在DLL文件中可以調(diào)用Windows的API供我們編程使用,Win32 API,64等。
當程序加載時,你的pre-code連接程序與功能,
通過PE文件,我們可以看到哪些函數(shù)被引用,
庫文件一般指計算機上的一類文件,分兩種,
一種是靜態(tài)庫,另一種是動態(tài)庫即
在Windows中,許多應用程序并不是一個完整的可執(zhí)行文件,它們被分割成一些相對獨立的動態(tài)鏈接庫,即DLL文件,放置于系統(tǒng)中。當我們執(zhí)行某一個程序時,相應的DLL文件就會被調(diào)用。一個應用程序可使用多個DLL文件,一個DLL文件也可能被不同的應用程序使用,這樣的DLL文件被稱為共享DLL文件。
可以簡單的把庫文件看成一種代碼倉庫,它提供給使用者一些可以直接拿來用的變量、函數(shù)或類。在庫文件的發(fā)展史上經(jīng)歷了“無庫-靜態(tài)鏈接庫-動態(tài)鏈接庫”的時代。靜態(tài)鏈接庫與動態(tài)鏈接庫都是共享代碼的方式,如果采用靜態(tài)鏈接庫,庫中的指令都被直接包含在最終生成的可執(zhí)行文件中了。但是若使用動態(tài)鏈接庫,該庫文件則不必被包含在最終可執(zhí)行文件中,可執(zhí)行文件執(zhí)行時可以“動態(tài)”地引用和卸載這個與可執(zhí)行文件獨立的庫文件。
①擴展應用程序
由于DLL能被應用程序動態(tài)載入內(nèi)存。所以,應用程序可以在需要時才將DLL載入到內(nèi)存中,這讓程序的可維護性變得很高。比如QQ的視頻功能需要升級,那么負責編寫QQ的程序員不必將QQ所有代碼都重寫,只需將視頻功能相關的DLL文件重寫即可。
②便于程序員合作
這個和我們最終用戶關系不大,僅供了解。我們都知道編程工具有很多,比如VB、VC、Delphi等,如果好幾個人合作來編寫一個大的程序,那么可能有的人用VB,有的人用VC,每人負責的部分所使用的編程語言都不同,究竟放在哪個編譯器中進行編譯呢?這就好比一群來自各個國家的人在共同編寫一篇文章,如果他們所使用的語言都不同,寫出來的文章怎么可能湊到一起呢?而有了DLL后,可以讓VC程序員寫一個DLL,然后VB程序員在程序中調(diào)用,無需為怎么將它們都編譯為一個單獨的EXE而發(fā)愁了。
③節(jié)省內(nèi)存
如果多個應用程序調(diào)用的是同一個動態(tài)鏈接庫,那么這個DLL文件不會被重復多次裝入內(nèi)存中,而是由這些應用程序共享同一個已載入內(nèi)存的DLL。就好比一個辦公室中,很少會為每一個員工配置一臺飲水機的,而是在一個公共位置放上一個飲水機,所有需要喝水的職員都可以共用這臺飲水機,降低了成本又節(jié)約了空間。
④共享程序資源
包括剛才提到過的通用文件對話框在內(nèi),DLL文件提供了應用程序間共享資源的可能。資源可以是程序?qū)υ捒颉⒆址D標,或者聲音文件等。
⑤解決應用程序本地化問題
在下載了某個程序的漢化包后,打開漢化說明,經(jīng)常可以看到用下載包中的DLL文件覆蓋掉程序原來的DLL,漢化就完成了。這些程序都是將執(zhí)行代碼和應用程序界面分開編寫了,所以漢化者只需簡單地將其中和程序界面相關的DLL漢化并發(fā)布即可。
靜態(tài)、運行時、動態(tài)
代碼庫可以被靜態(tài),運行時,動態(tài)鏈接。
靜態(tài)鏈接:所有當前代碼庫中的代碼都會被復制到可執(zhí)行程序中,這會增大可執(zhí)行程序的體積。難以區(qū)分是否被靜態(tài)鏈接過,因為PE文件頭沒有顯示相關信息。
運行時鏈接:在惡意代碼中很常用,只有在需要使用函數(shù)時,才鏈接到庫。
動態(tài)鏈接:程序啟動時鏈接。
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-rJVzoaJw-1630045248970)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p425)]
Dependency Walker【工具】
使用Dependency Walker查看可執(zhí)行文件的動態(tài)鏈接函數(shù)。
可以查看exe程序使用的DLL及函數(shù),
DLL文件里有多少個函數(shù),
以及EXE調(diào)用了哪個DLL的哪些函數(shù)?
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-xlie3JL9-1630045248971)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p426)]
2顯示了程序?qū)氲腄LL列表,點擊2后,
在3處顯示導入的函數(shù)列表。
4顯示這個DLL中所有可被導入的函數(shù),對我們不是特別有用,3,4的列中有序號,可執(zhí)行文件可以根據(jù)序號,而不是根據(jù)名字來導入函數(shù)。
當根據(jù)序號來導入函數(shù)時,
函數(shù)名字不會在可執(zhí)行文件中顯示,
對于我們分析來說會變難。
可以在4中通過查找序號,
來找出到底導入的是哪個函數(shù)。
5、6顯示運行程序時裝載的DLL版本額外信息和報告的錯誤。
會展示給我們程序用到所有的函數(shù),
以及這些函數(shù)在哪里被引用。
有一些函數(shù)是直接調(diào)用,有一些函數(shù)是間接調(diào)用。
Dependency Walker是Microsoft Visual C++ 中提供的非常有用的PE模塊依賴性分析工具。
主要功能如下:
查看 PE 模塊的導入和導出函數(shù)。
動態(tài)剖析 PE 模塊的模塊依賴性。
解析 C++ 函數(shù)名稱。
官方下載:http://www.dependencywalker.com/
在程序左側的樹狀欄中就列出了這個DLL使用了哪些其他DLL的功能函數(shù)(原來DLL中還可以調(diào)用其他DLLO),
而右側的兩個分欄列表分別顯示了函數(shù)輸入及輸出表,
函數(shù)輸出表即為該DLL提供給其他EXE或者DLL調(diào)用的函數(shù)的總列表。
函數(shù)輸出表的Function欄中即為輸出函數(shù)的名稱(見圖1),在QQZip.dll中共發(fā)現(xiàn)了2個函數(shù):Unzip、Zip。因此可以判斷該DLL在QQ程序中負責壓縮和解壓縮的任務。
https://www.pianshen.com/article/2385335/
導入函數(shù)
導入函數(shù)如果比較多的話,代表沒有被加殼,
但只有少數(shù)的導入函數(shù)對我們來說是有意義的。
WINDOWS IMPORTS
? The imported functions from the Win32 API can tell us a lot about what the program potentially does
? Can use several tools to list the imports in a PE file
? At the very least, they should pose some questions to direct further analysis
? As you become more proficient, you will start to recognise various imports and the potential behaviour they indicate
? But at the start you’ll end up having to look up the functions in the documentation (see MSDN)
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-lXk5lHPL-1630045248974)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p421)]
Example taken from Practical Malware Analysis, p19
Explain the W/A suffix… whether the function takes ASCII or Unicode chars
Demo where to find documentation
https://docs.microsoft.com/en-us/windows/win32/api/
看完了imports里的東西,要問自己一些問題:
QUESTIONS ARISING
? It’s searching for files — which files and why?
? It’s creating/manipulating files — which files and why?
? It’s hooking into Windows — what for?
? It has a GUI — how do we activate it, what options does it give?
? Potentially via a hot key (see RegisterHotKey()) — which key combo?
? Does the .rsrc section contain something interesting?
導出函數(shù)
與導入函數(shù)類似,DLL與EXE的導出函數(shù),是用來與其他程序或代碼進行交互時所使用的。通常,1個DLL會實現(xiàn)若干個函數(shù),然后將他們導出,使得別的程序可以導入并使用這些函數(shù)。
PE文件中包含一個文件中導出了哪些函數(shù)的信息。因為DLL文件本身就是實現(xiàn)一些導出函數(shù)然后被exe可執(zhí)行文件使用的,因此導出函數(shù)在DLL文件中是最常見的,而在exe文件中卻很少見。
將一些函數(shù)導出來讓其他人用,在PE文件中可以看到這些信息,詳略。
2. 基礎動態(tài)分析
Dynamic Analysis — Looking at the malware ‘a(chǎn)s it runs’
在文件運行時去用工具分析,
觀察與監(jiān)控系統(tǒng)中的行為,
它都干了什么,通過工具看到去對比靜態(tài)時的字符串,有很大的差異。
惡意軟件作者發(fā)現(xiàn)有其他特殊的軟件在運行,
則就什么都不做,因此我們需要使用crabber?
但對待高端的惡意代碼往往無效。
先靜態(tài),后動態(tài),在靜態(tài)走到不能走之后再做動態(tài)分析。
沙盒
簡單但粗糙
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-wAduBV2p-1630045248977)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p445)]
模擬一個虛擬的環(huán)境,沙盒可以自動做上面的事情,
還可以生成報告,
Cuckoo Sandbox
Hybrid analysis,幫你運行惡意文件,并生成報告。
https://www.hybrid-analysis.com/
Including doing some static analysis
沙盒有一些缺點,詳略
運行惡意代碼
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-SLe2R3lU-1630045248978)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p438)]
cl arguments should be visible as strings in the static analysis
通常可以通過命令行輸入命令或雙擊EXE文件去運行文件,
DLL有點特殊,可以用rundll32.exe進行運行。
C:>rundll32.exe DLLname, Export arguments
Export arguments必須是DLL導出函數(shù)列表中的函數(shù)名或序號(例如#1,#5)。
Process Monitor【工具】
進程監(jiān)視器,監(jiān)控所有運行的進程、線程、注冊表、文件系統(tǒng)、網(wǎng)絡、系統(tǒng)調(diào)用等等。
展示一個被監(jiān)視的事件列表,
告訴你相關的程序在系統(tǒng)中做了什么,
調(diào)用哪個windows的API。
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-0omycD5a-1630045248979)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p453)]
點capture,取消或開啟監(jiān)控,一般幾分鐘就可以。
所有的系統(tǒng)調(diào)用都會被捕獲,
時間長了會導致內(nèi)存不足,虛擬機崩潰。
在進行監(jiān)控分析之前,
先暫停捕獲,File->Capture Events
先clear一下屏幕,Edit->Clear Display
可以使用filter來進行過濾,不然內(nèi)容太多了,
并不能阻止消耗內(nèi)存。
可以換背景圖來嘗試變化。
需要有耐心,可能會有很多事件。
不應該被記錄網(wǎng)絡行為,因為微軟的兼容性原因。
Process Explorer【工具】
微軟的免費產(chǎn)品,有點像高級的windows任務管理器,
監(jiān)視系統(tǒng)上所有活躍的進程、被進程載入的DLL、
各種進程屬性和整體系統(tǒng)信息。
進程之間是有層級樹狀結構的,進程,子進程。
視圖每秒更新一次,默認情況下,服務是粉色,
進程是藍色,新進程是綠色,被終止進程是紅色。
綠色與紅色是臨時的,
雙擊xxx.exe,可以看其他詳細信息。
可以在Strings模塊上比較字符串,
可以選擇Image在硬盤,Memory在內(nèi)存,
如果有很大不同,代表發(fā)生了進程替換。
點擊verify按鈕,檢查是否有被修改過,
是否具有微軟的簽名認證,
惡意代碼經(jīng)常替換windows認證文件并試圖隱藏,
這個功能可能會失效,詳略。
惡意軟件可能會在運行時進行偽裝,
先打開一個無害的應用例如Chrome,
之后在內(nèi)存中替換成惡意代碼,
外表上看依然是在運行Chrome,
這樣查看內(nèi)存的字符串就變得很有意義,
可以進行對比。
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-4Sj1ov28-1630045248980)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p454)]
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-1o889G45-1630045248982)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p455)]
Regshot
對注冊表進行快照比較,對比2個快照,
看看差距在哪里。
先1st shot,再運行惡意代碼,
之后再2nd shot,再看差別,需要有耐心。
可以用更換背景圖片來測試。
模擬網(wǎng)絡
詳略
網(wǎng)絡監(jiān)聽
詳略
tcpdump or WireShark
不想讓病毒通過網(wǎng)絡傳播感染其他機器,
需要使用隔離的網(wǎng)絡環(huán)境:
FakeNet-NG
https://www.fireeye.com/services/freeware/fakenet-ng.html
The approach below runs completely outside the VM, and as such requires multiple VMs to be setup. It is likely that you may need to use both approaches.
But it is also relatively straight-forward to build an isolated LAN environment for testing, this page contains details of how to implement an isolated LAN environment.
Golden Rule: Check you are isolated before you run anything! traceroute/ping are your friends here.
Isolated Network Environments
Lots of malware makes network connections to local and remote machines. Can be instructive to watch this traffic to see what is happening.
e.g. by using tools such as tcpdump or WireShark
However, we do not want the malware to infect other computers or phone home, so we need to be able to run it within an isolated network environment.
Relatively straight-forward to build an isolated LAN.
Virtual Machine Hypervisors allow us to create virtual network switches, and to connect VMs to these switches. It is optional whether these switches are then connectd to the host computer, or the wider network environment (Internet). If we only connect the VMs to the virtual network switch, we create a contained network environment that allows the VMs to talk to each other, but nothing else.
But we want to be able to see traffic going to remote machines on the Internet…
Need to build an isolated ‘Internet’…
Not as hard as it sounds!
We only have to ensure that the VM can send/receive packets to the addresses it tries to, we don’t have to emulate the whole Internet!
The routes packets take across the Internet can change, so even if the malware author were to know the IP address of the instituion it is unlikely they’d be able to detect that something had changed.
Can always introduce network latency to the connection to simulate travel over the open Internet.
The following assumes that you are building this using virtual machines, but the same principles apply if you want to build it using real hardware (e.g. to watch malware on a phone handset via an isolated wireless network).
There are also some tools, such as FakeNet-NG, that can be used to simulate the network from within the test VM. The approach below runs completely outside the VM, and as such requires multiple VMs to be setup. It is likely that you may need to use both approaches.
This page details how to setup the environment for malware analysis, there are many tutorials available online that detail how to configure Linux/OpenBSD/etc. as routers, DHCP servers or DNS servers and so that information is not duplicated here. The links above are purely given as examples and were the first hits I came across on google… Other documentation is available — google it 😃
Golden Rule: Check you are isolated before you run anything! traceroute/ping are your friends here
Isolated Internet Topology
Aiming for a topology similar to the one shown in the following diagram:
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-OXEHnmmd-1630045248983)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p915)]
Technically, only the VMs in the dashed box need to be completely isolated, but I’d advise caution and connect the other bits to the real Internet only when needed.
Three main components of the network.
Isolated Network
(represented by the dashed box)
This is where we run our isolated VMs, important that this network does not connect to the host machine in anyway.
Notice, I’ve assigned this an IP range in an RFC1918 space but this is entirely optional — remember this network is not on the Internet so we can use any IP addresses we like 😃
Need to create this as a separate isolated network in the hypervisor. Using VMWare as an example, this is a two step process, which mimics the physical process of setting up a network:
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-89CwKIXa-1630045248985)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p916)]
Ensure that all the options are turned off, we do not want the host computer to be able to access this and we’ll provide DHCP/DNS via our router.
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-9hCTLri5-1630045248986)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p917)]
Make sure this is the only NIC in these VMs otherwise they’ll be able to talk to the real internet.
Other Hypervisor environments (VirtualBox, Hyper-V, etc.) offer similar facilities.
Router VM
Routes packets from the isolated network to elsewhere.
Standard VM, could run Windows, Linux, (Free|Open|Net|Dragonfly)BSD etc. — any OS that can route packets.
You may need to enable packet fowarding with sysctl.
My preference here is to use OpenBSD.
Designed to be secure by default!
Also has some nice networking features (such as allowing multiple virtual routing tables) that can be useful as setups get more advanced…
Also pf, OpenBSD’s firewall, is much simpler to configure than iptables IMO!
Will have multiple (virtual) NICs.
One in the isolated network.
One to connect to the network containing any services being provided to the isolated network.
Note down the MAC addresses of these NICs when creating them — very useful to help find which NIC is which in the router OS.
Provides DNS/DHCP services to our isolated network
Need to be able to provide both a recursive DNS server for isolated VMs to use
li>
DNS server logs will tell us what domains our machines are looking at.
Can be clever and return a honeypot address for all domains queried.
But watch out for malware that checks for this!
Do you want this to fetch real addresses from the Internet? Interesting question, DNS can be used as a back channel for communication.
And also, an authorative DNS server so we can add/override our own entries.
Lots of software options here, but I’d probably start with djbdns for DNS…
Install WireShark, tcpdump etc.
Can be used to sniff traffic leaving the isolated network. Depending on the implementation of the hypervisor, you might be able to sniff all network traffic on the isolated network.
Note that it is possible to use tcpdump from the command line in the router VM to capture network packets to a file which can then be opened on another machine in WireShark for later perusal.
Even if hypervisor doesn’t let you sniff all traffic on the isolated network, it is possible to architect your network around this (create an individual isolated network for each VM and bridge together in the router…)
VMs to provide copies of Internet Serviecs
These are optional, you don’t necessarily need them.
Again exist on a separate isolated network in your hypervisor. Create this in the same manner as before.
Again, the diagram shows I’ve used RFC1918 IP addresses here. Note though that I chose a vastly different set of IPs to make it clear which network is which!
Probably makes sense to use static IP allocation here, so you know which VM is providing which service.
Can use whatever OS you like.
Setup services as normal, e.g. use Apache WWW server to create a ‘Fake Google’…
Remember: we don’t need to duplicate all the functionality of the service, only the parts the malware acccesses.
Again we would probably develop this iteratively. Run the malware, see what it accesses, set up a duplicate server, then rerun the malware.
Configure DNS server on router to provide the server’s IP for any domain (e.g. www.google.com should return 192.168.42.23 for our ‘Fake Google’ example in the diagram above).
Some machines will attempt to connect directly to a known IP, e.g. to 172.217.23.14 (instead of www.google.com)
This is relatively straight-forward to cope with.
Set up the desired IP as an alias on the loopback interface of the machine providing the service with a netmask of 255.255.255.255 (/32), so for the example in the diagram, we’d create the alias using:
Linux: ip -4 addr add 172.217.23.14/32 dev lo.
OpenBSD: ifconfig lo0 inet alias 172.217.23.14 netmask 255.255.255.255.
Tell the router to route packets to that IP, to the IP address of the VM providing the service.
OpenBSD: route add 172.217.23.14/32 192.168.42.23.
Route will now send any packets for 172.217.23.14 to the correct VM.
Turn on packet forwarding on the VM providing the service, via sysctl, otherwise the VM won’t answer the packets.
Same approach will work for SSL/TLS encryped connections, but you’ll need to add your signing certificate to the infected VMs.
Will probably end up adding more services as you see what the malware tries to access.
Run them on separate VMs and build up a library of common services to reuse (via VM snapshots/clones).
Could also allow some packets to access the real Internet, but be careful! (Add another virtual NIC to the router VM that is connected to the Internet).
未整理
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-2fmZpsap-1630045248986)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p434)]
Instructions encode the algorithms
Manipulate data, change values in memory, update the values in registers
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-3KwG4Bwt-1630045248987)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p435)]
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-tCSxjIrR-1630045248988)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p436)]
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-LH1Ct500-1630045248988)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p437)]
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-e9YIqXe7-1630045248989)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p439)]
Stuxnet’s 21 DLL exports
Taken from the Symantec analysis report on Stuxnet
W32.Stuxnet Dossier by Nicolas Falliere, Liam O Murchu, and Eric Chien
Often DLL behaviour is contained within a DllMain function — called when the DLL started
DllMain與DllEntryPoint:
沒有區(qū)別,VC++的工程里入口函數(shù)叫DLLMain,
在其它編譯器里叫DllEntryPoint。
DllEntryPoint:
A DLL entry point, typically called DllMain
DllMain: The DLL entry point. The name DllMain is a placeholder for the library-defined function name. The DirectShow implementation uses the name DllEntryPoint.
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-XkIyq3b7-1630045248990)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p440)]
第一種可以用工具或?qū)懗绦蛲瓿?#xff0c;不用人眼一個個看。
第二種是運行時監(jiān)控+打日志
First one is a bit like the old ‘spot the difference’ game
Last one won’t necessary tell us what the program does, but we can use it to see if the program has been monkeyed about with Look at process memory space exploration in the lab
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-klfbRtSh-1630045248996)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p441)]
A bit like ‘spot the difference’
What do we mean by state — files, registry etc. see if any have changed Fortunately we can automate this
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-QsOdpuxE-1630045248997)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p442)]
Our static analysis might reveal ‘files of interest’ — if so we can start off by just looking at them — but we might miss something Hashes will tell us which files have changed, but we wouldn’t have the original file to compare with.
e.g. by using a tool such as Regshot
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-DGqhdvqe-1630045248998)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p443)]
It might not always do the same thing each time it is run Enables us to confirm our suspicions, for example
if static analysis suggested this was a key logger
Dynamic analysis might reveal the file that’s created containing the logged keys
Can then rollback and run again typing in a specific message to search for in the created file to confirm
What are the limitations of this approach… — get them to think
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-kWKgXiNH-1630045249002)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p444)]
What if the malware changes something Then restores the original value
Saw that with SolarWinds — changed the DLLHost.exe registry key Then put it back afterwards
rootkits can hide files from programs running
But not if we look at the file system externally,我們可以看看感染系統(tǒng)之外的的disk image,這樣就能看到被rootkit隱藏的信息。
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-TijEmcEW-1630045249003)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p446)]
Outside world == anything outside the program
Network easy to intercept Win32 API calls harder
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-UrOpPyG0-1630045249004)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p447)]
Assuming we let it talk to the internet
We can feed in our own packets and create a fake internet for the malware to talk to, capturing the data it sends and feeding in our own replies Or proxy the connections to see what it is talking to (And how)
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-Unmt9alk-1630045249006)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p448)]
使用軟件Process Monitor,可以監(jiān)控每一次windows API的調(diào)用,甚至能看到參數(shù)傳遞。
IF networking is easy to monitor, monitoring API calls is harder Look at the tools on Wednesday
WIN32 API CALLS
我們的程序調(diào)用Windows的打開進程API,
在中間加入監(jiān)聽器。
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-YdXLwzkB-1630045249009)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p449)]
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-rgZLlCYv-1630045249010)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p450)]
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-xzZWAChA-1630045249012)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p451)]
e.g. might see that malware makes a DNS lookup to somewhere
Then go and rerun it (from the same starting point) logging connections made to that machine Then find out that the data uses encryption (such as HTTPS)
So run it again using something
3. 高級靜態(tài)分析
使用逆向工程,將程序拆開,反匯編,看代碼,去分析。
學習難度比較高,需要掌握匯編語言,
代碼結構,windows操作系統(tǒng)等知識點。
惡意軟甲分析是逆向工程的一部分,
拿到1個惡意軟件后,通過逆向工程,
可以知道它做了什么,而不是去分析它的源代碼。
做軟件的流程:
先有想法,用匯編or高級編程語言(例如C)實現(xiàn),
可以用一些庫來幫助自己節(jié)省時間。
之后編譯器把代碼轉(zhuǎn)換成機器碼,
這樣操作系統(tǒng)才能識別,程序才能運行。
逆向工程分析軟件的流程:
我們先拿到機器碼或用VB寫的腳本、Java腳本,
這些腳本一般會被禁止反編譯或被打亂,
所有的變量都被改寫成短名稱,
空格被刪掉,讓讀者難以理解與閱讀。
通過這些腳本或機器碼來分析軟件做了什么,
之后才去了解里面有什么。
將惡意文件裝載到反匯編器中,查看程序指令,
這些指令是被CPU執(zhí)行的,看看到底它做了什么事情。
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-n809PW6N-1630045249015)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p459)]
機器碼
高級編程語言通過編譯器可以編譯成機器碼。
機器碼可以被CPU直接讀取并執(zhí)行的機器指令,
人類不可讀,不支持跨平臺,
不同種類的CPU執(zhí)使用的機器碼不一樣,
機器碼的種類也有很多。
操作碼 opcode
機器碼由操作碼(opcode)組成,
操作碼是一些十六進制形式的數(shù)字,
用于告訴處理器你想要它做什么。
opcode:一條機器指令,
比如我們用匯編語言寫的一條操作語句。
程序中的機器碼用一系列的二進制操作碼表示,
這些操作碼代表一組低級指令被CPU執(zhí)行。
執(zhí)行的操作都基于這些二級制操作碼,
例如1個二進制操作碼可能代表2個數(shù)相加,
另外1個操作碼可能代表去調(diào)用某個東西等等。
Prefix (1 bytes optional) !
Opcode can be 1, 2 or 3 bytes!
ModR/M is one byte (optional) — modifies which registers/memory are used! SIB 1 Byte optional !
Displacement (1,2 or 4 bytes) — added on to the address!
Immediate value (1, 2 or 4 bytes) — immediate value if used by the instruction! 64-bit mode can have an extra byte in here too!!
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-slOLE8pz-1630045249018)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p466)]
? x86 opcodes can vary in length from 1 to 15 bytes long
? Difficult to fetch from memory, since length is not know till you are three or four bytes into decoding it
? eip points to the first byte of the next instruction, updated as instructions read
? Possibly to use the structure to make it difficult for a disassembler to find code
? But not the CPU…
機器碼指令的類型
? Basic operations
? Maths(加減乘除)
? Boolean Algebra
? Comparisons
? Memory Access — usually including support for stacks
? Flow control — jumps and branches (both conditional and unconditional)
? Subroutines,子程序,子過程,調(diào)用其他函數(shù),其他函數(shù)稱為子過程,call誰誰就是誰的子過程。
? And others
Other instructions depend on the type of CPU — RISC CPUs will often just have a minimal subset of the above (perhaps with instructions to switch processor modes)!
CISC CPUS (such as the x86) add loads — AES encoding, string manipulations etc.
通過使用1個或多個機器碼指令來模擬高級語言的語法,
例如循環(huán),變量,數(shù)組,條件控制等等。
x86體系結構
Windows系統(tǒng)在x86和ARM的CPUs上均可運行,
x86是迄今為止最常見的平臺,無論是32位還是64位。
因為x86指令集非常復雜,惡意軟件正好可以利用。
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-sqQmK52H-1630045249019)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p476)]
Control Unit通過寄存器(指令指針)從內(nèi)存中獲得指令去執(zhí)行,寄存器負責存儲指令地址。
寄存器是CPU的基礎數(shù)據(jù)存儲單元,
經(jīng)常被用于節(jié)省時間,因為不需要CPU訪問內(nèi)存。
ALU(Arithmetic Logic Unit)執(zhí)行從內(nèi)存中獲取的指令,并將運算結果放回寄存器或內(nèi)存中。
指令不斷被獲取被執(zhí)行的重復過程,
形成了程序的運行。
CISC架構
CISC的英文全稱為“Complex Instruction Set Computer”,即“復雜指令系統(tǒng)計算機”,從計算機誕生以來,人們一直沿用CISC指令集方式。
早期的桌面軟件是按CISC設計的,并一直沿續(xù)到現(xiàn)在。
目前,桌面計算機流行的x86體系結構即使用CISC。
微處理器(CPU)廠商一直在走CISC的發(fā)展道路,
包括Intel、AMD,還有其他一些現(xiàn)在已經(jīng)更名的廠商,如TI(德州儀器)、IBM以及VIA(威盛)等。
在CISC微處理器中,程序的各條指令是按順序串行執(zhí)行的,每條指令中的各個操作也是按順序串行執(zhí)行的。
順序執(zhí)行的優(yōu)點是控制簡單,
但計算機各部分的利用率不高,執(zhí)行速度慢。
CISC架構的服務器主要以IA-32架構(英特爾架構)為主,而且多數(shù)為中低檔服務器所采用。
Little-endian:將低序字節(jié)存儲在起始地址(低位編址)
CPU
CPU中央處理器主要負責執(zhí)行代碼。
-
1978年6月,Intel推出了8086微處理器,標志著第三代微處理器問世。它采用16位寄存器、16位數(shù)據(jù)總線和29000個3微米技術的晶體管,售價360美元。不過當時由于360美元過于昂貴,大部分人都沒有足夠的錢購買使用此芯片的電腦,于是Intel在1年后推出了8位數(shù)據(jù)總線的微處理器8088。IBM公司1981年生產(chǎn)的第一臺電腦就是使用的這種芯片。
-
70年代末,因特爾生產(chǎn)了著名的16位8086處理器,之后又推出了80186與80286;
-
1985年,因特爾繼摩托羅拉之后,第二個研制出32位的微處理器80386;
-
1989年,因特爾推出80486處理器,具有浮點運算功能;
-
1993年,因特爾推出奔騰處理器,不再以數(shù)字命名其產(chǎn)品;
在工業(yè)界和學術界,
大家仍然習慣性的把因特爾的CPU稱為X86系列,
X作為通配符代替前面的數(shù)字。
x86正式一點的名字是IA-32(Intel Architecture 32-bit)。
x86架構的特點是CPU的寄存器是32位的,
因此也叫32位CPU。
基于32位CPU開發(fā)的操作系統(tǒng)就叫32位操作系統(tǒng),
因為目前x86架構在32位CPU的知名度,
32位操作系統(tǒng)也通常被稱為x86系統(tǒng)。
AMD皓龍,64位
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-205Hb5B1-1630045249021)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p456)]
X86和X86_64和AMD64
由于32位系統(tǒng)x86架構的種種限制,
包括速度,性能等方面,
Intel開始向64位架構發(fā)展,那么有2選擇:
結果AMD領先,比Intel率先制造出了商用的兼容x86的CPU,AMD稱之為AMD64,搶了64位PC的第一桶金,得到了用戶的認同。
而Intel選擇了設計一種不兼容x86的全新64為指令集,稱之為IA-64,但是比amd晚了一步,而且IA-64也挺慘淡的,因為是全新設計的CPU,沒有編譯器,也不支持windows(微軟把intel給忽悠了,承諾了會出安騰版windows server版,但是遲遲拿不出東西)。。。
后來不得不在時機落后的情況下也開始支持AMD64的指令集,但是換了個名字,叫x86_64,表示是x86指令集的64擴展。
也就是說實際上,x86_64,x64,AMD64基本上是同一個東西,我們現(xiàn)在用的intel/AMD的桌面級CPU基本上都是x86_64
i386
首先可以簡化一個概念,i386=Intel 80386。
i386通常被用來作為對Intel(英特爾)32位微處理器的統(tǒng)稱。
但是目前更多的時候,我們公認i386為32位系統(tǒng),
其實就是x86了。
寄存器
寄存器是CPU中數(shù)據(jù)的臨時基本存儲單元,
訪問寄存器的速度要高于訪問內(nèi)存的速度,
CPU通過寄存器很多時候不再需要訪問內(nèi)存,
從而節(jié)省了時間。
寄存器中既可以存儲數(shù)據(jù),又可以存儲地址。
寄存器主要作用:
x86寄存器種類:
- 通用寄存器(general registers),8個32位(或64位),用于CPU執(zhí)行;
? 段寄存器(segment registers),6個16位,用于定位內(nèi)存節(jié);
? 狀態(tài)標志,Status Register (EFLAGS),用于條件判斷;
? 指令指針,Instruction Pointer (EIP),用于定位要執(zhí)行的下一條指令;
這里使用32位名稱,
在64位模式中e被一個r替換!
64位模式添加了另一個8寄存器r9-r15!
有些特定要求特定的指令值需要存儲在特定的寄存器中。
For example, string instructions use the contents of the ECX, ESI, and EDI registers as operands!
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-6NbyY5ah-1630045249023)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p457)]
Could access the ax register as two 8-bit registers (high byte ah and low byte al)!
The same register was then extended to 32-bits, as eax — but you could still access the 16-bits (ax) or the 8-bit (ah and al) ! (Around the time of 80386)!
The same register was then extended to 64-bits, as rax — but you could still access the 32bits (eax) or the 16-bits (ax) or the 8-bit (ah and al) ! With the AMD Opteron!
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-5DTwP7ZX-1630045249026)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p458)]
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-hy7OCbyo-1630045249027)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p465)]
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-PW9SeZSU-1630045249029)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p478)]
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-LujQecpJ-1630045249030)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p460)]
通用寄存器
通用寄存器一般用于存儲數(shù)據(jù)或內(nèi)存地址,
而且經(jīng)常交換著使用以完成程序。
它們并不通用,一些x86指令只能使用特定的寄存器,
例如:
乘法和除法指令只能使用EAX和EDX。
還有一些約定(convention):
EAX通常存儲了一個函數(shù)的返回值,看到一個函數(shù)調(diào)用后立刻使用EAX,可能是在操作返回值。
EAX:累加器(Accumulator),
它的低16位即是AX,
而AX又可分為高8位AH和低8位AL。
EAX是很多加法乘法的默認寄存器,
在80386及其以上的微處理器中可以用來存放存儲單元的偏移地址。
AX寄存器是算術運算的主要寄存器。
EBX:基地址寄存器(Base Register),
它的低16位即是BX,而BX又可分為高8位BH和低8位BL。主要用于在內(nèi)存尋址時存放基地址。
ECX:計數(shù)寄存器(Count Register),它的低16位即是CX,而CX又可分為高8位CH和低8位CL。
在循環(huán)和字符串操作時,要用它來控制循環(huán)次數(shù);
在位操作中,當移多位時,要用CL來指明移位的位數(shù);是重復(REP)前綴指令和LOOP指令的內(nèi)定計數(shù)器。
EDX:數(shù)據(jù)寄存器(Data Register),
它的低16位即是DX,
而DX又可分為高8位DH和低8位DL。
在進行乘、除運算時,它可作為默認的操作數(shù)參與運算,也可用于存放I/O的端口地址;
且總是被用來放整數(shù)除法產(chǎn)生的余數(shù)。
ESI/EDI:分別叫做源/目標索引寄存器(Source/Destination Index Register),
它們的低16位分別是SI、DI。
它們主要用于存放存儲單元在段內(nèi)的偏移量,
用它們可實現(xiàn)多種存儲器操作數(shù)的尋址方式,
為以不同的地址形式訪問存儲單元提供方便。
在很多字符串操作指令中,
DS:ESI指向源串,
而ES:EDI指向目標串。
此外,它們又作為通用寄存器可以進行任意的常規(guī)的操作,如加減移位或普通的內(nèi)存間接尋址。
EBP/BSP:分別是基址針寄存器(Base Pointer Register)/堆棧指針寄存器(Stack Pointer Register),低16位是BP、SP,其內(nèi)存分別放著一個指針,該指針永遠指向系統(tǒng)棧最上面一個棧幀的棧頂/底部。
主要用于存放堆棧內(nèi)存儲單元的偏移量,
用它們可實現(xiàn)多種存儲器操作數(shù)的尋址方式,
為以不同的地址形式訪問存儲單元提供方便。
指針寄存器不可分割成8位寄存器。
作為通用寄存器,
也可存儲算術邏輯運算的操作數(shù)和運算結果。
并且規(guī)定:BP為基指針(Base Pointer)寄存器,
用它可直接存取堆棧中的數(shù)據(jù);
SP為堆棧指針(Stack Pointer)寄存器,
用它只可訪問棧頂。
標志寄存器
在x86架構中,標志寄存器是32位的,
每一位是一個標志,在執(zhí)行期間,
每一位要么是置位(1),要么是清除(0)。
由這些值來控制CPU的運算,
或者給出某些CPU運算的值。
一些重要的標志:
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-PyvDYwiG-1630045249031)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p461)]
指令指針
EIP的唯一作用就是告訴處理器下面該做什么,
保存了程序?qū)⒁獔?zhí)行的下一條指令的內(nèi)存地址。
攻擊者可以通過控制EIP來控制CPU將要執(zhí)行什么,
改變EIP使其指向惡意代碼,從而攻擊系統(tǒng)。
指令
指令是由匯編程序構成,在x86匯編語言中,
一條指令由一個助記符(要執(zhí)行的指令),
以及0個或多個操作數(shù)(說明指令要使用的信息)組成。
| mov | ecx | 0x42 |
x86有一個寄存器-內(nèi)存架構,
指令可以在寄存器上操作,
也可以直接在內(nèi)存上操作。
在32位系統(tǒng)中,每個地址都是4字節(jié)長,
因此后面用到參數(shù)偏移offset時,需要加4。
操作碼和字節(jié)序
每條指令使用操作碼(opcode=operation code)來告訴CPU要執(zhí)行什么樣的操作。
操作碼opcode在這里表示整條機器指令,
反匯編器將操作碼翻譯成匯編語言。
例如:
mov ecx, 0x42的操作碼是B9 42 00 00 00。
其中0xB9對應mov ecx,用0x42000000來表示0x42,是因為x86架構使用小端字節(jié)序。
數(shù)據(jù)的字節(jié)序(endianness)是指在一個大數(shù)據(jù)項中,最高位(大端,big-endian)還是最低位(小端,little-endian)被排在第一位(即被排在最低的地址上)。
一些惡意代碼在網(wǎng)絡通信時必須改變字節(jié)序,因為網(wǎng)絡數(shù)據(jù)使用大端字節(jié)序,而x86程序使用小端字節(jié)序。
IP地址127.0.0.1會表示為:
大端字節(jié)序(網(wǎng)絡):0x7F000001
小端字節(jié)序(本地):0x0100007F
確保不要把類似于IP地址的重要數(shù)據(jù)弄反。
x86的CPU是有點無字節(jié)序的,
一些常量在內(nèi)存中的字符串順序可能是錯的,需要改過來。
操作數(shù)Operand
操作數(shù)是指令要使用的數(shù)據(jù),有3種類型。
-
立即數(shù)(immediate)
固定的值,如0x42。 -
寄存器(register)
指向寄存器,如ecx。 -
內(nèi)存地址(memory address)
指向內(nèi)存地址,一般由方括號內(nèi)中的值、寄存器或方程式(計算內(nèi)存地址)組成,如[eax],指向內(nèi)存地址為EAX處的數(shù)據(jù)。使用方程式來計算內(nèi)存地址可以節(jié)省空間,不需要額外的指令來計算公式,不加方括號就是一條非法指令。要明確一點,內(nèi)存地址是可以用來計算的。
常見指令
采用Intel匯編語法,將目標操作數(shù)放在前面。
賦值指令
mov destination, source
移動數(shù)據(jù),復制,用于讀寫內(nèi)存,
將數(shù)據(jù)從一個位置移動到另一個位置,
將數(shù)據(jù)移動到寄存器或內(nèi)存,
注意,這里是直接覆蓋,并不會累加。
(mov是最簡單常見的指令)
【是復制還是剪切?復制】
mov eax, ebx
將EBX中的內(nèi)容復制到EAX
mov eax, 0x42
將立即數(shù)0x42復制到EAX
mov eax, [0x4037C4]
將內(nèi)存地址為0x4037C4處的4個字節(jié)復制到EAX
mov eax, [ebx]
將EBX指向的內(nèi)存地址處的4個字節(jié)復制到EAX
mov eax, [ebx + esi * 4]
將ebx + esi * 4的計算結果指向的內(nèi)存地址處的4個字節(jié)復制到EAX。
lea distinatioon, source
將內(nèi)存地址賦給目的操作數(shù),跟mov類似的一條指令,
lea是load effective address的縮寫,
即加載有效地址。
lea eax, [ebx+8]
將EBX+8的值給EAX,這個值可能是個地址。
mov eax, [ebx+8]
將內(nèi)存地址為EBX+8處的數(shù)據(jù)給EAX。
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-sEMJ8z2q-1630045249034)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p462)]
解釋mov eax, [ebx+8]
寄存器EBX存的值是0x00B30040,
[ebx+8]的意思是計算內(nèi)存地址,
先做16進制計算,
0x00B30040 + 8 = 0x00B30048,
方括號代表內(nèi)存地址,
之后找地址為0x00B30048的內(nèi)存值0x20,
將0x20賦給EAX。
而lea eax, [ebx+8]則是把0xB30048賦給EAX。
此外,lea指令還可以計算普通值,效率更高,
因為需要的指令更少。
lea ebx, [eax * 5 + 5]
其中eax是普通的數(shù)而不是內(nèi)存地址,
這條指令等價于ebx = (eax + 1) * 5。
運算指令
add destination, value
加法,從目標操作數(shù)中加上一個值
add eax, ebx
將EBX的值加入EAX并將結果保存在EAX
sub destination, value
減法,從目標操作數(shù)中減去一個值
sub指令會修改2個標志:ZF和CF
如果結果為0則ZF被置位,
如果目標操作數(shù)比要減去的值小則CF被置位。
sub eax, 0x10
EAX的值減去0x10
inc edx
加一,EDX的值遞增1
Increments EDX by 1
dec ecx
減一,ECX的值遞減1
Decrements ECX by 1
乘法與除法指令只能使用預先規(guī)定的寄存器EAX和EDX,
乘法與除法指令要操作的寄存器一般會在之前許多條指令的地方被賦值,
因此需要在程序的上下文中來尋找。
mul value
乘法,總是將EAX乘上value,
因此EAX必須在乘法指令出現(xiàn)前就賦值好。
乘法的結果以64位的形式分開存儲在2個寄存器中,
EDX存儲高32位,EAX存儲低32位。
mul 0x50
將EAX的值乘以0x50,并將結果存入EDX+EAX中
div value
除法,除法在運算方向上與乘法相反,
將EDX與EAX合起來存儲的64位值除以value,
因此在做除法前,EDX與EAX必須賦值好。
除法的商將存儲到EAX,余數(shù)存儲在EDX。
div 0x75
將EDX+EAX的值除以0x75,
并將結果存入EAX,將余數(shù)存入EDX。
imul與idiv是mul與div的有符號版本。
xor eax, eax
Clears the EAX register
把eax的值快速設置為0,
將EAX寄存器清零,為了優(yōu)化,
因為這條指令只需要2個字節(jié),
而mov eax, 0則需要5個字節(jié)。
xor ecx, ecx
or eax, 0x7575
對EAX的值進行與0x7575的or操作
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-pDUflGps-1630045249035)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p479)]
shr destination, count
右位移,由count決定移多少位
shl destination, count
左位移,由count決定移多少位
ror,循環(huán)右位移,將最低位循環(huán)移動到最高位
rol,循環(huán)左位移,將最高位循環(huán)移動到最低位
mov eax, 0xA
shl eax, 2
將EAX左移2位,這2個指令將導致EAX=0x28,
因為1010(0xA的二進制表示)左移2位之后為101000(0x28)
mov bl, 0xA
ror bl, 2
將BL循環(huán)移位移2位,這2條指令將導致BL = 10000010,因為1010向右循環(huán)移動2位為10000010。
條件指令
用來做比較的指令,根據(jù)比較結果做出決定。
test eax, eax
與自身進行text經(jīng)常被用于檢查是否為NULL,
效率高,消耗字節(jié)更少,花費的CPU周期也更少。
條件對比,類似于if,
后面肯定有一個yes或no的分支出來,
test指令執(zhí)行完畢后去看ZF標志位。
test指令與and指令的功能一樣,
但它并不會修改其使用的操作數(shù),
test指令只設置標志位。
test eax,eax基本上和and eax,eax是一樣的,
不同的是test不改變eax的結果,
test只是改變FLAG寄存器的狀態(tài),
也就是改變進位標志,零標志,溢出標志等等。
test eax,eax
je xxxxxxxx
test指令的操作是將目的操作數(shù)和源操作數(shù)按位與,
運算結果不送回目的操作數(shù),
然后根據(jù)結果設置SF,ZF,PF標志位,
并將CF和OF標志位清零,
一般下面會跟跳轉(zhuǎn),
根據(jù)ZF標志位是否為零來決定是否跳轉(zhuǎn),
即,這句意思就是判斷eax是否為零。
test指令操作是目的操作數(shù)和源操作數(shù)按位邏輯“與“操作
運算結果不送回目的操作數(shù)(基本上和 And eax,eax 是一樣的,不同的是test 不改變eax的結果)
然后根據(jù)結果設置SF、ZF、和PF標志位,
并將CF和OF標志位清零。
而JE是當ZF=1時跳轉(zhuǎn)。
即,當eax的值等于0時跳轉(zhuǎn)。
因此說,這里的test就是檢測eax的值是不是0
Flags
CF是進位標志,
PF是奇偶標志
AF是輔助進位標志
ZF是零標志
SF是符號標志
OF是溢出標志.
cmp [ebp+argc], 3
用參數(shù)argc與3進行比較,if(argc!=3)
cmp [ebp+VersionInformatioon.dwplatformId], 2
驗證是不是Win32NT的平臺
cmp [ebp+VersionInformation.dwMajorVersion], 5
檢查操作系統(tǒng)版本,如果大于5則表示高于vista,小于5則是低于vista
cmp指令與sub指令的功能一樣,
但cmp不影響其操作數(shù)。
cmp指令也是只用于設置標志位,
其執(zhí)行的結果是,ZF和CF標志位可能發(fā)生變化。
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-sdK3RHIT-1630045249038)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p474)]
分支指令
最常見的分支指令是跳轉(zhuǎn)指令,
在匯編指令中沒有if語句,只有條件跳轉(zhuǎn)。
條件跳轉(zhuǎn)使用標志位來決定是跳轉(zhuǎn),還是繼續(xù)執(zhí)行下一條指令。
jmp location
最簡單的跳轉(zhuǎn)指令,無條件跳轉(zhuǎn),不能用于if,
要被執(zhí)行的跳轉(zhuǎn)一定會被執(zhí)行,沒有任何條件限制。
jmp short
相對短轉(zhuǎn)移
這種指令格式的jmp指令實現(xiàn)的是段內(nèi)轉(zhuǎn)移,
它的修改范圍是:-128 ~ 127,
它向前轉(zhuǎn)移時最多128字節(jié),向后最多127.
jmp near
16位相對近轉(zhuǎn)移
該指令屬于段內(nèi)轉(zhuǎn)移,轉(zhuǎn)移范圍是-32768~32767
jz
如果ZF=1,跳轉(zhuǎn)至指定位置。
jnz
條件跳轉(zhuǎn)語句,如果ZF=0,則跳轉(zhuǎn)至指定位置。
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-EDZCnh7b-1630045249039)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p472)]
重復指令
詳略
rep
循環(huán)終止條件ECX=0
repe, repz
循環(huán)終止條件ECX=0或ZF=0
repne, repnz
循環(huán)終止條件ECX=0或ZF=1
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-QpYRUi3c-1630045249040)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p482)]
rep cmpsb
rep stosb
rep movsb
repne scasb
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-EecMpU9P-1630045249043)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p481)]
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-BSVpQlEF-1630045249044)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p483)]
其他指令
對于沒有見過的指令可以參考:
http://www.intel.com/products/processor/ manuals/index.htm.
匯編語言
匯編語言是異類語言的統(tǒng)稱,
對不同的處理器體系有不同的匯編語言,
這里只涉及到最流行的x86處理器匯編語言。
在沒有源碼的情況下,我們可以借助反匯編工具來生成匯編代碼,然后做逆向工程或去分析代碼。
數(shù)組
在匯編中,
數(shù)組的形式跟定義一排數(shù)據(jù)的效果是一樣的,
前提是必須要定義類型相同的數(shù)據(jù)。
定義數(shù)組元素時,每個元素的地址都是相鄰的,
在內(nèi)存地址上是連續(xù)的,
低地址在上面,越往下地址越高。
輸入輸出系統(tǒng)IO
為硬盤、鍵盤、顯示器等設備提供接口。
內(nèi)存RAM
內(nèi)存負責存儲數(shù)據(jù)和代碼。
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-HRstkbGx-1630045249045)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p477)]
數(shù)據(jù):一些數(shù)據(jù)在程序初始加載時被放到這里,成為靜態(tài)值或全局值,在程序運行時它們不會發(fā)生變化,在程序的任何部分都可以使用它們。
代碼:在執(zhí)行程序時CPU所取得的指令。
堆:為程序執(zhí)行期間需要的動態(tài)內(nèi)存,用于創(chuàng)建(分配)新的值,以及消除(釋放)不再需要的值。將其稱為動態(tài)內(nèi)存,是因為在程序運行期間內(nèi)容會經(jīng)常改變。
x86 MEMORY MODEL
? x86 has various models for how we can access memory
? Segmented memory
? Address accessed built up from the value in a segment register, and the address specified in the instruction
? Fortunately, these days most operating systems use a flat memory model
? But the segment registers still exist…
(Including Windows)
在內(nèi)存中,地址與數(shù)據(jù)是2個東西,它們是一一對應的,1個地址對應著1個數(shù)據(jù)。
而寄存器中只存了1個東西,可能是數(shù)據(jù),也可能是地址(引用)。
棧
棧只能用于短期存儲,
主要用于管理函數(shù)調(diào)用之間的數(shù)據(jù)交換,
給函數(shù)、局部變量、參數(shù)、
返回地址、流控制結構的內(nèi)存存儲在棧中。
棧是一種用來壓和彈操作后入先出(LIFO)的數(shù)據(jù)結構。
在內(nèi)存中,棧被分配成從上到下的(數(shù)據(jù)從上面壓入到棧中),
最高的內(nèi)存地址最先被使用,
持續(xù)的往棧中壓入數(shù)據(jù),則使用越低的內(nèi)存地址。
內(nèi)存地址也分大小,[最小的地址/低位內(nèi)存]在上面,
[最大的地址/高位內(nèi)存]在下面,
這也是為什么內(nèi)存地址尋址要用加減法。
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-eLSyOI7m-1630045249046)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p480)]
x86架構中,ESP與EBP原生支持棧,
ESP是棧指針(stack pointer),
包含了指向棧頂?shù)膬?nèi)存地址。
一些數(shù)據(jù)被壓入或彈出棧時,ESP的值相應改變。
EBP是個基指針(base pointer),
在一個函數(shù)中會保持不變,
因此程序可以使用它作為占位符來跟蹤局部變量和參數(shù)的位置。
棧相關指令
push, pop, call, leave, enter, ret.
使用push指令將函數(shù)的參數(shù)壓入棧中,
參數(shù)1在最下面,參數(shù)2在參數(shù)1上面,以此類推。
pop ebx
棧頂?shù)臄?shù)據(jù)會賦給EBX,ESP的值增加4。
函數(shù)調(diào)用
每一次函數(shù)調(diào)用,就會產(chǎn)生一個新的棧幀。
函數(shù)維護它自己的棧幀,直到返回,
這時調(diào)用者的棧幀被恢復,執(zhí)行權也返回給了調(diào)用函數(shù)。
許多函數(shù)包含一段序言(prologue),
它是在函數(shù)開始處的少數(shù)幾行代碼,
用戶保存函數(shù)中要用到的棧和寄存器。
在函數(shù)結尾的結語(epilogue),
將相關的棧和寄存器恢復至函數(shù)被調(diào)用前的狀態(tài)。
實現(xiàn)流程:
FUNCTION CALLS
? Like almost all CPUs, x86 supports calling subroutines (function calls)
? Does this using the call instruction
? Address of next instruction can be specified
? Relative (to the current instruction)
? Absolute
? Indirectly (the address pointed to by…)
? Once the destination address is calculated call will then
? Current instruction pointer (eip/rip) pushed onto the stack
? Instruction pointer set to address of start of subroutine
? Can return from a subroutine using ret
? Pops the old instruction pointer from the stack
? Places it into eip/rip so next instruction carries on after call
? Optionally, can then add an offset to the stack pointer
FUNCTION CALLS AND THE STACK
? Note that ret fetches the return address off the stack
? Stack is also used for various other things such as local variables and arrays
? Possibly to overwrite the return value on the stack
? Causing ret to return to a different place
? If malware can control where ret returns to, it can cause a program to do ‘something else’…
? Often used as a vector for initially executing malware code…
? Two mechanisms used
? Cause the stack to be overwritten with the code we want to execute
? Return-oriented programming
Hello, buffer overflow!
There are was to protect against code on the stack using the DEP bit.
FUNCTION CALL ARGUMENTS
? call enables us to call a subroutine, but how do we pass arguments?
? Several conventions used, most involve placing arguments onto the stack
? Caller and callee need to agree on the way arguments are passed…
? Return values passed in eax/rax
? Variations exist on whether it is the job of the caller or the callee to clean the arguments off the stack
? And the order the values are placed on the stack (left to right, or right to left)
? Other variants will use registers to pass values
Note that smaller data types can be promoted in size to larger sizes!
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-WDpnvTX8-1630045249048)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p467)]
Cdecl default for C/C++ on Windows! Argument length in bytes!
Also clrcall for managed functions! Thiscall default for C++ methods! 64-bit has its own calling convention! As does ARM!
FUNCTION PROLOGUES/EPILOGUE
? Most C compilers will compile a function prologue at the start of the function
? Pushes the current value of ebp
? Sets ebp to value of esp
? Allocate space for local variables on the stack (using sub)
? Preserve registers
? At the end of the function, an equivalent epilogue is generated to restore the stack/registers
? Side-effect of this is that ebp can be used to trace back up the call stack
棧的布局
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-8swMG3kl-1630045249051)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p463)]
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-XgudnBwj-1630045249051)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p464)]
反匯編Disassembly
反匯編將操作碼轉(zhuǎn)成匯編語言
? Need to also generate labels so we know where branches and subroutine calls go to
? If you come across a branch, subroutine call etc. then you make a note of that as being
another place to start converting code from…
? Should (in theory) find all the code accessible in the program
But as there is more than one way to make a jump !
Possible to have portions of code the disassembler doesn’t find — might come across them and need to go back and reanalyze some more code! (Now what were to happen if we were to jump into the middle of an instruction…)
ASSEMBLY SYNTAX
Two syntaxes used for x86 assembly language
? Intel syntax
? AT&T syntax
? Usual to use Intel syntax for x86 assembly language in the DOS and Windows world
? Instructions tend to have two operands — the first is the destination
? So add eax, 2 would mean eax = eax + 2
AT&T common in the UNIX world (e.g. Linux)! Lets go look at some assembly in Visual Studio 😉!
Ghidra(工具)
https://www.nsa.gov/resources/everyone/ghidra/About-Us/EEO-Diversity/Employee-Resource-Groups/
入口點一般是左側“Program Tree”下面Exports中的entry或者main。
雙擊變量或者函數(shù)可以進行跳轉(zhuǎn),
點擊變量的右鍵菜單可以在“References”看到該變量所有被應用的位置。
此外還有一個常用CFG圖,在“Window”-“Function Graph”中可以看到,跟隨當前程序函數(shù)而變化。
查看字符串:
windows-define strings
交叉引用快捷鍵
command + shift + F
https://www.sohu.com/a/299745429_120054144
個人認為,這2個軟件是相輔相成的,
并不是互相取代的關系。
Downloads for Amazon Corretto 11
https://docs.aws.amazon.com/corretto/latest/corretto-11-ug/downloads-list.html
https://ghidra-sre.org/
https://www.shogunlab.com/blog/2019/04/12/here-be-dragons-ghidra-0.html
https://www.shogunlab.com/blog/2019/12/22/here-be-dragons-ghidra-1.html
https://ghidra-sre.org/CheatSheet.html
IDA pro(工具)
免費版下載地址:
https://www.hex-rays.com/products/ida/support/download_freeware/
https://www.cnblogs.com/sch01ar/p/9537760.html
https://blog.csdn.net/dyxcome/article/details/91345138
https://blog.csdn.net/wang010366/article/details/52505345
圖形模式左下角的小視圖并不是全貌,只是局部視圖
交互式反匯編器,可以反匯編整個程序,
執(zhí)行查找函數(shù),棧分析,本地變量標識等等。
可以保存分析過程,
過程中的所有屬性都可以被修改或重新定義。
可以添加注釋,標記數(shù)據(jù)或函數(shù)名。
保存后可以下次繼續(xù)使用。
將文件作為原始二進制文件進行反匯編,
打開文件時,選擇binary file。
打開文件時選擇手動加載,可以加載PE文件頭和所有節(jié),惡意代碼經(jīng)常會往里面隱藏一些信息。
分號后面是注釋,可以自己加注釋,
右鍵enter comments。
函數(shù)的參數(shù)如果是魔法數(shù)字則可以改變?yōu)閰?shù)值為有意義的文字,在參數(shù)處右鍵點擊Use standard symbolic constant…在窗口中找到對應的描述,相關內(nèi)容可以通過msdn查到。
IDA圖形視圖會有執(zhí)行流,
Yes箭頭默認為綠色,
No箭頭默認為紅色,
藍色表示默認下一個執(zhí)行塊,沒有控制跳轉(zhuǎn)。
向上箭頭一般是循環(huán)
在寄存器窗口中顯示著每個寄存器當前的值和對應在反匯編窗口中的內(nèi)存地址。
函數(shù)在進入時都會保存堆棧地址EBP和ESP,
退出函數(shù)時恢復。
可以對函數(shù)進行重命名,右鍵函數(shù)名即可。
可以給假名改成有意義的名字,
相關聯(lián)的地方會自動更新。
搜索opcode,search-sequence of bytes
find all occurrences.
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-MNRyKy93-1630045249052)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p469)]
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-GeSFrYak-1630045249054)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p470)]
自動注釋
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-RtClC96S-1630045249055)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p471)]
可以快速識別出編譯器添加的庫代碼。
左側的函數(shù)列表中,可以過濾函數(shù)長度,復雜的函數(shù)可能會更長一些,F表示庫函數(shù)(library functions), 可以在識別函數(shù)時跳過這些編譯器生成的函數(shù)。start函數(shù)一般是程序的入口。
快捷鍵
按G鍵,可以直接跳轉(zhuǎn)至某一個地址,
例如:0x10001757
按ESC鍵,退回到上一個界面。
對代碼的開頭與結束位置選中,按P,將這段代碼強制編程一個函數(shù)。
按F5鍵,反編譯匯編代碼
按空格鍵,可以在文本模式與圖形模式下切換,
只能在IDA View-A。
shift + F12,顯示strings窗口,也可以view-subviews-strings。
交叉引用xref
可以查看到函數(shù)、字符串、數(shù)據(jù)被誰調(diào)用。
在函數(shù)的地址上按快捷鍵ctrl + x,
看type為P的,調(diào)用者地址的前綴可能會重復,
代表是相同的函數(shù),要仔細查看。
可以查看到自負被誰引用,
在自負的地址上按快捷鍵ctrl + x,
type = r代表讀,type = w代表寫。
從看字符串被誰引用,則雙擊字符串后,右側有個向上箭頭,雙擊后,上下的指令都要看看。
看指令,如果有shell,以及一些系統(tǒng)命令,包括cd,等等,則可能是為攻擊者開啟一個遠程shell對話。
可以為某個函數(shù)開啟交叉引用圖,可以設置深度,
雙擊進入某個函數(shù),之后點擊view-graphs-user xrefs chart…
分析函數(shù)
var_或者右邊是負數(shù)表示局部變量。
arg_或者右邊是正數(shù)表示參數(shù)。
Windows
PEB
PEB(Process Environment Block,進程環(huán)境塊)是存放進程信息的結構體(一種數(shù)據(jù)結構),擁有很多字段,包括全局上下文,啟動參數(shù),程序映像加載器等。
? Part of the kernel’s data structures about each process
? Fortunately this one lives in user space, so we can access it
? Contains a field called Ldr
? Pointer to a PEB_LDR_DATA structure
? Provides information about loaded modules for the processes
In computing the Process Environment Block (abbreviated PEB) is a data structure in the Windows NT operating system family. It is an opaque data structure that is used by the operating system internally, most of whose fields are not intended for use by anything other than the operating system.[1] Microsoft notes, in its MSDN Library documentation — which documents only a few of the fields — that the structure “may be altered in future versions of Windows”.[2] The PEB contains data structures that apply across a whole process, including global context, startup parameters, data structures for the program image loader, the program image base address, and synchronization objects used to provide mutual exclusion for process-wide data structures.[1]
https://www.cnblogs.com/DeeLMind/p/6854986.html
https://blog.csdn.net/CSNN2019/article/details/113113347
https://blog.csdn.net/CSNN2019/article/details/113105811
https://www.jianshu.com/p/28c8689b22af
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-MoTiFewi-1630045249056)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p475)]
typedef struct _PEB {UCHAR InheritedAddressSpace; // 00hUCHAR ReadImageFileExecOptions; // 01hUCHAR BeingDebugged; // 02h 這里QAQUCHAR Spare; // 03hPVOID Mutant; // 04hPVOID ImageBaseAddress; // 08hPPEB_LDR_DATA Ldr; // 0ChPRTL_USER_PROCESS_PARAMETERS ProcessParameters; // 10hPVOID SubSystemData; // 14hPVOID ProcessHeap; // 18hPVOID FastPebLock; // 1ChPPEBLOCKROUTINE FastPebLockRoutine; // 20hPPEBLOCKROUTINE FastPebUnlockRoutine; // 24hULONG EnvironmentUpdateCount; // 28hPVOID* KernelCallbackTable; // 2ChPVOID EventLogSection; // 30hPVOID EventLog; // 34hPPEB_FREE_BLOCK FreeList; // 38hULONG TlsExpansionCounter; // 3ChPVOID TlsBitmap; // 40hULONG TlsBitmapBits[0x2]; // 44hPVOID ReadOnlySharedMemoryBase; // 4ChPVOID ReadOnlySharedMemoryHeap; // 50hPVOID* ReadOnlyStaticServerData; // 54hPVOID AnsiCodePageData; // 58hPVOID OemCodePageData; // 5ChPVOID UnicodeCaseTableData; // 60hULONG NumberOfProcessors; // 64hULONG NtGlobalFlag; // 68h 還有這里!_(:зゝ∠)_UCHAR Spare2[0x4]; // 6ChLARGE_INTEGER CriticalSectionTimeout; // 70hULONG HeapSegmentReserve; // 78hULONG HeapSegmentCommit; // 7ChULONG HeapDeCommitTotalFreeThreshold; // 80hULONG HeapDeCommitFreeBlockThreshold; // 84hULONG NumberOfHeaps; // 88hULONG MaximumNumberOfHeaps; // 8ChPVOID** ProcessHeaps; // 90hPVOID GdiSharedHandleTable; // 94hPVOID ProcessStarterHelper; // 98hPVOID GdiDCAttributeList; // 9ChPVOID LoaderLock; // A0hULONG OSMajorVersion; // A4hULONG OSMinorVersion; // A8hULONG OSBuildNumber; // AChULONG OSPlatformId; // B0hULONG ImageSubSystem; // B4hULONG ImageSubSystemMajorVersion; // B8hULONG ImageSubSystemMinorVersion; // C0hULONG GdiHandleBuffer[0x22]; // C4hPVOID ProcessWindowStation; // ??? }注冊表Registry
注冊表是Windows中的一個重要的基于鍵值對的數(shù)據(jù)庫,用于存儲系統(tǒng)和應用程序的設置、配置信息,可以修改注冊表信息讓特定的程序在特定的時間去運行。
注冊表有三種東西:key(路徑),value name,value data。
其中存放著各種參數(shù),直接控制著windows的啟動、硬件驅(qū)動程序的裝載以及一些windows應用程序的運行。
這些作用包括了軟、硬件的相關配置和狀態(tài)信息,比如注冊表中保存有應用程序和資源管理器外殼的初始條件、首選項和卸載數(shù)據(jù)等,聯(lián)網(wǎng)計算機的整個系統(tǒng)的設置和各種許可,文件擴展名與應用程序的關聯(lián),硬件部件的描述、狀態(tài)和屬性,性能記錄和其他底層的系統(tǒng)狀態(tài)信息,以及其他數(shù)據(jù)等。
具體來說,在啟動Windows時,Registry會對照已有硬件配置數(shù)據(jù),檢測新的硬件信息;系統(tǒng)內(nèi)核從Registry中選取信息,包括要裝入什么設備驅(qū)動程序,以及依什么次序裝入,內(nèi)核傳送回它自身的信息,例如版權號等;
同時設備驅(qū)動程序也向Registry傳送數(shù)據(jù),并從Registry接收裝入和配置參數(shù),一個好的設備驅(qū)動程序會告訴Registry它在使用什么系統(tǒng)資源,例如硬件中斷或DMA通道等,另外,設備驅(qū)動程序還要報告所發(fā)現(xiàn)的配置數(shù)據(jù);
為應用程序或硬件的運行提供增加新的配置數(shù)據(jù)的服務。配合ini文件兼容16位Windows應用程序,當安裝—個基于Windows 3.x的應用程序時,應用程序的安裝程序Setup像在windows中—樣創(chuàng)建它自己的INI文件或在win.ini和system.ini文件中創(chuàng)建入口;
同時windows還提供了大量其他接口,允許用戶修改系統(tǒng)配置數(shù)據(jù),例如控制面板、設置程序等。
如果注冊表受到了破壞,輕則使windows的啟動過程出現(xiàn)異常,重則可能會導致整個windows系統(tǒng)的完全癱瘓。
Windows API
句柄Handle
句柄有點像指針,可以用來引用某個對象或某個內(nèi)存位置,
但它不能用來進行數(shù)學操作,并且它也不總是表示對象地址。
我們可以在程序中使用句柄來引用對象。
調(diào)用CreateWindowEx函數(shù)可以返回一個HWND窗口句柄,
在想對這個窗口做什么時可以使用這個句柄。
C語言
大量的惡意軟件是用C語言編寫。
主函數(shù)
標準C語言的主函數(shù)有2個參數(shù),
int main(int argc, char ** argv)
argc是命令行參數(shù)的個數(shù),包括程序名字本身,
argv是字符串數(shù)據(jù)指針,指向所有的命令行參數(shù)。
這個主函數(shù)所對應的匯編代碼:
004113CE cmp [ebp+argc], 3 ;判斷argc是否等于3 004113D2 jz short loc_4113D8004113D4 xor eax, eax 004113D6 jmp short loc_411414 004113D8 mov esi, esp004113DA push 2 ; MaxCount 004113DC push offset Str2 ; "-r" 004113E1 mov eax, [ebp+argv] ; argv數(shù)組的開始地址被載入eax 004113E4 mov ecx, [eax+4] ; 對eax加上4(這就是偏移)得到argv[1]004113E7 push ecx; Str1 004113E8 call strncmp 004113F8 test eax, eax 004113FA jnz short loc_411412 004113FC mov esi, esp ; 如果命令行中有-r,則這里會被執(zhí)行 004113FE mov eax, [ebp+argv] 00411401 mov ecx, [eax+8] ; 童年各國argv[]偏移8來獲得argv[2] 00411404 push ecx ; lpFileName 00411405 call DeleteFileA為什么偏移量是4,因為argv[]中每條記錄都是一個指向字符串的地址,而在32位系統(tǒng)中,每個地址都是4字節(jié)長。
C語言函數(shù)
int strncmp(char str1, char str2, size_t n)
把str1和str2進行比較,最多比較前n個字節(jié)。
如果返回值 < 0,則表示 str1 小于 str2。
如果返回值 > 0,則表示 str2 小于 str1。
如果返回值 = 0,則表示 str1 等于 str2。
wsprintf
wsprintf()將一系列的字符和數(shù)值輸入到緩沖區(qū)。
輸出緩沖區(qū)里的的值取決于格式說明符(即"%")。
格式化作用
如果寫入的是文字,
此函數(shù)給寫入的文字的末尾追加一個’\0’。
函數(shù)的返回值是寫入的長度,但不包括最后的’\0’。
%d 格式化為十進制有符號整數(shù)輸出到緩沖區(qū)
%ld格式化為十進制有符號長整型數(shù)輸出到緩沖區(qū)
%i,li 等同 %d,%ld
%u 格式化為十進制無符號整數(shù)輸出到緩沖區(qū)
%lu格式化為十進制無符號長整型數(shù)輸出到緩沖區(qū)
%s 格式化為字符串輸出到緩沖區(qū)
%c 格式化為單個字符輸出到緩沖區(qū)
%x 格式化為無符號以十六進制表示的整數(shù)(a-f小寫輸出)輸出到緩沖區(qū)
%X 格式化為無符號以十六進制表示的整數(shù)(A-F大寫輸出)輸出到緩沖區(qū)
%0 格式化為無符號以八進制表示的整數(shù)輸出到緩沖區(qū)
%p 格式化為十六進制指針地址輸出到緩沖區(qū)
Ix 在64位上格式化為無符號以十六進制表示的長整型數(shù),在32位上格式化為無符號以十六進制表示的整型數(shù)(a-f小寫輸出)
IX 在64位上格式化為無符號以十六進制表示的長整型數(shù),在32位上格式化為無符號以十六進制表示的整型數(shù)(a-f大寫寫輸出)
strcmp 字符串比較函數(shù)
strcmp函數(shù)是string compare(字符串比較)的縮寫,用于比較兩個字符串并根據(jù)比較結果返回整數(shù)。基本形式為strcmp(str1,str2),若str1=str2,則返回零;若str1<str2,則返回負數(shù);若str1>str2,則返回正數(shù)。
lstrcmp
函數(shù)功能:比較兩個字符串,此比較不區(qū)分大小寫。
函數(shù)原型:int lstrcmp(LPCTSTR lpString1,LPCTSTR lpString2);
參數(shù):
lpString1:指向?qū)⒈槐容^的第一個字符串。
lpString2:指向?qū)⒈槐容^的第二個字符串。
返回值:若第一個字符串比第二個字符串小則返回值為負;若第一個字符串比第二個字符串大則返回值為正;若兩個字符串相等則返回值為0。將被比較的第二個字符串。
memcmp 比較函數(shù)
將參數(shù)1減去參數(shù)2,如果結果是0代表字符串相同。
malloc 分配內(nèi)存空間
send 發(fā)送
atoi
把字符串轉(zhuǎn)換成整型數(shù)
ascii to integer
對抗反匯編
在程序中使用一些特殊構造的代碼或數(shù)據(jù),
讓反匯編分析工具產(chǎn)生不正確的程序代碼。
這種技術是由惡意軟件作者親手構造,
他們使用對抗反匯編技術來延緩或阻止分析人員,
在惡意代碼貶義和部署階段使用一個單獨的混淆工具,
或是直接在源代碼中插入混淆代碼。
反匯編算法可以分為2種:
線性反匯編算法(容易實現(xiàn),容易出錯),
面向代碼流的反匯編算法。
線性反匯編算法:
遍歷一個代碼段,一次一條指令的線性反匯編,
從不偏離。
ShellCode
ShellCode是一段用于利用軟件漏洞而執(zhí)行的代碼,ShellCode為16進制的機器碼,因為經(jīng)常讓攻擊者獲得shell而得名。
ShellCode常常使用機器語言編寫。
可在寄存器EIP溢出后,塞入一段可讓CPU執(zhí)行的ShellCode機器碼,讓電腦可以執(zhí)行攻擊者的任意指令。
4. 高級動態(tài)分析
在程序運行時去看機器碼,
可以在debugger中運行,
可以一步一步的去debug,
看惡意軟件的內(nèi)部狀態(tài)。
高價靜+高級動可以搞定大部分疑難雜癥。
未完待續(xù)。
名詞解釋
Manifest
Manifest是個XML的描述文件,對于每個DLL有DLL的Manifest文件,對于每個應用程序Application也有自己的Manifest。
對于應用程序而言,Manifest可以是一個和exe文件同一目錄下的.manifest文件,也可以是作為一個資源嵌入在exe文件內(nèi)部的(Embed Manifest)。
XP以前版本的windows,會像以前那樣執(zhí)行這個exe文件,尋找相應的dll,沒有分別Manifest只是個多余的文件或資源,dll文件會直接到system32的目錄下查找,并且調(diào)用。
這樣,如果公共DLL升級,將會導致之前安裝的應用程序不能使用,這就是“DLL Hell”的來源。
為了解決這個問題,.NET開發(fā)提出了side-by-by的開發(fā)方法,來避免這個問題。
主要方法,就是通過Manifest文件來查找相應的DLL。XP及以后的系統(tǒng)都集成了這樣一種查找DLL的方法。
默認Manifest文件都是內(nèi)嵌在exe/dll中的。
EXE調(diào)用DLL的過程
以下針對鏈接MFCxx.dll, MSVCPXX.DLL, MSVCRxx.dll的程序。
系統(tǒng)啟動exe時,會先檢查其Manifest文件(如果沒有查找到當前EXE中有Manifest,則會報“程序配置不正確的”的錯誤提示),查找系統(tǒng)中是否有注冊相應的Dll組件。如果有,則會去c:\windows\winsxs\Manifest文件夾根據(jù)相應的調(diào)用策略及Manifest文件,然后再根據(jù)Manifest中的內(nèi)容去c:\windows\winsxs同名文件夾中查找到關的DLL。
如果沒有查找到相應的DLL,則會到當前目錄來查找Microsoft.VC80.CRT.manifest和Microsoft.VC80.MFC.manifest。
如果沒有查找到當前EXE中有Manifest,則會報“程序配置不正確的”的錯誤提示。查到之后,就會去找相應的DLL。然后執(zhí)行程序。
選擇性看:
This is where your three options for requestedExecutionLevel start to come out:
asInvoker: The application will run with the same permissions as the process that started it. The application can be elevated to a higher permission level by selecting Run as Administrator.
highestAvailable: The application will run with the highest permission level that it can. If the user who starts the application is a member of the Administrators group, this option is the same as requireAdministrator. If the highest available permission level is higher than the level of the opening process, the system will prompt for credentials.
requireAdministrator: The application will run with administrator permissions. The user who starts the application must be a member of the Administrators group. If the opening process is not running with administrative permissions, the system will prompt for credentials.
https://docs.microsoft.com/en-us/windows/win32/sbscs/application-manifests
Dynamic analysis enables us to see when it calls them
What sequence it is done in
But also potentially what parameters they have.
軟件
普通軟件
每個軟件只能提供一小部分幫助,
因此要靈活綜合運用各種軟件,才能達到最終效果。
不要被某個點卡住,嘗試其他工具或方法,不同的角度去分析。
Sysinternals
Sysinternals之前為Winternals公司提供的免費工具,Winternals原本是一間主力產(chǎn)品為系統(tǒng)復原與資料保護的公司,為了解決工程師平常在工作上遇到的各種問題,便開發(fā)出許多小工具。
之后他們將這些工具集合起來稱為Sysinternals,并放在網(wǎng)絡供人免費下載,其中也包含部分工具的原始碼,一直以來都頗受IT專家社群的好評。
Sysinternals Suite包含一系列免費的系統(tǒng)工具,其中有大名鼎鼎的Process Explorer、FileMon、RegMon等,如果把系統(tǒng)管理員比喻成戰(zhàn)士的話,那么Sysinternals Suite就是我們手中的良兵利器。
熟悉和掌握這些工具,并且對Windows的體系有一定的了解,將大幅度的提高日常的診斷和排錯能力。
UPX
UPX(the Ultimate Packer for eXecutables)是一個非常全面的可執(zhí)行文件壓縮軟件,支持 dos/exe、dos/com、dos/sys、djgpp2/coff、 watcom/le、win32/pe、rtm32/pe、tmt/adam、atari/tos、linux/i386 等幾乎所有平臺上的可執(zhí)行文件,具有極佳的壓縮比,還可以對未壓縮的文件和壓縮完后進行比較。
可以pack與unpack。
惡意軟件
WannaCry
WannaCry(又叫Wanna Decryptor),一種“蠕蟲式”的勒索病毒軟件,大小3.3MB,由不法分子利用NSA(National Security Agency,美國國家安全局)泄露的危險漏洞“EternalBlue”(永恒之藍)進行傳播 [1] 。
勒索病毒肆虐,儼然是一場全球性互聯(lián)網(wǎng)災難,給廣大電腦用戶造成了巨大損失。最新統(tǒng)計數(shù)據(jù)顯示,100多個國家和地區(qū)超過10萬臺電腦遭到了勒索病毒攻擊、感染。 [2] 勒索病毒是自熊貓燒香以來影響力最大的病毒之一。WannaCry勒索病毒全球大爆發(fā),至少150個國家、30萬名用戶中招,造成損失達80億美元,已經(jīng)影響到金融,能源,醫(yī)療等眾多行業(yè),造成嚴重的危機管理問題。中國部分Windows操作系統(tǒng)用戶遭受感染,校園網(wǎng)用戶首當其沖,受害嚴重,大量實驗室數(shù)據(jù)和畢業(yè)設計被鎖定加密。部分大型企業(yè)的應用系統(tǒng)和數(shù)據(jù)庫文件被加密后,無法正常工作,影響巨大。
Cobalt Strike
https://www.jianshu.com/p/8d823adbc6b5
Cobalt Strike一款以Metasploit為基礎的GUI框架式滲透測試工具,集成了端口轉(zhuǎn)發(fā)、服務掃描,自動化溢出,多模式端口監(jiān)聽,exe、powershell木馬生成等。
一款工具,可以幫你測試系統(tǒng),
也可以幫你攻擊系統(tǒng)。
釣魚攻擊包括:站點克隆,目標信息獲取,
java執(zhí)行,瀏覽器自動攻擊等。
Cobalt Strike 主要用于團隊作戰(zhàn),可謂是團隊滲透神器,能讓多個攻擊者同時連接到團體服務器上,共享攻擊資源與目標信息和sessions。
Cobalt Strike 作為一款協(xié)同APT工具,針對內(nèi)網(wǎng)的滲透測試和作為apt的控制終端功能,使其變成眾多APT組織的首選。
SolarWinds
https://www.4hou.com/posts/pBk6
https://www.microsoft.com/security/blog/2021/01/20/deep-dive-into-the-solorigate-second-stage-activation-from-sunburst-to-teardrop-and-raindrop
IT管理軟件提供商SolarWinds,
是一家美國上市公司,網(wǎng)絡安全管理軟件產(chǎn)品。
微軟宣布將從今天開始,強制屏蔽和隔離已知含有Solorigate(sunburst)惡意軟件的SolarWindsOrion應用版本。上周末,多家媒體報道稱有俄羅斯政府背景的黑客組織入侵了SolarWinds,并在網(wǎng)絡監(jiān)控和庫存平臺Orion更迭版本中插入了惡意軟件。
在之前已經(jīng)確認黑客攻擊了IT管理軟件提供商SolarWinds的網(wǎng)絡,并用惡意軟件Sunburst感染了Orion應用程序的封包服務器。部署Orion應用程序的1.8萬個SolarWinds客戶都有潛在風險。
SolarWinds網(wǎng)絡安全管理軟件產(chǎn)品,
SolarWinds正在改變各類規(guī)模的企業(yè)監(jiān)控和管理其企業(yè)網(wǎng)絡的方式。
2020年12月14日,據(jù)路透社和《華盛頓郵報》報道,SolarWinds旗下的Orion網(wǎng)絡監(jiān)控軟件更新服務器遭黑客入侵并植入惡意代碼,導致美國財政部、商務部等多個政府機構用戶受到長期入侵和監(jiān)視,
甚至可能與上周曝出的FireEye網(wǎng)絡武器庫被盜事件有關。
SolarWinds供應鏈攻擊已經(jīng)導致許多美國政府機構和私營公司破產(chǎn)。
我們努力為大家提供經(jīng)濟,易于使用,
實施快速和高度有效的軟件產(chǎn)品。
這就是為什么全球有超過45,000用戶,
不論是小公司還是全球500強企業(yè),
都信任和使用我們的解決方案來探索,配置,監(jiān)控和管理日趨復雜的系統(tǒng)和構建網(wǎng)絡基礎構架的流程。
網(wǎng)絡安全公司賽門鐵克指出,從 SolarWinds 供應鏈攻擊中找到了第四款惡意軟件并將其命名為 Raindrop。之前找到的三款惡意軟件是 Sunspot、Sunburst (Solorigate) 和 Teardrop。
Solorigate(Sunburst)
一種惡意軟件
Solorigate攻擊
Teardrop
一種惡意軟件
賽門鐵克公司表示,Raindrop 僅用于入侵的最后階段,僅部署于少數(shù)精選的幾個目標網(wǎng)絡中。迄今為止,僅從調(diào)查案例中找到4個 Raindrop 樣本。
RainDrop
一種惡意軟件
Raindrop的發(fā)現(xiàn)是SolarWinds攻擊的重要一步,
到目前為止,
發(fā)現(xiàn)了四個Raindrop樣本用于交付Cobalt Strike Beacon,這是一個內(nèi)存后門,
能夠?qū)崿F(xiàn)執(zhí)行命令、鍵盤記錄、文件傳輸、權限提升、端口掃描和橫向移動等多種功能。
要了解 Raindrop 在這些攻擊活動中的角色和位置,我們必須首先梳理下整個 SolarWinds 事件的時間線。
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-KBeSkWZ6-1630045249059)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p420)]
從微軟、火眼、CrowdStrike 和其它公司提供的信息可知,SolarWinds 攻擊事件應該發(fā)生在2019年年中,當時黑客(被指和俄羅斯之間存在關聯(lián))攻陷了位于美國德克薩斯州的軟件廠商 SolarWinds 的內(nèi)網(wǎng)。
入侵者首先部署了 Sunspot 惡意軟件,專攻 SolarWinds 公司內(nèi)網(wǎng)。CrowdStrike 公司指出攻擊者利用 Sunspot 修改 SolarWinds Orion app 的 build 進程并將 Sunburst (Solorigate) 惡意軟件放在 IT 存儲管理系統(tǒng) Orion 的新版本中。
這些被木馬化的 Orion 版本未被檢測到并在2020年3月至6月期間活躍于 SolarWinds 的官方更新服務器中。應用了 Orion 更新的企業(yè)也在毫不知情的情況下將 Sunburst 惡意軟件安裝在系統(tǒng)中。
但 Sunburst 并不復雜且除了收集受感染網(wǎng)絡的信息并發(fā)送給一臺遠程服務器外并未做太多的事情。即使約1.8萬名 SolarWinds 客戶受 Sunburst 感染,但黑客仔細挑選了目標并選擇僅在少數(shù)幾個案例中提升攻擊,如美國政府機構、微軟或安全公司火眼等高層次目標。
當黑客決定“提升訪問權限”時,他們使用 Sunburst 下載并安裝 Teardrop 惡意軟件。
https://blog.csdn.net/smellycat000/article/details/112914568
一些資料
我如何能遠程控制一臺計算機?
我如何能寫一個最簡單的病毒?
https://www.isolves.com/it/aq/hk/
暗網(wǎng),洋蔥路由網(wǎng)絡
tor networking
onion routing protocol
洋蔥路由協(xié)議
http://www.xinhuanet.com//2017-07/21/c_1121360325.htm
并不是完全匿名,誰控制了exit nodes,
誰就可以控制網(wǎng)絡流量,
密碼可以被軟件所破解。
操作系統(tǒng)
gnome
DDOS攻擊需要配合在服務器內(nèi)安裝一個rookit一起使用,效果更好。
每次服務器重啟都會導致病毒自我復制之后讓服務器死機,
如何看系統(tǒng)日志?
如何獲得一臺局域網(wǎng)內(nèi)電腦的控制權?
來路不明的下載可能讓自己變成肉雞。
黑客通過未知網(wǎng)站下載、共享文件下載、釣魚郵件中的木馬或攻擊系統(tǒng)漏洞的腳本等手段去獲取機器的控制權,
這些機器可以是Mac,Windows,甚至智能手機,
之后把所有被感染的機器組織到一個網(wǎng)絡中,形成僵尸網(wǎng)絡,這個網(wǎng)絡中可能存在成百上千甚至幾百萬臺機器,
這些機器被感染后往往用戶無法察覺,繼續(xù)正常使用,
黑客可以遠程遙控這些機器,去做一些事情,
例如:
DDOS攻擊,挖礦,傳播病毒,網(wǎng)絡詐騙,垃圾郵件,網(wǎng)絡釣魚,個人隱私數(shù)據(jù)被盜,造成被勒索或身份盜用,出租或出售僵尸機器的等等。
被感染的機器可能會出現(xiàn)如下情況:
陡增的網(wǎng)絡流量,性能降低,CPU不穩(wěn)定等等。
基本攻擊
1、HTTP協(xié)議Content Lenth限制漏洞導致拒絕服務攻擊
使用POST方法時,可以設置ContentLenth來定義需要傳送的數(shù)據(jù)長度,例如ContentLenth:999999999,在傳送完成前,內(nèi) 存不會釋放,攻擊者可以利用這個缺陷,連續(xù)向WEB服務器發(fā)送垃圾數(shù)據(jù)直至WEB服務器內(nèi)存耗盡。這種攻擊方法基本不會留下痕跡。
2、為了提高用戶使用瀏覽器時的性能,現(xiàn)代瀏覽器還支持并發(fā)的訪問方式,瀏覽一個網(wǎng)頁時同時建立多個連接,以迅速獲得一個網(wǎng)頁上的多個圖標,這樣能更快速完成整個網(wǎng)頁的傳輸。HTTP1.1中提供了這種持續(xù)連接的方式,而下一代HTTP協(xié)議:HTTP-NG更增加了有關會話控制、豐富的內(nèi)容協(xié)商等方式的支持,來提供更高效率的連接。
黑客可以利用郵件,比如把郵件地址設置為和你公司郵件域名特別像的域名,給你發(fā)一個攜帶病毒的鏈接,當你點擊的時候(放心,你會點擊的),你的電腦就會自動下載病毒,病毒正式控制你的電腦,而你不自知。 這臺電腦正式成為一個僵尸主機。僵尸網(wǎng)絡本身不是一個物理上的概念,而是指所有被感染的主機組成的全集,是一個邏輯上概念。 一旦你的主機被感染,那么黑客就可以為所欲為了,你懂的,嘿嘿嘿。 曾經(jīng)有一個例子(某一合法活動),用戶被這種方式攻破后,黑客在這臺主機里發(fā)現(xiàn)了所有業(yè)務系統(tǒng)的賬號密碼以及使用手冊(有些用戶就這么傻),黑客只需要按照這些手冊就可以把所有的業(yè)務系統(tǒng)輪一遍,所有的數(shù)據(jù)全都可以被拿到,或者刪除,或者下載。
[1]實際上,真實的網(wǎng)絡犯罪分子會通過漏洞正面進攻沒有及時打補丁的脆弱系統(tǒng),也會通過木馬病毒側面進攻缺乏網(wǎng)絡安全意識的人,從而獲得計算機系統(tǒng)的控制權限,簡稱“肉雞”或“僵尸主機”。那么黑客控制了成百上千臺“僵尸主機”之后,他會做什么事情呢?這就涉及到僵尸網(wǎng)絡的應用場景,最常見的應該是DDoS分布式拒絕服務。舉一個不恰當?shù)睦?#xff0c;生活中我們搶口罩、搶紅包、搶優(yōu)惠券,總是搶不到,為什么呢?因為資源是有限的,而競爭者卻太多了。拒絕服務的本質(zhì)和其是類似的,都是通過搶占資源,來迫使服務不可正常使用,僵尸網(wǎng)絡發(fā)起的拒絕服務攻擊,瞬間就可以使中小企業(yè)的網(wǎng)站癱瘓。
另一個常見的僵尸網(wǎng)絡應用場景是垃圾郵件,因為郵件很傻的保護了發(fā)送者的真實地址,為犯罪分子提供了無形的保護傘,而垃圾郵件往往伴隨著惡意軟件、木馬病毒的二次傳播,更有釣魚郵件會誘導身份證、銀行卡密碼等隱私泄漏。然鵝,這僅僅是僵尸網(wǎng)絡應用的冰山一角,站在網(wǎng)絡安全研究員的立場上,對僵尸網(wǎng)絡還是太缺乏想象。您或許會有疑問?為什么會有人沒去談戀愛,沒去玩游戲,而是花費大好時光去攻擊你的計算機或手機呢?不妨試試換位思考,你知道惡意軟件的創(chuàng)作者都是什么樣的人嗎?他們又是如何從中牟取暴利的?
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-sFRmGbY8-1630045249060)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p419)]
1萬臺“肉雞”可以發(fā)送450萬個數(shù)據(jù)包,
占用4.5G的帶寬,
能夠讓絕大多數(shù)網(wǎng)站處于癱瘓的狀態(tài),
這些“肉雞”組成了一個中等的僵尸網(wǎng)絡。
網(wǎng)吧僵尸網(wǎng)絡攻擊1個違法的千年私服,試一下。
網(wǎng)吧豈不是僵尸網(wǎng)絡的溫床。
一些文件
exe
svchost.exe
svchost.exe通常是services.exe的子進程,
如果是獨立存在是高度可疑的。
winlogon.exe
Windows Logon Process(即winlogon.exe),是Windows NT 用戶登陸程序,用于管理用戶登錄和退出。該進程的正常路徑應是C:\Windows\System32,且是以 SYSTEM 用戶運行,若不是以上路徑且不以 SYSTEM 用戶運行,則可能是 W32.Netsky.D@mm 蠕蟲病毒,該病毒通過 EMail 郵件傳播,當你打開病毒發(fā)送的附件時,即會被感染。winlogon.exe是潛在被入侵的受害者。
explorer.exe
桌面主程序
wupdmgr.exe
wupdmgr.exe是windows update manger的縮寫,是自動升級的程序,存在于c:\windows\system32下,被刪除或被重命名后能立即自動生成。
winup.exe
(infecter.undef.65501)是一款infecter被感染文件,infecter作為傳統(tǒng)的病毒技術之一,至今仍廣泛地使用。
由于infecter類型病毒是通過被感染文件傳播的,病毒母體一般無法追查。infecter病毒的危害性主要體現(xiàn)在一旦中毒,
大量文件被感染,在安全廠商未推出解決方案之前,用戶不得不重新下載并安裝軟件。
dll
Kernel32.dll
This is a very common DLL that contains core functionality, such as access and manipulation of memory, files, and hardware.
Kernel32.dll顧名思義就是內(nèi)核相關的功能,
主要包含用于管理內(nèi)存、進程和線程的函數(shù);
Advapi32.dll
This DLL provides access to advanced core Windows components such as the Service Manager and Registry.
User32.dll
This DLL contains all the user-interface components, such as buttons, scroll bars, and components for controlling and responding to user actions.
User32.dll中包含的則是用于執(zhí)行用戶界面任務的函數(shù),比如把用戶的鼠標點擊操作傳遞給窗口,以便窗口根據(jù)用戶的點擊來執(zhí)行預定的事件;
Gdi32.dll
This DLL contains functions for displaying and manipulating graphics.
GDI32.dll的名稱用了縮寫,全稱是Graphical Device Interface(圖形設備接口),包含用于畫圖和顯示文本的函數(shù),比如要顯示一個程序窗口,就調(diào)用了其中的函數(shù)來畫這個窗口。
Ntdll.dll
This DLL is the interface to the Windows kernel. Executables generally do not import this file directly, although it is always imported indirectly by Kernel32.dll. If an executable imports this file, it means that the author intended to use functionality not normally available to Windows programs. Some tasks, such as hiding functionality or manipulating processes, will use this interface.
WSock32.dll and Ws2_32.dll
These are networking DLLs. A program that accesses either of these most likely connects to a network or performs network-related tasks.
Wininet.dll
This DLL contains higher-level networking functions that implement protocols such as FTP, HTTP, and NTP.
sfc_os.dll
關閉Windows文件保護的一種方式
psapi.dll
psapi.dll是Windows系統(tǒng)進程狀態(tài)支持模塊。
urlmon.dll
urlmon.dll是微軟Microsoft對象鏈接和嵌入相關模塊。通常情況下是在安裝操作系統(tǒng)過程中自動創(chuàng)建的,對于系統(tǒng)正常運行來說至關重要。在正常情況下不建議用戶對該類文件(urlmon.dll)進行隨意的修改。它的存在對維護計算機系統(tǒng)的穩(wěn)定具有重要作用。
常見Windows函數(shù)
GetModleFileName
返回進程名(包含路徑)
GetModuleBaseName
返回進程名(不包含路徑)
IsProcessorFeaturePresent
用于獲取當前電腦是否支持指定處理器功能特性
獲取系統(tǒng)中支持的x86處理器的特性
lstrcpy(LPWSTR lpString1, LPCWSTR lpString2)
拷貝字符串,
把第2個字符串的內(nèi)容拷貝到第1個字符串。
common Win32 API calls
這里沒有的話要去MSDN查。
createDirectory
創(chuàng)建目錄
CreateProcessA
創(chuàng)建其他進程,注意程序運行后是否啟動了其他程序。
CreateFile
WriteFile
可能在某個位置創(chuàng)建一個文件,我們要思考,
創(chuàng)建了什么文件,文件里包含了什么。
MoveFile
移動文件,我們需要思考,哪個文件被移動了。移動到哪里?
ReadFile
CopyFile
DeleteFile
操作文件
FindFirstFileW
查找到目錄下的第一個文件或目錄
FindNextFileW
查找下一文件或目錄
FindFirstFile/FindNextFile
Used to search through a directory and enumerate the filesystem.
RegisterClassExW
SetWindowTextW
ShowWindow
圖形化界面操作f
SetWindowsHookExW
可用于合法或間諜軟件,鍵盤記錄器,在調(diào)用SetWindowsHookEx的函數(shù)中指定指向鉤子子程的指針。
LowLevelKeyboardProc,LowLevelMouseProc
跟SetWindowsHookEx一起使用的回調(diào)函數(shù),
每次有新的鍵盤鼠標輸入事件時,系統(tǒng)會調(diào)用該它們。
LowLevelKeyboardProc與LowLevelMouseProc函數(shù)是由SetWindowsHookExW函數(shù)用于指定當鍵盤鼠標事件發(fā)生時調(diào)用哪個函數(shù)。
Hook Procedure有點像事件監(jiān)聽器,一旦它們被注冊,當特定事件發(fā)生時,它們會被調(diào)用,LowLevelKeyboardProc是一個響應鍵盤動作的hook。
為什么在這個例子中農(nóng),LowLevelKeyboardProc與LowLevelMouseProc被設置成導出函數(shù)呢?
-這是因為這個函數(shù)是由惡意軟件dll導出的,因此它們可以被系統(tǒng)自動掃描、導入。
Windows的各個進程的地址空間是相互隔離的,所以一個進程代碼是無法到另一個進程的地址空間去運行的.但是通過在進程中安裝全局鉤子的方法,鉤子函數(shù)所在的DLL就有可能被操作系統(tǒng)加載到其它進程的地址空間中去,進而實現(xiàn)了DLL注入.實現(xiàn)了DLL注入之后,這個DLL的代碼就可以在另一個進程的地址空間里做任何事.
下面簡單介紹一下利用鉤子注入DLL的步驟
1.調(diào)用SetWindowsHookEx安裝系統(tǒng)范圍內(nèi)的鉤子.
2.將鉤子函數(shù)的實現(xiàn)寫在DLL里
這樣,其它接收與這個鉤子相關消息的進程就會自動加載這個鉤子函數(shù)所在的DLL,從而實現(xiàn)了DLL注入.
Windows的鉤子Hook也是用來鉤東西的,比較抽象的是他是用來鉤Windows事件或者消息的。最常見的就是鼠標和鍵盤鉤子,用Hook鉤子鉤住鼠標、鍵盤,當你的鼠標、鍵盤有任何操作時,通過Hook就能知道他們都做了什么了。我們可以在同一個鉤子上掛很多東西。
應用程序可以在相應的鉤子Hook上設置多個鉤子子程序(Hook Procedures),由其組成一個與鉤子相關聯(lián)的指向鉤子函數(shù)的指針列表(鉤子鏈表)。當鉤子所監(jiān)視的消息出現(xiàn)時,Windows首先將其送到調(diào)用鏈表中所指向的第一個鉤子函數(shù)中,鉤子函數(shù)將根據(jù)其各自的功能對消息進行監(jiān)視、修改、控制,,并在處理完成后把消息傳遞給下一鉤子函數(shù),直至到達鉤子鏈表的末尾。在鉤子函數(shù)交出控制權后,被攔截的消息最終仍將交還給窗口處理函數(shù)。
http://blog.sina.com.cn/s/articlelist_1585708262_3_1.html
RegisterHotKey
注冊快捷鍵(例如Ctrl+Shift+P),用戶觸發(fā)后,無論在干什么,都立刻將用戶帶到注冊了快捷鍵的應用程序。
RegCloseKey
RegDeleteValueW
RegOpenCurrentUser
RegOpenKeyExW
RegQueryValueExW
RegCreateKey
創(chuàng)建注冊表的key,此時value是空的。
RegSetValue
設置注冊表的value(value name + value data)
注冊表相關,需要去搜一下字符串,
有沒有注冊表鍵值,
類似于文件目錄/xxx/xxx/xxx
Software\Microsoft\Windows\CurrentVersion\Run,惡意軟件常用,控制windows啟動時會自動裝載哪些程序。
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-w4E370Fq-1630045249061)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p427)]
accept
Used to listen for incoming connections. This function indicates that the program will listen for incoming connections on a socket.
OpenProcessToken+AdjustTokenPrivileges+SeDebugPrivilege+LookupPrivilegeValue,可以4個連著一起用,出現(xiàn)在惡意軟件中,比較經(jīng)典,用來確保有權限去調(diào)用某些函數(shù)。
OpenProcessToken
函數(shù)用來打開與進程相關聯(lián)的訪問令牌。得到進程的令牌句柄。
AdjustTokenPrivileges
Used to enable or disable specific access privileges. Malware that performs process injection often calls this function to gain additional permissions.
SeDebugPrivilege權限
By default, users can debug only processes that they own. In order to debug processes owned by other users, you have to possess the SeDebugPrivilege privilege. But don’t grant this privilege casually, because once you do, you gave away the farm. If you let users debug processes owned by other users, then they can debug processes owned by System, at which point they can inject code into the process and perform the logical equivalent of net localgroup administrators anybody /add, thereby elevating themselves (or anybody else) to administrator.
LookupPrivilegeValue
函數(shù)查看系統(tǒng)權限的特權值,返回信息到一個LUID結構體里。
AttachThreadInput
Attaches the input processing for one thread to another so that the second thread receives input events such as keyboard and mouse events. Keyloggers and other spyware use this function.
bind
Used to associate a local address to a socket in order to listen for incom- ing connections.
BitBlt
Used to copy graphic data from one device to another. Spyware some- times uses this function to capture screenshots. This function is often added by the compiler as part of library code.
CallNextHookEx
Used within code that is hooking an event set by SetWindowsHookEx. CallNextHookEx calls the next hook in the chain. Analyze the function calling CallNextHookEx to determine the purpose of a hook set by SetWindowsHookEx.
CertOpenSystemStore
Used to access the certificates stored on the local system.
CheckRemoteDebuggerPresent
Checks to see if a specific process (including your own) is being debugged. This function is sometimes used as part of an anti-debugging technique.
CoCreateInstance
Creates a COM object. COM objects provide a wide variety of functional- ity. The class identifier (CLSID) will tell you which file contains the code that implements the COM object. See Chapter 7 for an in-depth explanation of COM.
connect
Used to connect to a remote socket. Malware often uses low-level func- tionality to connect to a command-and-control server.
ConnectNamedPipe
Used to create a server pipe for interprocess communication that will wait for a client pipe to connect. Backdoors and reverse shells sometimes use ConnectNamedPipe to simplify connectivity to a command-and-control server.
ControlService
Used to start, stop, modify, or send a signal to a running service. If mal- ware is using its own malicious service, you’ll need to analyze the code that implements the service in order to determine the purpose of the call.
CreateFile
Creates a new file or opens an existing file.
CreateFileMapping
Creates a handle to a file mapping that loads a file into memory and makes it accessible via memory addresses. Launchers, loaders, and injec- tors use this function to read and modify PE files.
CreateMutex
Creates a mutual exclusion object that can be used by malware to ensure that only a single instance of the malware is running on a system at any given time. Malware often uses fixed names for mutexes, which can be good host-based indicators to detect additional installations of the malware.
OpenMutex
Opens a handle to a mutual exclusion object that can be used by malware to ensure that only a single instance of malware is running on a system at any given time. Malware often uses fixed names for mutexes, which can be good host-based indicators.
引入互斥量的概念,
保證同一時間只有一個實例在系統(tǒng)中運行。
The program creates a Mutex to ensure only one instance is running
CreateProcess
Creates and launches a new process. If malware creates a new process, you will need to analyze the new process as well.
CreateService
Creates a service that can be started at boot time. Malware uses CreateService for persistence, stealth, or to load kernel drivers.
創(chuàng)建服務,每次系統(tǒng)啟動后都會運行。
CreateToolhelp32Snapshot
Used to create a snapshot of processes, heaps, threads, and modules. Malware often uses this function as part of code that iterates through processes or threads.
Process32First/Process32Next
Used to begin enumerating processes from a previous call to CreateToolhelp32Snapshot. Malware often enumerates through processes to find a process to inject into.
OpenProcess
Opens a handle to another process running on the system. This handle can be used to read and write to the other process memory or to inject code into the other process.用于打開要寄生的目標進程。
GetCurrentProcess
獲取當前進程的一個偽句柄
GetProcessHeap
CreateRemoteThread
Used to start a thread in a remote process (one other than the calling process). Launchers and stealth malware use CreateRemoteThread to inject code into a different process and inject DLL.遠程加載DLL的核心內(nèi)容,用于控制目標進程調(diào)用API函數(shù)。創(chuàng)建遠程線程。
那我們要思考,是對哪個進程下手?之后調(diào)用什么?
WriteProcessMemory
Used to write data to a remote process. Malware uses WriteProcessMemory as part of process injection.用于在目標進程中寫入要加載的DLL名稱。
VirtualAllocEx
A memory-allocation routine that can allocate memory in a remote process. Malware sometimes uses VirtualAllocEx as part of process injection.用于在目標進程中分配/釋放內(nèi)存空間。
一般是CreateRemoteThread+WriteProcessMemory+VirtualAllocEx作配合,來創(chuàng)建空間,但如果沒有調(diào)用WriteProcessMemory+VirtualAllocEx,也沒有傳遞DLL名稱,那我們怎么知道CreateRemoteThread調(diào)用什么呢?我們只能用WriteProcessMemory。DLL必須已經(jīng)加載進受害者的線程中。
LocalAlloc
局部內(nèi)存對象的分配
從堆中分配指定大小的字節(jié)數(shù)
uBytes:[in]指定要分配的字節(jié)數(shù)。
uFlags:[in] Specifies how to allocate memory. If zero is specified, the default is the LMEM_FIXED flag. The following table shows possible values.
GlobalAlloc
全局內(nèi)存對象的分配
LocalFree
釋放局部內(nèi)存對象并使句柄失效
CryptAcquireContext
Often the first function used by malware to initialize the use of Windows encryption. There are many other functions associated with encryption, most of which start with Crypt.
CryptGenKey
https://docs.microsoft.com/en-us/previous-versions/aa925731(v=msdn.10)
This function generates a random cryptographic session key or a public/private key pair for use with the cryptographic service provider (CSP). The function retrieves a handle to the key in the phKey parameter. This handle can then be used as needed with any of the other CryptoAPI functions requiring a key handle.
When calling this function, the application must specify the algorithm. Because this algorithm type is kept bundled with the key, the application does not need to specify the algorithm later when the actual cryptographic operations are performed.
CryptEncrypt
https://docs.microsoft.com/en-us/previous-versions/aa925235(v=msdn.10)
This function encrypts data. The key held by the cryptographic service provider (CSP) and referenced by the hKey parameter specifies the algorithm used to encrypt the data parameter.
CryptImportKey
https://docs.microsoft.com/en-us/previous-versions/aa919782(v=msdn.10)
導入秘鑰
將密鑰從BLOB轉(zhuǎn)換到CSP中
CryptExportKey
https://docs.microsoft.com/en-us/previous-versions/windows/embedded/ms884452(v=msdn.10)
This function exports cryptographic keys from of a cryptographic service provider (CSP) in a secure manner.
The caller passes to the CryptImportKey function a handle to the key to be exported and gets a key binary large object (BLOB). This key BLOB can be sent over a nonsecure transport or stored in a nonsecure storage location. The key BLOB is useless until the intended recipient uses the CryptImportKey function, which imports the key into the recipient’s CSP.
DeviceIoControl
Sends a control message from user space to a device driver. DeviceIoControl is popular with kernel malware because it is an easy, flexible way to pass information between user space and kernel space.
DllCanUnloadNow
An exported function that indicates that the program implements a COM server.
DllGetClassObject
An exported function that indicates that the program implements a COM server.
DllInstall
An exported function that indicates that the program implements a COM server.
DllRegisterServer
An exported function that indicates that the program implements a COM server.
DllUnregisterServer
An exported function that indicates that the program implements a COM server.
EnableExecuteProtectionSupport
An undocumented API function used to modify the Data Execution Pro- tection (DEP) settings of the host, making it more susceptible to attack.
EnumProcesses
Used to enumerate through running processes on the system. Malware often enumerates through processes to find a process to inject into.
枚舉進程并輸入進程名和句柄,會返回給我們進程ID的集合。
EnumProcessModules
Used to enumerate the loaded modules (executables and DLLs) for a given process. Malware enumerates through modules when doing injection.
GetVolumeInformation
獲取磁盤驅(qū)動器與文件系統(tǒng)等相關信息
FindWindow
Searches for an open window on the desktop. Sometimes this function is used as an anti-debugging technique to search for OllyDbg windows.
FtpPutFile
A high-level function for uploading a file to a remote FTP server.
GetAdaptersInfo
Used to obtain information about the network adapters on the system. Backdoors sometimes call GetAdaptersInfo as part of a survey to gather information about infected machines. In some cases, it’s used to gather MAC addresses to check for VMware as part of anti-virtual machine techniques.
GetAsyncKeyState
Used to determine whether a particular key is being pressed. Malware sometimes uses this function to implement a keylogger.
GetDC
Returns a handle to a device context for a window or the whole screen. Spyware that takes screen captures often uses this function.
GetForegroundWindow
Returns a handle to the window currently in the foreground of the desktop. Keyloggers commonly use this function to determine in which window the user is entering his keystrokes.
gethostbyname
Used to perform a DNS lookup on a particular hostname prior to making an IP connection to a remote host. Hostnames that serve as command- and-control servers often make good network-based signatures.
gethostname
Retrieves the hostname of the computer. Backdoors sometimes use gethostname as part of a survey of the victim machine.
GetKeyState
Used by keyloggers to obtain the status of a particular key on the keyboard.
GetModuleFilename
Returns the filename of a module that is loaded in the current process. Malware can use this function to modify or copy files in the currently running process.
GetModuleHandle
Used to obtain a handle to an already loaded module. Malware may use GetModuleHandle to locate and modify code in a loaded module or to search for a good location to inject code.
GetStartupInfo
Retrieves a structure containing details about how the current process was configured to run, such as where the standard handles are directed.
GetSystemDefaultLangId
Returns the default language settings for the system. This can be used to customize displays and filenames, as part of a survey of an infected victim, or by “patriotic” malware that affects only systems from certain regions.
獲取系統(tǒng)默認語言信息
GetWindowsDirectory
Returns the file path to the Windows directory (usually C:\Windows). Malware sometimes uses this call to determine into which directory to install additional malicious programs.
GetTempPath
Returns the temporary file path. If you see malware call this function, check whether it reads or writes any files in the temporary file path.
SHGetSpecialFolderPath
獲取系統(tǒng)路徑
GetThreadContext
Returns the context structure of a given thread. The context for a thread stores all the thread information, such as the register values and current state.
GetTickCount
Retrieves the number of milliseconds since bootup. This function is sometimes used to gather timing information as an anti-debugging tech- nique. GetTickCount is often added by the compiler and is included in many executables, so simply seeing it as an imported function provides little information.
GetVersionEx
Returns information about which version of Windows is currently run- ning. This can be used as part of a victim survey or to select between dif- ferent offsets for undocumented structures that have changed between different versions of Windows.
獲取系統(tǒng)版本信息
IsDebuggerPresent
Checks to see if the current process is being debugged, often as part of an anti-debugging technique. This function is often added by the com- piler and is included in many executables, so simply seeing it as an imported function provides little information.
IsNTAdmin
Checks if the user has administrator privileges.
IsWoW64Process
Used by a 32-bit process to determine if it is running on a 64-bit operat- ing system.
LdrLoadDll
Low-level function to load a DLL into a process, just like LoadLibrary. Normal programs use LoadLibrary, and the presence of this import may indicate a program that is attempting to be stealthy.
LoadLibrary
Loads a DLL into a process that may not have been loaded when the program started. Imported by nearly every Win32 program.
目標進程通過調(diào)用此函數(shù)來加載病毒DLL
GetProcAddress
Retrieves the address of a function in a DLL loaded into memory. Used to import functions from other DLLs in addition to the functions imported in the PE file header.
通過其他DLL文件引入新的函數(shù)使用
GetProcAddress+LoadLibrary表示嘗試調(diào)用一些DLL的函數(shù)。那我們要思考,哪些DLL會被動態(tài)加載?之后會調(diào)用哪些函數(shù)。
LoadResource
Loads a resource from a PE file into memory. Malware sometimes uses resources to store strings, configuration information, or other malicious files.
FindResource
Used to find a resource in an executable or loaded DLL. Malware sometimes uses resources to store strings, configuration information, or other malicious files. If you see this function used, check for a .rsrc section in the malware’s PE header.
SizeofResource
aaa
LsaEnumerateLogonSessions
Enumerates through logon sessions on the current system, which can be used as part of a credential stealer.
MapViewOfFile
Maps a file into memory and makes the contents of the file accessible via memory addresses. Launchers, loaders, and injectors use this function to read and modify PE files. By using MapViewOfFile, the malware can avoid using WriteFile to modify the contents of a file.
MapVirtualKey
Translates a virtual-key code into a character value. It is often used by keylogging malware.
MmGetSystemRoutineAddress
Similar to GetProcAddress but used by kernel code. This function retrieves the address of a function from another module, but it can only get addresses from ntoskrnl.exe and hal.dll.
Module32First/Module32Next
Used to enumerate through modules loaded into a process. Injectors use this function to determine where to inject code.
NetScheduleJobAdd
Submits a request for a program to be run at a specified date and time. Malware can use NetScheduleJobAdd to run a different program. As a mal- ware analyst, you’ll need to locate and analyze the program that will be run in the future.
NetShareEnum
Used to enumerate network shares.
NtQueryDirectoryFile
Returns information about files in a directory. Rootkits commonly hook this function in order to hide files.
NtQueryInformationProcess
Returns various information about a specified process. This function is sometimes used as an anti-debugging technique because it can return the same information as CheckRemoteDebuggerPresent.
NtSetInformationProcess
Can be used to change the privilege level of a program or to bypass Data Execution Prevention (DEP).
OleInitialize
Used to initialize the COM library. Programs that use COM objects must call OleInitialize prior to calling any other COM functions.
OpenSCManager
Opens a handle to the service control manager. Any program that installs, modifies, or controls a service must call this function before any other service-manipulation function.
OutputDebugString
Outputs a string to a debugger if one is attached. This can be used as an anti-debugging technique.
PeekNamedPipe
Used to copy data from a named pipe without removing data from the pipe. This function is popular with reverse shells.
QueryPerformanceCounter
Used to retrieve the value of the hardware-based performance counter. This function is sometimes using to gather timing information as part of an anti-debugging technique. It is often added by the compiler and is included in many executables, so simply seeing it as an imported func- tion provides little information.
QueueUserAPC
Used to execute code for a different thread. Malware sometimes uses QueueUserAPC to inject code into another process.
ReadProcessMemory
Used to read the memory of a remote process.
recv
Receives data from a remote machine. Malware often uses this function to receive data from a remote command-and-control server.
RegisterHotKey
Used to register a handler to be notified anytime a user enters a partic- ular key combination (like CTRL-ALT-J), regardless of which window is active when the user presses the key combination. This function is some- times used by spyware that remains hidden from the user until the key combination is pressed.
RegOpenKey
Opens a handle to a registry key for reading and editing. Registry keys are sometimes written as a way for software to achieve persistence on a host. The registry also contains a whole host of operating system and application setting information.
ResumeThread
Resumes a previously suspended thread. ResumeThread is used as part of several injection techniques.
RtlCreateRegistryKey
Used to create a registry from kernel-mode code.
RtlWriteRegistryValue
Used to write a value to the registry from kernel-mode code.
SamIConnect
Connects to the Security Account Manager (SAM) in order to make future calls that access credential information. Hash-dumping programs access the SAM database in order to retrieve the hash of users’ login passwords.
SamIGetPrivateData
Queries the private information about a specific user from the Security Account Manager (SAM) database. Hash-dumping programs access the SAM database in order to retrieve the hash of users’ login passwords.
SamQueryInformationUse
Queries information about a specific user in the Security Account Man- ager (SAM) database. Hash-dumping programs access the SAM database in order to retrieve the hash of users’ login passwords.
send
Sends data to a remote machine. Malware often uses this function to send data to a remote command-and-control server.
SetFileTime
Modifies the creation, access, or last modified time of a file. Malware often uses this function to conceal malicious activity.
SetThreadContext
Used to modify the context of a given thread. Some injection techniques use SetThreadContext.
SetWindowsHookEx
Sets a hook function to be called whenever a certain event is called. Commonly used with keyloggers and spyware, this function also provides an easy way to load a DLL into all GUI processes on the system. This function is sometimes added by the compiler.
SfcTerminateWatcherThread
Used to disable Windows file protection and modify files that otherwise would be protected. SfcFileException can also be used in this capacity.
ShellExecute
Used to execute another program. If malware creates a new process, you will need to analyze the new process as well.
運行一個外部程序,或者打開一個已注冊的文件、打開一個目錄、打印文件等等功能,它可以打開電腦內(nèi)的任何文件,也可以打開URL。
StartServiceCtrlDispatcher
Used by a service to connect the main thread of the process to the service control manager. Any process that runs as a service must call this func- tion within 30 seconds of startup. Locating this function in malware tells you that the function should be run as a service.
SuspendThread
Suspends a thread so that it stops running. Malware will sometimes sus- pend a thread in order to modify it by performing code injection.
system
Function to run another program provided by some C runtime libraries. On Windows, this function serves as a wrapper function to CreateProcess.
Thread32First/Thread32Next
Used to iterate through the threads of a process. Injectors use these functions to find an appropriate thread to inject into.
Toolhelp32ReadProcessMemory
Used to read the memory of a remote process.
URLDownloadToFile
A high-level call to download a file from a web server and save it to disk. This function is popular with downloaders because it implements all the functionality of a downloader in one function call. 如果有這個函數(shù),則需要看一下字符串里是否有URL,如果有的話,很可能是從這里下載的。但我們要考慮,這個文件下載后會寫在哪里?
VirtualProtectEx
Changes the protection on a region of memory. Malware may use this function to change a read-only section of memory to an executable.
WideCharToMultiByte
Used to convert a Unicode string into an ASCII string.
WinExec
Used to execute another program. If malware creates a new process, you will need to analyze the new process as well.執(zhí)行可執(zhí)行文件,我們要思考,哪個進程被開始新執(zhí)行?
WlxLoggedOnSAS (and other Wlx* functions)
A function that must be exported by DLLs that will act as authentication modules. Malware that exports many Wlx* functions might be performing Graphical Identification and Authentication (GINA) replacement, as discussed in Chapter 11.
Wow64DisableWow64FsRedirection
Disables file redirection that occurs in 32-bit files loaded on a 64-bit sys- tem. If a 32-bit application writes to C:\Windows\System32 after calling this function, then it will write to the real C:\Windows\System32 instead of being redirected to C:\Windows\SysWOW64.
WSAStartup
Used to initialize low-level network functionality. Finding calls to
WSAStartup can often be an easy way to locate the start of network- related functionality.
GetCurrentProcessId
GetCurrentThreadId
都不是惡意的
CloseHandle
關閉句柄,幾乎哪里都用了,沒有太多分析價值。
網(wǎng)絡
inet_addr
Converts an IP address string like 127.0.0.1 so that it can be used by func- tions such as connect. The string specified can sometimes be used as a network-based signature.
InternetOpen
Initializes the high-level Internet access functions from WinINet, such as InternetOpenUrl and InternetReadFile. Searching for InternetOpen is a good way to find the start of Internet access functionality. One of the parameters to InternetOpen is the User-Agent, which can sometimes make a good network-based signature.
可以設置用于通信的User-Agent字段。
InternetOpenUrl
Opens a specific URL for a connection using FTP, HTTP, or HTTPS. URLs, if fixed, can often be good network-based signatures.
打開一個文件句柄
InternetCloseHandle
關閉已經(jīng)打開的文件句柄
InternetReadFile
Reads data from a previously opened URL.
從打開的句柄中獲取相關的數(shù)據(jù)
InternetWriteFile
Writes data to a previously opened URL.
InternetGetConnectedState
獲取系統(tǒng)網(wǎng)絡連接狀態(tài),
有可用的網(wǎng)絡連接就返回true或1,
否則返回false或0。
導出函數(shù)
ServiceMain,
代碼需要安裝一個服務,使其能夠正常運行。
常見CMD命令
sc delete MySQL
刪除MySQL服務
taskkill -f -im
taskkill是Windows命令行里終止指定程序“進程”的命令。 /f 表示強制終止 /im 表示指定的進程名稱,例如“explor.exe" 如果不使用名稱,使用進程號,則用/PID,例如(假設已知道某進程的PID號是3352,PID號可以在windows任務管理器中查看): taskkill /f /pid 3352
tasklist
列出任務列表分
其他資料
匯編
http://www.ruanyifeng.com/blog/2018/01/assembly-language-primer.html
錄播課
https://moodle.nottingham.ac.uk/mod/page/view.php?id=4850840;
https://moodle.nottingham.ac.uk/pluginfile.php/7236075/mod_resource/content/0/2020.COMP4101.04.Lab02.pdf
https://moodle.nottingham.ac.uk/pluginfile.php/7236075/mod_resource/content/0/2020.COMP4101.04.Lab02.pdf
B站大學
https://www.bilibili.com/video/BV1e4411r7VP?p=1
https://blog.csdn.net/qq_44370676
https://search.bilibili.com/all?keyword=%E6%B1%87%E7%BC%96&from_source=nav_suggest_new
https://blog.csdn.net/baidu_41108490/article/details/80323492
https://blog.csdn.net/baidu_41108490/article/details/80298973
https://blog.csdn.net/m0_37442062/article/details/102926761
刪完注冊表之后,想重現(xiàn)注冊表,
需要重啟Windows Explorer。
xxx.DLL有若干個導入導出函數(shù),想在動態(tài)分析時運行這個DLL,如何確定選擇哪個函數(shù)當做rundll32.exe的參數(shù)?
If xxx.DLL has several import and export functions, and I want to dynamic analysis and run this DLL, how could I be sure which function is suitable for the parameter of rundll32.exe when I wanna run this DLL?
You would need to identify the functions which can be run from your static analysis (e.g. via Dependency Walker)
32位文件?64位文件?
我們現(xiàn)在的VM上有快照嗎?怎么回滾?沒有
W/A suffix是什么?
這些也是函數(shù)嗎?
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-fFDtWDjx-1630045249062)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p452)]
C++的庫都是以下劃線開頭的
__crtTerminateProcess
C Runtime library,用C語言編程,
在你的代碼運行之前,你需要初始化全局變量或全局變量類型等,你需要用到C Runtime library。
官方電子版
https://ebookcentral.proquest.com/lib/nottingham/reader.action?docID=1137570
Practical Malware Analysis Lab7,9,11
https://blog.csdn.net/qq_35713009/article/details/88388609
https://malware-guide.com/blog/how-to-remove-guesswho-file-extension-ransomware
https://www.pcrisk.com/removal-guides/15384-guesswho-ransomware#creating-data-backups
沒有絕對的分析順序,都是根據(jù)線索去理清自己的思路。
基礎靜態(tài)分析
【綜合】
【判斷文件是否加殼加密?】
- 使用PEiD與VirusTotal雙保險,看是否有提示,Microsoft Visual C++不是加殼標識;
- 使用PEview或VirusTotal,看節(jié)名稱是否為UPX0,UPX1,UPX2,如果是的話代表被加殼,沒有名字的節(jié)也代表被加殼。此外,節(jié)中虛擬大小遠超過原始大小,代表是加殼的;
- 導入函數(shù)特別少,不超過10個(Hello World也會比這個多一些),有可能是加殼的,超過10個導入函數(shù)少代表是小程序;
- UPX脫殼命令:upx -o xxx.exe -d Lab01-02.exe
- size比大小
【字符串里的東西】
即使是加過殼的文件也有可能字符串是沒有被混淆過的,
是可讀的,因此無論是否加殼都要先看一下字符串。
-
里面有xxx.exe,代表可能對.exe文件進行操作,可能是受害者,被攻擊的對象,目標文件,一些類似以OpenProcess的操作可能都是針對這個xxx.exe的;
-
有公網(wǎng)IP或網(wǎng)址代表是網(wǎng)絡傳播惡意軟件,字符串里可能用障眼法1和l來迷惑我們,字符串里有的信息可以幫助你去檢查被感染機器內(nèi)的線索,例如Malservice等自定義關鍵字;
-
路徑信息可能是注冊表的key;
【檢查脫殼后的信息】
主要是看導入導出函數(shù)以及字符串
- 通過導入導出函數(shù)來推測其功能和含義,使用Dependency Walker和VirusTotal來查看導入導出函數(shù),kernel32.dll與msvcrt.dll幾乎被每個文件導入,LoadResource、FindResource、SizeofResource表示對資源進行操作or對數(shù)據(jù)進行提取,訪問.rsrc分區(qū)中的數(shù)據(jù),此刻我們要考慮,是什么樣的數(shù)據(jù),這些數(shù)據(jù)代表了什么,這些提取出來的數(shù)據(jù)可以被新建成1個新文件之后完全當成1個新的程序來運行(嵌入在里面的可執(zhí)行文件)。使用Resource Hacker打開文件,如果是二進制內(nèi)容,但有一行"This program cannot be run in DOS mode",這個是在所有PE文件頭都會包含的錯誤信息,這表示在這個文件中包含了另一個文件,使用Action->save resource as binary file存儲,之后再用PEview等去分析,WinExec執(zhí)行磁盤上的可執(zhí)行文件,碰到涉及到注冊表的函數(shù),可以搜一下字符串,看是否有相關的注冊表鍵值;
如果是靜態(tài)分析,先看DLL的導入函數(shù)列表,
例如先看kernel32.dll,把一些感興趣的函數(shù)記錄下來,
例如:OpenProcess,CreateRemoteThread,(LoadLibrary,GetProcAddress),WinExec,CreateFile,WriteFile,(LoadResource,FindResource,SizeofResource ),MoveFile,GetWindowsDirectory,GetTempPath。
然后記筆記,查筆記。
之后看看有沒有對注冊表進行操作的函數(shù)調(diào)用。 (如果沒有操作注冊表的話就不會使用注冊表來進行持久化)
之后是觀察字符串,拋掉之前看到的函數(shù)名與DLL名,我們還可以看到一些有趣的東西,
例如:winlogon.exe,可能是CreateRemoteThread的潛在受害者。
sfc_os.dll,可疑
SeDebugPrivilege,惡意軟件通過獲得SeDebugPrivilege來確保有權限調(diào)用CreateRemoteThread。
OpenProcessToken+AdjustTokenPrivileges+SeDebugPrivilege+LookupPrivilegeValue,可以4個連著一起用,出現(xiàn)在惡意軟件中,比較經(jīng)典,用來確保有權限去調(diào)用某些函數(shù)。
\system32\wupdmgr.exe,
可以猜測跟前面的GetWindowsDirectory,
GetTempPath有關,可能用這2個函數(shù)在system32路徑中用wupdmgr.exe做些什么壞事。
%s%s,跟printf有關
之后把整理出來的信息整合一下,
來推測出惡意軟件都做了什么?
EnumProcessModules
psapi.dll
GetModuleBaseNameA
psapi.dll
EnumProcesses
psapi.dll
貌似好像在通過EnumProcesses搜索一個特定的進程,搜索進程中的modules。
我們要考慮是什么進程,winlogon.exe? wupdmgr.exe? winup.exe? wupdmgrd.exe?
我猜可能是winlogon.exe,
因為EnumProcesses會返回給我們進程ID的集合,
通過進程ID我們可以調(diào)用OpenProcess來得到句柄,通過句柄我們可以調(diào)用GetModuleBaseName,可以得到進程的BaseName。
wupdmgr.exe可能不是,
因為文件名是作為路徑的一部分。
winup.exe可能不是,
原因同上,并且后面有%s%s。
wupdmgrd.exe可能不是,原因同上。
在字符串中,這句話出現(xiàn)2次是非常奇怪的: !This program cannot be run in DOS mode. 在字符串中,第2次出現(xiàn)這個的地方下面很可能是一個全新的可執(zhí)行文件, 可能存在文件嵌套的情況。
一般的套路:先建1個文件,再把它寫在某個地方。
用其他的可執(zhí)行文件替換windows update manager(wupdmgr.exe)可以進行持久化。
基本動態(tài)分析
動態(tài)分析后回告訴你字符串里的東西與導入函數(shù)是如何被使用的。
【前置準備工作】
0. 先進行靜態(tài)分析;
【開始運行】
點擊運行惡意軟件,運行一段時間后(不要太短)。。。
如果是DLL則需要用rundll32.exe
使用Process Explorer來確定rundll32.exe已經(jīng)停止,不在進程列表中了,這時再做第2個快照。
【運行結束】
可能出現(xiàn)安裝xxx服務,
那就需要再用net start xxx啟動服務,
在注冊表的values中能看到,DLL文件需要依賴一個EXE文件去運行,會運行在xxx.eve中,
需要查看每個相關進程直到找到當前dll,或者用Process Explorer的Find DLL來搜索。(Lab03-02.dll)
顯示的服務名為Intranet Network Awareness (INA+),描述為“Depends INA+, Col- lects and stores network configuration and location information, and notifies applications when this information changes.”
被安裝咋注冊表:HKLM\SYSTEM\CurrentControlSet\Services\IPRIP\ Parameters\ServiceDll: %CurrentDirectory%\xxx.dll
高級靜態(tài)分析
函數(shù)有2種,一種是引入的,一種是自定義的。
鏈到IDA pro章節(jié)
開啟Ida pro的自動注釋和機器碼功能,非常有用。
如果遇到一個函數(shù)中只有xor、or、and、shl、ror、shr、rol這樣的指令,并且反復出現(xiàn),看起來隨機排列,可能遇到了一個加密或壓縮函數(shù),不用看細節(jié),直接跳出來,繼續(xù)后面的分析。
有的程序太大太復雜,
千萬不要一個指令一個指令的找線索,非常浪費時間,
把握整體,抽象成塊狀結構,可以只看call指令。
在IDA pro文本模式下的左側箭頭代表跳轉(zhuǎn),
向上箭頭代表循環(huán),
如果是實線表示一定會發(fā)生,
如果是虛線表示可能會發(fā)生(有條件)。
在分析dll文件時,導出函數(shù)列表非常有用。
看到可疑的字符串與函數(shù)時時,可以用IDA pro的交叉引用,看哪些地方調(diào)用了。
子過程函數(shù)內(nèi)部的開頭部分會有局部變量或者參數(shù),
如果跟著的整數(shù)是正數(shù)則表示是參數(shù),
負數(shù)表示是局部變量。
可以在IDA pro中對一些數(shù)值進行轉(zhuǎn)換,
可以轉(zhuǎn)化成2、8、10、16進制、符號等等,
只要在數(shù)值上按右鍵即可。
使用IDA Pro,1個機器碼是16進制形式,每個機器碼都占1個內(nèi)存位置,
例如:
.text:004012BC 52
.text:004012BD 6A 01
.text:004012BF 8B 85 FC FE FF
尋址時,在32位下,+1就是往后定位1個機器碼
反抗反匯編
需要打開左側的機器碼顯示功能。
將程序中不合理的地方調(diào)整為正常代碼。
尋址帶加號的數(shù)字都要看看,不是+4,+8的那種,
+1,+2的那種是無效地址,因為位于2條指令中間。
jz short near ptr unk_40126D
jnz short near ptr unk_40126D
【相同目標的跳轉(zhuǎn)指令】
2個緊挨著的跳轉(zhuǎn)指令跳轉(zhuǎn)到相同的位置,
把光標放在40126D地址處,
在IDA Pro按D鍵,轉(zhuǎn)換成數(shù)據(jù)的形式。
call near ptr CB4C550XX
call的地址感覺是荒謬的,不可跳轉(zhuǎn)的,
把光標放在地址處,在IDA Pro按D鍵,轉(zhuǎn)換成數(shù)據(jù)的形式。(IDA會標紅)
jmp short near ptr loc_401215+1
jmp要跳轉(zhuǎn)的地方緊挨著自己
把光標放在401215地址處,
在IDA Pro按D鍵,轉(zhuǎn)換成數(shù)據(jù)的形式,
跳過某個幾個的機器碼(+幾就跳幾),
在IDA Pro按C鍵,轉(zhuǎn)換成代碼的形式。
test esp, esp
jnz short near ptr loc_401010+1
xor eax, eax
jz short near ptr loc_401010+1
【固定條件的跳轉(zhuǎn)指令】
跳轉(zhuǎn)到一段指令的中間位置(那個+1)是很不正常的,
把光標放在401010地址處,
在IDA Pro按D鍵,轉(zhuǎn)換成數(shù)據(jù)的形式。
要跳過,機器碼
db 0E8h(理論上EB代表call,在E8后面緊跟著的內(nèi)容就是目的地。E8的出現(xiàn)是為了欺騙反匯編器的陷阱)
db 0E9h (jmp)
db 0EBh
db 8Bh
db 45h
db 0Ch
db 0Fh
沒有對齊,一直轉(zhuǎn)換到一條指令挨著一條指令,
在IDA Pro按C鍵,轉(zhuǎn)換成代碼的形式。
此外還有一些稀奇古怪的東西也可以用C鍵:
db 824648Bh, 0A164h等等
jz short near ptr loc_4012E6+2
向上跳轉(zhuǎn),跳轉(zhuǎn)到了當前位置上面的位置
先看4012E6的機器碼,假如是66 B8 EB 05,
把光標放在4012E6地址處,
在IDA Pro按D鍵,轉(zhuǎn)換成數(shù)據(jù)的形式,
因為是+2,因此跳過66 B8,之后將其余部分
db轉(zhuǎn)化成代碼,
在IDA Pro按C鍵,轉(zhuǎn)換成代碼的形式。
轉(zhuǎn)化完成的代碼中可能包含一些多出來的機器碼,
這些機器碼會阻礙IDA把一段代碼轉(zhuǎn)化成圖形形式,
可以用90這個機器碼(Null)來把它們弄掉,
需要編寫idc腳本。
一些常見指令
3行指令可以是組合起來做1件事情。
一些約定:
EAX通常存儲了一個函數(shù)的返回值,看到一個函數(shù)調(diào)用后立刻使用EAX,可能是在操作返回值。
EBP通常引用局部變量、傳進來的參數(shù)。
EBP通常引用局部變量、傳進來的參數(shù)。
EBP是個基指針,在一個函數(shù)中會保持不變,
因此程序可以使用它作為占位符來跟蹤局部變量和參數(shù)的位置。
ESP是棧指針,包含了指向棧頂?shù)膬?nèi)存地址,
數(shù)據(jù)被壓入或彈出棧時,ESP的值相應改變。
乘法與除法指令只能使用EAX與EDX。
清理棧,調(diào)用windowsAPI不需要清理棧,
相應的DLL程序會負責清理棧。
ascii_stricmp是實現(xiàn),文檔跟stricmp一樣。
cmp [ebp+argc], 3 ; argc是個參數(shù),[ebp+argc]表示參數(shù)開始地址,與3進行比較。push 2 push offset Str2 ;"-r"mov eax, [ebp+argv] ; 數(shù)組的開始地址被加載進EAXmov ecx, [eax+4] ; 對eax里保存的內(nèi)存地址加4做偏移, ; 獲得數(shù)組里第2個下標,加8就是第3個下標。push ecx ; Str1 ; strncmp(argv[1], "-r", 2)在指令中的dword_40CF60表示變量存儲在,
0x40CF60這個內(nèi)存地址中。
2個全局變量相加,需要將x先復制到eax,
之后在eax上加y,再把eax復制回x。
全局變量通過內(nèi)存地址引用:
int x = 1; int y = 2; void main() {x = x+y;printf("Total = %d\n", x); }mov eax, dword_40CF60 # 全局變量x通過dword_40CF60來標記,在0x40CF60處的內(nèi)存位置。 add eax, dword_40C000 # 全局變量y通過dword_40C000來標記,實行x+y。 mov dword_40CF60, eax # 把x+y賦值給x mov ecx, dword_40CF60 # 裝載成參數(shù),準備壓入棧中 push ecx push offset aTotalD ;"total = %d\n" call printf局部變量通過棧地址引用:
void main(){int x = 1;int y = 2;x = x+y;printf("Total = %d\n", x); }# 未標記 mov dword ptr [ebp-4], 0 mov dword ptr [ebp-8], 1 mov eax, [ebp-4] add eax, [ebp-8] mov [ebp-4], eax mov ecx, [ebp-4] push ecx push offset aTotalD ; "total = %d\n" call printf# 標記后 mov [ebp+var_4], 0 mov [ebp+var_8], 1 mov eax, [ebp+var_4] add eax, [ebp+var_8] mov [ebp+var_4], eax mov ecx, [ebp+var_4] push ecx push offset aTotalD ; "total = %d\n" call printf算數(shù)運算:
int a = 0; int b = 1; a = a + 11; a = a - b; a--; b++; b = a % 3;mov [ebp+var_4], 0 mov [ebp+var_8], 1 mov eax, [ebp+var_4] add eax, 0Bh # 11轉(zhuǎn)成16進制是0B。mov [ebp+var_4], eaxmov ecx, [ebp+var_4] sub ecx, [ebp+var_8] mov [ebp+var_4], ecxmov edx, [ebp+var_4] sub edx,1 mov [ebp+var_4], edxmov eax, [ebp+var_8] add eax,1 mov [ebp+var_8], eaxmov eax, [ebp+var_4] cdq mov ecx, 3 idiv ecx mov [ebp+var_8], edxif跳轉(zhuǎn),對于跳轉(zhuǎn)最好是看圖形化界面,更容易理解:
int x = 1; int y = 2; if(x == y){printf("x equals y.\n"); }else{printf("x is not equal to y.\n"); }mov [ebp+var_8], 1 mov [ebp+var_4], 2 mov eax, [ebp+var_8] cmp eax, [ebp+var_4] jnz short loc_40102B # 如果x!=y,則跳轉(zhuǎn)會發(fā)生,否則不會發(fā)生。 push offset aXEqualsY_ ; "x equals y.\n" call printf add esp, 4 jmp short loc_401038 # 無條件跳轉(zhuǎn) loc_40102B: push offset aXIsNotEqualToY ; "x is not equal to y.\n" call printf嵌套if:
int x = 0; int y = 1; int z = 2; if(x == y){if(z==0){printf("z is zero and x = y.\n"); }else{printf("z is non-zero and x = y.\n");} }else{if(z==0){printf("z zero and x != y.\n"); }else{printf("z non-zero and x != y.\n"); } }# 詳略循環(huán):
int i; for(i=0; i<100; i++) {printf("i equals %d\n", i); }mov [ebp+var_4], 0 # 初始化i jmp short loc_401016 loc_40100D: mov eax, [ebp+var_4] add eax, 1 mov [ebp+var_4], eax # i自增1 loc_401016: cmp [ebp+var_4], 64h # 比較i與100,16進制的64=10進制的100 jge short loc_40102F # 如果不符合條件就跳出循環(huán)mov ecx, [ebp+var_4] push ecx push offset aID ; "i equals %d\n" call printf # 打印i add esp, 8 jmp short loc_40100D # 跳轉(zhuǎn)回去繼續(xù)循環(huán)你[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-GguZbCuc-1630045249063)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p473)]
while循環(huán):
int status=0; int result = 0; while(status == 0){result = performAction(); status = checkResult(result); }mov [ebp+var_4], 0 mov [ebp+var_8], 0 loc_401044: cmp [ebp+var_4], 0 jnz short loc_401063 call performAction mov [ebp+var_8], eax mov eax, [ebp+var_8] push eax call checkResult add esp, 4 mov [ebp+var_4], eax jmp short loc_401044nop
什么都不做,當它出現(xiàn)時,直接執(zhí)行下一條指令,
這條指令的opcode是0x90,可以起到填充代碼的作用,
降低shellcode可能在中間部分開始執(zhí)行所造成的風險。
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-TXnmd8eh-1630045249064)(evernotecid://BCE3D193-8584-4CB1-94B3-46FF37A1AC6C/appyinxiangcom/12192613/ENResource/p468)]
call
把call指令的下一條指令的地址入棧,調(diào)用函數(shù),函數(shù)執(zhí)行完畢后,執(zhí)行ret指令,將返回地址彈出到棧的頂部,并將它載入指令指針寄存器中,執(zhí)行剛好返回到call后面的指令。
pop edi
將棧頂?shù)膬?nèi)容出棧并保存在edi寄存器。
PTR 運算符可以用來重寫一個已經(jīng)被聲明過的操作數(shù)的大小類型。只要試圖用不同于匯編器設定的大小屬性來訪問操作數(shù),那么這個運算符就是必需的。
注意,PTR 必須與一個標準匯編數(shù)據(jù)類型一起使用,這些類型包括:BYTE、SEYTE、WORD、SWORD、DWORD、SDWORD、FWORD、QWORD 或 TBYTE。
將較小的值送入較大的目的操作數(shù)
lodsb 指令:從esi指向的源地址中逐一讀取一個字符,送入AL中; (然后,可以先判斷這個字符是什么字符,如0dh,0ah之類等,再執(zhí)行相應的操作);
匯編語言中,串操作指令LODSB/LODSW是塊裝入指令,其具體操作是把SI指向的存儲單元讀入累加器,LODSB就讀入AL,LODSW就讀入AX中,然后SI自動增加或減小1或2.其常常是對數(shù)組或字符串中的元素逐個進行處理。
(1) lodsb、lodsw:把DS:SI指向的存儲單元中的數(shù)據(jù)裝入AL或AX,然后根據(jù)DF標志增減SI。
(2) stosb、stosw:把AL或AX中的數(shù)據(jù)裝入ES:DI指向的存儲單元,然后根據(jù)DF標志增減DI
Practical Malware Analysis紙質(zhì)書
每個小節(jié)都會有3個試驗,難度依次提升,
第三個試驗是最難的,第一個是最簡單的。
第2章紙質(zhì)書,建虛擬機,直接忽略掉。
惡意代碼樣本下載,
www.practicalmalwareanalysis.com
https://nostarch.com/malware.htm
虛擬機
不要在自己的機器上去run惡意軟件,
用lab上的VM去run,
把windows自帶的殺毒軟件防火墻關掉,
隨時準備開回來。
用虛擬機可以模擬多種操作系統(tǒng)的版本,
方便做測試。
如果在虛擬機中做動態(tài)分析時,
惡意軟件把系統(tǒng)弄壞了,
可以恢復到上一個快照。
有些病毒知道自己運行在虛擬機中,
則會表現(xiàn)的不一樣。
惡意軟件會偵測到自己是運行在虛擬機中還是真實的系統(tǒng)中,會有一些差異化。
有些病毒會突破虛擬機跑到宿主機上來。
https://en.wikipedia.org/wiki/Virtual_machine_escape
總結
以上是生活随笔為你收集整理的明翰恶意软件分析笔记V0.1(持续更新)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java db4o,有用过db4O的吗?
- 下一篇: 超详细的纯CSS的照片墙特效