Windows
POWERSHELL
Base64 Encode & Decode Lin -> Win
Check SSH Key MD5 Hash
md5sum id_rsaEncode SSH Key to Base64
cat id_rsa | base64 -w 0;echo
justimaginethisissomerandomhashbecauseyoudontcareandidontcare=Decoding SSH Key on Windows machine
PS C:\> [IO.File]::WriteAllBytes("C:\Users\Public\id_rsa", [Convert]::FromBase64String("justimaginethisissomerandomhashbecauseyoudontcareandidontcare="))Confirming the MD5 Hashes Match
Get-FileHash C:\Users\Public\id_rsa -Algorithm md5Note: It's not always possible to use this method because cmd.exe has a maximum string length of 8191 characters. And also web shell may error because of this large strings.
Base64 Encode & Decode Win -> Lin
I explained above how to do encoding in Linux and decoding in Powershell, now I'll explain opposite: Encode in Powershell and decode in Linux
Encode File Using Powershell
Decode Base64 String in Linux
Get & Check Hash
Web Downloads
In any version of PowerShell, the System.Net.WebClient class can be used to download a file over HTTP, HTTPS or FTP. The following table describes WebClient methods for downloading data from a resource.
File Download
PowerShell DownloadString - Fileless Method. Fileless attacks work by using some operationg system functions to download the payload and execute it directly. Instead of downloading a PowerShell script to disk, we can run it directly in memory using the Invoke-Expression cmdlet or the alias IEX
Common Errors
Internet Explorer Error
SSL/TLS Untrusted certificate error
PowerShell Web Uploads
PowerShell doesn't have a built-in upload fucntions, so we need to use Invoke-WebRequest. or Invoke-RestMethod. Also we can use uploadserver module for Python, to install it we should use:
Turn On Web Server with Upload
PowerShell Script to Upload a File to Python Upload Server
PowerShell Base64 Web Upload. Convert file to base64 and send it using Invoke-WebRequest with POST method.
SMB
Downloads
Create the SMB Server
Copy a File from the SMB Server
But in some scenarios there would be an error, which forbids us unauthentificated guest access, so we could creat a smb server with authentification
Create the SMB Server with a Username and Password
Mount the SMB Server with Username and Password
Uploads
SMB Uploads will be more tricky because companies usually block uploads to SMB, cause it could cause a huge problem. BUUUT we could use HTTP or HTTPS protocol in return. It's because when you use SMB, it will first attempt to connect using SMB protocol, and if there's no SMB share available, it'll try to connect using HTTP. But for this we need WebDav protocol, it enables a webserver to behave like a fileserver, which we need. First you need to install it
Using the WebDav Python module
Connecting to the Webdav Share. DavWWWRoot isn't a folder, it's a special keyword that tells WebDAV that we are connection to the root of WebDav server. You could use any existing directory when you are connecting, as example
sharefolder
Uploading Files using SMB
FTP
Downloads
Installing FTP Server python3 module
Setting up a Python3 FTP Server
Transferring Files from an FTP Server Using Powershell
Create a Command File for the FTP Client and Download the Target File
Uploads
For this we would also use peftpdlib but we need to specify the option --write to allow clients to upload files to our attack host.
Starting FTP Server
Powershell Upload File
Create a Command File for the FTP Client to Upload a File