Pythonでハニーポット開発
Github上にあるハニーポットを動かそうとしたところエラーが発生した
パッケージがインストールされているがエラーが発生する
$ pip list Package Version ---------------------- -------------------- paramiko 2.4.1
該当のソースコード
https://github.com/apacketofsweets/Heka
Python
1#!/usr/bin/env python2.7 2import socket, sys, threading, thread 3import paramiko 4 5# Heka - A lightweight SSH honeypot for Unix/Linux 6# Keys can be generated by running the below command: 7# 'ssh-keygen -t rsa -f server.key' 8 9# Variables 10HOST_KEY = paramiko.RSAKey(filename='server.key') 11LOGINS = 'heka-logins.log' 12LOGFILE = 'heka-ssh.log' 13LOG_LOCK = threading.Lock() 14 15# Banner that displays when Heka is run 16BANNER = '''[*] Heka - A lightweight SSH Honeypot''' 17print BANNER 18 19# Requests user input on what port to run SSH service on 20PORT = input('[*] Specify what port to listen on: ') 21 22# Errors & Messages 23 24def socketerror(): 25 print("[!] ERROR: Failed to create socket.") 26 27def clienterror(): 28 print("[!] ERROR: Client handling error occurred.") 29 30# Connection logging 31class SSHServerHandler (paramiko.ServerInterface): 32 def __init__(self): 33 self.event = threading.Event() 34 35 def check_auth_password(self, username, password): 36 LOG_LOCK.acquire() 37 try: 38 log_handle = open(LOGINS,"a") 39 print("[#] Login attempt received: " + username + ":" + password) 40 log_handle.write(username + ":" + password + "\n") 41 log_handle.close() 42 finally: 43 LOG_LOCK.release() 44 return paramiko.AUTH_FAILED 45 46 def get_allowed_auths(self, username): 47 return 'password' 48 49# Transport 50def handleConnection(client): 51 transport = paramiko.Transport(client) 52 transport.add_server_key(HOST_KEY) 53 54 server_handler = SSHServerHandler() 55 56 transport.start_server(server=server_handler) 57 58 channel = transport.accept(1) 59 if not channel is None: 60 channel.close() 61 62# Starts SSH server and provides error messages if the connection can't 63# be opened on the specified port 64 65def main(): 66 67 try: 68 server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 69 server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) 70 server_socket.bind(('', PORT)) 71 server_socket.listen(100) 72 73 print "[*] Heka now listening on port %s" % PORT 74 paramiko.util.log_to_file (LOGFILE) 75 76 # Attempts to open socket 77 while(True): 78 try: 79 client_socket, client_addr = server_socket.accept() 80 thread.start_new_thread(handleConnection,(client_socket,)) 81 82 # Print error and exit if socket cannot be opened 83 except Exception as systemerror: 84 clienterror() 85 #print (systemerror) ## Uncomment to print system provided error 86 87 # Print error and exit if socket cannot be opened 88 except Exception as systemerror: 89 socketerror() 90 #print(systemerror) ## Uncomment to print system provided error 91 sys.exit(1) 92 93main()
###実行
$ python2.7 heka.py Traceback (most recent call last): File "heka.py", line 3, in <module> import paramiko ImportError: No module named paramiko
試したこと
$ pip install paramiko $ pip -V pip 20.2.3 from /home/ユーザー名/.local/lib/python3.8/site-packages/pip (python 3.8)
補足情報
Ubuntu 20.04.1 LTS
回答2件
あなたの回答
tips
プレビュー