首页
社区
课程
招聘
[原创]另类的注入--php版
发表于: 2016-12-12 17:29 2992

[原创]另类的注入--php版

2016-12-12 17:29
2992
本文结合php代码演示php代码注入,php对象注入,命令注入,ldap注入,xml注入,web-service注入
php代码基于bwapp,部分地方有改动。主要是总结一下,不足之处,请多多留言指教

1.php 代码注入
<?php @eval ("echo " . $_REQUEST["message"] . ";");?>

其实这已经是一句话木马了,因为滥用了eval而导致php代码注入
利用:执行php代码
效果:

2.php对象注入
介绍:https://www.secpulse.com/archives/4809.html
代码:来自xvwa
<?php
class PHPObjectInjection{
public $inject;
function __construct(){
                      }
function __wakeup(){
if(isset($this->inject)){
eval($this->inject);
}
}
}
 if(isset($_REQUEST['r'])){
$var1=unserialize($_REQUEST['r']);
if(is_array($var1)){
echo "<br/>".$var1[0]." - ".$var1[1];
}
}else{
echo "parameter is missing";
}
?>

利用:执行php代码
效果:
http://127.0.0.1/injection_php/phpobject.php?r=a:2:{i:0;s:4:"test";i:1;s:5:"hello";}

http://127.0.0.1/injection_php/phpobject.php?r=O:18:"PHPObjectInjection":1:{s:6:"inject";s:10:"phpinfo();";}

2.命令注入
<?php echo shell_exec("nslookup  " . $_REQUEST["message"])?>

利用:执行命令,跟服务器系统有关
可以用| ; && %0a等截断执行代码
效果:

3.ldap注入 (and的注入没弄出来,可能是open ldap更新了,不允许有语法错误的filter了吧)
ldap配置:http://blog.topspeedsnail.com/archives/2981
<?php $ds = ldap_connect("ldap://127.0.0.1/") or die("Could not connect to LDAP server.");
$filter = "(|(cn=".$_GET['name'].")(description=LDAP administrator))";
print $filter."</br>";
$justthese=array("cn","location","description");
$sr=ldap_search($ds,"dc=test,dc=com",$filter,$justthese);
print_r(ldap_get_entries($ds,$sr));?>

利用:权限提升
效果:
[IMG]http://bbs.pediy.com/attachment.php?attachmentid=109296[[/IMG]
加上)(& 相当于or 1=1 (&)是永真的意思

4.xml注入
<?php
$body = file_get_contents("php://input");
$xml = simplexml_load_string($body);
$login = $xml->login;
$message = $login . "'s secret has been reset!";
print_r($message);
?>

利用:读取文件
效果:

5.soap注入
soap介绍:http://www.runoob.com/soap/soap-tutorial.html
<?php
function get_tickets_stock($title)
{

	include("connect.php");        
	$sql = "SELECT tickets_stock FROM movies WHERE title = '" . $title . "'";
	$recordset = mysql_query($sql, $link);
        $row = mysql_fetch_array($recordset);
        mysql_close($link);
	return $row["tickets_stock"];

}
require("soap/nusoap.php");

// Creates an instance of the soap_server class
$server = new nusoap_server();

// Specifies the name of the server and the namespace
$server->configureWSDL("*** bWAPP Movie Service ***", "urn:movie_service");

// Registers the function we created with the SOAP server and passes several different parameters to the register method
// The first parameter is the name of the function
$server->register("get_tickets_stock",
// The second parameter specifies the input type
array("title" => "xsd:string"),
// The third parameter specifies the return type
array("tickets_stock" => "xsd:integer"),
// The next two parameters specify the namespace we are operating in, and the SOAP action
"urn:tickets_stock",
"urn:tickets_stock#get_tickets_stock");
// Checks if $HTTP_RAW_POST_DATA is initialized. If it is not, it initializes it with an empty string.
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : "";
// Calls the service. The web request is passed to the service from the $HTTP_RAW_POST_DATA variable.
$server->service($HTTP_RAW_POST_DATA);
?>

利用:soap连的数据库,还是sql注入吧
效果:

sql显错注入 'union select @@version#


总结:
原理:命令注入的本质是代码数据未分离
发现方式:熟悉各种语法,构造数据看是否会执行
通用修复方式:严格的正则限制参数内容

[课程]FART 脱壳王!加量不加价!FART作者讲授!

上传的附件:
收藏
免费 0
支持
分享
最新回复 (2)
雪    币: 2759
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
大部分图片挂了。希望能补上
2016-12-13 10:42
0
雪    币: 28
活跃值: (214)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
看不见图,有点难受
2017-3-6 16:39
0
游客
登录 | 注册 方可回帖
返回
//