1
0
Fork 0

xml-output added, .gitignore and README.md updated

master
MrMcX vor 6 Jahren
Ursprung 8471e639be
Commit 281f4cb769

6
.gitignore vendored

@ -94,3 +94,9 @@ ENV/
# Rope project settings # Rope project settings
.ropeproject .ropeproject
# Pycharm
.idea
# nmap output
*.xml
*.gnmap

@ -1,7 +1,12 @@
# Anmap - Automatic nmap Scanner # Anmap - Automatic nmap Scanner
Prerequisites:
* Python 3.6 (https://www.python.org/downloads/)
* python-nmap (https://xael.org/pages/python-nmap-en.html)
* nmap (https://nmap.org/)
``` ```
usage: anmap.py [-h] [-u U] [-v] HOST usage: anmap.py [-h] [-u UDP] [-v] [-d] [-o] HOST
This script automates nmap scans by quickly scanning all TCP ports first and This script automates nmap scans by quickly scanning all TCP ports first and
executing a thorough scan on all ports found open afterwards. Additionally it executing a thorough scan on all ports found open afterwards. Additionally it
@ -12,6 +17,9 @@ positional arguments:
optional arguments: optional arguments:
-h, --help show this help message and exit -h, --help show this help message and exit
-u U The number of UDP ports to scan (Default 1000) -u UDP, --udp UDP The number of UDP ports to scan (Default 1000)
-v This enables verbose output -v, --verbose This enables verbose output
-d, --debug Sets flags -v and -u 100 and scans only the first 1000
tcp ports
-o, --output Enables saving of output files
``` ```

@ -19,12 +19,15 @@ class ThoroughAnmapThread(AnmapThread):
def run(self): def run(self):
self.logger.log("Starting thorough scan on " + self.host) self.logger.log("Starting thorough scan on " + self.host)
self.nm.scan(self.host, "1," + ",".join(self.ports), self.nm.scan(self.host, "1," + ",".join(self.ports),
arguments='-sSVC -A -Pn{}'.format(output_argument(self.out, self.host, 2))) arguments='-sSVC -A -Pn{}'.format(output(self.out, self.host, 2)))
if self.out:
with open(output(True, self.host, 5), "w") as out:
out.write(self.nm.get_nmap_last_output())
host = self.nm[self.host] host = self.nm[self.host]
for p in host.all_tcp(): for p in host.all_tcp():
if p == 1: if p == 1:
continue continue
print("Port {}/tcp: {}".format(p, host['tcp'][p])) self.logger.log("Port {}/tcp: {}".format(p, host['tcp'][p]))
self.logger.log("Finished thorough scan on " + self.host) self.logger.log("Finished thorough scan on " + self.host)
@ -32,10 +35,13 @@ class UDPAnmapThread(AnmapThread):
def run(self): def run(self):
self.logger.log("Starting UDP scan on " + self.host) self.logger.log("Starting UDP scan on " + self.host)
self.nm.scan(self.host, arguments='-sVCU -A -Pn --top-ports {}{}'. self.nm.scan(self.host, arguments='-sVCU -A -Pn --top-ports {}{}'.
format(self.ports, output_argument(self.out, self.host, 3))) format(self.ports, output(self.out, self.host, 3)))
if self.out:
with open(output(True, self.host, 6), "w") as out:
out.write(self.nm.get_nmap_last_output())
host = self.nm[self.host] host = self.nm[self.host]
for p in host.all_udp(): for p in host.all_udp():
print("Port {}/udp: {}".format(p, host['udp'][p])) self.logger.log("Port {}/udp: {}".format(p, host['udp'][p]))
self.logger.log("Finished UDP scan on " + self.host) self.logger.log("Finished UDP scan on " + self.host)
@ -54,32 +60,41 @@ def date(long=False):
return datetime.now().strftime("%Y-%m-%d_%H%M") return datetime.now().strftime("%Y-%m-%d_%H%M")
def output_argument(o, host, st): def output(o, host, st):
host = host.replace("/", "x") host = host.replace("/", "x")
host = host.replace(" ", "") host = host.replace(" ", "")
if not o: if not o:
return "" return ""
if st == 1: if st == 1:
return " -oG nmap_{}_S_{}".format(host, date()) return " -oG nmap_{}_S_{}.gnmap".format(host, date())
if st == 2: if st == 2:
return " -oG nmap_{}_SVCA_{}".format(host, date()) return " -oG nmap_{}_SVCA_{}.gnmap".format(host, date())
if st == 3: if st == 3:
return " -oG nmap_{}_VCUA_{}".format(host, date()) return " -oG nmap_{}_VCUA_{}.gnmap".format(host, date())
if st == 4:
return "nmap_{}_S_{}.xml".format(host, date())
if st == 5:
return "nmap_{}_SVCA_{}.xml".format(host, date())
if st == 6:
return "nmap_{}_VCUA_{}.xml".format(host, date())
def run(args): def run(args):
if args.d: if args.debug:
args.v = True args.verbose = True
args.u = 100 args.udp = 100
l = Logger(args.v) l = Logger(args.verbose)
# Scanning all tcp ports # Scanning all tcp ports
nm = PortScanner() nm = PortScanner()
l.log("Starting quick scan") l.log("Starting quick scan")
if args.d: if args.debug:
nm.scan(args.HOST, arguments='-sS -Pn -p1-1000{}'.format(output_argument(args.o, args.HOST, 1))) nm.scan(args.HOST, arguments='-sS -Pn -p1-1000{}'.format(output(args.output, args.HOST, 1)))
else: else:
nm.scan(args.HOST, arguments='-sS -Pn -p-{}'.format(output_argument(args.o, args.HOST, 1))) nm.scan(args.HOST, arguments='-sS -Pn -p-{}'.format(output(args.output, args.HOST, 1)))
if args.output:
with open(output(True, args.HOST, 4), "w") as out:
out.write(nm.get_nmap_last_output())
l.log("Finished quick scan") l.log("Finished quick scan")
host_list = dict() host_list = dict()
for hostname in nm.all_hosts(): for hostname in nm.all_hosts():
@ -94,10 +109,10 @@ def run(args):
# Starting thorough and udp scan in separate threads # Starting thorough and udp scan in separate threads
thread_list = [] thread_list = []
for host, open_port_list in host_list.items(): for host, open_port_list in host_list.items():
t1 = ThoroughAnmapThread(host, open_port_list, l, args.o) t1 = ThoroughAnmapThread(host, open_port_list, l, args.output)
t1.start() t1.start()
thread_list.append(t1) thread_list.append(t1)
t2 = UDPAnmapThread(host, args.u, l, args.o) t2 = UDPAnmapThread(host, args.udp, l, args.output)
t2.start() t2.start()
thread_list.append(t2) thread_list.append(t2)
@ -112,11 +127,11 @@ if __name__ == "__main__":
"executing a thorough scan on all ports found open afterwards. " "executing a thorough scan on all ports found open afterwards. "
"Additionally it scans a given number of most used UDP ports.", "Additionally it scans a given number of most used UDP ports.",
prog="anmap.py") prog="anmap.py")
parser.add_argument("-u", default=1000, type=int, help="The number of UDP ports to scan (Default 1000)") parser.add_argument("-u", "--udp", 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("-v", "--verbose", action="store_true", help="This enables verbose output")
parser.add_argument("-d", action="store_true", parser.add_argument("-d", "--debug", action="store_true",
help="Sets flags -v and -u 100 and scans only the first 1000 tcp ports") 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("-o", "--output", 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)") parser.add_argument("HOST", type=str, help="The hosts to scan (Same notations as in nmap possible)")
try: try:

Laden…
Abbrechen
Speichern