Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Logging in with Perl


MaddinW's Avatar
Member
0 0

Hello everyone, I am trying to log in to hbh.com using a Perl script. But for some reason, I still cannot access the challenge page. Here is the code:```markup #!/usr/bin/perl -w use strict; use MIME::Base64::Perl; use WWW::Mechanize; use HTTP::Cookies;

my $agent=WWW::Mechanize->new;
$agent->cookie_jar(HTTP::Cookies->new);
$agent->agent_alias('Linux Mozilla');
$agent->get("http://www.hellboundhackers.com");
$agent->form_number(1);#("loginform");
$agent->set_fields(user_name=>'MaddinW',user_pass=>'not_my_password');
$agent->tick('remember_me','y');
$agent->click();
$agent->get("http://www.hellboundhackers.org/challenges/timed/timed1/index.php");  
print $agent->content."\n";

Thank you in advance.

Futility's Avatar
:(
80 122

Let me preface this by saying I don't know perl, so everything of the proceeding text could be wholly incorrect and make me look like a dumbass. If you don't want to read it, feel free to scoff and skip over me. I will hold no grudges. With that out of the way…

It would appear as though you're trying to directly log in with your script, ya? That's what the user_name/pass set_field is for? Now I don't see why you couldn't tweak that method until it works, but there's (probably) an easier way. It looks like perl can make/edit cookies, yes? So why not take out all your logging in nonsense (that doesn't seem to work) and replace it with something that says you already have logged in? Maybe find the cookies vital to identifying you as you and give them to your program?


MaddinW's Avatar
Member
0 0

WWW::Mechanize can set and read cookies automatically, so I dont see any reason to interfere with that. Editing or manually setting the cookies might do more harm than already has been done ;)


Arabian's Avatar
Member
0 0

There are a couple ways to submit forms. Your's, however, failed at all of them. Here's an example:

    use strict;
    use MIME::Base64::Perl;
    use WWW::Mechanize;
    use HTTP::Cookies;
     
    my $agent=WWW::Mechanize->new;
    $agent->cookie_jar(HTTP::Cookies->new);
    $agent->get("http://www.hellboundhackers.com");
    $agent->form_name("loginform");
    $agent->set_field(user_name=>'MaddinW',
             user_pass=>'not_my_password');
    #$agent->tick('remember_me','y'); #you're setting cookies and user agent, so the timeout will be longer than you'll need to get the job done. 
    $agent->submit();
    $agent->get("http://www.hellboundhackers.org/challenges/timed/timed1/index.php");  
    print $agent->content;


mechanize is a beautiful beast. Look on perlmonks for more info into its methods. A good way of checking the validity of your post is to use HTML's 'issuccess' function. IE (if $agent->is_success) {etcetc}

http://search.cpan.org/dist/WWW-Mechanize/


MaddinW's Avatar
Member
0 0

I have setup the script in the way I have written them for hackquest and wechall, so I dont think my script is completely wrong. There is just something I overlook and I dont know what.


just a panda's Avatar
Member
0 0

hey guys: its org ^_^


Arabian's Avatar
Member
0 0

^WINNER.

If i had community points i'd give them to you.

I have setup the script in the way I have written them for hackquest and wechall, so I dont think my script is completely wrong. There is just something I overlook and I dont know what.

if this is true, then you need to take a remedial course in how not to add frivolous statements to your scripts. Also, take the time to learn how the modules you're using work.


MaddinW's Avatar
Member
0 0

Thank you. It was a really stupid mistake that I made; but luckily the easiest one to correct I so far.