Skip to content

Instantly share code, notes, and snippets.

@stevommmm
Created August 5, 2012 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevommmm/3268114 to your computer and use it in GitHub Desktop.
Save stevommmm/3268114 to your computer and use it in GitHub Desktop.
Quick dirty honeypot
#!/usr/bin/env python
#import thread
import threading
import time
import socket
class honey(threading.Thread):
"""Honeypot"""
def __init__(self, host='', port=6000, f=None):
threading.Thread.__init__(self)
self.host = host
self.port = port
self.f = f
self.running = True
def writelog(self, client, port, data=''):
separator = '=' * 40
self.f.write('Time: %s\nServer Port: %d\nIP Address: %s\nPort: %d\n\n%s%s\n\n' %
(time.ctime(), self.port, client[0], client[1], data, separator))
def run(self):
print '[*] Listening on port %d' % self.port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((self.host, self.port))
s.listen(5)
while self.running:
(insock, address) = s.accept()
print '[*] %s:%d -> %s:%d' % (address[0], address[1], self.host, self.port)
try:
data = insock.recv(1024)
insock.close()
except socket.error:
self.writelog(address, self.port)
else:
self.writelog(address, self.port, data)
if __name__ == '__main__':
host = ''
ports = [23, 25, 1025, 3306]
threads = []
fopen = open('loghoney.txt', 'a')
try:
for port in ports:
print '[+] Starting port %d thread...' % port
threads.append(honey(host, port, fopen))
threads[-1].daemon = True
threads[-1].start()
except BaseException, e:
print '[-] Error: %s' % (e)
exit(1)
# Run forever, or until we kill it >.>
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
print '[+] Exiting...'
for thread in threads:
thread.running = False
time.sleep(3)
fopen.close()
exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment