π 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