Peter said:
Ok please explain why mysql_real_escape_string() is not good enough?
It's great but not by itself.
What happens when a person uses this:
';alert(String.fromCharCode(88,83,84))//\';alert(String.fromCharCode(88,83,85))//";alert(String.fromCharCode(88,83,86))//\";alert(String.fromCharCode(88,83,87))//--></SCRIPT>">'><SCRIPT>alert(String.fromCharCode(88,83,88))</SCRIPT>
Here is the same line of code, just urlencoded:
%27%3Balert%28String.fromCharCode%2888%2C83%2C84%29%29%2F%2F%5C%27%3Balert%28String.fromCharCode%2888%2C83%2C85%29%29%2F%2F%22%3Balert%28String.fromCharCode%2888%2C83%2C86%29%29%2F%2F%5C%22%3Balert%28String.fromCharCode%2888%2C83%2C87%29%29%2F%2F--%3E%3C%2FSCRIPT%3E%22%3E%27%3E%3CSCRIPT%3Ealert%28String.fromCharCode%2888%2C83%2C88%29%29%3C%2FSCRIPT%3E
Keep in mind: NamePros is using VB. VB splits "long-single-string" code with a space after x characters. Look above: At the end of the 2nd line above, %2FSCRI PT%3E .. see the space between I and P ? Also, there's another one before this ".fromCh arCode%" h and a .. a space! Really, it just prevents the post from no-wrap and having you scroll to the right to see the rest of it as one long line (cosmetics really).
So watch this if you're testing this on your own code. Just a safety guard for NP community and long strings. So when you test make sure there are no spaces (to really try this on your code).
Both should work if you're not properly filtering keywords used to search or save information to the db. Again, *_real_escape_string() doesn't work for that above. It'll just store it in the db, and when it's time to present itself, will be when the hack takes place. What is more, it may even show a javascript prompt alert which reads "XSS" (if you're just searching via keywords for example). That's what this example above does. 3 ways to try and ouput a javascript alert prompt (for those wondering what it is).
This code could be considered a Trojan (since it executes at a later date, sitting in your db waiting for the perfect time to present itself -- an article, a date, a username, etc) .. and it's just an example for the sake of this topic.
So, if your coding techniques are tight, the above examples should not work.
Take care,
-Peter