-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextractor.py
112 lines (76 loc) · 2.26 KB
/
extractor.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
from utils import *
from utils import _compressed, _wl
def check_for_password_zip():
has_pass = shell_cmd_output("./has_pass_zip " + _compressed + ".zip")
if has_pass != "":
return True
return False
def check_for_password_rar():
has_pass = shell_cmd_output("./has_pass_zip " + _compressed + ".rar")
if has_pass != "":
return True
return False
def parse_password(raw_password):
try:
''' file.zip:passwd:fileinside\nblabla '''
password = raw_password.split("\n")[0].split(':')[1]
except IndexError:
print(f'[~~~]ERROR -> password = {raw_password}')
exit()
return password
def extract_password_zip():
shell_cmd_raw("zip2john last_flag.zip > hash 2>/dev/null")
if _wl is not None:
shell_cmd("john hash --wordlist=" + _wl)
else:
shell_cmd("john hash")
raw_password = shell_cmd_output("john hash --show")
return parse_password(raw_password)
def extract_zip():
flag = "last_flag.zip"
redefine_type(flag)
passwd = None
if check_for_password_zip() is not False:
passwd = extract_password_zip()
if passwd is None:
shell_cmd("unzip -o -qq " + flag)
shell_cmd("rm " + flag)
else:
shell_cmd("unzip -o -P " + passwd + " -qq " + flag)
shell_cmd("rm " + flag + " hash")
def extract_tar():
flag = "last_flag.tar"
redefine_type(flag)
shell_cmd("tar -xf " + flag)
shell_cmd("rm " + flag)
def extract_bz2():
flag = "last_flag.bz2"
redefine_type(flag)
shell_cmd("bzip2 -dk " + flag)
shell_cmd("rm " + flag)
def extract_gunzip():
flag = "last_flag.gz"
redefine_type(flag)
shell_cmd("gzip -d " + flag)
# gunzip does not preserve file, not looked after options
# subprocess.call(["rm", flag])
def extract_xz():
flag = "last_flag.xz"
redefine_type(flag)
shell_cmd("tar -xf " + flag)
shell_cmd("rm " + flag)
def redefine_type_and_extract(type_):
if type_ == 0:
extract_tar()
elif type_ == 1:
extract_bz2()
elif type_ == 2:
extract_zip()
elif type_ == 3:
extract_gunzip()
elif type_ == 4:
extract_xz()
elif type_ == 5:
print_ascii()
elif type_ == 6:
print_unknown_type()