Initial commit
This commit is contained in:
commit
cd5d416419
2 files changed
+129
No files matched your search
+65
@@ -0,0 +1,65 @@
|
|||||||
|
# Created by https://www.gitignore.io
|
||||||
|
|
||||||
|
### Project ###
|
||||||
|
logins.txt
|
||||||
|
server.key
|
||||||
|
server.pub
|
||||||
|
paramiko.log
|
||||||
|
|
||||||
|
### Python ###
|
||||||
|
# Byte-compiled / optimized / DLL files
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
|
||||||
|
# C extensions
|
||||||
|
*.so
|
||||||
|
|
||||||
|
# Distribution / packaging
|
||||||
|
.Python
|
||||||
|
env/
|
||||||
|
build/
|
||||||
|
develop-eggs/
|
||||||
|
dist/
|
||||||
|
downloads/
|
||||||
|
eggs/
|
||||||
|
lib/
|
||||||
|
lib64/
|
||||||
|
parts/
|
||||||
|
sdist/
|
||||||
|
var/
|
||||||
|
*.egg-info/
|
||||||
|
.installed.cfg
|
||||||
|
*.egg
|
||||||
|
|
||||||
|
# PyInstaller
|
||||||
|
# Usually these files are written by a python script from a template
|
||||||
|
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||||
|
*.manifest
|
||||||
|
*.spec
|
||||||
|
|
||||||
|
# Installer logs
|
||||||
|
pip-log.txt
|
||||||
|
pip-delete-this-directory.txt
|
||||||
|
|
||||||
|
# Unit test / coverage reports
|
||||||
|
htmlcov/
|
||||||
|
.tox/
|
||||||
|
.coverage
|
||||||
|
.cache
|
||||||
|
nosetests.xml
|
||||||
|
coverage.xml
|
||||||
|
|
||||||
|
# Translations
|
||||||
|
*.mo
|
||||||
|
*.pot
|
||||||
|
|
||||||
|
# Django stuff:
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# Sphinx documentation
|
||||||
|
docs/_build/
|
||||||
|
|
||||||
|
# PyBuilder
|
||||||
|
target/
|
||||||
|
|
||||||
|
|
||||||
Executable
+64
@@ -0,0 +1,64 @@
|
|||||||
|
#!/usr/bin/env python2.7
|
||||||
|
import socket, sys, threading, thread
|
||||||
|
import paramiko
|
||||||
|
|
||||||
|
#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_LOCK = threading.Lock()
|
||||||
|
|
||||||
|
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()
|
||||||
|
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()
|
||||||
|
|
||||||
|
transport.start_server(server=server_handler)
|
||||||
|
|
||||||
|
channel = transport.accept(1)
|
||||||
|
if not channel is None:
|
||||||
|
channel.close()
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
paramiko.util.log_to_file ('paramiko.log')
|
||||||
|
|
||||||
|
while(True):
|
||||||
|
try:
|
||||||
|
client_socket, client_addr = server_socket.accept()
|
||||||
|
thread.start_new_thread(handleConnection,(client_socket,))
|
||||||
|
except Exception as e:
|
||||||
|
print("ERROR: Client handling")
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print("ERROR: Failed to create socket")
|
||||||
|
print(e)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
main()
|
||||||
Reference in new issue
Block a user