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类似,暂且放下

原文地址:https://www.cnblogs.com/gorillalee/p/14342805.html