def test_ap_pmf_sta_sa_query_no_response(dev, apdev): """WPA2-PSK AP with station using SA Query and getting no response""" ssid = "assoc-comeback" addr = dev[0].own_addr() wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5", drv_params="use_monitor=1") id = wpas.add_network() wpas.set_network(id, "mode", "2") wpas.set_network_quoted(id, "ssid", ssid) wpas.set_network(id, "proto", "WPA2") wpas.set_network(id, "key_mgmt", "WPA-PSK-SHA256") wpas.set_network(id, "ieee80211w", "2") wpas.set_network_quoted(id, "psk", "12345678") wpas.set_network(id, "pairwise", "CCMP") wpas.set_network(id, "group", "CCMP") wpas.set_network(id, "frequency", "2412") wpas.connect_network(id) bssid = wpas.own_addr() dev[0].connect(ssid, psk="12345678", ieee80211w="1", key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2", scan_freq="2412") wpas.request("DEAUTHENTICATE " + addr + " test=0") wpas.request("DISASSOCIATE " + addr + " test=0") ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=1) if ev is not None: raise Exception("Unexpected disconnection") wpas.request("SET ext_mgmt_frame_handling 1") wpas.request("DEAUTHENTICATE " + addr + " reason=6 test=0") wpas.request("DISASSOCIATE " + addr + " reason=7 test=0") dev[0].wait_disconnected() wpas.request("SET ext_mgmt_frame_handling 0") dev[0].wait_connected()
def test_ap_pmf_sta_unprot_deauth_burst(dev, apdev): """WPA2-PSK AP with station receiving burst of unprotected Deauthentication frames""" ssid = "deauth-attack" addr = dev[0].own_addr() wt = Wlantest() wt.flush() wt.add_passphrase("12345678") wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5", drv_params="use_monitor=1") id = wpas.add_network() wpas.set_network(id, "mode", "2") wpas.set_network_quoted(id, "ssid", ssid) wpas.set_network(id, "proto", "WPA2") wpas.set_network(id, "key_mgmt", "WPA-PSK-SHA256") wpas.set_network(id, "ieee80211w", "2") wpas.set_network_quoted(id, "psk", "12345678") wpas.set_network(id, "pairwise", "CCMP") wpas.set_network(id, "group", "CCMP") wpas.set_network(id, "frequency", "2412") wpas.connect_network(id) bssid = wpas.p2p_dev_addr() dev[0].connect(ssid, psk="12345678", ieee80211w="1", key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2", scan_freq="2412") for i in range(0, 10): wpas.request("DEAUTHENTICATE " + addr + " reason=6 test=0") wpas.request("DISASSOCIATE " + addr + " reason=7 test=0") ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=1) if ev is not None: raise Exception("Unexpected disconnection") num_req = wt.get_sta_counter("valid_saqueryreq_tx", bssid, addr) num_resp = wt.get_sta_counter("valid_saqueryresp_rx", bssid, addr) if num_req < 1: raise Exception("STA did not send SA Query") if num_resp < 1: raise Exception("AP did not reply to SA Query") if num_req > 1: raise Exception("STA initiated too many SA Query procedures (%d)" % num_req) time.sleep(10) for i in range(0, 5): wpas.request("DEAUTHENTICATE " + addr + " reason=6 test=0") wpas.request("DISASSOCIATE " + addr + " reason=7 test=0") ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=1) if ev is not None: raise Exception("Unexpected disconnection") num_req = wt.get_sta_counter("valid_saqueryreq_tx", bssid, addr) num_resp = wt.get_sta_counter("valid_saqueryresp_rx", bssid, addr) if num_req != 2 or num_resp != 2: raise Exception( "Unexpected number of SA Query procedures (req=%d resp=%d)" % (num_req, num_resp))
def test_monitor_iface_open(dev, apdev): """Open connection using cfg80211 monitor interface on AP""" wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5", drv_params="use_monitor=1") id = wpas.add_network() wpas.set_network(id, "mode", "2") wpas.set_network_quoted(id, "ssid", "monitor-iface") wpas.set_network(id, "key_mgmt", "NONE") wpas.set_network(id, "frequency", "2412") wpas.connect_network(id) dev[0].connect("monitor-iface", key_mgmt="NONE", scan_freq="2412")
def test_ap_pmf_sta_unprot_deauth_burst(dev, apdev): """WPA2-PSK AP with station receiving burst of unprotected Deauthentication frames""" ssid = "deauth-attack" addr = dev[0].p2p_dev_addr() wt = Wlantest() wt.flush() wt.add_passphrase("12345678") wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5", drv_params="use_monitor=1") id = wpas.add_network() wpas.set_network(id, "mode", "2") wpas.set_network_quoted(id, "ssid", ssid) wpas.set_network(id, "proto", "WPA2") wpas.set_network(id, "key_mgmt", "WPA-PSK-SHA256") wpas.set_network(id, "ieee80211w", "2") wpas.set_network_quoted(id, "psk", "12345678") wpas.set_network(id, "pairwise", "CCMP") wpas.set_network(id, "group", "CCMP") wpas.set_network(id, "frequency", "2412") wpas.connect_network(id) bssid = wpas.p2p_dev_addr() dev[0].connect(ssid, psk="12345678", ieee80211w="1", key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2", scan_freq="2412") for i in range(0, 10): wpas.request("DEAUTHENTICATE " + addr + " reason=6 test=0") wpas.request("DISASSOCIATE " + addr + " reason=7 test=0") ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=1) if ev is not None: raise Exception("Unexpected disconnection") num_req = wt.get_sta_counter("valid_saqueryreq_tx", bssid, addr) num_resp = wt.get_sta_counter("valid_saqueryresp_rx", bssid, addr) if num_req < 1: raise Exception("STA did not send SA Query") if num_resp < 1: raise Exception("AP did not reply to SA Query") if num_req > 1: raise Exception("STA initiated too many SA Query procedures (%d)" % num_req) time.sleep(10) for i in range(0, 5): wpas.request("DEAUTHENTICATE " + addr + " reason=6 test=0") wpas.request("DISASSOCIATE " + addr + " reason=7 test=0") ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=1) if ev is not None: raise Exception("Unexpected disconnection") num_req = wt.get_sta_counter("valid_saqueryreq_tx", bssid, addr) num_resp = wt.get_sta_counter("valid_saqueryresp_rx", bssid, addr) if num_req != 2 or num_resp != 2: raise Exception("Unexpected number of SA Query procedures (req=%d resp=%d)" % (num_req, num_resp))
def test_ap_pmf_sta_sa_query(dev, apdev): """WPA2-PSK AP with station using SA Query""" ssid = "assoc-comeback" addr = dev[0].own_addr() wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5", drv_params="use_monitor=1") id = wpas.add_network() wpas.set_network(id, "mode", "2") wpas.set_network_quoted(id, "ssid", ssid) wpas.set_network(id, "proto", "WPA2") wpas.set_network(id, "key_mgmt", "WPA-PSK-SHA256") wpas.set_network(id, "ieee80211w", "2") wpas.set_network_quoted(id, "psk", "12345678") wpas.set_network(id, "pairwise", "CCMP") wpas.set_network(id, "group", "CCMP") wpas.set_network(id, "frequency", "2412") wpas.connect_network(id) bssid = wpas.own_addr() wpas.dump_monitor() Wlantest.setup(wpas) wt = Wlantest() wt.flush() wt.add_passphrase("12345678") dev[0].connect(ssid, psk="12345678", ieee80211w="1", key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2", scan_freq="2412") wpas.dump_monitor() wpas.request("DEAUTHENTICATE " + addr + " test=0") wpas.dump_monitor() wpas.request("DISASSOCIATE " + addr + " test=0") wpas.dump_monitor() ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=1) if ev is not None: raise Exception("Unexpected disconnection") wpas.request("DEAUTHENTICATE " + addr + " reason=6 test=0") wpas.dump_monitor() wpas.request("DISASSOCIATE " + addr + " reason=7 test=0") wpas.dump_monitor() ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=1) if ev is not None: raise Exception("Unexpected disconnection") if wt.get_sta_counter("valid_saqueryreq_tx", bssid, addr) < 1: raise Exception("STA did not send SA Query") if wt.get_sta_counter("valid_saqueryresp_rx", bssid, addr) < 1: raise Exception("AP did not reply to SA Query") wpas.dump_monitor()
def test_ap_pmf_sta_sa_query(dev, apdev): """WPA2-PSK AP with station using SA Query""" ssid = "assoc-comeback" addr = dev[0].own_addr() wt = Wlantest() wt.flush() wt.add_passphrase("12345678") wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5", drv_params="use_monitor=1") id = wpas.add_network() wpas.set_network(id, "mode", "2") wpas.set_network_quoted(id, "ssid", ssid) wpas.set_network(id, "proto", "WPA2") wpas.set_network(id, "key_mgmt", "WPA-PSK-SHA256") wpas.set_network(id, "ieee80211w", "2") wpas.set_network_quoted(id, "psk", "12345678") wpas.set_network(id, "pairwise", "CCMP") wpas.set_network(id, "group", "CCMP") wpas.set_network(id, "frequency", "2412") wpas.connect_network(id) bssid = wpas.own_addr() wpas.dump_monitor() dev[0].connect(ssid, psk="12345678", ieee80211w="1", key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2", scan_freq="2412") wpas.dump_monitor() wpas.request("DEAUTHENTICATE " + addr + " test=0") wpas.dump_monitor() wpas.request("DISASSOCIATE " + addr + " test=0") wpas.dump_monitor() ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=1) if ev is not None: raise Exception("Unexpected disconnection") wpas.request("DEAUTHENTICATE " + addr + " reason=6 test=0") wpas.dump_monitor() wpas.request("DISASSOCIATE " + addr + " reason=7 test=0") wpas.dump_monitor() ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=1) if ev is not None: raise Exception("Unexpected disconnection") if wt.get_sta_counter("valid_saqueryreq_tx", bssid, addr) < 1: raise Exception("STA did not send SA Query") if wt.get_sta_counter("valid_saqueryresp_rx", bssid, addr) < 1: raise Exception("AP did not reply to SA Query") wpas.dump_monitor()
def test_monitor_iface_wpa2_psk(dev, apdev): """WPA2-PSK connection using cfg80211 monitor interface on AP""" wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5", drv_params="use_monitor=1") id = wpas.add_network() wpas.set_network(id, "mode", "2") wpas.set_network_quoted(id, "ssid", "monitor-iface-wpa2") wpas.set_network(id, "proto", "WPA2") wpas.set_network(id, "key_mgmt", "WPA-PSK") wpas.set_network_quoted(id, "psk", "12345678") wpas.set_network(id, "pairwise", "CCMP") wpas.set_network(id, "group", "CCMP") wpas.set_network(id, "frequency", "2412") wpas.connect_network(id) dev[0].connect("monitor-iface-wpa2", psk="12345678", scan_freq="2412")
def start_wpas_ap(ssid): wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5", drv_params="use_monitor=1") id = wpas.add_network() wpas.set_network(id, "mode", "2") wpas.set_network_quoted(id, "ssid", ssid) wpas.set_network(id, "proto", "WPA2") wpas.set_network(id, "key_mgmt", "WPA-PSK-SHA256") wpas.set_network(id, "ieee80211w", "2") wpas.set_network_quoted(id, "psk", "12345678") wpas.set_network(id, "pairwise", "CCMP") wpas.set_network(id, "group", "CCMP") wpas.set_network(id, "frequency", "2412") wpas.set_network(id, "scan_freq", "2412") wpas.connect_network(id) wpas.dump_monitor() return wpas
def test_ap_pmf_sta_sa_query_no_response(dev, apdev): """WPA2-PSK AP with station using SA Query and getting no response""" ssid = "assoc-comeback" addr = dev[0].own_addr() wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5", drv_params="use_monitor=1") id = wpas.add_network() wpas.set_network(id, "mode", "2") wpas.set_network_quoted(id, "ssid", ssid) wpas.set_network(id, "proto", "WPA2") wpas.set_network(id, "key_mgmt", "WPA-PSK-SHA256") wpas.set_network(id, "ieee80211w", "2") wpas.set_network_quoted(id, "psk", "12345678") wpas.set_network(id, "pairwise", "CCMP") wpas.set_network(id, "group", "CCMP") wpas.set_network(id, "frequency", "2412") wpas.connect_network(id) bssid = wpas.own_addr() wpas.dump_monitor() dev[0].connect(ssid, psk="12345678", ieee80211w="1", key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2", scan_freq="2412") wpas.dump_monitor() wpas.request("DEAUTHENTICATE " + addr + " test=0") wpas.dump_monitor() wpas.request("DISASSOCIATE " + addr + " test=0") wpas.dump_monitor() ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=1) if ev is not None: raise Exception("Unexpected disconnection") wpas.request("SET ext_mgmt_frame_handling 1") wpas.request("DEAUTHENTICATE " + addr + " reason=6 test=0") wpas.dump_monitor() wpas.request("DISASSOCIATE " + addr + " reason=7 test=0") wpas.dump_monitor() dev[0].wait_disconnected() wpas.dump_monitor() wpas.request("SET ext_mgmt_frame_handling 0") dev[0].wait_connected() wpas.dump_monitor()
def test_sta_dynamic_random_mac_addr_keep_oui(dev, apdev): """Dynamically added wpa_supplicant interface and random MAC address (keep OUI)""" params = hostapd.wpa2_params(ssid="sta-dynamic", passphrase="12345678") hapd = hostapd.add_ap(apdev[0]['ifname'], params) wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5") addr0 = wpas.get_driver_status_field("addr") wpas.request("SET preassoc_mac_addr 2") wpas.request("SET rand_addr_lifetime 0") id = wpas.connect("sta-dynamic", psk="12345678", mac_addr="2", scan_freq="2412") addr1 = wpas.get_driver_status_field("addr") if addr0 == addr1: raise Exception("Random MAC address not used") if addr1[3:8] != addr0[3:8]: raise Exception("OUI was not kept") sta = hapd.get_sta(addr0) if sta['addr'] != "FAIL": raise Exception("Unexpected STA association with permanent address") sta = hapd.get_sta(addr1) if sta['addr'] != addr1: raise Exception("STA association with random address not found") wpas.request("DISCONNECT") wpas.connect_network(id) addr2 = wpas.get_driver_status_field("addr") if addr1 != addr2: raise Exception("Random MAC address changed unexpectedly") wpas.remove_network(id) id = wpas.connect("sta-dynamic", psk="12345678", mac_addr="2", scan_freq="2412") addr2 = wpas.get_driver_status_field("addr") if addr1 == addr2: raise Exception("Random MAC address did not change") if addr2[3:8] != addr0[3:8]: raise Exception("OUI was not kept")