SQL injection in Serendipity (serendipity_fetchComments)
The serendipity_fetchComments function uses several parameters unescaped in SQL queries, and two callers pass configuration values that an administrator can control. An authenticated administrator could inject SQL to extract database records, including password hashes, or access files on the server.
bb9866f3f743d6bf69b6836 Follow
Originally disclosed on HackerOne
- Triaged in 18 days
- Fixed in 47 days
- Disclosed after 4 months
Summary by the program
Bug in upstream Serendipity software, got fixed in version 2.1.3.
The impact is limited, as it requires a backend login. Still it's a great finding and many thanks to the reporter.
The report
##Summary
An authenticated administrator can alter Entries to display on frontpage and Entries to display in Feeds in a way to perform a SQL injection and extract database records or access files on the underlying system.
##Description
The function serendipity_fetchComments (implemented in functions_comments.inc.php) allows to obtain an array of comments related to a specific entry id. It accepts six parameters that will impact the query:
$id: casted as integer and then used in the query;$limit: used unescaped in the query;$order: used unescaped in the query;$showAll: adds a fixed condition to the query;$type: used unescaped in the query;$where: used unescaped in the query.
Thus, any use of serendipity_fetchComments where either $limit, $order, $type or $where are user-controlled will result in a SQL injection. Two vulnerable calls were discovered.
The first one can be found in rss.php. The value of $serendipity['RSSfetchLimit'] comes from website's configuration (Entries to display in Feeds) and is used as second argument of serendipity_fetchComments:
<?php
// [...]
switch ($_GET['type']) {
case 'comments_and_trackbacks':
case 'trackbacks':
case 'comments':
$entries = serendipity_fetchComments(isset($_GET['cid']) ? $_GET['cid'] : null, $serendipity['RSSfetchLimit'], 'co.id desc', false, $_GET['type']);
The same way, serendipity_printCommentsByAuthor (implemented in functions_comments.inc.php) uses $serendipity['fetchLimit'] as second argument. The value of $serendipity['fetchLimit'] also comes from website's configuration (Entries to display on frontpage):
<?php
// [...]
$sql_limit = $serendipity['fetchLimit'] * ($serendipity['GET']['page']-1) . ',' . $serendipity['fetchLimit'];
$c = serendipity_fetchComments(null, $sql_limit, 'co.entry_id DESC, co.id ASC', false, $type, $sql_where);
Steps To Reproduce
- Access https://blog.fuzzing-project.org/serendipity_admin.php?serendipity[adminModule]=configuration as authenticated administrator.
- Alter either Entries to display on frontpage or Entries to display in Feeds (under Appearance and Options) by adding any non-numeric character in one of these fields.
- Access https://blog.fuzzing-project.org/rss.php?type=comment if you edited Entries to display in Feeds, or the homepage is you edited Entries to display on frontpage. The character
broke the correctness of the query and an error message will be displayed.
I don't have any test environment at the moment but let me know if you need a real payload to show it's possible to extract arbitrary database records.
Impact
An authenticated administrator can extract database records, including password hashes of other users of the instance. Depending on database user privileges, it could also allow to access other bases or files on the underlying server.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The function serendipity_fetchComments does not escape or validate the $limit, $order, $type, and $where parameters before using them in SQL queries, and callers pass administrator-controlled configuration values into these parameters.
Impact
An authenticated administrator could extract database records, including password hashes of other users, and depending on database privileges, access other databases or files on the server.
What the attacker needed
Authenticated administrator access
The fix
The bug was fixed in Serendipity version 2.1.3.
How it was found
- Log in as an authenticated administrator and go to the configuration page.
- Change either 'Entries to display on frontpage' or 'Entries to display in Feeds' by adding a non-numeric character.
- Visit the RSS feed or homepage to trigger the query and see an error message.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
SQL injection is when user input is inserted into a database query without proper handling, letting an attacker change the query's meaning. Here, an admin can set a configuration value that is later used directly in a database query, so they can add extra SQL commands. This requires an admin login, so the impact is limited to someone who already has high privileges.
What is SQL injection?
Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.