Secure Programming With Static Analysis
Secure Programming With Static Analysis
Complexity
Unforeseen Consequences
1.
2. 3.
Little errors can hurt a lot. Smart people make dumb mistakes.
As a group, programmers tend to make the same security mistakes over and over.
4.
Problems
Cross-site Scripting
Vulnerable Site
Malicious Site
Firewall
Victim Browser
Cross-Site Scripting
Cross-site scripting looks more and more like buffer overflow Buffer Overflow
Allows Arbitrary Code Execution Exploit is hard to write Easy mistake to make in C/C++ Well known problem for decades
Cross-site Scripting
Allows Arbitrary Code Execution Exploit is easy to write Easy mistake to make Well known problem for a decade
Answers
Competitors
Network-devices
Security in a Box
Focusing on the attack over the root cause, Now fixes applications is now the latest craze. Focused on protecting the infrastructure not the software. Some solutions serve as a stop gap, but by no means replace the need to build security in.
Security Light
Simply trying harder does not result in good security. To broaden reach of niche products, static analysis vendors add security to a list of quality issues. Security issues are not just another bug.
Plan
Build
Test
Field
Plan
Build
Test
Field
"Since most security for Web applications can be implemented by a system administrator, application developers need not pay attention to the details of securing the application"
BEA WebLogic Documentation
Opportunity
Todays Motivators
1) protect the business from bad guys
Developers Management
Security Testers
Build Server
chainsaw
Static Analysis
Fast compared to manual review Fast compared to testing Consistent Brings security knowledge with it Makes security review process easier for non-experts
RATS
Flawfinder ITS4
RATS
Flawfinder
ITS4
No Silver Bullet
Static Analysis Limitations Does not understand architecture Does not understand application semantics Does not understand social context
Type Checking
Taken for granted Imperfect:
short s = 0; int i = s; /* the type checker allows this */ short r = i; /* false positive: this will cause a type checking error at compile time.*/ /* false negative: passes type checking, fails at runtime */ Object[] objs = new String[1]; objs[0] = new Object();
Style Checking
Pickier than type checker, might look at
Whitespace Naming Deprecated functions gcc -Wall does some style checking
typedef enum { red, green, blue } Color; char* getColorString(Color c) { char* ret = NULL; switch (c) { case red: printf("red"); } return ret; }
Tools
Lint, PMD
Program Understanding
Help make sense of a large codebase Tools:
Fujaba Klockwork CAST Systems
Soundness Aspires to Sound WRT the specification: reports a bug if one exists Tools: Praxis, PolySpace, GrammaTech
Bug Finding
More sophisticated than a style checker Less ambitious than program verification Search code for bug idioms Find high-confidence, low noise results (low false positives) Soundness Example: double checked locking
if (fitz == null) { synchronized (this) { if (fitz == null) { fitz = new Fitzer(); } } }
Aspires to Sound WRT counterexample: never reports a bug that isnt a bug
Tools:
Security Review
Focus on finding exploitable code Find high-risk code constructs for review (low false negatives) Hint: summarize, dont simulate Tools Ancient: RATS, ITS4, FlawFinder New: Fortify Software and Ounce Labs
(command injection)
Analyzer
src
Front End
System Model
Analyzer
Results Viewer
Analyzer
Modeling Rules
Security Properties
Parsing
Language support
One language/compiler is straightforward Lots of combinations is harder
but
Decompilation can be difficult Loss of context hurts. A lot. Remediation requires mapping back to source anyway
(other operations)
freed
(other operations) free(x)
error
(other operations)
freed
(other operations) free(x)
error
(other operations)
freed
(other operations) free(x)
error
Interface
Must convince programmer that theres a bug in the code Different interfaces for different scenarios: Security auditor parachutes in to 2M line program Programmer reviews own code Programmers share code review responsibilities Interface is just as important as analysis Dont show same bad result twice
Common Problems
False positives Incomplete/inaccurate model Conservative analysis False negatives Incomplete/inaccurate model Missing rules Forgiving analysis
Untapped Potential
Customization Unique to your application or organization Design for testability Write code knowing that it will be checked
3) Do training up front
Software security training more important than tool training Tool training is helpful too
6) Appoint a champion
Make sure there is a point person on the dev team Choose a developer who knows a little about everything
Conventions
Design
Algorithms
Data Structures
Protocols
<Your Code>
Libraries
Language
Platform
Conventions
Design
Algorithms
Data Structures
Protocols
<Your Code>
Libraries
Language
Platform
Right answer
Better languages, libraries, frameworks, platforms, etc
Realistic answer
Build secure programs out of insecure pieces
Conventions Design Algorithms
Data Structures
Libraries
Language
Platform
Summary