#!/usr/bin/env python
# This is a update script for Backtrack 5 / R1.
# Author: sickness
# NOTE: This script will only work on Backtrack 5.
# For Feedback/Bugs: sick.n3ss416@gmail.com
# Blog: http://sickness.tor.hu
# Hope you like it!

#-----------------------------------
#-----------------------------------

import sys,os,subprocess,time,urllib2
from time import *

def internet_check():
  
	if subprocess.Popen("ping -q -c 1 -w 2 www.google.com > /dev/null",shell=True).wait() == 0:
		print "Internet is working!"
	else:
		print "Internet is not working!"
		print "To continue without internet connectivity comment '#' the function at line 666.\n"
		sys.exit()
		
#----------------------------------- Update functions!

def backtrack_update():

	print " [>] Updating and cleaning Backtrack, please wait.\n"
	
	if subprocess.Popen("apt-get update && apt-get -y dist-upgrade && apt-get autoremove -y && apt-get -y autoclean",shell=True).wait() == 0:
		print "\n"
		print " [>] Backtrack updated and cleaned successfully!\n"
	
	else:
		print "\n"
		print " [>] Failed to update Backtrack.\n"
	
def exploit_db():

        print " [>] Updating Exploit-db, please wait.\n"
        
        if subprocess.Popen("cd /pentest/exploits/exploitdb/ && svn up",shell=True).wait() == 0:
		print "\n"
        	print " [>] Exploit-db updated successfully!\n"
	
	else: 
		print "\n"
		print " [>] Failed to update Exploit-db.\n"
	

def s_e_t():

        print " [>] Updating SET, please wait.\n"
       
        if subprocess.Popen("cd /pentest/exploits/set/ && svn up",shell=True).wait() == 0:
	  print "\n"
	  print " [>] SET updated successfully!\n"
	
	else: 
		print "\n"
		print " [>] Failed to update SET.\n"
	
def warvox():

	print " [>] Updating Warvox, please wait.\n"
	
	if subprocess.Popen("cd /pentest/telephony/warvox/ && svn up",shell=True).wait() == 0:
	  print "\n"
	  print " [>] Warvox updated successfully!\n"
	
	else:
		print "\n"
		print " [>] Failed to update Warvox\n"
	
def aircrack():

	print " [>] Updating Aircrack-NG and Airodump, please wait.\n"

	subprocess.Popen("apt-get install libssl-dev",shell=True).wait()	
	if subprocess.Popen("cd /pentest/wireless/aircrack-ng/ && svn up",shell=True).wait() == 0: 
		
	  	if subprocess.Popen("cd /pentest/wireless/aircrack-ng/ && make",shell=True).wait() == 0:
			subprocess.Popen("cd /pentest/wireless/aircrack-ng/ && make install",shell=True).wait()
			subprocess.Popen("cd /pentest/wireless/aircrack-ng/scripts/ && chmod a+x airodump-ng-oui-update && ./airodump-ng-oui-update",shell=True).wait()
	  		print "\n"
	  		print " [>] Aircrack-NG and Airodump updated successfully!\n"
	
	else: 
		print "\n"
		print " [>] Failed to update Aircrack-ng.\n"
	
def giskismet():

	print " [>] Updating Giskismet, please wait.\n"
	
	if subprocess.Popen("cd /pentest/wireless/giskismet/ && svn up",shell=True).wait() == 0: 
	  print "\n"
	  print " [>] Giskismet updated successfully!\n"
	
	else: 
		print "\n"
		print " [>] Failed to update Giskismet.\n"
	
def msf():

	print " [>] Updating Metasploit, please wait.\n"
	
	if subprocess.Popen("cd /pentest/exploits/framework/ && svn up",shell=True).wait() == 0: 
	  print "\n"
	  print " [>] Metasploit updated successfully!\n"
	
	else: 
		print "\n"
		print " [>] Failed to update Metasploit.\n"
	
def w3af():

        print " [>] Updating W3AF, please wait.\n"
        
        if subprocess.Popen("cd /pentest/web/w3af/ && svn up",shell=True).wait() == 0: 
	  print "\n"
	  print " [>] W3AF updated successfully!\n"
	
	else: 
		print "\n"
		print " [>] Failed to update W3AF.\n"
	
def nikto():

        print " [>] Updating Nikto, please wait.\n"
        
        if subprocess.Popen("cd /pentest/web/nikto/ && ./nikto.pl -update",shell=True).wait() == 0: 
	  print "\n"
	  print " [>] Nikto updated successfully!\n"
	
	else: 
		print "\n"
		print " [>] Failed to update Nikto.\n"
	
def fasttrack():

        print " [>] Installing/Updating Fasttrack, please wait.\n"
        
	subprocess.Popen("apt-get -y install fasttrack",shell=True).wait()
        if subprocess.Popen("cd /pentest/exploits/fasttrack/ && ./fast-track.py -c 1",shell=True).wait() == 0: 
	  print "\n"
	  print " [>] Fasttrack  updated successfully!\n"
	
	else: 
		print "\n"
		print " [>] Failed to update Fasttrack.\n"
	
def pyrit():

	print " [>] Checking to see if  pyrit is installed.\n"
	
	if subprocess.Popen("pyrit > /dev/null",shell=True).wait() == 0: 
	    print "\n"
	    print " [>] Pyrit installed!\n"
	
	else: 
	    print " [>] Installing Pyrit, please wait.\n"
	    subprocess.Popen("apt-get -y install libssl-dev scapy python-dev",shell=True).wait()
	    subprocess.Popen("svn checkout http://pyrit.googlecode.com/svn/trunk/ pyrit_svn",shell=True).wait()
	    subprocess.Popen("cd pyrit_svn/pyrit && python setup.py build && python setup.py install",shell=True).wait()
	    subprocess.Popen("rm -rf pyrit_svn",shell=True).wait()
	    print "\n"
	    print " [>] Pyrit installed successfully!\n"
	
def nmap():

	print " [>] Updating Nmap Fingerprints, please wait.\n"
	
	if subprocess.Popen("wget http://nmap.org/svn/nmap-os-db -O /usr/local/share/nmap/nmap-os-db",shell=True).wait() == 0: 
	    print "\n"
	    print " [>] Nmap updated successfully!\n"
	
	else: 
	    print "\n"
	    print " [>] Failed to update nmap!\n"
	
def fimap():

	print " [>] Updating Fimap and installing MSF plugin, please wait.\n"
	
        if subprocess.Popen("cd /pentest/web/fimap/ && ./fimap.py --update-def",shell=True).wait() == 1: 
	    print "\n"
            print " [>] Fimap updated successfully!\n"
        
        else: 
	    print "\n"
            print " [>] Failed to update Fimap!\n"

def sslstrip():
	print " [>] Updating SSLStrip, please wait.\n"
	subprocess.Popen("rm -rf sslstrip*",shell=True).wait()
	
        if subprocess.Popen("wget http://www.thoughtcrime.org/software/sslstrip/sslstrip-0.9.tar.gz > /dev/null",shell=True).wait() == 0:
	    subprocess.Popen("apt-get -y purge sslstrip",shell=True).wait()
	    subprocess.Popen("tar xvfz sslstrip-0.9.tar.gz",shell=True).wait()
	    subprocess.Popen("rm -rf /pentest/web/sslstrip/",shell=True).wait()
	    subprocess.Popen("mv -f sslstrip-0.9 /pentest/web/sslstrip",shell=True).wait()
	    subprocess.Popen("cd /pentest/web/sslstrip && python ./setup.py install",shell=True).wait()
	    subprocess.Popen("rm -rf sslstrip*",shell=True).wait()
	    print "\n"
            print " [>] SSLStrip updated successfully!\n"
        
        else: 
	    print "\n"
            print " [>] Failed to update SSLStrip!\n"

def openvas():

	print " [>] Updating OpenVAS, please wait.\n"
	
        if subprocess.Popen("openvas-nvt-sync",shell=True).wait() == 0: 
	    print "\n"
            print " [>] OpenVAS updated successfully!\n"
        
        else: 
	    print "\n"
            print " [>] Failed to update OpenVAS!\n"

def sickfuzz():
	print " [>] Updating SickFuzz, please wait.\n"
	subprocess.Popen("rm -rf sickfuzz*",shell=True).wait()
	
        if subprocess.Popen("wget https://sickfuzz.googlecode.com/files/sickfuzz_v1.0.zip /dev/null",shell=True).wait() == 0:
	    subprocess.Popen("unzip sickfuzz_v1.0.zip",shell=True).wait()
	    subprocess.Popen("rm -rf /pentest/fuzzers/sickfuzz/",shell=True).wait()
	    subprocess.Popen("mv -f sickfuzz /pentest/fuzzers/",shell=True).wait()
	    subprocess.Popen("cd /pentest/fuzzers/sickfuzz/ && python ./setup.py install",shell=True).wait()
	    subprocess.Popen("rm -rf sickfuzz*",shell=True).wait()
	    print "\n"
            print " [>] SickFuzz updated successfully!\n"
        
        else: 
	    print "\n"
            print " [>] Failed to update SickFuzz!\n"

def wireshark():

	print " [>] Updating and installing wireshark, please wait.\n"

	subprocess.Popen("apt-get remove wireshark -y",shell=True).wait()
	subprocess.Popen("apt-get autoremove -y",shell=True).wait()	
	subprocess.Popen("apt-get update && apt-get install libtool flex libgtk2.0-dev lua50 dpatch libc-ares-dev docbook-xsl libpcre3-dev libcap-dev libgnutls-dev libkrb5-dev liblua5.1-0-dev libsmi2-dev libgeoip-dev xsltproc automake1.9 libssl-dev byacc libcap2-bin libportaudio0 smistrip snmp-mibs-downloader -y",shell=True).wait()
	subprocess.Popen("rm -rf wireshark*",shell=True).wait()
	
	if subprocess.Popen("svn co http://anonsvn.wireshark.org/wireshark/trunk/ wireshark",shell=True).wait() == 0: 
		subprocess.Popen("cd wireshark && ./autogen.sh",shell=True).wait()
		subprocess.Popen("cd wireshark && ./configure --with-ssl",shell=True).wait()
		subprocess.Popen("cd wireshark && make",shell=True).wait()
		subprocess.Popen("cd wireshark && make install",shell=True).wait()
		subprocess.Popen("cd wireshark && ldconfig",shell=True).wait()
		subprocess.Popen("rm -rf wireshark",shell=True).wait()
		subprocess.Popen('sed -i "s/dofile(DATA_DIR..\"console.lua\")/--dofile(DATA_DIR..\"console.lua\")/g" /usr/local/share/wireshark/init.lua',shell=True).wait()
		print "\n"
		print " [>] Wireshark updated successfully!\n"
	
	else: 
		print "\n"
		print " [>] Failed to update Wireshark!\n"

def update():

	print " [>] Updating the evil script.\n"
	
	subprocess.Popen("wget http://sickness.tor.hu/wp-content/uploads/2011/06/backtrack5_update.py -O backtrack5_update.py",shell=True).wait()
	subprocess.Popen("chmod a+x backtrack5_update.py",shell=True).wait()
	print "\n"
	print " [>] Update successfully, now please run the script again!\n"
	sleep(2)
	subprocess.Popen("./backtrack5_update.py",shell=True).wait()

def changelog():

	subprocess.Popen("cd /tmp && wget http://sickness.tor.hu/wp-content/uploads/2011/06/changelog.txt -o /dev/null",shell=True).wait()
	subprocess.Popen("less /tmp/changelog.txt",shell=True).wait()
	subprocess.Popen("rm -rf /tmp/changelog.txt",shell=True).wait()
	menu_main()

def tryharder():

	print "\n"
	print " [>] Wrong choice, try again ... \n"
	
#----------------------------------- Menus!

def header():
  
        print "\n        +-++-++-++-++-++-++-++-++-+ +-+ +-++-++-++-++-++-+"
        print "        |B||a||c||k||t||r||a||c||k| |5| |u||p||d||a||t||e|"
        print "        +-++-++-++-++-++-++-++-++-+ +-+ +-++-++-++-++-++-+\n"
        print "                 Author: sickness"
	print "		 Also thanks to g0tmi1k for his help!"
	print "		 Version: 1.3"
        print "                 Feedback/Bugs: sick.n3ss416@gmail.com"
        print "                 Blog: http://sickness.tor.hu\n"
        
def menu_exploit():
	
	header()
	print "			Section: EXPLOIT TOOLS\n"
        print " [>] 1. Metasploit Framework."
        print " [>] 2. Exploit-db."
        print " [>] 3. SET - Social Engineering Toolkit."
	print " [>] 4. Update all."
        print " [>] 5. Back."
        print "\n"
        
        try:
		choice = raw_input(" [>] Enter your choice: ")
	except KeyboardInterrupt:
		print "\n [>] Exiting!\n"
		sleep(1)
		sys.exit()
	
	if len(choice) > 3:
		tryharder()
		menu_exploit()
	elif choice == "1":
		try:
			msf()
			menu_exploit()
		except KeyboardInterrupt:
			print "\n [>] Exiting!\n"
			sleep(1)
			sys.exit()
	elif choice == "2":
		try:
			exploit_db()
			menu_exploit()
		except KeyboardInterrupt:
			print "\n [>] Exiting!\n"
			sleep(1)
			sys.exit()
	elif choice == "3":
		try:
			s_e_t()
			menu_exploit()
		except KeyboardInterrupt:
			print "\n [>] Exiting!\n"
			sleep(1)
			sys.exit()
	elif choice == "4":
		try:
			msf()
			exploit_db()
			s_e_t()
			menu_exploit()
		except KeyboardInterrupt:
			print "\n [>] Exiting!\n"
			sleep(1)
			sys.exit()
	elif choice == "5":
		try:
			menu_main()
		except KeyboardInterrupt:
			print "\n [>] Exiting!\n"
			sleep(1)
			sys.exit()
	else:
		tryharder()
		menu_exploit()
		
def menu_wireless():

	header()
        print "                        Section: WIRELESS & TELEPHONY\n"
        print " [>] 1. Aircrack-ng and Airdrop."
        print " [>] 2. WarVox."
        print " [>] 3. Giskismet."
        print " [>] 4. Update all."
        print " [>] 5. Back."
	print "\n"
        
        try:
		choice = raw_input(" [>] Enter your choice: ")
	except KeyboardInterrupt:
		print "\n [>] Exiting!\n"
		sleep(1)
		sys.exit()
	
	if len(choice) > 3:
		tryharder()
		menu_wireless()
	elif choice == "1":
		try:
			aircrack()
			menu_wireless()
		except KeyboardInterrupt:
			print "\n [>] Exiting!\n"
			sleep(1)
			sys.exit()
	elif choice == "2":
		try:
			warvox()
			menu_wireless()
		except KeyboardInterrupt:
			print "\n [>] Exiting!\n"
			sleep(1)
			sys.exit()
	elif choice == "3":
		try:
			giskismet()
			menu_wireless()
		except KeyboardInterrupt:
			print "\n [>] Exiting!\n"
			sleep(1)
			sys.exit()
	elif choice == "4":
		try:
			aircrack()
			warvox()
			giskismet()
			menu_wireless()
		except KeyboardInterrupt:
			print "\n [>] Exiting!\n"
			sleep(1)
			sys.exit()
	elif choice == "5":
		try:
			menu_main()
		except KeyboardInterrupt:
			print "\n [>] Exiting!\n"
			sleep(1)
			sys.exit()
	else:
		tryharder()
		menu_wireless()

def menu_web_db():

	header()
        print "                        Section: WEB & DATABASE\n"
        print " [>] 1. W3AF."
        print " [>] 2. Nikto."
	print " [>] 3. Fimap."
        print " [>] 4. Update all."
        print " [>] 5. Back."
        print "\n"

        try:
		choice = raw_input(" [>] Enter your choice: ")
	except KeyboardInterrupt:
		print "\n [>] Exiting!\n"
		sleep(1)
		sys.exit()
	
	if len(choice) > 3:
		tryharder()
		menu_web_db()
	elif choice == "1":
		try:
			w3af()
			menu_web_db()
		except KeyboardInterrupt:
			print "\n [>] Exiting!\n"
			sleep(1)
			sys.exit()
	elif choice == "2":
		try:
			nikto()
			menu_web_db()
		except KeyboardInterrupt:
			print "\n [>] Exiting!\n"
			sleep(1)
			sys.exit()
	elif choice == "3":
		try:
			fimap()
			menu_web_db()
		except KeyboardInterrupt:
			print "\n [>] Exiting!\n"
			sleep(1)
			sys.exit()
	elif choice == "4":
		try:
			w3af()
			nikto()
			fimap()
			menu_web_db()
		except KeyboardInterrupt:
			print "\n [>] Exiting!\n"
			sleep(1)
			sys.exit()
	elif choice == "5":
		try:
			menu_main()
		except KeyboardInterrupt:
			print "\n [>] Exiting!\n"
			sleep(1)
			sys.exit()
	else:
		tryharder()
		menu_web_db()

def menu_other():

	header()
	print "                        Section: OTHER\n"
	print " [>] 1. OpenVAS."
	print " [>] 2. Update all."
	print " [>] 3. Back."
	print "\n"

        try:
		choice = raw_input(" [>] Enter your choice: ")
	except KeyboardInterrupt:
		print "\n [>] Exiting!\n"
		sleep(1)
		sys.exit()
	
	if len(choice) > 3:
		tryharder()
		menu_other()
	elif choice == "1":
		try:
			openvas()
			menu_other()
		except KeyboardInterrupt:
			print "\n [>] Exiting!\n"
			sleep(1)
			sys.exit()
	elif choice == "2":
		try:
			#nmap()
			openvas()
			menu_other()
		except KeyboardInterrupt:
			print "\n [>] Exiting!\n"
			sleep(1)
			sys.exit()
	elif choice == "3":
		try:
			menu_main()
		except KeyboardInterrupt:
			print "\n [>] Exiting!\n"
			sleep(1)
			sys.exit()
	else:
		tryharder()
		menu_other()

def menu_optional():

	header()
        print "                        Section: OPTIONAL\n"
	print " [>] 1. FastTrack."
	print " [>] 2. Pyrit."
	print " [>] 3. SSLStrip."
	print " [>] 4. SickFuzz."
	print " [>] 5. Wireshark."
	print " [>] 6. Update all."
	print " [>] 7. Back."
	print "\n"

        try:
		choice = raw_input(" [>] Enter your choice: ")
	except KeyboardInterrupt:
		print "\n [>] Exiting!\n"
		sleep(1)
		sys.exit()
	
	if len(choice) > 3:
		tryharder()
		menu_optional()
	elif choice == "1":
		try:
			fasttrack()
			menu_optional()
		except KeyboardInterrupt:
			print "\n [>] Exiting!\n"
			sleep(1)
			sys.exit()
	elif choice == "2":
		try:
			pyrit()
			menu_optional()
		except KeyboardInterrupt:
			print "\n [>] Exiting!\n"
			sleep(1)
			sys.exit()
	elif choice == "3":
		try:
			sslstrip()
			menu_optional()
		except KeyboardInterrupt:
			print "\n [>] Exiting!\n"
			sleep(1)
			sys.exit()
	elif choice == "4":
		try:
			sickfuzz()
			menu_optional()
		except KeyboardInterrupt:
			print "\n [>] Exiting!\n"
			sleep(1)
			sys.exit()
	elif choice == "5":
		try:
			wireshark()
			menu_optional()
		except KeyboardInterrupt:
			print "\n [>] Exiting!\n"
			sleep(1)
			sys.exit()
	elif choice == "6":
		try:
			sickfuzz()
			wireshark()
			fasttrack()
			pyrit()
			menu_optional()
		except KeyboardInterrupt:
			print "\n [>] Exiting!\n"
			sleep(1)
			sys.exit()
	elif choice == "7":
		try:
			menu_main()
		except KeyboardInterrupt:
			print "\n [>] Exiting!\n"
			sleep(1)
			sys.exit()
	else:
		tryharder()
		menu_optional()

def menu_main():

	header()
	print "                        Section: MAIN\n"
	print " [>] 1.  Update and clean Backtrack."
	print " [>] 2.  Exploit tools."
	print " [>] 3.  Wireless & Telephony."
	print " [>] 4.  Web & Database."
	print " [>] 5.  Others."
	print " [>] 6.  Optional."
	print " [>] 7.  Update all."
	print " [>] 8.  Update script."
	print " [>] 9.  Changelog."
 	print " [>] 10. Exit."
	print "\n"

        try:
		choice = raw_input(" [>] Enter your choice: ")
	except KeyboardInterrupt:
		print "\n [>] Exiting!\n"
		sleep(1)
		sys.exit()
	
	if len(choice) > 3:
		tryharder()
		menu_main()
	elif choice == "1":
		try:
			backtrack_update()
			menu_main()
		except KeyboardInterrupt:
			print "\n [>] Exiting!\n"
			sleep(1)
			sys.exit()
	elif choice == "2":
		menu_exploit()
	elif choice == "3":
		menu_wireless()
	elif choice == "4":
		menu_web_db()
	elif choice == "5":
		menu_other()
	elif choice == "6":
		menu_optional()
	elif choice == "7":
		try:
			backtrack_update()
			exploit_db()
			s_e_t()
			warvox()
			aircrack()
			giskismet()
			msf()
			openvas()
			w3af()
			nikto()
			fimap()
			#nmap()
			menu_main()
		except KeyboardInterrupt:
			print "\n [>] Exiting!\n"
			sleep(1)
			sys.exit()
	elif choice == "8":
		try:
			update()
		except KeyboardInterrupt:
			print "\n [>] Exiting!\n"
			sleep(1)
			sys.exit()
	elif choice == "9":
		try:
			changelog()
		except KeyboardInterrupt:
			print "\n [>] Exiting!\n"
			sleep(1)
			sys.exit()
	elif choice == "10":
		print "\n [>] Exiting!\n"
		sleep(1)
		sys.exit()
	else:
		tryharder()
		menu_main()
internet_check()
menu_main()

