def filter_mac_one_way(smac, dmac): smac = mac_str_to_bytes(smac) dmac = mac_str_to_bytes(dmac) def f(rt): curr = rt.upper_layer while curr is not None: if hasattr(curr, 'src') and hasattr(curr, 'dst'): return curr.src == smac and curr.dst == dmac curr = curr.upper_layer return False return PacketFilter(f)
def filter_mac_two_way(mac1, mac2): mac1 = mac_str_to_bytes(mac1) mac2 = mac_str_to_bytes(mac2) def f(rt): curr = rt.upper_layer # radio tap does not have mac while curr is not None: if hasattr(curr, 'src') and hasattr(curr, 'dst'): return (curr.src == mac1 and curr.dst == mac2) or \ (curr.src == mac2 and curr.dst == mac1) curr = curr.upper_layer return False return PacketFilter(f)
def filter_mac_dest(mac): mac = mac_str_to_bytes(mac) def f(rt): curr = rt.upper_layer while curr is not None: if hasattr(curr, 'dst'): return curr.dst == mac curr = curr.upper_layer return False return PacketFilter(f)
def filter_mac_any(mac): mac = mac_str_to_bytes(mac) def f(rt): curr = rt.upper_layer while curr is not None: if (hasattr(curr, 'src') and curr.src == mac) or \ (hasattr(curr, 'dst') and curr.dst == mac): return True curr = curr.upper_layer return False return PacketFilter(f)
from pypacker.layer567 import dhcp from pypacker import psocket import time # interface to listen on IFACE = "wlan0" # # spoof DHCP request # dhcp_param = [dhcp.DHCP_OPT_NETMASK, dhcp.DHCP_OPT_ROUTER, dhcp.DHCP_OPT_DNS_SVRS, dhcp.DHCP_OPT_NISTIMESERV] dhcp_spoof = ethernet.Ethernet(src_s="20:16:d8:ef:1f:49", dst_s="ff:ff:ff:ff:ff:ff") +\ ip.IP(src_s="0.0.0.0", dst_s="255.255.255.255", p=ip.IP_PROTO_UDP, id=1) +\ udp.UDP(sport=68, dport=67) +\ dhcp.DHCP(chaddr=pypacker.mac_str_to_bytes("20:16:d8:ef:1f:49") + b"\x00" * 10, xid=0, opts=[ dhcp.DHCPOptMulti(type=dhcp.DHCP_OPT_MSGTYPE, len=3, body_bytes=b"\x01"), dhcp.DHCPOptSingle(type=0xff) ] ) psock = psocket.SocketHndl(iface_name=IFACE) for a in range(9): print("sending DHCP request") psock.send(dhcp_spoof.bin()) mac = "08:9e:01:dd:ee:f%d" % a dhcp_spoof.src_s = mac dhcp_spoof.chaddr = pypacker.mac_str_to_bytes(mac) + b"\x00" * 10
type=bool, help="Disable broadcast deauth", required=False, default=False) parser.add_argument("--macs_excluded", type=str, help="MAC addresses to exclude for deauth", required=False, default=set()) args = parser.parse_args() args.mac_src, args.ip_src = get_iface_info(args.iface_name) if type(args.macs_excluded) is str: args.macs_excluded = set([ pypacker.mac_str_to_bytes(mac) for mac in args.macs_excluded.split(",") ]) wifi_modes = {"wifi_deauth", "wifi_ap", "wifi_ap_ie", "wifi_auth"} if args.mode in wifi_modes: logger.info("trying to activate monitor mode on %s", args.iface_name) try: utils.set_interface_mode(args.iface_name, monitor_active=True, state_active=True) except: logger.warning("you need to be root to execute this attack") sys.exit(1)
def extract_features(mac, ws, we, data): mac_bytes = mac_str_to_bytes(mac) w = we - ws ctot_num = np.zeros(1) ctot_sz = np.zeros(1) stot_num = np.zeros(1) stot_sz = np.zeros(1) rtot_num = np.zeros(1) rtot_sz = np.zeros(1) l2tot_sz = np.zeros(1) ct_num = np.zeros(3) ct_sz = np.zeros(3) st_num = np.zeros(3) st_sz = np.zeros(3) rt_num = np.zeros(3) rt_sz = np.zeros(3) l2t_sz = np.zeros(3) c_num = np.zeros(64) c_sz = np.zeros(64) s_num = np.zeros(64) s_sz = np.zeros(64) r_num = np.zeros(64) r_sz = np.zeros(64) sts = None for ts, pkt in data: sts = ts if sts is None else sts ieee = pkt.ieee80211 l = len(ieee) ll = l * l tp = ieee.type stp = (ieee.subtype << 2) | ieee.type try: is_src = hasattr(ieee.upper_layer, 'src') and ieee.upper_layer.src == mac_bytes is_dst = hasattr(ieee.upper_layer, 'dst') and ieee.upper_layer.dst == mac_bytes except: print('Skipped packet:', mac, (ts - sts) / (10**9)) continue if is_src: stot_num += 1 st_num[tp] += 1 s_num[stp] += 1 stot_sz += l st_sz[tp] += l s_sz[stp] += l if is_dst: rtot_num += 1 rt_num[tp] += 1 r_num[stp] += 1 rtot_sz += l rt_sz[tp] += l r_sz[stp] += l ctot_num += 1 ct_num[tp] += 1 c_num[stp] += 1 ctot_sz += l ct_sz[tp] += l c_sz[stp] += l ratetot_num = ctot_num / w ratetot_sz = ctot_sz / w ratet_num = ct_num / w ratet_sz = ct_sz / w rate_num = c_num / w rate_sz = c_sz / w fract_num = ct_num / ctot_num fract_sz = ct_sz / ctot_sz frac_num = c_num / ctot_num frac_sz = c_sz / ctot_sz # Use stot_num, stot_sz somewhere? srattot_num = stot_num / ctot_num srattot_sz = stot_sz / ctot_sz sratt_num = st_num / ct_num sratt_sz = st_sz / ct_sz srat_num = s_num / c_num srat_sz = s_sz / c_sz rrattot_num = rtot_num / ctot_num rrattot_sz = rtot_sz / ctot_sz rratt_num = rt_num / ct_num rratt_sz = rt_sz / ct_sz rrat_num = r_num / c_num rrat_sz = r_sz / c_sz ltot_sz = ctot_sz / ctot_num lt_sz = ct_sz / ct_num l_sz = c_sz / c_num sdtot_sz = np.zeros(1) sdt_sz = np.zeros(3) sd_sz = np.zeros(64) for ts, pkt in data: ieee = pkt.ieee80211 l = len(ieee) tp = ieee.type stp = (ieee.subtype << 2) | ieee.type sdtot_sz += (l - ltot_sz)**2 sdt_sz[tp] += (l - lt_sz[tp])**2 sd_sz[stp] += (l - l_sz[stp])**2 sdtot_sz = np.sqrt(sdtot_sz / (ctot_num - 1)) sdt_sz = np.sqrt(sdt_sz / (ct_num - 1)) sd_sz = np.sqrt(sd_sz / (c_num - 1)) vec = list( map( np.nan_to_num, chain(ratetot_num, ratetot_sz, ratet_num, ratet_sz, rate_num, rate_sz, fract_num, fract_sz, frac_num, frac_sz, rrattot_num, rrattot_sz, sratt_num, sratt_sz, srat_num, srat_sz, srattot_num, srattot_sz, rratt_num, rratt_sz, rrat_num, rrat_sz, ltot_sz, lt_sz, l_sz, sdtot_sz, sdt_sz, sd_sz))) return vec