-
Notifications
You must be signed in to change notification settings - Fork 1
/
instrfuzz.asm
executable file
·184 lines (149 loc) · 2.72 KB
/
instrfuzz.asm
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
; INSTRFUZZ
;
; Copyright (c) 2024 Nicholas Starke
; https://github.com/nstarke/instrfuzz
;
; run: `bash instrfuzz.sh`
[bits 16]
; MBR boot sector address
org 0x7c00
start:
; vga video mode bios settings
mov al, 0x2
mov ah, 0x12
int 0x10
; vga video memory map
mov ax, 0xb800
mov ds, ax
mov es, ax
; set up code segment
push cs
; set up stack
pop ds
; print banner / options
mov bx, banner_str
call print_string
fuzz:
; print '\r'
mov al, 0xd
call print_letter
; print '\n'
mov al, 0xa
call print_letter
; print "INSN:"
mov bx, insn_str
call print_string
; put random value in ax
call get_random
mov bx, ax
mov [exec_context+6], ax
; get second random value
call get_random
; move second random value into cx.
mov cx, ax
; get third random value
call get_random
; multiply second and third random values to
; redistribute operand ranges.
mul cx
mov [exec_context+4], ax
mov dx, ax
call print_hex
mov dx, bx
call print_hex
jmp exec_context
exec_context:
pusha
nop
nop
nop
nop ; this and the next 3 byte are overwritten
nop ; overwritten
nop ; overwritten
nop ; overwritten
nop
nop
nop
popa
jmp reboot
reboot:
int 0x19
; relies on BIOS Services timer to create
; 'random' values returned in ax.
get_random:
push bx
push cx
push dx
push si
push di
xor ax, ax
in al, (0x40)
mov cl, 2
mov ah, al
in al, (0x40)
pop di
pop si
pop dx
pop cx
pop bx
ret
; Utility functions that aren't very interesting
; Collected from:
; * https://stackoverflow.com/questions/27636985/printing-hex-from-dx-with-nasm
; * https://github.com/nanochess/book8088
print_letter:
pusha
mov ah, 0xe
mov bx, 0xf
int 0x10
popa
ret
print_string:
pusha
print_string_begin:
mov al, [bx]
test al, al
je print_string_end
push bx
call print_letter
pop bx
inc bx
jmp print_string_begin
print_string_end:
popa
ret
print_hex:
pusha
mov si, hex_str
mov cx, 0
next_character:
inc cx
mov bx, dx
and bx, 0xf000
shr bx, 4
add bh, 0x30
cmp bh, 0x39
jg add_7
add_character_hex:
mov [si], bh
inc si
shl dx, 4
cmp cx, 4
jnz next_character
jmp _done
_done:
mov bx, hex_str
call print_string
popa
ret
add_7:
add bh, 0x7
jmp add_character_hex
hex_str:
db "0000", 0x0
banner_str:
db "Instructionfuzz By Nick Starke (https://github.com/nstarke)", 0xa, 0xd, 0xa
insn_str:
db "INSN:0x", 0x0
times 510-($-$$) db 0
db 0x55,0xaa