πŸ” Encode File Using PowerShell

Let’s learn how to Base64-encode a file in PowerShell, transfer it manually (like over SSH or copy-paste), and decode it on Linux.

πŸ” Encode File Using PowerShell & Transfer via Base64

Sometimes, a classic copy-paste βœ‚οΈ method is all you need to transfer files β€” especially when network transfer is tricky! Let’s learn how to Base64-encode a file in PowerShell, transfer it manually (like over SSH or copy-paste), and decode it on Linux. πŸ§ πŸ’‘


πŸ’» Step 1: Encode File with PowerShell

We’ll use PowerShell’s Get-Content and Convert classes to turn our file into a Base64 string.

PS C:\htb> [Convert]::ToBase64String((Get-Content -Path "C:\Windows\System32\drivers\etc\hosts" -Encoding Byte))

🧾 Output: You'll get a long Base64 string. Copy and paste it somewhere safe (like Notepad or your terminal window).


πŸ§ͺ Step 2: Confirm File Integrity with MD5

Let’s generate an MD5 hash to later confirm we’ve transferred the file correctly:

PS C:\htb> Get-FileHash "C:\Windows\System32\drivers\etc\hosts" -Algorithm MD5 | Select Hash

βœ… Example output:

Hash
----
3688374325B992DEF12793500307566D

🐧 Step 3: Decode on Linux

On your Pwnbox or attack host, paste the Base64 string and decode it:

echo "<base64-string>" | base64 -d > hosts

πŸ“Œ Replace <base64-string> with the long Base64 string you copied earlier.


πŸ” Step 4: Verify Integrity with md5sum

Let’s make sure it’s exactly the same file πŸ”

md5sum hosts

βœ… You should get:

3688374325b992def12793500307566d  hosts

Boom! πŸŽ‰ File successfully transferred and verified. No network shenanigans required!


Last updated