Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion wpcar/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

def write_csv(broadcast_stats_list, outfile):
with open(outfile, "w") as f:
writer = csv.writer(f)
writer = csv.writer(f, quoting=csv.QUOTE_ALL, escapechar='\\')
writer.writerow(["ssid", "bssid", "Hidden", "Channel", "Encryption"])
writer.writerows(broadcast_stats_list)

Expand Down
46 changes: 32 additions & 14 deletions wpcar/pcap.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import subprocess
import sys
import tempfile
import binascii

from colorama import Fore, Style
from datetime import datetime
Expand Down Expand Up @@ -99,24 +100,41 @@ def pcapng_to_pcap(infile, outfile=tempfile.NamedTemporaryFile().name):
logger.debug("Pcap %s successfully created", outfile)
return outfile

def is_hex_colon(test):
pattern = r'^([0-9A-Fa-f]{2}:)*[0-9A-Fa-f]{2}$'
match = re.match(pattern, test)
return match is not None

def get_broadcast_stats(pkt):
if int(pkt.wlan.fc_type) is 0:
if int(pkt.wlan.fc_subtype) is 8:
ssid = ''
channel = '0'
ssid_hidden = True
encryption = None
if int(pkt.wlan.fc_type) == 0:
if int(pkt.wlan.fc_subtype) == 8:
bssid = str(pkt.wlan.bssid)
logger.debug("BSSID: %s", bssid)
for layer in pkt.layers:
if 'ssid' in layer.field_names:
ssid = layer.ssid
if 'ds_current_channel' in layer.field_names:
channel = int(layer.ds_current_channel)
if 'fixed_capabilities_privacy' in layer.field_names:
if int(layer.fixed_capabilities_privacy) is 0:
if 'wlan_ssid' in layer.field_names:
ssid = layer.wlan_ssid
if is_hex_colon(ssid):
ssid = ssid.replace(':', '')
bytes_data = binascii.unhexlify(ssid)
ssid = bytes_data.decode('ascii')
logger.debug("SSID: %s", str(ssid))
if 'wlan_ds_current_channel' in layer.field_names:
logger.debug("Channel: %s", layer.wlan_ds_current_channel)
channel = int(layer.wlan_ds_current_channel)
if 'wlan_fixed_capabilities_privacy' in layer.field_names:
logger.debug("Encryption: %s", layer.wlan_fixed_capabilities_privacy)
if int(layer.wlan_fixed_capabilities_privacy) == 0:
encryption = None
else:
encryption = get_encryption(pkt)
logger.debug("Encryption: %s", encryption)
if ssid.startswith("SSID:"):
ssid = ''
if ssid:
if ssid != '':
ssid_hidden = False
else:
ssid_hidden = True
Expand All @@ -132,18 +150,18 @@ def get_encryption(pkt):
cipher = ''
auth = ''
for layer in pkt.layers:
if 'rsn_pcs_list' in layer.field_names:
pcs = str(' '.join(re.findall(r'(AES \(CCM\)|TKIP)', layer.rsn_pcs_list)))
if 'wlan_rsn_pcs_list' in layer.field_names:
pcs = str(' '.join(re.findall(r'(AES \(CCM\)|TKIP)', layer.wlan_rsn_pcs_list)))
privacy = pcs.replace('AES (CCM)', 'CCMP')
if "CCMP" and "TKIP" in privacy:
cipher = "WPA2 WPA"
elif "CCMP" in privacy:
cipher = "WPA2"
elif "TKIP" in privacy:
cipher = "WPA"
if 'rsn_akms_list' in layer.field_names:
if 'wlan_rsn_akms_list' in layer.field_names:
# TODO: I need to test this more for other suites but it seems good.
akms = str(' '.join(re.findall(r'PSK', layer.rsn_akms_list)))
akms = str(' '.join(re.findall(r'PSK', layer.wlan_rsn_akms_list)))
if akms:
auth = akms
else:
Expand All @@ -152,7 +170,7 @@ def get_encryption(pkt):
# Could use some smrtr logic
if encryption == '++':
for layer in pkt.layers:
if 'fixed_capabilities_privacy' in layer.field_names and int(layer.fixed_capabilities_privacy) is 1:
if 'wlan_fixed_capabilities_privacy' in layer.field_names and int(layer.wlan_fixed_capabilities_privacy) == 1:
encryption = str("WEP")
return encryption

Expand Down