Slashdot Mirror


Secure Programmer: Keep an Eye on Inputs

An anonymous reader writes "This article discusses various ways data gets into your program, emphasizing how to deal appropriately with them; you might not even know about them all! It first discusses how to design your program to limit the ways data can get into your program, and how your design influences what is an input. It then discusses various input channels and what to do about them, including environment variables, files, file descriptors, the command line, the graphical user interface (GUI), network data, and miscellaneous inputs."

157 comments

  1. Hmmm... by Anonymous Coward · · Score: 0

    If you know your inputs, then you know your outputs. This is an important lesson to learn, but most of us already know this...

    1. Re:Hmmm... by ATMAvatar · · Score: 2, Funny

      I'm a little source code, robust and stout.
      Here is my input, here is my out.

      --
      "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety."
  2. Keep your eyes... by Chris_Stankowitz · · Score: 0, Redundant

    on your input!

    1. Re:Keep your eyes... by Anonymous Coward · · Score: 0

      The fact that no one understands you doesn't make you an artist.

      But it will frequently get you a -1 Offtopic.

    2. Re:Keep your eyes... by Anonymous Coward · · Score: 0

      Garbage in.. garbage out. Common sense, right?

      (did not read the article)

    3. Re:Keep your eyes... by Anonymous Coward · · Score: 0

      Sometimes we call these things .sigs

    4. Re:Keep your eyes... by Anonymous Coward · · Score: 0

      The fact that no one understands you doesn't make you an artist.

      You were referring to yourself in that sig, weren't you. Cuz none of us know what the fuck you are talking about.

  3. Dugh by jkirby · · Score: 0, Troll

    Written by a contractor for sure!

    --
    Jamey Kirby
  4. Windows & Belkin by ForestGrump · · Score: 1, Interesting

    Doesn't windows throw random crap around?
    This unpredictable event seems to screw with programs when the ram is low.

    Also, those microsoft security holes we have seen in the past year of 2003 are no confidence to M$ security.

    Lastly, Belkin routers are no good for security. AFter all, they hijack your http requests and direct you to somewhere you didnt want to go!

    Grump.

    --
    Is it true that more people vote for the winner of American Idol, than vote for the president? -Ali G.
    1. Re:Windows & Belkin by AuMatar · · Score: 4, Insightful

      There are no controls on Windows inputs. Any process can send any message to any other process. Talk about insecure.

      You could probably majorly screw up a progoram by sending it random message numbers. It'd react as if you were sending random menu and other commands. Hmm, that sounds like a fun prank to play...

      --
      I still have more fans than freaks. WTF is wrong with you people?
    2. Re:Windows & Belkin by Anonymous Coward · · Score: 0

      I have gotten my first slashdot freak. My life is now complete.

      Wow, you've got a couple of rare ones. Any chance you're looking to trade?

    3. Re:Windows & Belkin by AtrN · · Score: 2, Informative

      See this paper. I remember reading the original document in (CACM IIRC) and was pleased to see it updated showing just how far "forward" we've come.

    4. Re:Windows & Belkin by Some+Bitch · · Score: 1

      What'll you give me for my homophobe?

    5. Re:Windows & Belkin by ManoMarks · · Score: 1

      I find that baseball bats take care of homophobes really well. Oh wait, you meant in trade...

      --

      That's gotta fit into your schema somewhere

    6. Re:Windows & Belkin by Anonymous Coward · · Score: 1, Insightful

      There are no controls on Windows inputs. Any process can send any message to any other process.

      Well, not quite. There are ways of isolating programs, but it's very rarely useful. (In fact, I've never done it, but I know it's possible.)

      But why bother with all that when you can just install a system-wide hook? It's quite easy to actually inject code into another process. Once you've got that you can muck with data or intercept system calls to your heart's delight.

      What it comes down to is that if you don't want a user to be able to screw up a machine, don't let them install applications and don't give them write access to critical bits of the machine. Untrusted programs should be quarantined.

      You could probably majorly screw up a progoram by sending it random message numbers. It'd react as if you were sending random menu and other commands.

      If you can mess up a program doing that then you've got bigger problems. If the user can crash it then what difference does it make than an external program can as well? It can be crashed, deliberately if given the opportunity.

    7. Re:Windows & Belkin by kasperd · · Score: 2, Informative

      Any process can send any message to any other process. Talk about insecure.

      Accourding to http://security.tombom.co.uk/shatter.html it is much worse than just that. Not only can anyone send such a message, but the messages can even force the receiver to execute arbitrary code.

      --

      Do you care about the security of your wireless mouse?
    8. Re:Windows & Belkin by cb8100 · · Score: 1

      "There are no controls on Windows inputs. Any process can send any message to any other process." While this is somewhat true, it is possible (and I wish more people realized this) to parse and look for appropriate messages to your application (I cut my teeth with Visual Studio on Win 9x). I stumbled across this quite by accident while trying to find a way to make an edit field accept hexadecimal values (of course VS doesn't offer that filter, so I had to write my own). Anyway, back to the original topic, 1) everyone should check his program's inputs and 2) always check for buffer overflows (*nudge nudge* Microsoft).

      --
      My lack of God, it's Trotsky!
  5. Hmmmm by Anonymous Coward · · Score: 0

    That goes against my ideas that you should allow any type of data to enter your program anywhere, anytime.

  6. then how will by OffTheLip · · Score: 0, Offtopic

    Microsoft products such as Outlook make the news? Garbage In Garbage Out.

  7. If you input ever displays as HTML by Anonymous Coward · · Score: 2, Insightful

    You'd be wise to add Cross Site Scripting attacks to your list of things to protect against.

    1. Re:If you input ever displays as HTML by borkus · · Score: 5, Insightful

      A big issue for many web programmers is failure to realize that forms and web interfaces that you provide the user aren't the only way to interact with your application. A lot of them pay attention to JavaScript validation and maxlength attributes rather than check the data on the server.

      New developers working on applications open to the internet often aren't used to developing in an evironment where programmers that don't work for their employer can access their app. All it takes for one dishonet person who knows slightly more than you to hack your app.

    2. Re:If you input ever displays as HTML by mcrbids · · Score: 4, Informative

      forms and web interfaces that you provide the user aren't the only way to interact with your application.

      So true, so true. For example (in PHP)

      <?
      if ($login='Admin' && $pass='19ak129')
      $secure=true;
      if ($secure)
      { // do something very important.
      }
      ?>

      In many cases this script's security could be bypassed by adding "&secure=true" at the end of the URL!

      I prefer to generate or define a set of values that are acceptable and check with in_array().

      EG:

      <?
      $acceptable=array('a', 'b','na');
      if (!in_array($acceptable, $_REQUEST[check]))
      die ('Sorry. Input in field "check" is invalid');
      ?>

      Or by using a regex. Assume that the input must be a number:

      <?
      $match="/[0-9]+/";
      if (preg_replace($match, '', $_REQUEST[number]))
      die ('You must put in a number');
      if (strlen($_REQUEST[number]>5))
      die ('Number you have entered is out of range');
      ?>

      You can oftentimes functionalize these so that it's as simple as:

      <?
      if ($error=Valid_Integer($_REQUEST[number]))
      die($error);
      ?>

      Simple methods that can greatly enhance security!

      --
      I have no problem with your religion until you decide it's reason to deprive others of the truth.
    3. Re:If you input ever displays as HTML by WoTG · · Score: 2, Informative

      Yeah, web applications were a mess, and bloody complex to do rather basic tasks. Fortunately, most platforms are getting better, and more conservative with age. For example, your PHP URL trick wouldn't work in a recent default installation of PHP where "register_globals" (the automagic system that makes all variables from HTTP POST, URL's, cookies, and sessions all the 'same') is "Off".

      I guess the moral of the story is that the web is young, and web platforms are even younger. With any luck, many of these headaches will disappear with time.

      BTW, anyone know of some magical code to block SQL injection vulnerabilities?

    4. Re:If you input ever displays as HTML by GAVollink · · Score: 2, Informative

      Magical!? Yes. It's really easy in fact. Simply do NOT use direct user input within an SQL statement. That seems really restrictive but it's not - it simply requires that you push back CHOICES to the user in creating your form... all sara john ...then you use the values (validated to be only numbers) to back-fill your SQL statement. If you are really feeling risky, then at the very least make sure that every character you recieve is [A-Za-z0-9 ], length verify it to make sure it matches the lenght of your field, and reject anything with single or double quotes embedded. It's not magic, it's... programming.

    5. Re:If you input ever displays as HTML by critter_hunter · · Score: 2, Interesting

      The option to register global variables is off by default since PHP 4 and for a very good reason: it's potentially insecure, as you demonstrated, and it also creates very sloppy code. Ever tried to debug a program you haven't written that uses those? You get variables that have never been declared being used, and it can be a pain to determine where exactly they come from. From an included file? $_POST? $_GET? Then you can get conflicta and it becomes an horrible mess - I can't understand why register_globals is an option, much less why it was the *default*

      --
      Karma: Could be worse (could be raining)
    6. Re:If you input ever displays as HTML by Admiral+Burrito · · Score: 3, Informative
      BTW, anyone know of some magical code to block SQL injection vulnerabilities?

      Use placeholders. PEAR DB supports them, as do other database abstraction layers. As long as you _always_ use placeholders you will be safe against SQL injection.

      If you can't depend on PEAR DB (or similar) to be installed / at the correct version, you could quickly build yourself a function that takes a variable number of arguments: a SQL statement containing '%s' (for strings) or %d (for numerics) followed by potentially hostile arguments. Run each of the arguments through mysql_escape_string (or equivalent for your DB) then build your SQL statement using sprintf. Note: I haven't tested that approach; use with caution.

    7. Re:If you input ever displays as HTML by JohnnyBigodes · · Score: 1

      You're nuts if you use auto-global variables in PHP like that.

      Use $_GET,$_POST,$_COOKIE,$_SESSION, etc. They're your friends. No more URL-hacking fun.

    8. Re:If you input ever displays as HTML by smartfart · · Score: 2, Informative

      Not to ignore the rest of your comment, but wouldn't initially setting $secure to a null value solve that problem?

      <?
      unset($secure);
      if ($login='Admin' && $pass='19ak129')
      $secure=true;
      if ($secure)
      { // do something very important.
      }
      ?>

    9. Re:If you input ever displays as HTML by Anonymous Coward · · Score: 0

      Even in your other examples, $error equals something (even if it is a result of a function call) can be bypassed by adding "&error=0".

      It is an issue of register_globals being on that creates the vulnerability, you imbecile.

    10. Re:If you input ever displays as HTML by Rich0 · · Score: 1

      I've seen this sort of thing at work all the time. Applications which rely on security through obscurity - I point out to the developers that the factors that they consider secret are in fact easy to find out and the usual response is that nobody else would think of that.

      In a controlled network environment in which the cost of tampering with the data is relatively small the most important requirement is traceability - if somebody breaks in you just fire them. On the other hand, if an internal hacker can get $500 million transferred to a swiss account by hacking into the code and leave the country before getting caught, knowing who did it is of less value.

      Personally, my feeling is that while you don't need to make internal apps completely bulletproof, internal developers need more awareness of security issues so that when they have a fundamental design choice to make, they can make the choice that makes the software more secure. You don't need to spend millions of dollars to make an application reasonably secure...

    11. Re:If you input ever displays as HTML by dkf · · Score: 1

      > Use placeholders.

      Excellent advice. Those of you looking for the Java term for this sort of thing should be looking for PreparedStatement. If your DB doesn't support anything like that, get a better DB.

      --
      "Little does he know, but there is no 'I' in 'Idiot'!"
  8. And code reviews, code reviews, code reviews by Brahmastra · · Score: 5, Insightful

    I believe code reviews with a large enough group of people to be extremely useful. Yeah, it takes time and you get some irritating comments from a few people about how there is a space between something or comma between something, but when multiple eyes look at it, someone always catches something you didn't. A few hours of extra pain on the side of programmers can prevent pain for millions in the form of blaster viruses, etc.

    1. Re:And code reviews, code reviews, code reviews by Anonymous Coward · · Score: 0

      "Yeah, it takes time" That's right. Time To Market is what really matters. I was always upset with The Military, but they used Tried and Tested schemes. They are outdated, but they work. I read something about NASA or some Govt Agency using an old ADA programming. You know those guys go though umpteen million code reviews, bunch of paperwork to fill out and all. They probably use some old OS. When using the "Latest and Greatest" software, you have to be on the Cutting Edge. It may not work just right and have bugs, but that is why there are Service Packs. When the product is finally right, it is outdated. 3.1, 95, 98, 2000, NT, XP. Every product is like that. If they spent time making it Fully functional and "No Updates", some other competitor will have marketed the product and got revenue while your still in a code review. Regards,

    2. Re:And code reviews, code reviews, code reviews by MurphyZero · · Score: 1

      Here at Cape Canaveral, for the Safety systems, it is taking ages to replace the old systems. But soon (the same thing said for the past ten years) we should be able to get rid of our 50s-70s technology and upgrade to mid 80s technology.

      --
      Our founding fathers removed the guys in charge. Be American. Vote incumbents out.
    3. Re:And code reviews, code reviews, code reviews by smallstepforman · · Score: 1

      The general consensus of code reviews is - well, since it already works, ship it as-is, but do use the following advice for future products. Refactoring the new buzzword which we should be pushing.

      --
      Revolution = Evolution
    4. Re:And code reviews, code reviews, code reviews by Anonymous Coward · · Score: 0

      That's not a code review, that's called "going through the motions."

    5. Re:And code reviews, code reviews, code reviews by Anonymous Coward · · Score: 0

      I agree, and will add that a more mature and effective process also includes requirements reviews and design reviews. Yes, it does take time, but what most people don't understand or believe is that it also saves time. In my experience it saves a surprising and substantial amount of time by eliminating rework and redesign. All in all you do spend more time in developement, but you also end up with a much, much better product. I work on large scale projects, and I can't see myself ever going back to the old 'by the seat of your pants' method; it just seems like an inefficient and obsolete process.

    6. Re:And code reviews, code reviews, code reviews by Anonymous Coward · · Score: 0

      "Time To Market is what really matters."

      You sound like a marketing manager, focusing on one metric and ignoring everything else. You fail to factor in the time saved in rework. You also sound like you don't have a clue how much time that is. While the competitor is working on service packs for pissed off customers, I'll be working on version 2.0.

  9. The more things change.... by billstewart · · Score: 5, Insightful
    One of the first lessons we learned in CS100 was to always validate the input, assuming that it might be bogus or actively malicious. I've been appalled over the last 25 years at the number of products, developers, and companies that don't understand that. Most of the internet security problems we've seen have been from inadequate handling of input data, typically the buffer overruns that are so easy to program in C if you're not paying attention.

    The article's worth reading, and really does justify it's "Level: Intermediate" label. Unlike when I was learning to program, there are lots of sources of input beyond your deck of punch cards (:-), and the author does a good job of explaining many of them, such as evil things that environment variables and file descriptors can be used for.

    --

    Bill Stewart
    New Fast-Compression-only CPR http://preview.tinyurl.com/dy575ks
    1. Re:The more things change.... by agslashdot · · Score: 3, Insightful

      While I agree with you from a theoretical standpoint, I'm sure you are aware why things like this get overlooked in day-to-day corporate IT programming tasks.
      eg. Manager says, write a UI that accepts username & account, and then spits out user transactions . During design phase, you invariably make the code hack-able so its easy to test. ie. I could put in "*" for account and it would spit out transactions of ALL users, regardless of the username. This is a useful backdoor, especially in development time when your UI has to interact with somebody else's data repository in some compplicated fashion.
      Ofcourse, its a given that the input validation logic must be modified and backdoor must be taken out when the UI is actually deployed. But corporate practices being what they are, someone else takes ownership of the code at that stage, and either doesn't understand the "star-feature" ( *) , or thinks its cool to have this in case of emergency debugging, so leaves it there. Soon, this stupid program that should have been running standalone on someone's box, gets a facelift and is shoved on the internet. Some cracker comes along and puts in a star for account & gets all the transactions, & pretty soon, register.co.uk gets wind of this and reports it on front page. by then, original programmer has moved on to some other task, requiring a new back-door :)

    2. Re:The more things change.... by Cragen · · Score: 0, Flamebait
      Yes, CS100 taught us much about the proper way of doing things, [rant] unless, of course, you went to my school, where the CS200 and CS300 projects used none of the code from the required books, none of the ideas of encapsulation or code re-use, & little of the algorithms actually introduced by the books. You see, all the projects were written by TA's (a group of grad students whose level of TEACHING ability ran from excellent to atrocious), and very little of the code in the project or the student submission was actually viewed by the professor. The phrase "mailing it in" would have been too good for the bums "teaching" our CS courses. We pretty much had to teach ourselves the essence of CS, hoping to someday get to the level of prof. that actually "taught" a course. [/end rant]. Nobody said this was easy stuff. Happy New Year to all.

      *cragen

    3. Re:The more things change.... by borgboy · · Score: 2, Informative

      Maybe the testing methodology you cite isn't so useful then, if you have to change your code when you're done testing. Backdoors are only bad if you put them in in the first place. Test First Design might be a better approach than Code an insecure backdoor as a test.

      --
      meh.
    4. Re:The more things change.... by fermion · · Score: 2, Insightful
      And the second thing I learned was to do things once and do it right. This means that input should happen in one place, the function should make sure the input will fit in the allocated space and contain only the proper data, and may even take an argument for the maximum size the calling fuction expects.

      What amazes me is that people try to optimize thier code by carefully minimizes thier input fuction. It is input. Input is slow. Go somewhere else to optimize. Create a good input fuction and leave it alone.

      The third thing I learned was to write a good validitating layer for memory allocation in C. Used as debug tool, it discover all most of the little memory problems that inevitable creep into C, as well as some buffer overflows. I know people bitch about how screwed up C is, but with the proper debug tools I had few problems.

      --
      "She's a scientist and a lesbian. She's not going to let it slide." Orphan Black
    5. Re:The more things change.... by glenebob · · Score: 1

      >> I know people bitch about how screwed up C is, but with the proper debug tools I had few problems.

      I'd say you had few problems because unlike so many in this business, you actually fathom the concept of validation, and know how to use C without letting it walk all over you. I don't know why that's difficult but apparently it is...

    6. Re:The more things change.... by Rich0 · · Score: 2, Funny

      The last time I checked coders in corporations got promoted for churning out the largest number of apps with the largest number of features in the shortest amount of time. The people who promote them are legitimate users of the application so they don't think to try to break it and see what happens. The security break-ins occur years after the original coder is gone.

      Besides - leaving some small holes in your code guarantees future work - which is hard to come by in this day and age.

  10. Re:file this under: by Anonymous Coward · · Score: 0

    Yes, they did (for those working for Microsoft).

  11. No inputs = useless? by whereiswaldo · · Score: 1

    A truly "secure" program would have no inputs, but that program would be useless.

    Not necessarily. What about a program which calculates pi or runs some kind of simulation? The 'input' is in the form of constants compiled into the executable. Technically there is no input, but the program is hardly useless.

    1. Re:No inputs = useless? by Anonymous Coward · · Score: 0

      It is secure unless someone goes after the memory locations of the constants

    2. Re:No inputs = useless? by Gherald · · Score: 1

      > What about a program which calculates pi or runs some kind of simulation?

      Ok, so maybe he failed to specify that such a program would be *relatively* useless.

      What good is a program that calculates pi if you cannot specify how many digits?

      What good is a simulation if you cannot specify which parameters to use, and how long you want to run it?

      Answer: not very good

    3. Re:No inputs = useless? by chrootstrap · · Score: 1

      A simulation can be perfectly useful though the data and lenght of operation has been hard coded into it. Another useful type of program without input are system monitors and watchdogs -- perhaps specifically for security purposes. If a language makes it quick and easy to create simulations (e.g. the 'R' language) with hard coded parameters, then the desire to reuse a program using different parameters may be lessened.

      --
      Hacking articles at http://www.geocities.com/chroo
    4. Re:No inputs = useless? by Anonymous Coward · · Score: 0

      There is a difference between "user input" and "input." A system monitor would have numerous inputs. Specifically, the system metrics that it is monitoring.

      The original comment is correct - any program that has no inputs whatsoever is unlikely to be found outside of an introductory-level programming class.

    5. Re:No inputs = useless? by Robert+The+Coward · · Score: 1

      "system monitors and watchdogs" how are those programs going to watch something with out data being inputed in some form?

    6. Re:No inputs = useless? by chrootstrap · · Score: 1

      I don't think that 'input' should include every system call to the kernel (including output-focused ones, as they return errno, etc), which are the bare essentials used by many monitors. imo, the kernel should rather be seen as the originating program with its processes like procedures which it calls. We can generalize 'input' further, including the results of functions, or even every register and value passed to machine operations, but I think it would be sophisticated. The article is talking about inputs that are not originating from the kernel, but from other processes through mechanisms such as file streams and environmental variables. We are talking about process-to-process input/output, not intraprocess or process-to-kernel input. As such 'input' is not required to make a useful and interesting program. Furthermore, there are many significant mathematical uses for programs that do not make use of even system calls in order to derive their parameters; calculating large prime numbers for example.

      --
      Hacking articles at http://www.geocities.com/chroo
    7. Re:No inputs = useless? by chrootstrap · · Score: 1

      I don't think that every system call should be considered an input in this case. The kernel is not merely another process (though microkernels blur thus considerably), but an integral and originating part of every process. A monitor can be very useful without ever getting input from another process, but only accessing the kernel. Particularly, the stating of 'no input = secure' indicates said context as the kernel is nearly always assumed secure.

      --
      Hacking articles at http://www.geocities.com/chroo
    8. Re:No inputs = useless? by whereiswaldo · · Score: 1

      What good is a program that calculates pi if you cannot specify how many digits?

      What good is a simulation if you cannot specify which parameters to use, and how long you want to run it?


      That information can be contained inside a constant and compiled into the final executable.

    9. Re:No inputs = useless? by Gherald · · Score: 1

      > That information can be contained inside a constant and compiled into the final executable.

      Can, yes, can. But they wouldn't be very useful.

    10. Re:No inputs = useless? by whereiswaldo · · Score: 1, Informative

      That information can be contained inside a constant and compiled into the final executable.

      Can, yes, can. But they wouldn't be very useful.

      Not very useful? Here are examples which require no input and which I think are useful:

      - a cpu meter (no input, just system calls).
      - an aquarium simulation screen saver.
      - one-off applications which produce a static output from hard-coded input.
      - complex mathematical calculations
      - true, false, bg, fg, ps, top, logout commands/utilities in Linux
      - a clock display application

    11. Re:No inputs = useless? by sir99 · · Score: 2, Insightful

      Your examples don't take user input, but most of them do take input of a different sort. The point of the article was that input can come from unexpected sources like environment variables, and that an attacker can sometimes subvert these inputs. The cpu meter, bg, fg, ps, top, logout, and clock programs all take input, in the form of system and library calls. Some of them also read input from configuration files.

      --
      The ocean parts and the meteors come down
      Laid out in amber, baby.
    12. Re:No inputs = useless? by whereiswaldo · · Score: 1

      The point of the article was that input can come from unexpected sources like environment variables, and that an attacker can sometimes subvert these inputs.

      Yes, I completely agree. But the article also says that program which do not take any input are useless. It is *my* point to refute this claim.

      The cpu meter, bg, fg, ps, top, logout, and clock programs all take input, in the form of system and library calls.

      What do you propose? That software developers don't even trust the system calls of the OS they are running on? What if someone is able to modify your binary before you even run? Should you check that as well? What if the CPU is actually a fake and has instructions embedded to contact the world and send your personal information out? How do you defend against that?

      Some of them also read input from configuration files.

      Granted, but in their basic form, none of these applications need to *require* any input from network, file, or user. Each can be accomplished using only system calls.

    13. Re:No inputs = useless? by sir99 · · Score: 1
      I just wanted to point out that you seemed to be using a more narrow definition of input than the article, which slants things a little differently.

      What do you propose? That software developers don't even trust the system calls of the OS they are running on?

      You can certainly trust most system calls, but one of the things the article mentioned was an attacker closing the std{in,out,err} file descriptors before execve(2)'ing your program. So on some systems, when you open(2) a file, you'd get the same handle that refers to console I/O. That's probably unexpected, and possibly exploitable (don't ask me how though ;-).

      Library calls can be suspect on some systems, too.

      However, the article seems to be mostly in the context of set-uid programs, while your example programs have little need to worry about security issues.

      I'd agree that you can have useful programs even with no input of any sort; the programs true and false that you mentioned are trivial examples.

      --
      The ocean parts and the meteors come down
      Laid out in amber, baby.
    14. Re:No inputs = useless? by luckyguesser · · Score: 1

      And the only person (hopefully...) that can define inputs in the source code would be the programmer. In other words, the most obvious limitation of this kind of program is that the user must have access to the source, knowledge of how to modify the source, and a means to compile and run the source.

      --


      The power of Christ compiles you.
      A Random Blog
  12. Re:file this under: by Carnildo · · Score: 1

    NO fscking SHIT!

    jesus christ on a pogo stick... somebody had to put this in an fsking security magazine?


    Given that every single way to compromise security involves bad input, it's not surprising that it's in a security magazine.

    --
    "They redundantly repeated themselves over and over again incessantly without end ad infinitum" -- ibid.
  13. perl -T says it all by DrJimbo · · Score: 3, Interesting

    The Perl language has built-in "taint-checking" enabled via the -T command line switch which causes Perl to automatically keep track of all information that possibly came from a user input and not allow any of it to do anything harmful (basically end up on a command line or in a file name).

    --
    We don't see the world as it is, we see it as we are.
    -- Anais Nin
    1. Re:perl -T says it all by Carnildo · · Score: 5, Informative

      The Perl language has built-in "taint-checking" enabled via the -T command line switch which causes Perl to automatically keep track of all information that possibly came from a user input and not allow any of it to do anything harmful (basically end up on a command line or in a file name).

      There are other harmful things that data can wind up doing that Perl can't check for. Things like being used as SQL queries, or the classic "pass the price as a CGI parameter" mistake. Taint checking is more useful as a reminder that you need to validate input than a way of keeping potentially bad input isolated.

      --
      "They redundantly repeated themselves over and over again incessantly without end ad infinitum" -- ibid.
    2. Re:perl -T says it all by mpath · · Score: 1
      Things like being used as SQL queries...
      In conjunction with the -T switch, you can also use the DBI placeholder methodology, which takes care of SQL-injection vulnerabilities:

      # isolating relevant Perl code
      @row_data = $database_handle->selectrow_array( 'SELECT * FROM customers_table WHERE lname=? AND email=? LIMIT 1', undef, $input1, $input2 );
      $statement_handle = $database_handle->prepare( 'INSERT INTO customers_table (lname,email) VALUES (?,?)' );
      $statement_handle->execute( $input1, $input2 );

      Fun Fun!

      --
      I'm not sure what the secret to success is, but the secret to failure lies in trying to please everyone -Bill Cosby
    3. Re:perl -T says it all by Anonymous Coward · · Score: 0

      Yes, but the "taint" attribute is determined and checked at run time. I.e., so you don't know that there is a flow of string tainting until your application is already running (so you require a test that exercises all interesting paths, to see the problem.) And its limited to Perl, of course.

      In an article I wrote about actually performing user input for C/C++:

      http://www.pobox.com/~qed/userInput.html

      I go over the analogous thing (to tainting) that you can do in C/C++ via compile time language features -- namely ordinary type checking. I also give a useful and buffer-overrun safe mechanism for actually getting input.

    4. Re:perl -T says it all by lesinator · · Score: 1
      There are other harmful things that data can wind up doing that Perl can't check for.

      This isn't just a Perl problem, its a problem with any language.


      Things like being used as SQL queries

      I don't see why people get so bunged up about SQL injection attacts. The main reason they're effective is because so few developers know the right way to move data between their programs and sql queries. There's a very simple solution to this problem that can be used in Perl and just about every language I've ever seen: don't pass strings straight into your database queries, use varbinds. Not only does this technique prevent security problems, but it can lead to significant increases in database performance.

    5. Re:perl -T says it all by pacman+on+prozac · · Score: 1

      Not wishing to start a flame war but for PHP users, turn on safe mode. That blocks exec() and similar "dangerous" functions. If needed you can turn them back on in <Directory> statements in apache config.

      Good time to mention magic_quotes_gpc and register globals as well.

      Of courses none of these are a replacement for good programming practises in the first place. magic_quotes can get annoying if you do filter input properly as it's easy to end up with double escaped strings (e.g \\\'test\\\' instead of \'test\').

      Generally speaking if your app breaks running under safe mode or without register globals its not very safe anyway and you need to read the PHP manual to update your coding.

    6. Re:perl -T says it all by archen · · Score: 1

      Yes, but the "taint" attribute is determined and checked at run time. I.e., so you don't know that there is a flow of string tainting until your application is already running (so you require a test that exercises all interesting paths, to see the problem.) And its limited to Perl, of course.

      Other languages have tainting also. My favorite being Ruby, which not only has taint checking, but can also have different levels of tainting depending upon your security needs. Besides which I'm not sure how 'requiring a test' is really a bad thing. I mean can you really expect anything to be secure without testing? Personally I find tainting to be essential, which is why I stay away from PHP. I'd rather have an application simply stop than passing on tainted information.

    7. Re:perl -T says it all by ChaosDiscord · · Score: 1
      The Perl language has built-in "taint-checking" enabled via the -T command line switch which causes Perl to automatically keep track of all information that possibly came from a user input and not allow any of it to do anything harmful (basically end up on a command line or in a file name).

      Taint checking isn't perfect, may have bugs in its implementation, and can't cover all possible cases. Taint checking is a wonderful tool, but it should only be one layer in a multi-layered defense. Don't view it as a one stop solution, just view it as extra-paranoid defense on top of your already securely designed code.

    8. Re:perl -T says it all by Anonymous Coward · · Score: 0
      Other languages have tainting also. My favorite being Ruby ...
      Yes but that's because these languages are dynamically typed. For statically typed languages like C/C++ you can capture the problem at *COMPILE* time with ordinary type checking. I.e., you can know if there is a problem or not before you ever run the program.
    9. Re:perl -T says it all by Anonymous Coward · · Score: 0
      I don't see why people get so bunged up about SQL injection attacts.

      Huh? You do know why! In fact, you go on to explain it:

      The main reason they're effective is because so few developers know the right way to move data between their programs and sql queries

    10. Re:perl -T says it all by TheLink · · Score: 1

      PHP = bad architecture. Many of the popular PHPisms are just bad design and security misfeatures waiting to happen.

      The fact that features like addslashes, magic quotes and register globals exist show little thought goes into PHP's design.

      Your input filters should be designed to filter data so that your _program_ can cope with it, NOT so that other programs can cope with it.

      After your program processes the input, you use the necessary _output_ filters for each different output so that other programs can cope with your program's outputs. e.g. SQL parameters, other applications, user browser (text or html), etc.

      Combining input and output filtering with just a single filter like "addslashes" is bad design, and is why on many sites you see superfluous backslashes.

      Magically sticking backslashes in front of everything is stupid for nontrivial apps and is likely to corrupt data. The fact that PHP programmers are commenting here about the joys of addslashes vs SQL injection shows how dismal things are in the PHP world.

      DB quoting/filtering should be left to the Database API. Placeholders and bind variables, standard functions for quoting. That way no matter what DB you use, doing the right thing can be properly delegated to the API. Not all databases use backslashes for quoting, and even if they do the way they use it can differ subtly.

      --
  14. Don't Trust the User by darkstar949 · · Score: 0, Redundant

    So don't trust the user, double check the data, and make sure than and error in the entry will not damage the program (Buffer overflow anyone?). This all sounds like common stuff that has been rehashed over and over again.

  15. "Obvious guy" would be proud. by Anonymous Coward · · Score: 0


    I don't program much, but all I can think is "well.. ya."

    Not to say it wouldn't be a nice intro, but by itself that artical didn't have any substance. Go into more sophisticated problems or something...

  16. Re:Slow news day? by Anonymous Coward · · Score: 0

    I'm inclinied to agree with that - actulay it seems like there has not been much the past few weeks. --- Anonymous Coward: Preventing Karam loss since 1997

  17. Murphy's Law strikes again. by Dr.+Bent · · Score: 5, Insightful

    It is a widely accepted engineering maxim that systems should be designed so that it is difficult to use them improperly. This is why (for example) a 110 volt plug will not fit in a 220 volt outlet. Developers who are concerned about the quality of the software they make would do well to follow this rule, and not just for security reasons. You should verify input data as early and as rigorously as possible wherever you can. Take advantage of things like XML validation and text box constraints to make it hard for users to enter bad data. And always follow the Fail-Fast principle...if something goes wrong: Complain! Loudly!. Don't let the user continue working if something has gone wrong. It's better to crash than to produce an erronous result.

    Just a little advice from a developer who's made enough mistakes to know better.

    1. Re:Murphy's Law strikes again. by FartingTowels · · Score: 2, Funny
      "This is why (for example) a 110 volt plug will not fit in a 220 volt outlet"

      You do not have any children, now do you? ;-)

    2. Re:Murphy's Law strikes again. by Tim+C · · Score: 2, Insightful

      Take advantage of things like... ext box constraints to make it hard for users to enter bad data

      That's good and necessary advice, but it's not sufficient, depending on your environment. If you're programming for the web, then you absolutely cannot rely on such things. Of course you should always set such constraints in the HTML where possible, but you *still* have to validate the inputs fully in your code.

      In case the reason why isn't obvious, it's because URLs are very easy to hand craft. There's no way you can stop me from sending 500 chars of data as the value of a field that you thought you'd constrained to be 10 chars. Even if you treat POST and GET differently, I can just whip up a little app to do POSTs for me if I'm so inclined.

      Front-end constraints and sanity checking (eg javascript that checks to make sure that all required fields have a value before submitting the form) are an invaluable part of the user experience, but they're no substitute for securely written code. The two things serve entirely different purposes.

      More generally speaking, you should santiy-check all input data, at all stages in the code.

    3. Re:Murphy's Law strikes again. by Anonymous Coward · · Score: 0

      the 110v plug will fit in the 220v outlet in thailand

    4. Re:Murphy's Law strikes again. by a_n_d_e_r_s · · Score: 1

      Well, the problem is that those checks in javascript happens on the client side and can be overridden by those smart enought to know what they are doing.

      So you must allways assume that even if you used javascript that something may be a problem with input data. One must always check the input in the server side cause one never know what a evil computer using criminal might send in.

      Too many use javascript for validation even hough it's useless for it. One always have to do validation in the server end anyway - doing it in javascript is mostly just a waste of developers time.

      Thus javascript sucks for input validation.

      --
      Just saying it like it are.
    5. Re:Murphy's Law strikes again. by Rich0 · · Score: 3, Insightful

      Keep in mind that the 110 and 220 plugs are designed to defeat accidental mixups. Computer input validation is generally designed to do the same. Hardening software against an attack is more analagous to giving your engineer the task of designing a plug and outlet such that it is physically impossible to plug anything but that one particular plug into the outlet, with the understanding that somebody with a good knowledge of engineering will try to defeat the design.

      Software is required to do a lot more than any physical security measure in existance. Your webserver could come under attack by any electronic measures that you could conceive of by a host of trained software engineers in another country. Chances are that the most a bank vault is designed to handle is a dozen guys with small arms, rudimentary safe-cracking gear, and some small explosives. If the US Army showed up with an M1 tank and 1000 tons of C4, the safe wouldn't last long. However, such a large-scale intrusion is unlikely to escape the watch of the police for long. On the other hand, a remote attack against a webserver can run for months without much being done to the attackers if they're in a rogue nation.

  18. hardly surprised that we have to go through this.. by hotrodman · · Score: 2, Insightful


    And why should anyone be surprised? In this age of "I read a book on VB last week and now I'm a software engineer!" type environment?
    I am not surprised that simple things like this are rehashed over and over. This is more suited to the programmer group of people who will sort data based on string comparisons, instead of learning how to use a real algorithm to do it, or keep writing static forms, instead of learning how to use a loop with a db backend - because they don't understand true programming concepts. In other words, about 80% of the current crop of overpaid, undereducated programmers that built corporate apps.

    - Eric

  19. Re:file this under: by Anonymous Coward · · Score: 0

    You make it sound like the article only says that. Well, you might be an expert, but speaking as an experienced userspace programmer with only limited security knowledge, I can tell you that to me it's of great interest. The (historical) IFS vulnerability, for example - I would never have thought of checking for something like that.

    Of course, you probably didn't bother to read the article before trashing it... this is Slashdot, after all.

  20. Re:Huh? by duffbeer703 · · Score: 0, Offtopic

    Guess who's going to be working at that N. American office?

    Hint: Not Americans

    --
    Conformity is the jailer of freedom and enemy of growth. -JFK
  21. Interesting article? by roady · · Score: 1

    What is so interesting about this article?

    I just wrote a document about secure programming and I found dozens of better articles about the exact same things like: here

  22. Perl's taint checking by Eryq · · Score: 5, Informative

    Perl programmers interested in writing secure scripts should *definitely* know about the -T (taint checking flag).

    From the FAQ:

    As we've seen, one of the most frequent security problems in CGI scripts is inadvertently passing unchecked user variables to the shell. Perl provides a "taint" checking mechanism that prevents you from doing this. Any variable that is set using data from outside the program (including data from the environment, from standard input, and from the command line) is considered tainted and cannot be used to affect anything else outside your program. The taint can spread. If you use a tainted variable to set the value of another variable, the second variable also becomes tainted. Tainted variables cannot be used in eval(), system(), exec() or piped open() calls. If you try to do so, Perl exits with a warning message. Perl will also exit if you attempt to call an external program without explicitly setting the PATH environment variable.

    --
    I'm a bloodsucking fiend! Look at my outfit!
    1. Re:Perl's taint checking by Anonymous+Cow+herd · · Score: 1

      Perl's taint checking was (at my last check) pretty easy to get around, allowing users to essentially bypass the taint checks quite easily. Also, perl 5.6.0 doesn't do taint checks (even with -T) on lists passed to exec() and system().

      --
      Ita erat quando hic adveni.
    2. Re:Perl's taint checking by Eryq · · Score: 2, Interesting

      IIRC, the goal of -T is not to prevent you from *ever* using tainted data; it was to prevent accidents: running shell scripts with insecure $PATH variables, etc.

      Untainting a variable by extracting a subpattern usually means "I know what I'm doing: I promise that I'll extract a safe substring from this". (Whether the developer *actually* knows what they're doing is, sadly, not detectable by Perl).

      (As for -T not affecting a list passed to exec()/system(): that does seem odd, but maybe there's some Larger Purpose to it that I don't get).

      BTW: I think it would have been better if you explicitly had to invoke some function like untaint() or this_is_safe_to_use_in_shell_commands()... just to make you think about it.

      But imperfect as it is, -T beats the pants off the alternative approach that most languages give you, which is "You're On Your Own, Sucka".

      --
      I'm a bloodsucking fiend! Look at my outfit!
    3. Re:Perl's taint checking by rgmoore · · Score: 2, Informative

      The purpose of taint checking is more as a debugging tool than an absolute check on illegitimate data. This fits with the general Perl view that the function of the language is to assist the programmer rather than to constrain him. Thus if you turn on taint checking, Perl will stop you from doing things directly using tainted data, but it lets you "launder" the data by running it through a regexp. This isn't a perfect solution, but anything that was radically better would be all-but impossible to code. It won't stop a lazy programmer from using:

      $var =~ m/^(.*)$/;
      $var = $1;

      to bypass the checking (false laziness!), but that's not its purpose. What it will do is to catch many non-obvious mistakes by a programmer who's actually trying to write safe code.

      --

      There's no point in questioning authority if you aren't going to listen to the answers.

  23. Addendum by roady · · Score: 1

    Before someone says "but your link is about a book, not an online article!" please see here

  24. Re:hardly surprised that we have to go through thi by fedor · · Score: 1

    But you don't understand!
    This is IBMs ON DEMAND Strategy!

    --
    :wq!
  25. Speaking of inputs. by Anonymous Coward · · Score: 1, Funny

    Michael dropped the soap again. Be gentle.

    1. Re:Speaking of inputs. by Anonymous Coward · · Score: 0

      Again? With the gash on his backside it's a wonder all his guts don't fall out.

  26. Keep an eye on buffer overruns by shuz · · Score: 2, Informative

    Ya you can talk about inputs to programs and how misc. and unwanted data get in there but watch for buffer overruns because thats what can really kill your program.

    --
    There is or can be built a machine that can simulate any physical object. -Church-Turing principle
    1. Re:Keep an eye on buffer overruns by shuz · · Score: 1

      That and dynamic global variables...

      --
      There is or can be built a machine that can simulate any physical object. -Church-Turing principle
    2. Re:Keep an eye on buffer overruns by Carnildo · · Score: 1

      Ya you can talk about inputs to programs and how misc. and unwanted data get in there but watch for buffer overruns because thats what can really kill your program.

      Where do you suppose the data for a buffer overrun comes from? Malicious input!

      --
      "They redundantly repeated themselves over and over again incessantly without end ad infinitum" -- ibid.
    3. Re:Keep an eye on buffer overruns by shuz · · Score: 1

      Correct, hense my point to avoiding situations that allow for malicious input.

      --
      There is or can be built a machine that can simulate any physical object. -Church-Turing principle
    4. Re:Keep an eye on buffer overruns by jilles · · Score: 2, Insightful

      No buffer overflows come from using flawed 1970's technology. Modern computer languages are immune to the worlds largest security problem: (i.e. buffer overflows) because they do something automatically that C programmers are supposed to do manually.

      Eliminate the buffer overflow and malicious input becomes invalid data which can be dealt with in a controlled fashion rather than executable gibberish.

      --

      Jilles
  27. What seems obvious to some... by Slick_Snake · · Score: 2, Insightful

    Is news to others. Many "Programmers" out there write code that does not do any error checking or catching and the result is all the crapware that we see today. We were all warned in our programming classes about memory leaks and buffer overflows, but they are still very prevalent in today's software. Perhaps we should all look harder at our code before selling off one it as a final product.

    1. Re:What seems obvious to some... by Flaming+Death · · Score: 0

      Amen. This is so utterly the case. The amount of code I see that goes to the customer with pointers unchecked, no black box, white box testing.. memory leaks.. the list goes on.. and so often it is just because ppl are lazy and dont do parameter checking or test error returns. Some of the worst stuff I have seen was shipped in debug because 'it wouldnt run in release'.. omg.. the number of people programming who havent even used debug, plain scares me..

  28. Dividing by chrootstrap · · Score: 3, Interesting

    The recommendations on dividing the program into unsecure and secure binaries to handle setuid access in GUI's can very properly be extrapolated to non-graphical programs. This is a very good strategy for allowing relatively wild programs access to important facilities and can involve many types of IPC including memory-mapped files (with proper protection) and sockets. To really secure a client program that needs access to criticals, put it in a chroot jail and have it communicate with an outside process through (e.g.) a socket. Separating programs into safe and unsafe sections and applying different security techinques to each is far more effective, imo, than trying to secure a single, large application. It can also provide many other benefits of encapsulation, etc. The security onus shifts to handling client requests in the secure section which is usually much more easy to do.

    --
    Hacking articles at http://www.geocities.com/chroo
  29. You'd Be Surprised by Anonymous Coward · · Score: 0
    Guess who's going to be working at that N. American office?

    Hint: Not Americans

    There will probably be a number of Americans employed at TCS Buffalo--as administrative assistants and salespeople. There will also be a need for some janitorial types.

    These job gains, however, will be offset by many multiples of job losses as TCS offshores IT, engineering, and back-office functions for American companies!

    Hooray for Hillary!

  30. Re:IFP battle by Anonymous Coward · · Score: 0

    You're on, foolio.
    Props to GNAA

  31. It is a never ending battle by Anonymous Coward · · Score: 0

    This will go on and on till the end of time.
    Nothing is truly secure.
    There will always be a hole somewhere.
    It is only meant as a deterent.

    There is (TTM) Time-To-Market which will screw up code reviews.
    There is insiders, There are spies, etc, etc.

    Take all that time to write a program and it is obsolete before it is released.

  32. Re:file this under: by chrootstrap · · Score: 2, Interesting

    "Given that every single way to compromise security involves bad input, it's not surprising that it's in a security magazine."

    What about program bugs that are not input related? If a program breaks when an internal timer overflows for example, or accessing a section of memory that has been deallocated. Such bugs can easily cause breaches in security as well as general system failure, all without any human intervention. It reminds me of the black out that Sterling mentions:

    http://www.lysator.liu.se/etexts/hacker/crashing.h tml#5
    --
    Hacking articles at http://www.geocities.com/chroo
  33. Secure coding documentation by Anonymous Coward · · Score: 2, Informative
  34. Re:file this under: by Anonymous Coward · · Score: 2, Interesting
    ... somebody had to put this in an fsking security magazine? ...
    The basic point is (translation: should be) self-evident, of course. And the points made in the article will (translation: should) be well-known to anyone who's spent a few years deploying apps in the DMZs that the Bigcorps use as their presence on the Big Bad Internet... but I found a few points in it and the referenced resources to add to my list as a beginner in that area.

    Basic point, I suppose, is that if you insist on using a U*ix-family OS in such an environment then you must ensure that the U*ix environment is clean at the beginning, which may well be more a matter of the procedures and quality control of the platform and the application deployment than of the individual apps.

    Oh, and btw, I thought the head of the thread was a kneejerk reaction, but - flamebait? Shame on whoever moderated it that way.

  35. Web by Andrea_from_Arg · · Score: 1

    How about when the applicacion is on the web? Javascript? Server roundtrips?

    --
    :: Andrea ::
    Anime Wallpapers
    1. Re:Web by cybermage · · Score: 1

      How about when the applicacion is on the web?

      When you're developing web applications, you've got to deal with the input in a few ways to be sure you can trust it:

      Do the user a favor and validate the input on their end using javascript.

      Repeat the validation on the server. Yes, that's right, repeat it. They could have javascript turned off, or could be deliberately bypassing the validation.

      When validating input, don't simply check that you're getting what you expect. Also confirm that you aren't getting what you don't want.

      Never, ever, ever evaluate input. It's an easy shortcut to write dynamic functions that use part of the input in the function, avoid this dangerous crutch.

      Do not store a user id in a cookie on their computer or in hidden input fields. Generate a session id and keep the user id on the server. The more you desire security, the sooner you should expire cookies.

      Be secure. Use very, very difficult to guess session identifiers (e.g., a random MD5 hash). Setup SSL when it's deserved (is money changing hands?)

  36. YUO = NAIVE by Anonymous Coward · · Score: 0
    .

    How is this moving business offshore? It looks like she is bringing offshore businesses HERE.

    Use your "critical thinking skills"! Why the fuck would a company that competes on price open an office in an "expensive" labor market? Do you really think they're in business to lose money?

    Answer: The office is a sales office, not a design center. Tata gains a sales foothold in middle American where it can quietly win business from American firms desperate to reduce costs. Hillary can "claim victory" by appearing to encourage job creation in sales and sales support while the reality is she's increasing job losses in the high-tech sector.

    Try actually reading the article.

    It's a press release straight from the Tata public relations department, you dipshit.

  37. Very good writer! by Anonymous Coward · · Score: 1, Insightful

    Another excellent article by David... oddly enough, I was reading his Program Library HOWTO (http://www.dwheeler.com/program-library/) just the other day to learn about dynamic loading libraries in Linux.

  38. Re:Your .sig by MrPerky · · Score: 0

    Adding Ad Absurdium, Ad Nauseum, or Ad Infinitum to your .sig would create another round of Adding Ad Absurdium, Ad Nauseum, or Ad Infinitum to your .sig would create another round of Adding Ad Absurdium, Ad Nauseum, or Ad Infinitum to your .sig would create another round of [/snip]

    --
    The preceding comment has been documented as containing no EPHI and is certifiable as HIPPA Phase II Compliant.
  39. stallman says... by Anonymous Coward · · Score: 0

    inputs want to be free, as in beer and sex with hookers

  40. Watch the USER! by anubi · · Score: 3, Interesting
    As long as we have no control over what the user tries to install and run in his machine, we are always going to be vulnerable to trojans.

    The proliferation of proprietary formats we are seeing that all do basically the same thing, like send sound files over the net, or view video clips, are encouraging mass downloads of programs from third party providers. These programs may well do what they said they would do, but with all this DMCA crap going on, its getting harder and harder to see if they are doing a little extra that wasn't in the bargain, like doing zombie work on the side to assist in little capers the originating author needs to pull off.

    What firewall or systems programming can stop a deliberately malicious program installed by an ignorant user? Say the program "demands" access to the internet for "verification/auto-update", then you have to set the firewall to allow this program access to the net. Now what happens? Its like giving car keys to a valet parking agent. You only have to trust he's only going to do what he says he will do. To add insult to injury, consider you generally have signed any recourse you have when you click that "I agree" button that confirms you have read and understood the EULA.

    What irritates me so about these "plug-ins", "macros", and "scripts" is that they are indeed executable. Nothing says the malicious person coding these things is gonna follow the rules. He is free to code some really nasties in assembler if he so desires. The state of music file distribution I find really disturbing. We have an MP3 format which is generally well understood, yet it seems everybody jumping on the bandwagon wants to use proprietary formats which are not generally understood, leaving us all open to the risks resulting from ignorance.

    As a public, we aren't helping much. We agree to any damn thing they print in the EULA. As a public, we should INSIST that if we are to be kept ignorant by law how something works, if that something does something malicious, then its maker should have full responsibility for the problems it generated.

    Basically I am proposing a trade. If you want the protection of law to keep the public ignorant, then you waive indemnity.

    We have a patent system and copyright system in place. Both were implemented on the concept that the work was to be in the open. Why aren't encrypted work also known as "trade secret" and not afforded protection by copyright or patent? Basically, any work encrypted would be considered a "trade secret", not in the open, hence not eligible for protection by the patent or copyright system at all? But to make this happen, its gonna take the will of a lot of people to pressure the legislators to enact this. Pressure as in "if you do not do this, start polishing your resume.".

    --
    "Prove all things; hold fast that which is good." [KJV: I Thessalonians 5:21]

  41. Perl security article in SysAdmin magazine by merlyn · · Score: 4, Informative

    I wrote a similar article recently for SysAdmin magazine, although the focus is more about Perl.

  42. This was well documented in the 1970's by pcause · · Score: 3, Insightful

    The Kernighan & Plauger book "Elements of Programming Style" dated 1979 talked extensively about the need to validate all inputs to subroutines and from the user. This is *not* new, it is just that few programmers have the discipline to follow the rules.

    The issue is making *no* assumptions about anything. The programmer *thinks* the file will be written be another piece of code that a team member is writing. But that program has a bug. or three years from now, other programs are creating the file and don't know abut some verbal discussion about field data. It takes great dligence and paranoia and management that allows you the time in the schedule to do this.

  43. environment variables by MellowTigger · · Score: 3, Funny

    The article is interesting, and they are right to point out the many dangers of relying on environment variables. Where I work (unidentified to protect the incompetent), programmers are not allowed access to the unix command line. Instead, all user exits are trapped, and programmers are forced to navigate through a homegrown menu system.

    This menu system relies on an environment variable ${WHATCANIDO} to store a list of permissions available to that user. Of course, I changed my .profile to add my own extension to the permission list. I even nicely dated, initialed, and described my change. ;)

    export WHATCANIDO=world_domination:$WHATCANIDO # 2000/10/31 tw Too easy

    So now when I get frustrated with the absurdity of this arrangement, I just take echo the environment variable to remind myself why I'm right and they're wrong.

    > echo $WHATCANIDO
    world_domination: [deleted]

  44. What about BIOS? Do you have to trust something? by G4from128k · · Score: 2, Insightful

    Somewhere along the line every application must trust something. At the very least, BIOS settings and environment variables that are owned by deeper layers of the OS must be trusted because they are inaccessible or indecipherable at the application layer. Reaching too far would break encapsulation and create brittle dependencies. An application can only check the variables and direct inputs that it has access to.

    I don't argue against validating inputs. Certainly all of the direct inputs to an application should be assumed to be untrustworthy unless a secure checksum validates that the inputs are indentical to some previously validated inputs. Checking inputs (or environmental variables) of immediately adjacent processes is probably also warranted (as a redundant "brother's keeper" policy).

    The real problem comes if the OS has a faulty validation methods. (And I won't get into the neccessity of trusting the hardware or bugs such as those that plagued the early Intel 586.00001 processors) If I check the validity of a user, filename, or geographically localized data format (e.g., a date), then my application is dependent on the quality of the OS's validator (and a lack of intervening malware).

    --
    Two wrongs don't make a right, but three lefts do.
  45. Re:hardly surprised that we have to go through thi by glenebob · · Score: 1

    >> overpaid, undereducated programmers that built corporate apps.

    Why the f*** does somebody have to tell you that you need to validate input? Why the f*** isn't that obvious??? If that sort of thing isn't painfully obvious to you, you probably should be in a different line of work, educated or not.

  46. Saving stuff in a database... SAFELY. by mcrbids · · Score: 1

    What about addslashes()?

    Since addslashes() is only truly useful when magic_quotes are off, I wrap it all in a function that checks the status of magic_quotes. Defined as something like:

    dbprep($string, $length=-1);

    So that if $length>0 the input cannot be longer than $length.

    I do the same for databased output, EG: dbout().

    Combine addslashes with a few others, such as htmlentities(), and perhaps a regex or something to check for [a-zA-Z0-9], and you have *very* powerful input validation.

    Am I missing something?

    --
    I have no problem with your religion until you decide it's reason to deprive others of the truth.
    1. Re:Saving stuff in a database... SAFELY. by Anonymous Coward · · Score: 0

      You still have to remember to do it. It makes much more sense to use a database layer that accepts parameterized queries. (JDBC, ODBC, etc) Then your input is always checked automatically.

  47. Problem: Hacker Languages by cryptoluddite · · Score: 2, Interesting

    Almost everything in this article only applies because of hacker languages like C and C++, which Linux and FreeBSD use for virtually everything. It is so easy to forget to double-check bounds, input format, pointers, and all the other usual suspects. It's bizarre how programmers will use these error-prone languages for marginal performance gains just because their ego and haxor status is on the line. Sure, the kernel and drivers need to be in C. Sure, a Java VM needs to be in C. Sure, C++ is a good langage for game engines. But almost nothing else should be written in C/C++.

    Command-line type programs can be written in Java and statically compiled into small, low-memory, fairly fast programs. And the JVM overhead is has almost no affect on the larger programs. But you have to work really hard to put a security problem into a Java app instead of working really hard not to. And you get garbage collection, an awesome API, security, faster compiling, dynamic classloading/linking, easier coding, etc. People think Java takes a lot of memory, is slow, and ugly. But that's almost entirely because of the Swing GUI, which is not actually all bad. Replace with IBM's SWT and you'll see a dramatic difference.

    Of course there are other languages besides Java that protect against security problems, but few that do so as completely and easily. If half the effort had been put into inplementing the Java APIs in open source as just on GTK/GTK+ then linux/bsd could do nothing for ten years and still be ahead of the rest.

    1. Re:Problem: Hacker Languages by Anonymous Coward · · Score: 0

      While Java is pretty secure with regards to system security, it isn't any more secure than other languages when it comes to application security. It doesn't help if nobody can break into your server when they can easily ruin you with malicious orders with falsified prices (because you choosed to pass the price back in via a hidden CGI field... d'oh!).

    2. Re:Problem: Hacker Languages by BattleTroll · · Score: 4, Insightful
      "But almost nothing else should be written in C/C++"

      What world are you living in? Blaming poor technique on the tool used is moronic. There are ample examples of poorly written, poorly secured Java code the invalidate all of the premises in this rant. I've seen hard coded passwords baked into java source that were visible through a 'strings' call. Someone forgets to obfuscate his or her classes, and the entire structure of the program is available through a reverse compiler. Sure, the JVM protects one from buffer overruns and the like but don't for one minute think that programming in Java prevents stupid errors from exposing you to vulnerabilities.

      Not to mention there are areas where java is not the silver-bullet you describe. If you need precise control over your memory allocation, java is not the tool to use. If your application requires precise timing, java is not the tool to use. Need to control over the placement of allocated memory? Writing your own transport layer? Need hooks into the kernel?

      The prime directive still holds true - use the correct tool for the job at hand. Follow the lemmings of "this tool is the only one you need" at your peril.

    3. Re:Problem: Hacker Languages by Anonymous Coward · · Score: 1, Insightful
      But almost nothing else should be written in C/C++.

      Write a kernel in Java. Write drivers in Java. Write init in Java. Then you can say that.

    4. Re:Problem: Hacker Languages by TheLink · · Score: 1

      But a dangerous tool can still be called a dangerous tool.

      An important difference between writing in C or some other unsafe language, and writing in Java/Perl or some other safer language is that, a simple mistake in the former tends to let the "attacker run arbitrary machine code of his own choice" whereas the latter tends not to.

      Of course there will be "attacker runs arbitrary SQL code/etc" but these are at least at a higher level and can usually be handled with safe interfaces/APIs. Whereas C is full of unsafe interfaces and APIs.

      Sure C is necessary. But it is actually quite a sad thing that there isn't a safer, reasonably efficient and popular system programming language in use. C is holding things back.

      It doesn't look good. Stuff like Forth appear to be as vulnerable as C is (arbitrary machine code vulns). Given that LISP/Forth often has code = data, what are the standard and safe ways of making sure that arbitrary LISP/Forth of the attacker's choice never gets executed?

      --
    5. Re:Problem: Hacker Languages by willdenniss · · Score: 1

      When you need native code (timing, memory placement, kernal etc) you can use the JNI. There is little you can do in C/C++ which can't be accessed from Java. Look at the Java OpenGL bindings for example.

      I agree that using the right tool for the job is the best way to approach it - but don't go around saying that you can't do those things in Java when you can.

      Will.

    6. Re:Problem: Hacker Languages by Anonymous Coward · · Score: 0
      >> There is little you can do in C/C++ which can't be accessed from Java. Look at the Java OpenGL bindings for example.

      Which are hideously slow and inefficient compared with the real thing. I'll keep my OpenGL apps in C, thanks! I actually want them to work well on a box that is less than 2 months old. (And yes, I have programs to back up my claims).

      There is a ton you can't do in Java. There is nothing you can't do in C!

    7. Re:Problem: Hacker Languages by willdenniss · · Score: 1

      Java bindings for OpenGL (JOGL) are a way you can make your precious C calls from Java. It is 1:1 - if you can do it in C with OpenGL, you can do it in Java (even the method names are hte same). Google is your friend. Will.

  48. Shooting yourself in the Foot in C by billstewart · · Score: 1
    C isn't screwed up. It's a really great language, nice and transparent, does exactly what you tell it with no surprises. You can shoot yourself in the foot if you want.

    The problem is that too many people aren't sufficiently careful, including the people who wrote the gets() I/O subroutine, so their Internet implementations typically resemble large quantities of foot-sized bright-colored bull's-eye signs marked "YOURS ARE HERE" and large numbers of guns and bullets of various sizes distributed to lots of people along with README files about attaching a sign to your foot to make sure it gets shot at.

    --

    Bill Stewart
    New Fast-Compression-only CPR http://preview.tinyurl.com/dy575ks
  49. OK, what do you do when you validate it? by Latent+Heat · · Score: 2, Insightful
    Yes, I am a believer in defensive programming, but I am not sure that defensive programming is the golden hammer. Verity Stob made a remark about taking a sick program and filling it with try-catch blocks to try to recover from every possible error condition -- I believe she called it "nailing a corpse on a tree" or some such thing. And her other remark was "the only place we seem to get exceptions is in destructors, so what's the point?" That had me on the ground in tears of laughter because destructors (freeing up resource in the right order) is one of the hardest things to get right.

    Ok, every last subroutine validates every last input. Then what do you do? Suppose an input is invalid -- do you halt? Throw and exception? Patch the input and keep going? Keep going but make an entry in a log file?

    It is excellent policy to be ultra paranoid about user input and to put "firewalls" between major program modules. But for every last subroutine to have its own error checks -- what if you have a top level subroutine that performs error checks and than passes validated results to helper subroutines? Do the helper subroutines need to repeat the checks?

    I think there has to be some analysis of the data flows and designation of raw and filtered data flows, who does the filtering, and what assumptions or assertions can be made about filtered flows, and assignment of responsibility to do the checking.

    In summary 1) defensive programming is not a substitute for good overall design, 2) there is a place for delegating responsibility for error checking and not chronically worrying about checked data.

  50. DRM? by tepples · · Score: 1

    You can certainly trust most system calls

    What if I'm writing a program to display a work under copyright or trade secret restriction? How can I be sure that the system calls haven't been patched with the cooperation of the owner of the machine to leak the work to a third party?

    1. Re:DRM? by whereiswaldo · · Score: 1

      You can certainly trust most system calls

      What if I'm writing a program to display a work under copyright or trade secret restriction? How can I be sure that the system calls haven't been patched with the cooperation of the owner of the machine to leak the work to a third party?

      You can't be sure that someone hasn't tampered with the machine. I don't think this is in the realm of what normal applications should have to worry about.

      Nonetheless, if you do have trade secrets and you are worried about them getting out, only use your machine, don't plug it into any networks, and disable wireless or other access points to the machine. You should also encrypt the filesystem with a strong password in case the machine falls into the wrong hands. Set up a password protected screen saver that times out after 1 minute. This should keep most people away from your trade secrets, but I'm no expert on this.

  51. Have a no-front-end-checking mode by r6144 · · Score: 1

    I'm not an experienced software engineer, but I think it would be good practice to first give the HTML pages a "development" mode where no input validation is done at that stage. Even better, all input should be entered from text boxes, so that you can give your program arbitrary input without handwriting URLs much. Front-end checking (such as client-side javascript) can be added at the same time or after the core engine is debugged, but it is still better to preserve the "development" mode in the code (for testers and developers only, of course).

    1. Re:Have a no-front-end-checking mode by Tim+C · · Score: 1

      That's pretty much the way we work - we never rely on the client having javascript enabled, as that could potentially prevent some people from using the site. We don't have a specific "development mode", but on any normal project the back-end code and HTML development are done by different people.

      Basically, we have interface developers who take the Photoshop images that the designers/art directors produce, and use them as a blueprint to create the HTML pages. They also produce any javascript that we do use. Meanwhile, we (programmers) are developing the back end code, using "white page" pages - ie plain HTML pages with little or no design. We don't generally waste time putting length restrictions on input boxes in our forms, as we'd only have to do it again when integrating our stuff with the final pages.

      On the other hand, we do 90%+ of our work in Java these days, so bounds checking is less of a problem. You still have to check stuff before inserting it into a db record, of course, but that's to prevent exceptions, rather than improve security.

    2. Re:Have a no-front-end-checking mode by sjames · · Score: 2, Insightful

      That's a good point. I have seen developers mistake javascript for sufficient input validation. The proper use of validation in javascript is to simply give a legitimate user a proper error message quickly without actually needint to perform a transaction with the server that will fail. The server must still re-validate the input.

  52. Output implies input by tepples · · Score: 1

    A monitor can be very useful without ever getting input from another process

    Where to write output is itself input, which comes ultimately from another process, through redirection of file descriptors or through chroot() of the file system.

    1. Re:Output implies input by chrootstrap · · Score: 1

      lol! okay, fair enough, though the output ('input') could end up in /dev/null. :)

      --
      Hacking articles at http://www.geocities.com/chroo
  53. Some concrete examples would have been nice by fizbin · · Score: 1
    I often find that the best way to talk about security practices is by illustrating general points with specific counterexamples. (Actually, this is a helpful technique in general - see, for example, the book "Counterexamples in Topology")

    For example, when talking about being aware of \0 characters, you could mention something like this: a friend of mine once wrote a jukebox-like web application that allowed people to queue requests on his machine. There was a certain input parameter that was restricted to being the name of a subdirectory of his music collection. So, here's how he validated the input (more or less, since this is from memory):
    my $musicdir = $q->param('musicdir');
    if ($musicdir =~ m([/\\])) {return 0;} # Error exit
    if (!diropen(INPDIR, "$musicbasedir/$musicdir")) {return 0;}
    map { print QUEUESCRIPT "$playercmd $musicbasedir/$musicdir/$_\n";} <INPDIR>
    QUEUESCRIPT was then a shell script that was queued up and ready to go.

    The consequences of passing
    musicdir=Dar%20Williams%20-%20The%20Honesty%20Room %00%0atelnet%20badplace|sh%0a
    to the script are left as an exercise for the reader.

    Now talk about the hazardous effects of \0 characters - instead of saying just "system calls aren't fine with \0 characters", you can say "many perl functions that interact with the underlying operating system - such as open, diropen, or the file tests (-r, -x, etc.) - will consider a string only up to the first \0. Therefore, if you are relying on calls to the operating system for validation of any parameter, be certain to strip out \0 characters first. Better yet, allow in only what you expect, and no more. A simple s/[^ -~]//g (assuming only US ascii input is allowed) will go a long way."

    A similar example of halting a buffer-overflow exploit might also be a good idea.

    Also, having a typo in the "Know the Language" section (= instead of =~) really obscures your point.
  54. Re:ASP -t doesn't say jack by pacman+on+prozac · · Score: 1

    What part of "Not wishing to start a flame war" was it that went rocketing over your head. All of it along with the rest of the post apparently.

    DB quoting/filtering should be left to the Database API.

    What like using seperate commands for different databases. You can look the rest up yourself, I'm bored of reading the PHP manual for other people.

    Register globals is there to allow backwards compatibility. Everyone, especially php.net, shout from the hills about how insecure it is and how it shouldn't be used.

    Magically sticking backslashes in front of everything is stupid for nontrivial apps and is likely to corrupt data.

    You must be in management, argueing with me by repeating what I said re-worded. As I said if you do filter your input then magic quotes GPC gets annoying, good job its simple to turn off really.

    The fact that PHP programmers are commenting here about the joys of addslashes vs SQL injection

    Well pedantically they should be talking about mysql_escape_strings or whichever for the database they're using. Unpedantically, nobody apart from you is under the illusion that addslashes is the only way to escape SQL strings. Coming from an ODBC background by any chance?

    You do seem to be suggesting that escaping SQL strings is a bad thing (tm), care to explain why?

    Also, please can you actually specify some preference of alternative language so we can get a proper flame war going instead of just flirting about like this :-)

  55. Re:ASP -t doesn't say jack by TheLink · · Score: 1

    "What like using seperate commands for different databases"

    That's not what I'd call a database API. That's pretty silly and error prone. Take a leaf from JDBC or Perl DBI, etc, or come up with something better, not worse.

    PHP should at least have a DB API that supports bind vars or placeholders. Or some other API so that data is automatically escaped the way it should be, and the risk of data being treated as commands is low/nil and it is easier to audit and find uncompliant DB related code. If the PHP developers can come up with an even better way to do it rather than bind vars and placeholders or whatever, then that'll be great.

    Think about it. Is it really such a good idea or design to have "mysql_escape_string", "pg_escape_string" and "xxxx_escape_string"? What happens if you change databases? What happens if you forget to use it, how do you check?

    In contrast if you require the use of prepared statements and bindvar stuff - the DB quoting is "included" with the DB call, so is harder to leave it out, and in most cases things become easier for the lazy programmer. Also, detecting programmers NOT doing the right thing is easier - any SQL statement with variables stuck in the string can be treated as not doing the right thing.

    The more people using xxx_escape_string means a lot more legacy code to deal with later on when the PHP folk figure out how to do things better. I

    "Register globals is there to allow backwards compatibility"

    Wow. Great design putting register globals and other good old PHPisms there in the first place.

    PHP deserves to be flamed till it's a bit better cooked. Right now while it is tasty it isn't really that safe for mass consumption.

    I'm sure I'm not the only one who has tried getting the PHP people to come up with a proper DB API. Maybe if enough people make enough noise someone who knows PHP enough would fix things.

    --
  56. Re:ASP -t doesn't say jack by pacman+on+prozac · · Score: 1

    There is the pear DB module, but I see your point. A "PDBC" or similar would be a good move.

    Personally I use a tiny SQL class that can be changed to allow different db to be used. Seems a tidier solution since the class is only about 20 lines.

    Can't argue that register globals was a bad idea in the first place, but allowing users to still run older software needing it is a good idea. Shame they keep breaking other major functions in minor version increments though really, kinda makes keeping the stupid functions in redundant.

  57. Re:ASP -t doesn't say jack by TheLink · · Score: 1

    Pear DB looks decent enough. Actually it looks rather like Perl DBI. Getting more people to standardize on Pear DB and depreciating mysql_escape_string, addslashes etc would be a good idea.

    Breaking major functions in minor version increments is another sign of how serious the PHP devs treat PHP. Not very reassuring - esp if you need to update PHP for say a security issue (we had to do a few of those). Only a few people will have tests for their entire code, and even then you never really know and have to go by faith...

    Oh well. For some reason it seems like Java breaks lots of stuff every version anyway (1.1, 1.2, 1.3). Looks like Perl will start breaking major stuff in the next major version. Still, it's not often I have to bump up a minor increment with Perl. PHP and Java do look a bit "beta" in comparison (heck PHP looks alpha sometimes- at one point in 4.0 history it was release every 2 months for security probs).

    Well I guess that's coz almost all the functions are bundled into PHP. Sure a security prob may not affect your code - doesn't use that feature, but try explaining it to a customer that you don't have to upgrade and worse - possibly break things. Esp when they're told truthfully by an independent auditor who says they are using a version of PHP that has security vulns. Gack.

    --