php反序列化长度变化尾部字符串逃逸(0CTF-2016-piapiapia)分享!

一个很可爱的登录界面:

php反序列化长度变化尾部字符串逃逸(0CTF-2016-piapiapia)

进行一下目录扫描,发现源码泄露www.zip,把源码给出:

index.php

  <?php  	require_once('class.php');  	if($_SESSION['username']) {  		header('Location: profile.php');  		exit;  	}  	if($_POST['username'] && $_POST['password']) {  		$username = $_POST['username'];  		$password = $_POST['password'];    		if(strlen($username) < 3 or strlen($username) > 16)   			die('Invalid user name');    		if(strlen($password) < 3 or strlen($password) > 16)   			die('Invalid password');    		if($user->login($username, $password)) {  			$_SESSION['username'] = $username;  			header('Location: profile.php');  			exit;	  		}  		else {  			die('Invalid user name or password');  		}  	}  	else {  ?>  <!DOCTYPE html>  <html>  <head>   <title>Login</title>   <link href="static/bootstrap.min.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet">   <script src="static/jquery.min.js"></script>   <script src="static/bootstrap.min.js"></script>  </head>  <body>  	<div class="container" >   		<form action="index.php" method="post" class="well" >   			<img src="static/piapiapia.gif" class="img-memeda " >  			<h3>Login</h3>  			<label>Username:</label>  			<input type="text" name="username" class="span3"/>  			<label>Password:</label>  			<input type="password" name="password"  class="span3">    			<button type="submit" class="btn btn-primary">LOGIN</button>  		</form>  	</div>  </body>  </html>  <?php  	}  ?>

在输入账号密码之后进入了profile.php,下面是profile.php的源码:

  <?php  	require_once('class.php');  	if($_SESSION['username'] == null) {  		die('Login First');	  	}  	$username = $_SESSION['username'];  	$profile=$user->show_profile($username);  	if($profile == null) {  		header('Location: update.php');  	}  	else {  		$profile = unserialize($profile);  		$phone = $profile['phone'];  		$email = $profile['email'];  		$nickname = $profile['nickname'];  		$photo = base64_encode(file_get_contents($profile['photo']));  ?>  <!DOCTYPE html>  <html>  <head>   <title>Profile</title>   <link href="static/bootstrap.min.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet">   <script src="static/jquery.min.js"></script>   <script src="static/bootstrap.min.js"></script>  </head>  <body>  	<div class="container" >   		<img src="data:image/gif;base64,<?php echo $photo; ?>" class="img-memeda " >  		<h3>Hi <?php echo $nickname;?></h3>  		<label>Phone: <?php echo $phone;?></label>  		<label>Email: <?php echo $email;?></label>  	</div>  </body>  </html>  <?php  	}  ?>

还有注册页面的源码(没有太大用),register.php:

  <?php  	require_once('class.php');  	if($_POST['username'] && $_POST['password']) {  		$username = $_POST['username'];  		$password = $_POST['password'];    		if(strlen($username) < 3 or strlen($username) > 16)   			die('Invalid user name');    		if(strlen($password) < 3 or strlen($password) > 16)   			die('Invalid password');  		if(!$user->is_exists($username)) {  			$user->register($username, $password);  			echo 'Register OK!<a href="index.php" rel="external nofollow" >Please Login</a>';		  		}  		else {  			die('User name Already Exists');  		}  	}  	else {  ?>  <!DOCTYPE html>  <html>  <head>   <title>Login</title>   <link href="static/bootstrap.min.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet">   <script src="static/jquery.min.js"></script>   <script src="static/bootstrap.min.js"></script>  </head>  <body>  	<div class="container" >   		<form action="register.php" method="post" class="well" >   			<img src="static/piapiapia.gif" class="img-memeda " >  			<h3>Register</h3>  			<label>Username:</label>  			<input type="text" name="username" class="span3"/>  			<label>Password:</label>  			<input type="password" name="password"  class="span3">    			<button type="submit" class="btn btn-primary">REGISTER</button>  		</form>  	</div>  </body>  </html>  <?php  	}  ?>  

然后是update.php:

  <?php  	require_once('class.php');  	if($_SESSION['username'] == null) {  		die('Login First');	  	}  	if($_POST['phone'] && $_POST['email'] && $_POST['nickname'] && $_FILES['photo']) {    		$username = $_SESSION['username'];  		if(!preg_match('/^d{11}$/', $_POST['phone']))  			die('Invalid phone');    		if(!preg_match('/^[_a-zA-Z0-9]{1,10}@[_a-zA-Z0-9]{1,10}.[_a-zA-Z0-9]{1,10}$/', $_POST['email']))  			die('Invalid email');  		  		if(preg_match('/[^a-zA-Z0-9_]/', $_POST['nickname']) || strlen($_POST['nickname']) > 10)  			die('Invalid nickname');    		$file = $_FILES['photo'];  		if($file['size'] < 5 or $file['size'] > 1000000)  			die('Photo size error');    		move_uploaded_file($file['tmp_name'], 'upload/' . md5($file['name']));  		$profile['phone'] = $_POST['phone'];  		$profile['email'] = $_POST['email'];  		$profile['nickname'] = $_POST['nickname'];  		$profile['photo'] = 'upload/' . md5($file['name']);    		$user->update_profile($username, serialize($profile));  		echo 'Update Profile Success!<a href="profile.php" rel="external nofollow" >Your Profile</a>';  	}  	else {  ?>  <!DOCTYPE html>  <html>  <head>   <title>UPDATE</title>   <link href="static/bootstrap.min.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet">   <script src="static/jquery.min.js"></script>   <script src="static/bootstrap.min.js"></script>  </head>  <body>  	<div class="container" >   		<form action="update.php" method="post" enctype="multipart/form-data" class="well" >   			<img src="static/piapiapia.gif" class="img-memeda " >  			<h3>Please Update Your Profile</h3>  			<label>Phone:</label>  			<input type="text" name="phone" class="span3"/>  			<label>Email:</label>  			<input type="text" name="email" class="span3"/>  			<label>Nickname:</label>  			<input type="text" name="nickname"  class="span3">  			<label for="file">Photo:</label>  			<input type="file" name="photo" class="span3"/>  			<button type="submit" class="btn btn-primary">UPDATE</button>  		</form>  	</div>  </body>  </html>  <?php  	}  ?>

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/phpttorial/471537.html

(0)
上一篇 2020年10月26日
下一篇 2020年10月26日

精彩推荐