Jump to content

Archived

This topic is now archived and is closed to further replies.

PineDominator

Mark 4 Setup Script

Recommended Posts

I made a script that I run after a reflash and It has come in handy when I mess the pineapple up and have to re install firmware, was getting tired of inputting this manually.

pineapple-mk4-setup-script.sh
Version 3.2

#!/bin/sh

# Version 3.2
# This is a script for the pineapple mark 4 firmware 2.7.1 up, Newer firmware may break this script, Read through to add or comment out what you don't want.
# Run: chmod +x pineapple-mk4-setup-script.sh; ./pineapple-mk4-setup-script.sh
# It is assumed a USB drive with swap partition is unplugged and waiting to be inserted: http://forums.hak5.org/index.php?showtopic=25882&hl=swap&st=0



red='\e[0;31m'
lightRed='\e[1;31m'
green='\e[0;32m'
yellow='\e[0;33m'
cyan='\e[0;36m'
textReset='\e[m'
bold='\033[1m'
boldEnd='\033[0m'
uWhite='\e[4;37m'


appleSuccess=true
changeTimeZone=true
autoStartKarma=true
DNSSpoofLogsToUSB=true
changeSSID=true
changePineapplePort=true
stealthAutoStart=true

updateFSTabForSwap=true
useUSB=true # Please use one;-)

cleanUpUSB=true
logsToUSB=false


isThereInternet=true # Required for installing packages!!!

# All get installed to /usb/
installSSLStrip=true # Requires Internet
installTCPDump=true # Requires Internet
installNMap=true # Requires Internet
installReaver=true #Requires Internet
installMDK3=true #Requires Internet


changeRootPassword=true
newrootpassword='pineapplesareyummy'

newSSID='AndroidAP'
newPineapplePort=1471 # make sure it's above 1024

newTimeZone='PST8PDT'                    # PST8PDT America/Vancouver visit http://wiki.openwrt.org/doc/uci/system#time.zones for a list of time zones
newTimeZoneLocation='America/Vancouver'    # Please be careful, do not put in the whole value IE "PST8PDT,M3.2.0,M11.1.0" just use the PST8PDT
                                        # If you mess this up you may need to use serial connection to fix!!!

echo
echo -e $uWhite$bold'Pineapple Mark 4 setup script created by'$cyan' petertfm'$textReset
echo
echo


# Enable Apple Success to disable portal page popup when dnsspoofing with no internet:
if [ $appleSuccess = true ]; then
    if [ -d /www/ ]; then
        if [ ! -d /www/library/ ]; then
            mkdir /www/library
            if [ ! -d /www/library/test/ ]; then
                mkdir /www/library/test
            fi
        fi
        if [ ! -f /www/library/test/success.html ]; then
            echo -e '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
        <TITLE>Success</TITLE>
</HEAD>
<BODY>
Success
</BODY>
</HTML>' > /www/library/test/success.html
        fi
        echo -e '/www/library/test/success.html Created: Tricks apple products to beleve there is internet when running dnsspoof.'
    else
        echo -e $lightRed'/www/ folder not found, most likely script needs to be updated, firmware may have changed'
    fi
    echo -e $textReset
fi


# Change Timezone:
if [ $changeTimeZone = true ]; then
    if [ -f /etc/config/system ]; then
        echo -e 'Changing TimeZone: '$yellow$newTimeZone$textReset'   Location: '$yellow$newTimeZoneLocation
        sed -i "s/option timezone.*/option timezone '"$newTimeZone"'/g" /etc/config/system
        if [ -f /etc/rc.d/S98sysntpd ]; then
            /etc/rc.d/S98sysntpd restart
        else
            echo -e $lightRed'/etc/rc.d/S98sysntpd file not found, most likely script needs to be updated, firmware may have changed'
        fi
    else
        echo -e $lightRed'/etc/config/system file not found, most likely script needs to be updated, firmware may have changed'
    fi
    echo -e $textReset
fi


# AutoStart Karma
if [ $autoStartKarma = true ]; then
    if [ -f /pineapple/karma/autoKarmaStart.php ]; then
        php /pineapple/karma/autoKarmaStart.php > /dev/null
        echo 'Karma AutoStart Enabled'
    else
        echo -e $lightRed'/pineapple/karma/autoKarmaStart.php file not found, most likely script needs to be updated, firmware may have changed'
    fi
    echo -e $textReset
fi


# DNSSpoof Logs to USB:
if [ $DNSSpoofLogsToUSB = true ]; then
    if [ -f /pineapple/dnsspoof/dnsspoof.sh ]; then
        echo -e '#!/bin/sh

if [ ! -d /usb/logs ]; then
    mkdir /usb/logs
fi
if [ ! -d /usb/logs/DNSSpoof ]; then
    mkdir /usb/logs/DNSSpoof
fi

if [ -b /dev/sda1 ]; then
    MYPATH="/usb/logs/DNSSpoof/DNSSpoof-"
    dnsspoofFile="null"
    x=1
    while :
    do
        dnsspoofFile=${MYPATH}${x}.log
        if [ ! -f $dnsspoofFile ]; then
                break
        fi
        x=$(( $x + 1 ))
    done

    if [ -f /usb/logs/DNSSpoof/DNSSpoof.log ]; then
        md5=`md5sum /usb/logs/DNSSpoof/DNSSpoof.log`
        if [ ${md5:0:32} != "9a13ce17b26d5d2e2e153584c2d7c8e8" ]; then
            cp /usb/logs/DNSSpoof/DNSSpoof.log ${dnsspoofFile}
        fi
    fi

    sed -i "s/$cmd = \\"cat logs\\/dnsspoof.log\\";.*/$cmd = \\"cat \\/usb\\/logs\\/DNSSpoof\\/DNSSpoof.log\\";/g" /pineapple/pages/logs.php
    dnsspoof -i br-lan -f /pineapple/config/spoofhost > /dev/null 2> /usb/logs/DNSSpoof/DNSSpoof.log
else
    sed -i "s/$cmd = \\"cat \\/usb\\/logs\\/DNSSpoof\\/DNSSpoof.log\\";.*/$cmd = \\"cat logs\\/dnsspoof.log\\";/g" /pineapple/pages/logs.php
    dnsspoof -i br-lan -f /pineapple/config/spoofhost > /dev/null 2> /pineapple/logs/dnsspoof.log
fi' > /pineapple/dnsspoof/dnsspoof.sh
        echo 'Installed DNSSpoof logs to usb by petertfm'
    else
        echo -e $lightRed'/pineapple/dnsspoof/dnsspoof.sh file not found, most likely script needs to be updated, firmware may have changed'
    fi
    echo -e $textReset
fi


# Changing SSID:
if [ $changeSSID = true ]; then
    echo -e 'Changing SSID: '$yellow$newSSID
    sed -i 's/option ssid.*/option ssid '$newSSID'/g' /etc/config/wireless
    echo -e $textReset
fi


# Changing Pineapple UI Port:
if [ $changePineapplePort = true ]; then
    echo -e 'Changing Pineapple UI Port: '$yellow$newPineapplePort
    currentPort=`cat /etc/config/uhttpd | grep -i listen_http | grep -v listen_https | tail -n 1`
    currentPortPos=`expr index "$currentPort" :`
    port=${currentPort:$currentPortPos}
    sed -i 's/'$port'/'$newPineapplePort'/g' /etc/config/uhttpd
    echo -e $textReset
fi


# Enable Stealth:
if [ $stealthAutoStart = true ]; then
    if [ -f /etc/rc.local ]; then
        sed -i '/icmp_echo_ignore_all/d' /etc/rc.local
        sed -i '/exit 0/d' /etc/rc.local
        echo -e 'echo -e 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all # Autostart Stealth mode
exit 0' >> /etc/rc.local
        echo 'Stealth AutoStart Enabled'
    else
        echo -e $lightRed'/etc/rc.local file not found, most likely script needs to be updated, firmware may have changed'
    fi
    echo -e $textReset
fi


# Updating FStab(USB):
if [ $updateFSTabForSwap = true ]; then
    if [ -f /etc/config/fstab ]; then
        echo 'Updateing fstab for use with swap partition'
        echo -e 'config global automount
       option from_fstab 1
       option anon_mount 1

config global autoswap
       option from_fstab 1
       option anon_swap 1

config mount
       option target   /usb
       option device   /dev/sda1
       option fstype   ext4
       option options  rw,sync
       option enabled  1
       option enabled_fsck 0

config swap
       option device   /dev/sda2
       option enabled  1' > /etc/config/fstab
    else
        echo -e $lightRed'/etc/config/fstab file not found, most likely script needs to be updated, firmware may have changed'
        echo -e $red'This script is outdated, Exiting...'
        exit 1
    fi
    echo -e $textReset
fi






#
##
###
####
##### The rest of this script is mostly USB related with an exception to changing the root password
if [ $useUSB = true ]; then

    echo
    read -p 'Please Insert USB Drive then press ENTER!!!' nullVar
    echo 'Sleeping 15 seconds, USB drive initializing.'
    sleep 15
    echo -e $textReset

    if [ -b /dev/sda1 ]; then # The dev name of what gets mounted to /usb/

        # Make swap:
        if [ $updateFSTabForSwap = true ]; then
            if [ -b /dev/sda2 ]; then
                echo 'mkswap /dev/sda2, Swap may already have been made previously'
                mkswap /dev/sda2
            else
                echo -e $lightRed'/dev/sda2 not found for swap!'
            fi
            echo -e $textReset
        fi


        # Starting fresh with pineapple created files/folders on USB, From a previous install/firmware.
        if [ $cleanUpUSB = true ]; then
            echo 'Removing folders on USB, In prep for fresh settings'
            echo -e $yellow'(NOTE) Keep /usb/etc/ and /usb/usr/ to save previously installed OPKG packages'$textReset
            if [ -d /usb/data/ ]; then
                echo -n -e "Remove /usb/data/ "$cyan"(y)/n? "$textReset
                read dataYesNo
                if [[ "$dataYesNo" == '' ]]; then
                    dataYesNo='y'
                fi
                if [ $dataYesNo == 'y' ]; then
                    echo 'Removing: /usb/data/ TCPDump module is known to use this folder'
                    rm -r /usb/data/
                fi
            fi
            if [ -d /usb/get/ ]; then
                echo -n -e "Remove /usb/get/ "$cyan"(y)/n? "$textReset
                read getYesNo
                if [[ "$getYesNo" == '' ]]; then
                    getYesNo='y'
                fi
                if [ $getYesNo == 'y' ]; then
                    echo 'Removing: /usb/get/ get module is known to use this folder'
                    rm -r /usb/get/
                fi
            fi
            if [ -d /usb/logs/ ]; then
                echo -n -e "Remove /usb/logs/ "$cyan"(y)/n? "$textReset
                read logsYesNo
                if [[ "$logsYesNo" == '' ]]; then
                    logsYesNo='y'
                fi
                if [ $logsYesNo == 'y' ]; then
                    echo 'Removing: /usb/logs/'
                    rm -r /usb/logs/
                fi
            fi
            if [ -d /usb/modules/ ]; then
                echo -n -e "Remove /usb/modules/ "$cyan"(y)/n? "$textReset
                read modulesYesNo
                if [[ "$modulesYesNo" == '' ]]; then
                    modulesYesNo='y'
                fi
                if [ $modulesYesNo == 'y' ]; then
                    echo 'Removing: /usb/modules/'
                    rm -r /usb/modules/
                fi
            fi
            if [ -d /usb/infusions/ ]; then
                echo -n -e "Remove /usb/infusions/ "$cyan"(y)/n? "$textReset
                read infusionsYesNo
                if [[ "$infusionsYesNo" == '' ]]; then
                    infusionsYesNo='y'
                fi
                if [ $infusionsYesNo == 'y' ]; then
                    echo 'Removing: /usb/infusions/'
                    rm -r /usb/infusions/
                fi
            fi
            if [ -d /usb/etc/ ]; then
                echo -n -e "Remove /usb/etc/ "$cyan"(y)/n? "$textReset
                read etcYesNo
                if [[ "$etcYesNo" == '' ]]; then
                    etcYesNo='y'
                fi
                if [ $etcYesNo == 'y' ]; then
                    echo 'Removing: /usb/etc/'
                    rm -r /usb/etc/
                fi
            fi
            if [ -d /usb/usr/ ]; then
                echo -n -e "Remove /usb/usr/ "$cyan"(y)/n? "$textReset
                read usrYesNo
                if [[ "$usrYesNo" == '' ]]; then
                    usrYesNo='y'
                fi
                if [ $usrYesNo == 'y' ]; then
                    echo 'Removing: /usb/usr/'
                    rm -r /usb/usr/
                fi
            fi
            if [ -d /usb/var/ ]; then
            echo -n -e "Remove /usb/var/ "$cyan"(y)/n? "$textReset
                read varYesNo
                if [[ "$varYesNo" == '' ]]; then
                    varYesNo='y'
                fi
                if [ $varYesNo == 'y' ]; then
                    echo 'Removing: /usb/var/'
                    rm -r /usb/var/
                fi
            fi
            echo -e $textReset
        fi


        # /logs/ folder to USB:
        if [ $logsToUSB = true ]; then
            if [ -d /pineapple/logs/ ]; then
                # Moving logs folder to USB is experimental, After this change the usb drive must remain inserted at all times
                echo 'Moving /pineapple/logs/ folder to /usb/logs/, and sym linking back to /pineapple/logs'
                echo -e $yellow$bold'WARNING!!! from this point on the usb drive must be inserted at all times!'$boldEnd
                mv /pineapple/logs/ /usb/
                ln -s /usb/logs/ /pineapple/logs
                echo 'To revert back: rm /pineapple/logs; mv /usb/logs/ /pineapple/'
            else
                echo -e $lightRed'/pineapple/logs folder not found, most likely script needs to be updated, firmware may have changed'
            fi
            echo -e $textReset
        fi




        # OPKG Update:
        if [ $isThereInternet = true ]; then
            opkg update
            echo
            echo -e $textReset


            # Install SSLStrip:
            if [ $installSSLStrip = true ]; then
                # This will take a couple minutes to complete
                echo 'Installing SSLStrip, This will take a moment to complete...'
                opkg --dest usb install sslstrip
                touch /usb/usr/lib/python2.7/site-packages/zope/__init__.py
                echo
                echo
                echo -e $textReset
            fi
    
    
            # Install TCPDump:
            if [ $installTCPDump = true ]; then
                echo 'Installing TCPDump'
                opkg --dest usb install tcpdump
                echo
                echo
                echo -e $textReset
            fi
    
    
            # Install NMap:
            if [ $installNMap = true ]; then
                echo 'Installing NMap'
                opkg --dest usb install nmap
                echo
                echo
                echo -e $textReset
            fi
    
    
            # Install Reaver:
            if [ $installReaver = true ]; then
                echo 'Installing Reaver'
                opkg --dest usb install reaver
                echo
                echo
                echo -e $textReset
            fi


            # Install MDK3:
            if [ $installMDK3 = true ]; then
                echo 'Installing MDK3'
                opkg --dest usb install mdk3
                echo
                echo
                echo -e $textReset
            fi


            # Needed extras for packages installed to /usb/
            if [ -d /usb/etc/ ]; then
                echo 'Sym linking /usb/etc/* with /etc/'
                ls /usb/etc/
                ln -s /usb/etc/* /etc/
                echo
            fi
            
            if [ -d /usb/usr/sbin/ ]; then
                echo 'Sym linking /usb/usr/sbin/* with /usr/sbin/'
                ls /usb/usr/sbin/
                ln -s /usb/usr/sbin/* /usr/sbin/
                echo
            fi
            
            if [ -d /usb/usr/share/ ]; then
                echo 'Sym linking /usb/usr/share/* with /usr/share/'
                ls /usb/usr/share/
                ln -s /usb/usr/share/* /usr/share/
                echo
            fi
            
            if [ -d /usb/usr/lib/ ]; then
                echo 'Sym linking /usb/usr/lib/*.* with /usr/lib/'
                ls /usb/usr/lib/
                ln -s /usb/usr/lib/*.* /usr/lib/
                echo
            fi
            
            if [ -d /usb/usr/include/ ]; then
                if [ ! -d /usr/include/ ]; then
                    echo 'Making directory /usr/include'
                    mkdir /usr/include
                fi
                echo 'Sym linking /usb/usr/include/* with /usr/include/'
                ls /usb/usr/include/
                ln -s /usb/usr/include/* /usr/include/
            fi

            echo
            echo

        fi # End of Internet Functions




    fi
fi
#####
####
###
##
# End of USB Functions






# Change root password:
if [ $changeRootPassword = true ]; then
    echo -n -e "Change root password to:"$yellow$newrootpassword$cyan" (y)/n? "$textReset
    read newPasswordYesNo
    if [[ "$newPasswordYesNo" == '' ]]; then
        newPasswordYesNo='y'
    fi
    if [ $newPasswordYesNo == 'y' ]; then
        echo -e $newrootpassword'\n'$newrootpassword | passwd
        echo -e 'New password for root: '$yellow$newrootpassword
        echo -e $textReset'Warning if root password is lost serial connection is required!!!'
    fi
    echo
    echo -e $textReset
fi


# Restart Pineapple UI Port:
if [ $changePineapplePort = true ]; then
    echo -e $textReset'Rebooting uhttpd server...'
    /etc/init.d/uhttpd restart
    echo -e $textReset
fi


echo
echo
echo -e $cyan'Issue reboot to finish'$textReset



Read through to see what it is setting up. there are links to the files in the script or just comment out that stuff.
:-D

Share this post


Link to post
Share on other sites

Great little script that can be easily modified for each individual, thanx for contributing!

If anyone has written a script to auto install modules that would be a great incorporation into this script. If not I may write it and post it here to add in. I am going to add this onto my USB. Usually I flash and go into auto-mode on re-installing everything.

Share this post


Link to post
Share on other sites

Just copy/paste the code in a text editor and save like: pineapple-mk4-setup-script.sh

Copy that file to your pineapple with scp or WinSCP

Before you execute the script make sure you have formatted the usb properly.

# It is assumed a USB drive with swap partition is unplugged and waiting to be inserted: http://forums.hak5.org/index.php?showtopic=25882&hl=swap&st=0

Then following the instructions which are described in the top of the code ;)

# Run: chmod +x pineapple-mk4-setup-script.sh; ./pineapple-mk4-setup-script.sh

Good luck ;)

Share this post


Link to post
Share on other sites

Very cool petertfm! I'll definitely be utilizing a modified-to-my-tastes version of this script next firmware flash!

telot

Share this post


Link to post
Share on other sites

Nice work! Definitely will be checking this out.

Share this post


Link to post
Share on other sites

Nice! Great script, more robust then the little one i made, mine only did a few things.

I created the script by using SSH, then issuing:

touch pineapple-setup.sh

Then ran

chmod +x pineapple-setup.sh

Then ran it ./pineapple-mk4-setup-script.sh

As someone else pointed out you can do the last two in the same run

# chmod +x pineapple-setup.sh; ./pineapple-setup.sh

Share this post


Link to post
Share on other sites

great I am glad it's welcomed:-D

If you do have your own or a modification please post:-)

Share this post


Link to post
Share on other sites

New Version 0.3

changed the way DnsSpoof was being auto-started, now adds it in /etc/rc.local

before It was added to the cron tabs, would run or wouldn't (random) I think because of the ntp time update.

Share this post


Link to post
Share on other sites

New Version 0.3

changed the way DnsSpoof was being auto-started, now adds it in /etc/rc.local

before It was added to the cron tabs, would run or wouldn't (random) I think because of the ntp time update.

does it matter exactly where u put it ? i.e. any folder in the pineapple?

Share this post


Link to post
Share on other sites

does it matter exactly where u put it ? i.e. any folder in the pineapple?

someone mentioned there usb but I like to have it out before running the script.

I always put mine in /tmp/

/tmp/ is not flash but ram memory and is lost after a power cycle.

Share this post


Link to post
Share on other sites

Okay, this is freaking weird!! Once I reboot and hit a random page (hackaday.com) the page loads, mostly, then I get the pbj.mp3 running about 3 or 4 times in the background. I'll hit another page and get the rickroll background, but the pbj.mp3 instead of the rickroll mp3. I'll hit a third page and get the pbj page, with an X where the gif should be, and the right song playing. The next page with have the nyan header, but no gif or any song. :huh:

Share this post


Link to post
Share on other sites

Okay, this is freaking weird!! Once I reboot and hit a random page (hackaday.com) the page loads, mostly, then I get the pbj.mp3 running about 3 or 4 times in the background. I'll hit another page and get the rickroll background, but the pbj.mp3 instead of the rickroll mp3. I'll hit a third page and get the pbj page, with an X where the gif should be, and the right song playing. The next page with have the nyan header, but no gif or any song. :huh:

probably because those pages have frames with other .php or .html content that is maybe from another ip? I have experienced with my android if I visit a page say google.com before enabling dnsspoof the ip for google.com gets cached and even with dnsspoof enabled goes to the real google.com, until I clear the cache on my android, I use an app called 1tap cleaner free

Share this post


Link to post
Share on other sites

Nice! Need to give this a go. Enough releases today? :)

haaha I like to think updates.

Please anyone post your own modifications or scripts:-)

Share this post


Link to post
Share on other sites

New Version 1.0 in first post.

Complete code rework and some new additions and improvements;-)

Share this post


Link to post
Share on other sites

updated to 1.1

now includes rainbow chicken man in random roll

chat roll is not setup by default, just not good enough:-(

and some minor adjustments

please re-download web.zip because it includes the files necessary for rainbow chicken man

EDIT:

fixed error in random roll. sorry

added ability to auto-start stealth mode

Share this post


Link to post
Share on other sites

Fantastic! Thank you very much for the script, is a great idea and has served me very useful, I allowed myself to Spanish translate fairly well to leave messages in my language. Currently I have 2.3.1 firmware and there is a project that has translated much of the wiki and quick start guides which usually consulted, as they have also translated into Spanish web interface (172.16.41.1/pineapple) and I'm trying to get my pineapple is in my natural language, I think that is replaced through ssh, but I'm not sure.

Anyway, thank you very much again for the time invested in developing this fantastic script.

Sorry for my english. :)

Share this post


Link to post
Share on other sites

Fantastic! Thank you very much for the script, is a great idea and has served me very useful, I allowed myself to Spanish translate fairly well to leave messages in my language. Currently I have 2.3.1 firmware and there is a project that has translated much of the wiki and quick start guides which usually consulted, as they have also translated into Spanish web interface (172.16.41.1/pineapple) and I'm trying to get my pineapple is in my natural language, I think that is replaced through ssh, but I'm not sure.

Anyway, thank you very much again for the time invested in developing this fantastic script.

Sorry for my english. :)

We are about to add multi-language support.

Once we do, I will contact the Spanish developers to translate our strings file.

Then you can enjoy your pineapple in Spanish ;)

Best,

Sebkinne

Share this post


Link to post
Share on other sites

Having problems getting this script to run. See error below:

m1Fhd.png

have you chmod +x

and I am not sure what the program you are trying to run from? winscp?

you need to run it from an ssh session so any errors or problems can be seen.

Share this post


Link to post
Share on other sites

have you chmod +x

and I am not sure what the program you are trying to run from? winscp?

you need to run it from an ssh session so any errors or problems can be seen.

I got it sorted now. For some reason when I put it in the /tmp/ folder instead of the root directory, it worked.

Share this post


Link to post
Share on other sites

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...