-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path_deprecated_yaml_web.py
95 lines (73 loc) · 2.64 KB
/
_deprecated_yaml_web.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
import os
import logging
import argparse
from urllib.parse import urlparse
import yaml
from config import config # noqa
from utils import utils, logging_config # noqa pylint: disable=unused-import
LOG = logging.getLogger("ptscripts.yaml_web")
def c_format(commands, args): # pylint: disable=too-many-locals
parsed_url = urlparse(args.url)
netloc = parsed_url.netloc.split(":")[0]
pentest_path = os.path.join(args.path, netloc)
for com in commands:
com['command'] = com['command'].format(
scripts_path=config.SCRIPTS_PATH,
pentest_path=pentest_path,
url=args.url, netloc=netloc,
)
def c_print(commands):
for com in commands:
if com.get('help') and com['help']:
print('# ' + com['help'])
print(com['command'])
def c_write(commands, args):
parsed_url = urlparse(args.url)
netloc = parsed_url.netloc.split(":")[0]
pentest_path = os.path.join(args.path, "{netloc}".format(netloc=netloc))
commands_path = os.path.join(pentest_path, "web_commands_{netloc}.txt".format(netloc=netloc))
scripts_path = os.path.join(pentest_path, "wc_{netloc}.sh".format(netloc=netloc))
with open(commands_path, "w") as f:
for com in commands:
f.write(com['command'] + "\n")
f.write("\n")
with open(scripts_path, "w") as f:
for com in commands:
f.write(com['command'] + "\n")
def load_commands(yaml_file):
with open(yaml_file, "r") as f:
return yaml.safe_load(f)
def get_name():
return input('Pentest directory name? ')
def get_url():
return input('URL? ')
def main(args):
if args.path:
args.path = args.path.rstrip('/')
if not args.url:
args.url = get_url()
commands_file = os.path.join(config.SCRIPTS_PATH, "commands/web_commands.yaml")
commands = load_commands(commands_file)
c_format(commands, args)
c_print(commands)
c_write(commands, args)
def parse_args(args):
parser = argparse.ArgumentParser(
parents=[utils.parent_argparser()],
description='Print web commands formatted for current pentest.',
)
parser.add_argument('-p', '--path', help="Full path to pentest folder (not url folder)")
parser.add_argument('-u', '--url', help="URL for the engagement.")
args = parser.parse_args(args)
logger = logging.getLogger("ptscripts")
if args.quiet:
logger.setLevel('ERROR')
elif args.verbose:
logger.setLevel('DEBUG')
logger.debug("Logger set to debug.")
else:
logger.setLevel('INFO')
return args
if __name__ == "__main__":
import sys
main(parse_args(sys.argv[1:]))