Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/python2.7
import sys
import os
import threading
import time
import SocketServer
class ThreadedTCPRequestHandler(SocketServer.BaseRequestHandler):
def handle(self):
self.data = self.request.recv(1024).strip()
print "received from %s: " % self.client_address[0]
print self.data
self.request.send(self.data.upper())
class ThreadedTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
pass
if __name__ == "__main__":
if not os.geteuid() == 0:
print "[-] Run as root. Exiting..."
sys.exit()
if len(sys.argv) != 3:
print "[-] Bad number of arguments! Exiting..."
print "[.] Usage:"
print "[.] ./honeypot.py offset range"
print "[.] i.e. \"honeypot.py 30 10\" (ports from 30 to 40)"
sys.exit()
else:
offset = int(sys.argv[1])
arg = int(sys.argv[2])
for i in range(arg):
port = i + offset
if port == 22:
continue
server = ThreadedTCPServer(("", port), ThreadedTCPRequestHandler)
server_thread = threading.Thread(target=server.serve_forever)
server_thread.setDaemon(True)
server_thread.start()
while True:
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment