SSRF-Vulnerable-Lab靶场训练

参考文章


1、file_get_content.php

提取并显示指定文件内容的应用程序代码
在编程语言中,有一些函数可以获取本地保存文件的内容。这些功能可能能够从远程URL以及本地文件(例如PHP中的file_get_contents)中获取内容。
如果没有对输入内容进行处理,或者处理的不够严格,将有可能导致SSRF漏洞攻击。
输入:file_get_content.php
显示:
在这里插入图片描述
直接暴露源码
输入:file:///C:/Windows/System32/drivers/etc/hosts
在这里插入图片描述
暴露出hosts文件内容
输入:http://127.0.0.1:80
在这里插入图片描述
可以探测端口

查看源码(部分):

if(isset($_POST['read']))
{

$file=trim($_POST['file']);

echo htmlentities(file_get_contents($file));

} 

发现对输入没有任何过滤。

2、sql_connect.php

应用程序提供接口以连接到远程主机
Web应用程序具有允许用户使用任何端口指定任何IP的接口。在这里,该应用程序具有尝试连接到“ MySQL”,“ LDAP”等服务的功能。

应用程序希望用户在输入字段中指定远程服务器的主机名/ IP,用户名和密码。然后,应用程序尝试通过指定的端口连接到远程服务器。在这种情况下,应用程序尝试与侦听特定端口的远程服务进行通信。当易受攻击的代码具有连接到MySQL之类的服务器的功能并且用户指定了SMB端口时,易受攻击的应用程序将尝试使用MySQL服务器服务数据包与SMB服务进行通信。即使端口是开放的,由于通信方式的差异,我们仍无法与服务进行通信。
按照默认值访问如图:
在这里插入图片描述
修改Host IP为:127.0.0.1:80 (80端口开启了)
在这里插入图片描述
明显不一样,用burpsuite爆破IP和端口,
查看源码(部分):

<?php
set_time_limit(0);
error_reporting(0);
if(isset($_POST['sbmt']))
{
$host=trim($_POST['host']);
$uname=trim($_POST['uname']);
$pass=trim($_POST['pass']);

$r=mysqli_connect($host,$uname,$pass);

if (mysqli_connect_errno())
  {
  echo  mysqli_connect_error();
  }
}
echo "<br>";
?>

可知,主要是通过mysqli_connect()连接,错误信息是mysqli_connect_errno(),

3、download.php

与file_get_content.php类似,
输入:download.php,就会下载download.php文件
在这里插入图片描述
同样的,输入:file:///C:/Windows/System32/drivers/etc/hosts
在这里插入图片描述
查看源码(部分):

function file_download($download)
{
	if(file_exists($download))
				{
					header("Content-Description: File Transfer"); 
					
					header('Content-Transfer-Encoding: binary');
					header('Expires: 0');
					header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
					header('Pragma: public');
					header('Accept-Ranges: bytes');
					header('Content-Disposition: attachment; filename="'.basename($download).'"'); 
					header('Content-Length: ' . filesize($download));
					header('Content-Type: application/octet-stream'); 
					ob_clean();
					flush();
					readfile ($download);
				}
				else
				{
				echo "<script>alert('file not found');</script>";	
				}
	
}
if(isset($_POST['download']))
{
$file=trim($_POST['file']);
file_download($file);
}

其中没有过滤,通过readfile()函数读取文件。

4、dns-spoofing.php

输入:dns-spoofing.php
直接爆出源码:
在这里插入图片描述
查看源码(部分):

if(isset($_POST['read']))
{
$file=strtolower($_POST['file']);
if(strstr($file, 'localhost') == false && preg_match('/(^https*:\/\/[^:\/]+)/', $file)==true)
  {
	$host=parse_url($file,PHP_URL_HOST);
	if(filter_var($host, FILTER_VALIDATE_IP)) 
		{
			if(filter_var($host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE |  FILTER_FLAG_NO_RES_RANGE)== false) 
				{
					
					echo '
						   <table width="50%" cellspacing="0" cellpadding="0" class="tb1" style="opacity: 0.6;">
						   <tr><td align=center style="padding: 10px;" >
							The provided IP is from Private range and hence not allowed

						   </td></tr></table>
						   <table width="50%" cellspacing="0" cellpadding="0" class="tb1" style="margin:10px 2px 10px;opacity: 0.6;" >';
				}
			else 
				{
					echo '<textarea rows=20 cols=60>'.file_get_contents($file)."</textarea>";
				}
		}
	else 
		{
			echo '<textarea rows=20 cols=60>'.file_get_contents($file)."</textarea>";
		}
  }
  
  elseif(strstr(strtolower($file), 'localhost') == true && preg_match('/(^https*:\/\/[^:\/]+)/', $file)==true) 
	{
		echo '
		<table width="30%" cellspacing="0" cellpadding="0" class="tb1" style="opacity: 0.6;">
						   <tr><td align=center style="padding: 10px;" >
							Tyring to access Localhost o_0 ? 

						   </td></tr></table>
						   <table width="50%" cellspacing="0" cellpadding="0" class="tb1" style="margin:10px 2px 10px;opacity: 0.6;" >';
	}
  else 
	{
		echo '<textarea rows=20 cols=60>'.file_get_contents($file)."</textarea>";
	}
}

简单的说就是,该脚本具有允许用户从远程URL获取数据的功能。用户需要指定远程URL与任何IP或域名这个脚本检查用户是否指定了“localhost”、“Internal IPs”或“Reserved IPs”的输入。如果用户指定的域/IP被列入黑名单,脚本将不会获取内容并停止处理。注意的是,该代码并没有将域/IP列入黑名单中
所以,没有可以类似题一的方法,输入:file:///C:/Windows/System32/drivers/etc/hosts
在这里插入图片描述

但这是不正规的,依作者的题意,应当基于DNS的欺骗绕过IP黑名单。目前并没有掌握该技巧,暂且放下。

5、dns_rebinding.php

应用程序不仅实现了内部和私有范围的IP黑名单,而且还将用户提供的域名解析为其IP,并再次执行检查是否已解析为黑名单。
在这种情况下,基于DNS的欺骗手段也不会访问内部/保留IP上托管的内容。应用程序代码对其IP执行域解析,并再次对解析的IP执行黑色列出的IP检查。

与题4类似,暂且放下

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
SSRF (Server Side Request Forgery) 测试是一个用于检测服务器端请求伪造漏洞的工具,它是一种常见的安全测试技术。为了安装 SSFRT 这一工具,你可以按照以下步骤操作: ### 安装依赖 首先,确保你的系统已安装 Python 和 pip(Python 的包管理器)。在命令行界面输入: ```bash pip install -r requirements.txt ``` 如果你是使用基于 Debian 或者 Ubuntu 的 Linux 发行版,则需要先安装 `libffi-dev`、`libssl-dev`、`python-dev` 等库,可以通过运行以下命令完成: ```bash sudo apt-get update sudo apt-get install libffi-dev libssl-dev python-dev ``` 接着,在你的项目目录中创建一个名为 `requirements.txt` 的文件,并添加所需的依赖(通常包括 `requests` 库),然后再次使用 `pip` 来安装: ```txt # requirements.txt 文件内容示例 requests==2.26.0 pip install -r requirements.txt ``` ### 安装 SSFRT 工具 使用 Git 克隆 SSFRT 的仓库到本地: ```bash git clone https://github.com/ssertool/ssftrt.git cd ssftrt pip install . ``` 或者从 PyPI 直接安装(如果已发布): ```bash pip install ssftrt ``` ### 使用 SSFRT 一旦 SSFRT 成功安装,你可以在 Python 脚本中导入并使用它来进行 SSRF 测试。典型的用法如下: ```python from ssertool.ssftrt import SSFRT ssf = SSFRT() results = ssf.scan('http://example.com', {'param': 'http://target.example.com'}) print(results) ``` 在这个例子中,我们尝试通过 `http://example.com` 的 URL 发起请求,其中 `param` 参数指向了目标 URL `http://target.example.com`。 ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值