HTTP/SMB/Nginx/Web Servers/Netcat

A good alternative for transferring files to Apache is NGINXarrow-up-right because it is configuration is less complicated, and the module system does not lead to security issues like Apache can do.

Nginx Enable PUT

# 1-Create a directory to handle uploaded files
sudo mkdir -p /var/www/uploads/SecretUploadDirectory

# 2-Change the owner to www-data
sudo chown -R www-data:www-data /var/www/uploads/SecretUploadDirectory

# 3-Create the NGINX Configuration file, by creating the file /etc/nginx/sites-available/upload.conf with the contents:

server {
	listen 9001;
	
	location /SecretUploadDirectory/ {
		root	/var/www/uploads;
		dav_methods	PUT;
	}
}

# 4-Symlink our site to the sites-enabled directory.
sudo ln -s /etc/nginx/sites-available/upload.conf /etc/nginx/sites-enabled/

# Start Nginx
sudo systemctl restart nginx.service

# IF ANY ERROS OCCURS check /var/log/nginx/error.log
# if we see there is already a module listening on port 80 remove default nginx conf
sudo rm /etc/nginx/sites-enabled/default


# we can then test upload by using cuurl and put 
curl -T /etc/passwd http://localhost:9001/SecretUploadDirectory/users.txt
tail -1 /var/www/upload/SecretUploadDirectory/users.txt 

SMB

Impacket SMBServer

In some cases, computers will not allow anonymous SMB connections. In this case, we may want to use the user/password flags to allow authentication on our SMB server. This can be done with the following command:

SMB / WebDAV

In case SMB traffic through the firewall has been restricted, WebDAVarrow-up-right may be a good option, as it relies on HTTP as a transport protocol.

Web Servers

Netcat

Basic nc

Connection Initiated by Pentester

Connection Initiated by Victim/TargeT

Using /dev/tcp device file

SCP

OpenSSH server can be enabled using this procedurearrow-up-right. On older Windows systems, the PuTTY Secure Copy client (pscp.exe) can be used.

FTP

Ftp-script.txt

FTP Transfer

TFTP

The TFTP client is not available by default in Windows, but it can be enabled using DISM. \

In newer versions of Windows, the Install-WindowsFeature PowerShell cmdlet can also be used. Both DISM and Install-WindowsFeature require administrative access.

RDP

Remote Desktop is often enabled on Windows machines, and from Linux, rdesktop can be used to expose a local folder in the remote RDP session.

After selecting the drive, we can interact with it in the remote session as follows:

Echo Copy

On machines with a very stringent lockdown policy, it may be necessary to echo copy files.

Echo copying files is very inefficient and can result in a large amount of data being transferred across the clipboard, so we can use an executable packer such as UPXarrow-up-right to make the source file as small as possible.

Next, we need to convert the binary data to base64. Windows contains a native utility that can do this - certutil.

Open the resulting text file in a text editor that supports the replacement of extended characters (\n \r \t \0 \x...), such as Notepad++. Replace newlines with echo ".

The first line doesn’t contain this, so we can manually prepend echo " to the first line. Next, we replace with " >> nc.txt.

FTP Transfer

If the last line has an echo " on its own, remove it.

Next, copy all the text, and paste it into the shell, pressing enter if needed on the last command. This time, use the -decode certutil switch to convert the base64 text back to binary.

OpenSSL base64

JavaScript

The following JavaScript, based on thisarrow-up-right post, can be used.

Code: javascript

It can be executed as follows.

Decryption

VBScript

Last updated