Miscellaneous File Transfer Methods
This section will cover alternative methods such as transferring files using Netcat, Ncat and using RDP and PowerShell sessions.
Last updated
This section will cover alternative methods such as transferring files using Netcat, Ncat and using RDP and PowerShell sessions.
Last updated
Related Sites:
The target or attacking machine can be used to initiate the connection, which is helpful if a firewall prevents access to the target. Let's create an example and transfer a tool to our target.
In this example, we'll transfer from our Pwnbox onto the compromised machine. We'll do it using two methods. Let's work through the first one.
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 using a single greater-than >
followed by the filename, SharpKatz.exe
.
If the compromised machine is using Ncat, we'll need to specify --recv-only
to close the connection once the file transfer is finished.
By 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. Typically, Ncat would continue running until the network connection is closed, as the remote side may transmit additional data. However, with --send-only
, there is no need to anticipate further incoming information.
Writing to this particular file makes Bash open a TCP connection to host:port
, and this feature may be used for file transfers.
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. Let's create an example and transfer a file from DC01
to DATABASE01
and vice versa.
We have a session as Administrator
in DC01
, the user has administrative rights on DATABASE01
, and PowerShell Remoting is enabled. Let's use Test-NetConnection to confirm we can connect to WinRM.
Because this session already has privileges over DATABASE01
, we don't need to specify credentials. In the example below, a session is created to the remote computer named DATABASE01
and stores the results in the variable named $Session
.
We can use the Copy-Item
cmdlet to copy a file from our local machine DC01
to the DATABASE01
session we have $Session
or vice versa.
RDP (Remote Desktop Protocol) is commonly used in Windows networks for remote access. We can transfer files using RDP by copying and pasting. We can right-click and copy a file from the Windows machine we connect to and paste it into the RDP session.
If we are connected from Linux, we can use xfreerdp
or rdesktop
. At the time of writing, xfreerdp
and rdesktop
allow copy from our target machine to the RDP session, but there may be scenarios where this may not work as expected.
As an alternative to copy and paste, we can mount a local resource on the target RDP server. rdesktop
or xfreerdp
can be used to expose a local folder in the remote RDP session.
To access the directory, we can connect to \\tsclient\
, allowing us to transfer files to and from the RDP session.
After selecting the drive, we can interact with it in the remote session that follows.
Note:
This drive is not accessible to any other users logged on to the target computer, even if they manage to hijack the RDP session.
From our attack host, we'll connect to the compromised machine on port 8000 using Netcat and send the file 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.
Instead of listening on our compromised machine, we can connect to a port on our attack host to perform the file transfer operation. This method is useful in scenarios where there's a firewall blocking inbound connections. Let's listen on port 443 on our Pwnbox and send the file as input to Netcat.
If we don't have Netcat or Ncat on our compromised machine, Bash supports read/write operations on a pseudo-device file .
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 , aka WinRM, to perform file transfer operations.
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.
Alternatively, from Windows, the native remote desktop client can be used.