需要環境
- python2.7
- IDA 7.0
- Bochs2.6.9
- nasm.exe(可選)
調試步驟
第一步,建立Img檔案
首先需要安裝Bochs模拟器,打開安裝目錄,運作
bximage.exe
,選擇1,然後一路回車,直到出現
Press any key to continue
安裝目錄下會出現一個
c.img
硬碟鏡像檔案
第二步,将MBR檔案,寫入IMG檔案
我這裡先使用nasm.exe把一個用彙編寫的mbr程式編譯成
bin
檔案,如果是有樣本的情況下,直接取出感染的
mbr
部分儲存成檔案即可
使用
python
腳本,把編譯好的
mbr
,寫入
img
檔案中
def UpdateImage(imgfile, mbrfile):
"""
Write the MBR code into the disk image
"""
# open image file
f = open(imgfile, "r+b")
if not f:
print "Could not open image file!"
return False
# open MBR file
f2 = open(mbrfile, "rb")
if not f2:
print "Could not open mbr file!"
return False
# read whole MBR file
mbr = f2.read()
f2.close()
# update image file
f.write(mbr)
f.close()
return True
下圖提示,已經寫入成功
第三步,編寫bochsrc配置檔案
在bochs安裝目錄,建立一個模拟器的配置檔案
bochsrc
romimage: file=$BXSHARE/BIOS-bochs-latest
vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest
megs: 16
ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
ata0-master: type=disk, path="c.img", mode=flat, cylinders=20, heads=16, spt=63
boot: disk
然後測試能否正常加載剛剛寫進
c.img
的
mbr
啟動模拟器指令:
bochs.exe -q -f bochsrc
第四步,使用IDA動态調試MBR
把剛才編寫的
bochsrc
檔案,使用
IDA
打開
在MBR程式入口下斷點,然後點
綠色按鈕
啟動調試
調試啟動後,會自動打開mbr模拟器,現在就可以調試mbr了~
參考連結:
- http://www.hexblog.com/?p=103&tdsourcetag=s_pctim_aiomsg
- https://sourceforge.net/projects/bochs/files/
- https://www.nasm.us/pub/nasm/releasebuilds/2.14.03rc2/