#!/bin/bash # defaults WAN=ppp0 LAN=wlan0 LANIP="192.168.133.1" DHCPR="192.168.133.2,192.168.133.254" DNS="208.67.222.222,8.8.4.4" RED=$(tput setaf 1 && tput bold) GREEN=$(tput setaf 2 && tput bold) STAND=$(tput sgr0) BLUE=$(tput setaf 6 && tput bold) usage() { echo "USAGE: $0 [-v][-d] [WAN=$WAN] [LAN=$LAN] [LANIP=$LANIP] [DHCPR=$DHCPR]" echo "USAGE: $0 [-v][-d] [WAN=$WAN] [LAN=$LAN] # disable forwarding" echo "USAGE: $0 [-v][-l] # print status" echo "defaults: WAN=ppp0 LAN=wlan0 LANIP=192.168.133.1 DNS=8.8.8.8,8.8.4.4 DHCPR=192.168.133.2,192.168.133.254" } list() { echo "Forwarding information" iptables -L echo "" iptables -L -t nat echo -e "\n/proc/sys/net/ipv4/ip_forward: $(cat /proc/sys/net/ipv4/ip_forward)" } listsettings() { echo "WAN=$WAN, LAN=$LAN LANIP=$LANIP DHCPR=$DHCPR" } # setup forwarding and the dnsmasq service fwd() { sysctl -w net.ipv4.ip_forward=1 # Put the interface in Ad-hoc mode iwconfig $LAN mode Ad-Hoc # Set the essid for the access point iwconfig $LAN essid TheH0le # Set auto channel iwconfig $LAN channel auto # Set the security (WEP) # Set Key #iwconfig $LAN key restricted s:0x000 # Set encryption #iwconfig $LAN key on ifconfig $LAN $LANIP/24 netmask 255.255.255.0 up #iptables -A FORWARD -o $WAN -i $LAN -s $LANIP/24 -m conntrack --ctstate NEW -j ACCEPT #iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT #iptables -t nat -A POSTROUTING -o $WAN -j MASQUERADE iptables-restore < /home/0x00/rules /usr/bin/dnsmasq -C /dev/null > /dev/null 2>&1 \ --domain-needed \ --bogus-priv \ --interface=$LAN \ --dhcp-option=6,$DNS \ --listen-address=$LANIP \ --dhcp-range=$DHCPR,12h \ echo "to disable: $0 -d" } # remove forwarding and the dnsmasq service unfwd() { pkill -9 dnsmasq ifconfig $LAN down sysctl -w net.ipv4.ip_forward=0 #iptables -D FORWARD -o $WAN -i $LAN -s $LANIP/24 -m conntrack --ctstate NEW -j ACCEPT #iptables -D FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT iptables -F iwconfig $LAN mode managed } # calculate DHCPR mkrange() { PRE=$(echo $LANIP | cut -d. -f-3) SUF=$(echo $LANIP | cut -d. -f4) DHCPR="$PRE.$(($SUF+1)),$PRE.253" } #-------- for arg in "$@" do case "$arg" in WAN=*|LAN=*|LANIP=* ) eval $arg ;; DHCPR=* ) eval $arg DHCPFLAG=true ;; -d ) echo "deleting forwarding" DISABLE=true ;; -l ) LIST=true ;; -v ) VERBOSE=true ;; * ) usage exit 0 ;; esac done [ $DHCPFLAG ] || mkrange [ $VERBOSE ] && listsettings [ $LIST ] && list && exit 1 if [ ! $DISABLE ] ; then fwd else unfwd fi eri