iExploit
Recent
Activity
Sign up
Have an account?
Sign in
Howdy, Stranger!
It looks like you're new here. If you want to get involved, click one of these buttons!
Sign In
Apply for Membership
Top Posters
Xin
3251
Sh3llc0d3
1910
chroniccommand
1389
undead
822
George
707
GameOver
675
Bursihido
406
m0rph
332
Mr. P-teo
270
D0WNGRADE
220
Who's Online (2)
Phage
6:17AM
rkrnoyhd
6:11AM
Powered by
Vanilla.
Made with
Bootstrap.
Looking to introduce yourself? Look no further, and click here! We also have IRC! [irc.evilzone.org #iexploit]
Web Application Security
How to secure your code from XSS
undead
August 2010
Posts: 822
How to secure your code from XSS
It's easy to secure if you found XSS bugs. Look at this code:
if(isset($_POST['form'])){echo "<html><body>" .$_POST['form']. "</body></html>";}
Say the variable $_POST['from'] was coming from a input box then you have a XSS attack.
It is a very easy way to secure that.
$charset='UTF-8'; $data = htmlentities ($_POST['form'], ENT_NOQUOTES, $charset);
if(isset($data)){echo "<html><body>" .$data. "</body></html>";}
That will take all possible code and make it not executable by turning it into stuff like
< ect.
You won't notice a diffrence when using htmlentries();.
Also there's another common function: striptags().
Another way to show you how to secure integer variables.
$this = $_GET['id'];
echo "You are viewing " . $this . "blog";
If we include ?id=<script>alert("XSS")</script>
in the URL it is going to execute our code. An easy way to secure this is using (int):
$this = (int)$_GET['id'];
echo "You are viewing " . $this . "blog";
Add a Comment