CGI Security COEN 351. CGI Security Security holes are exploited by user input. We need to check user input against Buffer overflows etc. that cause a.

Slides:



Advertisements
Similar presentations
PHP Form and File Handling
Advertisements

Module XIV SQL Injection
Hossain Shahriar Mohammad Zulkernine. One of the worst vulnerabilities in web applications It involves the generation of dynamic HTML contents with invalidated.
What is code injection? Code injection is the exploitation of a computer bug that is caused by processing invalid data. Code injection can be used by.
© 2008 Security Compass inc. 1 Firefox Plug-ins for Application Penetration Testing Exploit-Me.
Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation.
Chapter 9 Web Applications. Web Applications are public and available to the entire world. Easy access to the application means also easy access for malicious.
Linux+ Guide to Linux Certification, Second Edition
Information Networking Security and Assurance Lab National Chung Cheng University The Ten Most Critical Web Application Security Vulnerabilities Ryan J.W.
Information Networking Security and Assurance Lab National Chung Cheng University 1 Top Vulnerabilities in Web Applications (I) Unvalidated Input:  Information.
Guide To UNIX Using Linux Third Edition
CGI Programming: Part 1. What is CGI? CGI = Common Gateway Interface Provides a standardized way for web browsers to: –Call programs on a server. –Pass.
Designing Security In Web Applications Andrew Tomkowiak 10/8/2013 UW-Platteville Software Engineering Department
Web Application Vulnerabilities Checklist. EC-Council Parameter Checklist  URL request  URL encoding  Query string  Header  Cookie  Form field 
Martin Kruliš by Martin Kruliš (v1.0)1.
1 ‘Dynamic’ Web Pages So far, we have developed ‘static’ web-pages, e.g., cv.html, repair.html and order.html. There is often a requirement to produce.
Chapter 9 Using Perl for CGI Programming. Computation is required to support sophisticated web applications Computation can be done by the server or the.
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
Security.NET Chapter 1. How Do Attacks Occur? Stages of attack Examples of attacker actions 1. FootprintRuns a port scan on the firewall 2. PenetrationExploits.
Internet / Intranet CIS-536 Class 7. 2 HTML Forms A Method to Allow Users to Pass Information to a CGI Script Forms Allow Information to Be Entered Via:
CSCI 6962: Server-side Design and Programming Secure Web Programming.
Web Application Access to Databases. Logistics Test 2: May 1 st (24 hours) Extra office hours: Friday 2:30 – 4:00 pm Tuesday May 5 th – you can review.
Chapter 9 Web Applications. Web Applications are public and available to the entire world. Easy access to the application means also easy access for malicious.
JavaScript, Fourth Edition
© All rights reserved. Zend Technologies, Inc. PHP Security Kevin Schroeder Zend Technologies.
Week 7 Working with the BASH Shell. Objectives  Redirect the input and output of a command  Identify and manipulate common shell environment variables.
Lecture slides prepared for “Computer Security: Principles and Practice”, 3/e, by William Stallings and Lawrie Brown, Chapter 5 “Database and Cloud Security”.
Introduction to Programming the WWW I CMSC Summer 2004 Lecture 6.
USING PERL FOR CGI PROGRAMMING
OSI and TCP/IP Models And Some Vulnerabilities AfNOG th May 2011 – 10 th June 2011 Tanzania By Marcus K. G. Adomey.
Attacking Applications: SQL Injection & Buffer Overflows.
Security Scanners Mark Shtern. Popular attack targets Web – Web platform – Web application Windows OS Mac OS Linux OS Smartphone.
Top Five Web Application Vulnerabilities Vebjørn Moen Selmersenteret/NoWires.org Norsk Kryptoseminar Trondheim
Linux+ Guide to Linux Certification Chapter Eight Working with the BASH Shell.
OWASP Top Ten #1 Unvalidated Input. Agenda What is the OWASP Top 10? Where can I find it? What is Unvalidated Input? What environments are effected? How.
Website Development with PHP and MySQL Saving Data.
CGI Common Gateway Interface. CGI is the scheme to interface other programs to the Web Server.
Input Validation – common associated risks  ______________ user input controls SQL statements ultimately executed by a database server
Aniket Joshi Justin Thomas. Agenda Introduction to SQL Injection SQL Injection Attack SQL Injection Prevention Summary.
CGI Scripting and Vulnerabilities COEN 351: E-commerce Security.
By Sean Rose and Erik Hazzard.  SQL Injection is a technique that exploits security weaknesses of the database layer of an application in order to gain.
Crash Course in Web Hacking
HTTP-security Web servers are a major security concern in Windows NT and also more generally. One reason is that HTTP is one of the few services visible.
CSE 341, S. Tanimoto Lisp CGI - 1 Lisp CGI Programming for the Web Web servers can invoke Lisp to “intelligently” create web pages on the fly. We will.
More CGI Programming Here-docs HTML::Template Cookies File Uploading Taint Checking.
Creating Databases for Web applications Server side vs client side PHP basics Homework: Get your own versions of sending working: both html and Flash!
OWASP Building Secure Web Applications And the OWASP top 10 vulnerabilities.
Security Issues with PHP  PHP installation  PHP programming Willa Zhu & Eugene Burger.
 Previous lessons have focused on client-side scripts  Programs embedded in the page’s HTML code  Can also execute scripts on the server  Server-side.
 2001 Prentice Hall, Inc. All rights reserved. Chapter 7 - Introduction to Common Gateway Interface (CGI) Outline 7.1Introduction 7.2A Simple HTTP Transaction.
Security Issues With Web Based Systems. Security Issues Web Based Systems  Security can not be considered an add-on or afterthought  Security must be.
Linux+ Guide to Linux Certification, Second Edition
Secure Transactions Chapter 17. The user's machine No control over security of user's machine –Might be in very insecure: library, school, &c. Users disable.
Introduction to Programming the WWW I CMSC Winter 2003 Lecture 17.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
PHP: Further Skills 02 By Trevor Adams. Topics covered Persistence What is it? Why do we need it? Basic Persistence Hidden form fields Query strings Cookies.
Linux Administration Working with the BASH Shell.
Radoslav Georgiev Telerik Corporation
Lesson 11. CGI CGI is the interface between a Web page or browser and a Web server that is running a certain program/script. The CGI (Common Gateway Interface)
University of Kansas Department of Electrical Engineering and Computer Science Dr. Susan Gauch April 21, 2005 I T T C Introduction to Web Technologies.
Database and Cloud Security
Building Secure ColdFusion Applications
Protecting Memory What is there to protect in memory?
CS 330 Class 7 Comments on Exam Programming plan for today:
Protecting Memory What is there to protect in memory?
SQL Injection.
Protecting Memory What is there to protect in memory?
CS 371 Web Application Programming
Introduction to Programming the WWW I
SHELLSHOCK ATTACK.
Presentation transcript:

CGI Security COEN 351

CGI Security Security holes are exploited by user input. We need to check user input against Buffer overflows etc. that cause a program to misbehave. Input that is interpreted differently than the designer expects it.

CGI Security Interpretation example: Assume that we call a program within a script and pass user-provided parameters to the program. For example, a pretty-printer for ASCII art.

CGI Security Interpretation Example #!usr/bin/perl –w use CGI my $App = /temp/app.exe’; my $q = new CGI; my $string = $q->param( “string” ); unless ( $string ) { error( $q, “Need string parameter”);} local *PIPE; open PIPE, “$App \”$string\” |” or die “Cannot open pipe: $!”; print q->header(“text/plain” ); print while ; close PIPE;

CGI Security Interpretation Example We first verify that the user enters a string. We use a pipe in order to stream the output of app to the page. The “print while ;” statement takes the output one line at a time and prints it out.

CGI Security Interpretation Example #!usr/bin/perl –w use CGI my $App = /temp/app.exe’; my $q = new CGI; my $string = $q->param( “string” ); unless ( $string ) { error( $q, “Need string parameter”);} local *PIPE; open PIPE, “$App \”$string\” |” or die “Cannot open pipe: $!”; print q->header(“text/plain” ); print while ; close PIPE;

CGI Security Interpretation Example When Perl opens up a pipe, then user input is passed through a shell Assume users types in ‘rm -rf /’ on a Unix machine. The command would execute as if the following command would have been entered into a shell: $ /temp/app.exe “ \rm –rf /’ “

CGI Security Interpretation Example When Perl opens up a pipe, then user input is passed through a shell Assume users types in “; mail < /etc/passwd” on a Unix machine. The command would execute as if the following command would have been entered into a shell: $ /temp/app.exe “”; mail < /etc/passwd

CGI Security Interpretation Example Clearly, we need to be careful about filtering out bad input. Other examples include SQL injection attacks Access to resources

CGI Security Interpretation Example A simplistic countermeasure checks the input for bad characters, before we pass user input to the pipe. This is a bad strategy because it only excludes possible attacks. Much better to positively identify good input. Before 9/11, visa to US was granted unless there was a positive reason to exclude some-one. (Bad list.) After 9/11, visa to US demands proof of good attitudes. Bad policy maybe for the US, but good policy for web- servers (unless you eliminate legitimate traffic).

CGI Security Interpretation Example #!usr/bin/perl –w use CGI my $App = /temp/app.exe’; my $q = new CGI; my $string = $q->param( “string” ); unless ( $string ) { error( $q, “Need string parameter”);} if ($string =~ /[ ‘\$\\” ‘ ;& … ] ) {error($q, “Bad input”);} local *PIPE; open PIPE, “$App \”$string\” |” or die “Cannot open pipe: $!”; print q->header(“text/plain” ); print while ; close PIPE; This excludes characters $ \ “ ` ; &

CGI Security Interpretation Example We want to only allow strings that are alpha- numerical, have underscores, hyphens, periods, question marks, and exclamation points. However, the strategy of enumerating bad characters needs to be amended to exclude all possible escape sequences: ASCII / Unicode escapes Foreign language symbols Double escapes

CGI Security Interpretation Example #!usr/bin/perl –w use CGI my $App = /temp/app.exe’; my $q = new CGI; my $string = $q->param( “string” ); unless ( $string ) { error( $q, “Need string parameter”);} if ($string =~ /^[\w.!?-]+$/ ) {error($q, “Bad input”);} local *PIPE; open PIPE, “$App \”$string\” |” or die “Cannot open pipe: $!”; print q->header(“text/plain” ); print while ; close PIPE; This lists good characters: alpha-numeric. ! ? -

CGI Security Interpretation Example This is much better. But do we positively know that one could not write an attack string that way? What about users using a different character set? More importantly, a minor change can destroy the security. Better not use this idea.

CGI Security Interpretation Example Prevent the root problem: Do not pass arguments through the shell. First fork. Then let the child process call exec. This will prevent part of malicious user input to end up as a command.

CGI Security Interpretation Example #!usr/bin/perl –w use CGI my $App = /temp/app.exe’; my $q = new CGI; my $string = $q->param( “string” ); unless ( $string ) { error( $q, “Need string parameter”);} local *PIPE; my $pid = open PIPE, “-|”; die “Cannot fork $!” unless defined $pid; unless ( $pid ) { exec app, $ string or die “Cannot open pipe: $!”; } print q->header(“text/plain” ); print while ; close PIPE; This script bypasses the shell. This call to “open” tells Perl to fork and create a child process with a pipe connected to it. The child process is a copy of the current executing script and continues from the same point. Parent receives $pid of child process. Child receives $pid of zero. Child process calls exec, which calls the app on the input. Parent maintains pipe to the app.

CGI Security DO NOT TRUST INPUT Data in hidden fields can be changed by the user. Referer data can be changed. Data in cookies can be changed.

CGI Security Hidden Forms are not secure:

CGI Security Hidden forms are not secure: This script generates a new URL ame=Super+Blaster+3000&quantity=1&su bmit=Order. User can simply edit this URL and get another price posted to the webserver.

CGI Security Hidden forms are not secure Therefore, we use the Post-method. However: Attacker can save the webpage. Edit the form-field Change price that way. CGI script cannot distinguish which webpage called.

CGI Security Other possibility: Trust the referer field in the header. Someone using a standard browser cannot alter easily the referer field. However, you can send HTTP commands directly with netcat, … my $server = quotemeta( $ENV{HTTP_HOST} || $ENV(SERVER_NAME) ); unless ($ENV{HTTP_REFERER} =~ m|^https?://$server/| ) { error( $q, “Invalid referring URL.” );}

CGI Security Do not trust unencoded cookies. User can access and alter the cookie with any number of tools.

CGI Security Countermeasures: Protect data with encryption. Use SSL to protect data integrity and content in transit. Validate any information that the user can change by signature or digest.

CGI Security Protection Mechanism against alteration Use a secure digest: Concatenate values in hidden form with a secret value. Store the hash of the resulting string. When you receive data, verify the hash.

CGI Security Protection Mechanism against alteration

Perl Taint Mode Perl offers some protection against user input. In taint mode, Perl will not allow any data from outside the application to affect anything outside the application. Tainted variables can not be passed to eval shell calls on the file system

Perl Taint Mode Tainted variables taint variables calculated from them. However, to make things work, you usually need to untaint variables: If a variable matches with a regular expression using () groups, then they become untainted. if ($ =~ { $ = } else { warn ("TAINTED DATA SENT BY $ENV{'REMOTE_ADDR'}: $ $!"); $ = ""; # successful match did not occur }

CGI Security Data Storage Issues Danger: Opening files when the filename is dynamically generated based on user input. Move data files out of web server tree. Set file permissions. Principle of minimal permission. Files that only need to be read should be owned by nobody and should be write protected.

CGI Security Learn the Odds and Ends User should not be able to send to anyone but a single entity. Otherwise, it is trivial to fake coming from your organization.