views:

159

answers:

6

in these days, i'm interested in software security. As i'm reading papers i see that there are many attacks and researchers are trying to invent new methods for softwares to get more secure systems.

this question can be a general including all types of attacks.There are many experienced programmers in SO, i just want to learn what are using to check your code against these attacks ? Is there any tools you use or you don't care ?

For example i heard about,static,dynamic code analysis, fuzz testing.

  • SQL injection attacks
  • Cross Site Scripting
  • Bufferoverflow attacks
  • Logic errors
  • Any kind of Malwares
  • Covert Channels
  • ... ...

thanks

+2  A: 

Something that you haven't mentioned but I think is important: code reviews.

When you're just trying to implement something as fast as you can it is easy to overlook a security issue. A second pair of eyes can pick up many problems or potential problems, especially if the reviewer is experienced at spotting typical security holes.

I believe that it is possible in many cases to do manual code reviews without special tools. Just sit together at the same computer or even print out the code and do the review on the paper copy. But since you specifically asked for tools, a tool to help with manual code review is Rietveld. I haven't used it myself, but it is based on the same ideas used internally at Google (and written by the same guy, who also happens to be the author of Python).

Mark Byers
@Mark Byers,is this a kind of software or?
berkay
No: I mean getting a human reviewer to look at your code.
Mark Byers
@Mark Byers There should be more efficient way i guess.
berkay
@berkay: I think both techniques are useful. I don't think automatic testing tools will completely replace code reviews in the near future, if ever.
Mark Byers
@Mark Byers, thanks for the answer. appreciate it.
berkay
So what **tools** would help you do manual code reviews? (Static analysis tools like RATS and Coverity)
Rook
@Mark Byers oah i didn't read the very end, watching the youtube video right now :).
Rook
@The Rook: That's because I edited my post in response to your comment.
Mark Byers
A: 

Security is definitely a concern and developers should at least be aware of common vulnerabilities (and how to avoid them). Here are some resources that I find interesting:

Pascal Thivent
A: 

A tool doesn't know if your code is insecure.

Only you do (and the attackers).

At best the tool will spot a few vulnerabilities of one type in your code and make you realize you never protected against that type of vulnerability, but you will still have to go clean up all the instances the tool missed.

Longpoke
Tools help find low hanging fruit, although I agree there are some issues only a leet hacker can find.
Rook
@The Rook: If you write a 200K LOC program with an SQL DB , and you don't know how to prevent SQL injection, no tool on earth is going to save you. OP clearly doesn't know how to defend against all kinds of attacks, so the answer isn't to give him a tool, he should know how to defend against the attacks, and _then_ use a tool to check over.
Longpoke
+2  A: 

I'm going to focus on web application security here...

Really you want to get used to manually trawling through a website/application and playing with various parameters etc. so proxy tools are of great help (they allow you to capture and interact with forms, before they reach the server):

LiveHTTPHeaders - FireFox plugin.
Burp Proxy - Java based.

Obviously there becomes a point where manually crawling a whole website becomes rather time consuming/tedious and this is where automated scanning tools can be of help.

Black box:

WebSecurify - not used it but it's been created by a well known web app security guy.
Skipfish - Google released this recently so it's probably worth a look.

And there are many other commercial tools: WhiteHat Sentinel, HP Web Inspect and probably many others I can't remember.

White box:

A lot of the academic research I've seen is related to static code analysis tools; I've not used any because they all focused on PHP only and had some limitations.

Other resources:

ha.ckers.org - great blog, with an active forum related to web app sec. OWASP - as perviously mentioned, there are lots of insightful articles/guides/tutorials here.

If you want to learn more about manually attacking sites yourself the Damn Vulnerable Web App is a nice learning project. By that I mean, it's a web application that is written to be deliberately insecure, so you can test your knowledge of web application security vulnerabilities legally.

I wrote a black box scanner in Perl for my third year dissertation which was quite an interesting project. If you wanted to build something yourself it really just consisted of:

  • crawler
  • parser
  • attacker
Adam Taylor
+1 you actually posted links to useful tools.
Rook
+1  A: 

There are 2 types of software defects that can cause security problems: implementation bugs and design flaws.

Implementation bugs usually appear in a specific area in the code, they are relatively easy to detect and (usually) not too complicated to fix. You can detect (most) of these with automated tools that do static code analysis (tools like Fortify or Ounce) although these tools are expensive. With that said, you still have to remember that there are no "silver bullets" and you cannot not blindly rely only on the tool output without some sort of manual code review to confirm/understand the real risk behind the issues the tool reports.

The other problem is design flaws, that's another story. They are usually complex issues that are not consequence of a mistake in the code but poor choice in the design or architecture of the application. Those cannot be identified by an automated tool and really can only be detected manually, by a code/design/architecture review. They are usually very hard and expensive to fix passed the design phase.

So I recommend, reviewing your code for implementation bugs that can have impact on security (code review using automated tools like Fortify/Ounce + manual review of tool results) and reviewing your design for security flaws (no tools for this, has to be done by someone who knows about security).

For a good read on software security and the complexity behind designing secure software, check Software Security: Building Security In, by Gary McGraw (amazon link)

fms
@fms any software you can offer?
berkay
@berkay. You can check Fortify (http://www.fortify.com/products/) and Ounce (http://www.ouncelabs.com/) but both are very expensive. They can do data flow analysis, so it's not like just pattern search. On tho open source side, you can check the OWASP Code Crawler (http://codecrawler.codeplex.com/releases/view/43887) or Findbugs (http://findbugs.sourceforge.net/) although they don't analyze the data flow, they are more like powerful "greps" for potentially vulnerable patterns.
fms
+1 for fortify and other useful info.
Rook
A: 

I use tools to aid in the hunt for vulnerabilities, but you can't just fire off some test and assume everything is okay. When I am auditing a project I look at the code and I try and get a feel for the programmers style and skill level. If the code looks messy then chances are they are a novice and they will probably make novice mistakes.

It is important to identify security related functions in a project and manually audit them. Tamperdata is very helpful for manual auditing and exploit development because you can build custom http requests. A good example for manual auditing for PHP is: Are they using mysql_real_escape_string($var) or are they using htmlspecialchars($var,ENT_QUOTES) to stop sql injection? (ENT_QUOTES doesn't stop backslashes which is just as dangerous as quote marks for mysql, mssql is a different story.) Security functions are also places for "Logic errors" to crop up, and no tool is going to be able to detect this, this requires manual auditing.

If you are doing web application testing then Acunetix is the best testing tool you can use. Wapiti is a very good open source alternative. Although any tool can be used improperly. Before you do a web application test make sure error reporting is turned on, and also make sure you aren't suppressing sql errors, such as with a try/catch.

If you are doing Automated Static Code Analysis for vulnerabilities such as Buffer Overflows then Coverity is the best tool you can use(Fortify is nearly identical to Coverity). Coverity costs tens of thousands of dollars, but big names like the Department Of Homeland Security uses it. RATS is a open source alternative, although Coverity is far more complex of a tool. Both of these tools will produce a lot of false positives and false negatives. RATS looks for nasty function calls, but doesn't see if its still safe. So RATS will report every call to strcpy() strcat() sprintf(), but these can be safe if for instance you are just copying static text. This means you will have to dig though a lot of crap, but if you are doing a peer review then RATS helps a lot by narrowing the manual search. If you are trying to find a single exploitable vulnerability in a large code base, like Linux, then Rats isn't going to help much.

I have used Coverity and their sales team will claim it will "detect *ALL* vulnerabilities in your code base." But I can tell you from first hand experience that I found vanilla stack based buffer overflows with peach that Coverity didn't detect. (RATS did however pick up these issues, along with 1,000+ other function calls that where safe...) If you want a secure application or you want to find an exploitable buffer overflow then Peach is the platform tool you can use to build the tools you need.

If you are looking for more exotic memory corruption issues such as Dangling Pointers then Valgrind will help.

Rook
@The Rook, thanks for the answer, i was waiting for ur answer finally you wrote it:)
berkay
@berkay Hah, wow. I have updated my answer, feel free to ask questions.
Rook
Inability to exploit a program via fuzzer has nothing to do with weather it is secure or not.
Longpoke
"I have used Coverity and their sales team will claim it will "detect *ALL* vulnerabilities in your code base" Doesn't this hint that the program is garbage? Tamperdata is also garbage. I used Acuntex once a few years ago and I also found vulnerabilities within minutes after it being able to find nothing. Tamperdata crashes every 5 seconds. I can vouch for Valgrind though.
Longpoke
Might want to take a glance at this research before parting with cash for a commercial [web app sec] tool: http://ha.ckers.org/files/Accuracy_and_Time_Costs_of_Web_App_Scanners.pdf
Adam Taylor
@Longpoke Tamperdata is awesome for writing exploit code. I don't know why I would use anything else.
Rook
@Adam Taylor Wow I have never seen stats like this, thanks. But I'll be honest I use Acuentix because I have a pirated copy. I got Coverity though a trial, I pretended like I wanted to buy it. They gave me a nice teleconference tour for free. I recommend it if you have the spare time.
Rook
@Adam Taylor looks like I'm going to have to get a trial for ntoscanner :).
Rook