RSS Forums RSS
Please support our Perl advertiser: Programming Forums

Can't seem to find the problem...

Join Date: Jul 2008
Posts: 1
Reputation: w0h0m is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
w0h0m w0h0m is offline Offline
Newbie Poster

Can't seem to find the problem...

  #1  
Jul 22nd, 2008
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.

  1. #!/usr/bin/perl
  2. use LWP::UserAgent;
  3. use HTTP::Cookies;
  4. $host = @ARGV[0];
  5. @badID = (1,2,3,4,5);
  6. $arrSize = @badID;
  7. $i = 2;
  8.  
  9. if (@ARGV < 1)
  10. {
  11. print "\n\n [-] Specify a host";
  12. print "\n\n [!] Example: pm.pl http://www.sitename.com/path/\n\n";
  13. exit(0);
  14. }
  15. loginPrompt();
  16. sub login($$)
  17. {
  18. $browser = LWP::UserAgent->new(agent =>
  19. 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; T312461)' ,
  20. );
  21. $cookie_jar = HTTP::Cookies->new();
  22. $browser->cookie_jar($cookie_jar);
  23.  
  24. $response = $browser->post( $host.'/index.php?act=Login&CODE=01',
  25. [ 'referer' => '',
  26. 'UserName' =>$_[0],
  27. 'PassWord'=>$_[1],
  28. 'CookieDate' => '1',
  29. 'Privacy' => '1',
  30. 'submit'=>'Log me in' ]
  31. );
  32. $content = $response->content;
  33.  
  34. if ($content =~ /<head>/gmi)
  35. {print "\n[-] INCORRECT LOGIN\n"; loginPrompt()}
  36. else{msgInfo()}
  37. }
  38. sub spam()
  39. {
  40. for ($j = 0; $j <= $arrSize + 1; $j++)
  41. {
  42. if ($i > $uid){ print "\n\n
  43.  
  44. * Spamming Completed\n"; exit(0) }
  45.  
  46. if ($badID[$j] eq $i) { $i++; spam() }
  47. }
  48.  
  49. sleep(15);
  50.  
  51. $res = $browser->get("$host/index.php?act=Msg&CODE=4&MID=$i");
  52. $results = $res->content;
  53. if ($results =~ /name="post_key" value="([a-f0-9]{32})"(.*)/){$postkey = $1;}
  54. if ($results =~ /name="auth_key" value="([a-f0-9]{32})"(.*)/){$authkey = $2;}
  55. if ($results =~ /name="entered_name"(.*) value="(.*?)"(.*)/gmi){$name = $3;}
  56.  
  57. $resp = $browser->post( "$host/index.php?act=msg",
  58. [ 'removeattachid'=> '0',
  59. 'OID'=>'',
  60. 'act'=>'Msg',
  61. 'CODE'=>'04',
  62. 'MODE'=>'01',
  63. 'post_key'=> $postkey,
  64. 'auth_key'=>$authkey,
  65. 'entered_name'=>$name,
  66. 'msg_title'=> $subj,
  67. 'Post'=> $msg,
  68. 'post'=>'Submit', Referer => $host ]
  69. );
  70.  
  71. print "\n [!] Message Sent to: $name with SID $SID";
  72.  
  73. if ($i > $uid){print "\n\n
  74.  
  75. * Spamming Completed\n"; exit(0)}
  76.  
  77. else{$i++;spam()}
  78. }
  79. sub loginPrompt()
  80. {
  81. print "\nEnter your login name: ";
  82. chomp($id = <STDIN>);
  83. print "\nEnter your password: ";
  84. chomp($pass = <STDIN>);
  85. login($id, $pass);
  86. }
  87. sub msgInfo()
  88. {
  89. print "\nEnter message subject: ";
  90. chomp($subj = <STDIN>);
  91. print "\nEnter your message: ";
  92. chomp($msg = <STDIN>);
  93. print "\nEnter highest uid: ";
  94. chomp($uid = <STDIN>);
  95. spam();
  96. }
AddThis Social Bookmark Button
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 8:12 am.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC