Skip to main content

Building mdk4 for the Hak5 WiFi Pineapple Pager

· 6 min read
Roy Firestein
CEO at Autohost.ai

Complete guide for cross-compiling mdk4 for the Hak5 WiFi Pineapple Pager using the OpenWrt SDK.

Target Device Specifications

  • Device: Hak5 WiFi Pineapple Pager
  • CPU: 580 MHz MIPS 24KEc (MediaTek MT7628AN)
  • Architecture: mipsel_24kc (MIPS32r2, little-endian)
  • OS: Pineapple Pager 24.10.1 (based on OpenWrt 24.10.1)
  • Board: ramips/mt76x8
  • Kernel: Linux 6.6.86

Prerequisites

Build Host Requirements

This guide uses AWS Linux 2023 as the build host, but should work on any modern Linux distribution.

Install Build Dependencies

# Update package manager
sudo dnf update -y

# Install build essentials
sudo dnf install -y gcc make gcc-c++

# Install Perl modules (required by OpenWrt build system)
sudo dnf install -y perl-FindBin perl-Thread-Queue perl-IPC-Cmd

# Install additional build tools
sudo dnf install -y wget tar zstd file

Step 1: Download the OpenWrt SDK

Download the SDK matching your device's OpenWrt version and architecture.

# Navigate to home directory
cd ~

# Download OpenWrt SDK for ramips/mt76x8 (24.10.1)
wget https://downloads.openwrt.org/releases/24.10.1/targets/ramips/mt76x8/openwrt-sdk-24.10.1-ramips-mt76x8_gcc-13.3.0_musl.Linux-x86_64.tar.zst

# Extract the SDK (requires zstd)
tar --zstd -xf openwrt-sdk-24.10.1-ramips-mt76x8_gcc-13.3.0_musl.Linux-x86_64.tar.zst

# Navigate into SDK directory
cd openwrt-sdk-24.10.1-ramips-mt76x8_gcc-13.3.0_musl.Linux-x86_64

Note: If using a different OpenWrt version, find the matching SDK at: https://downloads.openwrt.org/releases/<version>/targets/<board>/<subtarget>/

Step 2: Install Required Dependencies

Install the libraries that mdk4 depends on.

# Update package feeds
./scripts/feeds update -a

# Install dependencies
./scripts/feeds install libnl-core libnl-genl libpcap

Step 3: Create mdk4 Package Directory

# Create package directory
mkdir -p package/mdk4

Step 4: Create Package Makefile

Create the OpenWrt package Makefile with proper configuration:

cat > package/mdk4/Makefile << 'EOF'
include $(TOPDIR)/rules.mk

PKG_NAME:=mdk4
PKG_VERSION:=4.2
PKG_RELEASE:=1

PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/aircrack-ng/mdk4.git
PKG_SOURCE_VERSION:=master
PKG_MIRROR_HASH:=skip

PKG_LICENSE:=GPL-3.0-or-later
PKG_LICENSE_FILES:=COPYING

PKG_BUILD_PARALLEL:=1

include $(INCLUDE_DIR)/package.mk

define Package/mdk4
SECTION:=net
CATEGORY:=Network
DEPENDS:=+libnl-core +libnl-genl +libpcap +libpthread
TITLE:=MDK4 WiFi Testing Tool
URL:=https://github.com/aircrack-ng/mdk4
endef

define Package/mdk4/description
MDK4 is a Wi-Fi testing tool from E7mer, ASPj of k2wrlz,
it uses the osdep library from the aircrack-ng project
to inject frames on several operating systems.
endef

TARGET_CPPFLAGS += \
-I$(STAGING_DIR)/usr/include \
-I$(STAGING_DIR)/usr/include/libnl3

TARGET_LDFLAGS += \
-L$(STAGING_DIR)/usr/lib

MAKE_FLAGS += \
PREFIX=/usr \
LIBNL="-lnl-3 -lnl-genl-3"

define Package/mdk4/install
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/src/mdk4 $(1)/usr/sbin/
endef

$(eval $(call BuildPackage,mdk4))
EOF

Key Points About the Makefile

Critical: The Makefile uses TARGET_CPPFLAGS += instead of overriding CFLAGS. This is essential because:

  • mdk4's internal build system adds -I.. in the osdep directory
  • Overriding CFLAGS breaks this, causing missing header errors
  • Using TARGET_CPPFLAGS += appends paths without breaking internal flags

Step 5: Install Package Dependencies

Before compiling, ensure all dependencies are built:

# Build dependencies
make package/libnl-core/compile V=s
make package/libnl-genl/compile V=s
make package/libpcap/compile V=s

Step 6: Compile mdk4

# Clean any previous builds (if recompiling)
rm -rf build_dir/target-*/mdk4*

# Compile mdk4 with verbose output
make package/mdk4/compile V=s

The compilation will take a few minutes. You should see:

  • Source code being downloaded from GitHub
  • Compilation of osdep library
  • Compilation of attack modules
  • Linking of final binary
  • Package creation

Step 7: Verify the Build

Check that the package was created successfully:

# Find the package
ls -lh bin/packages/mipsel_24kc/base/mdk4*.ipk

# Expected output:
# -rw-r--r-- 1 user user 53K <date> mdk4_4.2-r1_mipsel_24kc.ipk

Verify the binary architecture:

# Extract package to verify
cd /tmp
mkdir mdk4_test && cd mdk4_test
tar -xzf ~/openwrt-sdk-24.10.1-ramips-mt76x8_gcc-13.3.0_musl.Linux-x86_64/bin/packages/mipsel_24kc/base/mdk4_4.2-r1_mipsel_24kc.ipk
tar -xzf data.tar.gz
file ./usr/sbin/mdk4

# Expected output:
# ./usr/sbin/mdk4: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1 (SYSV),
# dynamically linked, interpreter /lib/ld-musl-mipsel-sf.so.1, no section header

Step 8: Deploy to WiFi Pineapple Pager

Copy Package from Build Server

# From your local machine, copy from the build server
scp -i ~/path/to/key.pem \
user@build-server:~/openwrt-sdk-24.10.1-ramips-mt76x8_gcc-13.3.0_musl.Linux-x86_64/bin/packages/mipsel_24kc/base/mdk4_4.2-r1_mipsel_24kc.ipk \
./

Transfer to Pineapple Pager

# Copy to device (adjust IP/hostname as needed)
scp mdk4_4.2-r1_mipsel_24kc.ipk root@pager:/tmp/

Install on Device

SSH into the Pineapple Pager:

ssh root@pager

Install the package:

# Navigate to package location
cd /tmp

# Install dependencies (if not already installed)
opkg update
opkg install libnl-core libnl-genl libpcap

# Install mdk4
opkg install mdk4_4.2-r1_mipsel_24kc.ipk

# Verify installation
which mdk4
mdk4 --version

Troubleshooting

Issue: Missing pcap.h or LINKTYPE errors

Symptoms:

error: 'LINKTYPE_IEEE802_11' undeclared
error: 'TCPDUMP_MAGIC' undeclared

Cause: The Makefile is completely overriding CFLAGS, breaking mdk4's internal include paths.

Solution: Use TARGET_CPPFLAGS += instead of CFLAGS= in the Makefile (already implemented in Step 4).

Issue: libnl errors

Symptoms:

error: netlink/genl/genl.h: No such file or directory

Solution: Install libnl dependencies:

./scripts/feeds install libnl-core libnl-genl
make package/libnl-core/compile V=s
make package/libnl-genl/compile V=s

Issue: libpcap errors

Symptoms:

undefined reference to 'pcap_*'

Solution: Install and compile libpcap:

./scripts/feeds install libpcap
make package/libpcap/compile V=s

Issue: Perl module errors

Symptoms:

Can't locate FindBin.pm

Solution: Install Perl modules:

# AWS Linux 2023 / Amazon Linux / Fedora
sudo dnf install -y perl-FindBin perl-Thread-Queue perl-IPC-Cmd

# Ubuntu / Debian
sudo apt install -y perl-base libfindbin-libs-perl

# Manual CPAN install (if packages unavailable)
sudo cpan FindBin Thread::Queue IPC::Cmd

Build Output Details

Files Created

  • Package: bin/packages/mipsel_24kc/base/mdk4_4.2-r1_mipsel_24kc.ipk (53KB)
  • Binary: usr/sbin/mdk4 (147KB stripped, inside package)

Binary Specifications

  • Format: ELF 32-bit LSB executable
  • Architecture: MIPS, MIPS32 rel2
  • Linking: Dynamically linked
  • Libc: musl (ld-musl-mipsel-sf.so.1)
  • Dependencies: libnl-3, libnl-genl-3, libpcap, libpthread

Additional Notes

Build Time

  • First build: ~5-10 minutes (includes downloading source)
  • Subsequent builds: ~2-3 minutes

Disk Space Requirements

  • OpenWrt SDK: ~1GB extracted
  • Build directory: ~200MB
  • Final package: 53KB

Alternative: Quick Rebuild

If you need to rebuild after making changes:

# Clean mdk4 only
rm -rf build_dir/target-*/mdk4*

# Rebuild
make package/mdk4/compile V=s

Using Different mdk4 Versions

To build a specific version instead of master:

Edit package/mdk4/Makefile and change:

PKG_SOURCE_VERSION:=master

To:

PKG_SOURCE_VERSION:=v4.2  # or specific commit hash

References