|
| 1 | +#! /usr/bin/env python3 |
| 2 | + |
| 3 | +''' |
| 4 | +Name: Shinobi-Scanner 1.1 |
| 5 | +Description: Network Scanner |
| 6 | +Version: Python 3.7 |
| 7 | +- |
| 8 | +Author: Igor M. Martins (r4msolo) |
| 9 | +''' |
| 10 | + |
| 11 | +import argparse |
| 12 | +import socket |
| 13 | +import sys |
| 14 | + |
| 15 | +class NetworkScan(): |
| 16 | + |
| 17 | + #Portas encontradas | Port found |
| 18 | + portfound = [] |
| 19 | + |
| 20 | + #Serviços encontrados | Services found |
| 21 | + flagfound = [] |
| 22 | + |
| 23 | + def __init__(self): |
| 24 | + print(banner) |
| 25 | + try: |
| 26 | + self.parameters() |
| 27 | + try: |
| 28 | + domain = args.address,socket.gethostbyaddr(args.address) |
| 29 | + x = domain[1][0] |
| 30 | + z = domain[1][2][0] |
| 31 | + print(RED+BOLD+"\n => Target",x,"<=>",z,"\n"+ENDC) |
| 32 | + except: |
| 33 | + print(RED+BOLD+"\n => Target",args.address,"\n"+ENDC) |
| 34 | + |
| 35 | + self.portScan() |
| 36 | + |
| 37 | + except TypeError: |
| 38 | + print(GREY+"[!] Use ./shinobi.py -h for help"+ENDC) |
| 39 | + quit() |
| 40 | + |
| 41 | + def portScan(self): |
| 42 | + #[DEFAULT] Varre todas portas se não for passado parâmetro | scans all ports as default |
| 43 | + if args.ports == None: |
| 44 | + self.ports = list(range(1,65536)) |
| 45 | + |
| 46 | + #Faz a varredura nas portas somente passadas por parametro | Scans the ports passed by parameter |
| 47 | + elif args.ports != None: |
| 48 | + self.ports = args.ports |
| 49 | + |
| 50 | + try: |
| 51 | + for num, port in enumerate(self.ports): |
| 52 | + conn = socket.socket(socket.AF_INET,socket.SOCK_STREAM) |
| 53 | + conn.settimeout(2) |
| 54 | + if conn.connect_ex((args.address,int(port))) == 0: |
| 55 | + try: |
| 56 | + #busca o serviço por banner retornado | finds the service by the returned banner |
| 57 | + flag = conn.recv(40).decode("utf-8","ignore").strip("\n") |
| 58 | + assert flag |
| 59 | + conn.close() |
| 60 | + |
| 61 | + except: |
| 62 | + flag = "\tUnknown" |
| 63 | + conn.close() |
| 64 | + |
| 65 | + self.portfound.append(port) |
| 66 | + self.flagfound.append(flag) |
| 67 | + |
| 68 | + conn.close() |
| 69 | + print(GREEN+"[!] Scanning ports",str(num+1)+"/"+str(len(self.ports)),"...","Open ports:",len(self.portfound), end = "\r") |
| 70 | + |
| 71 | + if len(self.portfound) >=1: |
| 72 | + self.showResults() |
| 73 | + else: |
| 74 | + print("\n[!] No port found") |
| 75 | + |
| 76 | + |
| 77 | + except KeyboardInterrupt: |
| 78 | + self.showResults() |
| 79 | + print("Scan finished by user...") |
| 80 | + |
| 81 | + def showResults(self): |
| 82 | + print("\n[+] Open ports found:\n[PORT]\t\t[SERVICE]\n") |
| 83 | + for l in self.portfound: |
| 84 | + index = self.portfound.index(l) |
| 85 | + flag = self.flagfound[index] |
| 86 | + print(str(l)+"/tcp"+"\t",flag) |
| 87 | + |
| 88 | + def parameters(self): |
| 89 | + global args |
| 90 | + parser = argparse.ArgumentParser() |
| 91 | + parser.add_argument("-a", dest="address", action="store", help="To set the address (ex. -a 127.0.0.1)") |
| 92 | + parser.add_argument("-p", dest="ports", nargs="+", action="store", help="For specific port scans (ex. -p 22 80)") |
| 93 | + args = parser.parse_args() |
| 94 | + |
| 95 | +'''Colors''' |
| 96 | +BLUE = '\033[94m' |
| 97 | +GREEN = '\033[92m' |
| 98 | +GREY = '\033[93m' |
| 99 | +RED = '\033[91m' |
| 100 | +ENDC = '\033[0m' |
| 101 | +BOLD = '\033[1m' |
| 102 | + |
| 103 | +if __name__ == "__main__": |
| 104 | + NetworkScan() |
0 commit comments