-
Notifications
You must be signed in to change notification settings - Fork 2
/
biovault.py
147 lines (119 loc) · 4.03 KB
/
biovault.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/python3
import os
import argparse
from threading import Thread
from itertools import cycle
from shutil import get_terminal_size
from time import sleep
from subprocess import PIPE, Popen
# Author: Shain Lakin
pm3_path = "/Users/shain/Documents/tools/proxmark3/"
uid = "0478A5D2CD5280"
pre = '0' * 32
banner = """
"""
class Loader:
def __init__(self, desc="Loading...", end="[+] Communicating with proxmark ... ", timeout=0.1):
"""
A loader-like context manager
Args:
desc (str, optional): The loader's description. Defaults to "Loading...".
end (str, optional): Final print. Defaults to "Done!...".
timeout (float, optional): Sleep time between prints. Defaults to 0.1.
"""
self.desc = desc
self.end = end
self.timeout = timeout
self._thread = Thread(target=self._animate, daemon=True)
self.steps = ["⢿", "⣻", "⣽", "⣾", "⣷", "⣯", "⣟", "⡿"]
self.done = False
def start(self):
self._thread.start()
return self
def _animate(self):
for c in cycle(self.steps):
if self.done:
break
print(f"\r{self.desc} {c}", flush=True, end="")
sleep(self.timeout)
def __enter__(self):
self.start()
def stop(self):
self.done = True
cols = get_terminal_size((80, 20)).columns
print("\r" + " " * cols, end="", flush=True)
print(f"\r{self.end}", flush=True)
def __exit__(self, exc_type, exc_value, tb):
self.stop()
# Parse arguments
parser = argparse.ArgumentParser(description="", \
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("-m", "--mode", type=str, default="r", help="Read/Write to vault")
parser.add_argument("-z", "--zero", action='store_true', help="Zero sector with null bytes" )
args = parser.parse_args()
# Static strings
zero = f"{pm3_path}pm3 -c \'script run hf_i2c_plus_2k_utils -s 1 -m f -f zero.null\'"
aes_enc = f"openssl aes-256-cbc -salt -pbkdf2 -in vault.txt -out vault.txt.enc"
write_vault = f"{pm3_path}pm3 -c \'script run hf_i2c_plus_2k_utils -s 1 -m f -f vault.txt.enc\'"
dump_vault = f"{pm3_path}pm3 -c \'script run hf_i2c_plus_2k_utils -s 1 -m d\' >/dev/null 2>&1"
extract = f"/bin/cat {uid}.hex | awk -F \'{pre}\' \'{{print $2}}\' > dump.bin"
reverse_hex = "xxd -r -ps dump.bin > vault.txt.enc"
aes_dec = "openssl aes-256-cbc -d -pbkdf2 -in vault.txt.enc -out vault.txt.dec"
display = "csvtojson vault.txt.dec | jq"
# Process function
def proc(cmd):
try:
proc = Popen(f"{cmd}".split(), \
stdin=PIPE, stdout=PIPE, stderr=PIPE)
proc.communicate()
except KeyboardInterrupt:
exit(0)
# Create null byte file
def zero_file():
with open(f"zero.null", "w+b") as z:
z.write(b"\0" * 3000)
# Delete files
def clean():
if args.mode == 'w':
os.remove("vault.txt")
os.remove("vault.txt.enc")
if args.zero:
os.remove("zero.null")
elif args.mode == 'r':
os.remove(f"{uid}.hex")
os.remove("dump.bin")
os.remove("vault.txt.enc")
os.remove("vault.txt.dec")
# Loading function
def wait():
loader = Loader("[+] Place proxmark on implant .. sleeping for 10").start()
sleep(10)
loader.stop()
print("[+] Reading data ...")
def main():
try:
if args.mode == 'r':
tag_path = ("./" + uid + ".hex")
wait()
os.system(dump_vault)
if os.path.exists(tag_path):
os.system(extract)
os.system(reverse_hex)
proc(aes_dec)
os.system(display)
clean()
else:
print("[!] Cannot read tag")
elif args.mode == 'w':
if args.zero:
wait()
zero_file()
os.system(zero)
proc(aes_enc)
wait()
os.system(write_vault)
clean()
except Exception as e:
print(e)
exit(0)
main()