-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoffice_docx.py
45 lines (36 loc) · 1.33 KB
/
office_docx.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
import argparse
import zipfile
import re
from tokenfinder import Tokenfinder
def check_office_files(file_location):
# Parsing arguments from master_script.py
parser.add_argument("--string", "-s", type=str, required=True)
# List of urls found
list_of_urls = []
try:
# Unzip the office file without saving to folder
unzipped_file = zipfile.ZipFile(args.file,"r")
# List of all the content of the zip
namelist = unzipped_file.namelist()
# Reads every file in the zip file and looks if it contains the string you wish to search for
for item in namelist:
content = str(unzipped_file.read(item))
token = Tokenfinder.find_tokens_in_string(content)
if token:
list_of_urls.extend(token)
except OSError:
print("error")
# If no results of the search
if len(list_of_urls) == 0:
return None
else:
print(str(len(list_of_urls)) +" canary URLs detected in the file")
for url in list_of_urls:
print("Canary detected: ", url)
print()
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--file", "-f", type=str, required=True)
args = parser.parse_args()
file_location = args.file
check_office_files(file_location)