ronin-support 0.1.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. data/.document +4 -0
  2. data/.rspec +1 -0
  3. data/.yardopts +1 -0
  4. data/COPYING.txt +504 -0
  5. data/ChangeLog.md +4 -0
  6. data/Gemfile +23 -0
  7. data/README.md +98 -0
  8. data/Rakefile +29 -0
  9. data/gemspec.yml +20 -0
  10. data/lib/ronin/extensions.rb +28 -0
  11. data/lib/ronin/extensions/file.rb +63 -0
  12. data/lib/ronin/extensions/ip_addr.rb +220 -0
  13. data/lib/ronin/extensions/kernel.rb +45 -0
  14. data/lib/ronin/extensions/meta.rb +22 -0
  15. data/lib/ronin/extensions/meta/object.rb +24 -0
  16. data/lib/ronin/extensions/string.rb +200 -0
  17. data/lib/ronin/formatting.rb +26 -0
  18. data/lib/ronin/formatting/binary.rb +22 -0
  19. data/lib/ronin/formatting/digest.rb +22 -0
  20. data/lib/ronin/formatting/extensions.rb +25 -0
  21. data/lib/ronin/formatting/extensions/binary.rb +24 -0
  22. data/lib/ronin/formatting/extensions/binary/file.rb +35 -0
  23. data/lib/ronin/formatting/extensions/binary/integer.rb +147 -0
  24. data/lib/ronin/formatting/extensions/binary/string.rb +363 -0
  25. data/lib/ronin/formatting/extensions/digest.rb +23 -0
  26. data/lib/ronin/formatting/extensions/digest/file.rb +117 -0
  27. data/lib/ronin/formatting/extensions/digest/string.rb +80 -0
  28. data/lib/ronin/formatting/extensions/http.rb +23 -0
  29. data/lib/ronin/formatting/extensions/http/integer.rb +57 -0
  30. data/lib/ronin/formatting/extensions/http/string.rb +102 -0
  31. data/lib/ronin/formatting/extensions/text.rb +23 -0
  32. data/lib/ronin/formatting/extensions/text/array.rb +125 -0
  33. data/lib/ronin/formatting/extensions/text/string.rb +206 -0
  34. data/lib/ronin/formatting/http.rb +22 -0
  35. data/lib/ronin/formatting/text.rb +22 -0
  36. data/lib/ronin/network.rb +29 -0
  37. data/lib/ronin/network/esmtp.rb +22 -0
  38. data/lib/ronin/network/extensions.rb +29 -0
  39. data/lib/ronin/network/extensions/esmtp.rb +22 -0
  40. data/lib/ronin/network/extensions/esmtp/net.rb +100 -0
  41. data/lib/ronin/network/extensions/http.rb +22 -0
  42. data/lib/ronin/network/extensions/http/net.rb +661 -0
  43. data/lib/ronin/network/extensions/imap.rb +22 -0
  44. data/lib/ronin/network/extensions/imap/net.rb +124 -0
  45. data/lib/ronin/network/extensions/pop3.rb +22 -0
  46. data/lib/ronin/network/extensions/pop3/net.rb +92 -0
  47. data/lib/ronin/network/extensions/smtp.rb +22 -0
  48. data/lib/ronin/network/extensions/smtp/net.rb +110 -0
  49. data/lib/ronin/network/extensions/ssl.rb +22 -0
  50. data/lib/ronin/network/extensions/ssl/net.rb +147 -0
  51. data/lib/ronin/network/extensions/tcp.rb +22 -0
  52. data/lib/ronin/network/extensions/tcp/net.rb +304 -0
  53. data/lib/ronin/network/extensions/telnet.rb +22 -0
  54. data/lib/ronin/network/extensions/telnet/net.rb +156 -0
  55. data/lib/ronin/network/extensions/udp.rb +22 -0
  56. data/lib/ronin/network/extensions/udp/net.rb +226 -0
  57. data/lib/ronin/network/http.rb +24 -0
  58. data/lib/ronin/network/http/exceptions.rb +22 -0
  59. data/lib/ronin/network/http/exceptions/unknown_request.rb +29 -0
  60. data/lib/ronin/network/http/http.rb +290 -0
  61. data/lib/ronin/network/http/proxy.rb +307 -0
  62. data/lib/ronin/network/imap.rb +49 -0
  63. data/lib/ronin/network/network.rb +41 -0
  64. data/lib/ronin/network/pop3.rb +49 -0
  65. data/lib/ronin/network/smtp.rb +24 -0
  66. data/lib/ronin/network/smtp/email.rb +143 -0
  67. data/lib/ronin/network/smtp/smtp.rb +68 -0
  68. data/lib/ronin/network/ssl.rb +47 -0
  69. data/lib/ronin/network/tcp.rb +22 -0
  70. data/lib/ronin/network/telnet.rb +109 -0
  71. data/lib/ronin/network/udp.rb +22 -0
  72. data/lib/ronin/path.rb +132 -0
  73. data/lib/ronin/support.rb +28 -0
  74. data/lib/ronin/support/inflector.rb +40 -0
  75. data/lib/ronin/support/version.rb +27 -0
  76. data/lib/ronin/templates.rb +23 -0
  77. data/lib/ronin/templates/erb.rb +75 -0
  78. data/lib/ronin/templates/template.rb +161 -0
  79. data/ronin-support.gemspec +10 -0
  80. data/spec/extensions/file_spec.rb +24 -0
  81. data/spec/extensions/ip_addr_spec.rb +171 -0
  82. data/spec/extensions/kernel_spec.rb +30 -0
  83. data/spec/extensions/string_spec.rb +177 -0
  84. data/spec/formatting/binary/helpers/hexdumps.rb +16 -0
  85. data/spec/formatting/binary/helpers/hexdumps/ascii.bin +0 -0
  86. data/spec/formatting/binary/helpers/hexdumps/hexdump_decimal_shorts.txt +17 -0
  87. data/spec/formatting/binary/helpers/hexdumps/hexdump_hex_bytes.txt +17 -0
  88. data/spec/formatting/binary/helpers/hexdumps/hexdump_hex_shorts.txt +17 -0
  89. data/spec/formatting/binary/helpers/hexdumps/hexdump_octal_bytes.txt +17 -0
  90. data/spec/formatting/binary/helpers/hexdumps/hexdump_octal_shorts.txt +17 -0
  91. data/spec/formatting/binary/helpers/hexdumps/hexdump_repeated.txt +6 -0
  92. data/spec/formatting/binary/helpers/hexdumps/od_decimal_bytes.txt +17 -0
  93. data/spec/formatting/binary/helpers/hexdumps/od_decimal_ints.txt +17 -0
  94. data/spec/formatting/binary/helpers/hexdumps/od_decimal_quads.txt +17 -0
  95. data/spec/formatting/binary/helpers/hexdumps/od_decimal_shorts.txt +17 -0
  96. data/spec/formatting/binary/helpers/hexdumps/od_hex_bytes.txt +17 -0
  97. data/spec/formatting/binary/helpers/hexdumps/od_hex_ints.txt +17 -0
  98. data/spec/formatting/binary/helpers/hexdumps/od_hex_quads.txt +17 -0
  99. data/spec/formatting/binary/helpers/hexdumps/od_hex_shorts.txt +17 -0
  100. data/spec/formatting/binary/helpers/hexdumps/od_octal_bytes.txt +17 -0
  101. data/spec/formatting/binary/helpers/hexdumps/od_octal_ints.txt +17 -0
  102. data/spec/formatting/binary/helpers/hexdumps/od_octal_quads.txt +17 -0
  103. data/spec/formatting/binary/helpers/hexdumps/od_octal_shorts.txt +17 -0
  104. data/spec/formatting/binary/helpers/hexdumps/od_repeated.txt +6 -0
  105. data/spec/formatting/binary/helpers/hexdumps/repeated.bin +1 -0
  106. data/spec/formatting/binary/integer_spec.rb +140 -0
  107. data/spec/formatting/binary/string_spec.rb +306 -0
  108. data/spec/formatting/digest/string_spec.rb +82 -0
  109. data/spec/formatting/http/integer_spec.rb +42 -0
  110. data/spec/formatting/http/string_spec.rb +76 -0
  111. data/spec/formatting/text/array_spec.rb +105 -0
  112. data/spec/formatting/text/string_spec.rb +180 -0
  113. data/spec/network/http/http_spec.rb +280 -0
  114. data/spec/network/http/proxy_spec.rb +150 -0
  115. data/spec/network/network_spec.rb +8 -0
  116. data/spec/network/ssl_spec.rb +14 -0
  117. data/spec/path_spec.rb +84 -0
  118. data/spec/spec_helper.rb +4 -0
  119. data/spec/support_spec.rb +8 -0
  120. data/spec/templates/classes/example_erb.rb +11 -0
  121. data/spec/templates/classes/example_template.rb +35 -0
  122. data/spec/templates/erb_spec.rb +21 -0
  123. data/spec/templates/helpers/data.rb +9 -0
  124. data/spec/templates/helpers/data/includes/_relative.erb +1 -0
  125. data/spec/templates/helpers/data/templates/example.erb +1 -0
  126. data/spec/templates/template_spec.rb +54 -0
  127. metadata +286 -0
@@ -0,0 +1,307 @@
1
+ #
2
+ # Ronin - A Ruby platform for exploit development and security research.
3
+ #
4
+ # Copyright (c) 2006-2010 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ #
6
+ # This library is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU Lesser General Public
8
+ # License as published by the Free Software Foundation; either
9
+ # version 2.1 of the License, or (at your option) any later version.
10
+ #
11
+ # This library is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
+ # Boston, MA 02110-1301 USA
20
+ #
21
+
22
+ require 'ronin/extensions/ip_addr'
23
+ require 'ronin/network/network'
24
+
25
+ module Ronin
26
+ module Network
27
+ module HTTP
28
+ #
29
+ # The {Proxy} class represents the information needed to connect
30
+ # to a HTTP Proxy. The {Proxy} class can also test the reliability
31
+ # of a HTTP proxy.
32
+ #
33
+ class Proxy < Struct.new(:host, :port, :user, :password)
34
+
35
+ #
36
+ # Creates a new Proxy object that represents a proxy to connect to.
37
+ #
38
+ # @param [Hash] options
39
+ # Additional options for the proxy.
40
+ #
41
+ # @option options [String] :host
42
+ # The host-name of the proxy.
43
+ #
44
+ # @option options [Integer] :port
45
+ # The port that the proxy is running on.
46
+ #
47
+ # @option options [String] :user
48
+ # The user-name to authenticate as.
49
+ #
50
+ # @option options [String] :password
51
+ # The password to authenticate with.
52
+ #
53
+ def initialize(options={})
54
+ super(
55
+ options[:host],
56
+ options[:port],
57
+ options[:user],
58
+ options[:password]
59
+ )
60
+ end
61
+
62
+ #
63
+ # Parses a proxy URL.
64
+ #
65
+ # @param [String, URI::HTTP] proxy
66
+ # The proxy URL in String form.
67
+ #
68
+ # @return [Proxy]
69
+ # The parsed proxy information.
70
+ #
71
+ # @example
72
+ # Proxy.parse('217.31.51.77:443')
73
+ #
74
+ # @example
75
+ # Proxy.parse('joe:lol@127.0.0.1:8080')
76
+ #
77
+ # @example
78
+ # Proxy.parse('http://201.26.192.61:8080')
79
+ #
80
+ def self.parse(proxy)
81
+ proxy = proxy.to_s.gsub(/^http(s)?:\/*/,'')
82
+
83
+ if proxy.include?('@')
84
+ auth, proxy = proxy.split('@',2)
85
+ user, password = auth.split(':')
86
+ else
87
+ user = nil
88
+ password = nil
89
+ end
90
+
91
+ host, port = proxy.split(':',2)
92
+ port = port.to_i if port
93
+
94
+ return self.new(
95
+ :host => host,
96
+ :port => port,
97
+ :user => user,
98
+ :password => password
99
+ )
100
+ end
101
+
102
+ #
103
+ # Creates a new proxy.
104
+ #
105
+ # @param [Proxy, URI::HTTP, Hash, String] proxy
106
+ # The proxy information.
107
+ #
108
+ # @return [Proxy]
109
+ # The new proxy.
110
+ #
111
+ # @raise [ArgumentError]
112
+ # The given proxy information was not a {Proxy}, `URI::HTTP`,
113
+ # `Hash` or {String}.
114
+ #
115
+ def self.create(proxy)
116
+ case proxy
117
+ when Proxy
118
+ proxy
119
+ when URI::HTTP
120
+ self.new(
121
+ :host => proxy.host,
122
+ :port => proxy.port,
123
+ :user => proxy.user,
124
+ :password => proxy.password
125
+ )
126
+ when Hash
127
+ self.new(proxy)
128
+ when String
129
+ self.parse(proxy)
130
+ when nil
131
+ self.new
132
+ else
133
+ raise(ArgumentError,"argument must be either a #{self}, URI::HTTP, Hash or String")
134
+ end
135
+ end
136
+
137
+ #
138
+ # Tests the proxy.
139
+ #
140
+ # @return [Boolean]
141
+ # Specifies if the proxy can proxy requests.
142
+ #
143
+ def valid?
144
+ begin
145
+ Net.http_get_body(
146
+ :url => 'http://www.example.com/',
147
+ :proxy => self
148
+ ).include?('Example Web Page')
149
+ rescue Timeout::Error, StandardError
150
+ return false
151
+ end
152
+ end
153
+
154
+ #
155
+ # Measures the latency of the proxy.
156
+ #
157
+ # @return [Float]
158
+ # The extra number of seconds it takes the proxy to process the
159
+ # request, compared to sending the request directly.
160
+ #
161
+ def latency
162
+ time = lambda { |proxy|
163
+ t1 = Time.now
164
+ Net.http_head(
165
+ :url => 'http://www.example.com/',
166
+ :proxy => proxy
167
+ )
168
+ t2 = Time.now
169
+
170
+ (t2 - t1)
171
+ }
172
+
173
+ begin
174
+ return (time.call(self) - time.call(nil))
175
+ rescue Timeout::Error, StandardError
176
+ return (1.0/0)
177
+ end
178
+ end
179
+
180
+ alias lag latency
181
+
182
+ #
183
+ # The IP address the proxy sends with proxied requests.
184
+ #
185
+ # @return [String]
186
+ # The IP address the proxy uses for our reuqests.
187
+ #
188
+ def proxied_ip
189
+ IPAddr.extract(Net.http_get_body(
190
+ :url => Network::IP_URL,
191
+ :proxy => self
192
+ )).first
193
+ end
194
+
195
+ #
196
+ # Determines whether the proxy forwards our IP address.
197
+ #
198
+ # @return [Boolean]
199
+ # Specifies whether the proxy will forward our IP address.
200
+ #
201
+ def transparent?
202
+ Network.ip == proxied_ip
203
+ end
204
+
205
+ #
206
+ # Determines whether the proxy will hide our IP address.
207
+ #
208
+ # @return [Boolean]
209
+ # Specifies whether the proxy will hide our IP address.
210
+ #
211
+ def anonymous?
212
+ !(transparent?)
213
+ end
214
+
215
+ #
216
+ # Disables the Proxy object.
217
+ #
218
+ def disable!
219
+ self.host = nil
220
+ self.port = nil
221
+ self.user = nil
222
+ self.password = nil
223
+
224
+ return self
225
+ end
226
+
227
+ #
228
+ # Specifies whether the proxy object is usable.
229
+ #
230
+ # @return [Boolean]
231
+ # Specifies whether the proxy object is usable by
232
+ # Net::HTTP::Proxy.
233
+ #
234
+ def enabled?
235
+ !(self.host.nil?)
236
+ end
237
+
238
+ #
239
+ # Builds a HTTP URI from the proxy information.
240
+ #
241
+ # @return [URI::HTTP, nil]
242
+ # The HTTP URI representing the proxy. If the proxy is disabled,
243
+ # then `nil` will be returned.
244
+ #
245
+ def url
246
+ return nil unless enabled?
247
+
248
+ userinfo = if self.user
249
+ if self.password
250
+ "#{self.user}:#{self.password}"
251
+ else
252
+ self.user
253
+ end
254
+ end
255
+
256
+ return URI::HTTP.build(
257
+ :userinfo => userinfo,
258
+ :host => self.host,
259
+ :port => self.port
260
+ )
261
+ end
262
+
263
+ #
264
+ # Converts the proxy object to a String.
265
+ #
266
+ # @return [String]
267
+ # The host-name of the proxy.
268
+ #
269
+ def to_s
270
+ self.host.to_s
271
+ end
272
+
273
+ #
274
+ # Inspects the proxy object.
275
+ #
276
+ # @return [String]
277
+ # The inspection of the proxy object.
278
+ #
279
+ def inspect
280
+ unless self.host
281
+ str = 'disabled'
282
+ else
283
+ str = ''
284
+
285
+ str << self.host.to_s
286
+ str << ":#{self.port}" if self.port
287
+
288
+ if self.user
289
+ auth_str = ''
290
+
291
+ auth_str << self.user.to_s
292
+
293
+ if self.password
294
+ auth_str << ":#{self.password}"
295
+ end
296
+
297
+ str = "#{auth_str}@#{str}"
298
+ end
299
+ end
300
+
301
+ return "#<#{self.class}: #{str}>"
302
+ end
303
+
304
+ end
305
+ end
306
+ end
307
+ end
@@ -0,0 +1,49 @@
1
+ #
2
+ # Ronin - A Ruby platform for exploit development and security research.
3
+ #
4
+ # Copyright (c) 2006-2010 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ #
6
+ # This library is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU Lesser General Public
8
+ # License as published by the Free Software Foundation; either
9
+ # version 2.1 of the License, or (at your option) any later version.
10
+ #
11
+ # This library is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
+ # Boston, MA 02110-1301 USA
20
+ #
21
+
22
+ require 'ronin/network/extensions/imap'
23
+
24
+ module Ronin
25
+ module Network
26
+ module IMAP
27
+ # Default imap port
28
+ DEFAULT_PORT = 143
29
+
30
+ #
31
+ # @return [Integer]
32
+ # The default Ronin IMAP port.
33
+ #
34
+ def IMAP.default_port
35
+ @default_port ||= DEFAULT_PORT
36
+ end
37
+
38
+ #
39
+ # Sets the default Ronin IMAP port.
40
+ #
41
+ # @param [Integer] port
42
+ # The new default Ronin IMAP port.
43
+ #
44
+ def IMAP.default_port=(port)
45
+ @default_port = port
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,41 @@
1
+ #
2
+ # Ronin - A Ruby platform for exploit development and security research.
3
+ #
4
+ # Copyright (c) 2006-2010 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ #
6
+ # This library is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU Lesser General Public
8
+ # License as published by the Free Software Foundation; either
9
+ # version 2.1 of the License, or (at your option) any later version.
10
+ #
11
+ # This library is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
+ # Boston, MA 02110-1301 USA
20
+ #
21
+
22
+ require 'ronin/extensions/ip_addr'
23
+
24
+ require 'uri'
25
+ require 'net/http'
26
+
27
+ module Ronin
28
+ module Network
29
+ IP_URL = URI('http://checkip.dyndns.org/')
30
+
31
+ #
32
+ # Determines the current external IP Address.
33
+ #
34
+ # @return [String]
35
+ # The external IP Address according to {http://checkip.dyndns.org}.
36
+ #
37
+ def Network.ip
38
+ IPAddr.extract(Net::HTTP.get(IP_URL)).first
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,49 @@
1
+ #
2
+ # Ronin - A Ruby platform for exploit development and security research.
3
+ #
4
+ # Copyright (c) 2006-2010 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ #
6
+ # This library is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU Lesser General Public
8
+ # License as published by the Free Software Foundation; either
9
+ # version 2.1 of the License, or (at your option) any later version.
10
+ #
11
+ # This library is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
+ # Boston, MA 02110-1301 USA
20
+ #
21
+
22
+ require 'ronin/network/extensions/pop3'
23
+
24
+ module Ronin
25
+ module Network
26
+ module POP3
27
+ # Default pop3 port
28
+ DEFAULT_PORT = 110
29
+
30
+ #
31
+ # @return [Integer]
32
+ # The default Ronin POP3 port.
33
+ #
34
+ def POP3.default_port
35
+ @default_port ||= DEFAULT_PORT
36
+ end
37
+
38
+ #
39
+ # Sets the default Ronin POP3 port.
40
+ #
41
+ # @param [Integer] port
42
+ # The new default Ronin POP3 port.
43
+ #
44
+ def POP3.default_port=(port)
45
+ @default_port = port
46
+ end
47
+ end
48
+ end
49
+ end