-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__main__.py
More file actions
102 lines (91 loc) · 2.74 KB
/
__main__.py
File metadata and controls
102 lines (91 loc) · 2.74 KB
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
93
94
95
96
97
98
99
100
101
102
'''
Windows only.
Use your phone to send UP and DOWN to your computer!
Useful for reading in Kindle.
WARNING: Running this may open vulnerabilities for your computer.
Don't run this if you don't know what you are doing.
Only run this if you are in a safe network, or inside a firewall.
I am not responsible if someone attacks your computer through this server.
'''
print('Loading...')
import keyboard
from interactive import listen
import sys
from myhttp import *
import os
from time import sleep
import qrcode
from threading import Thread
from local_ip import getLocalIP
PORT = 2338
trusted_ip = None
def main():
server = MyServer(MyOneServer, port=PORT)
server.start()
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)
potential_ip = getLocalIP()
imgs = []
class ShowImgThread(Thread):
def __init__(self, img):
Thread.__init__(self)
self.img = img
def run(self):
self.img.show()
potential_ip = {*potential_ip} - {'192.168.56.1'}
# Cisco Anyconnect shit
for ip in potential_ip:
addr = 'http://%s:%d' % (ip, PORT)
try:
imgs.append(qrcode.make(addr))
except Exception as e:
print('Error 198456', e)
print(addr)
print('Ctrl+C to stop.')
print('Q to display QR code for phone scan.')
try:
while True:
op = listen(timeout = 1)
if op == b'\x03':
raise KeyboardInterrupt
elif op == b'q':
[ShowImgThread(x).start() for x in imgs]
print('Loading image.')
elif op == b'\r':
print()
except KeyboardInterrupt:
print('Received ^C. ')
finally:
server.close()
server.join()
class MyOneServer(OneServer):
def handle(self, request):
if request.target == '/':
with open('page.html', 'rb') as f:
respond(self.socket, f.read())
elif request.target == '/down':
keyboard.press('down')
respond(self.socket, b'Yup')
elif request.target == '/up':
keyboard.press('up')
respond(self.socket, b'Yup')
elif request.target in ['/favicon.ico']:
pass
else:
print('Unknown request:', request.target)
class MyServer(Server):
def onConnect(self, addr):
global trusted_ip
if trusted_ip is None:
trusted_ip = addr[0]
elif addr[0] != trusted_ip:
print('SOMEONE IS ATTACKING!', addr)
self.close()
def handleQueue(self, intent):
assert False
def interval(self):
pass
if __name__ == '__main__':
main()
sys.exit(0)