From 7a858b7f9383282070ccb576c3a50701c6809c11 Mon Sep 17 00:00:00 2001 From: Simon Moser Date: Mon, 28 May 2018 19:08:08 +0200 Subject: [PATCH] Output saving added --- anmap.py | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/anmap.py b/anmap.py index 035bfc8..c1cb4b8 100644 --- a/anmap.py +++ b/anmap.py @@ -5,32 +5,37 @@ from datetime import datetime class AnmapThread(Thread): - def __init__(self, hostname, ports, logger): + def __init__(self, hostname, ports, logger, out): Thread.__init__(self) self.host = hostname self.ports = ports self.nm = PortScanner() self.logger = logger self.daemon = True + self.out = out class ThoroughAnmapThread(AnmapThread): def run(self): self.logger.log("Starting thorough scan on " + self.host) - self.nm.scan(self.host, "1," + ",".join(self.ports), arguments="-sSVC -A -Pn") + self.nm.scan(self.host, "1," + ",".join(self.ports), + arguments='-sSVC -A -Pn{}'.format(output_argument(self.out, self.host, 2))) host = self.nm[self.host] for p in host.all_tcp(): - print("Port {}: {}".format(p, host['tcp'][p])) + if p == 1: + continue + print("Port {}/tcp: {}".format(p, host['tcp'][p])) self.logger.log("Finished thorough scan on " + self.host) class UDPAnmapThread(AnmapThread): def run(self): self.logger.log("Starting UDP scan on " + self.host) - self.nm.scan(self.host, arguments="-sVCU -A -Pn --top-ports {}".format(self.ports)) + self.nm.scan(self.host, arguments='-sVCU -A -Pn --top-ports {}{}'. + format(self.ports, output_argument(self.out, self.host, 3))) host = self.nm[self.host] for p in host.all_udp(): - print("Port {}: {}".format(p, host['udp'][p])) + print("Port {}/udp: {}".format(p, host['udp'][p])) self.logger.log("Finished UDP scan on " + self.host) @@ -43,19 +48,38 @@ class Logger: print("{}: {}".format(date(True), message)) -def date(long = False): +def date(long=False): if long: return datetime.now().strftime("%Y-%m-%d_%H%M%S") return datetime.now().strftime("%Y-%m-%d_%H%M") +def output_argument(o, host, st): + host = host.replace("/", "x") + host = host.replace(" ", "") + if not o: + return "" + if st == 1: + return " -oG nmap_{}_S_{}".format(host, date()) + if st == 2: + return " -oG nmap_{}_SVCA_{}".format(host, date()) + if st == 3: + return " -oG nmap_{}_VCUA_{}".format(host, date()) + + def run(args): + if args.d: + args.v = True + args.u = 100 l = Logger(args.v) # Scanning all tcp ports nm = PortScanner() l.log("Starting quick scan") - nm.scan(args.HOST, arguments='-sS -Pn -p1-1000') + if args.d: + nm.scan(args.HOST, arguments='-sS -Pn -p1-1000{}'.format(output_argument(args.o, args.HOST, 1))) + else: + nm.scan(args.HOST, arguments='-sS -Pn -p-{}'.format(output_argument(args.o, args.HOST, 1))) l.log("Finished quick scan") host_list = dict() for hostname in nm.all_hosts(): @@ -70,10 +94,10 @@ def run(args): # Starting thorough and udp scan in separate threads thread_list = [] for host, open_port_list in host_list.items(): - t1 = ThoroughAnmapThread(host, open_port_list, l) + t1 = ThoroughAnmapThread(host, open_port_list, l, args.o) t1.start() thread_list.append(t1) - t2 = UDPAnmapThread(host, args.u, l) + t2 = UDPAnmapThread(host, args.u, l, args.o) t2.start() thread_list.append(t2) @@ -90,6 +114,9 @@ if __name__ == "__main__": prog="anmap.py") parser.add_argument("-u", default=1000, type=int, help="The number of UDP ports to scan (Default 1000)") parser.add_argument("-v", action="store_true", help="This enables verbose output") + parser.add_argument("-d", action="store_true", + help="Sets flags -v and -u 100 and scans only the first 1000 tcp ports") + parser.add_argument("-o", action="store_true", help="Enables saving of output files") parser.add_argument("HOST", type=str, help="The hosts to scan (Same notations as in nmap possible)") try: