0

I'm trying to pass parameters in a URL. I don't know what's missing, I tried to see how the URL looks after executing this script.

my $request3 = HTTP::Request->new(GET => $sql_activation);

my $useragent = LWP::UserAgent->new();
$useragent->timeout(10);

my $response2 = $useragent->request($request3);
if ($response2->is_success) {

    my $res2 = $response2->content;

    if ($res =~ m/[#](.*):(.*)[#]/g) {
        my ($key, $username) = ($1, $2);
        print "[+] $username:$key \n\n";
    }
    else {
      print "[-] Error \n\n";
    }
}

my $link =
      "http://localhost/wordpress/wp-login.php?action=rp&key=" 
    . $key
    . "&login="
    . $username;

sub post_url {

    my ($link, $formref) = @_;

    my $ua = new LWP::UserAgent(timeout => 300);
    $ua->agent('perlproc/1.0');
    my $get = $ua->post($link, $formref);

    if ($get->is_success) {
        print "worked \n";
    }
    else {
        print "Failed \n";
    }
}

After executing the script the URL is like this

site/wordpress/wp-login.php?action=rp&key=&login=
5
  • 1
    What do you expect $key and $username to be? Can you show where they are set? Commented May 16, 2013 at 18:12
  • What's missing is any code to set the variables you are using to construct the URI. Commented May 16, 2013 at 18:13
  • 1
    (And mashing strings together to make URIs isn't a great idea, use the URI module.) Commented May 16, 2013 at 18:14
  • @gpojd i've edited the code above Commented May 16, 2013 at 18:23
  • Adding use strict to your code would have given you a big clue to the problem. Commented May 17, 2013 at 9:47

1 Answer 1

1

Perl has block level scope. You define $key and $username in the block following an if statement. They don't live beyond that.

You need to create them (with my) before that block.

# HERE
my ( $key, $username );
if ( $response2->is_success ) {
    my $res2 = $response2->content;
    if ( $res =~ m/[#](.*):(.*)[#]/g ) {
        # Don't say my again
        ( $key, $username ) = ( $1, $2 );
    }
    else { print "[-] Error \n\n"; }
}
Sign up to request clarification or add additional context in comments.

1 Comment

@gilardinho, I'd go a step further and add use strict; and use warnings; to the top of your script. It would have caught that bug for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.