๐Ÿ” 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