ronin 1.0.0.pre3 → 1.0.0.pre4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (198) hide show
  1. data/COPYING.txt +623 -288
  2. data/ChangeLog.md +21 -2
  3. data/Gemfile +5 -12
  4. data/README.md +6 -7
  5. data/gemspec.yml +3 -3
  6. data/lib/ronin.rb +6 -7
  7. data/lib/ronin/address.rb +18 -7
  8. data/lib/ronin/arch.rb +6 -7
  9. data/lib/ronin/author.rb +6 -7
  10. data/lib/ronin/bootstrap.rb +6 -8
  11. data/lib/ronin/cached_file.rb +6 -7
  12. data/lib/ronin/campaign.rb +10 -11
  13. data/lib/ronin/class_methods.rb +6 -7
  14. data/lib/ronin/config.rb +6 -7
  15. data/lib/ronin/credential.rb +19 -8
  16. data/lib/ronin/database.rb +6 -7
  17. data/lib/ronin/database/database.rb +8 -9
  18. data/lib/ronin/database/exceptions.rb +6 -7
  19. data/lib/ronin/database/exceptions/invalid_config.rb +6 -7
  20. data/lib/ronin/database/exceptions/unknown_repository.rb +6 -7
  21. data/lib/ronin/database/migrations.rb +6 -7
  22. data/lib/ronin/database/migrations/create_addresses_table.rb +6 -7
  23. data/lib/ronin/database/migrations/create_arches_table.rb +6 -7
  24. data/lib/ronin/database/migrations/create_authors_table.rb +6 -7
  25. data/lib/ronin/database/migrations/create_cached_files_table.rb +6 -7
  26. data/lib/ronin/database/migrations/create_campaigns_table.rb +8 -7
  27. data/lib/ronin/database/migrations/create_countries_table.rb +6 -7
  28. data/lib/ronin/database/migrations/create_credentials_table.rb +16 -10
  29. data/lib/ronin/database/migrations/create_email_addresses_table.rb +10 -11
  30. data/lib/ronin/database/migrations/create_host_name_ip_addresses_table.rb +14 -9
  31. data/lib/ronin/database/migrations/create_ip_address_mac_addresses_table.rb +14 -9
  32. data/lib/ronin/database/migrations/create_licenses_table.rb +6 -7
  33. data/lib/ronin/database/migrations/create_open_ports_table.rb +11 -7
  34. data/lib/ronin/database/migrations/create_organizations_table.rb +8 -7
  35. data/lib/ronin/database/migrations/create_os_guesses_table.rb +13 -9
  36. data/lib/ronin/database/migrations/create_os_table.rb +6 -7
  37. data/lib/ronin/database/migrations/create_passwords_table.rb +6 -7
  38. data/lib/ronin/database/migrations/create_ports_table.rb +6 -7
  39. data/lib/ronin/database/migrations/create_proxies_table.rb +6 -7
  40. data/lib/ronin/database/migrations/create_remote_files_table.rb +6 -7
  41. data/lib/ronin/database/migrations/create_repositories_table.rb +6 -7
  42. data/lib/ronin/database/migrations/create_services_table.rb +6 -8
  43. data/lib/ronin/database/migrations/create_softwares_table.rb +6 -7
  44. data/lib/ronin/database/migrations/create_taggings_table.rb +6 -7
  45. data/lib/ronin/database/migrations/create_tags_table.rb +6 -7
  46. data/lib/ronin/database/migrations/create_targets_table.rb +7 -8
  47. data/lib/ronin/database/migrations/create_url_query_params_table.rb +6 -7
  48. data/lib/ronin/database/migrations/create_url_schemes_table.rb +6 -7
  49. data/lib/ronin/database/migrations/create_urls_table.rb +16 -9
  50. data/lib/ronin/database/migrations/create_user_names_table.rb +6 -7
  51. data/lib/ronin/database/migrations/create_vendors_table.rb +6 -7
  52. data/lib/ronin/database/migrations/exceptions.rb +6 -7
  53. data/lib/ronin/database/migrations/exceptions/duplicate_migration.rb +6 -7
  54. data/lib/ronin/database/migrations/exceptions/unknown_migration.rb +6 -7
  55. data/lib/ronin/database/migrations/graph.rb +19 -0
  56. data/lib/ronin/database/migrations/migration.rb +6 -7
  57. data/lib/ronin/database/migrations/migrations.rb +6 -7
  58. data/lib/ronin/email_address.rb +34 -13
  59. data/lib/ronin/engine.rb +6 -7
  60. data/lib/ronin/engine/buildable.rb +6 -7
  61. data/lib/ronin/engine/class_methods.rb +6 -7
  62. data/lib/ronin/engine/deployable.rb +6 -7
  63. data/lib/ronin/engine/engine.rb +6 -7
  64. data/lib/ronin/engine/exceptions.rb +6 -7
  65. data/lib/ronin/engine/exceptions/deploy_failed.rb +6 -7
  66. data/lib/ronin/engine/exceptions/not_built.rb +6 -7
  67. data/lib/ronin/engine/exceptions/verification_failed.rb +6 -7
  68. data/lib/ronin/engine/instance_methods.rb +6 -7
  69. data/lib/ronin/engine/verifiable.rb +6 -7
  70. data/lib/ronin/environment.rb +11 -7
  71. data/lib/ronin/exceptions.rb +6 -7
  72. data/lib/ronin/exceptions/duplicate_repository.rb +6 -7
  73. data/lib/ronin/exceptions/repository_not_found.rb +6 -7
  74. data/lib/ronin/host_name.rb +40 -22
  75. data/lib/ronin/host_name_ip_address.rb +11 -9
  76. data/lib/ronin/installation.rb +6 -7
  77. data/lib/ronin/ip_address.rb +41 -33
  78. data/lib/ronin/ip_address_mac_address.rb +11 -9
  79. data/lib/ronin/license.rb +6 -7
  80. data/lib/ronin/mac_address.rb +8 -13
  81. data/lib/ronin/model.rb +6 -7
  82. data/lib/ronin/model/cacheable.rb +6 -7
  83. data/lib/ronin/model/cacheable/cacheable.rb +6 -7
  84. data/lib/ronin/model/cacheable/class_methods.rb +6 -7
  85. data/lib/ronin/model/class_methods.rb +6 -7
  86. data/lib/ronin/model/has_authors.rb +6 -7
  87. data/lib/ronin/model/has_authors/class_methods.rb +8 -9
  88. data/lib/ronin/model/has_authors/has_authors.rb +6 -7
  89. data/lib/ronin/model/has_description.rb +6 -7
  90. data/lib/ronin/model/has_description/class_methods.rb +7 -8
  91. data/lib/ronin/model/has_description/has_description.rb +6 -7
  92. data/lib/ronin/model/has_license.rb +6 -7
  93. data/lib/ronin/model/has_license/class_methods.rb +7 -8
  94. data/lib/ronin/model/has_license/has_license.rb +6 -7
  95. data/lib/ronin/model/has_name.rb +6 -7
  96. data/lib/ronin/model/has_name/class_methods.rb +7 -12
  97. data/lib/ronin/model/has_name/has_name.rb +6 -7
  98. data/lib/ronin/model/has_title.rb +6 -7
  99. data/lib/ronin/model/has_title/class_methods.rb +7 -8
  100. data/lib/ronin/model/has_title/has_title.rb +6 -7
  101. data/lib/ronin/model/has_unique_name.rb +18 -7
  102. data/lib/ronin/model/has_version.rb +6 -7
  103. data/lib/ronin/model/has_version/class_methods.rb +7 -8
  104. data/lib/ronin/model/has_version/has_version.rb +6 -7
  105. data/lib/ronin/model/model.rb +6 -7
  106. data/lib/ronin/model/types.rb +6 -7
  107. data/lib/ronin/model/types/description.rb +6 -7
  108. data/lib/ronin/network/mixins.rb +11 -13
  109. data/lib/ronin/network/mixins/esmtp.rb +11 -13
  110. data/lib/ronin/network/mixins/http.rb +11 -13
  111. data/lib/ronin/network/mixins/imap.rb +11 -13
  112. data/lib/ronin/network/mixins/pop3.rb +11 -13
  113. data/lib/ronin/network/mixins/smtp.rb +11 -13
  114. data/lib/ronin/network/mixins/tcp.rb +11 -13
  115. data/lib/ronin/network/mixins/telnet.rb +11 -13
  116. data/lib/ronin/network/mixins/udp.rb +11 -13
  117. data/lib/ronin/open_port.rb +11 -11
  118. data/lib/ronin/organization.rb +8 -9
  119. data/lib/ronin/os.rb +6 -7
  120. data/lib/ronin/os_guess.rb +14 -12
  121. data/lib/ronin/password.rb +18 -7
  122. data/lib/ronin/port.rb +18 -7
  123. data/lib/ronin/proxy.rb +6 -7
  124. data/lib/ronin/proxy_credential.rb +6 -7
  125. data/lib/ronin/remote_file.rb +13 -11
  126. data/lib/ronin/repository.rb +8 -12
  127. data/lib/ronin/ronin.rb +6 -7
  128. data/lib/ronin/service.rb +8 -23
  129. data/lib/ronin/service_credential.rb +6 -7
  130. data/lib/ronin/software.rb +6 -7
  131. data/lib/ronin/spec/database.rb +6 -7
  132. data/lib/ronin/spec/ui/output.rb +6 -7
  133. data/lib/ronin/target.rb +11 -9
  134. data/lib/ronin/tcp_port.rb +6 -7
  135. data/lib/ronin/udp_port.rb +6 -7
  136. data/lib/ronin/ui.rb +6 -7
  137. data/lib/ronin/ui/cli.rb +6 -7
  138. data/lib/ronin/ui/cli/cli.rb +6 -7
  139. data/lib/ronin/ui/cli/command.rb +6 -7
  140. data/lib/ronin/ui/cli/commands.rb +6 -7
  141. data/lib/ronin/ui/cli/commands/campaigns.rb +6 -7
  142. data/lib/ronin/ui/cli/commands/console.rb +7 -8
  143. data/lib/ronin/ui/cli/commands/creds.rb +6 -7
  144. data/lib/ronin/ui/cli/commands/database.rb +6 -7
  145. data/lib/ronin/ui/cli/commands/emails.rb +6 -7
  146. data/lib/ronin/ui/cli/commands/exec.rb +6 -7
  147. data/lib/ronin/ui/cli/commands/help.rb +6 -7
  148. data/lib/ronin/ui/cli/commands/hosts.rb +10 -9
  149. data/lib/ronin/ui/cli/commands/ips.rb +10 -9
  150. data/lib/ronin/ui/cli/commands/repos.rb +6 -7
  151. data/lib/ronin/ui/cli/commands/urls.rb +6 -7
  152. data/lib/ronin/ui/cli/engine_command.rb +6 -7
  153. data/lib/ronin/ui/cli/exceptions.rb +6 -7
  154. data/lib/ronin/ui/cli/exceptions/unknown_command.rb +6 -7
  155. data/lib/ronin/ui/cli/model_command.rb +6 -7
  156. data/lib/ronin/ui/console.rb +8 -12
  157. data/lib/ronin/ui/hexdump.rb +6 -7
  158. data/lib/ronin/ui/hexdump/extensions.rb +6 -7
  159. data/lib/ronin/ui/hexdump/extensions/file.rb +6 -7
  160. data/lib/ronin/ui/hexdump/extensions/kernel.rb +6 -7
  161. data/lib/ronin/ui/hexdump/hexdump.rb +13 -7
  162. data/lib/ronin/ui/output.rb +6 -7
  163. data/lib/ronin/ui/output/helpers.rb +6 -7
  164. data/lib/ronin/ui/output/output.rb +6 -7
  165. data/lib/ronin/ui/output/terminal.rb +6 -7
  166. data/lib/ronin/ui/output/terminal/color.rb +6 -7
  167. data/lib/ronin/ui/output/terminal/raw.rb +6 -7
  168. data/lib/ronin/ui/shell.rb +6 -7
  169. data/lib/ronin/url.rb +123 -30
  170. data/lib/ronin/url_query_param.rb +32 -7
  171. data/lib/ronin/url_scheme.rb +6 -7
  172. data/lib/ronin/user_name.rb +6 -7
  173. data/lib/ronin/vendor.rb +6 -7
  174. data/lib/ronin/version.rb +7 -8
  175. data/lib/ronin/web_credential.rb +52 -8
  176. data/spec/arch_spec.rb +7 -0
  177. data/spec/author_spec.rb +1 -1
  178. data/spec/campaign_spec.rb +1 -1
  179. data/spec/credential_spec.rb +33 -0
  180. data/spec/database_spec.rb +23 -0
  181. data/spec/email_address_spec.rb +15 -0
  182. data/spec/engine/buildable_spec.rb +2 -2
  183. data/spec/engine/deployable_spec.rb +2 -2
  184. data/spec/host_name_spec.rb +20 -0
  185. data/spec/ip_address.rb +20 -3
  186. data/spec/model/cacheable_spec.rb +1 -1
  187. data/spec/model/has_description_spec.rb +1 -1
  188. data/spec/os_spec.rb +26 -0
  189. data/spec/password_spec.rb +4 -0
  190. data/spec/port_spec.rb +43 -0
  191. data/spec/repository_spec.rb +10 -10
  192. data/spec/service_spec.rb +18 -0
  193. data/spec/software_spec.rb +15 -5
  194. data/spec/url_query_param_spec.rb +30 -0
  195. data/spec/url_scheme_spec.rb +18 -0
  196. data/spec/url_spec.rb +54 -37
  197. metadata +18 -9
  198. data/lib/ronin/ui/async_console.rb +0 -130
@@ -1,21 +1,20 @@
1
1
  #
2
- # Ronin - A Ruby platform for exploit development and security research.
2
+ # Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
3
3
  #
4
- # Copyright (c) 2006-2010 Hal Brodigan (postmodern.mod3 at gmail.com)
4
+ # This file is part of Ronin.
5
5
  #
6
- # This program is free software; you can redistribute it and/or modify
6
+ # Ronin is free software: you can redistribute it and/or modify
7
7
  # it under the terms of the GNU General Public License as published by
8
- # the Free Software Foundation; either version 2 of the License, or
8
+ # the Free Software Foundation, either version 3 of the License, or
9
9
  # (at your option) any later version.
10
10
  #
11
- # This program is distributed in the hope that it will be useful,
11
+ # Ronin is distributed in the hope that it will be useful,
12
12
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
13
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
14
  # GNU General Public License for more details.
15
15
  #
16
16
  # You should have received a copy of the GNU General Public License
17
- # along with this program; if not, write to the Free Software
18
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
+ # along with Ronin. If not, see <http://www.gnu.org/licenses/>.
19
18
  #
20
19
 
21
20
  require 'ronin/ui/hexdump/hexdump'
@@ -1,21 +1,20 @@
1
1
  #
2
- # Ronin - A Ruby platform for exploit development and security research.
2
+ # Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
3
3
  #
4
- # Copyright (c) 2006-2010 Hal Brodigan (postmodern.mod3 at gmail.com)
4
+ # This file is part of Ronin.
5
5
  #
6
- # This program is free software; you can redistribute it and/or modify
6
+ # Ronin is free software: you can redistribute it and/or modify
7
7
  # it under the terms of the GNU General Public License as published by
8
- # the Free Software Foundation; either version 2 of the License, or
8
+ # the Free Software Foundation, either version 3 of the License, or
9
9
  # (at your option) any later version.
10
10
  #
11
- # This program is distributed in the hope that it will be useful,
11
+ # Ronin is distributed in the hope that it will be useful,
12
12
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
13
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
14
  # GNU General Public License for more details.
15
15
  #
16
16
  # You should have received a copy of the GNU General Public License
17
- # along with this program; if not, write to the Free Software
18
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
+ # along with Ronin. If not, see <http://www.gnu.org/licenses/>.
19
18
  #
20
19
 
21
20
  require 'ronin/ui/hexdump/hexdump'
@@ -1,21 +1,20 @@
1
1
  #
2
- # Ronin - A Ruby platform for exploit development and security research.
2
+ # Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
3
3
  #
4
- # Copyright (c) 2006-2010 Hal Brodigan (postmodern.mod3 at gmail.com)
4
+ # This file is part of Ronin.
5
5
  #
6
- # This program is free software; you can redistribute it and/or modify
6
+ # Ronin is free software: you can redistribute it and/or modify
7
7
  # it under the terms of the GNU General Public License as published by
8
- # the Free Software Foundation; either version 2 of the License, or
8
+ # the Free Software Foundation, either version 3 of the License, or
9
9
  # (at your option) any later version.
10
10
  #
11
- # This program is distributed in the hope that it will be useful,
11
+ # Ronin is distributed in the hope that it will be useful,
12
12
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
13
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
14
  # GNU General Public License for more details.
15
15
  #
16
16
  # You should have received a copy of the GNU General Public License
17
- # along with this program; if not, write to the Free Software
18
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
+ # along with Ronin. If not, see <http://www.gnu.org/licenses/>.
19
18
  #
20
19
 
21
20
  module Ronin
@@ -32,7 +31,14 @@ module Ronin
32
31
  #
33
32
  # @return [nil]
34
33
  #
34
+ # @raise [ArgumentError]
35
+ # The given object does not respond to the `#each_byte` method.
36
+ #
35
37
  def Hexdump.dump(object,output=STDOUT)
38
+ unless object.respond_to?(:each_byte)
39
+ raise(ArgumentError,"argument must respond to #each_byte")
40
+ end
41
+
36
42
  index = 0
37
43
  offset = 0
38
44
  hex_segment = nil
@@ -1,21 +1,20 @@
1
1
  #
2
- # Ronin - A Ruby platform for exploit development and security research.
2
+ # Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
3
3
  #
4
- # Copyright (c) 2006-2010 Hal Brodigan (postmodern.mod3 at gmail.com)
4
+ # This file is part of Ronin.
5
5
  #
6
- # This program is free software; you can redistribute it and/or modify
6
+ # Ronin is free software: you can redistribute it and/or modify
7
7
  # it under the terms of the GNU General Public License as published by
8
- # the Free Software Foundation; either version 2 of the License, or
8
+ # the Free Software Foundation, either version 3 of the License, or
9
9
  # (at your option) any later version.
10
10
  #
11
- # This program is distributed in the hope that it will be useful,
11
+ # Ronin is distributed in the hope that it will be useful,
12
12
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
13
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
14
  # GNU General Public License for more details.
15
15
  #
16
16
  # You should have received a copy of the GNU General Public License
17
- # along with this program; if not, write to the Free Software
18
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
+ # along with Ronin. If not, see <http://www.gnu.org/licenses/>.
19
18
  #
20
19
 
21
20
  require 'ronin/ui/output/output'
@@ -1,21 +1,20 @@
1
1
  #
2
- # Ronin - A Ruby platform for exploit development and security research.
2
+ # Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
3
3
  #
4
- # Copyright (c) 2006-2010 Hal Brodigan (postmodern.mod3 at gmail.com)
4
+ # This file is part of Ronin.
5
5
  #
6
- # This program is free software; you can redistribute it and/or modify
6
+ # Ronin is free software: you can redistribute it and/or modify
7
7
  # it under the terms of the GNU General Public License as published by
8
- # the Free Software Foundation; either version 2 of the License, or
8
+ # the Free Software Foundation, either version 3 of the License, or
9
9
  # (at your option) any later version.
10
10
  #
11
- # This program is distributed in the hope that it will be useful,
11
+ # Ronin is distributed in the hope that it will be useful,
12
12
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
13
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
14
  # GNU General Public License for more details.
15
15
  #
16
16
  # You should have received a copy of the GNU General Public License
17
- # along with this program; if not, write to the Free Software
18
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
+ # along with Ronin. If not, see <http://www.gnu.org/licenses/>.
19
18
  #
20
19
 
21
20
  require 'ronin/ui/output/output'
@@ -1,21 +1,20 @@
1
1
  #
2
- # Ronin - A Ruby platform for exploit development and security research.
2
+ # Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
3
3
  #
4
- # Copyright (c) 2006-2010 Hal Brodigan (postmodern.mod3 at gmail.com)
4
+ # This file is part of Ronin.
5
5
  #
6
- # This program is free software; you can redistribute it and/or modify
6
+ # Ronin is free software: you can redistribute it and/or modify
7
7
  # it under the terms of the GNU General Public License as published by
8
- # the Free Software Foundation; either version 2 of the License, or
8
+ # the Free Software Foundation, either version 3 of the License, or
9
9
  # (at your option) any later version.
10
10
  #
11
- # This program is distributed in the hope that it will be useful,
11
+ # Ronin is distributed in the hope that it will be useful,
12
12
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
13
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
14
  # GNU General Public License for more details.
15
15
  #
16
16
  # You should have received a copy of the GNU General Public License
17
- # along with this program; if not, write to the Free Software
18
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
+ # along with Ronin. If not, see <http://www.gnu.org/licenses/>.
19
18
  #
20
19
 
21
20
  require 'ronin/ui/output/terminal/color'
@@ -1,21 +1,20 @@
1
1
  #
2
- # Ronin - A Ruby platform for exploit development and security research.
2
+ # Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
3
3
  #
4
- # Copyright (c) 2006-2010 Hal Brodigan (postmodern.mod3 at gmail.com)
4
+ # This file is part of Ronin.
5
5
  #
6
- # This program is free software; you can redistribute it and/or modify
6
+ # Ronin is free software: you can redistribute it and/or modify
7
7
  # it under the terms of the GNU General Public License as published by
8
- # the Free Software Foundation; either version 2 of the License, or
8
+ # the Free Software Foundation, either version 3 of the License, or
9
9
  # (at your option) any later version.
10
10
  #
11
- # This program is distributed in the hope that it will be useful,
11
+ # Ronin is distributed in the hope that it will be useful,
12
12
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
13
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
14
  # GNU General Public License for more details.
15
15
  #
16
16
  # You should have received a copy of the GNU General Public License
17
- # along with this program; if not, write to the Free Software
18
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
+ # along with Ronin. If not, see <http://www.gnu.org/licenses/>.
19
18
  #
20
19
 
21
20
  require 'ronin/ui/output/terminal/raw'
@@ -1,21 +1,20 @@
1
1
  #
2
- # Ronin - A Ruby platform for exploit development and security research.
2
+ # Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
3
3
  #
4
- # Copyright (c) 2006-2010 Hal Brodigan (postmodern.mod3 at gmail.com)
4
+ # This file is part of Ronin.
5
5
  #
6
- # This program is free software; you can redistribute it and/or modify
6
+ # Ronin is free software: you can redistribute it and/or modify
7
7
  # it under the terms of the GNU General Public License as published by
8
- # the Free Software Foundation; either version 2 of the License, or
8
+ # the Free Software Foundation, either version 3 of the License, or
9
9
  # (at your option) any later version.
10
10
  #
11
- # This program is distributed in the hope that it will be useful,
11
+ # Ronin is distributed in the hope that it will be useful,
12
12
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
13
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
14
  # GNU General Public License for more details.
15
15
  #
16
16
  # You should have received a copy of the GNU General Public License
17
- # along with this program; if not, write to the Free Software
18
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
+ # along with Ronin. If not, see <http://www.gnu.org/licenses/>.
19
18
  #
20
19
 
21
20
  module Ronin
@@ -1,21 +1,20 @@
1
1
  #
2
- # Ronin - A Ruby platform for exploit development and security research.
2
+ # Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
3
3
  #
4
- # Copyright (c) 2006-2010 Hal Brodigan (postmodern.mod3 at gmail.com)
4
+ # This file is part of Ronin.
5
5
  #
6
- # This program is free software; you can redistribute it and/or modify
6
+ # Ronin is free software: you can redistribute it and/or modify
7
7
  # it under the terms of the GNU General Public License as published by
8
- # the Free Software Foundation; either version 2 of the License, or
8
+ # the Free Software Foundation, either version 3 of the License, or
9
9
  # (at your option) any later version.
10
10
  #
11
- # This program is distributed in the hope that it will be useful,
11
+ # Ronin is distributed in the hope that it will be useful,
12
12
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
13
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
14
  # GNU General Public License for more details.
15
15
  #
16
16
  # You should have received a copy of the GNU General Public License
17
- # along with this program; if not, write to the Free Software
18
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
+ # along with Ronin. If not, see <http://www.gnu.org/licenses/>.
19
18
  #
20
19
 
21
20
  module Ronin
@@ -1,21 +1,20 @@
1
1
  #
2
- # Ronin - A Ruby platform for exploit development and security research.
2
+ # Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
3
3
  #
4
- # Copyright (c) 2006-2010 Hal Brodigan (postmodern.mod3 at gmail.com)
4
+ # This file is part of Ronin.
5
5
  #
6
- # This program is free software; you can redistribute it and/or modify
6
+ # Ronin is free software: you can redistribute it and/or modify
7
7
  # it under the terms of the GNU General Public License as published by
8
- # the Free Software Foundation; either version 2 of the License, or
8
+ # the Free Software Foundation, either version 3 of the License, or
9
9
  # (at your option) any later version.
10
10
  #
11
- # This program is distributed in the hope that it will be useful,
11
+ # Ronin is distributed in the hope that it will be useful,
12
12
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
13
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
14
  # GNU General Public License for more details.
15
15
  #
16
16
  # You should have received a copy of the GNU General Public License
17
- # along with this program; if not, write to the Free Software
18
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
+ # along with Ronin. If not, see <http://www.gnu.org/licenses/>.
19
18
  #
20
19
 
21
20
  require 'ronin/ui/output/helpers'
data/lib/ronin/url.rb CHANGED
@@ -1,21 +1,20 @@
1
1
  #
2
- # Ronin - A Ruby platform for exploit development and security research.
2
+ # Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
3
3
  #
4
- # Copyright (c) 2009-2010 Hal Brodigan (postmodern.mod3 at gmail.com)
4
+ # This file is part of Ronin.
5
5
  #
6
- # This program is free software; you can redistribute it and/or modify
6
+ # Ronin is free software: you can redistribute it and/or modify
7
7
  # it under the terms of the GNU General Public License as published by
8
- # the Free Software Foundation; either version 2 of the License, or
8
+ # the Free Software Foundation, either version 3 of the License, or
9
9
  # (at your option) any later version.
10
10
  #
11
- # This program is distributed in the hope that it will be useful,
11
+ # Ronin is distributed in the hope that it will be useful,
12
12
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
13
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
14
  # GNU General Public License for more details.
15
15
  #
16
16
  # You should have received a copy of the GNU General Public License
17
- # along with this program; if not, write to the Free Software
18
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
+ # along with Ronin. If not, see <http://www.gnu.org/licenses/>.
19
18
  #
20
19
 
21
20
  require 'ronin/url_scheme'
@@ -53,10 +52,10 @@ module Ronin
53
52
  belongs_to :host_name
54
53
 
55
54
  # Port of the URL
56
- belongs_to :port, :model => 'TCPPort'
55
+ belongs_to :port, :model => 'TCPPort', :required => false
57
56
 
58
57
  # Path of the URL
59
- property :path, String, :default => ''
58
+ property :path, String
60
59
 
61
60
  # The fragment of the URL
62
61
  property :fragment, String
@@ -85,7 +84,7 @@ module Ronin
85
84
  # @since 1.0.0
86
85
  #
87
86
  def self.http
88
- all('scheme.name' => 'http')
87
+ all(:scheme => {:name => 'http'})
89
88
  end
90
89
 
91
90
  #
@@ -97,7 +96,7 @@ module Ronin
97
96
  # @since 1.0.0
98
97
  #
99
98
  def self.https
100
- all('scheme.name' => 'https')
99
+ all(:scheme => {:name => 'https'})
101
100
  end
102
101
 
103
102
  #
@@ -112,7 +111,7 @@ module Ronin
112
111
  # @since 1.0.0
113
112
  #
114
113
  def self.hosts(names)
115
- all('host.address' => names)
114
+ all(:host => {:address => names})
116
115
  end
117
116
 
118
117
  #
@@ -127,7 +126,7 @@ module Ronin
127
126
  # @since 1.0.0
128
127
  #
129
128
  def self.ports(numbers)
130
- all('port.number' => numbers)
129
+ all(:port => {:number => numbers})
131
130
  end
132
131
 
133
132
  #
@@ -172,7 +171,7 @@ module Ronin
172
171
  # @since 1.0.0
173
172
  #
174
173
  def self.query_param(name)
175
- all('query_params.name' => name)
174
+ all(:query_params => {:name => name})
176
175
  end
177
176
 
178
177
  #
@@ -187,7 +186,52 @@ module Ronin
187
186
  # @since 1.0.0
188
187
  #
189
188
  def self.query_value(value)
190
- all('query_params.value' => value)
189
+ all(:query_params => {:value => value})
190
+ end
191
+
192
+ #
193
+ # Searches for a URL.
194
+ #
195
+ # @param [URI::HTTP, String] url
196
+ # The URL to search for.
197
+ #
198
+ # @return [URL, nil]
199
+ # The matching URL.
200
+ #
201
+ # @since 1.0.0
202
+ #
203
+ def self.[](url)
204
+ return super(url) if url.kind_of?(Integer)
205
+
206
+ # optionally parse the URL
207
+ url = ::URI.parse(url) unless url.kind_of?(::URI)
208
+
209
+ port = if url.port
210
+ {:number => url.port}
211
+ end
212
+
213
+ path = normalized_path(url)
214
+ fragment = url.fragment
215
+
216
+ # create the initial query
217
+ query = all(
218
+ :scheme => {:name => url.scheme},
219
+ :host_name => {:address => url.host},
220
+ :port => port,
221
+ :path => path,
222
+ :fragment => fragment
223
+ )
224
+
225
+ if url.query
226
+ # add the query params to the query
227
+ URI::QueryParams.parse(url.query).each do |name,value|
228
+ query = query.all(
229
+ :query_params => {:name => name, :value => value}
230
+ )
231
+ end
232
+ end
233
+
234
+ return query.first
191
235
  end
192
236
 
193
237
  #
@@ -201,22 +245,38 @@ module Ronin
201
245
  #
202
246
  # @since 1.0.0
203
247
  #
204
- def URL.from(uri)
205
- new_url = URL.new(
206
- :scheme => URLScheme.first_or_new(:name => uri.scheme),
207
- :host_name => HostName.first_or_new(:address => uri.host),
208
- :port => TCPPort.first_or_new(:number => uri.port),
209
- :path => uri.path,
210
- :fragment => uri.fragment
211
- )
248
+ def self.from(uri)
249
+ # find or create the URL scheme, host_name and port
250
+ scheme = self.scheme.model.first_or_new(:name => uri.scheme)
251
+ host_name = self.host_name.model.first_or_new(:address => uri.host)
252
+ port = if uri.port
253
+ self.port.model.first_or_new(:number => uri.port)
254
+ end
212
255
 
256
+ path = normalized_path(uri)
257
+ fragment = uri.fragment
258
+
259
+ query_params = []
260
+
213
261
  if uri.respond_to?(:query_params)
262
+ # find or create the URL query params
214
263
  uri.query_params.each do |name,value|
215
- new_url.query_params.new(:name => name, :value => value)
264
+ query_params << self.query_params.model.first_or_new(
265
+ :name => name,
266
+ :value => value
267
+ )
216
268
  end
217
269
  end
218
270
 
219
- return new_url
271
+ # find or create the URL
272
+ return first_or_new(
273
+ :scheme => scheme,
274
+ :host_name => host_name,
275
+ :port => port,
276
+ :path => path,
277
+ :fragment => fragment,
278
+ :query_params => query_params
279
+ )
220
280
  end
221
281
 
222
282
  #
@@ -232,8 +292,8 @@ module Ronin
232
292
  #
233
293
  # @since 1.0.0
234
294
  #
235
- def URL.parse(url)
236
- URL.from(::URI.parse(url))
295
+ def self.parse(url)
296
+ from(::URI.parse(url))
237
297
  end
238
298
 
239
299
  #
@@ -251,13 +311,13 @@ module Ronin
251
311
  #
252
312
  # The port number used by the URL.
253
313
  #
254
- # @return [Integer]
314
+ # @return [Integer, nil]
255
315
  # The port number.
256
316
  #
257
317
  # @since 1.0.0
258
318
  #
259
319
  def port_number
260
- self.port.number
320
+ self.port.number if self.port
261
321
  end
262
322
 
263
323
  #
@@ -308,6 +368,7 @@ module Ronin
308
368
  # @since 1.0.0
309
369
  #
310
370
  def to_uri
371
+ # map the URL scheme to a URI class
311
372
  url_class = (SCHEMES[self.scheme.name] || ::URI::Generic)
312
373
 
313
374
  host = if self.host_name
@@ -317,12 +378,17 @@ module Ronin
317
378
  self.port.number
318
379
  end
319
380
 
381
+ query = unless self.query_params.empty?
382
+ self.query_string
383
+ end
384
+
385
+ # build the URI
320
386
  return url_class.build(
321
387
  :scheme => self.scheme.name,
322
388
  :host => host,
323
389
  :port => port,
324
390
  :path => self.path,
325
- :query => self.query_string,
391
+ :query => query,
326
392
  :fragment => self.fragment
327
393
  )
328
394
  end
@@ -339,5 +405,32 @@ module Ronin
339
405
  self.to_uri.to_s
340
406
  end
341
407
 
408
+ protected
409
+
410
+ #
411
+ # Normalizes the path of a URI.
412
+ #
413
+ # @param [URI] uri
414
+ # The URI containing the path.
415
+ #
416
+ # @return [String, nil]
417
+ # The normalized path.
418
+ #
419
+ # @since 1.0.0
420
+ #
421
+ def self.normalized_path(uri)
422
+ case uri
423
+ when URI::HTTP
424
+ # map empty HTTP paths to '/'
425
+ unless uri.path.empty?
426
+ uri.path
427
+ else
428
+ '/'
429
+ end
430
+ else
431
+ uri.path
432
+ end
433
+ end
434
+
342
435
  end
343
436
  end