PEP8 and python3 changes for root files

This commit is contained in:
Ryan Jarvis 2016-07-28 13:19:04 -07:00
parent 3089d919ec
commit 7f1bba07b9
5 changed files with 137 additions and 142 deletions

View file

@ -1,4 +1,5 @@
#!/usr/bin/env python
# coding=utf-8
import sys
import os
@ -71,50 +72,54 @@ if os.path.isfile(filename):
try:
print("[*] Spawning SET in a threaded process...")
child = pexpect.spawn("python setoolkit")
fileopen = open(filename, "r")
for line in fileopen:
line = line.rstrip()
# if we just use enter send default
if line == "":
line = "default"
with open(filename) as fileopen:
for line in fileopen:
line = line.rstrip()
# if we just use enter send default
if line == "":
line = "default"
match1 = re.search("OMGPASSWORDHERE", line)
if match1:
line = line.replace("OMGPASSWORDHERE", "")
password = True
match1 = re.search("OMGPASSWORDHERE", line)
if match1:
line = line.replace("OMGPASSWORDHERE", "")
password = True
if password is False:
print("[*] Sending command {0} to the interface...".format(line))
if password is True:
print("[*] Sending command [**********] (password masked) to the interface...")
password = False
if password is False:
print("[*] Sending command {0} to the interface...".format(line))
if password is True:
print("[*] Sending command [**********] (password masked) to the interface...")
password = False
if line == "default":
line = ""
if line == "default":
line = ""
if line == "CONTROL-C-HERE":
try:
print("[*] This may take a few seconds while SET catches up...")
child.expect("Next line of the body:")
time.sleep(2)
child.sendline("\n")
child.sendcontrol('c')
if line == "CONTROL-C-HERE":
try:
print("[*] This may take a few seconds while SET catches up...")
child.expect("Next line of the body:")
time.sleep(2)
child.sendline("\n")
child.sendcontrol('c')
# if the user is using pexpect < 2.3
except AttributeError:
print("[-] Error: You are running pexpect < 2.3 which is needed for this function")
choice = input("Would you like to install it now yes or no: ")
if choice == "yes" or choice == "y":
subprocess.Popen(
"wget http://sourceforge.net/projects/pexpect/files/pexpect/Release%202.3/pexpect-2.3.tar.gz;tar -zxvf pexpect-2.3.tar.gz;cd pexpect-2.3;python setup.py install;cd ..;rm -rf pexpect-2*", shell=True).wait()
try:
reload(pexpect)
child.sendcontrol('c')
except:
print("[*] Relaunch the Social-Engineer Toolkit for changes to apply.")
sys.exit()
if line != "CONTROL-C-HERE":
child.sendline(line)
# if the user is using pexpect < 2.3
except AttributeError:
print("[-] Error: You are running pexpect < 2.3 which is needed for this function")
choice = input("Would you like to install it now yes or no: ")
if choice == "yes" or choice == "y":
subprocess.Popen("wget http://sourceforge.net/projects/pexpect/files/pexpect/Release%202.3/pexpect-2.3.tar.gz;"
"tar -zxvf pexpect-2.3.tar.gz;"
"cd pexpect-2.3;"
"python setup.py install;"
"cd ..;"
"rm -rf pexpect-2*", shell=True).wait()
try:
reload(pexpect)
child.sendcontrol('c')
except:
print("[*] Relaunch the Social-Engineer Toolkit for changes to apply.")
sys.exit()
if line != "CONTROL-C-HERE":
child.sendline(line)
print("[*] Finished sending commands, interacting with the interface..")
child.interact()
@ -130,4 +135,4 @@ if os.path.isfile(filename):
# handle everything else
except Exception as e:
print("[*] Something went wrong, printing error: ", e)
print("[*] Something went wrong, printing error: {}".format(e))

36
seproxy
View file

@ -7,6 +7,8 @@
import sys
import getpass
import os
import subprocess
import re
import src.core.setcore as core
@ -26,42 +28,34 @@ if operating_system == "posix":
definepath = os.getcwd()
print("\n[*] Welcome to the SET-Proxy Configuration Utility")
print("\nEnter the proxy setting informatiom below.\n\nExample: http://10.3.1.1:8080\n")
print("\nEnter the proxy setting information below.\n\nExample: http://10.3.1.1:8080\n")
try:
proxy = input("Enter the proxy server: ")
username = input(
"Enter the username for the proxy (hit enter for none): ")
password = getpass.getpass(
"Enter the password for the proxy (hit enter for none): ")
username = input("Enter the username for the proxy (hit enter for none): ")
password = getpass.getpass("Enter the password for the proxy (hit enter for none): ")
except KeyboardInterrupt:
print("\n[!] Exiting the Social-Engineer Toolkit.")
sys.exit()
if username != "":
proxy_string = "export http_proxy='http://%s:%s@%s'" % (
username, password, proxy)
proxy_string = "export http_proxy='http://{}:{}@{}'".format(username, password, proxy)
else:
proxy_string = "export http_proxy='http://{}'".format(proxy)
if username == "":
proxy_string = "export http_proxy='http://%s'" % (proxy)
filewrite = open(core.setdir + "/proxy.config", "w")
filewrite.write(proxy_string)
filewrite.close()
from src.core.set import *
with open(os.path.join(core.setdir, "/proxy.config"), "w") as filewrite:
filewrite.write(proxy_string)
def kill_proc(port, flag):
proc = subprocess.Popen("netstat -antp | grep '%s'" % (port), shell=True, stdout=subprocess.PIPE)
proc = subprocess.Popen("netstat -antp | grep '{}'".format(port), shell=True, stdout=subprocess.PIPE)
stdout_value = proc.communicate()[0]
a = re.search("\d+/%s" % (flag), stdout_value)
a = re.search("\d+/{}".format(flag), stdout_value)
if a:
b = a.group()
b = b.replace("/%s" % (flag), "")
subprocess.Popen("kill -9 %s 1> /dev/null 2> /dev/null" %
(b), shell=True).wait()
b = b.replace("/{}".format(flag), "")
subprocess.Popen("kill -9 {} 1> /dev/null 2> /dev/null".format(b), shell=True).wait()
# cleans up stale processes from SET
try:
@ -72,7 +66,7 @@ if operating_system == "posix":
# handle errors
except Exception as error:
log(error)
core.log(error)
else:
print("[!] Sorry, this only works on posix (nix) based systems and is not compatible with this operating system.")

102
setoolkit
View file

@ -1,4 +1,5 @@
#!/usr/bin/env python
# coding=utf-8
import os
import re
import shutil
@ -37,7 +38,8 @@ if not os.path.isfile("/etc/setoolkit/set.config"):
shutil.copyfile("src/core/config.baseline", "/etc/setoolkit/set.config")
# here we check to ensure we have the latest version
data = open("/etc/setoolkit/set.config", "r").read()
with open("/etc/setoolkit/set.config") as fileopen:
data = fileopen.read()
if "CONFIG_VERSION=7.2" not in data:
print("[*] Overwriting old config for updates to SET. Backing up your old one in /etc/setoolkit/")
shutil.move("/etc/setoolkit/set.config", "/etc/setoolkit/set.config.bak")
@ -48,7 +50,8 @@ import src.core.setcore as core
from src.core.menu import text
from src.core.update_config import update_config
if os.path.isfile(core.setdir + "/version.lock"): os.remove(core.setdir + "/version.lock")
if os.path.isfile(os.path.join(core.setdir, "version.lock")):
os.remove(os.path.join(core.setdir, "version.lock"))
# check directory and make it
if not os.path.isdir("src/logs/"):
@ -57,9 +60,8 @@ if not os.path.isdir("src/logs/"):
# check set logfile
if not os.path.isfile("src/logs/set_logfile.log"):
# create new log
filewrite = open("src/logs/set_logfile.log", "w")
filewrite.write("")
filewrite.close()
with open("src/logs/set_logfile.log", "w") as filewrite:
filewrite.write("")
# check which operating system
operating_system = core.check_os()
@ -74,15 +76,12 @@ if operating_system == "posix":
if not os.path.isdir(userdir):
os.makedirs(userdir)
if not os.path.isdir(core.setdir + "/reports/"):
os.makedirs(core.setdir + "/reports")
if not os.path.isdir(os.path.join(core.setdir, "reports")):
os.makedirs(os.path.join(core.setdir, "reports"))
# check to see if we have python-pycrypto
try:
from Crypto.Cipher import AES
except ImportError:
print("[!] The python-pycrypto python module not installed. You will lose the ability to use multi-pyinjector.")
pass
@ -102,9 +101,13 @@ update_config()
# chmod routine
if operating_system == "posix":
# change permissions if nix
subprocess.Popen(
"chmod +x seautomate;chmod +x set-update;chmod +x setup.py;chmod +x set-proxy;chmod +x src/payloads/ratte/ratteserver;chmod +x src/payloads/set_payloads/listener.py",
stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
subprocess.Popen("chmod +x seautomate;"
"chmod +x set-update;"
"chmod +x setup.py;"
"chmod +x set-proxy;"
"chmod +x src/payloads/ratte/ratteserver;"
"chmod +x src/payloads/set_payloads/listener.py",
stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
dns = core.check_config("DNS_SERVER=")
if dns.lower() == "on":
@ -114,8 +117,7 @@ if dns.lower() == "on":
for root, dirs, files in os.walk(core.setdir):
for f in files:
try:
match = re.search(
".svn|entries|all-wcprops|props|text-base|prop-base|tmp", f)
match = re.search(".svn|entries|all-wcprops|props|text-base|prop-base|tmp", f)
if not match:
os.unlink(os.path.join(root, f))
@ -125,8 +127,7 @@ for root, dirs, files in os.walk(core.setdir):
# loop through all the directories
for d in dirs:
try:
match = re.search(
".svn|entries|all-wcprops|props|text-base|prop-base|tmp", d)
match = re.search(".svn|entries|all-wcprops|props|text-base|prop-base|tmp", d)
if not match:
shutil.rmtree(os.path.join(root, d))
except:
@ -135,9 +136,9 @@ for root, dirs, files in os.walk(core.setdir):
# if windows then do some stuff
if operating_system == "posix":
#
# ROOT CHECK
#
#
# ROOT CHECK
#
if os.geteuid() != 0:
print("\n The Social-Engineer Toolkit (SET) - by David Kennedy (ReL1K)")
@ -152,32 +153,38 @@ define_version = core.get_version()
core.cleanup_routine()
# create the set.options routine
filewrite = open(core.setdir + "/set.options", "w")
filewrite.write("{This is the main SET configuration file for all options used in SET}\n")
filewrite.close()
with open(os.path.join(core.setdir, "/set.options"), "w") as filewrite:
filewrite.write("{This is the main SET configuration file for all options used in SET}\n")
try:
# Remove old Signed_Updates
if os.path.isfile(core.setdir + "/Signed_Update.jar"):
os.remove(core.setdir + "/Signed_Update.jar")
if os.path.isfile(os.path.join(core.setdir, "/Signed_Update.jar")):
os.remove(os.path.join(core.setdir, "/Signed_Update.jar"))
# initial user menu
if not os.path.isfile("src/agreement4"):
fileopen = open("readme/LICENSE", "r")
for line in fileopen:
print((line.rstrip()))
with open("readme/LICENSE") as fileopen:
for line in fileopen:
print((line.rstrip()))
print((core.bcolors.RED + """
The Social-Engineer Toolkit is designed purely for good and not evil. If you are planning on using this tool for malicious purposes that are not authorized by the company you are performing assessments for, you are violating the terms of service and license of this toolset. By hitting yes (only one time), you agree to the terms of service and that you will only use this tool for lawful purposes only.""" + core.bcolors.GREEN))
print("{}The Social-Engineer Toolkit is designed purely"
" for good and not evil. If you are planning on "
"using this tool for malicious purposes that are "
"not authorized by the company you are performing "
"assessments for, you are violating the terms of "
"service and license of this toolset. By hitting "
"yes (only one time), you agree to the terms of "
"service and that you will only use this tool for "
"lawful purposes only.{}".format(core.bcolors.RED, core.bcolors.ENDC))
print(core.bcolors.GREEN)
choice = input("\nDo you agree to the terms of service [y/n]: ")
choice += " " # b/c method below
if choice[0].lower() == "y":
filewrite = open("src/agreement4", "w")
filewrite.write("user accepted")
filewrite.close()
with open("src/agreement4", "w") as filewrite:
filewrite.write("user accepted")
print(core.bcolors.ENDC)
else:
print((core.bcolors.ENDC + "[!] Exiting the Social-Engineer Toolkit, have a nice day." + core.bcolors.ENDC))
print(core.bcolors.ENDC + "[!] Exiting the Social-Engineer Toolkit, have a nice day." + core.bcolors.ENDC)
sys.exit()
while True:
@ -192,10 +199,8 @@ The Social-Engineer Toolkit is designed purely for good and not evil. If you are
# funny
if main_menu_choice == "hugs":
core.print_warning(
"Have you given someone a hug today? Remember a hug can change the world.")
pause = input(
"\nPlease give someone a hug then press {return} to continue.")
core.print_warning("Have you given someone a hug today? Remember a hug can change the world.")
pause = input("\nPlease give someone a hug then press {return} to continue.")
# funny2
if main_menu_choice == "freehugs":
@ -204,21 +209,17 @@ The Social-Engineer Toolkit is designed purely for good and not evil. If you are
# funny3
if main_menu_choice == "derbycon":
core.print_warning(
core.bcolors.BOLD + "YAYYYYYYYYYYYYYYYYYYYYYY DerbyCon.\n\nDerbyCon 6.0 'Recharge' -- September 23th - 25th 2016" + core.bcolors.ENDC)
pause = input(
core.bcolors.BOLD + "\nDon't miss it! Sep 23 - Sep 25th! Press {return} to continue." + core.bcolors.ENDC)
core.print_warning(core.bcolors.BOLD + "YAYYYYYYYYYYYYYYYYYYYYYY DerbyCon.\n\nDerbyCon 6.0 'Recharge' -- September 23th - 25th 2016" + core.bcolors.ENDC)
pause = input(core.bcolors.BOLD + "\nDon't miss it! Sep 23 - Sep 25th! Press {return} to continue." + core.bcolors.ENDC)
# rance
if main_menu_choice == "rance":
core.print_warning(
core.bcolors.BOLD + "We miss you buddy. David Jones (Rance) changed a lot of us and you'll always be apart of our lives (and SET). Fuck Cancer." + core.bcolors.ENDC)
core.print_warning(core.bcolors.BOLD + "We miss you buddy. David Jones (Rance) changed a lot of us and you'll always be apart of our lives (and SET). Fuck Cancer." + core.bcolors.ENDC)
pause = input("Press {return} to continue.")
# cavs
if main_menu_choice == "cavs":
core.print_warning(
core.bcolors.BOLD + "2015-2016 CHAMPS BABY!!! C l e e e e e e v eeee l a a n n d d d d d d d d d d d " + core.bcolors.ENDC)
core.print_warning(core.bcolors.BOLD + "2015-2016 CHAMPS BABY!!! C l e e e e e e v eeee l a a n n d d d d d d d d d d d " + core.bcolors.ENDC)
pause = input("Press {return} to continue.")
# quit out
@ -268,13 +269,14 @@ The Social-Engineer Toolkit is designed purely for good and not evil. If you are
# handle keyboard interrupts
except KeyboardInterrupt:
print(("\n\nThank you for " + core.bcolors.RED + "shopping" + core.bcolors.ENDC +
" with the Social-Engineer Toolkit.\n\nHack the Gibson...and remember...hugs are worth more than handshakes.\n"))
print(("\n\nThank you for {}shopping{} with the Social-Engineer Toolkit."
"\n\nHack the Gibson...and remember...hugs are worth more "
"than handshakes.\n".format(core.bcolors.RED, core.bcolors.ENDC)))
# handle exceptions
except Exception as error:
log(error)
print ("\n\n[!] Something went wrong, printing the error: "+ str(error))
core.log(error)
print("\n\n[!] Something went wrong, printing the error: " + str(error))
# cleanup routine
core.cleanup_routine()

View file

@ -1,4 +1,5 @@
#!/usr/bin/env python
# coding=utf-8
#
# Python installer
#
@ -36,19 +37,19 @@ if platform.system() == "Linux":
if os.path.isfile("/etc/apt/sources.list"):
# force install of debian packages
subprocess.Popen(
"apt-get --force-yes -y install git apache2 python-requests libapache2-mod-php python-pymssql build-essential python-pexpect python-pefile python-crypto python-openssl", shell=True).wait()
subprocess.Popen("apt-get --force-yes -y install "
"git apache2 python-requests libapache2-mod-php "
"python-pymssql build-essential python-pexpect "
"python-pefile python-crypto python-openssl", shell=True).wait()
# If pacman.conf exists, we have a Arch based system
elif os.path.isfile("/etc/pacman.conf"):
subprocess.Popen(
"pacman -S --noconfirm --needed git python2 python2-beautifulsoup3 python2-pexpect python2-crypto", shell=True).wait()
subprocess.Popen(
"wget https://pefile.googlecode.com/files/pefile-1.2.10-139.tar.gz", shell=True).wait()
subprocess.Popen(
"tar xvfz pefile-1.2.10-139.tar.gz", shell=True).wait()
subprocess.Popen(
"chmod a+x pefile-1.2.10-139/setup.py", shell=True).wait()
subprocess.Popen("pacman -S --noconfirm --needed git python2 "
"python2-beautifulsoup3 python2-pexpect python2-crypto", shell=True).wait()
subprocess.Popen("wget https://pefile.googlecode.com/files/pefile-1.2.10-139.tar.gz", shell=True).wait()
subprocess.Popen("tar xvfz pefile-1.2.10-139.tar.gz", shell=True).wait()
subprocess.Popen("chmod a+x pefile-1.2.10-139/setup.py", shell=True).wait()
subprocess.Popen("rm -rf pefile-1.2.10-139*", shell=True).wait()
# if dnf.conf is there, we are dealing with a >= fedora 22 - added thanks to whoismath pr
@ -58,14 +59,12 @@ if platform.system() == "Linux":
# if sources.list or pacman.conf is not available then we're running
# something offset
else:
print(
"[!] You're not running a Debian, Fedora or Arch variant. Installer not finished for this type of Linux distro.")
print("[!] You're not running a Debian, Fedora or Arch variant. Installer not finished for this type of Linux distro.")
print("[!] Install git, python-pexpect, python-crypto, python-openssl, python-pefile manually for all of SET dependancies.")
sys.exit()
if os.path.isdir("/usr/share/setoolkit"):
print(
"[!] SET is already installed in /usr/share/setoolkit. Remove and start again.")
print("[!] SET is already installed in /usr/share/setoolkit. Remove and start again.")
sys.exit()
if not os.path.isfile("/usr/bin/git"):
@ -77,14 +76,10 @@ if platform.system() == "Linux":
cwdpath = os.getcwd()
subprocess.Popen("cd ..;cp -rf %s /usr/share/setoolkit" % cwdpath, shell=True).wait()
print("[*] Installing setoolkit installer to /usr/bin/setoolkit...")
subprocess.Popen(
"echo #!/bin/bash > /usr/bin/setoolkit", shell=True).wait()
subprocess.Popen(
"echo cd /usr/share/setoolkit >> /usr/bin/setoolkit", shell=True).wait()
subprocess.Popen(
"echo exec python2 setoolkit $@ >> /usr/bin/setoolkit", shell=True).wait()
subprocess.Popen(
"cp /usr/share/setoolkit/seupdate /usr/bin/", shell=True).wait()
subprocess.Popen("echo #!/bin/bash > /usr/bin/setoolkit", shell=True).wait()
subprocess.Popen("echo cd /usr/share/setoolkit >> /usr/bin/setoolkit", shell=True).wait()
subprocess.Popen("echo exec python2 setoolkit $@ >> /usr/bin/setoolkit", shell=True).wait()
subprocess.Popen("cp /usr/share/setoolkit/seupdate /usr/bin/", shell=True).wait()
subprocess.Popen("chmod +x /usr/bin/setoolkit", shell=True).wait()
#print("[*] Note you will manually need to install Core Security 'Impacket'")
#print("[*] Download link: http://corelabs.coresecurity.com/index.php?module=Wiki&action=view&type=tool&name=Impacket")
@ -93,9 +88,8 @@ if platform.system() == "Linux":
print("[*] We are now finished! To run SET, type setoolkit...")
if platform.system() == 'Darwin':
subprocess.Popen(
"easy_install pexpect pycrypto pyopenssl pefile", shell=True).wait()
subprocess.Popen("easy_install pexpect pycrypto pyopenssl pefile", shell=True).wait()
if platform.system() != "Linux":
if platform.system() != "Darwin":
print("[!] Sorry this installer is not designed for any other system other than Linux and Mac. Please install the Python dependencies manually.")
if platform.system() not in ["Linux", "Darwin"]:
print("[!] Sorry this installer is not designed for any other system other "
"than Linux and Mac. Please install the Python dependencies manually.")

View file

@ -1,11 +1,11 @@
#!/usr/bin/env python
# coding=utf-8
#
# simple git update for set pulling from core modules
#
import os
import sys
import src.core.setcore as core
# check where we are and load default directory
@ -14,17 +14,17 @@ if os.path.isdir("/usr/share/setoolkit"):
os.chdir("/usr/share/setoolkit")
sys.path.append("/usr/share/setoolkit")
import src.core.setcore as core
# if we can't see our config then something didn't go good..
if not os.path.isfile("/etc/setoolkit/set.config"):
core.print_error("Cannot locate SET executable. Try running from the local directory.")
core.print_error("If this does not work, please run the setup.py install file.")
sys.exit()
from src.core.setcore import *
try:
# pull update set from the core libraries
update_set()
core.update_set()
# except keyboard interrupts
except KeyboardInterrupt: