Please create an account to participate in the Slashdot moderation system

 



Forgot your password?
typodupeerror
×
PHP Programming Software Apache IT Technology

PHP and SQL Security 305

An anonymous reader writes "PHP and SQL Security are being proven more weak every day. Uberhacker.Com is running a PHP and SQL security research project to raise awareness of secure scripting. The site hosts guides to secure PHP programming, forums, and scripting challenges to see who can create the most secure scripts."
This discussion has been archived. No new comments can be posted.

PHP and SQL Security

Comments Filter:
  • by enrico_suave ( 179651 ) on Tuesday April 27, 2004 @11:01AM (#8984140) Homepage
    or even a security site =) but I agree, totally.

    and to boot are they running php as a CGI instead of a module?

    *shrug*

    e.
  • by sczimme ( 603413 ) on Tuesday April 27, 2004 @11:05AM (#8984208)

    Or would you blame the workman who cuts off his arm with the buzz saw's totally unprotected blade?

    Yes, I would: he was obviously doing something with the saw that was inappropriate; what saw-oriented task [when done correctly] involves waving it at one's own arm?* The fact that the blade was unprotected is irrelevant since he should have known it was unprotected and therefore dangerous. All tools can be used stupidly, and oddly enough the results really can be the fault of the operator. It is also possible for fault to lie in more than one area.

    Yes, I know the traditional definition of 'hacking' includes making $ITEM do something it was not intended to do, but there are limits.

    * I'm guessing that 'buzz-saw' == 'circular saw'.
  • by Anonymous Coward on Tuesday April 27, 2004 @11:14AM (#8984314)
    It is an economic fact of life. People will always be learning in the job. We will never have a guaranteed level of expertise, let alone competence. Tools will have to start enforcing security. Humble coders have been dealing in overflows, SQL injection, and cross-site scripting forever. Tools that manage buffer/stack overflows are not just for junior programmers. Tools/frameworks that add taint checking and build-in automagic security (like ASP.Net's validaterequest). If we have to rely on all the programmers becoming competent experts we will never have security.
  • Crap site (Score:3, Interesting)

    by pommaq ( 527441 ) <straffaren@sPLAN ... minus physicist> on Tuesday April 27, 2004 @11:14AM (#8984323) Homepage
    Yes, that guide to secure scripting was very useful - a "hello world" program. Whoopee. To be frank, that site looked... well, less than professional, and with a name like "uberhacker" I expected their tips to be a little more advanced than "look, you can change the values in a query string but don't tell anyone!!!!11"

    That being said, I used to write a lot of PHP (I rarely do it anymore at work, but I still try to keep up with the language) and when I first started out I would have loved a comprehensive and easy-to-understand guide to common security holes. The world needs a simple "how to write security-conscious code" for beginners! The sooner you get to see stuff like SQL injection or XSS in action, the better.
  • Input verification (Score:3, Interesting)

    by ZeroExistenZ ( 721849 ) on Tuesday April 27, 2004 @11:24AM (#8984447)
    Think it was just a "look at my cool site, try to slashdot that one!" kindof 'article'.


    So far the most "unsafe" aspect with PHP / SQL setups is poor input validation;

    If you allow direct writing to your SQL and don't do sufficient checks on the input, well.. you'll get in probs with that.

    Proof of concept;
    Hello.. enter your email for free porn: sucker@hotmail.com '; DROP TABLE 'emails';

    Or you have those pages who mess up or display info which can be abused (and / or shouldn't be on that particular page) after there's a "<blockquote>" injected and redisplayed without checking..
    Same with <input type=text>

    Then.. there's JS, and htmlentities, and, and..
    All caffeine intense, and headache inducing subjects you should keep in mind if you plan on bringing something on wire.

    "Nah.. you don't have to do that.. Who's going to know how to do that?"
    "Trust me.. You want me to put in that extra code.."
    "If you really say so.."

    You also have stupid defaults, and uninspired [google.com] coding which gets abused, ofcourse...

    I actually like the PHP / SQL combination and believe it to be safe enough for what I do with it.

  • by l0ungeb0y ( 442022 ) on Tuesday April 27, 2004 @11:37AM (#8984639) Homepage Journal
    Sh!t PHP coding is as old as the hills.
    Some of my favorite things I see _ALL_ the time:

    Something bad happens while executing the code?
    Let's <? die("here's my database connection info in case you wanted it"); ?>

    Then there was the client who's previous developer was some moron who stored the database connection info into a .inc file under htdocs!

    The web "design" group who's MySQL database was wide open without authorizing with a password.

    The arsehole developers who built themselves little backdoor webpages during development to exec shell commands and upload/exec files ... not so much as an HTTP_AUTH to secure it with and would handily chmod 777 all uploaded files and put them under htdocs for ease in execution.

    I've seen about 3 websites store credit card numbers unencrypted into a MySQL database.

    I could go on and on and on, being a development gun for hire since 98, I've seen some things that defy all logic and explanation. In fact, I still wonder why they call it Computer Science. Now, Computational Arts I could buy into.
  • Re:magic_quotes (Score:3, Interesting)

    by drew ( 2081 ) on Tuesday April 27, 2004 @12:18PM (#8985186) Homepage
    that might be a good solution if it was the right way to escape quotes in most databases. what databases use \' other than mysql? in my experience, the correct way to escape a ' on oracle, ms sql, sybase, postgresql, etc. is ''. this drives me crazy at work, because for some unknown reason, we actually have magic_quotes enabled, so i have to strip_slashes, _and_ properly escape my quotes. grr....

    at least with PEAR::DB now, i can finally do:
    $db->query(select * from foo where a = ?", $a)
    and not worry about it- the way it should have been all along.
  • theory vs practice (Score:3, Interesting)

    by kpharmer ( 452893 ) * on Tuesday April 27, 2004 @01:20PM (#8986049)
    > Security does not belong in the database because it removes context of action.

    aha

    Well, rather than debate whether or not the data should be persisted in the context of its rules and actions (which doesn't work in reporting, btw), lets get down to what simply works.

    You need to plan on including security awareness within each layer and component of your architecture. Since we've moved beyond client-server we seldom now authenticate & authorize individual users in the database. That's fine, but locking down the data should still be done in any database, even if the granularity is now at the application level rather than the individual.

    The difference between today and ten years ago is that we're now mostly implementing database security at the application level of granularity.

    Here's a trivial example:
    - 20 users are in ldap group finance
    - all are also in ldap group report
    - 10 are also in ldap group invoice
    - 4 userids are used by the database:
    - userid invoice has ownership privs on invoice schema
    - userid gl has ownership privs on general ledger schema
    - userid fa has ownership privs on fixed-asset schema
    - userid report has read privs on above schemas
    - The invoice application will authenticate users via ldap service
    - The invoice application will use ldap service to authorize users using either report or invoice group depending on what the user attempts to do
    - The application(s) will connect to the database using either appropriate database userid. This will be used by database to ensure that invoice application does not attempt to write to general-ledger schema, etc.

    This isn't the end of your security concerns in the database. You've also got to lock down all your file systems, ensure that no users can create new database objects, etc, etc. That's also fairly straight-forward.

    Anyhow, don't get all hung up about where security must go - or in the interests of some kind of misguided purity you'll end up leaving giant gaping holes in your defenses. Implementing security at the application level of granularity is both simple and effective. Take advantage of it.

  • Re:Bind variables (Score:2, Interesting)

    by mal3 ( 59208 ) on Tuesday April 27, 2004 @04:54PM (#8989298)
    Not really, but given the content of the article I assume it's a problem.

    I don't doubt there may be more examples of bad ASP in the wild, but that has more to do with developer skills than anything else. PHP developers as a whole are probably more skilled than their MS counterparts. That's not the fault of the language though, and it's certainly not the fault of the RDBMS. ASP against any other database server would be just as bad.

    Why do you hate SQL Server so much?

    Here's an example of "Bind variables" courtesy of MS. Not what I'd call hard, but it is a little more involved than your example above. JSP does it in much the same way.

    Dim cn As New ADODB.Connection
    Dim cmdPrep1 As New ADODB.Command
    Dim prm1 As New ADODB.Parameter
    Dim prm2 As New ADODB.Parameter
    Dim strCn As String

    strCn = "Server=MyServerName;Database=pubs;Trusted_Connect ion=yes"
    cn.Provider = "sqloledb"
    cn.Open strCn
    Set cmdPrep1.ActiveConnection = cn
    cmdPrep1.CommandText = "UPDATE titles SET type=? WHERE title_id =?"
    cmdPrep1.CommandType = adCmdText
    cmdPrep1.Prepared = True

    Set prm1 = cmdPrep1.CreateParameter("Type", adChar, adParamInput, 12, "New Bus")
    cmdPrep1.Parameters.Append prm1

    Set prm2 = cmdPrep1.CreateParameter("ProductID", adInteger, adParamInput, 4, 3)
    cmdPrep1.Parameters.Append prm2

    cmdPrep1.Execute

    cn.Close

Beware of Programmers who carry screwdrivers. -- Leonard Brandwein

Working...