160 likes | 279 Views
Chapter Five (Continued). And some class exercises. But first…why wget did not work. A few months ago I added a module to my apache server called ModSecurity ModSecurity is an open source intrusion detection and prevention engine for web applications
E N D
Chapter Five (Continued) And some class exercises
But first…why wget did not work • A few months ago I added a module to my apache server called ModSecurity • ModSecurity is an open source intrusion detection and prevention engine for web applications • Operating as an Apache Web server module or standalone, the purpose of ModSecurity is to increase web application security, protecting web applications from known and unknown attacks.
The Threat - wget • Many web exploits take advantage of flaws in coding to use directory transversal as a means to execute programs such as wget • directory transversal is essentially http://rose.edu/../../bin/wget yada yada • Various combinations are tried until one succeeds (we will look at an actual attack later in the course) • But ModSecurity protects against wget attacks (well sort of…)
wget and User-Agent • A user agent is the client application used with a particular network protocol • Web user agents range from web browsers to search engine crawlers ("spiders"), etc. • When Internet users visit a web site, a text string is generally sent to identify the user agent to the server.
wget and User-Agent • This forms part of the HTTP request, prefixed with User-agent: or User-Agent: • wget has a command line option (-U) to modify or erase the User-Agent sent to server
Exercise • Use the following command to download the gettysburg.txt file to your class workstation: wget –U “” http://wildbill.org/gettysburg.txt • Now use wc determine: • The number of lines in the file • The number of words in the file • The number of characters in the file
Grep Exercise • Using grep try the following: grep four gettysburg.txt Ok now try: grep –i four gettysburg.txt Now look at the man page for grep…lot’s of options!
Using the Manipulate and Format Commands • These commands are: tr and pr • Used to edit and transform the appearance of data before it is displayed or printed
Translating CharactersUsing the tr command • tr copies data from the standard input to the standard output, substituting or deleting characters specified by options and patterns • The patterns are strings and the strings are sets of characters • A popular use of tr is converting lowercase characters to uppercase
tr Exercise • Type the following: tr t 0 < gettysburg.txt tr a-z A-Z < gettysburg.txt
Using the pr Command toFormat Your Output • pr prints specified files on the standard output in paginated form • By default, pr formats the specified files into single-column pages of 66 lines • Each page has a five-line header, its latest modification date, current page, and five-line trailer consisting of blank lines
Pr Exercise • Type the following: pr gettysburg.txt pr –header=“GBA Ver 1.0” gettysburg.txt pr –t gettysburg.txt pr – t –d gettysburg.txt
Using a Shell Script toImplement the Application • Shell scripts should contain: • The commands to execute • Comments to identify and explain the script so that users or programmers other than the author can understand how it works • Use the pound (#) character to mark comments in a script file
Running a Shell Script • The Bash shell accepts more variations in command structures that other UNIX shells thus it is more popular • You can run a shell script by typing sh followed by the name of the script, or make the script executable and type ./ prior to the script name sh filename.sh or ./filename.sh
Shell Script Discussion… • First line… #!/bin/bash • Uses: • Combine lengthy and repetitive sequences of commands into a single, simple command. • Create new commands using combinations of utilities in ways the original authors never thought of. • Simple shell scripts might be written as shell aliases, but the script can be made available to all users and all processes. Shell aliases apply only to the current shell. • Wrap programs over which you have no control inside an environment that you can control. • Rapid prototyping (but avoid letting prototypes become production)
Shell Script Discussion… • For easier reading use all UPPERCASE names for variables • # Use the comment character to add information to your scripts