Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Password Protection Can Be Bypassed

Status
Not open for further replies.

megp

Programmer
Aug 25, 2004
31
0
0
US
Greetings,

I have a CGI script (in rudimentary Perl) that takes login name and password data, compares it to a database, and if it matches, prints one page, if no match, redirects back to the login page with an error message. This all works fine.

My problem is that if one enters the location of the CGI script in the address bar, he is admitted through without a login name and password. I'm missing the component that tests to see if there is any incoming data to begin with, then redirects back to the login page if not. Please help.

Code:
#!/usr/bin/perl
#Line above gives path to Perl interpreter
require "cgi-lib.pl";

#Read incoming data into an array and set content type
&ReadParse;
print &PrintHeader;

#Set default test results to no match
$match="no";

#Open user database in read-only mode
open(FILE,"cmaa.txt") || die "Can't find database\n";
#Store contents of database in an array
@indata = <FILE>;
#Close database
close(FILE);

#Extract each record from the @indata array
foreach $i (@indata)
{
#Remove hard return
chomp($i);
#Assign names to variables
($fname,$lname,$co,$add,$city,$st,$zip,$tele,$email,$pwd1,$pwd2) = split(/\|/,$i);
#Compare login data to array
if ($fname=~/$in{'fname'}/i && $lname=~/$in{'lname'}/i && $pwd1=~/$in{'pwd'}/i)
{
$match="yes";
# Print personalized CMAA page

Obviously, there's more, but I believe the necessary piece would fit in here somewhere. Actual page is at login page is at
Thanks so much!
Meghan
 
Stop! Do not proceed with your current code unless you are bound by some strange limitations. cgi-lib is ancient and should no longer be used unless your using some ancient installation of perl. Use CGI instead. You should also start using "srict".

Most likely, the problem with your code is that you have not validated the user input before checking it against the file. Also you are using partial matching (sub string match) in you regexp instead of matching the entire string. Add string anchors /^$string$/:

Code:
if ($fname=~/^$in{'fname'}$/i && $lname=~/^$in{'lname'}$/i && $pwd1=~/$in{'pwd'}/i)



------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Okay, Kevin,

I've obtained CGI.pm (v3.25). I'm going to go see what I can figure out, but I may be back with more questions... I'm sure I'll thank you for the kick in the butt later :)

Meghan
 
Hi

Kevin said:
Add string anchors /^$string$/
Good advice, but you could continue with quoting : [tt]/^[red]\Q[/red]$string[red]\E[/red]$/[/tt] . Otherwise if someone's password is for example .* , then anything is accepted as password.

Feherke.
 
Or just quotemeta the string, which escapes all non-alphanumeric characters.

Code:
$string = '.*';
$string = quotemeta($string); # \.\*

if ($pwd1 =~ /^$string$/

-------------
Cuvou.com | The NEW Kirsle.net
 
Good advice, but you could continue with quoting : /^\Q$string\E$/ . Otherwise if someone's password is for example .* , then anything is accepted as password.

that is also good advice, hopefully passwords/names are only allowed to be alpha-numeric to begin it, but if not, \Q that sucka! [smile]

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
. . . or just use "eq" to compare the strings. Why use a regexp at all?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top