Docsity

Lecture Slides on Security Analysis | CS 4610, Study notes of Programming Languages

Partial preview of the text

Download Lecture Slides on Security Analysis | CS 4610 and more Study notes Programming Languages in PDF only on Docsity!

Security Analyses Security Analyses

For The Lazy Superhero For The Lazy Superhero

One-Slide Summary

  • We can statically detect buffer overruns in programs by modeling the space allocated for a buffer and the space used for a buffer. We cannot be right all the time.
  • SQL injection and cross-site scripting attacks occur when evil user input is used (parsed) as part of another important language (e.g., HTML or SQL).
  • Program analyses are expensive; recent research can randomize them to save time.

Static Analysis to

Detect Buffer Overruns

  • Detecting buffer overruns before distributing code would be better
  • Idea: Build a tool similar to a type checker to detect buffer overruns
  • This is a popular research area; we’ll present one idea at random [Wagner, Aiken, …] - You’ll see more in later lectures

Focus on Strings

  • Most important buffer overrun exploits are through string buffers - Reading an untrusted string from the network, keyboard, etc.
  • Focus the tool only on arrays of characters

Idea 2: The Abstraction

  • Model buffers as pairs of integer ranges
    • Alloc min allocated size of the buffer in bytes
    • Used max number of bytes actually in use
  • Use integer ranges
    • [x,y] = { x, x+1, …, y-1, y }
    • Alloc and used cannot be computed exactly

The Strategy

  • For each program expression, write constraints capturing the alloc and used of its string subexpressions
  • Solve the constraints for the entire program
  • Check for each string variable s used(s) · alloc(s)

Constraint Solving

  • Solving the constraints is akin to solving dataflow equations - Remember liveness? Constant prop?
  • Build a graph
    • Nodes are len(s), alloc(s)
    • Edges are constraints^ len(s)^ ·^ len(t)
  • Propagate information forward through the graph - Special handling of loops in the graph

Results

  • This technique found new buffer overruns in sendmail - Which is like shooting fish in a barrel …
  • Found new exploitable overruns in Linux nettools package
  • Both widely used
  • Previously hand-audited packages

Cat and Mouse

  • Suppose I have a server (e.g., Amazon.com)
  • Let's imagine that I have solved ...
    • Viruses: no malicious code on machine
    • Buffer overruns: no injection of evil assembly code
    • Buffer overruns: no non-control data attacks
    • Privileges: no running at root
    • Spam: as long as I'm dreaming, I'd like a pony ...
  • I can still convince the server to do the wrong thing with the resources it legitimately has access to ...

Three-Tier Web Application

  • This is how Amazon is structured
  • Query is a SQL database command generated by program logic

$userid = read_from_network(); if (!eregi('[0-9]+', $userid)) { unp_msg('You entered an invalid user ID.'); exit; } $user = $DB->query(“SELECT * FROM unp_user”. “WHERE userid='$userid'”); if (!DB->is_single_row($user)) { unp_msg('You entered an invalid user ID.'); exit; }

The Problem

Matches any string that

contains a sequence of

digits...

The Bad Place

// $userid == “1'; DROP TABLE unp_user; --” if (!eregi('[0-9]+', $userid)) { unp_msg('You entered an invalid user ID.'); exit; } $user = $DB->query(“SELECT * FROM unp_user”. “WHERE userid='$userid'”); if (!DB->is_single_row($user)) { unp_msg('You entered an invalid user ID.'); exit; }

Also A Bad Place: Viewing Data

// $userid == “1' OR 1 = 1 --” if (!eregi('[0-9]+', $userid)) { unp_msg('You entered an invalid user ID.'); exit; } $user = $DB->query(“SELECT * FROM unp_user”. “WHERE userid='$userid'”); if (!DB->is_single_row($user)) { unp_msg('You entered an invalid user ID.'); exit; } SELECT * FROM unp_user WHERE userid='1' OR 1 = 1 --'

SQL Code-Injection Vulnerabilities

  • A SQL injection attack exploits a vulnerability in the database layer of an application whereby user input is incorrectly filtered for string literal escape characters or otherwise unexpected executed.
  • Most common types of vulnerability in 2006:
    • 25.1% Cross-Site Scripting
    • 14% SQL Command Injection
    • 7.9% Buffer Overruns
  • Attacks are easy and expose valuable data