ronin-web 0.2.1 → 0.3.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. data/.document +4 -0
  2. data/.gemtest +0 -0
  3. data/.rspec +1 -0
  4. data/.yardopts +1 -0
  5. data/COPYING.txt +674 -0
  6. data/{History.txt → ChangeLog.md} +39 -8
  7. data/Gemfile +49 -0
  8. data/{README.txt → README.md} +56 -40
  9. data/Rakefile +25 -24
  10. data/bin/ronin-web +18 -5
  11. data/gemspec.yml +30 -0
  12. data/lib/ronin/network/{helpers → mixins}/web.rb +74 -39
  13. data/lib/ronin/web.rb +7 -6
  14. data/lib/ronin/web/extensions.rb +7 -6
  15. data/lib/ronin/web/extensions/nokogiri.rb +22 -0
  16. data/lib/ronin/web/extensions/nokogiri/xml.rb +22 -0
  17. data/lib/ronin/web/extensions/nokogiri/xml/attr.rb +35 -1
  18. data/lib/ronin/web/extensions/nokogiri/xml/document.rb +34 -4
  19. data/lib/ronin/web/extensions/nokogiri/xml/element.rb +36 -2
  20. data/lib/ronin/web/extensions/nokogiri/xml/node.rb +59 -20
  21. data/lib/ronin/web/extensions/nokogiri/xml/text.rb +36 -2
  22. data/lib/ronin/web/middleware.rb +27 -0
  23. data/lib/ronin/web/middleware/base.rb +144 -0
  24. data/lib/ronin/web/middleware/directories.rb +177 -0
  25. data/lib/ronin/web/middleware/files.rb +142 -0
  26. data/lib/ronin/web/middleware/filters.rb +28 -0
  27. data/lib/ronin/web/middleware/filters/campaign_filter.rb +77 -0
  28. data/lib/ronin/web/middleware/filters/ip_filter.rb +73 -0
  29. data/lib/ronin/web/middleware/filters/path_filter.rb +73 -0
  30. data/lib/ronin/web/middleware/filters/referer_filter.rb +71 -0
  31. data/lib/ronin/web/middleware/filters/user_agent_filter.rb +71 -0
  32. data/lib/ronin/web/middleware/filters/vhost_filter.rb +71 -0
  33. data/lib/ronin/web/middleware/helpers.rb +145 -0
  34. data/lib/ronin/web/middleware/proxy.rb +265 -0
  35. data/lib/ronin/web/middleware/proxy_request.rb +262 -0
  36. data/lib/ronin/web/middleware/request.rb +58 -0
  37. data/lib/ronin/web/middleware/response.rb +33 -0
  38. data/lib/ronin/web/middleware/router.rb +167 -0
  39. data/lib/ronin/web/middleware/rule.rb +103 -0
  40. data/lib/ronin/web/proxy.rb +7 -6
  41. data/lib/ronin/web/proxy/app.rb +7 -6
  42. data/lib/ronin/web/proxy/base.rb +14 -9
  43. data/lib/ronin/web/proxy/web.rb +9 -6
  44. data/lib/ronin/web/server.rb +7 -6
  45. data/lib/ronin/web/server/app.rb +7 -6
  46. data/lib/ronin/web/server/base.rb +209 -82
  47. data/lib/ronin/web/server/web.rb +10 -6
  48. data/lib/ronin/web/spider.rb +38 -26
  49. data/lib/ronin/web/version.rb +8 -7
  50. data/lib/ronin/web/web.rb +122 -80
  51. data/ronin-web.gemspec +15 -0
  52. data/spec/helpers/output.rb +3 -0
  53. data/spec/spec_helper.rb +2 -3
  54. data/spec/web/extensions/nokogiri_spec.rb +7 -7
  55. data/spec/web/{server/helpers/server.rb → helpers/rack_app.rb} +3 -14
  56. data/spec/web/helpers/root.rb +15 -0
  57. data/spec/web/helpers/root/test1.txt +1 -0
  58. data/spec/web/helpers/root/test1/index.html +1 -0
  59. data/spec/web/helpers/root/test1/test1.txt +1 -0
  60. data/spec/web/helpers/root/test2.txt +1 -0
  61. data/spec/web/helpers/root/test2/test2.txt +1 -0
  62. data/spec/web/helpers/root/test3.txt +1 -0
  63. data/spec/web/helpers/root/test3/test3.txt +1 -0
  64. data/spec/web/middleware/directories_spec.rb +86 -0
  65. data/spec/web/middleware/files_spec.rb +57 -0
  66. data/spec/web/middleware/filters/campaign_filter_spec.rb +30 -0
  67. data/spec/web/middleware/filters/ip_filter_spec.rb +25 -0
  68. data/spec/web/middleware/filters/path_filter_spec.rb +29 -0
  69. data/spec/web/middleware/filters/referer_filter_spec.rb +25 -0
  70. data/spec/web/middleware/filters/user_agent_filter_spec.rb +25 -0
  71. data/spec/web/middleware/filters/vhost_filter_spec.rb +23 -0
  72. data/spec/web/middleware/proxy_spec.rb +67 -0
  73. data/spec/web/middleware/response_spec.rb +20 -0
  74. data/spec/web/middleware/router_spec.rb +65 -0
  75. data/spec/web/middleware/rule_spec.rb +37 -0
  76. data/spec/web/proxy/base_spec.rb +1 -2
  77. data/spec/web/server/base_spec.rb +4 -13
  78. data/spec/web/server/classes/sub_app.rb +2 -2
  79. data/spec/web/server/classes/test_app.rb +1 -1
  80. data/spec/web/web_spec.rb +57 -67
  81. metadata +171 -146
  82. data.tar.gz.sig +0 -0
  83. data/Manifest.txt +0 -64
  84. data/lib/ronin/scanners/web.rb +0 -52
  85. data/lib/ronin/web/server/files.rb +0 -92
  86. data/lib/ronin/web/server/helpers.rb +0 -25
  87. data/lib/ronin/web/server/helpers/files.rb +0 -126
  88. data/lib/ronin/web/server/helpers/hosts.rb +0 -72
  89. data/lib/ronin/web/server/helpers/proxy.rb +0 -153
  90. data/lib/ronin/web/server/helpers/rendering.rb +0 -36
  91. data/lib/ronin/web/server/hosts.rb +0 -86
  92. data/lib/ronin/web/server/proxy.rb +0 -116
  93. data/spec/scanners/web_spec.rb +0 -24
  94. data/spec/web/helpers/root/index.html +0 -1
  95. data/spec/web/helpers/root/test.txt +0 -1
  96. data/spec/web/helpers/server.rb +0 -10
  97. data/spec/web/server/classes/files/dir/file.txt +0 -1
  98. data/spec/web/server/classes/files/dir/index.html +0 -1
  99. data/spec/web/server/classes/files/dir2/file2.txt +0 -1
  100. data/spec/web/server/classes/files/dir3/page.xml +0 -4
  101. data/spec/web/server/classes/files/file.txt +0 -1
  102. data/spec/web/server/classes/files_app.rb +0 -27
  103. data/spec/web/server/classes/hosts_app.rb +0 -40
  104. data/spec/web/server/classes/proxy_app.rb +0 -45
  105. data/spec/web/server/files_spec.rb +0 -74
  106. data/spec/web/server/hosts_spec.rb +0 -55
  107. data/spec/web/server/proxy_spec.rb +0 -49
  108. data/tasks/spec.rb +0 -10
  109. data/tasks/yard.rb +0 -13
  110. metadata.gz.sig +0 -3
@@ -1,52 +0,0 @@
1
- #
2
- # Ronin Web - A Ruby library for Ronin that provides support for web
3
- # scraping and spidering functionality.
4
- #
5
- # Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
6
- #
7
- # This program is free software; you can redistribute it and/or modify
8
- # it under the terms of the GNU General Public License as published by
9
- # the Free Software Foundation; either version 2 of the License, or
10
- # (at your option) any later version.
11
- #
12
- # This program is distributed in the hope that it will be useful,
13
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- # GNU General Public License for more details.
16
- #
17
- # You should have received a copy of the GNU General Public License
18
- # along with this program; if not, write to the Free Software
19
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
- #
21
-
22
- require 'ronin/web/spider'
23
- require 'ronin/scanners/scanner'
24
-
25
- module Ronin
26
- module Scanners
27
- class Web < Web::Spider
28
-
29
- include Scanner
30
-
31
- protected
32
-
33
- def each_target(&block)
34
- print_info "Started web spidering ..."
35
-
36
- history.clear
37
-
38
- unless visit_hosts.empty?
39
- enqueue("http://#{visit_hosts.first}/")
40
- end
41
-
42
- run do |page|
43
- print_info "Scanning page: #{page.url}"
44
- block.call(page)
45
- end
46
-
47
- print_info "Finished web spidering."
48
- end
49
-
50
- end
51
- end
52
- end
@@ -1,92 +0,0 @@
1
- #
2
- # Ronin Web - A Ruby library for Ronin that provides support for web
3
- # scraping and spidering functionality.
4
- #
5
- # Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
6
- #
7
- # This program is free software; you can redistribute it and/or modify
8
- # it under the terms of the GNU General Public License as published by
9
- # the Free Software Foundation; either version 2 of the License, or
10
- # (at your option) any later version.
11
- #
12
- # This program is distributed in the hope that it will be useful,
13
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- # GNU General Public License for more details.
16
- #
17
- # You should have received a copy of the GNU General Public License
18
- # along with this program; if not, write to the Free Software
19
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
- #
21
-
22
- require 'ronin/web/server/helpers/files'
23
-
24
- module Ronin
25
- module Web
26
- module Server
27
- module Files
28
- def self.included(base)
29
- base.module_eval do
30
- #
31
- # Hosts the contents of a file.
32
- #
33
- # @param [String] http_path
34
- # The path the web server will host the file at.
35
- #
36
- # @param [String] path
37
- # The path to the local file.
38
- #
39
- # @param [Symbol] custom_content_type
40
- # Optional content-type to host the file as.
41
- #
42
- # @example
43
- # MyApp.file '/robots.txt', '/path/to/my_robots.txt'
44
- #
45
- # @since 0.2.0
46
- #
47
- def self.file(http_path,path,custom_content_type=nil)
48
- path = File.expand_path(path)
49
-
50
- any(http_path) do
51
- return_file(path,custom_content_type)
52
- end
53
- end
54
-
55
- #
56
- # Hosts the contents of the directory.
57
- #
58
- # @param [String] http_path
59
- # The path the web server will host the directory at.
60
- #
61
- # @param [String] directory
62
- # The path to the local directory.
63
- #
64
- # @param [Symbol] custom_content_type
65
- # Optional content-type to host the contents of the directory
66
- # with.
67
- #
68
- # @example
69
- # MyApp.directory '/download/', '/tmp/files/'
70
- #
71
- # @since 0.2.0
72
- #
73
- def self.directory(http_path,directory,custom_content_type=nil)
74
- directory = File.expand_path(directory)
75
-
76
- any(File.join(http_path,'*')) do
77
- sub_path = File.expand_path(File.join('',params[:splat].first))
78
- full_path = File.join(directory,sub_path)
79
-
80
- return_file(full_path,custom_content_type)
81
- end
82
- end
83
-
84
- protected
85
-
86
- helpers Ronin::Web::Server::Helpers::Files
87
- end
88
- end
89
- end
90
- end
91
- end
92
- end
@@ -1,25 +0,0 @@
1
- #
2
- # Ronin Web - A Ruby library for Ronin that provides support for web
3
- # scraping and spidering functionality.
4
- #
5
- # Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
6
- #
7
- # This program is free software; you can redistribute it and/or modify
8
- # it under the terms of the GNU General Public License as published by
9
- # the Free Software Foundation; either version 2 of the License, or
10
- # (at your option) any later version.
11
- #
12
- # This program is distributed in the hope that it will be useful,
13
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- # GNU General Public License for more details.
16
- #
17
- # You should have received a copy of the GNU General Public License
18
- # along with this program; if not, write to the Free Software
19
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
- #
21
-
22
- require 'ronin/web/server/helpers/rendering'
23
- require 'ronin/web/server/helpers/files'
24
- require 'ronin/web/server/helpers/hosts'
25
- require 'ronin/web/server/helpers/proxy'
@@ -1,126 +0,0 @@
1
- #
2
- # Ronin Web - A Ruby library for Ronin that provides support for web
3
- # scraping and spidering functionality.
4
- #
5
- # Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
6
- #
7
- # This program is free software; you can redistribute it and/or modify
8
- # it under the terms of the GNU General Public License as published by
9
- # the Free Software Foundation; either version 2 of the License, or
10
- # (at your option) any later version.
11
- #
12
- # This program is distributed in the hope that it will be useful,
13
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- # GNU General Public License for more details.
16
- #
17
- # You should have received a copy of the GNU General Public License
18
- # along with this program; if not, write to the Free Software
19
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
- #
21
-
22
- module Ronin
23
- module Web
24
- module Server
25
- module Helpers
26
- module Files
27
- # Directory index files
28
- INDICES = ['index.htm', 'index.html']
29
-
30
- #
31
- # Sets the content_type based on the extension of a given file.
32
- #
33
- # @param [String] path
34
- # The path to guess the content-type for.
35
- #
36
- # @return [String]
37
- # The MIME content-type of the file.
38
- #
39
- # @example
40
- # content_type_for 'file.html'
41
- #
42
- # @since 0.2.0
43
- #
44
- def content_type_for(path)
45
- ext = File.extname(path).downcase
46
-
47
- return content_type(ext[1..-1])
48
- end
49
-
50
- #
51
- # Finds the index file for a given directory.
52
- #
53
- # @param [String] path
54
- # The path of the directory.
55
- #
56
- # @yield [index_path]
57
- # If a block is given, it will be passed the path of the
58
- # index file for the given directory.
59
- #
60
- # @yieldparam [String] index_path
61
- # The path to the index file.
62
- #
63
- # @return [String]
64
- # The path to the index file.
65
- #
66
- # @since 0.2.0
67
- #
68
- def index_of(path,&block)
69
- path = File.expand_path(path)
70
-
71
- Base.indices.each do |name|
72
- index = File.join(path,name)
73
-
74
- if File.file?(index)
75
- block.call(index) if block
76
- return index
77
- end
78
- end
79
-
80
- pass
81
- end
82
-
83
- #
84
- # Returns a file to the client with the appropriate content-type.
85
- #
86
- # @param [String] path
87
- # The path of the file to return.
88
- #
89
- # @param [Symbol] custom_content_type
90
- # Optional content-type to return the file with.
91
- #
92
- # @example
93
- # return_file 'lol.jpg'
94
- #
95
- # @example
96
- # return_file '/tmp/file', :html
97
- #
98
- # @since 0.2.0
99
- #
100
- def return_file(path,custom_content_type=nil)
101
- path = File.expand_path(path)
102
-
103
- pass unless File.exists?(path)
104
-
105
- if File.directory?(path)
106
- index_of(path) { |index| path = index }
107
- end
108
-
109
- if custom_content_type
110
- content_type custom_content_type
111
- else
112
- content_type_for path
113
- end
114
-
115
- case request.request_method
116
- when 'GET', 'POST'
117
- halt 200, File.new(path)
118
- else
119
- halt 302
120
- end
121
- end
122
- end
123
- end
124
- end
125
- end
126
- end
@@ -1,72 +0,0 @@
1
- #
2
- # Ronin Web - A Ruby library for Ronin that provides support for web
3
- # scraping and spidering functionality.
4
- #
5
- # Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
6
- #
7
- # This program is free software; you can redistribute it and/or modify
8
- # it under the terms of the GNU General Public License as published by
9
- # the Free Software Foundation; either version 2 of the License, or
10
- # (at your option) any later version.
11
- #
12
- # This program is distributed in the hope that it will be useful,
13
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- # GNU General Public License for more details.
16
- #
17
- # You should have received a copy of the GNU General Public License
18
- # along with this program; if not, write to the Free Software
19
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
- #
21
-
22
- module Ronin
23
- module Web
24
- module Server
25
- module Helpers
26
- module Hosts
27
- #
28
- # Calls a given block for requests with matching Host headers.
29
- #
30
- # @param [Regexp, String] name_or_pattern
31
- # The exact name or pattern to match Host headers.
32
- #
33
- # @yield []
34
- # The given block will be called when a request is received
35
- # with the matching Host header.
36
- #
37
- # @example
38
- # downloads = 0
39
- #
40
- # get '/file' do
41
- # for_host /^ftp/ do
42
- # downloads += 1
43
- #
44
- # content_type :txt
45
- # 'some file'
46
- # end
47
- #
48
- # for_host /^www/ do
49
- # downloads += 1
50
- #
51
- # 'some file'
52
- # end
53
- #
54
- # for_host 'localhost' do
55
- # "Total Downloads: #{downloads}"
56
- # end
57
- # end
58
- #
59
- # @since 0.2.0
60
- #
61
- def for_host(name_or_pattern,&block)
62
- if name_or_pattern.kind_of?(Regexp)
63
- halt(*block.call()) if request.host =~ name_or_pattern
64
- else
65
- halt(*block.call()) if request.host == name_or_pattern.to_s
66
- end
67
- end
68
- end
69
- end
70
- end
71
- end
72
- end
@@ -1,153 +0,0 @@
1
- #
2
- # Ronin Web - A Ruby library for Ronin that provides support for web
3
- # scraping and spidering functionality.
4
- #
5
- # Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
6
- #
7
- # This program is free software; you can redistribute it and/or modify
8
- # it under the terms of the GNU General Public License as published by
9
- # the Free Software Foundation; either version 2 of the License, or
10
- # (at your option) any later version.
11
- #
12
- # This program is distributed in the hope that it will be useful,
13
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- # GNU General Public License for more details.
16
- #
17
- # You should have received a copy of the GNU General Public License
18
- # along with this program; if not, write to the Free Software
19
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
- #
21
-
22
- require 'ronin/network/http'
23
-
24
- module Ronin
25
- module Web
26
- module Server
27
- module Helpers
28
- module Proxy
29
- #
30
- # Proxies the current request.
31
- #
32
- # @param [Hash] options
33
- # Additional options to use when proxying the request.
34
- #
35
- # @yield [(response), body]
36
- # If a block is given, it will be passed the optional response
37
- # of the proxied request and the body received from the
38
- # proxied request.
39
- #
40
- # @yieldparam [Net::HTTP::Response] response
41
- # The response of the proxied request.
42
- #
43
- # @yieldparam [String] body
44
- # The body from the proxied request.
45
- #
46
- # @example
47
- # get '/login.php' do
48
- # proxy do |body|
49
- # body.gsub(/https/,'http')
50
- # end
51
- # end
52
- #
53
- # @since 0.2.0
54
- #
55
- def proxy(options={},&block)
56
- default_options = {
57
- :host => request.host,
58
- :port => request.port,
59
- :method => request.request_method,
60
- :path => request.path_info,
61
- :query => request.query_string,
62
- :content_type => request.content_type
63
- }
64
-
65
- request.env.each do |name,value|
66
- if name =~ /^HTTP/
67
- default_options[name.gsub(/^HTTP_/,'').downcase.to_sym] = value
68
- end
69
- end
70
-
71
- options = default_options.merge(options)
72
- http_response = Net.http_request(options)
73
-
74
- response = Rack::Response.new(
75
- [http_response.body],
76
- http_response.code,
77
- http_response.to_hash
78
- )
79
-
80
- if block
81
- old_body = response.body.first
82
-
83
- new_body = if block.arity == 2
84
- block.call(response,old_body)
85
- else
86
- block.call(old_body)
87
- end
88
-
89
- response.body[0] = (new_body || old_body)
90
- end
91
-
92
- halt(response)
93
- end
94
-
95
- #
96
- # Proxies the current request.
97
- #
98
- # @param [Hash] options
99
- # Additional options to use when proxying the request.
100
- #
101
- # @yield [(response), doc]
102
- # If a block is given, it will be passed the optional response
103
- # of the proxied request and the document representing the
104
- # proxied request.
105
- #
106
- # @yieldparam [Net::HTTP::Response] response
107
- # The response of the proxied request.
108
- #
109
- # @yieldparam [Nokogiri::HTML, Nokogiri::XML] doc
110
- # The document representing the proxied request.
111
- #
112
- # @example
113
- # get '/login.php' do
114
- # proxy do |doc|
115
- # doc.search('form/@action').each do |action|
116
- # action.inner_text = action.inner_text.gsub(
117
- # /^https/, 'http'
118
- # )
119
- # end
120
- # end
121
- # end
122
- #
123
- # @since 0.2.0
124
- #
125
- def proxy_doc(options={},&block)
126
- proxy(options) do |response,body|
127
- case response.content_type
128
- when 'text/html'
129
- doc = Nokogiri::HTML(body)
130
- when 'text/xml'
131
- doc = Nokogiri::XML(body)
132
- else
133
- doc = nil
134
- end
135
-
136
- if doc
137
- if block
138
- if block.arity == 2
139
- block.call(response,doc)
140
- else
141
- block.call(doc)
142
- end
143
- end
144
-
145
- doc.to_s
146
- end
147
- end
148
- end
149
- end
150
- end
151
- end
152
- end
153
- end