๐ 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
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