File transfer / exfiltration
On Linux, it is recommended to verify the integrity of the transferred file using the built-in md5sum.
On Windows, the PowerShell cmdlet Get-FileHash -Algorithm MD5 can be used to compute the MD5 file's hash.
Server side / file sender
The following tools can be used to host files server-side.
[Linux / Windows] Python
The SimpleHTTPServer / http.server Python modules can be used to quickly start an HTTP server from the CLI.
The module is however limited : the listening interfaces can not be specified and no SSL/TLS layer is natively supported.
python2 -m SimpleHTTPServer <PORT>
python3 -m http.server <PORT>On Windows systems with out Python installed, the WinSimpleHTTP standalone binary can be used to start a the web server based on Python's SimpleHTTPServer module.
# Pre-compiled binaries are available on GitHub
pip install pyinstaller
pyinstaller web.py --onefile
web.exe <PORT>[Linux / Windows] Node
The http-server Node module can be used to setup an HTTP server from the CLI.
The module supports different configuration options and can be used to listen on a specific IP address as well as enabling SSL/TLS and CORS.
The http-server-with-auth Node module additionally provides a basic HTTP authentication mechanism.
[Linux] curl
[Linux / Windows] netcat
[Linux] socat
[Linux] impacket-smbserver
[Linux] SAMBA shares
A SAMBA share can be configured on Linux systems using the samba utility.
The samba configuration file's /etc/samba/smb.conf should be first updated to create a new network share. Access to the shared folder should be allowed at the filesystem level (restriction will still be enforced by the share configuration):
sudo chmod 0777 <SHARE_PATH>.
After the new network share is configured, the smbd daemon must be restarted:
[Windows] SMB shares
On Windows, the graphical interface of Windows Explorer can be used to share a specific folder over the network. Sharing a folder requires Administrators or NT AUTHORITY\SYSTEM privileges.
Note that the final access permissions for a shared resource are determined by considering both the NTFS permissions and the sharing protocol permissions, and then applying the more restrictive permissions. Thus, it is possible to grant "Everyone" full access permission when configuring the share permissions.
The above procedure, through Windows Explorer, can also be done in PowerShell:
Anonymous (ANONYMOUS LOGON) access may be prevented through system wide settings, independently of the access rights configured at the share and NTFS levels. Indeed, if the RestrictNullSessAccess registry key is enabled (set to 0x1), anonymous access are restricted to only the named pipes and shares that are defined, respectively, in the NullSessionPipes and NullSessionShares registry keys. Additional security parameters defined through registry keys may also interfere with anonymous access:
RestrictAnonymous: if enabled (set to0x1), prevents users who logged on anonymously to lists share names.EveryoneIncludesAnonymous: if disabled (set to0x0), prevents users who logged on anonymously to have the same rights as the built-in Everyone group.
The following PowerShell commands can be used to authorize anonymous access to the specified share and disable the security parameters that may interfere with anonymous logon system-wide (effectively lowering the computer security configuration however):
[Linux / Windows] FTP
[Linux / Windows] TFTP
[Linux] NFS server
The docker-nfs-server project can be used to host a NFS server in a docker container and expose the NFS server on the host.
If AppArmor is installed and enabled on the host running docker (can be checked with sudo aa-status), the documented additional steps must be followed to start the NFS server.
The mount utility can then be used to validate that the NFS directory is available:
[Windows] PowerShell HTTP PUT request
The PowerShell cmdlets Invoke-WebRequest and Invoke-RestMethod can be used to send a file, or directly a variable content, through a HTTP PUT request to a webserver (that should process the request and store the received PUT body):
[Windows] Simulated keyboard
A keyboard can be simulated, by emulating keystrokes, to send base64-encoded files on specifically hardened systems (that restrict the usage of the tools and utilities presented in this note and disable the clipboard). The simulated keystrokes may be used to write a file or in directly outputted into a PowerShell variable inside an interactive terminal.
The transfer time is however overwhelming long and this method is not adapted to larger files.
Client side / file receiver
The following tools can be used to download file from a server client side.
File transfer is easier on Linux machines as wget, curl or netcat are often packaged with the operating system distribution.
On Windows machines, the process is usually not as straight forward but multiples methods can still be used. Transferring the netcat utility may simplify the subsequent files transfer.
LOLBINS
The most reliable tools and methods are presented below. For a more exhaustive list of tools that can be used to transfer files on and off a Windows machine, refer to https://lolbas-project.github.io/#/download.
To following commands can be used to retrieve the list of binaries present on the host.
[Linux / Windows] echo & base64 encoding
The Linux built-ins echo and base64 and the Windows CMD built-ins echo and certutil can be used to easily transfer files on Linux / Windows systems.
Encode the file to be transferred using base64 server-side, copy it to the clipboard buffer, and decode it into a file client-side.
[Linux] wget
[Linux] curl
[Linux / Windows] netcat
[Linux] socat
[FreeBSD] fetch
The FreeBSD built-in fetch can be used to retrieve a file by URL:
[Linux / Windows] Python
[Linux / Windows] Perl
[Windows] Powershell
The PowerShell cmdlets Invoke-WebRequest, DownloadFile and New-PSDrive can be used to download files from a remote web service or SMB share.
[Windows] PowerShell remoting / WinRM
Files or folders can be uploaded or downloaded on a remote system through a PowerShell remoting session (WinRM) using the Copy-Item cmdlet:
[Windows] VBScript
VBScript, a Microsoft scripting language modeled on Visual Basic, can be used to transfer files (although larger files > 2MB tend to pose problem).
As the execution of VBScript may be restricted by GPO, the first step is to make sure VBScript can be used on the compromised machine:
If Successfully ran VBScript! is printed on the console screen, VBScript can be executed on the target. On the contrary, if any of the following error messages is displayed, the usage of VBScript is restricted:
The following CMD commands can be used to create a VBScript downloader (courtesy of @frizb):
The VBScript can then be used to download files on the target:
[Windows] SMB shares
The Windows built-in utility xcopy can be used to download or upload files on a remote SMB share over the network:
Additionally, SMB shares can be accessed and mounted using the Windows net command-line utility. Once mounted the drive can be accessed as a local drive.
The most interesting feature of using SMB is the fact that files can be directly executed over the SMB Share without the needed to write them to the target machine file system, effectively resulting in file less execution.
[Windows] BITS
Background Intelligent Transfer Service (BITS) is a Microsoft Windows component developed to asynchronously transfer files with a reduced network bandwidth usage. It is notably used by Windows Server Update Services (WSUS) and System Center Configuration Manager (SCCM) servers to deliver updates to Windows clients. Others third-party software, such as Firefox and Google Chrome, also rely on BITS to download their updates on Windows operating systems. BITS supports transfers over the SMB, HTTP and HTTPS protocols.
BITSAdmin is a Windows command-line built-in utility that can be used to create, download or upload files using BITS. Note that BITSAdmin will not attempt the download if the security context under which its executed does not have the permission to write files on the specified output path.
Due to its possible legitimate usage, download of files through bitsadmin may not be identified as malicious by Endpoint Detection and Response products.
Note that downloaded files can be directly and executed using bitsadmin:
The PowerShell Start-BitsTransfer may be used as well to download / upload files through BITS:
Note that while the Start-BitsTransfer cmdlet supports the specification of alternative PSCredential credentials with the -Credential parameter, the functionality is currently bugged. Instead, a temporary drive mapping should be created using the New-PSDrive cmdlet (PowerShell 3.0) or WScript.Network object.
[Windows] CertUtil
CertUtil is a Windows command-line tool designed to manage Certification Authority (CA) and certificates. One of its feature is the ability to download files from a remote webserver by specifying an URL.
Note that the usage of CertUtil is monitored by most Endpoint Detection and Response products and downloads through CertUtil may generate detection alerts.
[Windows] desktopimgdownldr.exe
desktopimgdownldr is a Windows built-in utility, initially designed to set desktop or background screen, that can be used to download arbitrary files from a web server.
The SYSTEMROOT environment variable is used by desktopimgdownldr to determine the output folder and can thus be used to specify an arbitrary output folder.
[Windows] findstr
findstr is a Windows utility used for searching patterns of text in files.
The following command can be used to search the string DoNotExist123456789 in the specified remote file and, since it does not exist (/V), download it.
[Linux / Windows] FTP
To download file interactively:
Paste the following commands into a remote Windows shell and download files over FTP non-interactively (replace by anonymous if using anonymous login):
In case of AV errors while trying to download a binary, omit the exe extension.
[Windows XP & 2003] TFTP
TFTP is a simple protocol for transferring files, implemented on top of the UDP/IP protocols. TFTP was designed to be small and easy to implement, and therefore it lacks most of the advanced features offered by more robust file transfer protocols. TFTP only reads and writes files from or to a remote server. It cannot list, delete, or rename files or directories and it has no provisions for user authentication.
Windows operating systems up to Windows XP and 2003 contain a TFTP client, by default. In Windows 7, 2008, and above, this tool needs to be explicitly added, during installation.
[Linux / Windows] SCP / PuTTY pscp
The Linux Secure Copy and Windows PuTTY's pscp utilities can be used to transfer files over SSH and can notably be used to retrieve and upload files from a compromised target exposing a SSH service.
[Windows] WinSCP
WinSCP is a file transfer graphical utility for Microsoft Windows, available as an installed program and a standalone binary. WinSCP support the following protocols / services:
FTPSFTPSCPWebDAVAmazon
S3buckets
WinSCP supports key-based authentication using PuTTY Private Key File (.pkf) as well as SSL based private keys.
[Linux / Windows] Metasploit meterpreter
The Metasploit meterpreter commands download and upload can be used to download / upload a specific file or to recursively download / upload directories and their contents.
[Linux / Windows] Python webserver processing PUT requests
The following Python code extends the Python SimpleHTTPServer module to process HTTP PUT request and store, in the directory the script was started, the PUT request body content as a file. The filename is specified in the URL requested.
Original author: Floating Octothorpe, https://f-o.org.uk/2017/receiving-files-over-http-with-python.html.
DNS exfiltration
Limited exfiltration using built-in utilities
DNS queries can be used to exfiltrate data through the requested domain name.
rclone
rclone is a command line utility written in Go to download / upload files and directories to and from over 40 cloud storage providers. In addition to more classical file upload services (FTP, SFTP / FTPS, Webdav, etc.), rclone supports a number of cloud services: MEGA, Google Drive, Microsoft OneDrive, Amazon S3 buckets, Azure Blob Storage, etc.).
rclone provides cloud equivalents to the unix common commands cat, ls, mkdir, cp, mv, mount, etc. commands. It supports multi-retries and verifies file operations using checksums.
It is notably used by some threats actors to exfiltrate files to online file storage and cloud provider with out raising suspicion.
References
https://lolbas-project.github.io/
https://labs.sentinelone.com/living-off-windows-land-a-new-native-file-downldr/
https://github.com/frizb/Windows-Privilege-Escalation
https://github.com/cube0x0/CVE-2021-1675
https://www.giac.org/paper/gcwn/22/limiting-anonymous-logon-network-access-named-pipes-shares/100328
Last updated