Advertisement
mightyroot

Openwrt hack soft

Jan 28th, 2013
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 16.74 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # Version 3.2
  4. # 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.
  5. # Run: chmod +x pineapple-mk4-setup-script.sh; ./pineapple-mk4-setup-script.sh
  6. # 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
  7.  
  8.  
  9.  
  10. red='\e[0;31m'
  11. lightRed='\e[1;31m'
  12. green='\e[0;32m'
  13. yellow='\e[0;33m'
  14. cyan='\e[0;36m'
  15. textReset='\e[m'
  16. bold='\033[1m'
  17. boldEnd='\033[0m'
  18. uWhite='\e[4;37m'
  19.  
  20.  
  21. appleSuccess=true
  22. changeTimeZone=true
  23. autoStartKarma=true
  24. DNSSpoofLogsToUSB=true
  25. changeSSID=true
  26. changePineapplePort=true
  27. stealthAutoStart=true
  28.  
  29. updateFSTabForSwap=true
  30. useUSB=true # Please use one;-)
  31.  
  32. cleanUpUSB=true
  33. logsToUSB=false
  34.  
  35.  
  36. isThereInternet=true # Required for installing packages!!!
  37.  
  38. # All get installed to /usb/
  39. installSSLStrip=true # Requires Internet
  40. installTCPDump=true # Requires Internet
  41. installNMap=true # Requires Internet
  42. installReaver=true #Requires Internet
  43. installMDK3=true #Requires Internet
  44.  
  45.  
  46. changeRootPassword=true
  47. newrootpassword='pineapplesareyummy'
  48.  
  49. newSSID='AndroidAP'
  50. newPineapplePort=1471 # make sure it's above 1024
  51.  
  52. newTimeZone='PST8PDT'                    # PST8PDT America/Vancouver visit http://wiki.openwrt.org/doc/uci/system#time.zones for a list of time zones
  53. 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
  54.                                         # If you mess this up you may need to use serial connection to fix!!!
  55.  
  56. echo
  57. echo -e $uWhite$bold'Pineapple Mark 4 setup script created by'$cyan' petertfm'$textReset
  58. echo
  59. echo
  60.  
  61.  
  62. # Enable Apple Success to disable portal page popup when dnsspoofing with no internet:
  63. if [ $appleSuccess = true ]; then
  64.     if [ -d /www/ ]; then
  65.         if [ ! -d /www/library/ ]; then
  66.             mkdir /www/library
  67.             if [ ! -d /www/library/test/ ]; then
  68.                 mkdir /www/library/test
  69.             fi
  70.         fi
  71.         if [ ! -f /www/library/test/success.html ]; then
  72.             echo -e '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
  73. <HTML>
  74. <HEAD>
  75.        <TITLE>Success</TITLE>
  76. </HEAD>
  77. <BODY>
  78. Success
  79. </BODY>
  80. </HTML>' > /www/library/test/success.html
  81.         fi
  82.         echo -e '/www/library/test/success.html Created: Tricks apple products to beleve there is internet when running dnsspoof.'
  83.     else
  84.         echo -e $lightRed'/www/ folder not found, most likely script needs to be updated, firmware may have changed'
  85.     fi
  86.     echo -e $textReset
  87. fi
  88.  
  89.  
  90. # Change Timezone:
  91. if [ $changeTimeZone = true ]; then
  92.     if [ -f /etc/config/system ]; then
  93.         echo -e 'Changing TimeZone: '$yellow$newTimeZone$textReset'   Location: '$yellow$newTimeZoneLocation
  94.         sed -i "s/option timezone.*/option timezone '"$newTimeZone"'/g" /etc/config/system
  95.         if [ -f /etc/rc.d/S98sysntpd ]; then
  96.             /etc/rc.d/S98sysntpd restart
  97.         else
  98.             echo -e $lightRed'/etc/rc.d/S98sysntpd file not found, most likely script needs to be updated, firmware may have changed'
  99.         fi
  100.     else
  101.         echo -e $lightRed'/etc/config/system file not found, most likely script needs to be updated, firmware may have changed'
  102.     fi
  103.     echo -e $textReset
  104. fi
  105.  
  106.  
  107. # AutoStart Karma
  108. if [ $autoStartKarma = true ]; then
  109.     if [ -f /pineapple/karma/autoKarmaStart.php ]; then
  110.         php /pineapple/karma/autoKarmaStart.php > /dev/null
  111.         echo 'Karma AutoStart Enabled'
  112.     else
  113.         echo -e $lightRed'/pineapple/karma/autoKarmaStart.php file not found, most likely script needs to be updated, firmware may have changed'
  114.     fi
  115.     echo -e $textReset
  116. fi
  117.  
  118.  
  119. # DNSSpoof Logs to USB:
  120. if [ $DNSSpoofLogsToUSB = true ]; then
  121.     if [ -f /pineapple/dnsspoof/dnsspoof.sh ]; then
  122.         echo -e '#!/bin/sh
  123.  
  124. if [ ! -d /usb/logs ]; then
  125.    mkdir /usb/logs
  126. fi
  127. if [ ! -d /usb/logs/DNSSpoof ]; then
  128.    mkdir /usb/logs/DNSSpoof
  129. fi
  130.  
  131. if [ -b /dev/sda1 ]; then
  132.    MYPATH="/usb/logs/DNSSpoof/DNSSpoof-"
  133.    dnsspoofFile="null"
  134.    x=1
  135.    while :
  136.    do
  137.        dnsspoofFile=${MYPATH}${x}.log
  138.        if [ ! -f $dnsspoofFile ]; then
  139.                break
  140.        fi
  141.        x=$(( $x + 1 ))
  142.    done
  143.  
  144.    if [ -f /usb/logs/DNSSpoof/DNSSpoof.log ]; then
  145.        md5=`md5sum /usb/logs/DNSSpoof/DNSSpoof.log`
  146.        if [ ${md5:0:32} != "9a13ce17b26d5d2e2e153584c2d7c8e8" ]; then
  147.            cp /usb/logs/DNSSpoof/DNSSpoof.log ${dnsspoofFile}
  148.        fi
  149.    fi
  150.  
  151.    sed -i "s/$cmd = \\"cat logs\\/dnsspoof.log\\";.*/$cmd = \\"cat \\/usb\\/logs\\/DNSSpoof\\/DNSSpoof.log\\";/g" /pineapple/pages/logs.php
  152.    dnsspoof -i br-lan -f /pineapple/config/spoofhost > /dev/null 2> /usb/logs/DNSSpoof/DNSSpoof.log
  153. else
  154.    sed -i "s/$cmd = \\"cat \\/usb\\/logs\\/DNSSpoof\\/DNSSpoof.log\\";.*/$cmd = \\"cat logs\\/dnsspoof.log\\";/g" /pineapple/pages/logs.php
  155.    dnsspoof -i br-lan -f /pineapple/config/spoofhost > /dev/null 2> /pineapple/logs/dnsspoof.log
  156. fi' > /pineapple/dnsspoof/dnsspoof.sh
  157.         echo 'Installed DNSSpoof logs to usb by petertfm'
  158.     else
  159.         echo -e $lightRed'/pineapple/dnsspoof/dnsspoof.sh file not found, most likely script needs to be updated, firmware may have changed'
  160.     fi
  161.     echo -e $textReset
  162. fi
  163.  
  164.  
  165. # Changing SSID:
  166. if [ $changeSSID = true ]; then
  167.     echo -e 'Changing SSID: '$yellow$newSSID
  168.     sed -i 's/option ssid.*/option ssid '$newSSID'/g' /etc/config/wireless
  169.     echo -e $textReset
  170. fi
  171.  
  172.  
  173. # Changing Pineapple UI Port:
  174. if [ $changePineapplePort = true ]; then
  175.     echo -e 'Changing Pineapple UI Port: '$yellow$newPineapplePort
  176.     currentPort=`cat /etc/config/uhttpd | grep -i listen_http | grep -v listen_https | tail -n 1`
  177.     currentPortPos=`expr index "$currentPort" :`
  178.     port=${currentPort:$currentPortPos}
  179.     sed -i 's/'$port'/'$newPineapplePort'/g' /etc/config/uhttpd
  180.     echo -e $textReset
  181. fi
  182.  
  183.  
  184. # Enable Stealth:
  185. if [ $stealthAutoStart = true ]; then
  186.     if [ -f /etc/rc.local ]; then
  187.         sed -i '/icmp_echo_ignore_all/d' /etc/rc.local
  188.         sed -i '/exit 0/d' /etc/rc.local
  189.         echo -e 'echo -e 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all # Autostart Stealth mode
  190. exit 0' >> /etc/rc.local
  191.         echo 'Stealth AutoStart Enabled'
  192.     else
  193.         echo -e $lightRed'/etc/rc.local file not found, most likely script needs to be updated, firmware may have changed'
  194.     fi
  195.     echo -e $textReset
  196. fi
  197.  
  198.  
  199. # Updating FStab(USB):
  200. if [ $updateFSTabForSwap = true ]; then
  201.     if [ -f /etc/config/fstab ]; then
  202.         echo 'Updateing fstab for use with swap partition'
  203.         echo -e 'config global automount
  204.       option from_fstab 1
  205.       option anon_mount 1
  206.  
  207. config global autoswap
  208.       option from_fstab 1
  209.       option anon_swap 1
  210.  
  211. config mount
  212.       option target   /usb
  213.       option device   /dev/sda1
  214.       option fstype   ext4
  215.       option options  rw,sync
  216.       option enabled  1
  217.       option enabled_fsck 0
  218.  
  219. config swap
  220.       option device   /dev/sda2
  221.       option enabled  1' > /etc/config/fstab
  222.     else
  223.         echo -e $lightRed'/etc/config/fstab file not found, most likely script needs to be updated, firmware may have changed'
  224.         echo -e $red'This script is outdated, Exiting...'
  225.         exit 1
  226.     fi
  227.     echo -e $textReset
  228. fi
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235. #
  236. ##
  237. ###
  238. ####
  239. ##### The rest of this script is mostly USB related with an exception to changing the root password
  240. if [ $useUSB = true ]; then
  241.  
  242.     echo
  243.     read -p 'Please Insert USB Drive then press ENTER!!!' nullVar
  244.     echo 'Sleeping 15 seconds, USB drive initializing.'
  245.     sleep 15
  246.     echo -e $textReset
  247.  
  248.     if [ -b /dev/sda1 ]; then # The dev name of what gets mounted to /usb/
  249.  
  250.         # Make swap:
  251.         if [ $updateFSTabForSwap = true ]; then
  252.             if [ -b /dev/sda2 ]; then
  253.                 echo 'mkswap /dev/sda2, Swap may already have been made previously'
  254.                 mkswap /dev/sda2
  255.             else
  256.                 echo -e $lightRed'/dev/sda2 not found for swap!'
  257.             fi
  258.             echo -e $textReset
  259.         fi
  260.  
  261.  
  262.         # Starting fresh with pineapple created files/folders on USB, From a previous install/firmware.
  263.         if [ $cleanUpUSB = true ]; then
  264.             echo 'Removing folders on USB, In prep for fresh settings'
  265.             echo -e $yellow'(NOTE) Keep /usb/etc/ and /usb/usr/ to save previously installed OPKG packages'$textReset
  266.             if [ -d /usb/data/ ]; then
  267.                 echo -n -e "Remove /usb/data/ "$cyan"(y)/n? "$textReset
  268.                 read dataYesNo
  269.                 if [[ "$dataYesNo" == '' ]]; then
  270.                     dataYesNo='y'
  271.                 fi
  272.                 if [ $dataYesNo == 'y' ]; then
  273.                     echo 'Removing: /usb/data/ TCPDump module is known to use this folder'
  274.                     rm -r /usb/data/
  275.                 fi
  276.             fi
  277.             if [ -d /usb/get/ ]; then
  278.                 echo -n -e "Remove /usb/get/ "$cyan"(y)/n? "$textReset
  279.                 read getYesNo
  280.                 if [[ "$getYesNo" == '' ]]; then
  281.                     getYesNo='y'
  282.                 fi
  283.                 if [ $getYesNo == 'y' ]; then
  284.                     echo 'Removing: /usb/get/ get module is known to use this folder'
  285.                     rm -r /usb/get/
  286.                 fi
  287.             fi
  288.             if [ -d /usb/logs/ ]; then
  289.                 echo -n -e "Remove /usb/logs/ "$cyan"(y)/n? "$textReset
  290.                 read logsYesNo
  291.                 if [[ "$logsYesNo" == '' ]]; then
  292.                     logsYesNo='y'
  293.                 fi
  294.                 if [ $logsYesNo == 'y' ]; then
  295.                     echo 'Removing: /usb/logs/'
  296.                     rm -r /usb/logs/
  297.                 fi
  298.             fi
  299.             if [ -d /usb/modules/ ]; then
  300.                 echo -n -e "Remove /usb/modules/ "$cyan"(y)/n? "$textReset
  301.                 read modulesYesNo
  302.                 if [[ "$modulesYesNo" == '' ]]; then
  303.                     modulesYesNo='y'
  304.                 fi
  305.                 if [ $modulesYesNo == 'y' ]; then
  306.                     echo 'Removing: /usb/modules/'
  307.                     rm -r /usb/modules/
  308.                 fi
  309.             fi
  310.             if [ -d /usb/infusions/ ]; then
  311.                 echo -n -e "Remove /usb/infusions/ "$cyan"(y)/n? "$textReset
  312.                 read infusionsYesNo
  313.                 if [[ "$infusionsYesNo" == '' ]]; then
  314.                     infusionsYesNo='y'
  315.                 fi
  316.                 if [ $infusionsYesNo == 'y' ]; then
  317.                     echo 'Removing: /usb/infusions/'
  318.                     rm -r /usb/infusions/
  319.                 fi
  320.             fi
  321.             if [ -d /usb/etc/ ]; then
  322.                 echo -n -e "Remove /usb/etc/ "$cyan"(y)/n? "$textReset
  323.                 read etcYesNo
  324.                 if [[ "$etcYesNo" == '' ]]; then
  325.                     etcYesNo='y'
  326.                 fi
  327.                 if [ $etcYesNo == 'y' ]; then
  328.                     echo 'Removing: /usb/etc/'
  329.                     rm -r /usb/etc/
  330.                 fi
  331.             fi
  332.             if [ -d /usb/usr/ ]; then
  333.                 echo -n -e "Remove /usb/usr/ "$cyan"(y)/n? "$textReset
  334.                 read usrYesNo
  335.                 if [[ "$usrYesNo" == '' ]]; then
  336.                     usrYesNo='y'
  337.                 fi
  338.                 if [ $usrYesNo == 'y' ]; then
  339.                     echo 'Removing: /usb/usr/'
  340.                     rm -r /usb/usr/
  341.                 fi
  342.             fi
  343.             if [ -d /usb/var/ ]; then
  344.             echo -n -e "Remove /usb/var/ "$cyan"(y)/n? "$textReset
  345.                 read varYesNo
  346.                 if [[ "$varYesNo" == '' ]]; then
  347.                     varYesNo='y'
  348.                 fi
  349.                 if [ $varYesNo == 'y' ]; then
  350.                     echo 'Removing: /usb/var/'
  351.                     rm -r /usb/var/
  352.                 fi
  353.             fi
  354.             echo -e $textReset
  355.         fi
  356.  
  357.  
  358.         # /logs/ folder to USB:
  359.         if [ $logsToUSB = true ]; then
  360.             if [ -d /pineapple/logs/ ]; then
  361.                 # Moving logs folder to USB is experimental, After this change the usb drive must remain inserted at all times
  362.                 echo 'Moving /pineapple/logs/ folder to /usb/logs/, and sym linking back to /pineapple/logs'
  363.                 echo -e $yellow$bold'WARNING!!! from this point on the usb drive must be inserted at all times!'$boldEnd
  364.                 mv /pineapple/logs/ /usb/
  365.                 ln -s /usb/logs/ /pineapple/logs
  366.                 echo 'To revert back: rm /pineapple/logs; mv /usb/logs/ /pineapple/'
  367.             else
  368.                 echo -e $lightRed'/pineapple/logs folder not found, most likely script needs to be updated, firmware may have changed'
  369.             fi
  370.             echo -e $textReset
  371.         fi
  372.  
  373.  
  374.  
  375.  
  376.         # OPKG Update:
  377.         if [ $isThereInternet = true ]; then
  378.             opkg update
  379.             echo
  380.             echo -e $textReset
  381.  
  382.  
  383.             # Install SSLStrip:
  384.             if [ $installSSLStrip = true ]; then
  385.                 # This will take a couple minutes to complete
  386.                 echo 'Installing SSLStrip, This will take a moment to complete...'
  387.                 opkg --dest usb install sslstrip
  388.                 touch /usb/usr/lib/python2.7/site-packages/zope/__init__.py
  389.                 echo
  390.                 echo
  391.                 echo -e $textReset
  392.             fi
  393.    
  394.    
  395.             # Install TCPDump:
  396.             if [ $installTCPDump = true ]; then
  397.                 echo 'Installing TCPDump'
  398.                 opkg --dest usb install tcpdump
  399.                 echo
  400.                 echo
  401.                 echo -e $textReset
  402.             fi
  403.    
  404.    
  405.             # Install NMap:
  406.             if [ $installNMap = true ]; then
  407.                 echo 'Installing NMap'
  408.                 opkg --dest usb install nmap
  409.                 echo
  410.                 echo
  411.                 echo -e $textReset
  412.             fi
  413.    
  414.    
  415.             # Install Reaver:
  416.             if [ $installReaver = true ]; then
  417.                 echo 'Installing Reaver'
  418.                 opkg --dest usb install reaver
  419.                 echo
  420.                 echo
  421.                 echo -e $textReset
  422.             fi
  423.  
  424.  
  425.             # Install MDK3:
  426.             if [ $installMDK3 = true ]; then
  427.                 echo 'Installing MDK3'
  428.                 opkg --dest usb install mdk3
  429.                 echo
  430.                 echo
  431.                 echo -e $textReset
  432.             fi
  433.  
  434.  
  435.             # Needed extras for packages installed to /usb/
  436.             if [ -d /usb/etc/ ]; then
  437.                 echo 'Sym linking /usb/etc/* with /etc/'
  438.                 ls /usb/etc/
  439.                 ln -s /usb/etc/* /etc/
  440.                 echo
  441.             fi
  442.            
  443.             if [ -d /usb/usr/sbin/ ]; then
  444.                 echo 'Sym linking /usb/usr/sbin/* with /usr/sbin/'
  445.                 ls /usb/usr/sbin/
  446.                 ln -s /usb/usr/sbin/* /usr/sbin/
  447.                 echo
  448.             fi
  449.            
  450.             if [ -d /usb/usr/share/ ]; then
  451.                 echo 'Sym linking /usb/usr/share/* with /usr/share/'
  452.                 ls /usb/usr/share/
  453.                 ln -s /usb/usr/share/* /usr/share/
  454.                 echo
  455.             fi
  456.            
  457.             if [ -d /usb/usr/lib/ ]; then
  458.                 echo 'Sym linking /usb/usr/lib/*.* with /usr/lib/'
  459.                 ls /usb/usr/lib/
  460.                 ln -s /usb/usr/lib/*.* /usr/lib/
  461.                 echo
  462.             fi
  463.            
  464.             if [ -d /usb/usr/include/ ]; then
  465.                 if [ ! -d /usr/include/ ]; then
  466.                     echo 'Making directory /usr/include'
  467.                     mkdir /usr/include
  468.                 fi
  469.                 echo 'Sym linking /usb/usr/include/* with /usr/include/'
  470.                 ls /usb/usr/include/
  471.                 ln -s /usb/usr/include/* /usr/include/
  472.             fi
  473.  
  474.             echo
  475.             echo
  476.  
  477.         fi # End of Internet Functions
  478.  
  479.  
  480.  
  481.  
  482.     fi
  483. fi
  484. #####
  485. ####
  486. ###
  487. ##
  488. # End of USB Functions
  489.  
  490.  
  491.  
  492.  
  493.  
  494.  
  495. # Change root password:
  496. if [ $changeRootPassword = true ]; then
  497.     echo -n -e "Change root password to:"$yellow$newrootpassword$cyan" (y)/n? "$textReset
  498.     read newPasswordYesNo
  499.     if [[ "$newPasswordYesNo" == '' ]]; then
  500.         newPasswordYesNo='y'
  501.     fi
  502.     if [ $newPasswordYesNo == 'y' ]; then
  503.         echo -e $newrootpassword'\n'$newrootpassword | passwd
  504.         echo -e 'New password for root: '$yellow$newrootpassword
  505.         echo -e $textReset'Warning if root password is lost serial connection is required!!!'
  506.     fi
  507.     echo
  508.     echo -e $textReset
  509. fi
  510.  
  511.  
  512. # Restart Pineapple UI Port:
  513. if [ $changePineapplePort = true ]; then
  514.     echo -e $textReset'Rebooting uhttpd server...'
  515.     /etc/init.d/uhttpd restart
  516.     echo -e $textReset
  517. fi
  518.  
  519.  
  520. echo
  521. echo
  522. echo -e $cyan'Issue reboot to finish'$textReset
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement