User authentication, passwords

Slides:



Advertisements
Similar presentations
Enabling Secure Internet Access with ISA Server
Advertisements

Cookies, Sessions. Server Side Includes You can insert the content of one file into another file before the server executes it, with the require() function.
Forms Authentication, Users, Roles, Membership Ventsislav Popov Crossroad Ltd.
Members Only & Login Modules Members Only works with the Login module to provide password protection to Web pages and files. Login Groups may be created.
1 Configuring Internet- related services (April 22, 2015) © Abdou Illia, Spring 2015.
1 Configuring Web services (Week 15, Monday 4/17/2006) © Abdou Illia, Spring 2006.
Apache Configuration Setting up a web server. Basic Server Facts Runs on port 80 Server application -> httpd Richly configurable Many defaults will let.
Chapter Apache Installation in Linux- Mandrake. Acknowledgment The following information has been obtained directly from
Apache Access Controls. Ways to control Allow/Deny access control –By IP –By domain name Password –Apache managed passwords –Realms.
Access control and user management in Apache 1WUCM1.
CP476 Internet Computing Browser and Web Server 1 Web Browsers A client software program that allows you to access and view Web pages on the Internet –Examples.
Apache : Installation, Configuration, Basic Security Presented by, Sandeep K Thopucherela, ECE Department.
SSL (Secure Socket Layer) and Secure Web Pages Rob Sodders, University of Florida CIS4930 “Advanced Web Design” Spring 2004
APACHE SERVER By Innovationframes.com »
Linux Operations and Administration
Microsoft Windows 2003 Server. Client/Server Environment Many client computers connect to a server.
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.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
Class 8Intro to Databases Authentication and Security Note: What we discuss in class today covers moderate to low security. Before you involve yourself.
CHAPTER 12 COOKIES AND SESSIONS. INTRO HTTP is a stateless technology Each page rendered by a browser is unrelated to other pages – even if they are from.
Forms Authentication, Users, Roles, Membership Svetlin Nakov Telerik Corporation
An introduction to Apache. Different Types of Web Servers Apache is the default web server for may Unix servers. IIS is Microsoft’s default web server.
Implementing ISA Server Publishing. Introduction What Are Web Publishing Rules? ISA Server uses Web publishing rules to make Web sites on protected networks.
5 Chapter Five Web Servers. 5 Chapter Objectives Learn about the Microsoft Personal Web Server Software Learn how to improve Web site performance Learn.
Copyright 2000 eMation SECURITY - Controlling Data Access with
Microsoft Internet Information Services 5.0 (IIS) By: Edik Magardomyan Fozi Abdurhman Bassem Albaiady Vince Serobyan.
Web Services CSCI N321 – System and Network Administration Copyright © 2007,2008 by Scott Orr and the Trustees of Indiana University.
IT:Network:Apps.  Microsoft Web Server ◦ Used by ~ 50% of Fortune 500 companies  Comes with Server OS  Expandable  Easy to use.
Course ILT Internet/intranet support Unit objectives Use the Internet Information Services snap-in to manage IIS, Web sites, virtual directories, and WebDAV.
Set 13: Web Servers (configuration and security) (Chapter 21) IT452 Advanced Web and Internet Systems.
Apache and... Virtual Hosts ---- aliases mod_rewrite ---- htaccess AFNOG 11 Kigali, Rwanda May 2010 Dorcas Muthoni Courtesy: Hervey Allen.
Database-Driven Web Sites, Second Edition1 Chapter 5 WEB SERVERS.
FTP Server and FTP Commands By Nanda Ganesan, Ph.D. © Nanda Ganesan, All Rights Reserved.
Chapter 8 Cookies And Security JavaScript, Third Edition.
Week seven CIT 354 Internet II. 2 Objectives Database_Driven User Authentication Using Cookies Session Basics Summary Homework and Project 2.
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
Web Site Access Control with Apache Fort Collins, CO Copyright © XTR Systems, LLC Web Site Access Control Using the Apache Web Server Instructor: Joseph.
Chapter 6: Authentications. Training Course, CS, NCTU 2 Overview  Getting Username and Password  Verifying Username and Password  Keeping The Verification.
Apache Security Travis Jeffries. Introduction Authentication and Authorization Strict Access Methods Defending against Attacks Bad CGI Programs Apache.
Module 11: Securing a Microsoft ASP.NET Web Application.
Cosc 4750 Configuring httpd, Mysql, And Samba. defaults By default httpd demean will startup and work User directories are turned off Default directory.
Web Database Programming Week 7 Session Management & Authentication.
1 Apache and... Virtual Hosts ---- aliases mod_rewrite ---- htaccess AFNOG X Cairo, Egypt May 2009 Hervey Allen.
Sessions, Cookies, &.htaccess IT 210. Procedural Issues  Quiz #3 Today!  Homework #3 Due Friday at midnight UML for Lab 4  Withdraw Deadline is Wed,
LinuxChix Apache. Serving Webpages The layer 7 protocol (HTTP) is what our browsers talk to get us the websites we can't seem to live without. HTTP is.
PHP-based Authentication
PHP Secure Communications Web Technologies Computing Science Thompson Rivers University.
1 Chapter Overview Creating Web Sites and FTP Sites Creating Virtual Directories Managing Site Security Troubleshooting IIS.
Authentication Names and Passwords Names and Passwords Also can use Groups Also can use Groups Webmaster can “require” authentication Webmaster can “require”
Database Access Control IST2101. Why Implementing User Authentication? Remove a lot of redundancies in duplicate inputs of database information – Your.
Web Technology – Web Server Setup : Chris Uriarte Meeting 4: Advanced Topics, Continued: Securing the Apache Server and Apache Performance Tuning Rutgers.
More than one site? Use multiple configuration files Use multiple configuration files  httpd –d {path}  Assumes “conf/httpd.conf” Logging transactions.
FTP COMMANDS OBJECTIVES. General overview. Introduction to FTP server. Types of FTP users. FTP commands examples. FTP commands in action (example of use).
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 2: Introduction to IS2803 Rob Gleasure
PHP Form Processing * referenced from
Unit-6 Handling Sessions and Cookies. Concept of Session Session values are store in server side not in user’s machine. A session is available as long.
Securing Web Applications Lesson 4B / Slide 1 of 34 J2EE Web Components Pre-assessment Questions 1. Identify the correct return type returned by the doStartTag()
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
Installing and Configuring Moodle. Download Download latest Windows Install package from Moodle.orgMoodle.org.
Web Server Administration Chapter 6 Configuring a Web Server.
Authentication & Authorisation Is the user allowed to access the site?
ArcGIS for Server Security: Advanced
Unit 7 Learning Objectives
Apache and... Virtual Hosts ---- aliases mod_rewrite ---- htaccess
Authentication & .htaccess
Enhanced Web Site Design Stanford University Continuing Studies CS 22
Unix System Administration
IIS.
Configuring Internet-related services
Designing IIS Security (IIS – Internet Information Service)
Presentation transcript:

User authentication, passwords Restricting Access User authentication, passwords

User Authentication Nowadays most internet applications are available only for registered (paying) users How do we restrict access to our website only to privileged users? Use login forms for user authentication

A simple login script What are the limitations of this? <html> <head><title>User Authentication</title></head> <body> <?php $user = strtolower($_POST["user"]); $pass = strtolower($_POST["pass"]); if (isset($user) && isset($pass) && $user=="php5" && $pass=="iscool") { ?> <h1>Welcome! Here is the truth about aliens visiting Earth ...</h1> } else { <h3>Please login</h3> <form method=post> User name: <input type=text name=user /><br/> Password: <input type=password name=pass /><br /> <input type=submit name=submit value=Login /> </form> } </body> </html> What are the limitations of this?

Limitations of simple login script It only protects the page on which it is included. We could include it on all pages we wish to protect using something like: include “login.php” Clearly not a good solution!

include vars.php <?php $color = 'green'; $fruit = 'apple'; ?> test.php <?php echo "A $color $fruit"; // A include 'vars.php'; echo "A $color $fruit"; // A green apple ?> When a file is included, the code it contains inherits the variable scope of the line on which the include occurs.

HTTP Authentication HTTP provides a mechanism for user authentication User credentials are sent in HTTP headers and stored in the server-side as superglobals: $_SERVER[‘PHP_AUTH_USER’] $_SERVER[‘PHP_AUTH_PW’]

Pre-pend this to all PHP files you wish to protect using include HTTP login script <?php // Has authorization been set? if (isset( $_SERVER["PHP_AUTH_USER"]) ) { // Get username and password $user = htmlspecialchars($_SERVER["PHP_AUTH_USER"]); $pass = htmlspecialchars($_SERVER["PHP_AUTH_PW"]); if (isset($user) && isset($pass) && $user=="dug" && $pass=="paradise") { echo "<h1>Welcome! You are logged in"; } // Otherwise send an HTTP header requesting authentication else { header("WWW-Authenticate: Basic realm=\"PHP 5 Protected Area\""); header("HTTP/1.1 401 Unauthorized"); ?> Pre-pend this to all PHP files you wish to protect using include

HTTP Authentication disadvantages Requires you to have certain privileges on your hosting web server Implementation depends on your web server application Preceding examples are for Apache IIS server requires manipulation of $_SERVER[‘HTTP_AUTHORIZATION’] Does not work in cgi mode (i.e. Xitami on Windows)

PHP Sessions Create a true login “session” Use session variables to tag a “logged in” status

Login script using sessions <?php session_start(); if (isset( $_POST["submit"] ) )// Have the credentials been submitted? { $user = strtolower($_POST["user"]); $pass = strtolower($_POST["pass"]); if ($user=="dug" && $pass=="paradise") { $_SESSION["username"] = $user; } else { echo "<p>Login incorrect!"; } ?> <html><head><title>Authentication</title></head><body> if (isset( $_SESSION["username"] ) ) { echo "<p>You are logged in"; } else { ?> <h3>Please login</h3> <form method=post> User name: <input type=text name=user /><br/> Password: <input type=password name=pass /><br /> <input type=submit name=submit value=Login /> </form> <?php } ?>

More Advanced logins Redirect after logging in Store login information for registered users Take login information from a file storing usernames and passwords of registered users Store this information in a database (see later) Raises issues of data security.

Authentication using Apache Part 1: Server Configuration: httpd.conf

Apache Authentication: Authorization: Access control Verify if the user/passwd correct Authorization: Once authenticated, does user have permission? Access control Grant or deny access based on some criteria e.g., IP address, group name, domain ...

File-based authentication Apache has a module that provides authentication mod_auth_basic Similar to /etc/passwd in Unix Entries look like admin:kajsJjkh97U (encrypted) To add a user (Linux and Windows) htpasswd -c <file> <userid> This creates a new file with encrypted passwords htpasswd <file> <userid2> Appends other users

Creating a user password file SYNTAX: htpasswd -c <file> <userid> C:\Program Files (x86)\EasyPHP-5.3.3\apache\bin>htpasswd -c password napoleon Automatically using MD5 format. New password: ******** Re-type new password: ******** Adding password for user napoleon Create a new file (will delete if it exists already) To create the file, use the htpasswd utility that came with Apache. This is located in the bin directory of wherever you installed Apache. Filename: password napoleon:$apr1$B5gzgGKw$AWVqtO2Romn5B4Zkc1bPk0 Encrypted password = hash key or message digest - One way

Settings for this Example Note: The password file was moved to another directory. Password File: C:\Program Files (x86)\EasyPHP-5.3.3\apache\users\password Restricted Directory: C:\Program Files (x86)\EasyPHP-5.3.3\www\protected

Configuring Apache: httpd.conf Directory you want to restrict access to Filename: httpd.conf <Directory "${path}/www/protected"> AuthUserFile "${path}/apache/users/password" AuthName "This is a protected area" AuthGroupFile /dev/null AuthType Basic Require valid-user </Directory> File containing user passwords Putting authentication directives in a <Directory> section, in your main server configuration file, is the preferred way ${path} = directory of easyPHP

Configuration Parameters AuthUserFile The location of the password file. AuthName The authentication realm or name. This is the message that the user will see in the username/password pop-up. AuthGroupFile The location of the group file, if any. AuthType The type of authentication being used. Require What conditions need to be satisfied in order to allow the user through. It could be more than one condition.

Summary of Steps Create a password file. Move the password file into a separate folder. Create a directory to be restricted access to. Modify Apache’s httpd.conf. Restart Apache webserver after making the modifications.

Sample Run: Accessing a “protected” section of your site a dialog box automatically pops-up for user authentication

Sample Run: Invalid user name, password!

Demo See Apache configuration, using EasyPHP. Find mod_auth_basic

Authentication using Apache Part 2: .htaccess files The .htaccess file is used to override default server settings in particular folders (directories). .htaccess files should be used only if you don't have access to the main server configuration file

File-based authentication By default overriding is not set on httpd.conf (Linux: in /etc/httpd/conf/) ... <Directory /> Options FollowSymLinks AllowOverride None </Directory> Follow Symbolic Links If FollowSymlinks is NOT set at all, Apache has to issue some extra system calls when looking for a file. For example, if you browse to the /index.html document, Apache would look for that file in your /www, /www/htdocs, and /www/htdocs/index.html. These additional system calls will add to the latency. The system call results are not cached, so they will occur on every request. Specifies which directives declared in the .htaccess file can override earlier configuration directives. http://www.maxi-pedia.com/FollowSymLinks

Example: File-based authentication Filename: httpd.conf AccessFileName .htaccess <Directory /> Options FollowSymLinks AllowOverride None Order Deny, Allow Deny from All </Directory> <Directory "${path}/www/protected2"> AllowOverride All Order allow,deny Allow from all Note that the default Apache access for <Directory /> is Allow from All. This means that Apache will serve any file mapped from an URL. This is the recommended initial setting! We can then override this for directories we want accessible. http://httpd.apache.org/docs/2.2/mod/core.html#directory Specifies which directives declared in the .htaccess file can override earlier configuration directives.

Settings for this Example Note: The password file was moved to another directory. Password File: C:\Program Files (x86)\EasyPHP-5.3.3\apache\users\password Restricted Directory: C:\Program Files (x86)\EasyPHP-5.3.3\www\protected2 Away from the folder open to the public (not in the document root)

Example: .htaccess Filename: .htaccess AuthUserFile "C:/Program Files/EasyPHP-5.3.2i/apache/users/password" AuthName "Protected Area 2" AuthGroupFile /dev/null AuthType Basic Require valid-user Create the file using a temporary name first, then rename it afterwards implemented by mod_auth_basic. (Alternatively, mod_auth_digest for Digest), better but non-standard yet. To implement authentication, you must also use the AuthName and Require directives. In addition, the server must have an authentication-provider module such as mod_authn_file and an authorization module such as mod_authz_user. Directory: C:\Program Files\EasyPHP-5.3.2i\www\protected2 Your .htaccess file should reside in this directory

Sample Run Filename: .htaccess AuthUserFile "C:/Program Files/EasyPHP-5.3.2i/apache/users/password" AuthName "Protected Area 2" AuthGroupFile /dev/null AuthType Basic Require valid-user

.htaccess files Pros Cons Easy way to allow authentication Control is given to users (developers) No admin Cons Performance: Apache reads and looks for .htaccess files for every GET Wrong permissions (given by directory owners) can lead to security problems

Another .htaccess Example (Linux) If allowed, the following .htaccess file overrides authorisation: <Directory /www/mysite/example> IndexIgnore * ##does not allow dir lists AuthType Basic AuthName "Private Area" ##popup AuthUserFile /usr/local/apache/passfile AuthAuthoritative on Require valid-user </Directory>

Options FollowSymLinks More on Apache Webserver’s Configuration Options FollowSymLinks Order Allow, Deny

Options FollowSymLinks Follow Symbolic Links Websites are often set up in a way that they show pictures and other content as being physically located at some other location than they really are. If a visitor requests /system/files/images/image.png then show him /pictures/image.png.“ You might see something like IMG SRC="/system/files/images/image.png" for the location of some picture. This would be viewable by a browser, but not downloadable as it resides in another physical directory. Enable FollowSymLinks by default Symbolic links are available in NTFS starting with Windows Vista. http://msdn.microsoft.com/en-us/library/aa365680(v=VS.85).aspx

Order Allow, Deny Restricting access Order allow, deny is a setting in your Apache web server configuration that is used to restrict access to certain directories (folders) or even globally. Configuring who can access your directories is very important for your web site security. Order allow,deny is one way to restrict who can see what.

Order Allow, Deny Restricting access The Allow directive affects which hosts "can access" an area of the server. Access is usually controlled by hostname, IP address, or IP address range. The Deny directive "restricts access" to the server. Restrictions can be based again on hostname, IP address, or environment variables. We can set the Order directive in two ways: Order allow, deny Order deny, allow

Order Allow, Deny Restricting access Order allow, deny tells your web server that the Allow rules are processed before the Deny rules. If the client does not match the Allow rule or it does match the Deny rule, then the client will be denied access. Order deny, allow means that the deny rules are processed before the allow rules. If the client does not match the deny rule or it does match the allow rule, then it will be granted access.

Order Allow, Deny    Example of Allow Allow from example.com All hosts from this domain will be allowed. Allowed: abc.example.com www.example.com. Not Allowed: www.abcexample.com    Only complete components are matched

Order Allow, Deny Example of Allow Allow from example.com This configuration will cause the server to perform a double reverse DNS lookup on the client IP address, regardless of the setting of the HostnameLookups directive. It will do a reverse DNS lookup on the IP address to find the associated hostname, and then do a forward lookup on the hostname to assure that it matches the original IP address. Only if the forward and reverse DNS are consistent and the hostname matches will access be allowed. Computer networks use the Domain Name System to determine the IP address associated with a domain name. This process is also known as forward DNS resolution. Reverse DNS lookup is the inverse process of this, the resolution of an IP address to its designated domain name. http://httpd.apache.org/docs/2.0/mod/core.html#hostnamelookups

Order Allow, Deny Example of Allow Allow from 10.1.2.3 Allow from 10.1 You can define the access level also by providing the IP address. In this example, just the host with just that IP address would be allowed access. Allow from 10.1 All hosts from all subnets within 10.1.x.x would be allowed access.

Order Allow, Deny Example <Directory "/www"> Order Allow, Deny Deny from all Allow from all </Directory> In this case, your client would be denied access. Why? Apache first evaluates the Allow directive rules and then the Deny directive rules. Allow from all would be executed first and then the Deny from all would take place.

Example: order has been swapped Order Deny, Allow Example: order has been swapped <Directory "/www"> Order Deny, Allow Deny from all Allow from all </Directory> The configuration above would result in your client being allowed access because the Deny from all rule would be processed first and the Allow from all rule would be processed second.

Example: restricted server, intranet site Order Deny, Allow Example: restricted server, intranet site <Directory "/www"> Order Deny, Allow Deny from all Allow from example.com </Directory> This configuration would restrict everyone from accessing the /www directory except hosts in the example.com domain. Abc.example.com would be allowed access www.myexample.com would be restricted.   Only complete components are matched

Example: blocking someone from some specific domain Order Allow, Deny Example: blocking someone from some specific domain <Directory "/www"> Order Allow, Deny Allow from all Deny from www.myattacker.com phishers.example.com </Directory> The configuration provided above would give access to everyone and restrict all hosts from the www.myattacker.com and phishers.example.com domains.

Order Allow, Deny What happens if you forget to provide specific rules and use just the Order allow,deny directive alone? <Directory "/www"> Order Allow, Deny </Directory> when you specify the Order allow,deny you also control the default access state. The example above will Deny all access to the /www directory because the default access state is set to Deny.

IndexIgnore IndexIgnore file [file] ... IndexIgnore relates to the default directory listing mechanism that returns a directory listing for directories which do not contain an index.html or other "index" file. If that file is present, then IndexIgnore does not do anything. IndexIgnore file [file] ... You can find the IndexIgnore directive in two places. httpd.conf Apache server configuration file .htaccess file If you edit IndexIgnore in your root .htaccess file, it will affect all subdirectories as well. If you want to apply your setting to a subdirectory only, then you have to add a .htaccess file to that subdirectory and edit that. IndexIgnore relies on the mod_autoindex module. Without this module enabled, no directory listings take place.

IndexIgnore Examples IndexIgnore readme.txt .htaccess IndexIgnore * Disable the readme.txt and .htaccess files from showing in your directory listing. IndexIgnore * Block the directory listing completely

Summary Methods for user authentication Simple login scripts HTTP authentication Authentication using sessions Enable FollowSymLinks by default

Summary The Allow and Deny directives are used to specify which clients are or are not allowed access to the server. The Order directive sets the default access state, and configures how the Allow and Deny directives interact with each other.

References http://httpd.apache.org/docs/2.0/howto/htaccess.html http://www.webreference.com/programming/apache_authentication/ http://www.digiways.com/articles/php/sessauth/ http://www.maxi-pedia.com/FollowSymLinks http://httpd.apache.org/docs/2.2/mod/core.html#directory http://www.apacheweek.com/features/userauth