HPP: HTML Parameter Pollution paper

简介:

HPP can be used to create unusual behaviour in applications
Which can typically end up giving weaknesses or possible attack vectors in the application

ASP.NET/IIS:
What it parses: All occurences of a given parameter 
Example: parameter1=value1,value2

ASP/IIS 
What it parses: All occurences of a given parameter 
Example: par1

PHP/Apache 
What it parses: Last occurrence of a given parameter 
Example: parameter1=value2

PHP/Zeus 
What it parses: Last occurence of a given parameter 
Example: parameter1=value2

JSP/Tomcat 
What it parses: First Occurence of given variable 
Example: parameter1=value1

JSP/Oracle server 
What it parses: First occurence of a given variable 
Example: parameter1=value1

JSP/Jetty 
What it parses: First occurence of a given variable 
Example: parameter1=value1

IBM Lotus Domino 
What it parses: Last occurence of a given variable 
Example: parameter1=value2

IBM HTTP 
What it parses: First occurence of given variable 
Example: parameter1=value1

Perl(module),libapreq2/Apache 
What it parses: First occurence of given variable 
Example: parameter1=value1

Perl CGI/Apache 
What it parses: First occurence of given variable 
Example: parameter1=value1

Perl(module),lib?/Apache 
What it parses: Becomes an array 
Example: ARRAY(0x8b9059c)

python(module)/Apache 
What it parses: First occurence of given variable 
Example: parameter1=value1

Python/Zope 
What it parses: Becomes an array 
Example: ['value1','value2']

IceWarp 
What it parses: Last occurence of given variable 
Example: parameter1=value2

DBMan 
What it parses: All occurences of given variable 
Example: parameter1=value1~~value2

Some things HPP can help achieve:

* Gaining knowledge about the webserver and technologies used
* Gaining directory information
* Obfuscating logs with false entries
* Dumping cgi information

And many more things...

The attacks are structed by manipulating how the server processes parameters in the URL
Such as for DBMan:
Entering the url: http://address/cgi-b...
Would dump an error message quoting:


  CGI ERROR
 
----------------------------------------------------------
 
Error Message : Debug Information
 
Script Location       : location of db.cgi
 
Perl Version  : version
 
Setup File    : configuration file
 
Session ID    : aaaa~~bbbb
 
 
Form Variables
 
-----------------------------------------------------------
  db            
: default
  uid          
: aaaa~~bbbb
 
 
Environment Variables
 
-----------------------------------------------------------
  DOCUMENT_ROOT
: document root
  GATEWAY_INTERFACE    
: CGI/1.1
 


The use of GET/POST/Cookie may modify expected application behaviors and it can be used to override parameters



So here's an example situation also from AppsecEU09:


This being the source code of the application:



 
void private executeBackendRequest(HTTPRequest request){
   
String amount=request.getParameter("amount");
   
String beneficiary=request.getParameter("recipient");

   
HttpRequest("http://backendServer.com/servlet/actions","POST","action=transfer&amount="<font color="red">+amount+</font>"&recipient="<font color="red">+beneficiary</font>);

A malicious user may send a request like:



 http
://frontendHost.com/page?amount=1000&recipient=Mat%26action%3dwithdraw


Then, the frontend will build the following back-end request:



 
HttpRequest("http://backendServer.com/servlet/actions","POST","action=transfer&amount="+amount+"&recipient="+beneficiary);

Which translates too:



 action
=transfer&amount=1000&recipient=Mat&action=withdraw


This can even be used to bypass Web application firewalls:


Whenever the environment concatenates multiple occurrences (e.g. ASP, ASP.NET, DBMan), an aggressor can split the payload


The user would send



 http
://mySecureApp/db.cgi?par=<Payload_1>&par=<Payload_2>


This would result in:



 par
=<Payload_1>~~<Payload_2>

Being parsed and result in the server running the mal-payload, resulting in mass pwnage



Not only are web application firewalls not safe, but neither is mod_rewrite if not configured correctly!


Badly configured rules:



 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\.+page\.php.*\HTTP/
 
RewriteRule ^page\.php.*$ -[F,L]
 
RewriteCond %{REQUEST_FILENAME} !-f
 
RewriteCond %{REQUEST_FILENAME} !-d
 
RewriteRule ^([^/]+)$ page.php?action=view&page=$1&id=0 [L]

Where

http://address/string

becomes:


http://address/page....

So therefore a hacker could exploit this with:



 http
://host/string%26action%3dedit

And the url will be rewritten as:



 http
://host/page.php?action=view&page=abc&action=edit&id=0


This can be used in conjunction to bypass current restrictions and perform attacks such as:


* XSS


* FPI


* SQL Injection


* RFI/LFI



And can be furthered to obfuscate logs



Defense



Take into mind:



* Application business logic


* Technology used(PHP, ASP etc)


* Data validation (as usual!)


* Output encoding


* Filtering is the key to defend our systems!


* Don't use HtmlEntities. They're out of context!Instead, apply URL Encoding


* Use strict regexp in URL Rewriting


* Know your application environment!













本文转hackfreer51CTO博客,原文链接:http://blog.51cto.com/pnig0s1992/502451,如需转载请自行联系原作者

相关文章
|
5月前
|
数据采集 JavaScript 数据挖掘
如何使用 PHP Simple HTML DOM Parser 轻松获取网页中的特定数据
本文介绍了使用PHP Simple HTML DOM Parser进行网页数据抓取的方法,尤其适用于从懂车帝二手车网站提取汽车品牌、价格和里程等关键信息。首先,安装并配置所需库,使用代理IP和设置cookie与useragent来模拟用户行为,避免被封。然后,通过编写PHP脚本,利用cURL获取网页内容,解析HTML并提取所需数据,最终将数据保存至CSV文件。文章强调了正确配置代理和用户代理的重要性,并提供了完整的PHP代码示例,以帮助读者理解和应用网页抓取技术。
如何使用 PHP Simple HTML DOM Parser 轻松获取网页中的特定数据
SVG pattern 使用(patternUnits、patternContentUnits)
SVG pattern 使用(patternUnits、patternContentUnits)
295 0
报错 An error happened during template parsing (template: “ServletContext resource [/shiroTest.html]“)
报错 An error happened during template parsing (template: “ServletContext resource [/shiroTest.html]“)
sublime 打开报错 Error loading syntax file “Packages/HTML/HTML.sublime-syntax“: Apparent recursion withi
卸载步骤 打开sublime工具,按shift+command+p,打开输入框 输入remove package 输入 JavaScriptNext-ES6 Syntax,找到此插件,选中,enter卸载 重启sublime,弹出框消失
586 0
01-CSS3-justify-content: space-around; justify-content: space-between;
01-CSS3-justify-content: space-around; justify-content: space-between;