How to use the pypacker.layer12.ieee80211 function in pypacker

To help you get started, we’ve selected a few pypacker examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mike01 / pypacker / tests / test_pypacker.py View on Github external
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" +
			b"\xe2\xe8\x5f\xac\xd3\x1c\x90\x16\x15\xa0\x71\x30\xee\xac\xdd\xe5\x8d\x1f\x5b" +
			b"\xbc\xb6\x03\x51\xf1\xee\xff\xaa\xc9\xf5\x16\x1d\x2c\x5e\x52\x49\x3c\xaf\x7f" +
			b"\x13\x12\x1a\x24\xfb\xb8\xc1\x4e\xb7\xd8\x53\xfb\x76\xc0\x6e\xc8\x30\x8d\x2a" +
github mike01 / pypacker / tests / test_pypacker.py View on Github external
def test_data_qos(self):
		print_header("Data QoS")
		# cut away RadioTap header
		rlen = self.packet_bytes[3][2]
		ieee = ieee80211.IEEE80211(self.packet_bytes[3][rlen:])
		self.assertEqual(ieee.bin(), self.packet_bytes[3][rlen:])
		self.assertEqual(ieee.type, ieee80211.DATA_TYPE)
		self.assertEqual(ieee.subtype, ieee80211.D_QOS_DATA)
		self.assertEqual(ieee.dataframe.bssid, b"\x24\x65\x11\x85\xe9\xae")
		self.assertEqual(ieee.dataframe.src, b"\x00\xa0\x0b\x21\x37\x84")
		self.assertEqual(ieee.dataframe.dst, b"\x24\x65\x11\x85\xe9\xac")
		self.assertEqual(ieee.dataframe.seq_frag, 0xd008)
		print(ieee.dataframe.body_bytes)
		self.assertEqual(ieee.dataframe.body_bytes,
			b"\xaa\xaa\x03\x00\x00\x00\x08\x06\x00\x01" +
			b"\x08\x00\x06\x04\x00\x01\x00\xa0\x0b\x21\x37\x84\xc0\xa8\xb2\x16\x00\x00\x00\x00" +
			b"\x00\x00\xc0\xa8\xb2\x01")
github mike01 / pypacker / tests / test_pypacker.py View on Github external
def test_ack(self):
		print_header("ACK")
		# cut away RadioTap header
		rlen = self.packet_bytes[2][2]
		ieee = ieee80211.IEEE80211(self.packet_bytes[2][rlen:])
		self.assertEqual(ieee.bin(), self.packet_bytes[2][rlen:])
		self.assertEqual(ieee.version, 0)
		self.assertEqual(ieee.type, ieee80211.CTL_TYPE)
		self.assertEqual(ieee.subtype, ieee80211.C_ACK)
		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)
		# print(ieee)
		self.assertEqual(ieee.ack.dst, b"\x00\xa0\x0b\x21\x37\x84")
github mike01 / pypacker / tests / test_pypacker.py View on Github external
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" +
			b"\xe2\xe8\x5f\xac\xd3\x1c\x90\x16\x15\xa0\x71\x30\xee\xac\xdd\xe5\x8d\x1f\x5b" +
			b"\xbc\xb6\x03\x51\xf1\xee\xff\xaa\xc9\xf5\x16\x1d\x2c\x5e\x52\x49\x3c\xaf\x7f" +
github mike01 / pypacker / pypacker / layer12 / radiotap.py View on Github external
if channel >= 15:
		return 5035000000 + (channel - 7) * 5 * 1000000
	return None


class Radiotap(pypacker.Packet):
	__hdr__ = (
		("version", "B", 0),
		("pad", "B", 0),
		("len", "H", 0x0800),
		("present_flags", "I", 0),
		("flags", None, FlagTriggerList)		# stores: (XXX_MASK, value)
	)

	__handler__ = {
		RTAP_TYPE_80211: ieee80211.IEEE80211
	}

	# handle frame check sequence
	def _get_fcs(self):
		try:
			return self._fcs
		except AttributeError:
			return b""

	def _set_fcs(self, fcs):
		self._fcs = fcs

	fcs = property(_get_fcs, _set_fcs)

	def _get_channel(self):
		return self.flags.get_by_key(CHANNEL_MASK)
github mike01 / sledgehammer / sledgehammer.py View on Github external
if bssid in pargs.macs_excluded:
					#logger.debug("excluding AP: %r", bssid)
					continue

				if client in pargs.macs_excluded or\
						client in wdata[pargs.current_channel][bssid]:
					#logger.debug("excluding client: %r", bssid)
					continue
					# logger.debug("new client: %r %s", client, utils.get_vendor_for_mac(client))
				wdata[pargs.current_channel][bssid].add(client)

	pargs.is_running = True
	pargs.current_channel = channels[0]

	layer_radiotap = radiotap.Radiotap()
	layer_iee80211 = ieee80211.IEEE80211(type=ieee80211.MGMT_TYPE,
										subtype=ieee80211.M_DEAUTH)
	layer_deauth = ieee80211.IEEE80211.Deauth()
	pkt_deauth = layer_radiotap + layer_iee80211 + layer_deauth

	thread_listen = threading.Thread(target=listen_cycler, args=[pargs])
	thread_listen.start()

	logger.info("first round slow start..")

	for cnt in range(pargs.count):
		seq = 0
		layer_deauth.seq = seq

		if not pargs.is_running:
			break
github mike01 / pypacker / tools / beacon_fetcher.py View on Github external
wlan_reader	= psocket.SocketHndl(iface_name=wlan_monitor_if, timeout=999)

print("please wait for wlan traffic to show up")

aps_found	= {}
time_start	= time.time()

for i in range(100000):
	raw_bytes = wlan_reader.recv()
	drvinfo = radiotap.Radiotap(raw_bytes)

	if i % 1000 == 0:
		print("packets/s: %d" % (i / (time.time() - time_start)))

	try:
		beacon = drvinfo[ieee80211.IEEE80211.Beacon]

		if beacon is None:
			continue

		mac_ap = beacon.src1_s
		# print(beacon)
		ie_ssid	= beacon.params[0].data

		# signal	= 0xffffffff ^ drvinfo.dids[3].value
		# quality	= drvinfo.dids[4].value

		if mac_ap not in aps_found:
			aps_found[mac_ap] = ie_ssid
			# print("found new AP: %s, %s, -%d dB, Quality: %d" % (mac_ap, ie_ssid, signal, quality))
			print("found new AP: %s %s" % (mac_ap, ie_ssid))
	except Exception as e:
github mike01 / pypacker / tools / ap_dos.py View on Github external
from pypacker import psocket

# name of monitor interface to use
wlan_monitor_if	= sys.argv[1]
# MAC address of access point
ap_mac		= sys.argv[2]

print("interface/ap: %s %s" % (wlan_monitor_if, ap_mac))
utils.set_wlan_monmode(wlan_monitor_if, monitor_active=False, reactivate=False)
utils.set_ethernet_address(wlan_monitor_if, "24:77:03:01:5C:8D")
utils.set_wlan_monmode(wlan_monitor_if, monitor_active=True)

psocket		= psocket.SocketHndl(wlan_monitor_if)

auth_req_orig	= radiotap.Radiotap() +\
		ieee80211.IEEE80211(type=ieee80211.MGMT_TYPE, subtype=ieee80211.M_AUTH, to_ds=0, from_ds=0) +\
		ieee80211.IEEE80211.Auth(dst_s=ap_mac, bssid_s=ap_mac)
beacon_orig	= radiotap.Radiotap() +\
		ieee80211.IEEE80211(type=ieee80211.MGMT_TYPE, subtype=ieee80211.M_BEACON, to_ds=0, from_ds=0) +\
		ieee80211.IEEE80211.Beacon(
			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")]
		)


def send_auth(mac):
	"""Send authentications to ap having mac 'mac'"""
	auth_req = copy.deepcopy(auth_req_orig)
	start_time = time.time()
github mike01 / pypacker / tools / visualize_wlan.py View on Github external
def config_cb(packet, v_src, v_dst, edge, config_v, config_e):
	# print("got packet...")
	# v_src.cnt_n += 1
	# v_dst.cnt_n += 1

	if packet[ieee80211.IEEE80211.Beacon] is not None:
		beacon = packet[ieee80211.IEEE80211.Beacon]
		v_src.mac_s = beacon.src_s
		v_src.ssid_s = beacon.params.find_value(0, extract_cb=lambda x: x.id).body_bytes.decode("utf-8")
		# config_v["text"][v_src] = v_src.mac_s + "|" + v_src.ssid_s
	elif packet[ieee80211.IEEE80211.Dataframe] is not None:
		data = packet[ieee80211.IEEE80211.Dataframe]
		# config_v["text"][v_src] = v_src.mac_s = data.src_s
		# v_src.mac_s = data.src_s
		v_src.mac_s = data.bssid_s
		if data.dst_s != "FF:FF:FF:FF:FF:FF":
			v_dst.mac_s = data.dst_s

		# if len(v_dst.mac_s) == 0:
			# only set if not already set
			# config_v["text"][v_dst] = v_dst.mac_s = data.dst_s

	config_v["text"][v_src] = v_src.mac_s + "|" + v_src.ssid_s

	if edge is not None:
		config_v["text"][v_dst] = v_dst.mac_s + "|" + v_dst.ssid_s
		edge.cnt_n += 1
		config_e["text"][edge] = "(%s)" % edge.cnt_n