Jump to content

Recommended Posts

Posted (edited)

Sir/Ma'am,

I made some slight modifications to the wp4.sh script to streamline it a bit, and also to make it a little more vocal if you want it to be.

I also added in a small sanity check to make sure that you're running it as root.

At the top of the script, I left the two variables that I could see being changed more often. The rest of the variable defaults were rolled into the lines of code using the ${read value:-$default value if blank} syntax.

Also, if you set debug=1, it'll echo each step of the process and let you know what's going on. This way you can hopefully catch a problem if one is there.

Would love to hear your feedback.

#!/bin/bash


#define variables
debug=0 # When enabled, will display all settings in console.
pinelandef=eth0 # Interface of ethernet cable directly connected to Pineapple.
pinewandef=wlan0 # i.e. wlan0 for wifi, ppp0 for 3g modem/dialup, eth0 for lan.


if [[ $UID != "0" ]]; then
echo "Script must be run as root!"
exit 1
fi


echo "$(tput setaf 1)  _       ___ _______    ____  _                              __   "
echo " | |     / (_) ____(_)  / __ \\(_)___  ___  ____ _____  ____  / /__ "
echo " | | /| / / / /_  / /  / /_/ / / __ \/ _ \/ __ '/ __ \/ __ \/ / _ \\"
echo " | |/ |/ / / __/ / /  / ____/ / / / /  __/ /_/ / /_/ / /_/ / /  __/"
echo " |__/|__/_/_/   /_/  /_/   /_/_/ /_/\___/\__,_/ .___/ .___/_/\___/ "
echo " $(tput sgr0) OWN the Network                            $(tput setaf 1)/_/   /_/$(tput sgr0)       v2.1"
echo ""


echo -n "Pineapple Netmask [255.255.255.0]: "
read pinenetmask


echo -n "Pineapple Network [172.16.42.0/24]: "
read pinenet


echo -n "Interface between PC and Pineapple [eth0]: "
read pinelan


echo -n "Interface between PC and Internet [wlan0]: "
read pinewan


echo "Attempting to get default gateway. Script will hang here if you do not have a connection to the internet."
pinegwdef=`netstat -nr | awk 'BEGIN {while ($3!="0.0.0.0") getline; print $2}'` #Usually correct by default. 
echo -n "Internet Gateway [$pinegwdef]: "
read pinegw


echo -n "IP Address of Host PC [172.16.42.42]: "
read pinehostip


echo -n "IP Address of Pineapple [172.16.42.1]: "
read pineip


#Display settings
if [[ $debug = "1" ]]; then
echo "Debugging is $(tput setaf 2)ENABLED$(tput sgr0)"
echo "Pineapple connected to: ${pinelan:-$pinelandef}"
echo "Internet connection from: ${pinewan:-pinewandef}"
echo "Internet connection gateway: ${pinegw:-$pinegwdef}"
echo "Host Computer IP: ${pinehostip:-172.16.42.42}"
echo "Pineapple IP: ${pineip:-172.16.42.1}"
echo "Network: ${pinenet:-172.16.42.0/24}"
echo "Netmask: ${pinenetmask:-255.255.255.0}"
fi


echo ""
echo "$(tput setaf 6)     _ .   $(tput sgr0)        $(tput setaf 7)___$(tput sgr0)          $(tput setaf 3)\||/$(tput sgr0)   Internet: $pinegw - $pinewan"
echo "$(tput setaf 6)   (  _ )_ $(tput sgr0) $(tput setaf 2)<-->$(tput sgr0)  $(tput setaf 7)[___]$(tput sgr0)  $(tput setaf 2)<-->$(tput sgr0)  $(tput setaf 3),<><>,$(tput sgr0)  Computer: $pinehostip"
echo "$(tput setaf 6) (_  _(_ ,)$(tput sgr0)       $(tput setaf 7)\___\\$(tput sgr0)        $(tput setaf 3)'<><>'$(tput sgr0) Pineapple: $pinenet - $pinelan"


#Bring up Ethernet Interface directly connected to Pineapple
ifconfig ${pinelan:-$pinelandef} ${pinehostip:-172.16.42.42} netmask ${pinenetmask:-255.255.255.0} up


# Enable IP Forwarding
echo '1' > /proc/sys/net/ipv4/ip_forward
if [[ $debug = "1" ]]; then
echo -n "IP forwarding enabled. /proc/sys/net/ipv4/ip_forward set to "
cat /proc/sys/net/ipv4/ip_forward
fi


#clear chains and rules
iptables -X
iptables -F
iptables -t nat -F
if [[ $debug = "1" ]]; then
echo "IPTables chains and rules cleared."
fi


#setup IP forwarding
iptables -A FORWARD -i ${pinewan:-pinewandef} -o ${pinelan:-$pinelandef} -s ${pinenet:-172.16.42.0/24} -m state --state NEW -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A POSTROUTING -t nat -j MASQUERADE
if [[ $debug = "1" ]]; then
echo "IP forwarding enabled."
fi


#remove default route
route del default
if [[ $debug = "1" ]]; then
echo "Default route removed."
fi


#add default gateway
route add default gw ${pinegw:-$pinegwdef} ${pinewan:-wlan0}
if [[ $debug = "1" ]]; then
echo "Pineapple default gateway configured."
fi


echo ""
echo "Browse to http://${pineip:-172.16.42.1}:1471  --  Happy Hacking!"
echo ""

Cheers,

-Shadow

Edited by ShadowBlade72
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...