Tell me more ×
IT Security Stack Exchange is a question and answer site for IT security professionals. It's 100% free, no registration required.

I am php developer. I have enabled Captcha and CSRF tokens but still some one is inserting random values in my database. Please give me an idea about how anyone can insert junk values in my database if I have enabled both Catpcha and CSRF Tokens.

share|improve this question
We'll need more info to help if we even can. Is this a system you built or a pre-built system that you have installed? – AJ Henderson Jan 3 at 14:21
1  
Please define "junk" values. Is this an issue that you have a HTML form for say age (with choices pulldown choices between 1 and 100) and someone decided to say their age is 666? (This is trivial to do; edit the HTML page before submitting the form). If you don't want those junk values you have to do input sanitation in your code. Or is it you keep getting spammed advertisements in comments posted quickly (then your captcha is either too easy; not properly implemented; or someone doesn't mind paying a human ~$2 to solve about a thousand CAPTCHAs for them so they can spam you). – dr jimbob Jan 3 at 19:42
why downvote is their any issue with my question – Vipan Kumar Jan 4 at 13:38

closed as not a real question by Polynomial, Gilles, AJ Henderson, Lucas Kauffman, Scott Pack Jan 5 at 15:56

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, see the FAQ.

3 Answers

up vote 3 down vote accepted

In addition to what others have said, your question demonstrates a category mistake. You're talking about "securing your site" and you listed two countermeasures.

CAPTCHA is meant to deter automated submissions - to prevent automated programs from submitting data to your application. This doesn't prevent a human being from inserting malicious/garbage data.

CSRF tokens are meant to prevent your website from falling prey to Cross-Site Request Forgery. That's something that happens when another site is infected with XSS, and that injected JavaScript is performing actions on your site. It also has little or nothing to do with garbage input getting into your database (unless that malicious script on the other site is injecting it, but that would be incidental and not relevant to how to prevent it.)

Neither of these have anything to do with bad data getting into your database (except incidentally). The only way to prevent bad data from getting into the database is to filter input, which is done via a combination of input form validation, and proper SQL Injection prevention techniques (not contencating strings, using parameterized stored procedures or prepared statements if the language supports them, etc.

In your case, the most relevant is input validation. And I strongly recommend a white-list approach if feasible.

No offense, but your question indicates that your level of familiarity with basic secure web development principles is on the beginner end of the scale. (And I really mean no offense! It took years for me to understand as much as I do now, and I'm STILL not an expert!)

Actually securing your site (at least making it as secure as humanly possible requires an understanding of all the threats and potential attack surfaces of your website, as well as an understanding of the strengths and weaknesses of your platform and even programming language.

I'd strongly recommend spending some time at the OWASP site, starting out in the OWASP Top 10. This is an excellent research for learning about the various threats out there, and how to best protect yourself against them. Even if you don't find specific code samples for your language/platform of choice, you'll gain enough knowledge to perform more intelligent Google searches, and better find specific advice applicable to your chosen tool-set.

There are other good resources, but at a minimum, every web developer needs to understand the OWASP Top 10 threats, and how to defend against them. Even if your site doesn't host sensitive data, if someone can perform an SQL Injection, they can inject JavaScript on your site to perform a CSRF attack on other sites.

Learning secure web development principles simply isn't optional, it's a must.

share|improve this answer
+1 - Best answer so far. There's many ways other than SQL injection to get "junk" values in the database; simply not implementing server-side input sanitation. – dr jimbob Jan 3 at 19:45

You're probably falling victim to SQL injection, which neither CSRF tokens or a CAPTCHA will prevent. If you're using mysql_query, that's your problem - it's possible to inject values and query language into variables passed by the user. Switch to parameterised queries, using MySQLi or PDO.

share|improve this answer
i am using parameterised queries using PDO and php 5 – Vipan Kumar Jan 3 at 12:53
1  
Are you actually putting the values into parameters, rather than using concatenation? Using PDO doesn't automatically protect you. – Polynomial Jan 3 at 12:56
yes i am using paramerised queries with ?,?,? – Vipan Kumar Jan 3 at 12:57
3  
I'd guess you probably screwed up a query somewhere. Without a full review of the site's source, we can't really tell you. I suggest you hire someone to do a code security review. – Polynomial Jan 3 at 12:58
2  
You'll need to find a company in your country that offers web application security reviews. I don't know of any in India, but I'm sure you could quickly find some via a quick Google search. – Polynomial Jan 3 at 13:02
show 4 more comments

Try to find out how is the junk data inserted. First check which tables and which fields in the database are affected. After you make a list with these fields, check your code and see where they are referenced. This may help you detect the vulnerable code, by analyzing the respective functions.

If the problem you have is on inputs that are publicly available (contact forms) for non-authenticated users and the only way to prevent automated attacks is through CAPTCHAs, take into account that the CAPTCHA implementation may be faulty. I've seen numerous websites where the same question is displayed every time (e.g. 2+3=?).

There are many ways in which a CAPTCHA library can fail. What CAPTCHA library are you using?

share|improve this answer
i am using recaptcha from google code – Vipan Kumar Jan 3 at 17:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.