[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

rovernet auto login



New and improved rovernet auto login script. You can specify the
username and password in the script or let it prompt you on the console.

You need (atleast as far as debian packages go)
libcrypt-ssleay-perl
libwww-perl
-- 
Jon
"All things change in a dynamic environment.
Your effort to remain what you are is what limits you."
	- The Puppet Master
#!/usr/bin/perl -W

use LWP;

use strict;

my $username="";
my $password="";

if($username eq "") {
	print "Username: ";
	$username = <STDIN>;
	chomp($username);
}

if($password eq "") {
	print "Password: ";
	$password = <STDIN>;
	chomp($password);
}

my $browser = LWP::UserAgent->new;
$browser->cookie_jar({});

sub find_line {
	my ($haystack, $needle)=@_;
	my @data=split(/\n/, $haystack);
	my @results;

	for(my $i=0; $i<=$#data; $i++) {
		if($data[$i] =~ /$needle/i) {
			$results[$#results+1]=$data[$i];
		}
	}
	return @results;
}

sub extract_value {
	my ($data, $key)=@_;
	my ($line)=find_line($data, "name=\"$key\" value=");
	$line =~ s/^.*name\=\"$key\" value\=\"([a-zA-Z0-9_\.:\/%=&-]*)\"[ \>].*$/$1/gi;
	return $line;
}

sub get_refresh {
	my ($data)=@_;
	my ($line)=find_line($data, "<meta http-equiv=\"refresh\" ");
	$line =~ s/^<meta http\-equiv\=\"refresh\" content\=\"[0-9]+\; *URL\=(.*)\"\>$/$1/g;
	return $line;
}

sub login {
	my ($browser, $username, $password)=@_;
	my $url = "http://www.google.com/";;
	my $response = $browser->get($url);
	if(!$response->is_success) {
		exit(1);
	}

	($url)=find_line($response->content, "/RoverNet/login");
	$url =~ s/^.*<a href\=\"(.*)\">.*$/$1/g;

	$response = $browser->get($url);
	if(!$response->is_success) {
		exit(2);
	}

	($url)=find_line($response->content, "login.mtu.edu/tools/public/login");
	$url =~ s/^.* action\=\"(.*)\" method.*$/$1/g;
	my %bits;
	$bits{"userid"}=$username;
	$bits{"password"}=$password;
	$bits{"proxy_back"}=extract_value($response->content, "proxy_back");
	$bits{"back"}=extract_value($response->content, "back");
	$bits{"backname"}=extract_value($response->content, "backname");
	$bits{"appid"}=extract_value($response->content, "appid");
	$bits{"seconds"}=extract_value($response->content, "seconds");
	$bits{"crosscheck"}=extract_value($response->content, "crosscheck");
	$bits{"globalname"}=extract_value($response->content, "globalname");
	$bits{"globalsecure"}=extract_value($response->content, "globalsecure");
	$bits{"globalttl"}=extract_value($response->content, "globalttl");
	$bits{"RoverNet"}=extract_value($response->content, "RoverNet");
	$bits{"authz"}=extract_value($response->content, "authz");
	$bits{"Login"}=extract_value($response->content, "Login");

	$response=$browser->post($url, \%bits);
	if(!$response->is_success) {
		exit(3);
	}

	$url = extract_value($response->content, "back");
	$url =~ s/%26/&/gi;
	$url =~ s/%2F/\//gi;
	$url =~ s/%3A/:/gi;
	$url =~ s/%3D/=/gi;
	$url =~ s/%3F/?/gi;

	$response=$browser->get($url);
	if(!$response->is_success) {
		exit(4);
	}

	($url)=find_line($response->content, "/RoverNet/verify");
	$url =~ s/^.*url\=(.*)\">.*$/$1/g;

	$response=$browser->get($url);
	if(!$response->is_success) {
		exit(5);
	}
}

login($browser, $username, $password);

Attachment: signature.asc
Description: Digital signature