-
Notifications
You must be signed in to change notification settings - Fork 45
/
WhidEngine.py
63 lines (52 loc) · 2.44 KB
/
WhidEngine.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
import requests
import re
from pathlib import Path
from urllib.parse import urlencode, quote_plus
class WhidEngine(object):
# NOTE: check if the panel is reachable
def __init__(self, panel):
try:
if not "ESPloit" in requests.get(panel, timeout=1).text:
print("\033[91mError 404, are you connected on the right AP?")
self.update_firmware()
except Exception as e:
print (e)
print("\033[91mError, couldn't reach the Wifi Portal !\033[0m")
# NOTE: this update use the last firmware on Github
# You may need to build a new one with your keyboard mapping
def update_firmware(self):
update = "https://github.com/exploitagency/ESPloitV2/releases"
update = requests.get(update).text
regex = re.compile("exploit.*\.bin")
last = "https://github.com/" + regex.findall(update)[0]
name = "firmware/"+"-".join(last.split('/')[-2:])
download = Path(name)
if not download.exists():
print("Downloading the last release: %s" % last)
r = requests.get(last, stream=True)
if r.status_code == 200:
with open(name, 'wb') as f:
for chunk in r:
f.write(chunk)
# NOTE: send the payload to the /runlivepayload page
def send_payload(self, user_converted, panel):
payloads = { "livepayload":user_converted, "livepayloadpresent":1}
encoded = urlencode( payloads, quote_via=quote_plus)
try:
print('Sending payload to %s' % panel)
if not "200" in str(requests.post(panel, data=encoded)):
print("\033[91mError 404, are you connected on the right AP?")
except Exception as e:
print("\033[91mError, couldn't reach the Wifi Portal !")
# NOTE : mapping is use for retro-compatibility
def convert_to_keymap(self, user_input, payload, mapping=False):
if mapping:
# Dirty version, if you don't want to upgrade the firmware
fr_mapping = './mazqwAZQW&é"\'(-è_çà)^$Mù,?;:!§1234567890'
en_mapping = '<>;qwazQWAZ1234567890-[]:\'mM,./?!@#$%^&*()'
user_converted = user_input.translate(str.maketrans(fr_mapping,en_mapping))
else:
user_converted = user_input
# Merge the payload and the user input
user_converted = payload % user_converted
return user_converted