How to use the pypacker.layer12.radiotap.Radiotap 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_rtap_ieee(self):
		print_header("Radiotap IEEE 80211")
		rtap_ieee = radiotap.Radiotap(self.packet_bytes[0])
		self.assertEqual(rtap_ieee.bin(), self.packet_bytes[0])
		self.assertEqual(rtap_ieee.version, 0)
		print("len: %d" % rtap_ieee.len)
		self.assertEqual(rtap_ieee.len, 0x1200)  # 0x1200 = 18
		self.assertEqual(rtap_ieee.present_flags, 0x2e480000)
github mike01 / sledgehammer / sledgehammer.py View on Github external
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")
github mike01 / pypacker / tools / read_n_show.py View on Github external
"""
	Read cnt packets from a pcap file, default: 1000
	"""
	f = open(fname, "rb")
	pcap = ppcap.Reader(f)

	cnt = 0

	for ts, buf in pcap:
		cnt += 1
		"""
		if cnt > 1:
			continue
		"""
		print(">>> read packet %d" % cnt)
		rt = radiotap.Radiotap(buf)
		print("%r" % rt)
		print("%r" % rt.ieee80211)

		try:
			print("%r" % rt.ieee80211.dataframe)
		except:
			try:
				print("%r" % rt.ieee80211.assocreq)
			except:
				try:
					print("%r" % rt.ieee80211.beacon)
				except:
					try:
						print("%r" % rt.ieee80211.proberesp)
					except:
						try:
github mike01 / pypacker / pypacker / ppcap.py View on Github external
DLT_PPP					= 9
DLT_FDDI				= 10
DLT_PFSYNC				= 18
DLT_IEEE802_11				= 105
DLT_LINUX_SLL				= 113
DLT_PFLOG				= 117
DLT_IEEE802_11_RADIO			= 127
DLT_CAN_SOCKETCAN		        = 227
DLT_LINKTYPE_BLUETOOTH_LE_LL		= 251
LINKTYPE_BLUETOOTH_LE_LL_WITH_PHDR	= 256

PCAPTYPE_CLASS = {
	DLT_LINUX_SLL: linuxcc.LinuxCC,
	DLT_EN10MB: ethernet.Ethernet,
	DLT_CAN_SOCKETCAN: can.CAN,
	DLT_IEEE802_11_RADIO: radiotap.Radiotap,
	LINKTYPE_BLUETOOTH_LE_LL_WITH_PHDR: btle.BTLEHdr
}


class PcapFileHdr(pypacker.Packet):
	"""pcap file header."""
	# header length = 24
	__hdr__ = (
		("magic", "I", TCPDUMP_MAGIC),
		("v_major", "H", PCAP_VERSION_MAJOR),
		("v_minor", "H", PCAP_VERSION_MINOR),
		("thiszone", "I", 0),
		("sigfigs", "I", 0),
		("snaplen", "I", 1500),
		("linktype", "I", 1),
	)
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 / mac_finder.py View on Github external
import sys
import cmd
import re
import socket
import logging
import struct
from multiprocessing import Process, Queue

from sqlalchemy import *
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relation, relationship, sessionmaker

from pypacker.layer12 import ieee80211, radiotap
from pypacker import psocket, utils, ppcap

Radiotap = radiotap.Radiotap

root_logger = logging.getLogger()
root_logger.handlers = []
logger = logging.getLogger("macfinder")
# logger.setLevel(logging.WARNING)
# logger.setLevel(logging.INFO)
logger.setLevel(logging.DEBUG)

# create formatter and add it to the handlers
formatter = logging.Formatter("%(message)s")
streamhandler = logging.StreamHandler()
streamhandler.setFormatter(formatter)
logger.addHandler(streamhandler)

unpack_B = struct.Struct(">B").unpack
github mike01 / pypacker / tools / ap_dos.py View on Github external
from pypacker.layer12 import radiotap, ieee80211
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)
github mike01 / pypacker / tools / visualize_wlan.py View on Github external
def __iter__(self):
		while True:
			try:
				yield self.psock.recvp(lowest_layer=radiotap.Radiotap)[0]
			except Exception as e:
				print(e)
				continue
		self.psock.close()
github mike01 / pypacker / tools / beacon_fetcher.py View on Github external
from pypacker import psocket
from pypacker.layer12 import ieee80211, radiotap
import time

wlan_monitor_if	= "wlan1"

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