User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Perl section within the Software Development category of DaniWeb, a massive community of 402,787 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,819 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Perl advertiser: Programming Forums
Views: 418 | Replies: 3
Reply
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  
Join Date: Mar 2006
Posts: 596
Reputation: KevinADC is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 31
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Posting Pro

Re: Can't seem to find the problem...

  #2  
Jul 22nd, 2008
I nominate you for forum cross-poster of the month award. Thats three perl forums so far I have seen this same question posted on.
Reply With Quote  
Join Date: Jul 2008
Location: New Jersey
Posts: 46
Reputation: chaosprime is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
chaosprime's Avatar
chaosprime chaosprime is offline Offline
Light Poster

Re: Can't seem to find the problem...

  #3  
Jul 29th, 2008
Y'know, that sorta looks less like a 'challenge' and more like an actual forum abuse script.
Chaos
Lost Souls: text based RPG
MUDseek: MUD gaming search
Reply With Quote  
Join Date: May 2008
Location: Ontario, Canada
Posts: 45
Reputation: Major Major is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
Major Major Major Major is offline Offline
Light Poster

Re: Can't seem to find the problem...

  #4  
Jul 29th, 2008
Originally Posted by chaosprime View Post
Y'know, that sorta looks less like a 'challenge' and more like an actual forum abuse script.



You're right. especially when "spamming complete" shows up at least twice in the code.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Perl Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Perl Forum

All times are GMT -4. The time now is 10:09 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC