Skip to content

Commit

Permalink
Fixes for path handling, especially user config dir.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brigham Toskin committed Feb 1, 2018
1 parent f5b2f4c commit 0672c27
Show file tree
Hide file tree
Showing 19 changed files with 153 additions and 152 deletions.
2 changes: 1 addition & 1 deletion modules/ratte_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
pass

definepath = os.getcwd()
setdir = core.setdir()
setdir = core.userconfigpath

MAIN = " RATTE Java Applet Attack (Remote Administration Tool Tommy Edition) - Read the readme/RATTE_README.txt first"

Expand Down
4 changes: 2 additions & 2 deletions modules/ratte_only_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def prepare_ratte(ipaddr, ratteport, persistent, customexe):
############
# PATCH Server IP into RATTE
############
with open(os.path.join(core.setdir + "ratteM.exe"), "wb") as filewrite:
with open(os.path.join(core.userconfigpath, "ratteM.exe"), "wb") as filewrite:

host = (len(ipaddr) + 1) * "X"
r_port = (len(str(ratteport)) + 1) * "Y"
Expand Down Expand Up @@ -126,7 +126,7 @@ def main():
############
prepare_ratte(ipaddr, ratteport, persistent, customexe)

core.print_status("Payload has been exported to %s" % os.path.join(core.setdir + "ratteM.exe"))
core.print_status("Payload has been exported to %s" % os.path.join(core.userconfigpath, "ratteM.exe"))

###################
# start ratteserver
Expand Down
2 changes: 1 addition & 1 deletion seproxy
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ if operating_system == "posix":
else:
proxy_string = "export http_proxy='http://{0}'".format(proxy)

with open(os.path.join(core.setdir + "/proxy.config"), "w") as filewrite:
with open(os.path.join(core.userconfigpath, "/proxy.config"), "w") as filewrite:
filewrite.write(proxy_string)

def kill_proc(port, flag):
Expand Down
21 changes: 11 additions & 10 deletions setoolkit
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ import src.core.setcore as core
from src.core.menu import text
from src.core.update_config import update_config

if os.path.isfile(os.path.join(core.setdir, "version.lock")):
os.remove(os.path.join(core.setdir, "version.lock"))

if os.path.isfile(os.path.join(core.userconfigpath, "version.lock")):
os.remove(os.path.join(core.userconfigpath, "version.lock"))

# check directory and make it
if not os.path.isdir("src/logs/"):
Expand All @@ -69,16 +70,16 @@ operating_system = core.check_os()

# use ~/.set
if operating_system == "posix":
if not os.path.isdir(core.setdir):
if not os.path.isdir(core.userconfigpath):
# create the set variables
os.makedirs(core.setdir)
os.makedirs(core.userconfigpath)
# if for some reason it failed to pull the path
userdir = os.path.join(os.path.expanduser('~'), '.set')
if not os.path.isdir(userdir):
os.makedirs(userdir)

if not os.path.isdir(os.path.join(core.setdir, "reports")):
os.makedirs(os.path.join(core.setdir, "reports"))
if not os.path.isdir(os.path.join(core.userconfigpath, "reports")):
os.makedirs(os.path.join(core.userconfigpath, "reports"))

# check to see if we have python-pycrypto
try:
Expand Down Expand Up @@ -115,7 +116,7 @@ if dns.lower() == "on":
core.start_dns()

# remove old files
for root, dirs, files in os.walk(core.setdir):
for root, dirs, files in os.walk(core.userconfigpath):
for f in files:
try:
match = re.search(".svn|entries|all-wcprops|props|text-base|prop-base|tmp", f)
Expand Down Expand Up @@ -154,13 +155,13 @@ define_version = core.get_version()
core.cleanup_routine()

# create the set.options routine
with open(os.path.join(core.setdir, "/set.options"), "w") as filewrite:
with open(os.path.join(core.userconfigpath, "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(os.path.join(core.setdir, "/Signed_Update.jar")):
os.remove(os.path.join(core.setdir, "/Signed_Update.jar"))
if os.path.isfile(os.path.join(core.userconfigpath, "Signed_Update.jar")):
os.remove(os.path.join(core.userconfigpath, "Signed_Update.jar"))

# initial user menu
if not os.path.isfile("src/agreement4"):
Expand Down
20 changes: 10 additions & 10 deletions src/autorun/autolaunch.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
definepath = os.getcwd()
msf_path = core.meta_path()
me = core.mod_name()
autorun_path = os.path.join(core.setdir, "autorun")
autorun_path = os.path.join(core.userconfigpath, "autorun")

trigger = 0

Expand All @@ -21,23 +21,23 @@
subprocess.Popen("rm -rf {0} 1> /dev/null 2> /dev/null;"
"mkdir {0} 1> /dev/null 2> /dev/null;"
"cp {1} {2} 1> /dev/null 2> /dev/null".format(autorun_path,
os.path.join(core.setdir, "payload.exe"),
os.path.join(core.userconfigpath, "payload.exe"),
os.path.join(autorun_path, "program.exe")),
shell=True).wait()

if os.path.isfile(os.path.join(core.setdir, "fileformat.file")):
if os.path.isfile(os.path.join(core.userconfigpath, "fileformat.file")):
trigger = 2
subprocess.Popen("rm -rf {0} 1> /dev/null 2> /dev/null;"
"mkdir {0} 1> /dev/null 2> /dev/null;"
"cp {1} {0} 1> /dev/null 2>/dev/null".format(autorun_path,
os.path.join(core.setdir, "template.pdf")),
os.path.join(core.userconfigpath, "template.pdf")),
shell=True).wait()

if os.path.isfile(os.path.join(core.setdir, "/dll/openthis.wab")):
if os.path.isfile(os.path.join(core.userconfigpath, "/dll/openthis.wab")):
subprocess.Popen("rm -rf {0} 1> /dev/null 2> /dev/null;"
"mkdir {0} 1> /dev/null 2> /dev/null;"
"cp {1} {0} 1> /dev/null 2> /dev/null".format(autorun_path,
os.path.join(core.setdir, "/dll/*")),
os.path.join(core.userconfigpath, "/dll/*")),
shell=True).wait()
trigger = 3

Expand Down Expand Up @@ -71,9 +71,9 @@
if choice1.lower() == "yes" or choice1.lower() == "y":
# if we used something to create other than solo.py then write out the
# listener
if not os.path.isfile(os.path.join(core.setdir, "meta_config")):
with open(os.path.join(core.setdir, "meta_config"), 'w') as filewrite, \
open(os.path.join(core.setdir, "payload.options")) as fileopen:
if not os.path.isfile(os.path.join(core.userconfigpath, "meta_config")):
with open(os.path.join(core.userconfigpath, "meta_config"), 'w') as filewrite, \
open(os.path.join(core.userconfigpath, "payload.options")) as fileopen:
for line in fileopen:
line = line.split(" ")
filewrite.write("use multi/handler\n")
Expand All @@ -86,7 +86,7 @@
# create the listener
core.print_status("Launching Metasploit.. This could take a few. Be patient! Or else no shells for you..")
subprocess.Popen("{0} -r {1}".format(os.path.join(msf_path, "msfconsole"),
os.path.join(core.setdir, "meta_config")),
os.path.join(core.userconfigpath, "meta_config")),
shell=True).wait()
else:
core.print_warning("cancelling...")
Expand Down
78 changes: 39 additions & 39 deletions src/core/setcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,11 +463,11 @@ def cleanup_routine():
try:
# restore original Java Applet
shutil.copyfile("%s/src/html/Signed_Update.jar.orig" %
(definepath()), setdir + "/Signed_Update.jar")
(definepath()), userconfigpath + "Signed_Update.jar")
if os.path.isfile("newcert.pem"):
os.remove("newcert.pem")
if os.path.isfile(setdir + "/interfaces"):
os.remove(setdir + "/interfaces")
if os.path.isfile(userconfigpath + "interfaces"):
os.remove(userconfigpath + "interfaces")
if os.path.isfile("src/html/1msf.raw"):
os.remove("src/html/1msf.raw")
if os.path.isfile("src/html/2msf.raw"):
Expand All @@ -476,10 +476,10 @@ def cleanup_routine():
os.remove("msf.exe")
if os.path.isfile("src/html/index.html"):
os.remove("src/html/index.html")
if os.path.isfile(setdir + "/Signed_Update.jar"):
os.remove(setdir + "/Signed_Update.jar")
if os.path.isfile(setdir + "/version.lock"):
os.remove(setdir + "/version.lock")
if os.path.isfile(userconfigpath + "Signed_Update.jar"):
os.remove(userconfigpath + "Signed_Update.jar")
if os.path.isfile(userconfigpath + "version.lock"):
os.remove(userconfigpath + "version.lock")

except:
pass
Expand Down Expand Up @@ -559,19 +559,19 @@ def generate_random_string(low, high):
def site_cloner(website, exportpath, *args):
grab_ipaddress()
ipaddr = grab_ipaddress()
filewrite = open(setdir + "/interface", "w")
filewrite = open(userconfigpath + "interface", "w")
filewrite.write(ipaddr)
filewrite.close()
filewrite = open(setdir + "/ipaddr", "w")
filewrite = open(userconfigpath + "ipaddr", "w")
filewrite.write(ipaddr)
filewrite.close()
filewrite = open(setdir + "/site.template", "w")
filewrite = open(userconfigpath + "site.template", "w")
filewrite.write("URL=" + website)
filewrite.close()
# if we specify a second argument this means we want to use java applet
if args[0] == "java":
# needed to define attack vector
filewrite = open(setdir + "/attack_vector", "w")
filewrite = open(userconfigpath + "attack_vector", "w")
filewrite.write("java")
filewrite.close()
sys.path.append("src/webattack/web_clone")
Expand All @@ -586,7 +586,7 @@ def site_cloner(website, exportpath, *args):

# copy the file to a new folder
print_status("Site has been successfully cloned and is: " + exportpath)
subprocess.Popen("mkdir '%s';cp %s/web_clone/* '%s'" % (exportpath, setdir,
subprocess.Popen("mkdir '%s';cp %s/web_clone/* '%s'" % (exportpath, userconfigpath,
exportpath), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).wait()


Expand Down Expand Up @@ -666,7 +666,7 @@ def java_applet_attack(website, port, directory):
if check_options != 0:

# move the file to the specified directory and filename
subprocess.Popen("cp %s/msf.exe %s/%s" % (setdir, directory, filename),
subprocess.Popen("cp %s/msf.exe %s/%s" % (userconfigpath, directory, filename),
stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).wait()

applet_name = check_options("APPLET_NAME=")
Expand All @@ -675,7 +675,7 @@ def java_applet_attack(website, port, directory):

# lastly we need to copy over the signed applet
subprocess.Popen(
"cp %s/Signed_Update.jar %s/%s" % (setdir, directory, applet_name),
"cp %s/Signed_Update.jar %s/%s" % (userconfigpath, directory, applet_name),
stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).wait()

# start the web server by running it in the background
Expand All @@ -700,41 +700,41 @@ def teensy_pde_generator(attack_method):
if attack_method == "beef":
# specify the filename
filename = open("src/teensy/beef.ino", "r")
filewrite = open(setdir + "/reports/beef.ino", "w")
filewrite = open(userconfigpath + "reports/beef.ino", "w")
teensy_string = (
"Successfully generated Teensy HID Beef Attack Vector under %s/reports/beef.ino" % (setdir))
"Successfully generated Teensy HID Beef Attack Vector under %s/reports/beef.ino" % (userconfigpath))

# if we are doing the attack vector teensy beef
if attack_method == "powershell_down":
# specify the filename
filename = open("src/teensy/powershell_down.ino", "r")
filewrite = open(setdir + "/reports/powershell_down.ino", "w")
filewrite = open(userconfigpath + "reports/powershell_down.ino", "w")
teensy_string = (
"Successfully generated Teensy HID Attack Vector under %s/reports/powershell_down.ino" % (setdir))
"Successfully generated Teensy HID Attack Vector under %s/reports/powershell_down.ino" % (userconfigpath))

# if we are doing the attack vector teensy
if attack_method == "powershell_reverse":
# specify the filename
filename = open("src/teensy/powershell_reverse.ino", "r")
filewrite = open(setdir + "/reports/powershell_reverse.ino", "w")
filewrite = open(userconfigpath + "reports/powershell_reverse.ino", "w")
teensy_string = (
"Successfully generated Teensy HID Attack Vector under %s/reports/powershell_reverse.ino" % (setdir))
"Successfully generated Teensy HID Attack Vector under %s/reports/powershell_reverse.ino" % (userconfigpath))

# if we are doing the attack vector teensy beef
if attack_method == "java_applet":
# specify the filename
filename = open("src/teensy/java_applet.ino", "r")
filewrite = open(setdir + "/reports/java_applet.ino", "w")
filewrite = open(userconfigpath + "reports/java_applet.ino", "w")
teensy_string = (
"Successfully generated Teensy HID Attack Vector under %s/reports/java_applet.ino" % (setdir))
"Successfully generated Teensy HID Attack Vector under %s/reports/java_applet.ino" % (userconfigpath))

# if we are doing the attack vector teensy
if attack_method == "wscript":
# specify the filename
filename = open("src/teensy/wscript.ino", "r")
filewrite = open(setdir + "/reports/wscript.ino", "w")
filewrite = open(userconfigpath + "reports/wscript.ino", "w")
teensy_string = (
"Successfully generated Teensy HID Attack Vector under %s/reports/wscript.ino" % (setdir))
"Successfully generated Teensy HID Attack Vector under %s/reports/wscript.ino" % (userconfigpath))

# All the options share this code except binary2teensy
if attack_method != "binary2teensy":
Expand All @@ -750,7 +750,7 @@ def teensy_pde_generator(attack_method):
# specify the filename
import src.teensy.binary2teensy
teensy_string = (
"Successfully generated Teensy HID Attack Vector under %s/reports/binary2teensy.ino" % (setdir))
"Successfully generated Teensy HID Attack Vector under %s/reports/binary2teensy.ino" % (userconfigpath))

print_status(teensy_string)
#
Expand Down Expand Up @@ -811,26 +811,26 @@ def upx(path_to_file):
"Packing the executable and obfuscating PE file randomly, one moment.")
# packing executable
subprocess.Popen(
"%s -9 -q -o %s/temp.binary %s" % (upx_path, setdir, path_to_file),
"%s -9 -q -o %s/temp.binary %s" % (upx_path, userconfigpath, path_to_file),
stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).wait()
# move it over the old file
subprocess.Popen("mv %s/temp.binary %s" % (setdir, path_to_file),
subprocess.Popen("mv %s/temp.binary %s" % (userconfigpath, path_to_file),
stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).wait()

# random string
random_string = generate_random_string(3, 3).upper()

# 4 upx replace - we replace 4 upx open the file
fileopen = open(path_to_file, "rb")
filewrite = open(setdir + "/temp.binary", "wb")
filewrite = open(userconfigpath + "temp.binary", "wb")

# read the file open for data
data = fileopen.read()
# replace UPX stub makes better evasion for A/V
filewrite.write(data.replace("UPX", random_string, 4))
filewrite.close()
# copy the file over
subprocess.Popen("mv %s/temp.binary %s" % (setdir, path_to_file),
subprocess.Popen("mv %s/temp.binary %s" % (userconfigpath, path_to_file),
stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).wait()
time.sleep(3)

Expand Down Expand Up @@ -873,21 +873,21 @@ def show_banner(define_version, graphic):
version = ""

def pull_version():
if not os.path.isfile(setdir + "/version.lock"):
if not os.path.isfile(userconfigpath + "version.lock"):
try:

url = (
'https://raw.githubusercontent.com/trustedsec/social-engineer-toolkit/master/src/core/set.version')
version = urlopen(url).read().rstrip().decode('utf-8')
filewrite = open(setdir + "/version.lock", "w")
filewrite = open(userconfigpath + "version.lock", "w")
filewrite.write(version)
filewrite.close()

except KeyboardInterrupt:
version = "keyboard interrupt"

else:
version = open(setdir + "/version.lock", "r").read()
version = open(userconfigpath + "version.lock", "r").read()

if cv != version:
if version != "":
Expand Down Expand Up @@ -1414,8 +1414,8 @@ def copyfolder(sourcePath, destPath):
def check_options(option):
# open the directory
trigger = 0
if os.path.isfile(setdir + "/set.options"):
fileopen = open(setdir + "/set.options", "r").readlines()
if os.path.isfile(userconfigpath + "set.options"):
fileopen = open(userconfigpath + "set.options", "r").readlines()
for line in fileopen:
match = re.search(option, line)
if match:
Expand All @@ -1433,21 +1433,21 @@ def check_options(option):

def update_options(option):
# if the file isn't there write a blank file
if not os.path.isfile(setdir + "/set.options"):
filewrite = open(setdir + "/set.options", "w")
if not os.path.isfile(userconfigpath + "set.options"):
filewrite = open(userconfigpath + "set.options", "w")
filewrite.write("")
filewrite.close()

# remove old options
fileopen = open(setdir + "/set.options", "r")
fileopen = open(userconfigpath + "set.options", "r")
old_options = ""
for line in fileopen:
match = re.search(option, line)
if match:
line = ""
old_options = old_options + line
# append to file
filewrite = open(setdir + "/set.options", "w")
filewrite = open(userconfigpath + "set.options", "w")
filewrite.write(old_options + "\n" + option + "\n")
filewrite.close()

Expand Down Expand Up @@ -1771,7 +1771,7 @@ def setdir():
return "src/program_junk/"

# set the main directory for SET
setdir = setdir()
userconfigpath = setdir()

# Copyright (c) 2007 Brandon Sterne
# Licensed under the MIT license.
Expand Down
Loading

0 comments on commit 0672c27

Please sign in to comment.