-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpwntomate.py
executable file
·64 lines (58 loc) · 4.03 KB
/
pwntomate.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This software must not be used by military or secret service organisations.
# License: TODO
import os, sys, argparse, json, glob, subprocess
from libnmap.parser import NmapParser
greeter = '''[31m
██▓███ █ ████▄ █▄▄▄█████▓▒█████ ███▄ ▄███▓▄▄▄ ▄▄▄█████▓█████
▓██░ ██▓█░ █ ░███ ▀█ █▓ ██▒ ▓▒██▒ ██▓██▒▀█▀ ██▒████▄ ▓ ██▒ ▓▓█ ▀
▓██░ ██▓▒█░ █ ░▓██ ▀█ ██▒ ▓██░ ▒▒██░ ██▓██ ▓██▒██ ▀█▄▒ ▓██░ ▒▒███
▒██▄█▓▒ ░█░ █ ░▓██▒ ▐▌██░ ▓██▓ ░▒██ ██▒██ ▒██░██▄▄▄▄█░ ▓██▓ ░▒▓█ ▄
▒██▒ ░ ░░██▒██▒██░ ▓██░ ▒██▒ ░░ ████▓▒▒██▒ ░██▒▓█ ▓██▒▒██▒ ░░▒████▒
▒▓▒░ ░ ░ ▓░▒ ▒░ ▒░ ▒ ▒ ▒ ░░ ░ ▒░▒░▒░░ ▒░ ░ ░▒▒ ▓▒█░▒ ░░ ░░ ▒░ ░
░▒ ░ ▒ ░ ░░ ░░ ░ ▒░ ░ ░ ▒ ▒░░ ░ ░ ▒ ▒▒ ░ ░ ░ ░ ░
░░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ▒ ░ ░ ░ ▒ ░ ░
░ ░ ░ ░ ░ ░ ░ ░ ░
[0m'''
version = "0.0.3#beta"
parser = argparse.ArgumentParser(description="pwntomate version " + version + "\nhttps://github.com/honze-net/pwntomate", epilog="This software must not be used by military or secret service organisations.", formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument("xml", help="path to Nmap XML file")
parser.add_argument("-b", help="path to base directory for tool output (default: ~/.pwntomate)", default="~/.pwntomate", dest="basedir")
parser.add_argument("-t", help="path to custom tool directory (default: ./tools)", default="./tools", dest="tooldir")
parser.add_argument("-x", help="Executes the generated script automatically. (Be careful!)", action="store_true", dest="execute")
if len(sys.argv) == 1: # If no arguments are specified, print greeter, help and exit.
print greeter
parser.print_help()
sys.exit(1)
args = parser.parse_args()
try:
report = NmapParser.parse_fromfile(args.xml)
except IOError:
print 'file %s not found' % args.xml
sys.exit(1)
shellscript = '''#!/bin/bash
# autogenerated script by pwntomate %s
# https://github.com/honze-net/pwntomate
''' % version
for host in report.hosts:
for service in host.services:
for filename in glob.glob(args.tooldir+"/*.tool"):
tool = json.load(open(filename, 'r'))
if tool["active"] and (service.service in tool["trigger"] or 'all' in tool["trigger"]):
cmd = tool["command"]
if service.tunnel == 'ssl':
cmd = cmd.replace("{s}", "s")
else:
cmd = cmd.replace("{s}", "")
cmd = cmd.replace("{outputdir}", "{baseoutputdir}/{ip}/{port}/{toolname}") # make this configurable
cmd = cmd.replace("{ip}", host.address)
cmd = cmd.replace("{port}", str(service.port))
cmd = cmd.replace("{baseoutputdir}", args.basedir.replace(" ", "\ "))
cmd = cmd.replace("{toolname}", tool["toolname"].replace(" ", "\ "))
shellscript += 'mkdir -p %s/%s/%s/%s\n' % (args.basedir.replace(" ", "\ "), host.address, service.port, tool["toolname"].replace(" ", "\ ")) # TODO remove double configuration of {baseoutputdir}/{ip}/{port}/{toolname}. things can go wrong.
shellscript += '%s\n' % cmd
if args.execute:
subprocess.call(shellscript, shell=True)
else:
print shellscript