Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Commit

Permalink
[Windows] Defense against multiple USB devices with the
Browse files Browse the repository at this point in the history
same Vendor/Product IDs.
Additionally, when the system is killed send the device that caused it if applicable
  • Loading branch information
Lvl4Sword authored May 1, 2019
1 parent f7d4892 commit 288ccde
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions killer/killer_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def detect_bt(self):
raise NotImplementedError

def detect_usb(self):
# TODO - Should this return if nothing is in the whitelist?
# Feels like it should be done elsewhere.
if not self.config['windows']['usb_id_whitelist']:
log.warning("No USB devices whitelisted, skipping detection...")
return
Expand All @@ -34,20 +36,26 @@ def detect_usb(self):
hex_id = '%X' % (0x100000000 + decimal_id)
ids.append(hex_id)

log.debug('USB: %s', ', '.join(ids) if ids else 'none detected')
log.debug('USB:', ', '.join(ids) if ids else 'none detected')

for each_device in ids:
if each_device not in self.config['windows']['usb_id_whitelist']:
self.kill_the_system('USB Allowed Whitelist')
self.kill_the_system('USB Allowed Whitelist: {0}'.format(each_device))
else:
if self.config['windows']['usb_id_whitelist'][each_device] != ids.count(each_device):
self.kill_the_system('USB Duplicate Device: {0}'.format(each_device))
for device in self.config['windows']['usb_connected_whitelist']:
if device not in ids:
self.kill_the_system('USB Connected Whitelist')
self.kill_the_system('USB Connected Whitelist: {0}'.format(device))
else:
if self.config['windows']['usb_connected_whitelist'][each_device] != ids.count(each_device):
self.kill_the_system('USB Whitelist Duplicate Device: {0}'.format(each_device))

def detect_ac(self):
status = power.get_power_status().ac_line_status
status = power.ACLineStatus(status)

log.debug('AC: %s', status.name)
log.debug('AC:', status.name)

if status != power.ACLineStatus.ONLINE:
# If not connected to power, shutdown
Expand All @@ -57,7 +65,7 @@ def detect_battery(self):
status = power.get_power_status().battery_flag
status = power.BatteryFlags(status)

log.debug('Battery: %s', status)
log.debug('Battery:', status)

if status == power.BatteryFlags.NONE:
self.kill_the_system('Battery')
Expand All @@ -72,7 +80,7 @@ def detect_ethernet(self):
for each in ipconfig_cmd.split('\r\n\r\n'):
mac_address = re.findall(MAC_ADDRESS_REGEX, each)
if mac_address == self.config['windows']['ethernet_interface']:
log.debug('MAC Address Detected: %s', mac_address)
log.debug('MAC Address:', mac_address)
media_state = re.findall(MEDIA_STATE_REGEX, each)
if media_state:
self.kill_the_system('Ethernet')
Expand Down

0 comments on commit 288ccde

Please sign in to comment.