Hello Monks!
This has been done before but I am trying to write my own CGI/Traceroute program so I can become enlightened.
The below code works but it is not secure- someone can type
127.0.0.1 | cat /etc/passwd and grab my password file!
Ack!
If I uncomment the line below the code doesn't work:
$value =~ s /|/ /g;
Any ideas on what I need to do so the code is totally secure and works?
Thanks!!
#!/usr/bin/perl -w
use CGI;
my $query = new CGI;
$value = $query->param('trace');
#$value =~ s (/;#!"'`|)/ /g;
$value =~ s /;/ /g;
$value =~ s /#/ /g;
$value =~ s /!/ /g;
$value =~ s /"/ /g;
$value =~ s /'/ /g;
$value =~ s /`/ /g;
#$value =~ s /|/ /g;
open (TRACE, "traceroute $value |");
@traceroute = <TRACE>;
close (TRACE);
print "Content-Type: text/html\n\n";
print "<html>\n<head>\n<title>\nRavenGate TraceRoute Results\n</title>
+\n</head>\n<body>\n";
print "Hello There- I am writing this from scratch so please be patien
+t. Thanks!\n\n";
foreach $item (@traceroute) {
print "<BR>$item\n\n";
}
print "</body>\n</html>\n";
exit (0);
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.