-
Notifications
You must be signed in to change notification settings - Fork 0
/
htbman.py
62 lines (51 loc) · 1.88 KB
/
htbman.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
#!/usr/bin/env python3
from argparse import ArgumentParser
from datetime import datetime
from pathlib import Path
from utils import ask
import subprocess
import sys
# TODO
# setup.py to access from any dir
# which instruments are used/learned
# get the name and IP of the box from HTB
# when the box is rooted, move all in db, gather all info (flags, utilities, compressed files)
# some kind of api?
class HTBox:
def __init__(self, path: str, *args):
self.vars = self.parse_vars(args)
self.bwd = Path(path)
self.name = self.bwd.parts[-1]
if not self.bwd.exists():
if ask('Path does not exist. Create?') == 'y':
self.new_box()
def init_scan(self):
pass
# subprocess nmaps
def parse_vars(self, vars: tuple) -> dict:
result = {}
for var in vars:
if '=' in var:
k, v = var.split('=')
result[k.strip()] = v.strip()
return result
def new_box(self):
self.bwd.mkdir()
with open(self.bwd / 'walkthrough.txt', 'w') as fo:
cur_time = datetime.now().strftime("%d-%m-%Y %H:%M")
fo.write(f'# Started {self.name} at {cur_time}')
def main():
sargs = sys.argv
parser = ArgumentParser()
#parser.add_argument('-n', '--new', dest='name', help="Create new box's folder with walkthrough.txt")
parser.add_argument('-i', '--init-scan', dest='ip',
help="Perform initial scan (nmap -A -p$(nmap -p-) ...) IP")
parser.add_argument('-f', '--finish', dest='fin', help="Finish the box")
parser.add_argument('path', help='Path to folder with box')
parser.add_argument('vars', help='Box variables: var1=qwe var2=rty', nargs='*')
args = parser.parse_args(sargs[1:])
box = HTBox(args.path, args.vars)
if len(sargs) == 1:
parser.print_help()
if __name__ == '__main__':
main()