-
Notifications
You must be signed in to change notification settings - Fork 5
/
generate.py
94 lines (72 loc) · 1.65 KB
/
generate.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
import os
import sys
import random
import json
from random import choice
rtf="{\\rtf1"
oo="{\\*"
pp="}"
def genrandomtagindex(len):
index=[]
for i in range(0,len-1):
index.append(random.randint(0,1700))
return index
def genstarttagitem(obj,target,pp):
group=[]
i=0
while i< len(pp):
if obj==str(pp[i]["description"])and target!=i:
cr=str(pp[i]["controlwd"])
indexN=cr.find("N")
if indexN!=-1:
value=genrandomvalue(1000)
cr=cr[:indexN]+str(value)
group.append(cr)
i=i+1
return group
def getgrouptag(returntag):
count=random.randint(len(returntag)/2,len(returntag))
slice1=random.sample(returntag,count)
tag=""
j=0
while(len(slice1)>j):
tag=tag+slice1[j]
j=j+1
return tag
def genrandomvalue(max):
return random.randint(0,max)
def genrtf(obj):
pp=json.loads(obj)
index=genrandomtagindex(10)
item=""
rtf="{\\rtf1"
oo="{\\*"
returntag=[]
selfgroup=""
filename="filename"
for i in index:
cr=str(pp[i]["controlwd"])
filename=cr
indexN=cr.find("N")
if indexN!=-1:
value=genrandomvalue(1000)
cr=cr[:indexN]+str(value)
if pp[i]["type"]=="Destination":
cr=oo+str(pp[i]["controlwd"])
returntag=genstarttagitem(pp[i]["description"],i,pp)
selfgroup=getgrouptag(returntag)
cr=cr+selfgroup+"}"
item=cr+item
#item=item+"}"
rtf=rtf+item+"}"
value=random.randint(0,0x20000)
name="F:\\research\\rtffuzzer\\rtf\\"+filename+"%s"%value+".rtf"
print name
fp=open(name,"wb")
fp.write(rtf)
fp.close()
if __name__ == '__main__':
fp=open("rtf.json","rb")
obj=fp.read()
for i in range(0,0x2000):
genrtf(obj)