Cleans up setup.py logic, better supports Mac filesystem restrictions.

This commit is contained in:
Brigham Toskin 2018-01-31 12:06:42 -08:00
parent e3a3a142be
commit 8cd739cc33

View file

@ -3,35 +3,66 @@
#
# Python installer
#
import subprocess
import sys
import os
import platform
import shutil
import subprocess
import sys
# if nix then run installer
if platform.system() == "Linux":
# give installer a null value
installer = False
# Check user ID
if os.getuid() != 0:
print("Are you root? Please execute as root")
exit()
## pre-install sanity checks ##
try:
# if our command option is true then install stuff
if sys.argv[1] == "install":
installer = True
# if index is out of range then flag options
except IndexError:
print("** SET Dependency Installer **")
# if our command option is true then install stuff
if len(sys.argv) != 2 or sys.argv[1] != "install":
print("** SET Installer **")
print("** Written by: Dave Kennedy (ReL1K) **")
print("** Visit: https://www.trustedsec.com **")
print("\nTo install: setup.py install")
print("\nTo install, run: `# setup.py install'")
exit()
# if user specified install then lets to the installation
if installer is True:
platformOS = platform.system()
if platformOS not in ["Linux", "Darwin"]:
print("[!] Sorry this installer is not designed for %s (only Linux and Mac)"
". Please install the Python dependencies manually." % platformOS)
exit()
# Check user ID
if os.getuid() != 0:
print("** SET Installer **")
print("[!] Please execute as root: `$ sudo python setup.py install'")
exit()
## SET installation ##
# do install of SET itself
def install(prefix):
destdir = "%s/share/setoolkit" % prefix
bindir = "%s/bin" % prefix
print("[*] Copying setoolkit into the %s directory..." % destdir)
subprocess.Popen("cp -rf . %s" % destdir, shell=True).wait()
print("[*] Installing setoolkit runner to %s..." % bindir)
subprocess.Popen("echo \#!/bin/bash > %s/setoolkit" % bindir, shell=True).wait()
subprocess.Popen("echo cd {0} >> {1}/setoolkit".format(destdir, bindir), shell=True).wait()
subprocess.Popen("echo exec python setoolkit $@ >> %s/setoolkit" % bindir, shell=True).wait()
subprocess.Popen("chmod +x %s/setoolkit" % bindir, shell=True).wait()
print("[*] Installing setoolkit updater to %s..." % bindir)
subprocess.Popen("cp {0}/seupdate {1}/".format(destdir, bindir), shell=True).wait()
subprocess.Popen("chmod +x %s/seupdate" % bindir, shell=True).wait()
if not os.path.isdir("/etc/setoolkit/"):
print("[*] Creating setoolkit config dir /etc/setoolkit./..")
os.makedirs("/etc/setoolkit/")
if not os.path.isfile("/etc/setoolkit/set.config"):
print("[*] Installing default setoolkit config to /etc/setoolkit./..")
shutil.copyfile("src/core/config.baseline", "/etc/setoolkit/set.config")
print("[*] We are now finished! To run SET, type `setoolkit'...")
# if linux then run installer
if platformOS == "Linux":
print("[*] Installing dependencies...")
# if we trigger on sources.list then we know its ubuntu
if os.path.isfile("/etc/apt/sources.list"):
@ -72,20 +103,15 @@ if platform.system() == "Linux":
print("[!] Install GIT and run the installer again.")
sys.exit()
print("[*] Copying SET into the /usr/share/setoolkit directory...")
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("chmod +x /usr/bin/setoolkit", shell=True).wait()
print("[*] We are now finished! To run SET, type setoolkit...")
try:
install(prefix="/usr")
except Exception as e:
print("[!] Error installing setoolkit", e)
if platform.system() == 'Darwin':
if platformOS == 'Darwin':
print("[*] Installing dependencies...")
subprocess.Popen("easy_install pexpect pycrypto pyopenssl pefile", shell=True).wait()
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.")
try:
install(prefix="/usr/local")
except Exception as e:
print("[!] Error installing setoolkit", e)