| 1 | + | #!/usr/bin/env python3 |
| 2 | + | # server for hosting exploit search |
| 3 | + | |
| 4 | + | from exploitdb import exploitdb |
| 5 | + | import socketserver |
| 6 | + | |
| 7 | + | _PORT_ = 4521 |
| 8 | + | _IP_ = '0.0.0.0' |
| 9 | + | |
| 10 | + | class SearchHandler(socketserver.StreamRequestHandler): |
| 11 | + | def handle(self): |
| 12 | + | print('[+] Connection from '+ self.client_address[0]) |
| 13 | + | data = self.rfile.readline().decode().strip() |
| 14 | + | while not data == '': |
| 15 | + | print('[ ] Searching for: ' + data) |
| 16 | + | output = [ ] |
| 17 | + | results = self.server.search(data) |
| 18 | + | for exploits in results: |
| 19 | + | output.append(exploits[0]['description'] + ' id: ' + exploits[0]['id']) |
| 20 | + | if len(output) > 0: |
| 21 | + | self.wfile.write('\n'.join(output).encode() + b'\n') |
| 22 | + | data = self.rfile.readline().decode().strip() |
| 23 | + | print('[-] Closing connection from ' + self.client_address[0]) |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | class ExploitServer(exploitdb.ExploitSearch, socketserver.ThreadingMixIn, socketserver.TCPServer): |
| 28 | + | def __init__(self, connectionInfo, handler): |
| 29 | + | exploitdb.ExploitSearch.__init__(self) |
| 30 | + | socketserver.TCPServer.__init__(self, connectionInfo, handler) |
| 31 | + | socketserver.ThreadingMixIn.__init__(self) |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | def main(): |
| 38 | + | exploit = ExploitServer((_IP_, _PORT_), SearchHandler) |
| 39 | + | print('[ ] Starting server on port ' + str(_PORT_)) |
| 40 | + | try: |
| 41 | + | exploit.serve_forever() |
| 42 | + | except: |
| 43 | + | print('[-] Caught exception. Shutting down.') |
| 44 | + | exploit.shutdown() |
| 45 | + | exploit.server_close() |
| 46 | + | |
| 47 | + | if __name__ == "__main__": |
| 48 | + | main() |