links 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ .rvmrc
2
+ *.swp
3
+ *.gem
4
+ .bundle
5
+ Gemfile.lock
6
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in w3ping.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010-2012 Paolo Perego
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # links
2
+
3
+ ## Introduction
4
+
5
+ [links](https://github.com/thesp0nge/links) is a tool for discovering a website
6
+ available pages without making too much noise.
7
+
8
+ The idea came to me during a penetration test since I had a bulk list of URLs
9
+ to check for availability and I wanted to automate this process.
10
+
11
+ ## Installing links
12
+
13
+ Installing links is easy. You can always obtain the latest stable code by using the following command:
14
+
15
+ ```
16
+ gem install links
17
+ ```
18
+
19
+ If you want to install a _pre_ release, such as a _release candidate_ you can do it this way:
20
+ ```
21
+ gem install links --pre
22
+ ```
23
+
24
+ ## Using links
25
+
26
+ After you installed links gem, you have the links command you can use this way:
27
+
28
+ ```
29
+ links http://www.some.org/somepage.html
30
+ ```
31
+
32
+ ## Contributing to links
33
+
34
+ * Check out the latest master to make sure the feature hasn't been implemented
35
+ or the bug hasn't been fixed yet
36
+ * Check out the issue tracker to make sure someone already hasn't requested it
37
+ and/or contributed it
38
+ * Fork the project
39
+ * Start a feature/bugfix branch
40
+ * Commit and push until you are happy with your contribution
41
+ * Make sure to add tests for it. This is important so I don't break it in a
42
+ future version unintentionally.
43
+ * Please try not to mess with the Rakefile, version, or history. If you want to
44
+ have your own version, or is otherwise necessary, that is fine, but please
45
+ isolate to its own commit so I can cherry-pick around it.
46
+
47
+ ## Copyright
48
+
49
+ Copyright (c) 2010-2012 Paolo Perego, <thesp0nge@gmail.com>. See LICENSE for
50
+ further details.
51
+
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
8
+
data/bin/links ADDED
@@ -0,0 +1,94 @@
1
+ #!/usr/bin/env ruby
2
+ require "links"
3
+ require "rainbow"
4
+ require 'getoptlong'
5
+
6
+ opts = GetoptLong.new(
7
+ [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
8
+ [ '--version', '-v', GetoptLong::NO_ARGUMENT ],
9
+ [ '--bulk', '-b', GetoptLong::REQUIRED_ARGUMENT ],
10
+ [ '--robots', '-r', GetoptLong::NO_ARGUMENT ]
11
+ )
12
+
13
+ trap("INT") { puts '['+'INTERRUPTED'.color(:red)+']'; exit -1 }
14
+ list=[]
15
+ robots=false
16
+
17
+ opts.each do |opt, arg|
18
+ case opt
19
+ when '--help'
20
+ puts "usage: links [-bvh] [filename]"
21
+ puts " -b filename: loads the url list from a plain text file"
22
+ puts " -r : parse robots.txt and make requests to disallowed urls"
23
+ puts " -v : shows version information"
24
+ puts " -h : shows this help"
25
+ exit 0
26
+ when '--version'
27
+ puts "links #{Links::Version.version}"
28
+ exit 0
29
+ when '--robots'
30
+ robots=true
31
+ when '--bulk'
32
+ if ! File.exists?(arg)
33
+ puts "links: file not found (#{arg})".color(:red)
34
+ exit 1
35
+ end
36
+ list = File.open(arg).readlines
37
+ if list.count <= 0
38
+ puts "links: invalid url list".color(:red)
39
+ exit 1
40
+ end
41
+ end
42
+ end
43
+
44
+ target = ARGV[0]
45
+
46
+ if list.count == 0
47
+ list<<target
48
+ end
49
+
50
+ if list[0].nil?
51
+ puts "links: missing target".color(:red)
52
+ exit 1
53
+ end
54
+
55
+ if robots
56
+ list = Links::Api.robots(target)
57
+ end
58
+
59
+ list.each do |l|
60
+ print "#{l}:".color(:white)
61
+ if robots
62
+ code = Links::Api.human('http://'+target+l)
63
+ else
64
+ code = Links::Api.human(l)
65
+ end
66
+ case code
67
+ when "Open"
68
+ print " #{code}\n".color(:green)
69
+ when "Non existent"
70
+ print " #{code}\n".color(:red)
71
+ when "Closed"
72
+ print " #{code}\n".color(:red)
73
+ else
74
+ print " #{code}\n".color(:yellow)
75
+ end
76
+
77
+ if code == 301
78
+ new_link = Links::Api.follow(l)
79
+ printf "following from #{l} to #{new_link}\n".color(:grey)
80
+ code = Links::Api.human(l)
81
+ case code
82
+ when "Open"
83
+ print " #{code}\n".color(:green)
84
+ when "Non existent"
85
+ print " #{code}\n".color(:red)
86
+ when "Closed"
87
+ print " #{code}\n".color(:red)
88
+ else
89
+ print " #{code}\n".color(:yellow)
90
+ end
91
+
92
+ end
93
+
94
+ end
data/lib/links/api.rb ADDED
@@ -0,0 +1,85 @@
1
+ require "net/http"
2
+ require "nokogiri"
3
+
4
+ module Links
5
+ class Api
6
+
7
+ def self.code(url)
8
+ res = Links::Api.get(url)
9
+ res.code ||= -1
10
+ end
11
+
12
+ def self.links(url)
13
+ res = Links::Api.get(url)
14
+ if res.nil?
15
+ return []
16
+ end
17
+ doc = Nokogiri::HTML.parse(res.body)
18
+ l = doc.css('a').map { |link| link['href'] }
19
+ l
20
+ end
21
+
22
+ def self.robots(site, only_disallow=true)
23
+
24
+ if (! site.start_with? 'http://') and (! site.start_with? 'https://')
25
+ site = 'http://'+site
26
+ end
27
+
28
+ list = []
29
+ begin
30
+ res=Net::HTTP.get_response(URI(site+'/robots.txt'))
31
+ if (res.code != "200")
32
+ return []
33
+ end
34
+
35
+ res.body.split("\n").each do |line|
36
+ if only_disallow
37
+ if (line.start_with?('Disallow'))
38
+ list << line.split(":")[1].strip.chomp
39
+ end
40
+ else
41
+ if (line.start_with?('Allow') or line.start_with?('Disallow'))
42
+ list << line.split(":")[1].strip.chomp
43
+ end
44
+ end
45
+ end
46
+ rescue
47
+ return []
48
+ end
49
+
50
+ list
51
+ end
52
+
53
+ def self.follow(url)
54
+ l = Links::Api.links(url)
55
+ l[0]
56
+ end
57
+
58
+ def self.human(url)
59
+ case self.code(url).to_i
60
+ when 200
61
+ return "Open"
62
+ when 301
63
+ return "Moved"
64
+ when 404
65
+ return "Non existent"
66
+ when 401
67
+ return "Closed"
68
+ when 403
69
+ return "Forbidden"
70
+ else
71
+ return "Broken"
72
+ end
73
+ end
74
+
75
+ private
76
+ def self.get(url)
77
+ begin
78
+ Net::HTTP.get_response(URI(url))
79
+ rescue
80
+ return nil
81
+ end
82
+ end
83
+
84
+ end
85
+ end
@@ -0,0 +1,16 @@
1
+ module Links
2
+ module Version
3
+ MAJOR = 0
4
+ MINOR = 20
5
+ PATCH = 0
6
+ BUILD = ''
7
+
8
+ def self.version
9
+ if BUILD.empty?
10
+ return [MAJOR, MINOR, PATCH].compact.join('.')
11
+ else
12
+ return [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
13
+ end
14
+ end
15
+ end
16
+ end
data/lib/links.rb ADDED
@@ -0,0 +1,2 @@
1
+ require "links/version"
2
+ require "links/api"
data/links.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "links/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "links"
7
+ s.version = Links::Version.version
8
+ s.authors = ["Paolo Perego"]
9
+ s.email = ["thesp0nge@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Fetch, discover and crawl what's available in a website.}
12
+ s.description = %q{During the first stage of a security test, it's useful to enumerate website urls without making too much noise. Links can help in this using robots.txt or link in a web page telling you the website contents.}
13
+ s.license = "BSD"
14
+
15
+ s.rubyforge_project = "links"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ # specify any dependencies here; for example:
23
+ s.add_development_dependency "rake"
24
+ s.add_development_dependency "rspec"
25
+ s.add_development_dependency "nokogiri"
26
+ s.add_development_dependency "rainbow"
27
+ # s.add_runtime_dependency "rest-client"
28
+ s.add_runtime_dependency "nokogiri"
29
+ s.add_runtime_dependency "rainbow"
30
+ end
@@ -0,0 +1 @@
1
+ require 'w3ping'
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe W3ping do
4
+ it "should pass" do
5
+ pending
6
+ end
7
+
8
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: links
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.20.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Paolo Perego
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &70178993924920 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70178993924920
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70178998811440 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70178998811440
36
+ - !ruby/object:Gem::Dependency
37
+ name: nokogiri
38
+ requirement: &70178998810960 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70178998810960
47
+ - !ruby/object:Gem::Dependency
48
+ name: rainbow
49
+ requirement: &70178998810280 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70178998810280
58
+ - !ruby/object:Gem::Dependency
59
+ name: nokogiri
60
+ requirement: &70178998809620 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: *70178998809620
69
+ - !ruby/object:Gem::Dependency
70
+ name: rainbow
71
+ requirement: &70178998808840 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: *70178998808840
80
+ description: During the first stage of a security test, it's useful to enumerate website
81
+ urls without making too much noise. Links can help in this using robots.txt or link
82
+ in a web page telling you the website contents.
83
+ email:
84
+ - thesp0nge@gmail.com
85
+ executables:
86
+ - links
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - bin/links
96
+ - lib/links.rb
97
+ - lib/links/api.rb
98
+ - lib/links/version.rb
99
+ - links.gemspec
100
+ - spec/spec_helper.rb
101
+ - spec/w3ping_spec.rb
102
+ homepage: ''
103
+ licenses:
104
+ - BSD
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project: links
123
+ rubygems_version: 1.8.17
124
+ signing_key:
125
+ specification_version: 3
126
+ summary: Fetch, discover and crawl what's available in a website.
127
+ test_files:
128
+ - spec/spec_helper.rb
129
+ - spec/w3ping_spec.rb