bochs 的使用方法
安装bochs
bochs是一个模拟器,ubuntu下安装apt过程如下:
1 | sudo apt install bochs |
另外,也可以通过下载bochs源码自行编译。
使用bochs
这里以创建一个引导文件,并启动bochs为例。
创建一个汇编文件,并使用nasm编译该文件生成boot.bin
- 创建一个boot.asm文件,输入一下内容,参考自bochs使用教程[Linux篇]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19org 07c00h ; 告诉编译器程序加载到 7c00处
mov ax, cs
mov ds, ax
mov es, ax
call DispStr ; 调用显示字符串例程
jmp $ ; 无限循环
DispStr:
mov ax, BootMessage
mov bp, ax ; es:bp = 串地址
mov cx, 16 ; cx = 串长度
mov ax, 01301h ; ah = 13, al = 01h
mov bx, 000ch ; 页号为 0(bh = 0) 黑底红字(bl = 0Ch,高亮)
mov dl, 0
int 10h ; 10h 号中断
ret
BootMessage:
db "Hello, OS world!"
times 510-($-$$) db 0 ; 填充剩下的空间,使生成的二进制代码恰好为
dw 0xaa55 ; 结束标志- 使用
nasm boot.asm -o boot.bin
将以上汇编代码编译成二进制文件
创建一个映像软盘,并将boot.bin写入软盘中
- 使用bximage创建软盘,参考自实现操作系统之环境搭建
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31bximage
========================================================================
bximage
Disk Image Creation Tool for Bochs
$Id: bximage.c 11315 2012-08-05 18:13:38Z vruppert $
========================================================================
Do you want to create a floppy disk image or a hard disk image?
Please type hd or fd. [hd] fd
Choose the size of floppy disk image to create, in megabytes.
Please type 0.16, 0.18, 0.32, 0.36, 0.72, 1.2, 1.44, 1.68, 1.72, or 2.88.
[1.44]
I will create a floppy image with
cyl=80
heads=2
sectors per track=18
total sectors=2880
total bytes=1474560
What should I name the image?
[a.img]
Writing: [] Done.
I wrote 1474560 bytes to a.img.
The following line should appear in your bochsrc:
floppya: image="a.img", status=inserted
ls
a.img- 将第一步生成的boot.bin写入软盘映像a.img中
1
dd if=boot.bin of=a.img bs=512 count=1 conv=notrunc
创建bochs的配置文件
- 创建一个配置文件bochs.rc参考Bochs简易教程
1
2
3
4
5megs:32 # 指定虚拟系统会被分配的内存大小32MB
romimage:flie=/usr/share/bochs/BIOS-bochs-latest #设置加载路径对应真实机器的BIOS
vgaromimage:file=/usr/share/bochs/VGABIOS-lgpl-latest #设置加载路径对应真实机器的VGABIOS
floppya:1_44=a.img,status=inserted # floppya是第一软驱,floppyb是第二软驱。后面标明的是软驱镜像文件的位置(boot.img是自己写的引导加载程序),软盘是否插入
boot: a # 选择所启动的盘符类型使用配置文件启动bochs
- 启动bochs的命令如下
1
2bochs -f bochs.rc
c # 执行c之前,可以下断点,然后调试启动过程练习bochs题目
这一小节待整理
- 0x7c00
- square ctf 2017 - floppy
https://github.com/oh-iowned/ctf-writeups/blob/master/2017/square-ctf/floppy/README.md
http://www.actforit.com/wp/reverse/square-ctf-2017-floppy-web-1000-pts/
- flare on ctf 2018 (侧重逆向)
https://blog.attify.com/flare-on-5-writeup-part9/
https://www.fireeye.com/content/dam/fireeye-www/blog/pdfs/FlareOn5_Challenge12_Solution.pdf
https://emanuelecozzi.net/posts/ctf/flareon-2018-challenge-12-cat-grep-writeup/
https://www.fireeye.com/blog/threat-research/2018/10/2018-flare-on-challenge-solutions.html