-
Notifications
You must be signed in to change notification settings - Fork 1
/
fuzz_dd.py
333 lines (303 loc) · 21.5 KB
/
fuzz_dd.py
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
import time
import random
import argparse
from boofuzz import *
from boofuzz import helpers
from boofuzz import constants
from base.ospf_dd import OSPFDDFuzzer
'''
OSPF DD #1
- 不包含LSA,DD序列号随机
- Options是fuzzable的
'''
class OSPFDDFuzzer_1(OSPFDDFuzzer):
def __init__(self, router_id, area_id, rhost, rpc_port=1234):
super().__init__(router_id, area_id, rhost, rpc_port)
random.seed(time.time())
def do_fuzz(self):
PARAM_ROUTER_ID = self.router_id
PARAM_AREA_ID = self.area_id
s_initialize('ospf_dd')
if s_block_start('IP'):
if s_block_start('IP Header'):
s_byte(value=0x45, name='Version', fuzzable=False) # IPv4
s_byte(value=0xC0, name='TOS', fuzzable=False) # TOS
s_size(block_name='OSPF', length=2, math=lambda x: x + 20, name='Total Length', endian=BIG_ENDIAN, fuzzable=False) # Total Length
s_word(value=0x0000, name='Identification', fuzzable=False) # Identification
s_word(value=0x0000, name='Flags & Fragment Offset', fuzzable=False)
s_byte(value=0x01, name='TTL', fuzzable=False) # TTL
s_byte(value=0x59, name='Protocol', fuzzable=False) # Protocol OSPF
s_checksum(name='Checksum', block_name='IP Header', algorithm='ipv4', endian=BIG_ENDIAN, fuzzable=False) # Checksum
s_dword(value=helpers.ip_str_to_bytes(PARAM_ROUTER_ID), name='Router ID', endian=BIG_ENDIAN, fuzzable=False) # Source IP
s_dword(value=helpers.ip_str_to_bytes(self.rhost), name='Target IP', endian=BIG_ENDIAN, fuzzable=False) # Target IP
s_block_end()
if s_block_start('OSPF'):
if s_block_start('Header'):
s_byte(value=0x02, name='Version', fuzzable=False) # Version OSPFv2
s_byte(value=0x02, name='Type', fuzzable=False) # Packet type Database Description
s_size(block_name='Database Description', length=2, math=lambda x: x + 24, name='Packet Length', endian=BIG_ENDIAN, fuzzable=False) # Packet Length
s_dword(value=helpers.ip_str_to_bytes(PARAM_ROUTER_ID), name='Router ID', endian=BIG_ENDIAN, fuzzable=False) # Router ID
s_dword(value=helpers.ip_str_to_bytes(PARAM_AREA_ID), name='Area ID', endian=BIG_ENDIAN, fuzzable=False) # Area ID
s_checksum(name='Checksum', block_name='OSPF', algorithm='ipv4', endian=BIG_ENDIAN, fuzzable=False) # Checksum
s_word(value=0x0000, name='Autype', endian=BIG_ENDIAN, fuzzable=False) # Autype
s_qword(value=0x00000000, name='Authentication', endian=BIG_ENDIAN, fuzzable=False) # Authentication
s_block_end()
if s_block_start('Database Description'):
s_word(value=1500, name='Interface MTU', endian=BIG_ENDIAN, fuzzable=False) # Interface MTU
s_byte(value=0x02, name='Options', endian=BIG_ENDIAN, fuzzable=True) # Options
s_byte(value=0x07, name='DB Description', endian=BIG_ENDIAN, fuzzable=False) # DB Description
s_dword(name='DD Sequence Number', endian=BIG_ENDIAN, fuzzable=True) # DD Sequence Number
s_block_end()
s_block_end()
s_block_end()
self.session_handle.connect(s_get('ospf_dd'))
self.session_handle.fuzz()
'''
OSPF DD #2
- 包含随机LSA,DD序列号随机
- DB Description是fuzzable的
'''
class OSPFDDFuzzer_2(OSPFDDFuzzer):
def __init__(self, router_id, area_id, rhost, rpc_port=1234):
super().__init__(router_id, area_id, rhost, rpc_port)
random.seed(time.time())
def do_fuzz(self):
PARAM_ROUTER_ID = self.router_id
PARAM_AREA_ID = self.area_id
s_initialize('ospf_dd')
if s_block_start('IP'):
if s_block_start('IP Header'):
s_byte(value=0x45, name='Version', fuzzable=False) # IPv4
s_byte(value=0xC0, name='TOS', fuzzable=False) # TOS
s_size(block_name='OSPF', length=2, math=lambda x: x + 20, name='Total Length', endian=BIG_ENDIAN, fuzzable=False) # Total Length
s_word(value=0x0000, name='Identification', fuzzable=False) # Identification
s_word(value=0x0000, name='Flags & Fragment Offset', fuzzable=False)
s_byte(value=0x01, name='TTL', fuzzable=False) # TTL
s_byte(value=0x59, name='Protocol', fuzzable=False) # Protocol OSPF
s_checksum(name='Checksum', block_name='IP Header', algorithm='ipv4', endian=BIG_ENDIAN, fuzzable=False) # Checksum
s_dword(value=helpers.ip_str_to_bytes(PARAM_ROUTER_ID), name='Router ID', endian=BIG_ENDIAN, fuzzable=False) # Source IP
s_dword(value=helpers.ip_str_to_bytes(self.rhost), name='Target IP', endian=BIG_ENDIAN, fuzzable=False) # Target IP
s_block_end()
if s_block_start('OSPF'):
if s_block_start('Header'):
s_byte(value=0x02, name='Version', fuzzable=False) # Version OSPFv2
s_byte(value=0x02, name='Type', fuzzable=False) # Packet type Database Description
s_size(block_name='Database Description', length=2, math=lambda x: x + 24, name='Packet Length', endian=BIG_ENDIAN, fuzzable=False) # Packet Length
s_dword(value=helpers.ip_str_to_bytes(PARAM_ROUTER_ID), name='Router ID', endian=BIG_ENDIAN, fuzzable=False) # Router ID
s_dword(value=helpers.ip_str_to_bytes(PARAM_AREA_ID), name='Area ID', endian=BIG_ENDIAN, fuzzable=False) # Area ID
s_checksum(name='Checksum', block_name='OSPF', algorithm='ipv4', endian=BIG_ENDIAN, fuzzable=False) # Checksum
s_word(value=0x0000, name='Autype', endian=BIG_ENDIAN, fuzzable=False) # Autype
s_qword(value=0x00000000, name='Authentication', endian=BIG_ENDIAN, fuzzable=False) # Authentication
s_block_end()
if s_block_start('Database Description'):
s_word(value=1500, name='Interface MTU', endian=BIG_ENDIAN, fuzzable=False) # Interface MTU
s_byte(value=0x02, name='Options', endian=BIG_ENDIAN, fuzzable=False) # Options
s_byte(value=0x07, name='DB Description', endian=BIG_ENDIAN, fuzzable=True) # DB Description
s_dword(name='DD Sequence Number', endian=BIG_ENDIAN, fuzzable=True) # DD Sequence Number
num_lsa = random.randint(1, 10)
for num in range(num_lsa):
if s_block_start(f'LSA Header - {num}'):
s_word(value=0x0001, name='LS Age', endian=BIG_ENDIAN, fuzzable=False) # LS Age
s_byte(value=0x02, name='Options', fuzzable=False) # Options
s_byte(value=random.randint(1, 7), name='LS Type', fuzzable=False) # LS Type
s_dword(value=helpers.ip_str_to_bytes(PARAM_ROUTER_ID), name='Link State ID', endian=BIG_ENDIAN, fuzzable=False)
s_dword(value=helpers.ip_str_to_bytes(PARAM_ROUTER_ID), name='Advertising Router', endian=BIG_ENDIAN, fuzzable=False)
s_dword(name='LS Sequence Number', endian=BIG_ENDIAN, fuzzable=True) # DD Sequence Number
s_checksum(name='Checksum', block_name=f'LSA Header - {num}', algorithm='ipv4', endian=BIG_ENDIAN, fuzzable=False) # LS Checksum
s_size(block_name=f'LSA Header - {num}', length=2, math=lambda x: x + 20, name='Length', endian=BIG_ENDIAN, fuzzable=False)
s_block_end()
s_block_end()
s_block_end()
s_block_end()
self.session_handle.connect(s_get('ospf_dd'))
self.session_handle.fuzz()
'''
OSPF DD #3
- 包含随机LSA,DD序列号随机
- LSA Header中Options是fuzzable的
'''
class OSPFDDFuzzer_3(OSPFDDFuzzer):
def __init__(self, router_id, area_id, rhost, rpc_port=1234):
super().__init__(router_id, area_id, rhost, rpc_port)
random.seed(time.time())
def do_fuzz(self):
PARAM_ROUTER_ID = self.router_id
PARAM_AREA_ID = self.area_id
s_initialize('ospf_dd')
if s_block_start('IP'):
if s_block_start('IP Header'):
s_byte(value=0x45, name='Version', fuzzable=False) # IPv4
s_byte(value=0xC0, name='TOS', fuzzable=False) # TOS
s_size(block_name='OSPF', length=2, math=lambda x: x + 20, name='Total Length', endian=BIG_ENDIAN, fuzzable=False) # Total Length
s_word(value=0x0000, name='Identification', fuzzable=False) # Identification
s_word(value=0x0000, name='Flags & Fragment Offset', fuzzable=False)
s_byte(value=0x01, name='TTL', fuzzable=False) # TTL
s_byte(value=0x59, name='Protocol', fuzzable=False) # Protocol OSPF
s_checksum(name='Checksum', block_name='IP Header', algorithm='ipv4', endian=BIG_ENDIAN, fuzzable=False) # Checksum
s_dword(value=helpers.ip_str_to_bytes(PARAM_ROUTER_ID), name='Router ID', endian=BIG_ENDIAN, fuzzable=False) # Source IP
s_dword(value=helpers.ip_str_to_bytes(self.rhost), name='Target IP', endian=BIG_ENDIAN, fuzzable=False) # Target IP
s_block_end()
if s_block_start('OSPF'):
if s_block_start('Header'):
s_byte(value=0x02, name='Version', fuzzable=False) # Version OSPFv2
s_byte(value=0x02, name='Type', fuzzable=False) # Packet type Database Description
s_size(block_name='Database Description', length=2, math=lambda x: x + 24, name='Packet Length', endian=BIG_ENDIAN, fuzzable=False) # Packet Length
s_dword(value=helpers.ip_str_to_bytes(PARAM_ROUTER_ID), name='Router ID', endian=BIG_ENDIAN, fuzzable=False) # Router ID
s_dword(value=helpers.ip_str_to_bytes(PARAM_AREA_ID), name='Area ID', endian=BIG_ENDIAN, fuzzable=False) # Area ID
s_checksum(name='Checksum', block_name='OSPF', algorithm='ipv4', endian=BIG_ENDIAN, fuzzable=False) # Checksum
s_word(value=0x0000, name='Autype', endian=BIG_ENDIAN, fuzzable=False) # Autype
s_qword(value=0x00000000, name='Authentication', endian=BIG_ENDIAN, fuzzable=False) # Authentication
s_block_end()
if s_block_start('Database Description'):
s_word(value=1500, name='Interface MTU', endian=BIG_ENDIAN, fuzzable=False) # Interface MTU
s_byte(value=0x02, name='Options', endian=BIG_ENDIAN, fuzzable=False) # Options
s_byte(value=0x07, name='DB Description', endian=BIG_ENDIAN, fuzzable=False) # DB Description
s_dword(name='DD Sequence Number', endian=BIG_ENDIAN, fuzzable=True) # DD Sequence Number
num_lsa = random.randint(1, 10)
for num in range(num_lsa):
if s_block_start(f'LSA Header - {num}'):
s_word(value=0x0001, name='LS Age', endian=BIG_ENDIAN, fuzzable=False) # LS Age
s_byte(value=0x02, name='Options', fuzzable=True) # Options
s_byte(value=random.randint(1, 7), name='LS Type', fuzzable=False) # LS Type
s_dword(value=helpers.ip_str_to_bytes(PARAM_ROUTER_ID), name='Link State ID', endian=BIG_ENDIAN, fuzzable=False)
s_dword(value=helpers.ip_str_to_bytes(PARAM_ROUTER_ID), name='Advertising Router', endian=BIG_ENDIAN, fuzzable=False)
s_dword(name='LS Sequence Number', endian=BIG_ENDIAN, fuzzable=True) # DD Sequence Number
s_checksum(name='Checksum', block_name=f'LSA Header - {num}', algorithm='ipv4', endian=BIG_ENDIAN, fuzzable=False) # LS Checksum
s_size(block_name=f'LSA Header - {num}', length=2, math=lambda x: x + 20, name='Length', endian=BIG_ENDIAN, fuzzable=False)
s_block_end()
s_block_end()
s_block_end()
s_block_end()
self.session_handle.connect(s_get('ospf_dd'))
self.session_handle.fuzz()
'''
OSPF DD #4
- 包含随机LSA,DD序列号随机
- Link State ID,Advertising Router 随机
'''
class OSPFDDFuzzer_4(OSPFDDFuzzer):
def __init__(self, router_id, area_id, rhost, rpc_port=1234):
super().__init__(router_id, area_id, rhost, rpc_port)
random.seed(time.time())
def do_fuzz(self):
PARAM_ROUTER_ID = self.router_id
PARAM_AREA_ID = self.area_id
s_initialize('ospf_dd')
if s_block_start('IP'):
if s_block_start('IP Header'):
s_byte(value=0x45, name='Version', fuzzable=False) # IPv4
s_byte(value=0xC0, name='TOS', fuzzable=False) # TOS
s_size(block_name='OSPF', length=2, math=lambda x: x + 20, name='Total Length', endian=BIG_ENDIAN, fuzzable=False) # Total Length
s_word(value=0x0000, name='Identification', fuzzable=False) # Identification
s_word(value=0x0000, name='Flags & Fragment Offset', fuzzable=False)
s_byte(value=0x01, name='TTL', fuzzable=False) # TTL
s_byte(value=0x59, name='Protocol', fuzzable=False) # Protocol OSPF
s_checksum(name='Checksum', block_name='IP Header', algorithm='ipv4', endian=BIG_ENDIAN, fuzzable=False) # Checksum
s_dword(value=helpers.ip_str_to_bytes(PARAM_ROUTER_ID), name='Router ID', endian=BIG_ENDIAN, fuzzable=False) # Source IP
s_dword(value=helpers.ip_str_to_bytes(self.rhost), name='Target IP', endian=BIG_ENDIAN, fuzzable=False) # Target IP
s_block_end()
if s_block_start('OSPF'):
if s_block_start('Header'):
s_byte(value=0x02, name='Version', fuzzable=False) # Version OSPFv2
s_byte(value=0x02, name='Type', fuzzable=False) # Packet type Database Description
s_size(block_name='Database Description', length=2, math=lambda x: x + 24, name='Packet Length', endian=BIG_ENDIAN, fuzzable=False) # Packet Length
s_dword(value=helpers.ip_str_to_bytes(PARAM_ROUTER_ID), name='Router ID', endian=BIG_ENDIAN, fuzzable=False) # Router ID
s_dword(value=helpers.ip_str_to_bytes(PARAM_AREA_ID), name='Area ID', endian=BIG_ENDIAN, fuzzable=False) # Area ID
s_checksum(name='Checksum', block_name='OSPF', algorithm='ipv4', endian=BIG_ENDIAN, fuzzable=False) # Checksum
s_word(value=0x0000, name='Autype', endian=BIG_ENDIAN, fuzzable=False) # Autype
s_qword(value=0x00000000, name='Authentication', endian=BIG_ENDIAN, fuzzable=False) # Authentication
s_block_end()
if s_block_start('Database Description'):
s_word(value=1500, name='Interface MTU', endian=BIG_ENDIAN, fuzzable=False) # Interface MTU
s_byte(value=0x02, name='Options', endian=BIG_ENDIAN, fuzzable=False) # Options
s_byte(value=0x07, name='DB Description', endian=BIG_ENDIAN, fuzzable=False) # DB Description
s_dword(name='DD Sequence Number', endian=BIG_ENDIAN, fuzzable=True) # DD Sequence Number
num_lsa = random.randint(1, 10)
for num in range(num_lsa):
if s_block_start(f'LSA Header - {num}'):
s_word(value=0x0001, name='LS Age', endian=BIG_ENDIAN, fuzzable=False) # LS Age
s_byte(value=0x02, name='Options', fuzzable=False) # Options
s_byte(value=random.randint(1, 7), name='LS Type', fuzzable=False) # LS Type
s_dword(name='Link State ID', endian=BIG_ENDIAN, fuzzable=True) # Link State ID
s_dword(name='Advertising Router', endian=BIG_ENDIAN, fuzzable=True) # Advertising Router
s_dword(name='LS Sequence Number', endian=BIG_ENDIAN, fuzzable=True) # DD Sequence Number
s_checksum(name='Checksum', block_name=f'LSA Header - {num}', algorithm='ipv4', endian=BIG_ENDIAN, fuzzable=False) # LS Checksum
s_size(block_name=f'LSA Header - {num}', length=2, math=lambda x: x + 20, name='Length', endian=BIG_ENDIAN, fuzzable=False)
s_block_end()
s_block_end()
s_block_end()
s_block_end()
self.session_handle.connect(s_get('ospf_dd'))
self.session_handle.fuzz()
'''
OSPF DD #5
- LSA random生成
'''
class OSPFDDFuzzer_5(OSPFDDFuzzer):
def __init__(self, router_id, area_id, rhost, rpc_port=1234):
super().__init__(router_id, area_id, rhost, rpc_port)
random.seed(time.time())
def do_fuzz(self):
PARAM_ROUTER_ID = self.router_id
PARAM_AREA_ID = self.area_id
s_initialize('ospf_dd')
if s_block_start('IP'):
if s_block_start('IP Header'):
s_byte(value=0x45, name='Version', fuzzable=False) # IPv4
s_byte(value=0xC0, name='TOS', fuzzable=False) # TOS
s_size(block_name='OSPF', length=2, math=lambda x: x + 20, name='Total Length', endian=BIG_ENDIAN, fuzzable=False) # Total Length
s_word(value=0x0000, name='Identification', fuzzable=False) # Identification
s_word(value=0x0000, name='Flags & Fragment Offset', fuzzable=False)
s_byte(value=0x01, name='TTL', fuzzable=False) # TTL
s_byte(value=0x59, name='Protocol', fuzzable=False) # Protocol OSPF
s_checksum(name='Checksum', block_name='IP Header', algorithm='ipv4', endian=BIG_ENDIAN, fuzzable=False) # Checksum
s_dword(value=helpers.ip_str_to_bytes(PARAM_ROUTER_ID), name='Router ID', endian=BIG_ENDIAN, fuzzable=False) # Source IP
s_dword(value=helpers.ip_str_to_bytes(self.rhost), name='Target IP', endian=BIG_ENDIAN, fuzzable=False) # Target IP
s_block_end()
if s_block_start('OSPF'):
if s_block_start('Header'):
s_byte(value=0x02, name='Version', fuzzable=False) # Version OSPFv2
s_byte(value=0x02, name='Type', fuzzable=False) # Packet type Database Description
s_size(block_name='Database Description', length=2, math=lambda x: x + 24, name='Packet Length', endian=BIG_ENDIAN, fuzzable=False) # Packet Length
s_dword(value=helpers.ip_str_to_bytes(PARAM_ROUTER_ID), name='Router ID', endian=BIG_ENDIAN, fuzzable=False) # Router ID
s_dword(value=helpers.ip_str_to_bytes(PARAM_AREA_ID), name='Area ID', endian=BIG_ENDIAN, fuzzable=False) # Area ID
s_checksum(name='Checksum', block_name='OSPF', algorithm='ipv4', endian=BIG_ENDIAN, fuzzable=False) # Checksum
s_word(value=0x0000, name='Autype', endian=BIG_ENDIAN, fuzzable=False) # Autype
s_qword(value=0x00000000, name='Authentication', endian=BIG_ENDIAN, fuzzable=False) # Authentication
s_block_end()
if s_block_start('Database Description'):
s_word(value=1500, name='Interface MTU', endian=BIG_ENDIAN, fuzzable=False) # Interface MTU
s_byte(value=0x02, name='Options', endian=BIG_ENDIAN, fuzzable=False) # Options
s_byte(value=0x07, name='DB Description', endian=BIG_ENDIAN, fuzzable=False) # DB Description
s_dword(name='DD Sequence Number', endian=BIG_ENDIAN, fuzzable=False) # DD Sequence Number
num_lsa = random.randint(1, 10)
s_random(name='LSA', min_length=20, max_length=20 * num_lsa, num_mutations=4096, fuzzable=True)
s_block_end()
s_block_end()
s_block_end()
self.session_handle.connect(s_get('ospf_dd'))
self.session_handle.fuzz()
'''
Modify this code to choose different test suites and parameters.
'''
if __name__ == '__main__':
argparser = argparse.ArgumentParser()
argparser.add_argument('--router_id', dest='router_id', type=str, required=True, help='Router ID')
argparser.add_argument('--area_id', dest='area_id', type=str, required=True, help='Area ID')
argparser.add_argument('--tip', dest='tip', type=str, required=True, help='Target IP address')
argparser.add_argument('--trpc_port', dest='trpc_port', type=int, required=True, default=1234, help='Target RPC port')
args = argparser.parse_args()
ROUTER_ID = args.router_id
AREA_ID = args.area_id
TIP = args.tip
TRPC_PORT = args.trpc_port
'''
Instantiate and run a test suite
'''
fuzzer = OSPFDDFuzzer_1(router_id=ROUTER_ID, area_id=AREA_ID, rhost=TIP, rpc_port=TRPC_PORT)
# fuzzer = OSPFDDFuzzer_2(router_id=ROUTER_ID, area_id=AREA_ID, rhost=TIP, rpc_port=TRPC_PORT)
# fuzzer = OSPFDDFuzzer_3(router_id=ROUTER_ID, area_id=AREA_ID, rhost=TIP, rpc_port=TRPC_PORT)
# fuzzer = OSPFDDFuzzer_4(router_id=ROUTER_ID, area_id=AREA_ID, rhost=TIP, rpc_port=TRPC_PORT)
# fuzzer = OSPFDDFuzzer_5(router_id=ROUTER_ID, area_id=AREA_ID, rhost=TIP, rpc_port=TRPC_PORT)
fuzzer.do_fuzz()
print('Done!')