firefart/WordpressPingbackPortScanner

GetOptlong issue

Closed this issue · 11 comments

Gem.loaded_specs throws an exception in Ruby-1.9

ruby 1.9.2dev (2010-07-02) [x86_64-linux]
gem 1.3.7
irb 0.9.6(09/06/30)
$ ruby ./wppps.rb -a -t http://localhost http://cixtor.com
[ERROR] undefined method 'version' for nil:NilClass
Trace :
./wppps.rb:80:in 'get_xml_rpc_url'
./wppps.rb:274:in 'block in <main>'
./wppps.rb:270:in 'each'
./wppps.rb:270:in '<main>'

Seems that Ruby-1.9 doesn't support Gem.load_specs anymore.

$ irb
irb(main):001:0> require 'rubygems'
=> false
irb(main):002:0> require 'typhoeus'
=> true
irb(main):003:0> Gem.loaded_specs["typhoeus"].version
NoMethodError: undefined method `version' for nil:NilClass
    from (irb):3
    from /usr/bin/irb:12:in `<main>'
irb(main):004:0>

Hi,
thx for your report. Can you please provide a sample command line call? I can not reproduce this issue.

Can't reproduce it on my side:

irb
1.9.2-p320 :001 > require 'rubygems'
 => false 
1.9.2-p320 :002 > require 'typhoeus'
 => true 
1.9.2-p320 :003 > Gem.loaded_specs["typhoeus"].version
 => #<Gem::Version "0.4.2"> 
1.9.2-p320 :004 >

I used rvm to install 1.9.2, did a gem install typhoeus --version 0.4.2 and it worked.
Can you post your output from Gem.loaded_specs?

Sorry, but I don't know how to test this out. Check the image attached.
POC-1 => WP-Pingback-Port-Scanner

I've updated the code today and with some modifications in a copy of the file wppps.rb I executed the two files with the same parameters, the original executable doesn't print anything usefull because the script exit at line 305 inside a conditional where the length of the array ARGV is checked.
Somehow the gem GetoptLong (in my environment) reset the array ARGV inside the sentence Try/Catch started at line 277; I put a code like this p ARGV in line 276 and line 301 to get the list of parameters in the first dump and an empty array in the second dump.
POC-2 => WP-Pingback-Port-Scanner

thx for the screens! i implemented the ARGV.dup fix on the master branch. Can you please try it again?

Not working, check this new screenshot, I use the original file wppps.rb updated after the change 8f11d1b and the script I've modified (the last one works).

POC-3 => WP-Pingback-Port-Scanner

You can see the changes between the two scripts, and the most important thing is the position of the expression arguments = ARGV.dup, I placed that sentence in line 274 before GetoptLong and you placed it in line 302 after GetoptLong; I don't know very much about Ruby, but you can see in the lateral left panel that using the same parameters the script wppps.rb doesn't works, and wppps.rb.fork it works.

I don't want to bother you with this, I want to know why this code works in your environment and not in mine. Can you provide a screenshot using this version of the script and the parameters used in the last image? I want to know if there's something wrong in my Ruby path.

a ok i see! Can you try it again now?

Almost. Now it's failing when the method get_xml_rpc_url is executed in line 316 because in the arguments processed in line 312 there are expressions different than a Host, in my case I used:

$ ./wppps.rb -v -a -t http://www.cixtor.com/ http://blog.cixtor.com/
["-v", "-a", "-t", "http://www.cixtor.com/", "http://blog.cixtor.com/"]
[ERROR] Url -v does not provide a XML-RPC url
Trace : ./wppps.rb:142:in `get_xml_rpc_url'

POC-4 => WP-Pingback-Port-Scanner

As you can see the script is trying to use -v as the hostname instead of one of the two URL provided, that's why I added a regular expression in a conditional before to declare the variable url_cleaned in line 313; also my script doesn't works if I use more than one URL and one of those doesn't provide a XML-RPC interface.

Works: $ ./wppps.rb.fork -t http://www.with-wordpress.com/
It doesn't: $ ./wppps.rb.fork -t http://www.without-wordpress.com/ http://www.with-wordpress.com/

hmpf that's because getoptlong modifies the ARGV array...will look into this

can you please try again?

Now it works. Thanks, this is a very good Port-Scanner 👍

thx :)