forked from yesimxev/badbt
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ducky.py
69 lines (51 loc) · 1.79 KB
/
ducky.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
#!/usr/bin/python3
from send_string import BtkStringClient
from time import sleep
import keymap
import getopt
import sys
import os
def modgen(keys):
tmp = [0, 0, 0, 0, 0, 0, 0, 0]
tmp[0] = 1 if ("RIGHTMETA") in keys else 0
tmp[1] = 1 if ("RIGHTALT") in keys else 0
tmp[2] = 1 if ("RIGHTSHIFT") in keys else 0
tmp[3] = 1 if ("RIGHTCTRL") in keys else 0
tmp[4] = 1 if ("GUI" or "META" or "LEFTMETA") in keys else 0
tmp[5] = 1 if ("ALT" or "LEFTALT") in keys else 0
tmp[6] = 1 if ("SHIFT" or "LEFTSHIFT") in keys else 0
tmp[7] = 1 if ("CTRL" or "LEFTCTRL") in keys else 0
return tmp
def f_word(word, line):
if(word == 'REM' or word == '#'):
print('COMMENT')
elif(word == 'STRING'):
ducky.send_string(txt[line][7:])
elif(word == 'DELAY'):
sleep(DEFAULT_DELAY/1000) if len(txt[line]) == 5 else sleep(int(txt[line][6:])/1000)
elif(f'KEY_{word}' in keymap.keytable):
tmpm = modgen(txt[line].split()[:-1])
tmpk = txt[line].split()[-1].upper()
ducky.send_key_down(keymap.keytable[f'KEY_{tmpk}'], tmpm)
ducky.send_key_up()
else:
print('NOT FOUND: '+ word)
if __name__ == "__main__":
if not os.geteuid() == 0:
sys.exit("[!]Run as root")
sopts = 'hd:'
opts, args = getopt.getopt(sys.argv[1:], sopts)
for opt, arg in opts:
if opt == '-h':
print(f'\nUsage:\n\tpython {sys.argv[0]} -d [DUCKY_TXT]')
sys.exit()
elif opt == '-d':
ducky = arg
with open(ducky, 'r') as f:
txt = f.readlines()
for i in range(len(txt)):
txt[i] = txt[i].strip()
ducky = BtkStringClient()
for line in range(len(txt)):
if txt[line]:
f_word(txt[line].split()[0], line)