ronin 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. data/History.txt +19 -1
  2. data/Manifest.txt +8 -17
  3. data/README.txt +0 -4
  4. data/Rakefile +14 -15
  5. data/TODO.txt +1 -2
  6. data/lib/ronin.rb +2 -2
  7. data/lib/ronin/extensions.rb +1 -0
  8. data/lib/ronin/extensions/file.rb +33 -0
  9. data/lib/ronin/formatting/extensions/http/string.rb +12 -0
  10. data/lib/ronin/formatting/extensions/text/string.rb +4 -4
  11. data/lib/ronin/model.rb +8 -0
  12. data/lib/ronin/objectify/exceptions/object_context_not_found.rb +3 -1
  13. data/lib/ronin/objectify/exceptions/unknown_object_context.rb +3 -1
  14. data/lib/ronin/sessions/telnet.rb +5 -2
  15. data/lib/ronin/{web.rb → translators.rb} +1 -2
  16. data/lib/ronin/{hexdump.rb → ui.rb} +2 -2
  17. data/lib/ronin/{hexdump/extensions.rb → ui/hexdump.rb} +2 -2
  18. data/lib/ronin/ui/hexdump/extensions.rb +25 -0
  19. data/lib/ronin/{hexdump → ui/hexdump}/extensions/file.rb +2 -2
  20. data/lib/ronin/{hexdump → ui/hexdump}/extensions/kernel.rb +2 -2
  21. data/lib/ronin/ui/hexdump/hexdump.rb +78 -0
  22. data/lib/ronin/version.rb +1 -1
  23. data/spec/formatting/html_spec.rb +9 -0
  24. data/spec/formatting/http_spec.rb +9 -0
  25. data/spec/formatting/text_spec.rb +20 -1
  26. metadata +12 -51
  27. data/lib/ronin/hexdump/hexdump.rb +0 -76
  28. data/lib/ronin/sessions/web.rb +0 -78
  29. data/lib/ronin/web/extensions.rb +0 -1
  30. data/lib/ronin/web/extensions/hpricot.rb +0 -5
  31. data/lib/ronin/web/extensions/hpricot/comment.rb +0 -19
  32. data/lib/ronin/web/extensions/hpricot/container.rb +0 -46
  33. data/lib/ronin/web/extensions/hpricot/doc.rb +0 -21
  34. data/lib/ronin/web/extensions/hpricot/elem.rb +0 -25
  35. data/lib/ronin/web/extensions/hpricot/tag.rb +0 -19
  36. data/lib/ronin/web/extensions/hpricot/text.rb +0 -19
  37. data/lib/ronin/web/web.rb +0 -331
  38. data/spec/web/extensions/hpricot_spec.rb +0 -62
@@ -1,21 +0,0 @@
1
- require 'ronin/web/extensions/hpricot/container'
2
- require 'ronin/web/extensions/hpricot/tag'
3
- require 'ronin/web/extensions/hpricot/text'
4
- require 'ronin/web/extensions/hpricot/comment'
5
- require 'ronin/web/extensions/hpricot/elem'
6
-
7
- module Hpricot
8
- class Doc
9
-
10
- include Comparable
11
-
12
- #
13
- # Returns +true+ if the documents children match the children of the
14
- # _other_ document.
15
- #
16
- def ==(other)
17
- children == other.children
18
- end
19
-
20
- end
21
- end
@@ -1,25 +0,0 @@
1
- require 'ronin/web/extensions/hpricot/container'
2
-
3
- require 'hpricot'
4
-
5
- module Hpricot
6
- class Elem
7
-
8
- include Comparable
9
-
10
- #
11
- # Returns +true+ if the element has the same starting-tag and
12
- # ending-tag as the _other_ element, returns +false+ otherwise.
13
- #
14
- def eql?(other)
15
- return false unless self.class == other.class
16
-
17
- return (stag == other.stag && etag == other.etag)
18
- end
19
-
20
- def ==(other)
21
- self.eql?(other) && super(other)
22
- end
23
-
24
- end
25
- end
@@ -1,19 +0,0 @@
1
- require 'hpricot'
2
-
3
- module Hpricot
4
- module Tag
5
-
6
- #
7
- # Returns +true+ if the tag has the same name as the _other_ tag,
8
- # returns +false+ otherwise.
9
- #
10
- def eql?(other)
11
- return false unless self.class == other.class
12
-
13
- return self.name == other.name
14
- end
15
-
16
- alias == eql?
17
-
18
- end
19
- end
@@ -1,19 +0,0 @@
1
- require 'hpricot'
2
-
3
- module Hpricot
4
- class Text
5
-
6
- #
7
- # Returns +true+ if the text node has the same content the _other_ text
8
- # node, returns +false+ otherwise.
9
- #
10
- def eql?(other)
11
- return false unless self.class == other.class
12
-
13
- return content == other.content
14
- end
15
-
16
- alias == eql?
17
-
18
- end
19
- end
@@ -1,331 +0,0 @@
1
- #
2
- #--
3
- # Ronin - A Ruby platform designed for information security and data
4
- # exploration tasks.
5
- #
6
- # Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
7
- #
8
- # This program is free software; you can redistribute it and/or modify
9
- # it under the terms of the GNU General Public License as published by
10
- # the Free Software Foundation; either version 2 of the License, or
11
- # (at your option) any later version.
12
- #
13
- # This program is distributed in the hope that it will be useful,
14
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- # GNU General Public License for more details.
17
- #
18
- # You should have received a copy of the GNU General Public License
19
- # along with this program; if not, write to the Free Software
20
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
- #++
22
- #
23
-
24
- require 'ronin/network/http'
25
-
26
- require 'uri/http'
27
- require 'mechanize'
28
- require 'open-uri'
29
- require 'spidr'
30
-
31
- module Ronin
32
- module Web
33
- #
34
- # Returns the default Ronin Web proxy port.
35
- #
36
- def Web.default_proxy_port
37
- Network::HTTP.default_proxy_port
38
- end
39
-
40
- #
41
- # Sets the default Ronin Web proxy port to the specified _port_.
42
- #
43
- def Web.default_proxy_port=(port)
44
- Network::HTTP.default_proxy_port = port
45
- end
46
-
47
- #
48
- # Returns the +Hash+ of the Ronin Web proxy information.
49
- #
50
- def Web.proxy
51
- Network::HTTP.proxy
52
- end
53
-
54
- #
55
- # Resets the Web proxy settings.
56
- #
57
- def Web.disable_proxy
58
- Network::HTTP.disable_proxy
59
- end
60
-
61
- #
62
- # Creates a HTTP URI based from the given _proxy_info_ hash. The
63
- # _proxy_info_ hash defaults to Web.proxy, if not given.
64
- #
65
- def Web.proxy_url(proxy_info=Web.proxy)
66
- if Web.proxy[:host]
67
- userinfo = nil
68
-
69
- if (Web.proxy[:user] || Web.proxy[:password])
70
- userinfo = "#{Web.proxy[:user]}:#{Web.proxy[:password]}"
71
- end
72
-
73
- return URI::HTTP.build(
74
- :host => Web.proxy[:host],
75
- :port => Web.proxy[:port],
76
- :userinfo => userinfo,
77
- :path => '/'
78
- )
79
- end
80
- end
81
-
82
- #
83
- # Returns the supported Web User-Agent Aliases.
84
- #
85
- def Web.user_agent_aliases
86
- WWW::Mechanize::AGENT_ALIASES
87
- end
88
-
89
- #
90
- # Returns the Ronin Web User-Agent
91
- #
92
- def Web.user_agent
93
- Network::HTTP.user_agent
94
- end
95
-
96
- #
97
- # Sets the Ronin Web User-Agent to the specified _new_agent_.
98
- #
99
- def Web.user_agent=(new_agent)
100
- Network::HTTP.user_agent = new_agent
101
- end
102
-
103
- #
104
- # Sets the Ronin Web User-Agent to the specified user agent alias
105
- # _name_.
106
- #
107
- def Web.user_agent_alias=(name)
108
- Network::HTTP.user_agent = Web.user_agent_aliases[name.to_s]
109
- end
110
-
111
- #
112
- # Opens the _url_ with the given _options_. The contents of the _url_
113
- # will be returned.
114
- #
115
- # _options_ may contain the following keys:
116
- # <tt>:user_agent_alias</tt>:: The User-Agent Alias to use.
117
- # <tt>:user_agent</tt>:: The User-Agent string to use.
118
- # <tt>:proxy</tt>:: A +Hash+ of the proxy information to use.
119
- #
120
- # Web.open('http://www.hackety.org/')
121
- #
122
- # Web.open('http://tenderlovemaking.com/',
123
- # :user_agent_alias => 'Linux Mozilla')
124
- #
125
- # Web.open('http://www.wired.com/', :user_agent => 'the future')
126
- #
127
- def Web.open(url,options={})
128
- headers = {}
129
-
130
- if options[:user_agent_alias]
131
- headers['User-Agent'] = Web.user_agent_aliases[options[:user_agent_alias]]
132
- elsif options[:user_agent]
133
- headers['User-Agent'] = options[:user_agent]
134
- elsif Web.user_agent
135
- headers['User-Agent'] = Web.user_agent
136
- end
137
-
138
- proxy = (options[:proxy] || Web.proxy)
139
- if proxy[:host]
140
- headers[:proxy] = Web.proxy_url(proxy)
141
- end
142
-
143
- return Kernel.open(url,headers)
144
- end
145
-
146
- #
147
- # Creates a new Mechanize agent with the given _options_.
148
- #
149
- # _options_ may contain the following keys:
150
- # <tt>:user_agent_alias</tt>:: The User-Agent Alias to use.
151
- # <tt>:user_agent</tt>:: The User-Agent string to use.
152
- # <tt>:proxy</tt>:: A +Hash+ of the proxy information to use.
153
- #
154
- # Web.agent
155
- # Web.agent(:user_agent_alias => 'Linux Mozilla')
156
- # Web.agent(:user_agent => 'wooden pants')
157
- #
158
- def Web.agent(options={},&block)
159
- agent = WWW::Mechanize.new
160
-
161
- if options[:user_agent_alias]
162
- agent.user_agent_alias = options[:user_agent_alias]
163
- elsif options[:user_agent]
164
- agent.user_agent = options[:user_agent]
165
- elsif Web.user_agent
166
- agent.user_agent = Web.user_agent
167
- end
168
-
169
- proxy = (options[:proxy] || Web.proxy)
170
- if proxy[:host]
171
- agent.set_proxy(proxy[:host],proxy[:port],proxy[:user],proxy[:password])
172
- end
173
-
174
- block.call(agent) if block
175
- return agent
176
- end
177
-
178
- #
179
- # Gets the specified _url_ with the given _options_. If a _block_ is
180
- # given, it will be passed the retrieved page.
181
- #
182
- # _options_ may contain the following keys:
183
- # <tt>:user_agent_alias</tt>:: The User-Agent Alias to use.
184
- # <tt>:user_agent</tt>:: The User-Agent string to use.
185
- # <tt>:proxy</tt>:: A +Hash+ of the proxy information to use.
186
- #
187
- # Web.get('http://www.0x000000.com') # => WWW::Mechanize::Page
188
- #
189
- # Web.get('http://www.rubyinside.com') do |page|
190
- # page.search('div.post/h2/a').each do |title|
191
- # puts title.inner_text
192
- # end
193
- # end
194
- #
195
- def Web.get(url,options={},&block)
196
- page = Web.agent(options).get(url)
197
-
198
- block.call(page) if block
199
- return page
200
- end
201
-
202
- #
203
- # Gets the specified _url_ with the given _options_, returning the body
204
- # of the requested page. If a _block_ is given, it will be passed the
205
- # body of the retrieved page.
206
- #
207
- # _options_ may contain the following keys:
208
- # <tt>:user_agent_alias</tt>:: The User-Agent Alias to use.
209
- # <tt>:user_agent</tt>:: The User-Agent string to use.
210
- # <tt>:proxy</tt>:: A +Hash+ of the proxy information to use.
211
- #
212
- # Web.get_body('http://www.rubyinside.com') # => String
213
- #
214
- # Web.get_body('http://www.rubyinside.com') do |body|
215
- # puts body
216
- # end
217
- #
218
- def Web.get_body(url,options={},&block)
219
- body = Web.get(url,options).body
220
-
221
- block.call(body) if block
222
- return body
223
- end
224
-
225
- #
226
- # Posts the specified _url_ with the given _options_. If a _block_ is
227
- # given, it will be passed the posted page.
228
- #
229
- # _options_ may contain the following keys:
230
- # <tt>:query</tt>:: The query parameters to post to the specified _url_.
231
- # <tt>:user_agent_alias</tt>:: The User-Agent Alias to use.
232
- # <tt>:user_agent</tt>:: The User-Agent string to use.
233
- # <tt>:proxy</tt>:: A +Hash+ of the proxy information to use.
234
- #
235
- # Web.post('http://www.rubyinside.com') # => WWW::Mechanize::Page
236
- #
237
- def Web.post(url,options={},&block)
238
- query = (options[:query] || {})
239
- page = Web.agent(options).post(url,query)
240
-
241
- block.call(page) if block
242
- return page
243
- end
244
-
245
- #
246
- # Poststhe specified _url_ with the given _options_, returning the body
247
- # of the posted page. If a _block_ is given, it will be passed the
248
- # body of the posted page.
249
- #
250
- # _options_ may contain the following keys:
251
- # <tt>:user_agent_alias</tt>:: The User-Agent Alias to use.
252
- # <tt>:user_agent</tt>:: The User-Agent string to use.
253
- # <tt>:proxy</tt>:: A +Hash+ of the proxy information to use.
254
- #
255
- # Web.post_body('http://www.rubyinside.com') # => String
256
- #
257
- # Web.post_body('http://www.rubyinside.com') do |body|
258
- # puts body
259
- # end
260
- #
261
- def Web.post_body(url,options={},&block)
262
- body = Web.post(url,options).body
263
-
264
- block.call(body) if block
265
- return body
266
- end
267
-
268
- #
269
- # Creates a new Spidr::Agent object with the given _options_ and
270
- # _block_. If a _block_ is given, it will be passed the newly created
271
- # Spidr::Agent object.
272
- #
273
- # _options_ may contain the following keys:
274
- # <tt>:proxy</tt>:: The proxy to use while spidering. Defaults to
275
- # Web.proxy.
276
- # <tt>:user_agent</tt>:: The User-Agent string to send. Defaults to
277
- # Web.user_agent.
278
- # <tt>:referer</tt>:: The referer URL to send.
279
- # <tt>:delay</tt>:: Duration in seconds to pause between spidering each
280
- # link. Defaults to 0.
281
- # <tt>:host</tt>:: The host-name to visit.
282
- # <tt>:hosts</tt>:: An +Array+ of host patterns to visit.
283
- # <tt>:ignore_hosts</tt>:: An +Array+ of host patterns to not visit.
284
- # <tt>:ports</tt>:: An +Array+ of port patterns to visit.
285
- # <tt>:ignore_ports</tt>:: An +Array+ of port patterns to not visit.
286
- # <tt>:links</tt>:: An +Array+ of link patterns to visit.
287
- # <tt>:ignore_links</tt>:: An +Array+ of link patterns to not visit.
288
- # <tt>:exts</tt>:: An +Array+ of File extension patterns to visit.
289
- # <tt>:ignore_exts</tt>:: An +Array+ of File extension patterns to not
290
- # visit.
291
- #
292
- def Web.spider_agent(options={},&block)
293
- options = Web.spider_default_options.merge(options)
294
-
295
- return Spidr::Agent.new(options,&block)
296
- end
297
-
298
- #
299
- # Creates a new Spidr::Agent object with the given _options_ and will
300
- # begin spidering the specified host _name_. If a _block_ is given it
301
- # will be passed the newly created Spidr::Agent object, before the
302
- # agent begins spidering.
303
- #
304
- def Web.spider_host(name,options={},&block)
305
- options = Web.spider_default_options.merge(options)
306
-
307
- return Spidr::Agent.host(name,options,&block)
308
- end
309
-
310
- #
311
- # Creates a new Spidr::Agent object with the given _options_ and will
312
- # begin spidering the host of the specified _url_. If a _block_ is
313
- # given it will be passed the newly created Spidr::Agent object, before
314
- # the agent begins spidering.
315
- #
316
- def Web.spider_site(url,options={},&block)
317
- options = Web.spider_default_options.merge(options)
318
-
319
- return Spidr::Agent.site(url,options,&block)
320
- end
321
-
322
- protected
323
-
324
- #
325
- # Returns the default options for Spidr::Agent.
326
- #
327
- def Web.spider_default_options
328
- {:proxy => Web.proxy, :user_agent => Web.user_agent}
329
- end
330
- end
331
- end
@@ -1,62 +0,0 @@
1
- require 'ronin/web/extensions/hpricot'
2
-
3
- require 'spec_helper'
4
-
5
- describe Hpricot do
6
- before(:all) do
7
- @doc = Hpricot(%{<html><head><title>test</title></head><body><p><b>This is a test</b> html <i>page</i>.</p></div></body></html>})
8
-
9
- @edited_doc = Hpricot(%{<html><head><title>test</title></head><body><p><b>This is a test</b> html page.</p></div></body></html>})
10
- end
11
-
12
- it "should be able to test if two elements are equal" do
13
- elem1 = @doc.at('b')
14
- elem2 = @edited_doc.at('b')
15
-
16
- (elem1 == elem2).should == true
17
- end
18
-
19
- it "should be able to test if two elements are not equal" do
20
- elem1 = @doc.at('p').children.last
21
- elem2 = @edited_doc.at('b')
22
-
23
- (elem1 == elem2).should == false
24
- end
25
-
26
- it "should be able to compare two elements" do
27
- elem1 = @doc.at('p')
28
- elem2 = @edited_doc.at('p')
29
-
30
- (elem1 > elem2).should == true
31
- (elem2 < elem1).should == true
32
- end
33
-
34
- it "should be able to iterate over every child" do
35
- children = []
36
-
37
- @doc.every_child { |child| children << child }
38
-
39
- children.length.should == 13
40
- end
41
-
42
- it "should be able to iterate over every text node" do
43
- text = []
44
-
45
- @doc.all_text { |node| text << node.content }
46
-
47
- text.should == ['test', 'This is a test', ' html ', 'page', '.']
48
- end
49
-
50
- it "should provide a count of all sub-children" do
51
- @doc.count_children.should == 13
52
- end
53
-
54
- it "should be able to test if two Hpricot documents are equal" do
55
- (@doc == @doc).should == true
56
- end
57
-
58
- it "should be able to compare two Hpricot documents" do
59
- (@doc > @edited_doc).should == true
60
- (@edited_doc < @doc).should == true
61
- end
62
- end