Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_beacon(self):
print_header("Beacon")
# cut away RadioTap header
rlen = self.packet_bytes[0][2]
ieee = ieee80211.IEEE80211(self.packet_bytes[0][rlen:])
self.assertEqual(ieee.bin(), self.packet_bytes[0][rlen:])
self.assertEqual(ieee.version, 0)
self.assertEqual(ieee.type, ieee80211.MGMT_TYPE)
self.assertEqual(ieee.subtype, ieee80211.M_BEACON)
self.assertEqual(ieee.to_ds, 0)
self.assertEqual(ieee.from_ds, 0)
self.assertEqual(ieee.pwr_mgt, 0)
self.assertEqual(ieee.more_data, 0)
self.assertEqual(ieee.protected, 0)
self.assertEqual(ieee.order, 0)
beacon = ieee[ieee80211.IEEE80211.Beacon]
self.assertEqual(beacon.dst, b"\xff\xff\xff\xff\xff\xff")
self.assertEqual(beacon.src, b"\x24\x65\x11\x85\xe9\xae")
self.assertEqual(beacon.bssid, b"\x24\x65\x11\x85\xe9\xae")
print("%04x" % beacon.capa)
self.assertEqual(beacon.seq_frag, 0x702D)
def test_data(self):
print_header("Data")
# cut away RadioTap header
rlen = self.packet_bytes[5][2]
ieee = ieee80211.IEEE80211(self.packet_bytes[5][rlen:])
self.assertEqual(ieee.bin(), self.packet_bytes[5][rlen:])
self.assertEqual(ieee.type, ieee80211.DATA_TYPE)
self.assertEqual(ieee.subtype, ieee80211.D_NORMAL)
self.assertEqual(ieee.protected, 1)
self.assertEqual(ieee.dataframe.dst, b"\x01\x00\x5e\x7f\xff\xfa")
self.assertEqual(ieee.dataframe.src, b"\x00\x1e\xe5\xe0\x8c\x06")
self.assertEqual(ieee.dataframe.bssid, b"\x00\x22\x3f\x89\x0d\xd4")
self.assertEqual(ieee.dataframe.seq_frag, 0x501e)
print(ieee.dataframe.body_bytes)
self.assertEqual(ieee.dataframe.body_bytes,
b"\x62\x22\x39\x61\x98\xd1\xff\x34" +
b"\x65\xab\xc1\x3c\x8e\xcb\xec\xef\xef\xf6\x25\xab\xe5\x89\x86\xdf\x74\x19\xb0" +
b"\xa4\x86\xc2\xdb\x38\x20\x59\x08\x1f\x04\x1b\x96\x6b\x01\xd7\x6a\x85\x73\xf5" +
b"\x4a\xf1\xa1\x2f\xf3\xfb\x49\xb7\x6b\x6a\x38\xef\xa8\x39\x33\xa1\xc8\x29\xc7" +
b"\x0a\x88\x39\x7c\x31\xbf\x55\x96\x24\xd5\xe1\xbf\x62\x85\x2c\xe3\xdf\xb6\x80" +
b"\x3e\x92\x1c\xbf\x13\xcd\x47\x00\x8e\x9f\xc6\xa7\x81\x91\x71\x9c\x0c\xad\x08" +
def wifi_ap_cb(pargs):
"""
Create a massive amount of fake APs
"""
if pargs.channels is not None:
channels = [int(channel) for channel in pargs.channels.split(",")]
else:
channels = utils.get_available_wlan_channels(pargs.iface_name)
beacon_orig = radiotap.Radiotap() + \
ieee80211.IEEE80211(type=ieee80211.MGMT_TYPE, subtype=ieee80211.M_BEACON, to_ds=0, from_ds=0) + \
ieee80211.IEEE80211.Beacon(
dst=b"\xFF\xFF\xFF\xFF\xFF\xFF",
src=b"\xFF\xFF\xFF\xFF\xFF\xFF",
params=[ieee80211.IEEE80211.IE(id=0, len=10, body_bytes=b"\x00" * 10),
ieee80211.IEEE80211.IE(id=1, len=8, body_bytes=b"\x82\x84\x8b\x96\x0c\x12\x18\x24"),
ieee80211.IEEE80211.IE(id=3, len=1, body_bytes=b"\x04"),
ieee80211.IEEE80211.IE(id=5, len=4, body_bytes=b"\x00\x01\x00\x00"),
ieee80211.IEEE80211.IE(id=0x2A, len=1, body_bytes=b"\x00")])
beacon = copy.deepcopy(beacon_orig)
_beacon = beacon[ieee80211.IEEE80211.Beacon]
mac = pypacker.get_rnd_mac()
essid = "FreeHotspot"
_beacon.src = mac
_beacon.bssid = mac
_beacon.params[0].body_bytes = bytes(essid, "ascii")
_beacon.params[0].len = len(essid)
def _dissect(self, buf):
self._init_triggerlist("params", buf[20:], IEEE80211._unpack_ies)
return len(buf)
IE_ESR : IE,
IE_HT_INFO : IE
}
# handler for IEEE80211
# position in list = type-ID
dicts = [IEEE80211.m_decoder, IEEE80211.c_decoder, IEEE80211.d_decoder]
decoder_dict_complete = {}
for pos, decoder_dict in enumerate(dicts):
for key_decoder, val_decoder in decoder_dict.items():
# same subtype-ID for different type-IDs, distinguish via "type_factor + subtype"
# not doing so would lead to eg: type:0 + subtype:1 == type:1 + subtype:0
decoder_dict_complete[TYPE_FACTORS[pos] + key_decoder] = val_decoder
pypacker.Packet.load_handler(IEEE80211, decoder_dict_complete)
# handler for Action
CATEGORY_BLOCK_ACK_FACTOR = IEEE80211.Action.CATEGORY_BLOCK_ACK * 4
pypacker.Packet.load_handler(IEEE80211.Action,
{
CATEGORY_BLOCK_ACK_FACTOR + IEEE80211.Action.CODE_BLOCK_ACK_REQUEST: IEEE80211.Action.BlockAckRequest,
CATEGORY_BLOCK_ACK_FACTOR + IEEE80211.Action.CODE_BLOCK_ACK_RESPONSE: IEEE80211.Action.BlockAckResponse
}
ie_decoder = {
IE_SSID : IE,
IE_RATES : IE,
IE_FH : FH,
IE_DS : DS,
IE_CF : CF,
IE_TIM : TIM,
IE_IBSS : IBSS,
IE_HT_CAPA : IE,
IE_ESR : IE,
IE_HT_INFO : IE
}
# handler for IEEE80211
# position in list = type-ID
dicts = [IEEE80211.m_decoder, IEEE80211.c_decoder, IEEE80211.d_decoder]
decoder_dict_complete = {}
for pos, decoder_dict in enumerate(dicts):
for key_decoder, val_decoder in decoder_dict.items():
# same subtype-ID for different type-IDs, distinguish via "type_factor + subtype"
# not doing so would lead to eg: type:0 + subtype:1 == type:1 + subtype:0
decoder_dict_complete[TYPE_FACTORS[pos] + key_decoder] = val_decoder
pypacker.Packet.load_handler(IEEE80211, decoder_dict_complete)
# handler for Action
CATEGORY_BLOCK_ACK_FACTOR = IEEE80211.Action.CATEGORY_BLOCK_ACK * 4
pypacker.Packet.load_handler(IEEE80211.Action,
{
CATEGORY_BLOCK_ACK_FACTOR + IEEE80211.Action.CODE_BLOCK_ACK_REQUEST: IEEE80211.Action.BlockAckRequest,
CATEGORY_BLOCK_ACK_FACTOR + IEEE80211.Action.CODE_BLOCK_ACK_RESPONSE: IEEE80211.Action.BlockAckResponse
start_time = time.time()
aps_per_channel = 5
current_channel = 1
for i in range(1, 10000):
if i % 100 == 0:
diff = time.time() - start_time
print("%d pps" % (i / diff))
if i % aps_per_channel == 0:
current_channel += 1
current_channel %= 13
if current_channel == 0:
current_channel = 1
# utils.switch_wlan_channel(wlan_monitor_if, current_channel)
_beacon = beacon[ieee80211.IEEE80211.Beacon]
mac = pypacker.get_rnd_mac()
_beacon.src = mac
_beacon.bssid = mac
# set new ssid
_beacon.params[0].body_bytes = bytes("".join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10)), "ascii")
# print(_beacon.params[0].body_bytes)
_beacon.seq = 0
# print(_beacon)
try:
for x in range(100):
# send multiple beacons for every ap
psocket.send(beacon.bin())
_beacon.seq = x
# _beacon.ts = x << (8*7)
wlan_reader = psocket.SocketHndl(wlan_monitor_if)
print("please wait for wlan traffic to show up")
raw_bytes = wlan_reader.recv()
# print(Radiotap(raw_bytes))
print(prism.Prism(raw_bytes))
# grab some beacons on the current channel
bc_cnt = 0
for i in range(10):
raw_bytes = wlan_reader.recv()
# drvinfo = radiotap.Radiotap(raw_bytes)
drvinfo = prism.Prism(raw_bytes)
try:
beacon = drvinfo[ieee80211.IEEE80211.Beacon]
if beacon is None:
continue
mac_ap = drvinfo[ieee80211.IEEE80211.MGMTFrame].bssid
mac_ap = pypacker.mac_bytes_to_str(mac_ap)
# print("beacon: %s" % beacon)
# assume ascending order, 1st IE is Beacon
ie_ssid = beacon.ies[0].body_bytes
# Note: only for prism-header
print("bssid: %s, ssid: %s (Signal: -%d dB, Quality: %d)"
% (mac_ap,
ie_ssid,
0xffffffff ^ drvinfo.dids[3].value,
drvinfo.dids[4].value)
)
bc_cnt += 1
except Exception as e: