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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why isn't my script working??

Status
Not open for further replies.

t0r

Technical User
Nov 15, 2007
7
US
Ok, I made a script that should connect to steamcommunity.com, try logging in from a .txt file of username/passwords, and print back to me if the login was successful or not...

I'm sorta new to PERL so I'm not 100% positive on what to look for, but here is whats happening.

I don't know how the perl script detects if the login was successful or not. In the script I wrote in what should be in the html to render a successful login or a failure but I don't think the script is picking/detecting it...

anyways, I might be missing something totally obvious but heres my script.


#!/usr/bin/perl -w

use LWP::UserAgent;

my $username;
my $password;
my $filename = '/tmp/blah.txt';

open( FILE, "< /tmp/blah.txt" ) or die "Can't open $filename : $!";
while( <FILE> ) {
print "Attempting line: " . $_;
($username, $password) = split (/ /, $_);
k_go_now($username, $password);

# Sleep to keep us slightly more hidden and load off their servers
sleep(1);
}

# k go now sub; grabs input from file ($username, $password) tries to login
sub k_go_now
{
my ($username,
$password) = @_;
$ua = LWP::UserAgent->new;
$ua->agent("MyApp/0.1 ");

# Create a request
my $req = HTTP::Request->new(POST => ' $req->content_type('application/x- $req->content('query=lib
# Pass request to the user agent and get a response back
my $res = $ua->request($req);

# Check the outcome of the response
if ($res->is_success) {
check_output ($res->content);
}
else {
print $res->status_line, "\n";
}
}

# suib check_output checks the response from the website and if it's any good
sub check_output
{
my ($output) = @_;


if ($output =~ /Incorrect Login/)
{
print "Nope, failed login\n";
} elsif ($output =~ /Hello/)
{
print "got'em with login details\n";
} else
{
print "unknown response !!!\n$output\n\n";
}
}



Thanks!
 
Why are you attmepting multiple logins from a file? I am concerned that you are trying a brute force method of finding names/passwords.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
I'm not brute forcing anything,
I have a list of accounts I buy/sell/trade and it's important for me to be able to check if they all work without having to individually check 1 by 1 and this is the best way I can think of.


 
[blue]MillerH[/blue]: The #This does not work comment you left in the earlier example seems a bit unfortunate[ponder]

_________________________________
In theory, there is no difference between theory and practice. In practice, there is. [attributed to Yogi Berra]
 
Not sure what you mean by that
 
Why not try duplicating the form instead of getting it from the site and filling it in? May not work though if the form uses javascript.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Ya I tried that so this is my last resort, the script itself works but it isn't recognizing keywords when the login was successful/failure so it doesn't correctly print back the response whether the login worked or not..which is my problem
 
Compare the page before login to the page after login. A failed login will result in a different page than a successful one.


"We must fall back upon the old axiom that when all other contingencies fail, whatever remains, however improbable, must be the truth." - Sherlock Holmes

 
I have compared them, The only difference in the failed login is underneath the login box it says "Incorrect Login" and the successful login page is totally different...

For some reason the script isn't detecting the "Incorrect Login
 
The site must send back a cookie of the login is succesful. I would look into reading the cookie.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Ok, I asked around and found a different approach.
I'm not sure how to incorporate this new sub into my existing script, any ideas?

sub Steam() {
print "File Containg username:password > ";
chomp(my $steam = <STDIN>);
open(S, $steam) || die("Error: $!");
my @steamcheck = <S>;
close(S);
print "-- Accounts Loaded - Checking --\n";
foreach my $steamcheck (@steamcheck) {
$steamcheck =~ s/^\s+//;
$steamcheck =~ s/\s+$//;
unless($steamcheck =~ m/(.*?)\:(.*?)(\ |$)/g){next;}
my $steamuser = $1;
my $steampass = $2;
my $steamlogin = $ua->get(" if ($steamlogin->is_success) {
if($steamlogin->content =~ m/Signed in as/i) {
$stfound++;
print "-- Steam[".$yfound."] Found --\n";
open(STFnd, ">>Steam.txt");
print STFnd "".$stfound.". Steam - ".$steamcheck."\n";
close(STFnd);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top