Go4Expert (http://www.go4expert.com/)
-   Perl (http://www.go4expert.com/forums/perl/)
-   -   Can't seem to figure this error out (http://www.go4expert.com/forums/figure-error-t12352/)

yah0m 22Jul2008 23:11

Can't seem to figure this error out
For a challenge, we have to code a script that can pull information from a web page and then use it to automate an action on that site. What I've chosen to try and do is code an IPB Forum Advertiser. The process is easy, but I can't seem to get it to work.

The Problem: so far I can't seem to get it to login and not sure what I'm doing wrong.


use LWP::UserAgent;
use HTTP::Cookies;
$host = @ARGV[0];
@badID = (1,2,3,4,5);
$arrSize = @badID;
$i = 2;

if (@ARGV < 1)
  print "\n\n [-] Specify a host";
  print "\n\n [!] Example: pm.pl http://www.sitename.com/path/\n\n";
sub login($$)
  $browser = LWP::UserAgent->new(agent =>
        'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; T312461)' ,
  $cookie_jar = HTTP::Cookies->new();

    $response = $browser->post( $host.'/index.php?act=Login&CODE=01',
      [ 'referer' => '',
        'UserName' =>$_[0],
    'CookieDate' => '1',
    'Privacy' => '1',
        'submit'=>'Log me in' ]
$content = $response->content;

if ($content =~ /<head>/gmi)
{print "\n[-] INCORRECT LOGIN\n"; loginPrompt()}
sub spam()
  for ($j = 0; $j <= $arrSize + 1; $j++)
  if ($i > $uid){ print "\n\n

    * Spamming Completed\n"; exit(0) }

  if ($badID[$j] eq $i) { $i++; spam() }


    $res = $browser->get("$host/index.php?act=Msg&CODE=4&MID=$i");
    $results = $res->content;
    if ($results =~ /name="post_key" value="([a-f0-9]{32})"(.*)/){$postkey = $1;}
    if ($results =~ /name="auth_key" value="([a-f0-9]{32})"(.*)/){$authkey = $2;}
    if ($results =~ /name="entered_name"(.*) value="(.*?)"(.*)/gmi){$name = $3;}

    $resp = $browser->post( "$host/index.php?act=msg",
        [ 'removeattachid'=> '0',
          'post_key'=> $postkey,
          'msg_title'=> $subj,
      'Post'=> $msg,
          'post'=>'Submit', Referer => $host ]

    print "\n [!] Message Sent to: $name with SID $SID";

    if ($i > $uid){print "\n\n

    * Spamming Completed\n"; exit(0)}

sub loginPrompt()
  print "\nEnter your login name: ";
  chomp($id = <STDIN>);
  print "\nEnter your password: ";
  chomp($pass = <STDIN>);
  login($id, $pass);
sub msgInfo()
  print "\nEnter message subject: ";
  chomp($subj = <STDIN>);
  print "\nEnter your message: ";
  chomp($msg = <STDIN>);
  print "\nEnter highest uid: ";
  chomp($uid = <STDIN>);

naveen 23Jul2008 14:33

Re: Can't seem to figure this error out

Without going through your code in great detail, I've a few points -

1) I'm not too sure if you can authenticate the way you are doing, using LWP::UserAgent. Also, you are calling the subroutine login with username and password as parameters, but nowhere in sub login you are using them.

2) WWW::Mechanize is a module which is used to automate tasks related to web page automation, authentication etc. You can have a look at it.

3) You need to post more detailed information about what you want to achieve. For eg. what is the content of the page you're leeching, what information you are extracting, what action you want to automate etc. Examples would be great.

4) Do you get any error on running your script? If yes, please post the complete error. Else state whatever is happening on running the script.


All times are GMT +5.5. The time now is 08:47.