80211_hwsim

十一月 26, 2023 [wifi] #80211

80211_hwsim

# Build mac80211_hwsim as part of kernel configuration
# Load the module
modprobe mac80211_hwsim
# Run hostapd (AP) for wlan0
hostapd hostapd.conf
# Run wpa_supplicant (station) for wlan1
wpa_supplicant -Dnl80211 -iwlan1 -c wpa_supplicant.conf
modprobe -r mac80211_hwsim
modprobe mac80211_hwsim radios=2

# Launch in background, write logs to file instead of stdout
hostapd -B -f hostapd.log -i wlan0 hostapd.conf
# Set IP @ first (otherwise dhcpd will frown and just exit)
ip addr add 192.168.42.1/24 dev wlan0
# Launch in background is implicit
dhcpd -cf dhcpd.conf wlan0
# Launch in background, write logs to file instead of stdout
wpa_supplicant -B -c wpa_supplicant.conf -f wpa_supplicant.log -i wlan1

# Get ourselves a fresh IP @, and go into background once the lease has been obtained
dhclient -4 wlan1
# Note: you may get the following warning message; do not worry, it does not mean
# you could not get an IP @
# cat: can't open '/etc/resolv.conf.*': No such file or directory
# Record every function call in the kernel, for the whole duration of the command
trace-cmd record -p function iw dev wlan1 set channel 8
#   plugin 'function'
# CPU0 data recorded at offset=0x182000
#     208896 bytes in size
trace-cmd record -p function -l '*80211*' iw dev wlan1 set channel 8
trace-cmd report
cat > ./send_deauth_pkt.py <<EOF
#! /usr/bin/python3

from scapy.all import *

pkt = Dot11(addr1='02:00:00:00:00:00', addr2='02:00:00:00:01:00') / Dot11Deauth(reason=8)
print("Sending the following packet:")
pkt.show()
sendp(pkt, count=1, iface='wlan1')
EOF
trace-cmd record -p function -l '*80211*' ./send_deauth_pkt.py

hostapd 配置

##ssid:别人所看到的无线接入点的名称; ##hw_mode:指定802.11协议,其中 a = IEEE 802.11a, b = IEEE 802.11b, g = IEEE 802.11g; ##channel:设定无线频道; ##interface:接入点设备名称,注意不要包含ap后缀,即如果该设备称为wlan0ap,填写wlan0即可; ##bridge:指定所处网桥; ##driver:设定无线驱动; ##macaddr_acl:可选,指定MAC地址过滤规则,0表示除非在禁止列表否则允许,1表示除非在允许列表否则禁止,2表示使用外部RADIUS服务器; ##accept_mac_file:指定允许MAC列表文件所在; ##deny_mac_file:指定禁止MAC列表文件所在;

cat > ./hostapd.conf <<EOF
ssid=test
hw_mode=g
channel=10
interface=wlan0
bridge=br0
driver=nl80211
ignore_broadcast_ssid=0
macaddr_acl=0
accept_mac_file=/etc/hostapd.accept
deny_mac_file=/etc/hostapd.deny
EOF