-
Notifications
You must be signed in to change notification settings - Fork 7
/
padding.py
60 lines (45 loc) · 1.12 KB
/
padding.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
import re
import os
class setPadding():
def __init__(self, filename, padsize):
self.filename = filename
self.padsize = padsize
self.msize = padsize * 1048576
def setPsize(self):
data = 'A' * self.msize
return data
def addPadding(self):
dsize = self.setPsize()
with open("static/"+self.filename, "r") as in_file:
buff = in_file.readlines()
filew = open("/tmp/"+self.filename+"_pad", "w")
d1=True
for line in buff:
if d1:
if "<head>" in line:
print line
filew.write(line)
filew.write("<script>\n")
filew.write("var secret_var = '%s'\n" % dsize)
filew.write("</script>\n")
results="set"
d1=False
else:
results="Notset"
filew.write(line)
else:
filew.write(line)
filew.close()
if results != "set":
f = open("/tmp/"+self.filename+"_pad", 'r+')
lines = f.readlines()
f.seek(0)
f.write("<script>\n")
f.write("var secret_var = %s\n" % dsize)
f.write("</script>\n")
for line in lines:
f.write(line)
f.close()
if __name__ == "__main__":
res = setPadding('virus1.html', 10)
print res.addPadding()