-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathVertX_Query.py
executable file
·211 lines (178 loc) · 6.82 KB
/
VertX_Query.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
#!/usr/bin/env python
#
# VertX_Query.py - HID VertX Discovery and Query Tool
# by brad antoniewicz
#
import struct
import socket
import binascii
import getopt
import sys
import random
from socket import *
def usage():
help = "Options:\n"
help += "\t-h <host>\t host\n"
help += "\t-p <port>\t port (default 4070)\n"
help += "\t-v \t\t verbose\n"
help += "\t-m <code> \t Message Type code\n"
help += "\t-A <args> \t Arguments to append to message, if Message Type code supports it\n"
help += "\nSupported Message Types:\n"
help += "\t01 \t Discover\n"
help += "\t02 \t command_blink_on \t args=time to blink\n"
help += "\t03 \t command_blink_off\n"
return help
def process_resp(recv_data,msg_type):
# ('discovered;090;MAC_ADDR;VertXController;IP_ADDR;2;V2000;2.2.7.18;02/27/2007;', ('10.112.18.50', 4070))
mac=0
if msg_type == "01":
data = recv_data[0].split(';')
print "\tType:\t\t",data[3],"-",data[6]
print "\tVersion:\t",data[7]
print "\tIP Address:\t",data[4]
print "\tMAC Address:\t",data[2]
mac = data[2]
return mac
def get_mac(host,port):
msg_to_send = buildmsg("01",0,0,host,port)
if msg_to_send:
mac = sendmsg(host,port,binascii.unhexlify(msg_to_send),0,0,"01")
return mac
def buildmsg(msg_type,args,verbose,host,port):
# Basic Connect
if msg_type == "01" :
# discover;013;
msg = "646973636f7665723b3031333b"
elif msg_type == "02":
# command_blink_on;042;MAC_ADDR;30;
if args == 0:
args = 30
print "[+] Querying Host first to pull MAC address"
msg = "command_blink_on;042;"
msg += get_mac(host,port)
msg += ";%s;" % args
msg = binascii.hexlify(msg)
print "[+] Sending command_blink_on"
elif msg_type == "03":
# command_blink_off;042;MAC_ADDR;1;
print "[+] Querying host first to pull MAC address"
msg = "command_blink_off;042;"
msg += get_mac(host,port)
msg += ";1;"
msg = binascii.hexlify(msg)
print "[+] Sending command_blink_off"
else :
print "[!] Message Type", msg_type, "unsupported!"
print "[!] Unsupported message types can only be used with -f\n"
print "[!] Quiting..."
return 0
## Get the length of our msg
total_length = len(binascii.unhexlify(msg))
datahex=msg
if verbose:
print '[Verbose] Message before Send:\nH(', total_length, '):', datahex, '\t | \tA:', binascii.unhexlify(datahex)
return datahex
def sendmsg(host,port,hex_msg,verbose,count,msg_type):
udp=0
#sss0bbb 2016-04-01 added to correct UnboundLocalError
mac=0
if ((msg_type == "01") or (msg_type == "02") or (msg_type == "03")):
if verbose:
print '[Verbose] Message type indicates UDP'
udp=1
if udp:
s = socket(AF_INET,SOCK_DGRAM)
if ( host == "255.255.255.255"):
if verbose:
print '[Verbose] Destination is Broadcast'
s.bind(('',0))
s.setsockopt(SOL_SOCKET, SO_BROADCAST,1)
else:
s = socket.socket()
s.settimeout(2)
recv_data = 0
if verbose:
print '[+] Target',host,':',port
print "[+] Sending msg with length",len(hex_msg)
if udp:
s.sendto(hex_msg,(host,port))
error=0
else:
s.connect((host,port))
error = s.sendall(hex_msg)
if error:
print "[!] Error:",error
else:
try:
if udp:
recv_data = s.recvfrom(1024);
else:
recv_data = s.recv(1024);
except:
if count:
print "[",count,":ALERT] Client timed out or didnt respond!"
else:
print "[ALERT] Client timed out or didnt respond!"
if recv_data:
if verbose:
print '[+] Client Resp:'
print '\t ascii:\t',recv_data
if not udp:
print '\t hex:\t',binascii.hexlify(recv_data)
else:
print "[+] Got Response"
mac = process_resp(recv_data,msg_type)
else:
if count:
print "[",count,"] No recv_data"
else:
print "[+] No recv_data"
if not udp:
s.shutdown(2)
s.close()
if mac:
return mac
def main():
print "VertX_Query.py - HID VertX Discovery and Query Tool"
print "by brad antoniewicz"
print "--------------------------------------\n"
try:
opts, args = getopt.getopt(sys.argv[1:], "h:p:m:vfs:atA:",[])
except getopt.GetoptError:
print usage()
return
port = 4070
host = cmdcode = verbose = fuzz = hex_str = dumbfuzz = ftype = vals = args = 0
for o, a in opts:
if o == "-h":
host = a
if o == "-p":
port = int(a)
if o == "-m":
cmdcode = a
if o == "-v":
verbose = 1
if o == "-f":
fuzz = 1
if o == "-s":
hex_str = a
if o == "-a":
vals = 1
if o == "-t":
ftype = a
if o == "-A":
args = a
if (host == 0) or (cmdcode == 0):
print usage()
return
if verbose and cmdcode:
print "[Verbose] Command code: ",cmdcode
if fuzz:
fuzz_msg(host,port,cmdcode,hex_str,verbose,ftype,vals)
elif dumbfuzz:
dumbfuzzer(verbose)
else:
msg_to_send = buildmsg(cmdcode,args,verbose,host,port)
if msg_to_send:
sendmsg(host,port,binascii.unhexlify(msg_to_send),verbose,0,cmdcode)
main()