-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathfuzz_update.py
597 lines (505 loc) · 35.8 KB
/
fuzz_update.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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
import argparse
from boofuzz import *
from boofuzz import helpers
from boofuzz import constants
from base.bgp_update import BaseUpdateFuzzer
'''
BGP UPDATE #1
- BGP header length is correct
- Everything past the "type" octet is the fuzzload
'''
class BgpUpdateFuzzer_1(BaseUpdateFuzzer):
def __init__(self, bgp_id, asn_id, rhost, rpc_port=1234, rport='179', hold_time=240):
super().__init__(bgp_id, asn_id, rhost, rpc_port, rport, hold_time)
self.poc_name = 'BgpUpdateFuzzer_1_testcase_%s.py'
def do_fuzz(self):
PARAM_ASN_ID = self.asn_id
PARAM_BGP_ID = self.bgp_id
PARAM_HOLD_TIME = self.hold_time
s_initialize('BGP_OPEN')
with s_block('HEADER'):
s_static(name='marker', value=b'\xff'*16)
s_static(name='length', value=b'\x00\x6b')
s_static(name='type', value=b'\x01')
with s_block('OPEN_MSG'):
s_static(name='version', value=b'\x04')
s_word(name='my_as', value=PARAM_ASN_ID, endian=BIG_ENDIAN, fuzzable=False)
s_word(value=PARAM_HOLD_TIME, endian=BIG_ENDIAN, name="Hold Time", fuzzable=False)
s_static(name='bgp_identifier', value=helpers.ip_str_to_bytes(PARAM_BGP_ID))
s_static(name='opt_params_len', value=b'\x4e')
s_static(name='opt_params', value=b'\x02\x06\x01\x04\x00\x01\x00\x01\x02\x02\x80\x00\x02\x02\x02\x00' \
b'\x02\x02\x46\x00\x02\x06\x41\x04\x00\x00\x00\x02\x02\x02\x06\x00' \
b'\x02\x06\x45\x04\x00\x01\x01\x01\x02\x13\x49\x11\x0f\x73\x74\x61' \
b'\x6e\x64\x61\x73\x68\x2d\x75\x62\x75\x6e\x74\x75\x00\x02\x04\x40' \
b'\x02\xc0\x78\x02\x09\x47\x07\x00\x01\x01\x80\x00\x00\x00'
)
s_initialize('BGP_KEEPALIVE')
with s_block('HEADER'):
s_static(name='marker', value=b'\xff'*16)
s_static(name='length', value=b'\x00\x13')
s_static(name='type', value=b'\x04')
s_initialize('BGP_UPDATE')
with s_block('HEADER'):
s_static(name='marker', value=b'\xff'*16)
s_size(name='header_len', length=2, math=lambda x: x + 19, block_name='FUZZLOAD', endian=BIG_ENDIAN, fuzzable=False)
s_static(name='type', value=b'\x02')
with s_block('FUZZLOAD'):
s_random(min_length=0, max_length=1024, num_mutations=1024, fuzzable=True)
self.session_handle.connect(s_get('BGP_OPEN'))
self.session_handle.connect(s_get('BGP_OPEN'),s_get('BGP_KEEPALIVE'))
self.session_handle.connect(s_get('BGP_KEEPALIVE'),s_get('BGP_UPDATE'))
self.session_handle.fuzz()
'''
BGP UPDATE #2
- BGP header length is correct
- Withdrawn routes length is set to 0x0000
- Total path attr. length is correct (dynamic)
- Path attributes is fuzzable (min len = 0, max len = 4068, mutations = 4096)
'''
class BgpUpdateFuzzer_2(BaseUpdateFuzzer):
def __init__(self, bgp_id, asn_id, rhost, rpc_port=1234, rport='179', hold_time=240):
super().__init__(bgp_id, asn_id, rhost, rpc_port, rport, hold_time)
self.poc_name = 'BgpUpdateFuzzer_2_testcase_%s.py'
def do_fuzz(self):
PARAM_ASN_ID = self.asn_id
PARAM_BGP_ID = self.bgp_id
PARAM_HOLD_TIME = self.hold_time
s_initialize('BGP_OPEN')
with s_block('HEADER'):
s_static(name='marker', value=b'\xff'*16)
s_static(name='length', value=b'\x00\x6b')
s_static(name='type', value=b'\x01')
with s_block('OPEN_MSG'):
s_static(name='version', value=b'\x04')
s_word(name='my_as', value=PARAM_ASN_ID, endian=BIG_ENDIAN, fuzzable=False)
s_word(value=PARAM_HOLD_TIME, endian=BIG_ENDIAN, name="Hold Time", fuzzable=False)
s_static(name='bgp_identifier', value=helpers.ip_str_to_bytes(PARAM_BGP_ID))
s_static(name='opt_params_len', value=b'\x4e')
s_static(name='opt_params', value=b'\x02\x06\x01\x04\x00\x01\x00\x01\x02\x02\x80\x00\x02\x02\x02\x00' \
b'\x02\x02\x46\x00\x02\x06\x41\x04\x00\x00\x00\x02\x02\x02\x06\x00' \
b'\x02\x06\x45\x04\x00\x01\x01\x01\x02\x13\x49\x11\x0f\x73\x74\x61' \
b'\x6e\x64\x61\x73\x68\x2d\x75\x62\x75\x6e\x74\x75\x00\x02\x04\x40' \
b'\x02\xc0\x78\x02\x09\x47\x07\x00\x01\x01\x80\x00\x00\x00'
)
s_initialize('BGP_KEEPALIVE')
with s_block('HEADER'):
s_static(name='marker', value=b'\xff'*16)
s_static(name='length', value=b'\x00\x13')
s_static(name='type', value=b'\x04')
s_initialize('BGP_UPDATE')
with s_block('HEADER'):
s_static(name='marker', value=b'\xff'*16)
s_size(name='header_len', length=2, math=lambda x: x + 19, block_name='UPDATE', endian=BIG_ENDIAN, fuzzable=False)
s_static(name='type', value=b'\x02')
with s_block('UPDATE'):
s_word(name='withdrawn_len', value=b'\x00\x00', endian=BIG_ENDIAN, fuzzable=False)
s_size(name='total_path_attr_len', length=2, block_name='FUZZLOAD', endian=BIG_ENDIAN, fuzzable=False)
with s_block('FUZZLOAD'):
s_random(num_mutations=1024, min_length=0, max_length=1024, fuzzable=True)
self.session_handle.connect(s_get('BGP_OPEN'))
self.session_handle.connect(s_get('BGP_OPEN'),s_get('BGP_KEEPALIVE'))
self.session_handle.connect(s_get('BGP_KEEPALIVE'),s_get('BGP_UPDATE'))
self.session_handle.fuzz()
'''
BGP UPDATE #3
- BGP header length is correct
- Withdrawn routes length is set to 0x0000
- fuzz single attribute (non-extended length of 1 octet)
'''
class BgpUpdateFuzzer_3(BaseUpdateFuzzer):
def __init__(self, bgp_id, asn_id, rhost, rpc_port=1234, rport='179', hold_time=240):
super().__init__(bgp_id, asn_id, rhost, rpc_port, rport, hold_time)
self.poc_name = 'BgpUpdateFuzzer_3_testcase_%s.py'
def do_fuzz(self):
PARAM_ASN_ID = self.asn_id
PARAM_BGP_ID = self.bgp_id
PARAM_HOLD_TIME = self.hold_time
s_initialize('BGP_OPEN')
with s_block('HEADER'):
s_static(name='marker', value=b'\xff'*16)
s_static(name='length', value=b'\x00\x6b')
s_static(name='type', value=b'\x01')
with s_block('OPEN_MSG'):
s_static(name='version', value=b'\x04')
s_word(name='my_as', value=PARAM_ASN_ID, endian=BIG_ENDIAN, fuzzable=False)
s_word(value=PARAM_HOLD_TIME, endian=BIG_ENDIAN, name="Hold Time", fuzzable=False)
s_static(name='bgp_identifier', value=helpers.ip_str_to_bytes(PARAM_BGP_ID))
s_static(name='opt_params_len', value=b'\x4e')
s_static(name='opt_params', value=b'\x02\x06\x01\x04\x00\x01\x00\x01\x02\x02\x80\x00\x02\x02\x02\x00' \
b'\x02\x02\x46\x00\x02\x06\x41\x04\x00\x00\x00\x02\x02\x02\x06\x00' \
b'\x02\x06\x45\x04\x00\x01\x01\x01\x02\x13\x49\x11\x0f\x73\x74\x61' \
b'\x6e\x64\x61\x73\x68\x2d\x75\x62\x75\x6e\x74\x75\x00\x02\x04\x40' \
b'\x02\xc0\x78\x02\x09\x47\x07\x00\x01\x01\x80\x00\x00\x00'
)
s_initialize('BGP_KEEPALIVE')
with s_block('HEADER'):
s_static(name='marker', value=b'\xff'*16)
s_static(name='length', value=b'\x00\x13')
s_static(name='type', value=b'\x04')
s_initialize('BGP_UPDATE')
with s_block('HEADER'):
s_static(name='marker', value=b'\xff'*16)
s_size(name='header_len', length=2, math=lambda x: x + 19, block_name='UPDATE', endian=BIG_ENDIAN, fuzzable=False)
s_static(name='type', value=b'\x02')
with s_block('UPDATE'):
s_word(name='withdrawn_len', value=b'\x00\x00', endian=BIG_ENDIAN, fuzzable=False)
s_size(name='total_path_attr_len', length=2, block_name='ATTRS', endian=BIG_ENDIAN, fuzzable=False)
with s_block('ATTRS'):
s_group(name='flags', values=[b'\xe0', b'\xc0', b'\xa0', b'\x80', b'\x60', b'\x40', b'\x20', b'\x00'])
s_byte(name='type_code', value=0x00, fuzzable=True)
s_byte(name='attr_len', value=0x00, fuzzable=True)
with s_block('FUZZLOAD'):
s_random(num_mutations=1024, min_length=0, max_length=1024, fuzzable=True)
self.session_handle.connect(s_get('BGP_OPEN'))
self.session_handle.connect(s_get('BGP_OPEN'),s_get('BGP_KEEPALIVE'))
self.session_handle.connect(s_get('BGP_KEEPALIVE'),s_get('BGP_UPDATE'))
self.session_handle.fuzz()
'''
BGP UPDATE #4
- BGP header length is correct
- Withdrawn routes length is set to 0x0000
- fuzz single attribute (extended length of 2 octets)
'''
class BgpUpdateFuzzer_4(BaseUpdateFuzzer):
def __init__(self, bgp_id, asn_id, rhost, rpc_port=1234, rport='179', hold_time=240):
super().__init__(bgp_id, asn_id, rhost, rpc_port, rport, hold_time)
self.poc_name = 'BgpUpdateFuzzer_4_testcase_%s.py'
def do_fuzz(self):
PARAM_ASN_ID = self.asn_id
PARAM_BGP_ID = self.bgp_id
PARAM_HOLD_TIME = self.hold_time
s_initialize('BGP_OPEN')
with s_block('HEADER'):
s_static(name='marker', value=b'\xff'*16)
s_static(name='length', value=b'\x00\x6b')
s_static(name='type', value=b'\x01')
with s_block('OPEN_MSG'):
s_static(name='version', value=b'\x04')
s_word(name='my_as', value=PARAM_ASN_ID, endian=BIG_ENDIAN, fuzzable=False)
s_word(value=PARAM_HOLD_TIME, endian=BIG_ENDIAN, name="Hold Time", fuzzable=False)
s_static(name='bgp_identifier', value=helpers.ip_str_to_bytes(PARAM_BGP_ID))
s_static(name='opt_params_len', value=b'\x4e')
s_static(name='opt_params', value=b'\x02\x06\x01\x04\x00\x01\x00\x01\x02\x02\x80\x00\x02\x02\x02\x00' \
b'\x02\x02\x46\x00\x02\x06\x41\x04\x00\x00\x00\x02\x02\x02\x06\x00' \
b'\x02\x06\x45\x04\x00\x01\x01\x01\x02\x13\x49\x11\x0f\x73\x74\x61' \
b'\x6e\x64\x61\x73\x68\x2d\x75\x62\x75\x6e\x74\x75\x00\x02\x04\x40' \
b'\x02\xc0\x78\x02\x09\x47\x07\x00\x01\x01\x80\x00\x00\x00'
)
s_initialize('BGP_KEEPALIVE')
with s_block('HEADER'):
s_static(name='marker', value=b'\xff'*16)
s_static(name='length', value=b'\x00\x13')
s_static(name='type', value=b'\x04')
s_initialize('BGP_UPDATE')
with s_block('HEADER'):
s_static(name='marker', value=b'\xff'*16)
s_size(name='header_len', length=2, math=lambda x: x + 19, block_name='UPDATE', endian=BIG_ENDIAN, fuzzable=False)
s_static(name='type', value=b'\x02')
with s_block('UPDATE'):
s_word(name='withdrawn_len', value=b'\x00\x00', endian=BIG_ENDIAN, fuzzable=False)
s_size(name='total_path_attr_len', length=2, block_name='ATTRS', endian=BIG_ENDIAN, fuzzable=False)
with s_block('ATTRS'):
s_group(name='flags', values=[b'\xf0', b'\xd0', b'\xb0', b'\x90', b'\x70', b'\x50', b'\x30', b'\x10'])
s_byte(name='type_code', value=0x00, fuzzable=True)
s_word(name='attr_len', value=0x0000, fuzzable=True)
with s_block('FUZZLOAD'):
s_random(num_mutations=1024, min_length=0, max_length=1024, fuzzable=True)
self.session_handle.connect(s_get('BGP_OPEN'))
self.session_handle.connect(s_get('BGP_OPEN'),s_get('BGP_KEEPALIVE'))
self.session_handle.connect(s_get('BGP_KEEPALIVE'),s_get('BGP_UPDATE'))
self.session_handle.fuzz()
'''
BGP UPDATE #5
- BGP header length is correct
- Withdrawn routes length is set to 0x0000
- fuzz single attribute (non-extended length of 1 octet)
- attribute length is correct
'''
class BgpUpdateFuzzer_5(BaseUpdateFuzzer):
def __init__(self, bgp_id, asn_id, rhost, rpc_port=1234, rport='179', hold_time=240):
super().__init__(bgp_id, asn_id, rhost, rpc_port, rport, hold_time)
self.poc_name = 'BgpUpdateFuzzer_5_testcase_%s.py'
def do_fuzz(self):
PARAM_ASN_ID = self.asn_id
PARAM_BGP_ID = self.bgp_id
PARAM_HOLD_TIME = self.hold_time
s_initialize('BGP_OPEN')
with s_block('HEADER'):
s_static(name='marker', value=b'\xff'*16)
s_static(name='length', value=b'\x00\x6b')
s_static(name='type', value=b'\x01')
with s_block('OPEN_MSG'):
s_static(name='version', value=b'\x04')
s_word(name='my_as', value=PARAM_ASN_ID, endian=BIG_ENDIAN, fuzzable=False)
s_word(value=PARAM_HOLD_TIME, endian=BIG_ENDIAN, name="Hold Time", fuzzable=False)
s_static(name='bgp_identifier', value=helpers.ip_str_to_bytes(PARAM_BGP_ID))
s_static(name='opt_params_len', value=b'\x4e')
s_static(name='opt_params', value=b'\x02\x06\x01\x04\x00\x01\x00\x01\x02\x02\x80\x00\x02\x02\x02\x00' \
b'\x02\x02\x46\x00\x02\x06\x41\x04\x00\x00\x00\x02\x02\x02\x06\x00' \
b'\x02\x06\x45\x04\x00\x01\x01\x01\x02\x13\x49\x11\x0f\x73\x74\x61' \
b'\x6e\x64\x61\x73\x68\x2d\x75\x62\x75\x6e\x74\x75\x00\x02\x04\x40' \
b'\x02\xc0\x78\x02\x09\x47\x07\x00\x01\x01\x80\x00\x00\x00'
)
s_initialize('BGP_KEEPALIVE')
with s_block('HEADER'):
s_static(name='marker', value=b'\xff'*16)
s_static(name='length', value=b'\x00\x13')
s_static(name='type', value=b'\x04')
s_initialize('BGP_UPDATE')
with s_block('HEADER'):
s_static(name='marker', value=b'\xff'*16)
s_size(name='header_len', length=2, math=lambda x: x + 19, block_name='UPDATE', endian=BIG_ENDIAN, fuzzable=False)
s_static(name='type', value=b'\x02')
with s_block('UPDATE'):
s_word(name='withdrawn_len', value=b'\x00\x00', endian=BIG_ENDIAN, fuzzable=False)
s_size(name='total_path_attr_len', length=2, block_name='ATTRS', endian=BIG_ENDIAN, fuzzable=False)
with s_block('ATTRS'):
s_group(name='flags', values=[b'\xe0', b'\xc0', b'\xa0', b'\x80', b'\x60', b'\x40', b'\x20', b'\x00'])
s_byte(name='type_code', value=0x00, fuzzable=True)
s_size(name='attr_len', length=1, block_name='FUZZLOAD', fuzzable=False)
with s_block('FUZZLOAD'):
s_random(num_mutations=1024, min_length=0, max_length=1024, fuzzable=True)
self.session_handle.connect(s_get('BGP_OPEN'))
self.session_handle.connect(s_get('BGP_OPEN'),s_get('BGP_KEEPALIVE'))
self.session_handle.connect(s_get('BGP_KEEPALIVE'),s_get('BGP_UPDATE'))
self.session_handle.fuzz()
'''
BGP UPDATE #6
- BGP header length is correct
- Withdrawn routes length is set to 0x0000
- fuzz single attribute (extended length of 2 octets)
- attribute length is correct
'''
class BgpUpdateFuzzer_6(BaseUpdateFuzzer):
def __init__(self, bgp_id, asn_id, rhost, rpc_port=1234, rport='179', hold_time=240):
super().__init__(bgp_id, asn_id, rhost, rpc_port, rport, hold_time)
self.poc_name = 'BgpUpdateFuzzer_6_testcase_%s.py'
def do_fuzz(self):
PARAM_ASN_ID = self.asn_id
PARAM_BGP_ID = self.bgp_id
PARAM_HOLD_TIME = self.hold_time
s_initialize('BGP_OPEN')
with s_block('HEADER'):
s_static(name='marker', value=b'\xff'*16)
s_static(name='length', value=b'\x00\x6b')
s_static(name='type', value=b'\x01')
with s_block('OPEN_MSG'):
s_static(name='version', value=b'\x04')
s_word(name='my_as', value=PARAM_ASN_ID, endian=BIG_ENDIAN, fuzzable=False)
s_word(value=PARAM_HOLD_TIME, endian=BIG_ENDIAN, name="Hold Time", fuzzable=False)
s_static(name='bgp_identifier', value=helpers.ip_str_to_bytes(PARAM_BGP_ID))
s_static(name='opt_params_len', value=b'\x4e')
s_static(name='opt_params', value=b'\x02\x06\x01\x04\x00\x01\x00\x01\x02\x02\x80\x00\x02\x02\x02\x00' \
b'\x02\x02\x46\x00\x02\x06\x41\x04\x00\x00\x00\x02\x02\x02\x06\x00' \
b'\x02\x06\x45\x04\x00\x01\x01\x01\x02\x13\x49\x11\x0f\x73\x74\x61' \
b'\x6e\x64\x61\x73\x68\x2d\x75\x62\x75\x6e\x74\x75\x00\x02\x04\x40' \
b'\x02\xc0\x78\x02\x09\x47\x07\x00\x01\x01\x80\x00\x00\x00'
)
s_initialize('BGP_KEEPALIVE')
with s_block('HEADER'):
s_static(name='marker', value=b'\xff'*16)
s_static(name='length', value=b'\x00\x13')
s_static(name='type', value=b'\x04')
s_initialize('BGP_UPDATE')
with s_block('HEADER'):
s_static(name='marker', value=b'\xff'*16)
s_size(name='header_len', length=2, math=lambda x: x + 19, block_name='UPDATE', endian=BIG_ENDIAN, fuzzable=False)
s_static(name='type', value=b'\x02')
with s_block('UPDATE'):
s_word(name='withdrawn_len', value=b'\x00\x00', endian=BIG_ENDIAN, fuzzable=False)
s_size(name='total_path_attr_len', length=2, block_name='ATTRS', endian=BIG_ENDIAN, fuzzable=False)
with s_block('ATTRS'):
s_group(name='flags', values=[b'\xf0', b'\xd0', b'\xb0', b'\x90', b'\x70', b'\x50', b'\x30', b'\x10'])
s_byte(name='type_code', value=0x00, fuzzable=True)
s_size(name='attr_len', length=2, block_name='FUZZLOAD', endian=BIG_ENDIAN, fuzzable=False)
with s_block('FUZZLOAD'):
s_random(num_mutations=1024, min_length=0, max_length=1024, fuzzable=True)
self.session_handle.connect(s_get('BGP_OPEN'))
self.session_handle.connect(s_get('BGP_OPEN'),s_get('BGP_KEEPALIVE'))
self.session_handle.connect(s_get('BGP_KEEPALIVE'),s_get('BGP_UPDATE'))
self.session_handle.fuzz()
'''
BGP UPDATE #7
- BGP header length is correct
- withdrawn routes length is fuzzable
- ... followed by a random fuzzload
'''
class BgpUpdateFuzzer_7(BaseUpdateFuzzer):
def __init__(self, bgp_id, asn_id, rhost, rpc_port=1234, rport='179', hold_time=240):
super().__init__(bgp_id, asn_id, rhost, rpc_port, rport, hold_time)
self.poc_name = 'BgpUpdateFuzzer_7_testcase_%s.py'
def do_fuzz(self):
PARAM_ASN_ID = self.asn_id
PARAM_BGP_ID = self.bgp_id
PARAM_HOLD_TIME = self.hold_time
s_initialize('BGP_OPEN')
with s_block('HEADER'):
s_static(name='marker', value=b'\xff'*16)
s_static(name='length', value=b'\x00\x6b')
s_static(name='type', value=b'\x01')
with s_block('OPEN_MSG'):
s_static(name='version', value=b'\x04')
s_word(name='my_as', value=PARAM_ASN_ID, endian=BIG_ENDIAN, fuzzable=False)
s_word(value=PARAM_HOLD_TIME, endian=BIG_ENDIAN, name="Hold Time", fuzzable=False)
s_static(name='bgp_identifier', value=helpers.ip_str_to_bytes(PARAM_BGP_ID))
s_static(name='opt_params_len', value=b'\x4e')
s_static(name='opt_params', value=b'\x02\x06\x01\x04\x00\x01\x00\x01\x02\x02\x80\x00\x02\x02\x02\x00' \
b'\x02\x02\x46\x00\x02\x06\x41\x04\x00\x00\x00\x02\x02\x02\x06\x00' \
b'\x02\x06\x45\x04\x00\x01\x01\x01\x02\x13\x49\x11\x0f\x73\x74\x61' \
b'\x6e\x64\x61\x73\x68\x2d\x75\x62\x75\x6e\x74\x75\x00\x02\x04\x40' \
b'\x02\xc0\x78\x02\x09\x47\x07\x00\x01\x01\x80\x00\x00\x00'
)
s_initialize('BGP_KEEPALIVE')
with s_block('HEADER'):
s_static(name='marker', value=b'\xff'*16)
s_static(name='length', value=b'\x00\x13')
s_static(name='type', value=b'\x04')
s_initialize('BGP_UPDATE')
with s_block('HEADER'):
s_static(name='marker', value=b'\xff'*16)
s_size(name='header_len', length=2, math=lambda x: x + 19, block_name='UPDATE', endian=BIG_ENDIAN, fuzzable=False)
s_static(name='type', value=b'\x02')
with s_block('UPDATE'):
s_word(name='withdrawn_len', value=b'\x00\x00', endian=BIG_ENDIAN, fuzzable=True)
with s_block('FUZZLOAD'):
s_random(num_mutations=1024, min_length=0, max_length=1024, fuzzable=True)
self.session_handle.connect(s_get('BGP_OPEN'))
self.session_handle.connect(s_get('BGP_OPEN'),s_get('BGP_KEEPALIVE'))
self.session_handle.connect(s_get('BGP_KEEPALIVE'),s_get('BGP_UPDATE'))
self.session_handle.fuzz()
'''
BGP UPDATE #8
- BGP header length is correct
- withdrawn routes length is correct
- ... followed by a random fuzzload
'''
class BgpUpdateFuzzer_8(BaseUpdateFuzzer):
def __init__(self, bgp_id, asn_id, rhost, rpc_port=1234, rport='179', hold_time=240):
super().__init__(bgp_id, asn_id, rhost, rpc_port, rport, hold_time)
self.poc_name = 'BgpUpdateFuzzer_8_testcase_%s.py'
def do_fuzz(self):
PARAM_ASN_ID = self.asn_id
PARAM_BGP_ID = self.bgp_id
PARAM_HOLD_TIME = self.hold_time
s_initialize('BGP_OPEN')
with s_block('HEADER'):
s_static(name='marker', value=b'\xff'*16)
s_static(name='length', value=b'\x00\x6b')
s_static(name='type', value=b'\x01')
with s_block('OPEN_MSG'):
s_static(name='version', value=b'\x04')
s_word(name='my_as', value=PARAM_ASN_ID, endian=BIG_ENDIAN, fuzzable=False)
s_word(value=PARAM_HOLD_TIME, endian=BIG_ENDIAN, name="Hold Time", fuzzable=False)
s_static(name='bgp_identifier', value=helpers.ip_str_to_bytes(PARAM_BGP_ID))
s_static(name='opt_params_len', value=b'\x4e')
s_static(name='opt_params', value=b'\x02\x06\x01\x04\x00\x01\x00\x01\x02\x02\x80\x00\x02\x02\x02\x00' \
b'\x02\x02\x46\x00\x02\x06\x41\x04\x00\x00\x00\x02\x02\x02\x06\x00' \
b'\x02\x06\x45\x04\x00\x01\x01\x01\x02\x13\x49\x11\x0f\x73\x74\x61' \
b'\x6e\x64\x61\x73\x68\x2d\x75\x62\x75\x6e\x74\x75\x00\x02\x04\x40' \
b'\x02\xc0\x78\x02\x09\x47\x07\x00\x01\x01\x80\x00\x00\x00'
)
s_initialize('BGP_KEEPALIVE')
with s_block('HEADER'):
s_static(name='marker', value=b'\xff'*16)
s_static(name='length', value=b'\x00\x13')
s_static(name='type', value=b'\x04')
s_initialize('BGP_UPDATE')
with s_block('HEADER'):
s_static(name='marker', value=b'\xff'*16)
s_size(name='header_len', length=2, math=lambda x: x + 19, block_name='UPDATE', endian=BIG_ENDIAN, fuzzable=False)
s_static(name='type', value=b'\x02')
with s_block('UPDATE'):
s_size(name='withdrawn_len', block_name='FUZZLOAD', length=2, endian=BIG_ENDIAN, fuzzable=False)
with s_block('FUZZLOAD'):
s_random(num_mutations=1024, min_length=0, max_length=1024, fuzzable=True)
self.session_handle.connect(s_get('BGP_OPEN'))
self.session_handle.connect(s_get('BGP_OPEN'),s_get('BGP_KEEPALIVE'))
self.session_handle.connect(s_get('BGP_KEEPALIVE'),s_get('BGP_UPDATE'))
self.session_handle.fuzz()
'''
BGP UPDATE #9
- BGP header length is correct
- withdrawn routes length is 0
- ... followed by Path Attributes
'''
class BgpUpdateFuzzer_9(BaseUpdateFuzzer):
def __init__(self, bgp_id, asn_id, rhost, rpc_port=1234, rport='179', hold_time=240):
super().__init__(bgp_id, asn_id, rhost, rpc_port, rport, hold_time)
self.poc_name = 'BgpUpdateFuzzer_9_testcase_%s.py'
def do_fuzz(self):
PARAM_ASN_ID = self.asn_id
PARAM_BGP_ID = self.bgp_id
PARAM_HOLD_TIME = self.hold_time
s_initialize('BGP_OPEN')
with s_block('HEADER'):
s_static(name='marker', value=b'\xff' * 16)
s_size(block_name="BGP_OPEN", length=2, endian="big", fuzzable=False, name="Length") # Length
s_static(name='type', value=b'\x01')
with s_block('OPEN_MSG'):
s_static(value=b"\x04", name="Version") # BGP Version
s_word(name='my_as', value=PARAM_ASN_ID, endian=BIG_ENDIAN, fuzzable=False)
s_static(value=b"\x00\xb4", name="Hold Time") # Hold Time
s_static(name='bgp_identifier', value=helpers.ip_str_to_bytes(PARAM_BGP_ID))
s_static(value=b"\x06", name="Opt Params Length") # Optional Params Length
s_static(value=b"\x02\x04\x40\x02\x80\x78", name="Opt Params")
s_initialize('BGP_KEEPALIVE')
with s_block('HEADER'):
s_static(name='marker', value=b'\xff' * 16)
s_static(name='length', value=b'\x00\x13')
s_static(name='type', value=b'\x04')
s_initialize('BGP_UPDATE')
with s_block("BGP_UPDATE"):
s_static(value=b"\xff" * 16, name="Marker") # Marker
s_size(block_name="BGP_UPDATE", length=2, endian="big", fuzzable=False, name="Length") # Length
s_static(value=b"\x02", name="Type") # Type (UPDATE)
with s_block("BGP_UPDATE Body"):
s_static(value=b"\x00\x00", name="Withdrawn Routes Length") # Withdrawn Routes Length
s_size(block_name="Path Attributes", length=2, endian="big", fuzzable=False,
name="Path Attributes Length")
with s_block("Path Attributes"):
with s_block("Path Attribute"):
s_byte(value=0xc0, fuzzable=True, name="Attr Flags") # Attribute flags
s_byte(value=255, fuzzable=True, name="Attr Type") # Attribute type code
s_size(block_name="Attr Value", length=1, endian="big", fuzzable=True, name="Attr Length")
s_string(value="dummy_attr_value", name="Attr Value", fuzzable=True,
max_len=0) # Attribute value
# s_string(value="dummy_attr_value", name="Attr Value", fuzzable=True) # Attribute value
with s_block("NLRI"):
s_byte(value=24, name="Prefix Length 1") # Prefix length
s_static(value=b"\x6f\x00\x00", name="Prefix 1") # Address (111.0.0.0)
s_byte(value=24, name="Prefix Length 2") # Prefix length
s_static(value=b"\x6f\x01\x00", name="Prefix 2") # Address (111.1.0.0)
self.session_handle.connect(s_get('BGP_OPEN'))
self.session_handle.connect(s_get('BGP_OPEN'), s_get('BGP_KEEPALIVE'))
self.session_handle.connect(s_get('BGP_KEEPALIVE'), s_get('BGP_UPDATE'))
self.session_handle.fuzz()
'''
Modify this code to choose different test suites and parameters.
'''
if __name__ == '__main__':
'''
Set the parameters
'''
argparser = argparse.ArgumentParser()
argparser.add_argument('--fbgp_id', dest='fbgp_id', type=str, required=True, help='Fuzzer BGP ID.')
argparser.add_argument('--fasn', dest='fasn', type=int, required=True, default=2, help='Fuzzer ASN number.')
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()
FBGP_ID = args.fbgp_id
FASN = args.fasn
TIP = args.tip
TRPC_PORT = args.trpc_port
'''
Instantiate and run a test suite
'''
fuzzer = BgpUpdateFuzzer_1(bgp_id=FBGP_ID, asn_id=FASN, rhost=TIP, rpc_port=TRPC_PORT)
#fuzzer = BgpUpdateFuzzer_2(bgp_id=FBGP_ID, asn_id=FASN, rhost=TIP, rpc_port=TRPC_PORT)
#fuzzer = BgpUpdateFuzzer_3(bgp_id=FBGP_ID, asn_id=FASN, rhost=TIP, rpc_port=TRPC_PORT)
#fuzzer = BgpUpdateFuzzer_4(bgp_id=FBGP_ID, asn_id=FASN, rhost=TIP, rpc_port=TRPC_PORT)
#fuzzer = BgpUpdateFuzzer_5(bgp_id=FBGP_ID, asn_id=FASN, rhost=TIP, rpc_port=TRPC_PORT)
#fuzzer = BgpUpdateFuzzer_6(bgp_id=FBGP_ID, asn_id=FASN, rhost=TIP, rpc_port=TRPC_PORT)
#fuzzer = BgpUpdateFuzzer_7(bgp_id=FBGP_ID, asn_id=FASN, rhost=TIP, rpc_port=TRPC_PORT)
#fuzzer = BgpUpdateFuzzer_8(bgp_id=FBGP_ID, asn_id=FASN, rhost=TIP, rpc_port=TRPC_PORT)
#fuzzer = BgpUpdateFuzzer_9(bgp_id=FBGP_ID, asn_id=FASN, rhost=TIP, rpc_port=TRPC_PORT)
fuzzer.do_fuzz()