Docsity

Command Injection: Overview, Consequences, Mitigations and Examples, Slides of Software Engineering

Partial preview of the text

Download Command Injection: Overview, Consequences, Mitigations and Examples and more Slides Software Engineering in PDF only on Docsity!

It is better to ask forgiveness than

permission

Overview

  • What is Command Injection?
  • Extended Description
  • Applicable Platforms
  • Time of Introduction
  • Common Consequences
  • Demonstrative Examples
  • Potential Mitigations
  • Extra Defensive Measures (get tough);
  • Summary

Brute force example

String user_input ; Special_function_Sample(user_input) ;

user_input = “fred”; Special_function_Sample(fred)

User_input= fred”);print(“foo

Special_function_sample(“fred”); print(“foo”)

What if ….

Extended Description

Command injection vulnerabilities typically occur when:

  • Data enters the application from an untrusted source.
  • The data is part of a string that is executed as a command by the application.
  • By executing the command, the application gives an attacker a privilege or capability that the attacker would not otherwise have. (huge security breach)

Time of Introduction

  • Architecture and Design
  • Implementation

Common Consequences

Scope Effect

Access Control Command injection allows for the execution of arbitrary commands and code by the attacker

Integrity If a malicious user injects a character t delimits the end of one command and the beginning of another, it may be possible to then insert an entirely new and unrelated command that was not intended to be executed

Demonstrative Examples (continue)

Example 3 Language: Java

……. String script = System.getProperty("SCRIPTNAME"); if (script != null) System.exec(script); …….

Demonstrative Examples (continue)

Example4 Language: Perl use CGI qw(:standard); $name = param('name'); $nslookup = "/path/to/nslookup"; print header; if (open($fh, "$nslookup $name|")) { while (<$fh>) { print escapeHTML($_); print "
\n"; } close($fh); } Suppose an attacker provides a domain name like this:cwe.mitre.org%20%3B%20/bin/ls%20-l /path/to/nslookup cwe.mitre.org ; /bin/ls -l

Potential Mitigations (continue…)

Phase: Implementation

  • Code Review
  • Input Validation

Code Review (continue)

  • Identify every construct that could possibly be

used to invoke any kind of command

processor

  • If any of this construct are used check to see

if there is defensive measure taken

Input Validation (continue…)

There are three ways to determine data validity:

  • Black List
  • White List
  • The “quoting” approach

Example… python

for char in filename:

if ( not char in string.asscii_letters and

not char in string.digits and char <> .):

raise “inputvalidationError”

Resources

  • 19 dedly sins of software security –Michael Howard, David LeBlanc, and John Viega
  • Image cover : www.uberreview.com/2007/04/lethal- injection-a...
  • CWe - ttp://cwe.mitre.org/data/definitions/77.html
  • Advance Comand Injection Exploit -- david d. rude
  • http://www.owasp.org/index.php/Command_Injection
  • http://portal.acm.org/citation.cfm?id=