Results 1 to 1 of 1

Thread: Setting up Kali as a Router/Wireless Access Point

  1. #1
    Join Date
    2023-Aug
    Posts
    5

    Setting up Kali as a Router/Wireless Access Point

    Below is a bash script I created to set up Kali as a Router/Wireless Access Point. Please note:
    1. If you are using a VM, set your network adapter to bridged adapter. Then choose your internal wireless card (if using wifi) or your modem (if using ethernet).
    2. Ensure you have a wireless interface adapter (such as wlan0) enabled, before running the script and after your machine restarts.
    3. If your router is on the 192.168.10.0/24 subnet (not likely), you will need to change the ip addresses in the script so it is outside the subnet used by your router.
    4. Create the script file in Linux. If you create it in Windows and move it to your Linux environment, you will need to run this command to convert the script to use Unix-style line endings: dos2unix your_script_name.sh
    5. Before running the script, you will need to run this command to make the script executable: chmod +x your_script_name.sh
    6. You need to run the script with sudo for it to execute successfully and without user interaction: sudo ./your_script_name.sh

    Enjoy!

    SCRIPT BELOW:

    #!/bin/bash
    # Prompt for SSID and Passphrase
    read -p "Enter SSID: " ssid
    read -p "Enter Passphrase: " passphrase
    read -p "Wireless Interface: " interface


    #Step 1: Set up wireless interface and set subnet.
    sudo ip addr add 192.168.10.1/24 dev $interface
    sudo ip link set "$interface" up


    # Step 2: Configure Network Interface
    echo "Configuring network interface..."
    cat <<EOF > /etc/network/interfaces
    source-directory /etc/network/interfaces.d
    auto lo
    iface lo inet loopback
    allow-hotplug wlan0
    iface wlan0 inet static
    address 192.168.10.1
    netmask 255.255.255.0
    EOF
    systemctl enable networking


    # Step 3: Create WAP Configuration
    sudo apt install -y hostapd
    echo "Creating hostapd configuration..."
    sudo bash -c "cat > /etc/hostapd/hostapd.conf <<EOF
    interface=$interface
    driver=nl80211
    ssid=$ssid
    hw_mode=g
    channel=7
    wmm_enabled=0
    macaddr_acl=0
    auth_algs=1
    ignore_broadcast_ssid=0
    wpa=2
    wpa_passphrase=$passphrase
    wpa_key_mgmt=WPA-PSK
    wpa_pairwise=TKIP
    rsn_pairwise=CCMP
    EOF"
    sudo systemctl unmask hostapd
    sudo systemctl enable hostapd


    # Step 4: Configure DNS and DHCP
    echo "Configuring dnsmasq..."
    cat <<EOF > /etc/dnsmasq.conf
    interface=$interface
    dhcp-range=192.168.10.50,192.168.10.150,12h
    dhcp-option=3,192.168.10.1
    dhcp-option=6,8.8.8.8,8.8.4.4
    EOF
    apt install dnsmasq
    systemctl enable dnsmasq


    # Step 5: Enable IPv4 Forwarding
    echo "Enabling IPv4 forwarding..."
    echo "net.ipv4.ip_forward=1" > /etc/sysctl.conf


    # Step 6: Set NAT and Firewall Rules
    echo "Setting up iptables rules..."
    mkdir -p /etc/iptables
    iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
    iptables -A FORWARD -i eth0 -o $interface -m state --state RELATED,ESTABLISHED -j ACCEPT
    iptables -A FORWARD -i $interface -o eth0 -j ACCEPT
    iptables-save > /etc/iptables/rules.v4


    # Set DEBIAN_FRONTEND to noninteractive to auto-accept prompts
    export DEBIAN_FRONTEND=noninteractive


    # Install iptables-persistent without manual confirmation
    apt-get install -y iptables-persistent


    # Reset DEBIAN_FRONTEND to its default value
    unset DEBIAN_FRONTEND


    # Step 7: Enable netfilter-persistent and Reboot
    echo "Enabling netfilter-persistent..."
    systemctl enable netfilter-persistent


    reboot
    Last edited by loby; 2023-09-14 at 21:15. Reason: Solved Question / Providing Solution for Others

Similar Threads

  1. issue with setting up an "evil access point" script.
    By parsec in forum General Archive
    Replies: 1
    Last Post: 2015-11-19, 06:29
  2. Cracking a WPA/WPA2 wireless Access Point
    By MrShingles in forum How-To Archive
    Replies: 26
    Last Post: 2015-06-02, 20:44
  3. Rogue Access Point with 2 Wireless Cards
    By m4rshall in forum General Archive
    Replies: 2
    Last Post: 2014-07-01, 07:12

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •