set 13: web servers (configuration and security) (chapter 21) it452 advanced web and internet...

16
Set 13: Web Servers (configuration and security) (Chapter 21) T452 Advanced Web and Internet Systems

Upload: clarence-fowler

Post on 12-Jan-2016

214 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Set 13: Web Servers (configuration and security) (Chapter 21) IT452 Advanced Web and Internet Systems

Set 13: Web Servers(configuration and security)

(Chapter 21)

IT452 Advanced Web and Internet Systems

Page 2: Set 13: Web Servers (configuration and security) (Chapter 21) IT452 Advanced Web and Internet Systems

Key Questions

• What does a web server do?

• How can I control it?– URL re-writing / re-direction (and why do I care?)

• Access control and security– Developers

– Users

Page 3: Set 13: Web Servers (configuration and security) (Chapter 21) IT452 Advanced Web and Internet Systems

• One server to rule them all?

Popular Web Servers

http://news.netcraft.com/archives/2010/06/16/june-2010-web-server-survey.html

Page 4: Set 13: Web Servers (configuration and security) (Chapter 21) IT452 Advanced Web and Internet Systems

Web Server Basics

http://www.example.com/products/widget.html

What happens? Where does it come from?

Are we sure?

http://www.example.com/cgi-bin/search.pl?q=widgets

What happens? Where does it come from?

Page 5: Set 13: Web Servers (configuration and security) (Chapter 21) IT452 Advanced Web and Internet Systems

URL Guidance

• Things to avoid

• Things to do

• How to do this?

Page 6: Set 13: Web Servers (configuration and security) (Chapter 21) IT452 Advanced Web and Internet Systems

How to control a web server?

• Apache – we focus on the most popular server

httpd.conf– The entire site

– Must be root user to edit

– Requires restart

.htaccess– Per directory

– Possibly each user (depends on config)

– Re-read for each request

Page 7: Set 13: Web Servers (configuration and security) (Chapter 21) IT452 Advanced Web and Internet Systems

Content Control

1. Redirection

2. Rewriting

3. Content negotiation

Page 8: Set 13: Web Servers (configuration and security) (Chapter 21) IT452 Advanced Web and Internet Systems

Redirection

# NOTE: this is an example .htaccess file

# Redirect a subdirectory to another websiteRedirect /~nchamber/it452/examples http://newplace734.com/crazycats

# Or redirect a subdirectory to another subdirectoryRedirect /~nchamber/it452/examples /~nchamber/test2

# Redirect permanently, add the ‘permanent’ optionRedirect permanent /~nchamber/it452/examples http://newplace734.com/newdir

Page 9: Set 13: Web Servers (configuration and security) (Chapter 21) IT452 Advanced Web and Internet Systems

Redirection OR Rewriting

# NOTE: continuation of .htaccess file, still in ‘change’ directory

# Must turn on the rewrite engine first.RewriteEngine On

# Sets the URL that fills in as your rewrite target’s base directory.# The default is /home/username/public_htmlRewriteBase /~username

# Rules use the directory paths, and redirect to same serverRewriteRule ^oldfile3.txt$ change/test3.txt [R,L]RewriteRule ^oldfile*.txt$ change/catchOldFiles.txt [R,L]

# Behind the scenes changeRewriteRule ^oldfile5.txt$ change/test5.txt [L]

# More complex# redirect change/stuff/dogs to change/query.pl?q=dogs# 302 = temp changeRewriteRule ^stuff/([^/]+)/?$ change/query.pl?q=$1 [R=302,L]

Page 10: Set 13: Web Servers (configuration and security) (Chapter 21) IT452 Advanced Web and Internet Systems

Exercise

• Create a rewrite rule:– People visit your site: www.burritos.com/filling/beef

– Turn all possible fillings into search terms that are sent to your script: www.burritos.com/search/fillings.pl?type=beef

– Make it silent so the user doesn’t see the new URL.

– It should not redirect a longer URL from the user like: www.burritos.com/filling/beef/salsa

Page 11: Set 13: Web Servers (configuration and security) (Chapter 21) IT452 Advanced Web and Internet Systems

Apache Access Control – Options

1. Domain/IP restrictions– Manually list the domains that are allowed or not

2. Basic password protection– Create a basic password file with usernames– Passwords are sent over plain text (or the hash is sent over plain text)

3. More advanced modules – keep passwords in DB rather than “flat file”

Page 12: Set 13: Web Servers (configuration and security) (Chapter 21) IT452 Advanced Web and Internet Systems

1. Access control: IP-based

<LIMIT GET>order deny,allowdeny from allallow from .nadn.navy.milallow from .usna.navy.milallow from .usna.eduallow from .naps.edu # Naval Academy Prep Schoolallow from 192.190.228. # test benchallow from 192.190.229. # test benchallow from 192.31.8 # test benchallow from 207.86.40.42 # NAPSallow from 131.158.248. # Navy Medicalallow from 131.158.247. # Navy Medicalallow from 137.225.250. # Joint Spectrum Commandallow from 12.110.116.250 # Alumni Associationallow from 128.56.allow from 131.121.allow from 131.122.</LIMIT>

Page 13: Set 13: Web Servers (configuration and security) (Chapter 21) IT452 Advanced Web and Internet Systems

2. Access Control: “Basic”

Whole directoryAuthType BasicAuthUserFile /home/mXXX/public_html/.htpasswdAuthName "Members Only"require valid-user

Per file<Files somefile.html>AuthType BasicAuthUserFile /home/mXXX/public_html/.htpasswdAuthName "Members Only"require valid-user</Files>

Can also list specific users

Require user nchamber needham

Page 14: Set 13: Web Servers (configuration and security) (Chapter 21) IT452 Advanced Web and Internet Systems

3. Access Control: “Digest”

Same as “Basic”, but AuthType is different:AuthType Digest

Both Basic and Digest can also list specific usersRequire user nchamber needham

Create the password file:htpasswd -c c:/wamp/.htpasswd username ORhtdigest -c c:/wamp/.htpasswddigest realm username

“-c” creates a new file – omit to just add new entry

Provide the actual path to the password file

Don’t store password file in the web space!

Page 15: Set 13: Web Servers (configuration and security) (Chapter 21) IT452 Advanced Web and Internet Systems

Where to get more info

• Textbook (some in Chapter 21)

• Redirection/rewriting– Simple overviewhttp://www.yourhtmlsource.com/sitemanagement/urlrewriting.html

– Not-so-simple details http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html#RewriteRule

• Access controlhttp://httpd.apache.org/docs/1.3/howto/auth.html

Page 16: Set 13: Web Servers (configuration and security) (Chapter 21) IT452 Advanced Web and Internet Systems

Extra Info: Users and Passwords

• Don’t save passwords in plain text!• Encryption: md5

– Basic approach, ok for normal sites

– *Not collision resistant

– Online databases can lookup common passwords!

• Perl requirements:– Use Digest::MD5 qw(md5 md5_hex)

– my $hashed = md5_hex($password)