Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3 update #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions honeypot.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
#!/usr/bin/env python2.7
import socket, sys, threading, thread
#!/usr/bin/env python3
import socket, sys, threading
import _thread as thread
import paramiko

#generate keys with 'ssh-keygen -t rsa -f server.key'
# generate keys with 'ssh-keygen -t rsa -f server.key'
HOST_KEY = paramiko.RSAKey(filename='server.key')
SSH_PORT = 2222
LOGFILE = 'logins.txt' #File to log the user:password combinations to
LOGFILE = 'logins.txt' # File to log the user:password combinations to
LOGFILE_LOCK = threading.Lock()

class SSHServerHandler (paramiko.ServerInterface):
class SSHServerHandler(paramiko.ServerInterface):
def __init__(self):
self.event = threading.Event()

def check_auth_password(self, username, password):
LOGFILE_LOCK.acquire()
try:
logfile_handle = open(LOGFILE,"a")
print("New login: " + username + ":" + password)
logfile_handle.write(username + ":" + password + "\n")
logfile_handle.close()
with open(LOGFILE, "a") as logfile_handle:
print("New login: " + username + ":" + password)
logfile_handle.write(username + ":" + password + "\n")
finally:
LOGFILE_LOCK.release()
return paramiko.AUTH_FAILED


def get_allowed_auths(self, username):
return 'password'

def handleConnection(client):
transport = paramiko.Transport(client)

transport.add_server_key(HOST_KEY)

server_handler = SSHServerHandler()
Expand All @@ -38,20 +38,23 @@ def handleConnection(client):
channel = transport.accept(1)
if not channel is None:
channel.close()
print('Closing connection.')

def main():
try:
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server_socket.bind(('', SSH_PORT))
server_socket.listen(100)
print('SSH Honeypot Server Started.')

paramiko.util.log_to_file ('paramiko.log')
paramiko.util.log_to_file('paramiko.log')

while(True):
while True:
try:
client_socket, client_addr = server_socket.accept()
thread.start_new_thread(handleConnection,(client_socket,))
print('Connection Received From:', client_addr)
thread.start_new_thread(handleConnection, (client_socket,))
except Exception as e:
print("ERROR: Client handling")
print(e)
Expand All @@ -61,4 +64,4 @@ def main():
print(e)
sys.exit(1)

main()
main()