Skip to content
3dg1luk43Public

About

One-file Bash tool to spin up a 2.4 GHz WPA2 AP (hostapd + dnsmasq) on Linux for mobile pentests. Open WLAN→router, DHCP/DNS, iptables NAT, repeatable port forwards/transparent REDIRECT (e.g. to Burp). Clean teardown on Ctrl-C.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

simple-ap (Kali-friendly Wi-Fi AP for mobile pentests)

simpleap.sh spins up a 2.4 GHz WPA2 AP on Linux for mobile app/network testing. It’s built to be reliable on Kali in a VM with Realtek AU USB adapters (e.g. AWUS036ACS).

  • Open WLAN → router by default (host services on 10.10.10.1:* and reach clients from the router).
  • DHCP/DNS via dnsmasq, AP via hostapd.
  • NAT + port forwards via iptables (iptables-nft); explicit INPUT rules so DHCP works even when the distro’s INPUT policy is DROP.
  • Transparent REDIRECT/DNAT helpers for Burp or other tooling.
  • Non-destructive: unique /tmp run dir, live logs, Ctrl-C reverts everything.
  • Compat mode for flaky AP drivers (disables 11n/WMM/PMF).

Driver setup (Realtek AU / Alfa AWUS)

On current kernels (Kali ≥ 2025, kernel ≥ ~6.x, tested on 7.1.x): use the mainline rtw88 driver. It is in-tree, needs no build, and supports AP mode natively.

The RTL8811/8812/8814AU chips used by the Alfa AWUS036AC / AWUS036ACS are now handled by the kernel's rtw88 USB driver (rtw88_8812au, rtw88_8821au, rtw88_8814au). Because rtw88 is a mac80211/cfg80211 driver, hostapd drives it directly — no DKMS, no pinned commits.

The old out-of-tree aircrack-ng rtl8812au @ 63cf0b4 recipe (for Kali 2024) is obsolete and no longer compiles on modern kernels: they removed the deprecated EXTRA_CFLAGS/EXTRA_LDFLAGS Kbuild vars (now ccflags-y/ldflags-y), the legacy timer API (from_timer/del_timer* → timer_container_of/timer_delete*), and migrated many cfg80211_ops from net_device to wireless_dev. Don't fight that — use rtw88.

# 1) Update the OS (get the newest rtw88 from the kernel package)
sudo apt update && sudo apt full-upgrade -y
sudo reboot now
# 2) Make sure nothing blacklists the in-tree driver
grep -rniE 'rtw88|rtl8xxxu' /etc/modprobe.d/ | grep -i blacklist   # expect no output
# 3) Load the driver (usually automatic on plug-in) and confirm the interface
sudo modprobe rtw88_8812au     # RTL8812AU (AWUS036AC)
sudo modprobe rtw88_8821au     # RTL8811AU (AWUS036ACS)
# plug the adapter in, then:
iw dev                          # should show wlanX
# 4) Verify AP mode is supported
iw list | sed -n '/Supported interface modes:/,/Band 1/p'   # must include "* AP"

Notes

  • If you previously installed an out-of-tree 8812au / realtek-rtl88xxau-dkms, remove any blacklist rtw88 / blacklist rtl8xxxu lines it dropped in /etc/modprobe.d/, otherwise the in-tree driver can't bind.
  • A stale dkms status entry for 8812au that only shows added (never built) is harmless, but you can drop it: sudo dkms remove 8812au/<version> --all.
  • rtw88 is maintained with the kernel, so kernel upgrades don't require a rebuild.

Only if rtw88 genuinely fails for your specific adapter, the interactive installer (--install) offers an out-of-tree DKMS fallback that clones current aircrack-ng master — note it may still need manual source patches on bleeding-edge kernels.


Quick start

chmod +x simpleap.sh

# one-shot automatic setup: installs deps + the right driver for your kernel
sudo ./simpleap.sh --install

# Realtek/VM-friendly baseline: channel 1, compat mode, Burp on local :8080
sudo ./simpleap.sh wlan0 eth0 PentestAP StrongPass123 \
  --channel 1 --mode compat \
  --forward tcp:80=8080 \
  --forward tcp:443=8080
  • SSID PentestAP on 2.4 GHz ch 1.
  • Clients get 10.10.10.0/24; router is 10.10.10.1.
  • HTTP/HTTPS from clients transparently redirected to local :8080 (Burp). Install Burp CA on devices if you intercept TLS.

Stop with Ctrl-C — rules and processes are removed.


Automatic installer (--install)

Fully automatic, no prompts — run it once and it sets everything up:

sudo ./simpleap.sh --install

What it does:

  1. Installs runtime packages (hostapd dnsmasq iptables iproute2 iw tcpdump).
  2. Verifies the required tools are present.
  3. Autodetects the running kernel and installs the appropriate Wi-Fi driver:
    • Kernel with in-tree rtw88 AU support (Kali ≥ 2025 / kernel ≥ ~6.x, incl. the 7.x series): loads the mainline rtw88 driver — no build. If an older out-of-tree install left a blacklist rtw88/rtl8xxxu line behind, it is neutralized automatically so the in-tree driver can bind.
    • Kernel without in-tree AU support (legacy): clones aircrack-ng rtl8812au, applies modern-kernel compatibility patches (ccflags-y, timer-API shims, disables the bridge extension) and installs it via DKMS.
  4. Reports the detected Wi-Fi interfaces and confirms AP-mode capability.

Because the driver decision is made from uname -r at run time, the same command works across both installed kernels — boot either one and re-run --install (the in-tree driver ships per-kernel; a DKMS driver auto-rebuilds per-kernel).

Installer output is structured and explicit ([STEP], [CMD], [OK], [INFO], [WARN], [DONE], [NEXT]).


Cleanup utility (--cleanup)

If a run crashes or leaves partial state, use the built-in comprehensive cleanup:

sudo ./simpleap.sh --cleanup

You can target non-default interfaces/subnet:

sudo ./simpleap.sh --cleanup --wifi-if wlan1 --uplink-if eth1 --subnet 10.20.30.0/24

What --cleanup does:

  • Stops hostapd and dnsmasq
  • Removes NAT PREROUTING REDIRECT/DNAT rules for the Wi-Fi interface
  • Removes known INPUT/OUTPUT/FORWARD/MASQUERADE rules added by the script
  • Flushes IP addresses on Wi-Fi interface, sets interface back to managed mode, sets it down
  • Re-enables NetworkManager management for the Wi-Fi interface (if nmcli is available)
  • Sets net.ipv4.ip_forward=0

Output is structured and shows exact commands before execution.


Usage

sudo ./simpleap.sh WIFI_IF UPLINK_IF SSID WPA2_PSK \
  [--channel 1] [--subnet 10.10.10.0/24] [--gateway 10.10.10.1] \
  [--dhcp-start 10.10.10.50] [--dhcp-end 10.10.10.150] \
  [--mode normal|compat] [--country CZ] \
  [--debug] \
  [--forward SPEC]... \
  [--lease MAC=IP]...

Required positionals

  • WIFI_IF – wireless NIC (e.g. wlan0)
  • UPLINK_IF – internet uplink (e.g. eth0)
  • SSID – network name
  • WPA2_PSK – 8..63 chars

Named options

  • --channel N – 2.4 GHz channel (default 1)
  • --subnet CIDR – default 10.10.10.0/24
  • --gateway IP – default 10.10.10.1
  • --dhcp-start IP / --dhcp-end IP – default 10.10.10.50–150
  • --mode normal|compat – use compat for Realtek AU
  • --country CC – regdomain (default CZ)
  • --debug – print debug messages to stderr
  • --forward SPEC – port forward rule (below)
  • --lease MAC=IP – pin client leases

Logs (tailed live & saved): /tmp/simpleap.<if>.<timestamp>.../{hostapd.log,dnsmasq.log,dnsmasq.leases}


Forwarding rules

--forward supports:

  • tcp|udp:INPORT=DSTPORT → REDIRECT to local router (10.10.10.1:DSTPORT) e.g. --forward tcp:80=8080
  • tcp|udp:INPORT=DSTIP:DSTPORT → DNAT to DSTIP:DSTPORT e.g. --forward tcp:22=10.10.10.60:2222

Applied to client traffic arriving on WIFI_IF (PREROUTING). Hairpin wlan0→wlan0 is allowed so DNAT to clients works.


Live proxy toggle (hotkey)

While the AP is running in a terminal, flip client traffic between through the proxy and straight to the Internet on the fly — no restart:

  • Press p → toggle a transparent REDIRECT of client tcp {80 443} to the local proxy port (default 8080, i.e. Burp/mitmproxy).
  • Press q → quit (same as Ctrl-C: everything is torn down).
# start with the proxy OFF (default) — press p to send traffic to Burp when you want it
sudo ./simpleap.sh wlan0 eth0 PentestAP StrongPass123 --mode compat --channel 1

# start with the proxy already ON, custom port / ports:
sudo ./simpleap.sh wlan0 eth0 PentestAP StrongPass123 \
  --proxy-on --proxy-port 8080 --proxy-ports "80 443 8443"

Options: --proxy-port N (default 8080), --proxy-ports "P.." (default "80 443"), --proxy-on (start enabled). Each toggle also flushes the client's conntrack so the new routing takes effect immediately for live flows. The toggle is independent of --forward (which stays available for arbitrary custom REDIRECT/DNAT rules).

For intercepted HTTPS the device must trust your CA and the proxy must run in transparent/invisible mode on the target port. The hotkeys need a real terminal (a TTY); when the script is backgrounded it simply serves the AP without hotkeys.


Static DHCP leases

--lease aa:bb:cc:dd:ee:ff=10.10.10.60
--lease 00:11:22:33:44:55=10.10.10.61

What the script does

  1. Sets regdomain, kills wpa_supplicant for WIFI_IF, unmanages it in NetworkManager.

  2. Configures WIFI_IF to __ap, assigns GATEWAY/PREFIX, brings it up.

  3. Enables net.ipv4.ip_forward=1.

  4. iptables (iptables-nft):

    • INPUT: accept all from WIFI_IF (router services reachable), plus explicit DHCP/DNS/ICMP accepts.
    • OUTPUT: accept to WIFI_IF (router→clients).
    • FORWARD: accept both directions and wlan0→wlan0 (hairpin).
    • NAT: MASQUERADE on UPLINK_IF.
    • PREROUTING NAT: installs --forward REDIRECT/DNAT rules.
  5. dnsmasq: binds to GATEWAY on WIFI_IF, authoritative DHCP/DNS, verbose logs.

  6. hostapd: WPA2-PSK/CCMP on 2.4 GHz; compat disables 11n/WMM/PMF (most stable for AU).

  7. Live tails both logs; Ctrl-C tears everything down.


Requirements

  • Root.
  • hostapd, dnsmasq, iptables, iw, ip, ss, tcpdump (optional).
  • Wi-Fi adapter supporting AP (nl80211). Targeted: Realtek AWUS036ACS (8811/8812AU) on Kali VM + VMware/VirtualBox.

Install on Kali:

sudo apt update
sudo apt install -y hostapd dnsmasq iptables tcpdump
# optional Python CLI tooling manager (preferred over plain pip):
sudo apt install -y pipx python3-venv
pipx ensurepath
# Driver: on current kernels the in-tree rtw88 driver already supports AWUS AU cards
#         (see "Driver setup" above) - no out-of-tree DKMS build needed.

Troubleshooting

Phone stuck on “Obtaining IP address” Use a second terminal:

ss -lupn 'sport = :67 or :68 or :53'     # dnsmasq bound to 10.10.10.1?
tcpdump -ni wlan0 -vvv port 67 or 68    # DHCPDISCOVER / OFFER / REQUEST / ACK visible?

Two root causes seen on Realtek AU + Kali, both handled automatically now:

  1. Client associates + 4-way handshake completes, then no DHCP and it disconnects (tcpdump on wlan0 shows no client frames, or only association in hostapd.log). This is the rtw88 USB adapter sleeping / USB-3 self-interference. Fix (applied by --install, persisted in /etc/modprobe.d/rtw88-ap.conf):

    options rtw88_core disable_lps_deep=Y
    options rtw88_usb  switch_usb_mode=N
    # then: modprobe -r rtw88_8821au ... ; modprobe rtw88_8821au
  2. DISCOVER reaches wlan0 and iptables shows it accepted, but dnsmasq never answers — the host runs a native nftables firewall (table inet filter, nftables.service) with policy drop on input/forward. That base chain runs alongside the iptables (ip filter) chain this script edits, so an iptables ACCEPT is overridden by the inet-filter drop (DHCP dropped before dnsmasq; and forwarding/Internet blocked too). simpleap.sh now detects this and adds the matching accepts into inet filter (removed again on Ctrl-C / --cleanup). Check:

    nft list chain inet filter input     # should show iifname "wlan0" ... accept lines
    nft list chain inet filter forward   # wlan0<->eth0 accepts present?

If DISCOVERs appear but no OFFERs and neither applies: another INPUT policy is dropping — ensure you ran the script as root and nothing else overwrote the rules.

SSID not visible Use --mode compat and channel 1 or 6. Fresh SSID. If still dead, reload the module and retry:

sudo ip link set wlan0 down
sudo modprobe -r rtw88_8821au rtw88_8812au 2>/dev/null
sudo rfkill unblock all
sudo modprobe rtw88_8821au 2>/dev/null || sudo modprobe rtw88_8812au 2>/dev/null

Minimal hostapd check:

cat >/tmp/hapd-min.conf <<'EOF'
interface=wlan0
driver=nl80211
ssid=MINTEST
hw_mode=g
channel=6
wmm_enabled=0
ieee80211n=0
auth_algs=1
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_passphrase=12345678
wpa_pairwise=CCMP
EOF
sudo ip link set wlan0 up
sudo hostapd -dd /tmp/hapd-min.conf

TLS interception --forward tcp:443=8080 breaks HTTPS unless the device trusts your CA. Install the Burp CA (or only redirect 80).

Crash cleanup (manual)

# defaults: wlan0 / eth0 / 10.10.10.0/24
sudo ./simpleap.sh --cleanup

# custom targets
sudo ./simpleap.sh --cleanup --wifi-if <WIFI_IF> --uplink-if <UPLINK_IF> --subnet <SUBNET>

Security notes

  • This is a test harness, not a home AP: WLAN → router is wide open by design.
  • Clients can talk to each other (AP isolation off).
  • Use a legal country code and channels.

Attribution

Driver workaround and procedure summarized from Sapsan’s article (thanks to Janek): https://sapsan-sklep.pl/en/blogs/articles/alfa-awus-kali-linux-2024-fix-en

About

One-file Bash tool to spin up a 2.4 GHz WPA2 AP (hostapd + dnsmasq) on Linux for mobile pentests. Open WLAN→router, DHCP/DNS, iptables NAT, repeatable port forwards/transparent REDIRECT (e.g. to Burp). Clean teardown on Ctrl-C.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages