• (cs) in reply to oldami
    oldami:
    All this password by mouse and the absurd copy and paste excersize is mostly a waste of time. Any good malware (is that an oxymoron) will simply hook into IE and capture the data that gets posted.
    Yes, but that's only how far I could go in that system. This indirection technique just avoids the keylogger and screenlogger. Keep in mind that one way or the other the information has to get to the browser; there is no way to bypass it. I made my part of the information flow more secure and that's pretty much all I can do.

    But I did NOT use IE... this alone increased security too.

  • Global Warmer (unregistered) in reply to KattMan
    KattMan:
    Global Warmer:
    KattMan:
    Global Warmer:
    I am not a hacker or a security guru so could someone please explain to me why banning SQL keywords as part of your strategy is a bad thing? I realize it should not be your only defense but what is wrong with it being part of it?

    As others have shown, you will be banning valid words. Ban "drop" and when asking for someones favorite song they can't enter a true statement "Drop it like it's hot". Or perhaps if you aren't look for just the single word but any string containing it, then Mr. Andropolis can't get an account with you.

    OK I can see that problem, but isn't it more of a minor inconvenience for really a minimal number of people? I don’t think it would rise to the level of grabbing torches and marching over to the developer’s house in the middle of the night to rid the world of one more moron like some seem to advocate. And no, I have never used this method of security. I am just curious so if I ever do run across a reason to have to implement something.

    Depending on the words you use this "minimal" number of people could grow to be a significant percentage. Remember, one person has the problem, he tells three. All this for soemthing that doesn't even address the issue. You are trying to prevent user entered data from escaping out of a SQL statement and being run like a command. This is resolved by implemeting easy to use parameterized queries; bonus for these is that you piss no one off. Why would you turn away even a small percentage of potential clients when you don't have to?

    Yeah, it was that "Better Ways" part that was escaping me. You're right, I wouldn't want to piss anyone off if I didn't have to, just didn't see that "didn't have to" part Thanks

  • John Rudy (unregistered)

    My favorite is the last one, using the SQL keywords. I had a client whose former developer tried a similar tactic -- they "sanitized" (ahem) every input from the web site.

    Among the no-no words were all of the above, plus my favorite, exec. Since exec was never allowed as input, any user signing up for the site using an e-mail address of execpc.com, executrain.com, etc., was simply denied the ability to sign up -- and therefore the client literally lost business.

    We cleaned up that mess pretty quickly. Especially since all of the SQL input of the site was already encapsulated in parameterized queries.

    Oy!

  • Crabs (unregistered) in reply to Global Warmer
    Global Warmer:
    I have seen that other places too. Taking screen shots and monitoring mouse clicks is a bit tedious don't you think? When do you do it? Constantly? I'm not a hacker but it seems to me that besides the huge burden that could be on the host system and network you would have to go through thousands of screen shots just to find the one were the user is entering the desired info. Once you find it you then have to match up clicks from the same moments while praying they don't move the input screen or maximize it or flip over to their IM screen in the middle make some clicks then flip back etc. Like I said, I’m not a hacker so maybe it is easier then I am thinking but I don’t think so.

    How about this for a trojan?:

    1. Monitor connections to this logon page (and others like it)
    2. When connected, on every mouse click, take screen shot, send to offshore server.
    3. ?????? (and I think we can answer the question)
    4. Profit!

    Lets look at the easy things to do: Hook into IE and figure out what its connecting to. Check. Figure out when the mouse is clicking. Check. Taking a screen shot. Check. Sending it. Check.

    Of course, it's a pretty targetted trojan, as it will only work on sites like the ones described above. But there's nothing really stopping someone from rolling this into their own keyboard logger.

  • (cs) in reply to ST
    ST:
    No disrespect my friend, but I would not let you use my computer to check your e-mail!
    No problem, I don't intend to anyway :) Not that I could, we can even be in different continents. I think I have some friends nearer.

    I forgot to mention when I wrote it that I was thinking of a worst-case scenario - a lan-house PC, AKA virus colony. If I was in your house I supposedly know you as I knew my friend, then I can trust you enough to skip the whole USB search.

  • (cs) in reply to Global Warmer
    Global Warmer:
    I am not a hacker or a security guru so could someone please explain to me why banning SQL keywords as part of your strategy is a bad thing? I realize it should not be your only defense but what is wrong with it being part of it?

    It just misses the point. You need to properly prepare/escape the query before you run it. If you do that correctly it doesn't matter what the input is, so there is no point in banning SQL keywords, and your database will be perfectly capable of handling little bobby tables, little jimmy delete where, and little suzy update.

    Banning keywords is a pain anyway. Inevitably there will be a person who will want to use one of them, and will grow incensed because they can't.

  • (cs) in reply to John Rudy
    John Rudy:
    My favorite is the last one, using the SQL keywords. I had a client whose former developer tried a similar tactic -- they "sanitized" (ahem) every input from the web site.

    Among the no-no words were all of the above, plus my favorite, exec. Since exec was never allowed as input, any user signing up for the site using an e-mail address of execpc.com, executrain.com, etc., was simply denied the ability to sign up -- and therefore the client literally lost business.

    We cleaned up that mess pretty quickly. Especially since all of the SQL input of the site was already encapsulated in parameterized queries.

    Oy!

    The Clibuttic Mistake

  • Paula Bean (unregistered) in reply to snoofle
    snoofle:
    Smash King:
    A while ago I had to use a friend's computer because my connection was down. He had an antivirus and he is not the sort of screw-up that plays around malware-ridden sites. Yet when I had to enter my mail password, I typed every keyboard character onto notepad and went back and forth copy-pasting them on my webmail password field, and not on the correct sequence. Sometimes I used the mouse, sometimes the keyboard. I would copy a string where only two separated characters mattered to me, then place the cursor between them and hold Del (single keystroke) until they were together. Anyone trying to recreate my password would have to log all my activity very carefully.
    With all due respect to your diligence, if you do this on a FRIENDs computer, what do you do when using the computer of a less trusted individual?

    We have just implemented this as a new security measure in our shop, means were 100% safe and secure....and thats a price were prepared to pay for the improved efficiency of our staff....

  • (cs) in reply to Aaron
    Aaron:
    Leak:
    Bah humbug.

    Just drop the Little Bobby Tables attack into the password field and you can use ";--" all you want...

    Thanks for the reference. We've only seen it 537 times on this site so far, so people might have started to forget.
    Glad to be of service. I'll be here all week...

    np: Amon Tobin - The Killer's Vanilla (Foley Room)

  • Harrow (unregistered) in reply to Aaron
    Aaron:
    Leak:
    Bah humbug.

    Just drop the Little Bobby Tables attack into the password field and you can use ";--" all you want...

    Thanks for the reference. We've only seen it 537 times on this site so far, so people might have started to forget.
    You counted them??!!

    -Harrow.

  • Peets (unregistered) in reply to Aaron
    Aaron:
    Leak:
    Bah humbug.

    Just drop the Little Bobby Tables attack into the password field and you can use ";--" all you want...

    Thanks for the reference. We've only seen it 537 times on this site so far, so people might have started to forget.

    It obviously was a good joke - it keeps re-appearing :-)

  • Victor (unregistered)

    TRWTF is these people believing parametrized queries makes you safe, there is always a moron who would use exec inside the stored procedure to build the query dynamically...

    Now, from experience don't say anything in a job interview, just go with the "official microsoft answer": parametrized queries (tm)

  • Zap Brannigan (unregistered) in reply to Global Warmer
    Global Warmer:
    Coincoin:
    Global Warmer:
    I am not a hacker or a security guru so could someone please explain to me why banning SQL keywords as part of your strategy is a bad thing? I realize it should not be your only defense but what is wrong with it being part of it?

    Because it's like lining the inside of an armoured tank with paper.

    It adds complexity and pisses of the users for absolutely no gain compared to actually preventing the keywords from doing damage.

    Now that makes sense to me.... thank you

    Pissing off users for absolutely no gain is Sysadmin 101.

  • Channel6 (unregistered) in reply to m0ffx
    m0ffx:
    Evidently they've never heard of the latest feature in that 'special software' - monitoring mouse clicks and taking screenshots.

    Is that sarcasm or are you for real? Is there really malware that does this?

  • (cs)

    All this fancy "security" and they're still hard-coding the opening and closing quotes instead of using a QuotedStr()-like function to quote the string, doubling any internal quotes*.

    *Which a parameterized query would do automatically, anyways. But that's too easy...

  • The Hackers (unregistered)

    Smash King: Trust us, we don't give a fsck about your webmail password.

    There are tens of thousands of people falling for phishing scams every day, and giving up credit card data.

    Hell, there are hundreds of people still falling for the Nigerian Prince scam. What makes you think anyone cares about your hotmail account?

  • Zach Bora (unregistered) in reply to m0ffx
    m0ffx:
    Also from Lincoln County Credit Union's site:
    Why can’t I use my physical keyboard to enter my password/PIN?

    The Password/PIN must now be entered using your mouse. The on-screen keyboard is used to prevent possible hackers from getting passwords while using special software designed to monitor keyboard strokes.

    Evidently they've never heard of the latest feature in that 'special software' - monitoring mouse clicks and taking screenshots.

    I was playing some mmorpg the other day. The login screen is a normal one with user/pass but to enter the game, you need to put a 4 digit code on your character. The digits are aligned on the screen and you have to click the numbers with your mouse. These numbers are sorted randomly and each time you click, they reorder themselves.

    I still haven't understood why the characters/toons are "secure" but not the account.

    CAPTCHA : bene

  • (cs) in reply to Aaron

    Maybe the site should have a dropdown of obligitory responses including various xkcd strips and stuff about wooden tables.

  • (cs) in reply to RayMarron
    RayMarron:
    *Which a parameterized query would do automatically, anyways. But that's too easy...

    Huh? I always thought prepared statements would NOT be combined together to one query if the dbms is capable of handling these. So there would be no quote doubling/escaping. It's just sent as "additional" data in the packet, the query having those values replaced by ? or a smiliar replacement.

    Of course, if the dbms can't handle those prepared statements, somewhere they have to be combined together with their values into one query.

  • Asiago Chow (unregistered) in reply to oldami
    oldami:
    All this password by mouse and the absurd copy and paste excersize is mostly a waste of time. Any good malware (is that an oxymoron) will simply hook into IE and capture the data that gets posted.

    The better mouse-based password entry systems combine OTP and CAPTCHA characteristics to make something that is easy enough for humans to bypass (so it won't keep your girlfriend or pissed off helpdesk staff out) but are fairly challenging to automate (so they slow down the massive automated attacks that represent the real risk at this point). Not a waste of time. Copy paste tricks will slow your boyfriend with the hardware keylogger but aren't going to stop anyone.

    Regarding the keyword list... I have no idea whether they actually did that for security or not. "Security" has market value in some realms. It's like the "no guns" signs you see in store windows in some areas -- nobody who is planning to commit a crime with a gun is going to be bothered by a "no guns" sign, but some store actually spent money to put up that sign thinking it would improve their bottom line. Why? Because they thought their customers would perceive the store as being more secure and would be more likely to shop there. That can even apply to security measures that actually interfere with the customers. Sort of the "everybody take off your shoes for the TSA" approach to security. So long as they block only whole words ('in' not 'indiana') it isn't even a huge bother.

  • Thunder (unregistered) in reply to tgape
    tgape:
    The second example is a classic example of 'trying too hard'. For that code, any username with a ' character in it will cause problems, so just ban the lot of them. Of course, I tend to be more draconian, and also ban ", \, ,, ., and any other special character that seems interesting to me. (Actually, to be technical, I *allow* alphanumeric, underscores, and, depending on the system and field, maybe dashes and/or spaces. If it's for international use, I'll also allow unicode characters which are not part of the standard 7-bit ASCII set - but I'm only generous there because I haven't heard of any of those being exploitable.)
    Wow. I'm glad you're not programming my web site. Maybe next time, you'll try query bindings...
  • (cs)

    There is nothing steamier than a hot sequel injection! Just turns me on thinking about it.

  • nullptr (unregistered)

    Actually, yeah, NULL.

    ' UNION SELECT login, passwd, NULL, NULL FROM users --

    is a great way to leak information from a database. Still an asinine defense, though.

  • gamers2000 (unregistered) in reply to Harrow

    select (*) FROM articles where columns like '%');%'

    Oh wait.

  • A. Cube (unregistered) in reply to Global Warmer
    I realize it should not be your only defense but what is wrong with it being part of it?

    Because if you have done your job properly (sanitize/escape data), it is completely irrelevant what keywords are used and it is a huge annoyance to the user to be unable to use commonplace words.

  • gamers2000 (unregistered) in reply to Harrow
    Harrow:
    Aaron:
    Leak:
    Bah humbug.

    Just drop the Little Bobby Tables attack into the password field and you can use ";--" all you want...

    Thanks for the reference. We've only seen it 537 times on this site so far, so people might have started to forget.
    You counted them??!!

    -Harrow.

    select (*) FROM articles where columns like '%');%'

    Oh wait.

    (Sorry about double post,quoting phail)

  • (cs) in reply to The Hackers
    The Hackers:
    Smash King: Trust us, we don't give a fsck about your webmail password.

    There are tens of thousands of people falling for phishing scams every day, and giving up credit card data.

    Hell, there are hundreds of people still falling for the Nigerian Prince scam. What makes you think anyone cares about your hotmail account?

    Why do you write in plural? Do you have multiple-personality issues? Or do you want to give the impression that you're a part of a fearful #4x0R group instead of a simple lame script kiddie (if that at all)?

    As for my webmail password, it may be little value for you, but it is quite important to me. Important enough to make me spend 40 seconds on this little measure. Besides, email accounts are used for other purposes other than communication with an old college friend; the information in it could be valuable enough to be worth those 40 seconds; and my password might be used in other authentication systems.

  • Thunder (unregistered) in reply to Zach Bora
    Zach Bora:
    m0ffx:
    Also from Lincoln County Credit Union's site:
    Why can’t I use my physical keyboard to enter my password/PIN?

    The Password/PIN must now be entered using your mouse. The on-screen keyboard is used to prevent possible hackers from getting passwords while using special software designed to monitor keyboard strokes.

    Evidently they've never heard of the latest feature in that 'special software' - monitoring mouse clicks and taking screenshots.

    I was playing some mmorpg the other day. The login screen is a normal one with user/pass but to enter the game, you need to put a 4 digit code on your character. The digits are aligned on the screen and you have to click the numbers with your mouse. These numbers are sorted randomly and each time you click, they reorder themselves.

    I still haven't understood why the characters/toons are "secure" but not the account.

    CAPTCHA : bene

    the idea here isn't security, it's to prevent automated/bot logins.

  • Lance (unregistered) in reply to JR

    Why not

    base64_decode(base64_decode(base64_encode(base64_encode($sensitive_string))))

    Double-encoding works so much better.

  • (cs) in reply to tgape
    tgape:
    If it's for international use, I'll also allow unicode characters which are not part of the standard 7-bit ASCII set - but I'm only generous there because I haven't heard of any of those being exploitable.)

    Overlong UTF-8 sequences. Google them.

  • (cs) in reply to Juifeng

    Prepared statements won't, but the results of those statements might.

    If the user inputs '; DROP DATABASE--

    Your code looks like this:

    $SQL = "SELECT * FROM users WHERE name LIKE '@INPUT';"
    Run($Sql)
    

    Yes, @INPUT becomes properly escaped and passed into the database as a single string, '''; DROP DATABASE'

    BUT what if instead of a direct SELECT, you ran a stored proc:

    Procedure SelectUsers (@Input varchar(255))
    AS
    @SQL = 'SELECT * FROM users WHERE name LIKE ' + @Input + ';'
    EXEC(@SQL)
    

    You have the same problem all over again. SELECT * FROM users WHERE name LIKE ''; DROP DATABASE-- ';'

    Alternatively, you also risk having a replay attack. Basically, someone puts something harmful into a field that will be accessible by others. Say the tagline underneath someone's avatar. They put in as their tagline "<script>MASSIVE XSS BUMREAM</script>". Or they put in a Bobby Tables, and then start looking for other insecure stored procs in your system.

    Let's say their favorite fruit is ';--DROP DATABASE, and you've made sure that your user-entering fields are properly parametarized. So when he updates his profile with the Evil Fruit, it's saved OK and doesn't trigger anything. Then he hits the button that says "Find all users with the same fruit preference as me", which submits ';--DROP DATABASE to a second stored procedure written by the junior developer, that isn't paramaterized...

    So a double defense is better. Make sure your don't accept harmful stuff (unescaped special characters, etc) to catch everything you know about, and paramaterize EVERYTHING to catch everything you don't know about.

  • (cs) in reply to The Hackers
    The Hackers:
    Smash King: Trust us, we don't give a fsck about your webmail password.

    There are tens of thousands of people falling for phishing scams every day, and giving up credit card data.

    Hell, there are hundreds of people still falling for the Nigerian Prince scam. What makes you think anyone cares about your hotmail account?

    Please to respond with your email address and password to prove your point that no one cares about a webmail account.

  • Luiz Marques (unregistered) in reply to m0ffx
    m0ffx:
    Evidently they've never heard of the latest feature in that 'special software' - monitoring mouse clicks and taking screenshots.

    Shhh, don't give them ideas - one of the banks I use online has an awful system that flashes the actual number codes and turn them into asterisks when your cursor is above them. It also scrambles the numbers between clicks.

    It's incredibly annoying to use!

    My favorite bank now uses hardware tokens... Impossible to capture with a trojan, and the only thing I have to do is not lose them.

  • Dave (unregistered) in reply to m0ffx
    m0ffx:
    Also from Lincoln County Credit Union's site:
    Why can’t I use my physical keyboard to enter my password/PIN?

    The Password/PIN must now be entered using your mouse. The on-screen keyboard is used to prevent possible hackers from getting passwords while using special software designed to monitor keyboard strokes.

    Evidently they've never heard of the latest feature in that 'special software' - monitoring mouse clicks and taking screenshots.

    Perhaps I am missing some sarcasm here. I have seen the mouse-based login before and it is actually very secure. Screenshots wouldn't do you much good unless you were taking several a second. This would cause a noticeable delay on many systems. Capture of mouse clicks could provide some useful information, but would be much harder to parse through than keyboard logs.

  • drop (unregistered) in reply to JR

    Surely, base64_decode(base64_decode(base64_decode(base64_encode(base64_encode(base64_encode($sensitive_string)))))) , would be much more secure!

  • gamers2000 (unregistered)

    while(true) { base64_decode(base64_encode($sensitive_string)); }

    Infinite security. Perfect.

  • EMan (unregistered)

    I'm confused... It seems to me that base64 encoding the table entries would prevent SQL injection. Granted it does so in the weirdest and most roundabout way ever, but it would work, wouldn't it?

  • PG (unregistered) in reply to halcyon1234
    halcyon1234:
    So a double defense is better. Make sure your don't accept harmful stuff (unescaped special characters, etc) to catch everything you know about, and paramaterize EVERYTHING to catch everything you don't know about.

    Nope.

    You beat the living sh*t out of your devlopers that don't use prepared statements, and DBAs that allow SPs that create strings and exec them like that.

    Code reviews ever heard of them?

  • Dustin (unregistered) in reply to JR

    Wait -- wouldn't this be more secure?

    base64_decode(base64_decode(base64_decode(base64_encode(base64_encode(base64_encode($sensitive_string))))))

  • Franz Kafka (unregistered) in reply to halcyon1234
    halcyon1234:
    Let's say their favorite fruit is ';--DROP DATABASE, and you've made sure that your user-entering fields are properly parametarized. So when he updates his profile with the Evil Fruit, it's saved OK and doesn't trigger anything. Then he hits the button that says "Find all users with the same fruit preference as me", which submits ';--DROP DATABASE to a second stored procedure written by the junior developer, that isn't paramaterized...

    So a double defense is better. Make sure your don't accept harmful stuff (unescaped special characters, etc) to catch everything you know about, and paramaterize EVERYTHING to catch everything you don't know about.

    how about you just ban unparameterized queries? I know, some places don't even use source control, but rejecting code out of hand unless it uses parameters solvers this side of the problem. Stripping html out of stuff that other users will see, or using a filter that only allows specific markup fixes the xss attack.

  • (cs) in reply to Victor
    Victor:
    TRWTF is these people believing parametrized queries makes you safe, there is always a moron who would use exec inside the stored procedure to build the query dynamically...

    Now, from experience don't say anything in a job interview, just go with the "official microsoft answer": parametrized queries (tm)

    Parameterized queries makes you safe from users. They can not make you safe from your own moronic coders that would exec a query in a stored proc.

    The point here is to protect you from malicious users. Code reviews are supposed to protect you from the idiots you hire.

  • xtremezone (unregistered) in reply to JR
    JR:
    I wonder why the coder responsible for the first example didn't see fit to increase the security in the same way that he created it. After all, the following routine would be twice as effective:

    base64_decode(base64_encode(base64_decode(base64_encode($sensitive_string))))

    And even more secure:

    base64_decode(base64_encode(base64_decode(base64_encode(base64_decode(base64_encode($sensitive_string))))))

    Genius stuff, surely.

    It's been a while since I've written PHP (and I'm assuming it's PHP) so bare with me...
    /*

    • You can never be secure enough. Recommend security level
    • no less than 999. */ function make_sensitive_string_safe($sensitive_string, $security_level = 0) { $sensitive_string = base64_decode(base64_encode($sensitive_string)); if($security_level > 0) make_sensitive_string_safe($sensitive_string, --$security_level); return($sensitive_string); }
    (Untested :P)

    <sarcasm/>

  • xtremezone (unregistered)

    Ah, forgot to assign the result back to the variable (and I wonder if 999 would be enough to overflow the stack in typical operation...). :-[ You get the point.

  • (cs) in reply to JR

    Do you really think that would solve anything? My guess is that he hoped the encoding process would be vulnerable to the same sort of error, without access to the SQL database, and would only return the part of the string that did not contain the SQL injection. The following decode line is so that the rest of the password is readable in its original form. Doing that over and over again would add nothing.

  • Fedaykin (unregistered)

    Parametrized queries are not rocket science. In fact, using them is vastly easier than all the attempted hacks to prevent injection attacks.

    Nothing pained me more than when I first Googled "prevent SQL injection" several years ago and the first several pages of results had morons suggesting trying to sanitize input and other stupid hacks.

  • php guy (unregistered)

    seems like most of the problem lies in selecting the username and password at the same time. with php i generally do:

    $username=$_POST['username']; $password=$_POST['password']; $password_md5=md5($password); $db_val=getPass($username); //getPass: select password from users where username=$username //the query can't be broken via injection

    if ($password_md5 == $db_val ) { $_SESSION['authenticated']=true; }

  • Brent Seidel (unregistered) in reply to EMan
    EMan:
    I'm confused... It seems to me that base64 encoding the table entries would prevent SQL injection. Granted it does so in the weirdest and most roundabout way ever, but it would work, wouldn't it?

    This might be true, if the base64 encoded values were stored in the database. However, in the example shown the value is encoded and then immediately decoded, so you wind up stuffing the original value into the database.

  • (cs) in reply to PG
    Code reviews ever heard of them?

    I shudder to think of such a perfect world like that, because then there'd be no more WTFs-- and then what would I do with my time?

  • (cs) in reply to EMan
    Eman:
    I'm confused... It seems to me that base64 encoding the table entries would prevent SQL injection. Granted it does so in the weirdest and most roundabout way ever, but it would work, wouldn't it?

    In theory, yes. At first.

    But it makes the data pretty had to work with. Every time you want to do anything with the data, you'd have to un-encode it.

    Then you'd still be in the same boat, because the unencoded data would be DROP DATABASE, and the minute you try to use it in a query, poof.

    That is assuming your servers don't grind to a halt first from having to encode and decode every piece of data you process. Or if they are able to handle it, you hope your company doesn't grind to a halt because it spent all its money on servers that are spec'd beyond its requirements.

  • dynedain (unregistered) in reply to JR
    JR:
    I wonder why the coder responsible for the first example didn't see fit to increase the security in the same way that he created it. After all, the following routine would be twice as effective:

    base64_decode(base64_encode(base64_decode(base64_encode($sensitive_string))))

    And even more secure:

    base64_decode(base64_encode(base64_decode(base64_encode(base64_decode(base64_encode($sensitive_string))))))

    Genius stuff, surely.

    Actually, that would be a great way to "improve" the performance of your web app. Throw in a bunch of layers of encoding/decoding. Then, when the client complaigns it's too slow, remove a couple layers of the encode/decode. Voila! Instant 'optimization' and speed improvements!

Leave a comment on “SQL Injection Protection * 3”

Log In or post as a guest

Replying to comment #:

« Return to Article