arachni 0.4.0.4 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (688) hide show
  1. data/ACKNOWLEDGMENTS.md +2 -2
  2. data/AUTHORS.md +1 -4
  3. data/CHANGELOG.md +102 -3
  4. data/CONTRIBUTORS.md +4 -1
  5. data/EXPLOITATION.md +6 -6
  6. data/Gemfile +3 -0
  7. data/HACKING.md +29 -10
  8. data/LICENSE.md +176 -339
  9. data/NOTICE +12 -0
  10. data/README.md +160 -119
  11. data/Rakefile +83 -45
  12. data/arachni.gemspec +124 -0
  13. data/bin/arachni +14 -8
  14. data/bin/arachni_console +52 -0
  15. data/bin/arachni_rpc +14 -8
  16. data/bin/arachni_rpcd +15 -9
  17. data/bin/arachni_rpcd_monitor +14 -8
  18. data/bin/arachni_script +41 -0
  19. data/bin/arachni_web +18 -19
  20. data/bin/arachni_web_autostart +17 -18
  21. data/external/metasploit/plugins/arachni.rb +7 -9
  22. data/external/metasploit/{LICENSE → plugins/arachni/LICENSE} +0 -0
  23. data/external/metasploit/{modules → plugins/arachni/modules}/exploits/unix/webapp/arachni_exec.rb +1 -1
  24. data/external/metasploit/{modules → plugins/arachni/modules}/exploits/unix/webapp/arachni_path_traversal.rb +2 -2
  25. data/external/metasploit/{modules → plugins/arachni/modules}/exploits/unix/webapp/arachni_php_eval.rb +1 -1
  26. data/external/metasploit/{modules → plugins/arachni/modules}/exploits/unix/webapp/arachni_php_include.rb +1 -1
  27. data/external/metasploit/{modules → plugins/arachni/modules}/exploits/unix/webapp/arachni_sqlmap.rb +2 -2
  28. data/external/scripts/LICENSE.tpl +174 -0
  29. data/external/scripts/README.md +95 -0
  30. data/external/scripts/README.tpl +30 -0
  31. data/external/scripts/build.sh +631 -0
  32. data/external/scripts/build_all.sh +29 -0
  33. data/external/scripts/build_and_package.sh +100 -0
  34. data/external/scripts/cross_build_and_package.sh +20 -0
  35. data/external/scripts/installer.sh.tpl +166 -0
  36. data/external/scripts/lib/readlink_f.sh +40 -0
  37. data/external/scripts/package.sh +134 -0
  38. data/external/scripts/push_nightlies.sh +125 -0
  39. data/extras/placeholder +0 -0
  40. data/gfx/README.md +18 -0
  41. data/gfx/compiled/banner.png +0 -0
  42. data/gfx/compiled/favicon.ico +0 -0
  43. data/gfx/compiled/icon.png +0 -0
  44. data/gfx/compiled/logo.png +0 -0
  45. data/gfx/compiled/spider.png +0 -0
  46. data/gfx/font/Beneath_the_Surface.ttf +0 -0
  47. data/gfx/font/bts_readme.txt +14 -0
  48. data/gfx/source/banner.svg +999 -0
  49. data/gfx/source/icon.svg +627 -0
  50. data/gfx/source/logo.svg +672 -0
  51. data/gfx/source/spider.png +0 -0
  52. data/gfx/source/spider.svg +277 -0
  53. data/lib/arachni.rb +30 -5
  54. data/lib/arachni/audit_store.rb +111 -143
  55. data/lib/arachni/banner.rb +37 -0
  56. data/lib/arachni/bloom_filter.rb +74 -0
  57. data/lib/arachni/cache.rb +21 -0
  58. data/lib/arachni/cache/base.rb +170 -0
  59. data/lib/arachni/cache/least_cost_replacement.rb +89 -0
  60. data/lib/arachni/cache/least_recently_used.rb +73 -0
  61. data/lib/arachni/cache/random_replacement.rb +52 -0
  62. data/lib/arachni/component/manager.rb +391 -0
  63. data/lib/arachni/component/options.rb +38 -0
  64. data/lib/arachni/component/options/address.rb +41 -0
  65. data/lib/arachni/component/options/base.rb +126 -0
  66. data/lib/arachni/component/options/bool.rb +55 -0
  67. data/lib/arachni/component/options/enum.rb +51 -0
  68. data/lib/arachni/component/options/float.rb +45 -0
  69. data/lib/arachni/component/options/int.rb +44 -0
  70. data/lib/arachni/component/options/path.rb +36 -0
  71. data/lib/arachni/component/options/port.rb +37 -0
  72. data/lib/arachni/component/options/string.rb +44 -0
  73. data/lib/arachni/component/options/url.rb +42 -0
  74. data/lib/arachni/crypto/rsa_aes_cbc.rb +14 -8
  75. data/lib/arachni/database.rb +4 -4
  76. data/lib/arachni/database/base.rb +14 -8
  77. data/lib/arachni/database/hash.rb +21 -12
  78. data/lib/arachni/database/queue.rb +15 -9
  79. data/lib/arachni/element/base.rb +147 -0
  80. data/lib/arachni/element/capabilities/auditable.rb +623 -0
  81. data/lib/arachni/element/capabilities/auditable/rdiff.rb +243 -0
  82. data/lib/arachni/element/capabilities/auditable/taint.rb +141 -0
  83. data/lib/arachni/element/capabilities/auditable/timeout.rb +330 -0
  84. data/lib/arachni/element/capabilities/body.rb +19 -0
  85. data/lib/arachni/element/capabilities/mutable.rb +286 -0
  86. data/lib/arachni/element/capabilities/path.rb +19 -0
  87. data/lib/arachni/element/capabilities/refreshable.rb +48 -0
  88. data/lib/arachni/element/capabilities/server.rb +19 -0
  89. data/lib/arachni/element/cookie.rb +1043 -0
  90. data/lib/arachni/element/form.rb +1364 -0
  91. data/lib/arachni/element/header.rb +87 -0
  92. data/lib/arachni/element/link.rb +227 -0
  93. data/lib/arachni/exceptions.rb +12 -34
  94. data/lib/arachni/framework.rb +345 -436
  95. data/lib/arachni/http.rb +445 -409
  96. data/lib/arachni/http/cookie_jar.rb +163 -0
  97. data/lib/arachni/issue.rb +102 -65
  98. data/lib/arachni/mixins/observable.rb +25 -28
  99. data/lib/arachni/mixins/progress_bar.rb +11 -5
  100. data/lib/arachni/mixins/terminal.rb +17 -11
  101. data/lib/arachni/module.rb +4 -4
  102. data/lib/arachni/module/auditor.rb +270 -793
  103. data/lib/arachni/module/base.rb +107 -101
  104. data/lib/arachni/module/element_db.rb +54 -59
  105. data/lib/arachni/module/key_filler.rb +35 -35
  106. data/lib/arachni/module/manager.rb +178 -68
  107. data/lib/arachni/module/output.rb +25 -30
  108. data/lib/arachni/module/trainer.rb +85 -156
  109. data/lib/arachni/module/utilities.rb +29 -138
  110. data/lib/arachni/options.rb +496 -162
  111. data/lib/arachni/page.rb +186 -0
  112. data/lib/arachni/parser.rb +392 -2
  113. data/lib/arachni/plugin.rb +4 -4
  114. data/lib/arachni/plugin/base.rb +113 -44
  115. data/lib/arachni/plugin/manager.rb +120 -54
  116. data/lib/arachni/report.rb +4 -4
  117. data/lib/arachni/report/base.rb +59 -44
  118. data/lib/arachni/report/manager.rb +33 -32
  119. data/lib/arachni/rpc/client.rb +2 -0
  120. data/lib/arachni/rpc/client/base.rb +31 -18
  121. data/lib/arachni/rpc/client/dispatcher.rb +24 -11
  122. data/lib/arachni/rpc/client/instance.rb +24 -11
  123. data/lib/arachni/rpc/server/base.rb +12 -9
  124. data/lib/arachni/rpc/server/dispatcher.rb +161 -164
  125. data/lib/arachni/rpc/server/dispatcher/handler.rb +164 -0
  126. data/lib/arachni/rpc/server/{node.rb → dispatcher/node.rb} +86 -104
  127. data/lib/arachni/rpc/server/distributor.rb +432 -0
  128. data/lib/arachni/rpc/server/framework.rb +266 -758
  129. data/lib/arachni/rpc/server/instance.rb +38 -53
  130. data/lib/arachni/rpc/server/module/manager.rb +17 -20
  131. data/lib/arachni/rpc/server/output.rb +73 -179
  132. data/lib/arachni/rpc/server/plugin/manager.rb +58 -24
  133. data/lib/arachni/ruby.rb +6 -4
  134. data/lib/arachni/ruby/array.rb +30 -9
  135. data/lib/arachni/ruby/enumerable.rb +29 -0
  136. data/lib/arachni/ruby/object.rb +47 -12
  137. data/lib/arachni/ruby/string.rb +69 -24
  138. data/lib/arachni/ruby/webrick.rb +31 -0
  139. data/lib/arachni/session.rb +279 -0
  140. data/lib/arachni/spider.rb +295 -149
  141. data/lib/arachni/typhoeus/hydra.rb +18 -4
  142. data/lib/arachni/typhoeus/request.rb +52 -65
  143. data/lib/arachni/typhoeus/response.rb +62 -22
  144. data/lib/arachni/typhoeus/utils.rb +25 -0
  145. data/lib/arachni/ui/cli/cli.rb +331 -298
  146. data/lib/arachni/ui/cli/output.rb +105 -77
  147. data/lib/arachni/ui/foo/output.rb +116 -0
  148. data/lib/arachni/ui/rpc/dispatcher_monitor.rb +5 -12
  149. data/lib/arachni/ui/rpc/rpc.rb +43 -48
  150. data/lib/arachni/ui/web/addon_manager.rb +18 -13
  151. data/lib/arachni/ui/web/addons/sample.rb +14 -8
  152. data/lib/arachni/ui/web/addons/scheduler.rb +14 -8
  153. data/lib/arachni/ui/web/addons/scheduler/views/index.erb +1 -1
  154. data/lib/arachni/ui/web/addons/scheduler/views/options.erb +0 -3
  155. data/lib/arachni/ui/web/dispatcher_manager.rb +14 -9
  156. data/lib/arachni/ui/web/instance_manager.rb +14 -8
  157. data/lib/arachni/ui/web/log.rb +14 -10
  158. data/lib/arachni/ui/web/output_stream.rb +11 -5
  159. data/lib/arachni/ui/web/report_manager.rb +14 -10
  160. data/lib/arachni/ui/web/scheduler.rb +16 -11
  161. data/lib/arachni/ui/web/server.rb +62 -56
  162. data/lib/arachni/ui/web/server/public/style.css +1 -1
  163. data/lib/arachni/ui/web/server/views/addon.erb +1 -1
  164. data/lib/arachni/ui/web/server/views/dispatchers.erb +3 -3
  165. data/lib/arachni/ui/web/server/views/dispatchers_edit.erb +2 -2
  166. data/lib/arachni/ui/web/server/views/error.erb +1 -1
  167. data/lib/arachni/ui/web/server/views/home.erb +2 -2
  168. data/lib/arachni/ui/web/server/views/instance.erb +6 -6
  169. data/lib/arachni/ui/web/server/views/layout.erb +4 -4
  170. data/lib/arachni/ui/web/server/views/settings.erb +13 -8
  171. data/lib/arachni/ui/web/server/views/welcome.erb +1 -1
  172. data/lib/arachni/ui/web/utilities.rb +24 -35
  173. data/lib/arachni/uri.rb +619 -0
  174. data/lib/arachni/utilities.rb +316 -0
  175. data/lib/arachni/version.rb +12 -6
  176. data/lib/version +1 -0
  177. data/modules/audit/code_injection.rb +64 -81
  178. data/modules/audit/code_injection_timing.rb +57 -75
  179. data/modules/audit/csrf.rb +87 -185
  180. data/modules/audit/ldapi.rb +42 -67
  181. data/modules/audit/os_cmd_injection.rb +53 -71
  182. data/modules/audit/os_cmd_injection/payloads.txt +1 -1
  183. data/modules/audit/os_cmd_injection_timing.rb +54 -75
  184. data/modules/audit/os_cmd_injection_timing/payloads.txt +1 -3
  185. data/modules/audit/path_traversal.rb +84 -110
  186. data/modules/audit/response_splitting.rb +41 -53
  187. data/modules/audit/rfi.rb +68 -76
  188. data/modules/audit/session_fixation.rb +86 -0
  189. data/modules/audit/sqli.rb +51 -77
  190. data/modules/audit/sqli/regexp_ids.txt +5 -19
  191. data/modules/audit/sqli/regexp_ignore.txt +2 -0
  192. data/modules/audit/sqli_blind_rdiff.rb +51 -62
  193. data/modules/audit/sqli_blind_timing.rb +53 -73
  194. data/modules/audit/trainer.rb +21 -58
  195. data/modules/audit/unvalidated_redirect.rb +41 -51
  196. data/modules/audit/xpath.rb +38 -69
  197. data/modules/audit/xpath/errors.txt +2 -3
  198. data/modules/audit/xss.rb +65 -69
  199. data/modules/audit/xss_event.rb +50 -69
  200. data/modules/audit/xss_path.rb +63 -89
  201. data/modules/audit/xss_script_tag.rb +53 -66
  202. data/modules/audit/xss_tag.rb +46 -65
  203. data/modules/audit/xss_uri.rb +22 -24
  204. data/modules/recon/allowed_methods.rb +46 -62
  205. data/modules/recon/backdoors.rb +39 -66
  206. data/modules/recon/backup_files.rb +49 -79
  207. data/modules/recon/common_directories.rb +39 -63
  208. data/modules/recon/common_directories/directories.txt +0 -5
  209. data/modules/recon/common_files.rb +34 -63
  210. data/modules/recon/directory_listing.rb +66 -116
  211. data/modules/recon/grep/captcha.rb +34 -41
  212. data/modules/recon/grep/credit_card.rb +57 -68
  213. data/modules/recon/grep/cvs_svn_users.rb +40 -50
  214. data/modules/recon/grep/emails.rb +34 -41
  215. data/modules/recon/grep/html_objects.rb +30 -33
  216. data/modules/recon/grep/http_only_cookies.rb +57 -0
  217. data/modules/recon/grep/insecure_cookies.rb +55 -0
  218. data/modules/recon/grep/mixed_resource.rb +93 -0
  219. data/modules/recon/grep/private_ip.rb +34 -32
  220. data/modules/recon/grep/ssn.rb +33 -31
  221. data/modules/recon/grep/unencrypted_password_forms.rb +84 -0
  222. data/modules/recon/htaccess_limit.rb +38 -54
  223. data/modules/recon/http_put.rb +48 -62
  224. data/modules/recon/interesting_responses.rb +77 -79
  225. data/modules/recon/webdav.rb +53 -79
  226. data/modules/recon/xst.rb +44 -63
  227. data/modules/test2.rb +46 -0
  228. data/path_extractors/anchors.rb +17 -15
  229. data/path_extractors/forms.rb +17 -15
  230. data/path_extractors/frames.rb +17 -18
  231. data/path_extractors/generic.rb +52 -55
  232. data/path_extractors/links.rb +16 -14
  233. data/path_extractors/meta_refresh.rb +33 -18
  234. data/path_extractors/scripts.rb +17 -15
  235. data/plugins/autologin.rb +60 -85
  236. data/plugins/beep_notify.rb +25 -27
  237. data/plugins/cookie_collector.rb +28 -45
  238. data/plugins/defaults/autothrottle.rb +43 -51
  239. data/plugins/defaults/content_types.rb +63 -52
  240. data/plugins/defaults/healthmap.rb +45 -62
  241. data/plugins/defaults/{metamodules → meta}/remedies/discovery.rb +34 -69
  242. data/plugins/defaults/meta/remedies/manual_verification.rb +61 -0
  243. data/plugins/defaults/meta/remedies/timing_attacks.rb +108 -0
  244. data/plugins/defaults/meta/uniformity.rb +81 -0
  245. data/plugins/defaults/profiler.rb +68 -115
  246. data/plugins/defaults/resolver.rb +33 -28
  247. data/plugins/email_notify.rb +60 -62
  248. data/plugins/form_dicattack.rb +67 -121
  249. data/plugins/http_dicattack.rb +51 -65
  250. data/plugins/libnotify.rb +37 -41
  251. data/plugins/proxy.rb +407 -152
  252. data/plugins/proxy/panel/403_forbidden.html.erb +11 -0
  253. data/plugins/proxy/panel/404_not_found.html.erb +6 -0
  254. data/plugins/proxy/panel/css/bootstrap.min.css +9 -0
  255. data/plugins/proxy/panel/css/panel.css +30 -0
  256. data/plugins/proxy/panel/help.html.erb +66 -0
  257. data/plugins/proxy/panel/img/glyphicons-halflings-white.png +0 -0
  258. data/plugins/proxy/panel/img/glyphicons-halflings.png +0 -0
  259. data/plugins/proxy/panel/img/record.png +0 -0
  260. data/plugins/proxy/panel/inspect.html.erb +7 -0
  261. data/plugins/proxy/panel/js/bootstrap.min.js +6 -0
  262. data/plugins/proxy/panel/js/jquery.min.js +2 -0
  263. data/plugins/proxy/panel/js/panel.js +39 -0
  264. data/plugins/proxy/panel/layout.html.erb +25 -0
  265. data/plugins/proxy/panel/page_accordion.html.erb +67 -0
  266. data/plugins/proxy/panel/page_twin_accordion.html.erb +18 -0
  267. data/plugins/proxy/panel/panel.html.erb +63 -0
  268. data/plugins/proxy/panel/shutdown_message.html.erb +7 -0
  269. data/plugins/proxy/panel/verify_login_check.html.erb +31 -0
  270. data/plugins/proxy/panel/verify_login_final.html.erb +26 -0
  271. data/plugins/proxy/panel/verify_login_sequence.html.erb +45 -0
  272. data/plugins/proxy/server.rb +175 -47
  273. data/plugins/proxy/ssl-interceptor-cert.pem +34 -0
  274. data/plugins/proxy/ssl-interceptor-pkey.pem +51 -0
  275. data/plugins/rescan.rb +27 -28
  276. data/plugins/script.rb +53 -0
  277. data/plugins/vector_feed.rb +226 -0
  278. data/plugins/waf_detector.rb +70 -73
  279. data/reports/afr.rb +23 -24
  280. data/reports/ap.rb +25 -36
  281. data/reports/html.rb +109 -163
  282. data/reports/html/default.erb +13 -12
  283. data/reports/html/default/configuration.erb +21 -21
  284. data/reports/html/default/css/main.css +350 -350
  285. data/reports/html/default/issues.erb +1 -1
  286. data/reports/html/default/js/charts.js +2 -2
  287. data/reports/html/default/js/helpers.js +0 -42
  288. data/reports/html/default/js/init.js +0 -1
  289. data/reports/html/default/sitemap.erb +2 -2
  290. data/reports/html/default/summary.erb +4 -4
  291. data/reports/html/default/summary_issue.erb +1 -1
  292. data/reports/json.rb +26 -28
  293. data/reports/marshal.rb +23 -25
  294. data/reports/metareport.rb +65 -98
  295. data/reports/plugin_formatters/html/autologin.rb +34 -41
  296. data/reports/plugin_formatters/html/content_types.rb +46 -52
  297. data/reports/plugin_formatters/html/cookie_collector.rb +41 -47
  298. data/reports/plugin_formatters/html/discovery.rb +36 -41
  299. data/reports/plugin_formatters/html/form_dicattack.rb +28 -34
  300. data/reports/plugin_formatters/html/healthmap.rb +48 -55
  301. data/reports/plugin_formatters/html/http_dicattack.rb +28 -34
  302. data/reports/plugin_formatters/html/profiler.rb +26 -30
  303. data/reports/plugin_formatters/html/profiler/template.erb +7 -7
  304. data/reports/plugin_formatters/html/resolver.rb +44 -52
  305. data/reports/plugin_formatters/html/timing_attacks.rb +42 -44
  306. data/reports/plugin_formatters/html/uniformity.rb +37 -42
  307. data/reports/plugin_formatters/html/waf_detector.rb +26 -34
  308. data/reports/plugin_formatters/stdout/autologin.rb +28 -40
  309. data/reports/plugin_formatters/stdout/content_types.rb +36 -53
  310. data/reports/plugin_formatters/stdout/cookie_collector.rb +28 -41
  311. data/reports/plugin_formatters/stdout/discovery.rb +27 -37
  312. data/reports/plugin_formatters/stdout/form_dicattack.rb +22 -35
  313. data/reports/plugin_formatters/stdout/healthmap.rb +40 -57
  314. data/reports/plugin_formatters/stdout/http_dicattack.rb +22 -36
  315. data/reports/plugin_formatters/stdout/profiler.rb +55 -74
  316. data/reports/plugin_formatters/stdout/resolver.rb +18 -34
  317. data/reports/plugin_formatters/stdout/timing_attacks.rb +27 -39
  318. data/reports/plugin_formatters/stdout/uniformity.rb +32 -44
  319. data/reports/plugin_formatters/stdout/waf_detector.rb +20 -32
  320. data/reports/plugin_formatters/xml/autologin.rb +27 -49
  321. data/reports/plugin_formatters/xml/content_types.rb +41 -66
  322. data/reports/plugin_formatters/xml/cookie_collector.rb +29 -49
  323. data/reports/plugin_formatters/xml/discovery.rb +23 -41
  324. data/reports/plugin_formatters/xml/form_dicattack.rb +22 -40
  325. data/reports/plugin_formatters/xml/healthmap.rb +44 -63
  326. data/reports/plugin_formatters/xml/http_dicattack.rb +22 -41
  327. data/reports/plugin_formatters/xml/profiler.rb +65 -89
  328. data/reports/plugin_formatters/xml/resolver.rb +21 -41
  329. data/reports/plugin_formatters/xml/timing_attacks.rb +27 -45
  330. data/reports/plugin_formatters/xml/uniformity.rb +36 -55
  331. data/reports/plugin_formatters/xml/waf_detector.rb +23 -42
  332. data/reports/stdout.rb +120 -121
  333. data/reports/txt.rb +29 -45
  334. data/reports/xml.rb +109 -148
  335. data/reports/xml/buffer.rb +66 -79
  336. data/reports/yaml.rb +26 -28
  337. data/rpcd_handlers/placeholder +0 -0
  338. data/spec/arachni/audit_store_spec.rb +223 -0
  339. data/spec/arachni/bloom_filter_spec.rb +76 -0
  340. data/spec/arachni/cache/base_spec.rb +275 -0
  341. data/spec/arachni/cache/least_cost_replacement_spec.rb +58 -0
  342. data/spec/arachni/cache/least_recently_used_spec.rb +91 -0
  343. data/spec/arachni/cache/random_replacement_spec.rb +43 -0
  344. data/spec/arachni/component/manager_spec.rb +448 -0
  345. data/spec/arachni/component/options/address_spec.rb +32 -0
  346. data/spec/arachni/component/options/base_spec.rb +105 -0
  347. data/spec/arachni/component/options/bool_spec.rb +67 -0
  348. data/spec/arachni/component/options/enum_spec.rb +51 -0
  349. data/spec/arachni/component/options/float_spec.rb +42 -0
  350. data/spec/arachni/component/options/int_spec.rb +46 -0
  351. data/spec/arachni/component/options/path_spec.rb +32 -0
  352. data/spec/arachni/component/options/port_spec.rb +38 -0
  353. data/spec/arachni/component/options/string_spec.rb +38 -0
  354. data/spec/arachni/component/options/url_spec.rb +36 -0
  355. data/spec/arachni/crypto/rsa_aes_cbc_spec.rb +31 -0
  356. data/spec/arachni/database/hash_spec.rb +217 -0
  357. data/spec/arachni/database/queue_spec.rb +52 -0
  358. data/spec/arachni/element/base_spec.rb +127 -0
  359. data/spec/arachni/element/body_spec.rb +9 -0
  360. data/spec/arachni/element/capabilities/auditable/rdiff_spec.rb +47 -0
  361. data/spec/arachni/element/capabilities/auditable/taint_spec.rb +110 -0
  362. data/spec/arachni/element/capabilities/auditable/timeout_spec.rb +107 -0
  363. data/spec/arachni/element/capabilities/mutable_spec.rb +261 -0
  364. data/spec/arachni/element/cookie_spec.rb +362 -0
  365. data/spec/arachni/element/form_spec.rb +668 -0
  366. data/spec/arachni/element/header_spec.rb +49 -0
  367. data/spec/arachni/element/link_spec.rb +220 -0
  368. data/spec/arachni/element/path_spec.rb +9 -0
  369. data/spec/arachni/element/server_spec.rb +9 -0
  370. data/spec/arachni/framework_spec.rb +860 -0
  371. data/spec/arachni/http/cookie_jar_spec.rb +267 -0
  372. data/spec/arachni/http_spec.rb +991 -0
  373. data/spec/arachni/issue_spec.rb +307 -0
  374. data/spec/arachni/mixins/observable_spec.rb +59 -0
  375. data/spec/arachni/mixins/progress_bar_spec.rb +41 -0
  376. data/spec/arachni/module/auditor_spec.rb +506 -0
  377. data/spec/arachni/module/element_db_spec.rb +131 -0
  378. data/spec/arachni/module/key_filler.rb +15 -0
  379. data/spec/arachni/module/manager_spec.rb +154 -0
  380. data/spec/arachni/module/trainer_spec.rb +102 -0
  381. data/spec/arachni/module/utilities_spec.rb +30 -0
  382. data/spec/arachni/module/utilities_spec/read_file.txt +3 -0
  383. data/spec/arachni/options_spec.rb +555 -0
  384. data/spec/arachni/page_spec.rb +290 -0
  385. data/spec/arachni/parser_spec.rb +508 -0
  386. data/spec/arachni/plugin/manager_spec.rb +174 -0
  387. data/spec/arachni/report/base_spec.rb +53 -0
  388. data/spec/arachni/report/manager_spec.rb +82 -0
  389. data/spec/arachni/rpc/client/base_spec.rb +157 -0
  390. data/spec/arachni/rpc/client/dispatcher_spec.rb +40 -0
  391. data/spec/arachni/rpc/client/instance_spec.rb +92 -0
  392. data/spec/arachni/rpc/server/base_spec.rb +40 -0
  393. data/spec/arachni/rpc/server/dispatcher/handler.rb +120 -0
  394. data/spec/arachni/rpc/server/dispatcher/node_spec.rb +220 -0
  395. data/spec/arachni/rpc/server/dispatcher_spec.rb +136 -0
  396. data/spec/arachni/rpc/server/distributor_spec.rb +628 -0
  397. data/spec/arachni/rpc/server/framework_hpg_spec.rb +321 -0
  398. data/spec/arachni/rpc/server/framework_simple_spec.rb +453 -0
  399. data/spec/arachni/rpc/server/instance_spec.rb +81 -0
  400. data/spec/arachni/rpc/server/modules/manager_spec.rb +79 -0
  401. data/spec/arachni/rpc/server/options_spec.rb +124 -0
  402. data/spec/arachni/rpc/server/output_spec.rb +238 -0
  403. data/spec/arachni/rpc/server/plugin/manager_spec.rb +86 -0
  404. data/spec/arachni/ruby/array_spec.rb +103 -0
  405. data/spec/arachni/ruby/enumerable_spec.rb +37 -0
  406. data/spec/arachni/ruby/object_spec.rb +38 -0
  407. data/spec/arachni/ruby/string_spec.rb +77 -0
  408. data/spec/arachni/ruby/webrick_spec.rb +15 -0
  409. data/spec/arachni/session_spec.rb +308 -0
  410. data/spec/arachni/spider_spec.rb +383 -0
  411. data/spec/arachni/typhoeus/hydra_spec.rb +14 -0
  412. data/spec/arachni/typhoeus/requrest_spec.rb +58 -0
  413. data/spec/arachni/typhoeus/response_spec.rb +78 -0
  414. data/spec/arachni/uri_spec.rb +462 -0
  415. data/spec/arachni/utilities_spec.rb +297 -0
  416. data/spec/fixtures/auditstore.afr +2959 -0
  417. data/spec/fixtures/cookies.txt +9 -0
  418. data/spec/fixtures/modules/test.rb +58 -0
  419. data/spec/fixtures/modules/test2.rb +46 -0
  420. data/spec/fixtures/modules/test3.rb +46 -0
  421. data/spec/fixtures/passwords.txt +17 -0
  422. data/spec/fixtures/plugins/bad.rb +46 -0
  423. data/spec/fixtures/plugins/defaults/default.rb +45 -0
  424. data/spec/fixtures/plugins/distributable.rb +42 -0
  425. data/spec/fixtures/plugins/loop.rb +32 -0
  426. data/spec/fixtures/plugins/wait.rb +34 -0
  427. data/spec/fixtures/plugins/with_options.rb +31 -0
  428. data/spec/fixtures/reports/base_spec/plugin_formatters/with_formatters/foobar.rb +21 -0
  429. data/spec/fixtures/reports/base_spec/with_formatters.rb +23 -0
  430. data/spec/fixtures/reports/base_spec/with_outfile.rb +24 -0
  431. data/spec/fixtures/reports/base_spec/without_outfile.rb +20 -0
  432. data/spec/fixtures/reports/manager_spec/afr.rb +21 -0
  433. data/spec/fixtures/reports/manager_spec/foo.rb +26 -0
  434. data/spec/fixtures/rescan.afr.tpl +145 -0
  435. data/spec/fixtures/rpcd_handlers/echo.rb +68 -0
  436. data/spec/fixtures/run_mod/body.rb +58 -0
  437. data/spec/fixtures/run_mod/cookies.rb +58 -0
  438. data/spec/fixtures/run_mod/empty.rb +58 -0
  439. data/spec/fixtures/run_mod/flch.rb +63 -0
  440. data/spec/fixtures/run_mod/forms.rb +58 -0
  441. data/spec/fixtures/run_mod/headers.rb +58 -0
  442. data/spec/fixtures/run_mod/links.rb +58 -0
  443. data/spec/fixtures/run_mod/nil.rb +57 -0
  444. data/spec/fixtures/run_mod/path.rb +58 -0
  445. data/spec/fixtures/run_mod/server.rb +58 -0
  446. data/spec/fixtures/script_plugin.rb +1 -0
  447. data/spec/fixtures/taint_module/taint.rb +48 -0
  448. data/spec/fixtures/usernames.txt +13 -0
  449. data/spec/fixtures/wait_module/wait.rb +48 -0
  450. data/spec/helpers/auditor.rb +9 -0
  451. data/spec/helpers/misc.rb +41 -0
  452. data/spec/helpers/processes.rb +112 -0
  453. data/spec/helpers/requires.rb +8 -0
  454. data/spec/helpers/server.rb +54 -0
  455. data/spec/logs/Dispatcher - 2752-13830.log +49 -0
  456. data/spec/logs/Dispatcher - 2766-8238.log +35 -0
  457. data/spec/logs/Dispatcher - 2808-9029.log +31 -0
  458. data/spec/logs/Dispatcher - 2854-8571.log +26 -0
  459. data/spec/logs/Dispatcher - 2888-10411.log +20 -0
  460. data/spec/logs/Dispatcher - 2922-14464.log +13 -0
  461. data/spec/logs/Dispatcher - 2957-15255.log +19 -0
  462. data/spec/logs/Dispatcher - 3216-14203.log +35 -0
  463. data/spec/logs/Dispatcher - 3305-8622.log +43 -0
  464. data/spec/logs/Dispatcher - 3340-15426.log +35 -0
  465. data/spec/logs/Dispatcher - 3399-12586.log +40 -0
  466. data/spec/logs/Dispatcher - 3433-14149.log +26 -0
  467. data/spec/logs/Dispatcher - 3582-6198.log +27 -0
  468. data/spec/logs/Dispatcher - 3616-11169.log +13 -0
  469. data/spec/logs/Dispatcher - 3849-9016.log +7 -0
  470. data/spec/logs/output_spec.log +4 -0
  471. data/spec/logs/placeholder +0 -0
  472. data/spec/modules/audit/code_injection_spec.rb +25 -0
  473. data/spec/modules/audit/code_injection_timing_spec.rb +24 -0
  474. data/spec/modules/audit/csrf_spec.rb +38 -0
  475. data/spec/modules/audit/ldapi_spec.rb +19 -0
  476. data/spec/modules/audit/os_cmd_injection_spec.rb +24 -0
  477. data/spec/modules/audit/os_cmd_injection_timing_spec.rb +24 -0
  478. data/spec/modules/audit/path_traversal_spec.rb +23 -0
  479. data/spec/modules/audit/response_splitting_spec.rb +19 -0
  480. data/spec/modules/audit/rfi_spec.rb +19 -0
  481. data/spec/modules/audit/session_fixation_spec.rb +23 -0
  482. data/spec/modules/audit/sqli_blind_rdiff_spec.rb +19 -0
  483. data/spec/modules/audit/sqli_blind_timing_spec.rb +23 -0
  484. data/spec/modules/audit/sqli_spec.rb +24 -0
  485. data/spec/modules/audit/trainer_spec.rb +25 -0
  486. data/spec/modules/audit/unvalidated_redirect_spec.rb +24 -0
  487. data/spec/modules/audit/xpath_spec.rb +25 -0
  488. data/spec/modules/audit/xss_event_spec.rb +19 -0
  489. data/spec/modules/audit/xss_path_spec.rb +19 -0
  490. data/spec/modules/audit/xss_script_tag_spec.rb +19 -0
  491. data/spec/modules/audit/xss_spec.rb +24 -0
  492. data/spec/modules/audit/xss_tag_spec.rb +19 -0
  493. data/spec/modules/recon/allowed_methods_spec.rb +19 -0
  494. data/spec/modules/recon/backdoors_spec.rb +19 -0
  495. data/spec/modules/recon/backup_files_spec.rb +19 -0
  496. data/spec/modules/recon/common_directories_spec.rb +19 -0
  497. data/spec/modules/recon/common_files_spec.rb +19 -0
  498. data/spec/modules/recon/directory_listing_spec.rb +19 -0
  499. data/spec/modules/recon/grep/captcha_spec.rb +19 -0
  500. data/spec/modules/recon/grep/credit_card_spec.rb +19 -0
  501. data/spec/modules/recon/grep/cvs_svn_users_spec.rb +19 -0
  502. data/spec/modules/recon/grep/emails_spec.rb +19 -0
  503. data/spec/modules/recon/grep/html_objects_spec.rb +19 -0
  504. data/spec/modules/recon/grep/http_only_cookies_spec.rb +19 -0
  505. data/spec/modules/recon/grep/insecure_cookies_spec.rb +19 -0
  506. data/spec/modules/recon/grep/mixed_resource_spec.rb +20 -0
  507. data/spec/modules/recon/grep/private_ip_spec.rb +26 -0
  508. data/spec/modules/recon/grep/ssn_spec.rb +19 -0
  509. data/spec/modules/recon/grep/unencrypted_password_forms_spec.rb +19 -0
  510. data/spec/modules/recon/htaccess_limit_spec.rb +19 -0
  511. data/spec/modules/recon/http_put_spec.rb +19 -0
  512. data/spec/modules/recon/interesting_responses_spec.rb +27 -0
  513. data/spec/modules/recon/webdav_spec.rb +19 -0
  514. data/spec/modules/recon/xst_spec.rb +19 -0
  515. data/spec/path_extractors/anchors_spec.rb +19 -0
  516. data/spec/path_extractors/forms_spec.rb +19 -0
  517. data/spec/path_extractors/frames_spec.rb +20 -0
  518. data/spec/path_extractors/generic_spec.rb +28 -0
  519. data/spec/path_extractors/links_spec.rb +19 -0
  520. data/spec/path_extractors/meta_refresh_spec.rb +24 -0
  521. data/spec/path_extractors/scripts_spec.rb +19 -0
  522. data/spec/pems/cacert.pem +39 -0
  523. data/spec/pems/client/cert.pem +39 -0
  524. data/spec/pems/client/foo-cert.pem +39 -0
  525. data/spec/pems/client/foo-key.pem +51 -0
  526. data/spec/pems/client/key.pem +51 -0
  527. data/spec/pems/server/cert.pem +39 -0
  528. data/spec/pems/server/key.pem +51 -0
  529. data/spec/plugins/autologin_spec.rb +76 -0
  530. data/spec/plugins/autothrottle_spec.rb +45 -0
  531. data/spec/plugins/content_types_spec.rb +93 -0
  532. data/spec/plugins/cookie_collector_spec.rb +32 -0
  533. data/spec/plugins/form_dicattack_spec.rb +60 -0
  534. data/spec/plugins/healthmap_spec.rb +40 -0
  535. data/spec/plugins/http_dicattack_spec.rb +40 -0
  536. data/spec/plugins/meta/remedies/discovery_spec.rb +15 -0
  537. data/spec/plugins/meta/remedies/manual_verification_spec.rb +28 -0
  538. data/spec/plugins/meta/remedies/timing_attacks_spec.rb +30 -0
  539. data/spec/plugins/meta/uniformity_spec.rb +83 -0
  540. data/spec/plugins/profiler_spec.rb +82 -0
  541. data/spec/plugins/rescan_spec.rb +26 -0
  542. data/spec/plugins/resolver_spec.rb +16 -0
  543. data/spec/plugins/script_spec.rb +12 -0
  544. data/spec/plugins/vector_feed_spec.rb +155 -0
  545. data/spec/plugins/waf_detector_spec.rb +41 -0
  546. data/spec/reports/afr_spec.rb +13 -0
  547. data/spec/reports/ap_spec.rb +9 -0
  548. data/spec/reports/html_spec.rb +13 -0
  549. data/spec/reports/json_spec.rb +17 -0
  550. data/spec/reports/marshal_spec.rb +13 -0
  551. data/spec/reports/stdout_spec.rb +9 -0
  552. data/spec/reports/txt_spec.rb +8 -0
  553. data/spec/reports/xml_spec.rb +13 -0
  554. data/spec/reports/yaml_spec.rb +13 -0
  555. data/spec/servers/arachni/element/capabilities/auditable/rdiff.rb +36 -0
  556. data/spec/servers/arachni/element/capabilities/auditable/taint.rb +10 -0
  557. data/spec/servers/arachni/element/capabilities/auditable/timeout.rb +30 -0
  558. data/spec/servers/arachni/element/cookie.rb +37 -0
  559. data/spec/servers/arachni/element/form.rb +93 -0
  560. data/spec/servers/arachni/element/header.rb +22 -0
  561. data/spec/servers/arachni/element/link.rb +26 -0
  562. data/spec/servers/arachni/framework.rb +54 -0
  563. data/spec/servers/arachni/http.rb +140 -0
  564. data/spec/servers/arachni/http_auth.rb +9 -0
  565. data/spec/servers/arachni/module/auditor.rb +135 -0
  566. data/spec/servers/arachni/module/trainer.rb +40 -0
  567. data/spec/servers/arachni/parser.rb +70 -0
  568. data/spec/servers/arachni/rpc/server/framework_hpg.rb +21 -0
  569. data/spec/servers/arachni/rpc/server/framework_simple.rb +30 -0
  570. data/spec/servers/arachni/session.rb +110 -0
  571. data/spec/servers/arachni/spider.rb +148 -0
  572. data/spec/servers/modules/audit/code_injection.rb +140 -0
  573. data/spec/servers/modules/audit/code_injection_timing.rb +110 -0
  574. data/spec/servers/modules/audit/csrf.rb +80 -0
  575. data/spec/servers/modules/audit/ldapi.rb +73 -0
  576. data/spec/servers/modules/audit/os_cmd_injection.rb +140 -0
  577. data/spec/servers/modules/audit/os_cmd_injection_timing.rb +111 -0
  578. data/spec/servers/modules/audit/path_traversal.rb +176 -0
  579. data/spec/servers/modules/audit/response_splitting.rb +114 -0
  580. data/spec/servers/modules/audit/rfi.rb +113 -0
  581. data/spec/servers/modules/audit/session_fixation.rb +87 -0
  582. data/spec/servers/modules/audit/sqli.rb +118 -0
  583. data/spec/servers/modules/audit/sqli/coldfusion +1 -0
  584. data/spec/servers/modules/audit/sqli/db2 +4 -0
  585. data/spec/servers/modules/audit/sqli/emc +2 -0
  586. data/spec/servers/modules/audit/sqli/informix +3 -0
  587. data/spec/servers/modules/audit/sqli/interbase +2 -0
  588. data/spec/servers/modules/audit/sqli/jdbc +0 -0
  589. data/spec/servers/modules/audit/sqli/mssql +26 -0
  590. data/spec/servers/modules/audit/sqli/mysql +13 -0
  591. data/spec/servers/modules/audit/sqli/oracle +6 -0
  592. data/spec/servers/modules/audit/sqli/postgresql +7 -0
  593. data/spec/servers/modules/audit/sqli/sqlite +4 -0
  594. data/spec/servers/modules/audit/sqli/sybase +0 -0
  595. data/spec/servers/modules/audit/sqli_blind_rdiff.rb +74 -0
  596. data/spec/servers/modules/audit/sqli_blind_timing.rb +121 -0
  597. data/spec/servers/modules/audit/trainer_module.rb +160 -0
  598. data/spec/servers/modules/audit/unvalidated_redirect.rb +115 -0
  599. data/spec/servers/modules/audit/xpath.rb +111 -0
  600. data/spec/servers/modules/audit/xpath/dotnet +5 -0
  601. data/spec/servers/modules/audit/xpath/general +13 -0
  602. data/spec/servers/modules/audit/xpath/java +3 -0
  603. data/spec/servers/modules/audit/xpath/libxml2 +2 -0
  604. data/spec/servers/modules/audit/xpath/php +2 -0
  605. data/spec/servers/modules/audit/xss.rb +152 -0
  606. data/spec/servers/modules/audit/xss_event.rb +80 -0
  607. data/spec/servers/modules/audit/xss_path.rb +44 -0
  608. data/spec/servers/modules/audit/xss_script_tag.rb +73 -0
  609. data/spec/servers/modules/audit/xss_tag.rb +139 -0
  610. data/spec/servers/modules/module_server.rb +14 -0
  611. data/spec/servers/modules/recon/allowed_methods.rb +5 -0
  612. data/spec/servers/modules/recon/backdoors.rb +4 -0
  613. data/spec/servers/modules/recon/backup_files.rb +28 -0
  614. data/spec/servers/modules/recon/common_directories.rb +6 -0
  615. data/spec/servers/modules/recon/common_files.rb +6 -0
  616. data/spec/servers/modules/recon/directory_listing.rb +30 -0
  617. data/spec/servers/modules/recon/grep/captcha.rb +27 -0
  618. data/spec/servers/modules/recon/grep/credit_card.rb +28 -0
  619. data/spec/servers/modules/recon/grep/cvs_svn_users.rb +23 -0
  620. data/spec/servers/modules/recon/grep/emails.rb +21 -0
  621. data/spec/servers/modules/recon/grep/html_objects.rb +7 -0
  622. data/spec/servers/modules/recon/grep/http_only_cookies.rb +21 -0
  623. data/spec/servers/modules/recon/grep/insecure_cookies.rb +21 -0
  624. data/spec/servers/modules/recon/grep/mixed_resource.rb +83 -0
  625. data/spec/servers/modules/recon/grep/private_ip.rb +18 -0
  626. data/spec/servers/modules/recon/grep/ssn.rb +5 -0
  627. data/spec/servers/modules/recon/grep/unencrypted_password_forms.rb +33 -0
  628. data/spec/servers/modules/recon/htaccess_limit.rb +8 -0
  629. data/spec/servers/modules/recon/http_put.rb +7 -0
  630. data/spec/servers/modules/recon/interesting_responses.rb +5 -0
  631. data/spec/servers/modules/recon/webdav.rb +25 -0
  632. data/spec/servers/modules/recon/xst.rb +6 -0
  633. data/spec/servers/plugins/autologin.rb +38 -0
  634. data/spec/servers/plugins/autothrottle.rb +8 -0
  635. data/spec/servers/plugins/content_types.rb +17 -0
  636. data/spec/servers/plugins/cookie_collector.rb +20 -0
  637. data/spec/servers/plugins/form_dicattack.rb +28 -0
  638. data/spec/servers/plugins/healthmap.rb +16 -0
  639. data/spec/servers/plugins/http_dicattack.rb +9 -0
  640. data/spec/servers/plugins/http_dicattack_secure.rb +9 -0
  641. data/spec/servers/plugins/http_dicattack_unprotected.rb +5 -0
  642. data/spec/servers/plugins/meta/remedies/discovery.rb +7 -0
  643. data/spec/servers/plugins/meta/remedies/timing_attacks.rb +29 -0
  644. data/spec/servers/plugins/profiler.rb +82 -0
  645. data/spec/servers/plugins/rescan.rb +31 -0
  646. data/spec/servers/plugins/waf_detector.rb +33 -0
  647. data/spec/shared/component.rb +43 -0
  648. data/spec/shared/element/capabilities/auditable.rb +729 -0
  649. data/spec/shared/element/capabilities/refreshable.rb +56 -0
  650. data/spec/shared/module.rb +162 -0
  651. data/spec/shared/path_extractor.rb +47 -0
  652. data/spec/shared/plugin.rb +50 -0
  653. data/spec/shared/reports.rb +47 -0
  654. data/spec/spec_helper.rb +53 -0
  655. metadata +870 -323
  656. data/extras/modules/recon/raft_dirs.rb +0 -108
  657. data/extras/modules/recon/raft_dirs/raft-large-directories.txt +0 -62290
  658. data/extras/modules/recon/raft_files.rb +0 -110
  659. data/extras/modules/recon/raft_files/raft-large-files.txt +0 -37037
  660. data/extras/modules/recon/svn_digger_dirs.rb +0 -108
  661. data/extras/modules/recon/svn_digger_dirs/Licence.txt +0 -674
  662. data/extras/modules/recon/svn_digger_dirs/ReadMe-Arachni.txt +0 -4
  663. data/extras/modules/recon/svn_digger_dirs/ReadMe.txt +0 -6
  664. data/extras/modules/recon/svn_digger_dirs/all-dirs.txt +0 -5960
  665. data/extras/modules/recon/svn_digger_files.rb +0 -114
  666. data/extras/modules/recon/svn_digger_files/Licence.txt +0 -674
  667. data/extras/modules/recon/svn_digger_files/ReadMe-Arachni.txt +0 -4
  668. data/extras/modules/recon/svn_digger_files/ReadMe.txt +0 -6
  669. data/extras/modules/recon/svn_digger_files/all-extensionless.txt +0 -25419
  670. data/extras/modules/recon/svn_digger_files/all.txt +0 -43135
  671. data/lib/arachni/component_manager.rb +0 -293
  672. data/lib/arachni/component_options.rb +0 -425
  673. data/lib/arachni/parser/auditable.rb +0 -606
  674. data/lib/arachni/parser/elements.rb +0 -315
  675. data/lib/arachni/parser/page.rb +0 -168
  676. data/lib/arachni/parser/parser.rb +0 -866
  677. data/lib/arachni/rpc/server/options.rb +0 -95
  678. data/lib/arachni/ui/web/addons/autodeploy.rb +0 -207
  679. data/lib/arachni/ui/web/addons/autodeploy/lib/manager.rb +0 -398
  680. data/lib/arachni/ui/web/addons/autodeploy/views/index.erb +0 -291
  681. data/modules/recon/mixed_resource.rb +0 -100
  682. data/modules/recon/unencrypted_password_forms.rb +0 -107
  683. data/path_extractors/sitemap.rb +0 -31
  684. data/plugins/defaults/metamodules/remedies/manual_verification.rb +0 -65
  685. data/plugins/defaults/metamodules/remedies/timing_attacks.rb +0 -134
  686. data/plugins/defaults/metamodules/uniformity.rb +0 -99
  687. data/reports/metareport/arachni_metareport.rb +0 -174
  688. data/reports/plugin_formatters/stdout/metamodules.rb +0 -82
@@ -0,0 +1,19 @@
1
+ =begin
2
+ Copyright 2010-2012 Tasos Laskos <tasos.laskos@gmail.com>
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ =end
16
+
17
+ module Arachni::Element
18
+ BODY = 'body'
19
+ end
@@ -0,0 +1,286 @@
1
+ =begin
2
+ Copyright 2010-2012 Tasos Laskos <tasos.laskos@gmail.com>
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ =end
16
+
17
+ module Arachni
18
+ require Options.dir['lib'] + 'module/utilities'
19
+ require Options.dir['lib'] + 'module/key_filler'
20
+
21
+ module Element::Capabilities
22
+ module Mutable
23
+
24
+ #
25
+ # @return [String] name of the altered/mutated parameter
26
+ #
27
+ attr_accessor :altered
28
+
29
+ #
30
+ # Holds constant bitfields that describe the preferred formatting
31
+ # of injection strings.
32
+ #
33
+ module Format
34
+
35
+ #
36
+ # Leaves the injection string as is.
37
+ #
38
+ STRAIGHT = 1 << 0
39
+
40
+ #
41
+ # Appends the injection string to the default value of the input vector.<br/>
42
+ # (If no default value exists Arachni will choose one.)
43
+ #
44
+ APPEND = 1 << 1
45
+
46
+ #
47
+ # Terminates the injection string with a null character.
48
+ #
49
+ NULL = 1 << 2
50
+
51
+ #
52
+ # Prefix the string with a ';', useful for command injection modules
53
+ #
54
+ SEMICOLON = 1 << 3
55
+
56
+ end
57
+
58
+ # Default formatting and permutation options
59
+ MUTATION_OPTIONS = {
60
+ #
61
+ # Formatting of the injection strings.
62
+ #
63
+ # A new set of audit inputs will be generated
64
+ # for each value in the array.
65
+ #
66
+ # Values can be OR'ed bitfields of all available constants
67
+ # of {Format}.
68
+ #
69
+ format: [ Format::STRAIGHT, Format::APPEND,
70
+ Format::NULL, Format::APPEND | Format::NULL ],
71
+
72
+
73
+ # skip mutation with default/original values (for {Arachni::Element::Form} elements)
74
+ skip_orig: false,
75
+
76
+ # flip injection value and input name
77
+ param_flip: false,
78
+
79
+ # array of parameter names remain untouched
80
+ skip: [],
81
+
82
+ #
83
+ # nil: use system settings (!Options.fuzz_methods)
84
+ # true: don't create mutations with other methods (GET/POST)
85
+ # false: create mutations with other methods (GET/POST)
86
+ #
87
+ respect_method: nil
88
+ }
89
+
90
+ # @return [String] value of the altered input
91
+ def altered_value
92
+ self[altered].to_s
93
+ end
94
+
95
+ # @param [String] value sets the value for the altered input
96
+ def altered_value=( value )
97
+ self[altered] = value
98
+ end
99
+
100
+ # @return [Bool] +true+ if the element has not been mutated, +false+ otherwise.
101
+ def original?
102
+ self.altered.nil?
103
+ end
104
+
105
+ # @return [Bool] +true+ if the element has been mutated, +false+ otherwise.
106
+ def mutated?
107
+ !original?
108
+ end
109
+
110
+ # @return [Set] names of input vectors to be excluded from {#mutations}.
111
+ def immutables
112
+ @immutables ||= Set.new
113
+ end
114
+
115
+ #
116
+ # Injects the +injection_str+ in self's values according to formatting options
117
+ # and returns an array of permutations of self.
118
+ #
119
+ # Vector names in {#immutables} will be excluded.
120
+ #
121
+ # @param [String] injection_str the string to inject
122
+ # @param [Hash] opts {MUTATION_OPTIONS}
123
+ #
124
+ # @return [Array]
125
+ #
126
+ # @see #immutables
127
+ #
128
+ def mutations( injection_str, opts = {} )
129
+ opts = MUTATION_OPTIONS.merge( opts )
130
+ hash = auditable.dup
131
+
132
+ var_combo = []
133
+ return [] if !hash || hash.empty?
134
+
135
+ chash = hash.dup
136
+ hash.keys.each do |k|
137
+ # don't audit parameter flips
138
+ next if hash[k] == seed || immutables.include?( k )
139
+
140
+ chash = Module::KeyFiller.fill( chash )
141
+ opts[:format].each do |format|
142
+ str = format_str( injection_str, chash[k], format )
143
+
144
+ elem = self.dup
145
+ elem.altered = k.dup
146
+ elem.auditable = chash.merge( { k => str } )
147
+ var_combo << elem
148
+ end
149
+
150
+ end
151
+
152
+ if opts[:param_flip]
153
+ elem = self.dup
154
+
155
+ # when under HPG mode element auditing is strictly regulated
156
+ # and when we flip params we essentially create a new element
157
+ # which won't be on the whitelist
158
+ elem.override_instance_scope
159
+
160
+ elem.altered = 'Parameter flip'
161
+ elem[injection_str] = seed
162
+ var_combo << elem
163
+ end
164
+
165
+ opts[:respect_method] = !Options.fuzz_methods? if opts[:respect_method].nil?
166
+
167
+ # add the same stuff with different methods
168
+ if !opts[:respect_method]
169
+ var_combo |= var_combo.map do |f|
170
+ c = f.dup
171
+ c.method = (f.method.to_s.downcase == 'get' ? 'post' : 'get')
172
+ c
173
+ end
174
+ end
175
+
176
+ print_debug_injection_set( var_combo, opts )
177
+ var_combo.uniq
178
+ end
179
+
180
+ # alias for #mutations
181
+ def mutations_for( *args )
182
+ mutations( *args )
183
+ end
184
+ # alias for #mutations
185
+ def permutations( *args )
186
+ mutations( *args )
187
+ end
188
+ # alias for #mutations
189
+ def permutations_for( *args )
190
+ permutations( *args )
191
+ end
192
+
193
+ private
194
+
195
+ #
196
+ # Prepares an injection string following the specified formating options
197
+ # as contained in the format bitfield.
198
+ #
199
+ # @see Format
200
+ # @param [String] injection_str
201
+ # @param [String] default_str default value to be appended by the
202
+ # injection string if {Format::APPEND} is set in 'format'
203
+ # @param [Integer] format bitfield describing formating preferencies
204
+ #
205
+ # @return [String]
206
+ #
207
+ def format_str( injection_str, default_str, format )
208
+ semicolon = null = append = ''
209
+
210
+ null = "\0" if ( format & Format::NULL ) != 0
211
+ semicolon = ';' if ( format & Format::SEMICOLON ) != 0
212
+ append = default_str if ( format & Format::APPEND ) != 0
213
+ semicolon = append = null = '' if ( format & Format::STRAIGHT ) != 0
214
+
215
+ semicolon + append + injection_str.to_s + null
216
+ end
217
+
218
+ def print_debug_injection_set( var_combo, opts )
219
+ return if !debug?
220
+
221
+ print_debug
222
+ print_debug_trainer( opts )
223
+ print_debug_formatting( opts )
224
+ print_debug_combos( var_combo )
225
+ end
226
+
227
+ def print_debug_formatting( opts )
228
+ print_debug '------------'
229
+
230
+ print_debug 'Injection string format combinations set to:'
231
+ print_debug '|'
232
+ msg = []
233
+ opts[:format].each do |format|
234
+ if( format & Format::NULL ) != 0
235
+ msg << 'null character termination (Format::NULL)'
236
+ end
237
+
238
+ if( format & Format::APPEND ) != 0
239
+ msg << 'append to default value (Format::APPEND)'
240
+ end
241
+
242
+ if( format & Format::STRAIGHT ) != 0
243
+ msg << 'straight, leave as is (Format::STRAIGHT)'
244
+ end
245
+
246
+ prep = msg.join( ' and ' ).capitalize + ". [Combo mask: #{format}]"
247
+ prep.gsub!( 'format::null', "Format::NULL [#{Format::NULL}]" )
248
+ prep.gsub!( 'format::append', "Format::APPEND [#{Format::APPEND}]" )
249
+ prep.gsub!( 'format::straight', "Format::STRAIGHT [#{Format::STRAIGHT}]" )
250
+
251
+ print_debug "|----> #{prep}"
252
+
253
+ msg.clear
254
+ end
255
+ nil
256
+ end
257
+
258
+ def print_debug_combos( combos )
259
+ print_debug
260
+ print_debug 'Prepared combinations:'
261
+ print_debug '|'
262
+
263
+ combos.each do |elem|
264
+ altered = elem.altered
265
+ combo = elem.auditable
266
+
267
+ print_debug '|'
268
+ print_debug "|--> Auditing: #{altered}"
269
+ print_debug "|--> Combo: "
270
+
271
+ combo.each { |c_combo| print_debug "|------> #{c_combo}" }
272
+ end
273
+
274
+ print_debug
275
+ print_debug '------------'
276
+ print_debug
277
+ end
278
+
279
+ def print_debug_trainer( opts )
280
+ print_debug 'Trainer set to: ' + ( opts[:train] ? 'ON' : 'OFF' )
281
+ end
282
+
283
+ end
284
+
285
+ end
286
+ end
@@ -0,0 +1,19 @@
1
+ =begin
2
+ Copyright 2010-2012 Tasos Laskos <tasos.laskos@gmail.com>
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ =end
16
+
17
+ module Arachni::Element
18
+ PATH = 'path'
19
+ end
@@ -0,0 +1,48 @@
1
+ =begin
2
+ Copyright 2010-2012 Tasos Laskos <tasos.laskos@gmail.com>
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ =end
16
+
17
+ module Arachni::Element
18
+ module Capabilities::Refreshable
19
+
20
+ #
21
+ # Refreshes the form's inputs and re-applies user updates.
22
+ #
23
+ # The way it works is by requesting the {Element::Base#url}, parsing the response
24
+ # and updating the form with the fresh form's inputs.
25
+ #
26
+ # @param [Hash] http_opts HTTP options to pass to the request
27
+ # @param [Block] block if a block is given the request will be async
28
+ # and the block will be called with the
29
+ # updated form.
30
+ #
31
+ # @return [Form] self
32
+ #
33
+ def refresh( http_opts = {}, &block )
34
+ updated = nil
35
+ http.get( url.to_s, http_opts.merge( async: !!block ) ) do |res|
36
+ # find ourselves
37
+ f = self.class.from_response( res ).select { |f| f.id == id_from( :original ) }.first
38
+ # get user updates
39
+ updates = changes
40
+ # update the form's inputs with the fresh ones and re-apply the user changes
41
+ updated = update( f.auditable ).update( updates )
42
+ block.call( updated ) if block_given?
43
+ end
44
+ updated
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1,19 @@
1
+ =begin
2
+ Copyright 2010-2012 Tasos Laskos <tasos.laskos@gmail.com>
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ =end
16
+
17
+ module Arachni::Element
18
+ SERVER = 'server'
19
+ end
@@ -0,0 +1,1043 @@
1
+ =begin
2
+ Copyright 2010-2012 Tasos Laskos <tasos.laskos@gmail.com>
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ =end
16
+
17
+ require 'webrick'
18
+ require 'uri'
19
+
20
+ require Arachni::Options.dir['lib'] + 'element/base'
21
+
22
+ module Arachni::Element
23
+
24
+ COOKIE = 'cookie'
25
+
26
+ #
27
+ # Represents a Cookie object and provides helper class methods for parsing, encoding, etc.
28
+ #
29
+ # @author Tasos "Zapotek" Laskos <tasos.laskos@gmail.com>
30
+ #
31
+ class Cookie < Arachni::Element::Base
32
+
33
+ #
34
+ # Default cookie values
35
+ #
36
+ DEFAULT = {
37
+ "name" => nil,
38
+ "value" => nil,
39
+ "version" => 0,
40
+ "port" => nil,
41
+ "discard" => nil,
42
+ "comment_url" => nil,
43
+ "expires" => nil,
44
+ "max_age" => nil,
45
+ "comment" => nil,
46
+ "secure" => nil,
47
+ "path" => nil,
48
+ "domain" => nil,
49
+ "httponly" => false
50
+ }
51
+
52
+ def initialize( url, raw = {} )
53
+ super( url, raw )
54
+
55
+ self.action = @url
56
+ self.method = 'get'
57
+
58
+ @raw ||= {}
59
+ if @raw['name'] && @raw['value']
60
+ self.auditable = { @raw['name'] => @raw['value'] }
61
+ else
62
+ self.auditable = raw.dup
63
+ end
64
+
65
+ @raw = @raw.merge( DEFAULT.merge( @raw ) )
66
+ if @raw['value'] && !@raw['value'].empty?
67
+ @raw['value'] = decode( @raw['value'].to_s )
68
+ end
69
+
70
+ parsed_uri = uri_parse( @url )
71
+ if !@raw['path']
72
+ path = parsed_uri.path
73
+ path = !path.empty? ? path : '/'
74
+ @raw['path'] = path
75
+ end
76
+
77
+ @raw['domain'] ||= parsed_uri.host
78
+
79
+ @raw['max_age'] = @raw['max_age'] if @raw['max_age']
80
+
81
+ @orig = self.auditable.dup
82
+ @orig.freeze
83
+ end
84
+
85
+ #
86
+ # Overrides {Capabilities::Auditable#audit} to enforce cookie exclusion
87
+ # settings from {Arachni::Options#exclude_cookies}.
88
+ #
89
+ # @see Capabilities::Auditable#audit
90
+ #
91
+ def audit( *args )
92
+ if Arachni::Options.exclude_cookies.include?( name )
93
+ auditor.print_info "Skipping audit of '#{name}' cookie."
94
+ return
95
+ end
96
+ super( *args )
97
+ end
98
+
99
+ #
100
+ # Indicates whether the cookie must be only sent over an encrypted channel.
101
+ #
102
+ # @example
103
+ # p Cookie.from_set_cookie( 'http://owner-url.com', 'session=stuffstuffstuff; secure' ).first.secure?
104
+ # #=> true
105
+ #
106
+ # p Cookie.from_set_cookie( 'http://owner-url.com', 'session=stuffstuffstuff' ).first.secure?
107
+ # #=> false
108
+ #
109
+ # @return [Bool]
110
+ #
111
+ def secure?
112
+ @raw['secure'] == true
113
+ end
114
+
115
+ #
116
+ # Indicates whether the cookie is safe from modification from client-side code.
117
+ #
118
+ # @example
119
+ # p Cookie.from_set_cookie( 'http://owner-url.com', 'session=stuffstuffstuff; httpOnly' ).first.http_only?
120
+ # #=> true
121
+ #
122
+ # p Cookie.from_set_cookie( 'http://owner-url.com', 'session=stuffstuffstuff' ).first.http_only?
123
+ # #=> false
124
+ #
125
+ # @return [Bool]
126
+ #
127
+ def http_only?
128
+ @raw['httponly'] == true
129
+ end
130
+
131
+ #
132
+ # Indicates whether the cookie is to be discarded at the end of the session.
133
+ #
134
+ # Doesn't play a role during the scan but it can provide useful info to modules and such.
135
+ #
136
+ # @example
137
+ # # doesn't have an expiration date, i.e. it should be discarded at the end of the session
138
+ # p Cookie.from_set_cookie( 'http://owner-url.com', 'session=stuffstuffstuff' ).first.session?
139
+ # #=> true
140
+ #
141
+ # # does have an expiration date, i.e. not a session cookie
142
+ # p Cookie.from_set_cookie( 'http://owner-url.com', 'session=stuffstuffstuff; Expires=Thu, 01 Jan 1970 00:00:01 GMT' ).first.session?
143
+ # #=> false
144
+ #
145
+ # @return [Bool]
146
+ #
147
+ def session?
148
+ @raw['expires'].nil?
149
+ end
150
+
151
+ #
152
+ # @example
153
+ # p Cookie.from_set_cookie( 'http://owner-url.com', 'session=stuffstuffstuff' ).first.expires_at
154
+ # #=> nil
155
+ #
156
+ # p Cookie.from_set_cookie( 'http://owner-url.com', 'session=stuffstuffstuff; Expires=Thu, 01 Jan 1970 00:00:01 GMT' ).first.expires_at
157
+ # #=> 1970-01-01 02:00:01 +0200
158
+ #
159
+ #
160
+ # @return [Time, NilClass] expiration +Time+ of the cookie or +nil+ if it
161
+ # doesn't have one (i.e. is a session cookie)
162
+ #
163
+ def expires_at
164
+ expires
165
+ end
166
+ #
167
+ # Indicates whether or not the cookie has expired.
168
+ #
169
+ # @example Without a time argument.
170
+ #
171
+ # # session cookie
172
+ # p Cookie.from_set_cookie( 'http://owner-url.com', 'session=stuffstuffstuff' ).first.expired?
173
+ # #=> false
174
+ #
175
+ # # cookie with the expiration date in the future
176
+ # p Cookie.from_set_cookie( 'http://owner-url.com', 'session=stuffstuffstuff; Expires=Thu, 01 Jan 2020 00:00:01 GMT' ).first.expired?
177
+ # #=> true
178
+ #
179
+ # # expired cookie
180
+ # p Cookie.from_set_cookie( 'http://owner-url.com', 'session=stuffstuffstuff; Expires=Thu, 01 Jan 1970 00:00:01 GMT' ).first.expired?
181
+ # #=> true
182
+ #
183
+ # @example With a time argument.
184
+ #
185
+ # future_time = Cookie.expires_to_time( 'Thu, 01 Jan 2021 00:00:01 GMT' )
186
+ #
187
+ # # session cookie
188
+ # p Cookie.from_set_cookie( 'http://owner-url.com', 'session=stuffstuffstuff' ).first.expired?( future_time )
189
+ # #=> false
190
+ #
191
+ # # cookie with the expiration date in the future
192
+ # p Cookie.from_set_cookie( 'http://owner-url.com', 'session=stuffstuffstuff; Expires=Thu, 01 Jan 2020 00:00:01 GMT' ).first.expired?( future_time )
193
+ # #=> true
194
+ #
195
+ # # expired cookie
196
+ # p Cookie.from_set_cookie( 'http://owner-url.com', 'session=stuffstuffstuff; Expires=Thu, 01 Jan 1970 00:00:01 GMT' ).first.expired?( future_time )
197
+ # #=> true
198
+ #
199
+ # @param [Time] time to compare against
200
+ #
201
+ # @return [Boolean]
202
+ #
203
+ def expired?( time = Time.now )
204
+ expires_at != nil && time > expires_at
205
+ end
206
+
207
+ #
208
+ # @example
209
+ # p Cookie.from_set_cookie( 'http://owner-url.com', 'session=stuffstuffstuff' ).first.simple
210
+ # #=> {"session"=>"stuffstuffstuff"}
211
+ #
212
+ #
213
+ # @return [Hash] simple representation of the cookie as a hash with the
214
+ # cookie name as key and the cookie value as value.
215
+ def simple
216
+ self.auditable.dup
217
+ end
218
+
219
+ # @return [String] name of the current element, 'cookie' in this case.
220
+ def type
221
+ Arachni::Element::COOKIE
222
+ end
223
+
224
+ def dup
225
+ d = super
226
+ d.action = self.action
227
+ d
228
+ end
229
+
230
+ #
231
+ # Sets auditable inputs as a key=>value pair.
232
+ #
233
+ # @example
234
+ # p c = Cookie.from_set_cookie( 'http://owner-url.com', 'session=stuffstuffstuff' ).first
235
+ # #=> ["session=stuffstuffstuff"]
236
+ #
237
+ # p c.auditable
238
+ # #=> {"session"=>"stuffstuffstuff"}
239
+ #
240
+ # p c.auditable = { 'new-name' => 'new-value' }
241
+ # #=> {"new-name"=>"new-value"}
242
+ #
243
+ # p c
244
+ # #=> new-name=new-value
245
+ #
246
+ #
247
+ # @param [Hash] inputs name => value pair
248
+ #
249
+ def auditable=( inputs )
250
+ k = inputs.keys.first.to_s
251
+ v = inputs.values.first.to_s
252
+
253
+ raw = @raw.dup
254
+ raw['name'] = k
255
+ raw['value'] = v
256
+
257
+ @raw = raw.freeze
258
+
259
+ if k.to_s.empty?
260
+ super( {} )
261
+ else
262
+ super( { k => v } )
263
+ end
264
+ end
265
+
266
+ #
267
+ # Overrides {Capabilities::Mutable#mutations} to handle cookie-specific limitations
268
+ # and the {Arachni::Options#audit_cookies_extensively} option.
269
+ #
270
+ # c = Cookie.from_set_cookie( 'http://owner-url.com', 'session=stuffstuffstuff' ).first
271
+ #
272
+ # @example Default
273
+ # p c.mutations 'seed'
274
+ # #=> [session=seed, session=stuffstuffstuffseed, session=seed%00, session=stuffstuffstuffseed%00]
275
+ #
276
+ # @example With parameter flip
277
+ # p c.mutations 'seed', param_flip: true
278
+ # #=> [session=seed, session=stuffstuffstuffseed, session=seed%00, session=stuffstuffstuffseed%00, seed=eb987f5d6a6948193f3677ee70eaedf0e1454f1eb715322ec627f0a32848f8bd]
279
+ #
280
+ # @example Extensive audit
281
+ #
282
+ # Arachni::Options.audit_cookies_extensively = true
283
+ #
284
+ # # this option presupposes that an auditor (with page) is available
285
+ # Auditor = Class.new do
286
+ # include Arachni::Module::Auditor
287
+ #
288
+ # def page
289
+ # Page.new( links: [Link.new( 'http://owner-url.com', input1: 'value1' )] )
290
+ # end
291
+ #
292
+ # def self.info
293
+ # { name: 'My custom auditor' }
294
+ # end
295
+ # end
296
+ #
297
+ # c.auditor = Auditor.new
298
+ #
299
+ # p mutations = c.mutations( 'seed' )
300
+ # #=> [session=seed, session=stuffstuffstuffseed, session=seed%00, session=stuffstuffstuffseed%00, http://owner-url.com/?input1=value1, http://owner-url.com/?input1=value1, http://owner-url.com/?input1=value1, http://owner-url.com/?input1=value1]
301
+ #
302
+ # # if we take a closer look at the Link mutations we see that this link will be submitted with various cookie mutations
303
+ # ap mutations.select { |m| m.is_a? Link }
304
+ # #=> [
305
+ # # [0] #<Arachni::Element::Link:0x02de90e8
306
+ # # @audit_id_url = "http://owner-url.com/",
307
+ # # attr_accessor :action = "http://owner-url.com/",
308
+ # # attr_accessor :altered = "mutation for the 'session' cookie",
309
+ # # attr_accessor :auditable = {
310
+ # # "input1" => "value1"
311
+ # # },
312
+ # # attr_accessor :auditor = #<Auditor:0x000000029e7648>,
313
+ # # attr_accessor :method = "get",
314
+ # # attr_accessor :url = "http://owner-url.com/",
315
+ # # attr_reader :hash = -4537574543719230301,
316
+ # # attr_reader :opts = {
317
+ # # :cookies => {
318
+ # # "session" => "seed"
319
+ # # }
320
+ # # },
321
+ # # attr_reader :orig = {
322
+ # # "input1" => "value1"
323
+ # # },
324
+ # # attr_reader :raw = {
325
+ # # :input1 => "value1"
326
+ # # }
327
+ # # >,
328
+ # # [1] #<Arachni::Element::Link:0x02df3f98
329
+ # # @audit_id_url = "http://owner-url.com/",
330
+ # # attr_accessor :action = "http://owner-url.com/",
331
+ # # attr_accessor :altered = "mutation for the 'session' cookie",
332
+ # # attr_accessor :auditable = {
333
+ # # "input1" => "value1"
334
+ # # },
335
+ # # attr_accessor :auditor = #<Auditor:0x000000029e7648>,
336
+ # # attr_accessor :method = "get",
337
+ # # attr_accessor :url = "http://owner-url.com/",
338
+ # # attr_reader :hash = -4537574543719230301,
339
+ # # attr_reader :opts = {
340
+ # # :cookies => {
341
+ # # "session" => "stuffstuffstuffseed"
342
+ # # }
343
+ # # },
344
+ # # attr_reader :orig = {
345
+ # # "input1" => "value1"
346
+ # # },
347
+ # # attr_reader :raw = {
348
+ # # :input1 => "value1"
349
+ # # }
350
+ # # >,
351
+ # # [2] #<Arachni::Element::Link:0x02adcf80
352
+ # # @audit_id_url = "http://owner-url.com/",
353
+ # # attr_accessor :action = "http://owner-url.com/",
354
+ # # attr_accessor :altered = "mutation for the 'session' cookie",
355
+ # # attr_accessor :auditable = {
356
+ # # "input1" => "value1"
357
+ # # },
358
+ # # attr_accessor :auditor = #<Auditor:0x000000029e7648>,
359
+ # # attr_accessor :method = "get",
360
+ # # attr_accessor :url = "http://owner-url.com/",
361
+ # # attr_reader :hash = -4537574543719230301,
362
+ # # attr_reader :opts = {
363
+ # # :cookies => {
364
+ # # "session" => "seed\x00"
365
+ # # }
366
+ # # },
367
+ # # attr_reader :orig = {
368
+ # # "input1" => "value1"
369
+ # # },
370
+ # # attr_reader :raw = {
371
+ # # :input1 => "value1"
372
+ # # }
373
+ # # >,
374
+ # # [3] #<Arachni::Element::Link:0x02b0c0a0
375
+ # # @audit_id_url = "http://owner-url.com/",
376
+ # # attr_accessor :action = "http://owner-url.com/",
377
+ # # attr_accessor :altered = "mutation for the 'session' cookie",
378
+ # # attr_accessor :auditable = {
379
+ # # "input1" => "value1"
380
+ # # },
381
+ # # attr_accessor :auditor = #<Auditor:0x000000029e7648>,
382
+ # # attr_accessor :method = "get",
383
+ # # attr_accessor :url = "http://owner-url.com/",
384
+ # # attr_reader :hash = -4537574543719230301,
385
+ # # attr_reader :opts = {
386
+ # # :cookies => {
387
+ # # "session" => "stuffstuffstuffseed\x00"
388
+ # # }
389
+ # # },
390
+ # # attr_reader :orig = {
391
+ # # "input1" => "value1"
392
+ # # },
393
+ # # attr_reader :raw = {
394
+ # # :input1 => "value1"
395
+ # # }
396
+ # # >
397
+ # # ]
398
+ #
399
+ #
400
+ # @see Capabilities::Mutable#mutations
401
+ #
402
+ def mutations( injection_str, opts = {} )
403
+ flip = opts.delete( :param_flip )
404
+ muts = super( injection_str, opts )
405
+
406
+ if flip
407
+ elem = self.dup
408
+
409
+ # when under HPG mode element auditing is strictly regulated
410
+ # and when we flip params we essentially create a new element
411
+ # which won't be on the whitelist
412
+ elem.override_instance_scope
413
+
414
+ elem.altered = 'Parameter flip'
415
+ elem.auditable = { injection_str => seed }
416
+ muts << elem
417
+ end
418
+
419
+ if !orphan? && Arachni::Options.audit_cookies_extensively?
420
+ # submit all links and forms of the page along with our cookie mutations
421
+ muts << muts.map do |m|
422
+ (auditor.page.links | auditor.page.forms).map do |e|
423
+ next if e.auditable.empty?
424
+ c = e.dup
425
+ c.altered = "mutation for the '#{m.altered}' cookie"
426
+ c.auditor = auditor
427
+ c.opts[:cookies] = m.auditable.dup
428
+ c.auditable = Arachni::Module::KeyFiller.fill( c.auditable.dup )
429
+ c
430
+ end
431
+ end.flatten.compact
432
+ muts.flatten!
433
+ end
434
+
435
+ muts
436
+ end
437
+
438
+ #
439
+ # Uses the method name as a key to cookie attributes in {DEFAULT}.
440
+ #
441
+ # @example
442
+ # c = Cookie.from_set_cookie( 'http://owner-url.com/stuff', 'session=stuffstuffstuff' ).first
443
+ #
444
+ # p c.name
445
+ # #=> "session"
446
+ #
447
+ # p c.value
448
+ # #=> "stuffstuffstuff"
449
+ #
450
+ # p c.path
451
+ # #=> "/stuff"
452
+ #
453
+ #
454
+ def method_missing( sym, *args, &block )
455
+ return @raw[sym.to_s] if respond_to?( sym )
456
+ super( sym, *args, &block )
457
+ end
458
+
459
+ #
460
+ # Used by {#method_missing} to determine if it should process the call.
461
+ #
462
+ # @return [Bool]
463
+ #
464
+ def respond_to?( sym )
465
+ @raw.include?( sym.to_s ) || super( sym )
466
+ end
467
+
468
+ #
469
+ # @example
470
+ # p Cookie.from_set_cookie( 'http://owner-url.com/', 'session=stuffstuffstuff' ).first.to_s
471
+ # #=> "session=stuffstuffstuff"
472
+ #
473
+ # p Cookie.new( 'http://owner-url.com/', '% ; freaky name' => 'freaky value;%' ).to_s
474
+ # #=> "%25+%3B+freaky+name=freaky+value%3B%25"
475
+ #
476
+ #
477
+ # @return [String] to be used in a 'Cookie' request header. (name=value)
478
+ #
479
+ def to_s
480
+ "#{encode( name )}=#{encode( value )}"
481
+ end
482
+
483
+ #
484
+ # Returns an array of cookies from an Netscape HTTP cookiejar file.
485
+ #
486
+ # @example Parsing a Netscape HTTP cookiejar file
487
+ #
488
+ # # Given a cookie-jar file with the following contents:
489
+ # #
490
+ # # # comment, should be ignored
491
+ # # .domain.com TRUE /path/to/somewhere TRUE Tue, 02 Oct 2012 19:25:57 GMT first_name first_value
492
+ # #
493
+ # # # ignored again
494
+ # # another-domain.com FALSE / FALSE second_name second_value
495
+ # #
496
+ # # # with expiry date as seconds since epoch
497
+ # # .blah-domain TRUE / FALSE 1596981560 NAME OP5jTLV6VhYHADJAbJ1ZR@L8~081210
498
+ #
499
+ # p Cookie.from_file 'http://owner-url.com', 'cookies.jar'
500
+ # #=> [first_name=first_value, second_name=second_value, NAME=OP5jTLV6VhYHADJAbJ1ZR@L8~081210]
501
+ #
502
+ # # And here's the fancier dump:
503
+ # # [
504
+ # # [0] #<Arachni::Element::Cookie:0x011636d0
505
+ # # attr_accessor :action = "http://owner-url.com/",
506
+ # # attr_accessor :auditable = {
507
+ # # "first_name" => "first_value"
508
+ # # },
509
+ # # attr_accessor :method = "get",
510
+ # # attr_accessor :url = "http://owner-url.com/",
511
+ # # attr_reader :hash = -473180912834263695,
512
+ # # attr_reader :opts = {},
513
+ # # attr_reader :orig = {
514
+ # # "first_name" => "first_value"
515
+ # # },
516
+ # # attr_reader :raw = {
517
+ # # "domain" => ".domain.com",
518
+ # # "path" => "/path/to/somewhere",
519
+ # # "secure" => true,
520
+ # # "expires" => 2012-10-02 22:25:57 +0300,
521
+ # # "name" => "first_name",
522
+ # # "value" => "first_value",
523
+ # # "version" => 0,
524
+ # # "port" => nil,
525
+ # # "discard" => nil,
526
+ # # "comment_url" => nil,
527
+ # # "max_age" => nil,
528
+ # # "comment" => nil,
529
+ # # "httponly" => false
530
+ # # }
531
+ # # >,
532
+ # # [1] #<Arachni::Element::Cookie:0x011527b8
533
+ # # attr_accessor :action = "http://owner-url.com/",
534
+ # # attr_accessor :auditable = {
535
+ # # "second_name" => "second_value"
536
+ # # },
537
+ # # attr_accessor :method = "get",
538
+ # # attr_accessor :url = "http://owner-url.com/",
539
+ # # attr_reader :hash = -2673771862017142861,
540
+ # # attr_reader :opts = {},
541
+ # # attr_reader :orig = {
542
+ # # "second_name" => "second_value"
543
+ # # },
544
+ # # attr_reader :raw = {
545
+ # # "domain" => "another-domain.com",
546
+ # # "path" => "/",
547
+ # # "secure" => false,
548
+ # # "expires" => nil,
549
+ # # "name" => "second_name",
550
+ # # "value" => "second_value",
551
+ # # "version" => 0,
552
+ # # "port" => nil,
553
+ # # "discard" => nil,
554
+ # # "comment_url" => nil,
555
+ # # "max_age" => nil,
556
+ # # "comment" => nil,
557
+ # # "httponly" => false
558
+ # # }
559
+ # # >,
560
+ # # [2] #<Arachni::Element::Cookie:0x011189f0
561
+ # # attr_accessor :action = "http://owner-url.com/",
562
+ # # attr_accessor :auditable = {
563
+ # # "NAME" => "OP5jTLV6VhYHADJAbJ1ZR@L8~081210"
564
+ # # },
565
+ # # attr_accessor :method = "get",
566
+ # # attr_accessor :url = "http://owner-url.com/",
567
+ # # attr_reader :hash = 4086929775905476282,
568
+ # # attr_reader :opts = {},
569
+ # # attr_reader :orig = {
570
+ # # "NAME" => "OP5jTLV6VhYHADJAbJ1ZR@L8~081210"
571
+ # # },
572
+ # # attr_reader :raw = {
573
+ # # "domain" => ".blah-domain",
574
+ # # "path" => "/",
575
+ # # "secure" => false,
576
+ # # "expires" => 2020-08-09 16:59:20 +0300,
577
+ # # "name" => "NAME",
578
+ # # "value" => "OP5jTLV6VhYHADJAbJ1ZR@L8~081210",
579
+ # # "version" => 0,
580
+ # # "port" => nil,
581
+ # # "discard" => nil,
582
+ # # "comment_url" => nil,
583
+ # # "max_age" => nil,
584
+ # # "comment" => nil,
585
+ # # "httponly" => false
586
+ # # }
587
+ # # >
588
+ # # ]
589
+ #
590
+ #
591
+ # @param [String] url request URL
592
+ # @param [String] filepath Netscape HTTP cookiejar file
593
+ #
594
+ # @return [Array<Cookie>]
595
+ #
596
+ def self.from_file( url, filepath )
597
+ File.open( filepath, 'r' ).map do |line|
598
+ # skip empty lines
599
+ next if (line = line.strip).empty? || line[0] == '#'
600
+
601
+ c = {}
602
+ c['domain'], foo, c['path'], c['secure'], c['expires'], c['name'],
603
+ c['value'] = *line.split( "\t" )
604
+
605
+ # expiry date is optional so if we don't have one push everything back
606
+ begin
607
+ c['expires'] = expires_to_time( c['expires'] )
608
+ rescue
609
+ c['value'] = c['name'].dup
610
+ c['name'] = c['expires'].dup
611
+ c['expires'] = nil
612
+ end
613
+ c['secure'] = (c['secure'] == 'TRUE') ? true : false
614
+ new( url, c )
615
+ end.flatten.compact
616
+ end
617
+
618
+ #
619
+ # Converts a cookie's expiration date to a Ruby +Time+ object.
620
+ #
621
+ # @example String time format
622
+ # p Cookie.expires_to_time "Tue, 02 Oct 2012 19:25:57 GMT"
623
+ # #=> 2012-10-02 22:25:57 +0300
624
+ #
625
+ # @example Seconds since Epoch
626
+ # p Cookie.expires_to_time "1596981560"
627
+ # #=> 2020-08-09 16:59:20 +0300
628
+ #
629
+ # p Cookie.expires_to_time 1596981560
630
+ # #=> 2020-08-09 16:59:20 +0300
631
+ #
632
+ # @param [String] expires
633
+ #
634
+ # @return [Time]
635
+ #
636
+ def self.expires_to_time( expires )
637
+ (expires_to_i = expires.to_i) > 0 ? Time.at( expires_to_i ) : Time.parse( expires )
638
+ end
639
+
640
+ #
641
+ # Returns an array of cookies from an HTTP response.
642
+ #
643
+ #
644
+ # @example
645
+ # body = <<-HTML
646
+ # <html>
647
+ # <head>
648
+ # <meta http-equiv="Set-Cookie" content="cookie=val; httponly">
649
+ # <meta http-equiv="Set-Cookie" content="cookie2=val2; Expires=Thu, 01 Jan 1970 00:00:01 GMT; Path=/; Domain=.foo.com; HttpOnly; secure">
650
+ # </head>
651
+ # </html>
652
+ # HTML
653
+ #
654
+ # response = Typhoeus::Response.new(
655
+ # body: body,
656
+ # effective_url: 'http://stuff.com',
657
+ # headers_hash: {
658
+ # 'Set-Cookie' => "coo%40ki+e2=blah+val2%40; Expires=Thu, 01 Jan 1970 00:00:01 GMT; Path=/; Domain=.foo.com; HttpOnly"
659
+ # }
660
+ # )
661
+ #
662
+ # p Cookie.from_response response
663
+ # # [cookie=val, cookie2=val2, coo@ki+e2=blah+val2@]
664
+ #
665
+ # # Fancy dump:
666
+ # # [
667
+ # # [0] #<Arachni::Element::Cookie:0x028e30f8
668
+ # # attr_accessor :action = "http://stuff.com/",
669
+ # # attr_accessor :auditable = {
670
+ # # "cookie" => "val"
671
+ # # },
672
+ # # attr_accessor :method = "get",
673
+ # # attr_accessor :url = "http://stuff.com/",
674
+ # # attr_reader :hash = 2101892390575163651,
675
+ # # attr_reader :opts = {},
676
+ # # attr_reader :orig = {
677
+ # # "cookie" => "val"
678
+ # # },
679
+ # # attr_reader :raw = {
680
+ # # "name" => "cookie",
681
+ # # "value" => "val",
682
+ # # "version" => 0,
683
+ # # "port" => nil,
684
+ # # "discard" => nil,
685
+ # # "comment_url" => nil,
686
+ # # "expires" => nil,
687
+ # # "max_age" => nil,
688
+ # # "comment" => nil,
689
+ # # "secure" => nil,
690
+ # # "path" => "/",
691
+ # # "domain" => "stuff.com",
692
+ # # "httponly" => true
693
+ # # }
694
+ # # >,
695
+ # # [1] #<Arachni::Element::Cookie:0x028ec0e0
696
+ # # attr_accessor :action = "http://stuff.com/",
697
+ # # attr_accessor :auditable = {
698
+ # # "cookie2" => "val2"
699
+ # # },
700
+ # # attr_accessor :method = "get",
701
+ # # attr_accessor :url = "http://stuff.com/",
702
+ # # attr_reader :hash = 1525536412599744532,
703
+ # # attr_reader :opts = {},
704
+ # # attr_reader :orig = {
705
+ # # "cookie2" => "val2"
706
+ # # },
707
+ # # attr_reader :raw = {
708
+ # # "name" => "cookie2",
709
+ # # "value" => "val2",
710
+ # # "version" => 0,
711
+ # # "port" => nil,
712
+ # # "discard" => nil,
713
+ # # "comment_url" => nil,
714
+ # # "expires" => 1970-01-01 02:00:01 +0200,
715
+ # # "max_age" => nil,
716
+ # # "comment" => nil,
717
+ # # "secure" => true,
718
+ # # "path" => "/",
719
+ # # "domain" => ".foo.com",
720
+ # # "httponly" => true
721
+ # # }
722
+ # # >,
723
+ # # [2] #<Arachni::Element::Cookie:0x028ef3f8
724
+ # # attr_accessor :action = "http://stuff.com/",
725
+ # # attr_accessor :auditable = {
726
+ # # "coo@ki e2" => "blah val2@"
727
+ # # },
728
+ # # attr_accessor :method = "get",
729
+ # # attr_accessor :url = "http://stuff.com/",
730
+ # # attr_reader :hash = 3179884445716720825,
731
+ # # attr_reader :opts = {},
732
+ # # attr_reader :orig = {
733
+ # # "coo@ki e2" => "blah val2@"
734
+ # # },
735
+ # # attr_reader :raw = {
736
+ # # "name" => "coo@ki e2",
737
+ # # "value" => "blah val2@",
738
+ # # "version" => 0,
739
+ # # "port" => nil,
740
+ # # "discard" => nil,
741
+ # # "comment_url" => nil,
742
+ # # "expires" => 1970-01-01 02:00:01 +0200,
743
+ # # "max_age" => nil,
744
+ # # "comment" => nil,
745
+ # # "secure" => nil,
746
+ # # "path" => "/",
747
+ # # "domain" => ".foo.com",
748
+ # # "httponly" => true
749
+ # # }
750
+ # # >
751
+ # # ]
752
+ #
753
+ # @param [Typhoeus::Response] response
754
+ #
755
+ # @return [Array<Cookie>]
756
+ #
757
+ # @see from_document
758
+ # @see from_headers
759
+ #
760
+ def self.from_response( response )
761
+ ( from_document( response.effective_url, response.body ) |
762
+ from_headers( response.effective_url, response.headers_hash ) )
763
+ end
764
+
765
+ #
766
+ # Returns an array of cookies from a document based on +Set-Cookie+ http-equiv meta tags.
767
+ #
768
+ # @example
769
+ #
770
+ # body = <<-HTML
771
+ # <html>
772
+ # <head>
773
+ # <meta http-equiv="Set-Cookie" content="cookie=val; httponly">
774
+ # <meta http-equiv="Set-Cookie" content="cookie2=val2; Expires=Thu, 01 Jan 1970 00:00:01 GMT; Path=/; Domain=.foo.com; HttpOnly; secure">
775
+ # </head>
776
+ # </html>
777
+ # HTML
778
+ #
779
+ # p Cookie.from_document 'http://owner-url.com', body
780
+ # #=> [cookie=val, cookie2=val2]
781
+ #
782
+ # p Cookie.from_document 'http://owner-url.com', Nokogiri::HTML( body )
783
+ # #=> [cookie=val, cookie2=val2]
784
+ #
785
+ # # Fancy dump:
786
+ # # [
787
+ # # [0] #<Arachni::Element::Cookie:0x02a23030
788
+ # # attr_accessor :action = "http://owner-url.com/",
789
+ # # attr_accessor :auditable = {
790
+ # # "cookie" => "val"
791
+ # # },
792
+ # # attr_accessor :method = "get",
793
+ # # attr_accessor :url = "http://owner-url.com/",
794
+ # # attr_reader :hash = 1135494168462266792,
795
+ # # attr_reader :opts = {},
796
+ # # attr_reader :orig = {
797
+ # # "cookie" => "val"
798
+ # # },
799
+ # # attr_reader :raw = {
800
+ # # "name" => "cookie",
801
+ # # "value" => "val",
802
+ # # "version" => 0,
803
+ # # "port" => nil,
804
+ # # "discard" => nil,
805
+ # # "comment_url" => nil,
806
+ # # "expires" => nil,
807
+ # # "max_age" => nil,
808
+ # # "comment" => nil,
809
+ # # "secure" => nil,
810
+ # # "path" => "/",
811
+ # # "domain" => "owner-url.com",
812
+ # # "httponly" => true
813
+ # # }
814
+ # # >,
815
+ # # [1] #<Arachni::Element::Cookie:0x026745b0
816
+ # # attr_accessor :action = "http://owner-url.com/",
817
+ # # attr_accessor :auditable = {
818
+ # # "cookie2" => "val2"
819
+ # # },
820
+ # # attr_accessor :method = "get",
821
+ # # attr_accessor :url = "http://owner-url.com/",
822
+ # # attr_reader :hash = -765632517082248204,
823
+ # # attr_reader :opts = {},
824
+ # # attr_reader :orig = {
825
+ # # "cookie2" => "val2"
826
+ # # },
827
+ # # attr_reader :raw = {
828
+ # # "name" => "cookie2",
829
+ # # "value" => "val2",
830
+ # # "version" => 0,
831
+ # # "port" => nil,
832
+ # # "discard" => nil,
833
+ # # "comment_url" => nil,
834
+ # # "expires" => 1970-01-01 02:00:01 +0200,
835
+ # # "max_age" => nil,
836
+ # # "comment" => nil,
837
+ # # "secure" => true,
838
+ # # "path" => "/",
839
+ # # "domain" => ".foo.com",
840
+ # # "httponly" => true
841
+ # # }
842
+ # # >
843
+ # # ]
844
+ #
845
+ # @param [String] url owner URL
846
+ # @param [String, Nokogiri::HTML::Document] document
847
+ #
848
+ # @return [Array<Cookie>]
849
+ #
850
+ # @see parse_set_cookie
851
+ #
852
+ def self.from_document( url, document )
853
+ # optimizations in case there are no cookies in the doc,
854
+ # avoid parsing unless absolutely necessary!
855
+ if !document.is_a?( Nokogiri::HTML::Document )
856
+ # get get the head in order to check if it has an http-equiv for set-cookie
857
+ head = document.to_s.match( /<head(.*)<\/head>/imx )
858
+
859
+ # if it does feed the head to the parser in order to extract the cookies
860
+ return [] if !head || !head.to_s.downcase.substring?( 'set-cookie' )
861
+
862
+ document = Nokogiri::HTML( head.to_s )
863
+ end
864
+
865
+ Arachni::Utilities.exception_jail {
866
+ document.search( "//meta[@http-equiv]" ).map do |elem|
867
+ next if elem['http-equiv'].downcase != 'set-cookie'
868
+ parse_set_cookie( url, elem['content'] )
869
+ end.flatten.compact
870
+ } rescue []
871
+ end
872
+
873
+ #
874
+ # Returns an array of cookies from the +Set-Cookie+ header field.
875
+ #
876
+ # @example
877
+ # p Cookie.from_headers 'http://owner-url.com', { 'Set-Cookie' => "coo%40ki+e2=blah+val2%40" }
878
+ # #=> [coo@ki+e2=blah+val2@]
879
+ #
880
+ # # Fancy dump:
881
+ # # [
882
+ # # [0] #<Arachni::Element::Cookie:0x01e17250
883
+ # # attr_accessor :action = "http://owner-url.com/",
884
+ # # attr_accessor :auditable = {
885
+ # # "coo@ki e2" => "blah val2@"
886
+ # # },
887
+ # # attr_accessor :method = "get",
888
+ # # attr_accessor :url = "http://owner-url.com/",
889
+ # # attr_reader :hash = -1249755840178478661,
890
+ # # attr_reader :opts = {},
891
+ # # attr_reader :orig = {
892
+ # # "coo@ki e2" => "blah val2@"
893
+ # # },
894
+ # # attr_reader :raw = {
895
+ # # "name" => "coo@ki e2",
896
+ # # "value" => "blah val2@",
897
+ # # "version" => 0,
898
+ # # "port" => nil,
899
+ # # "discard" => nil,
900
+ # # "comment_url" => nil,
901
+ # # "expires" => nil,
902
+ # # "max_age" => nil,
903
+ # # "comment" => nil,
904
+ # # "secure" => nil,
905
+ # # "path" => "/",
906
+ # # "domain" => "owner-url.com",
907
+ # # "httponly" => false
908
+ # # }
909
+ # # >
910
+ # # ]
911
+ #
912
+ # @param [String] url request URL
913
+ # @param [Hash] headers
914
+ #
915
+ # @return [Array<Cookie>]
916
+ #
917
+ # @see forms_set_cookie
918
+ #
919
+ def self.from_headers( url, headers )
920
+ set_strings = []
921
+ headers.each { |k, v| set_strings = [v].flatten if k.downcase == 'set-cookie' }
922
+
923
+ return set_strings if set_strings.empty?
924
+ exception_jail {
925
+ set_strings.map { |c| parse_set_cookie( url, c ) }.flatten
926
+ } rescue []
927
+ end
928
+
929
+ #
930
+ # Parses the +Set-Cookie+ header value into cookie elements.
931
+ #
932
+ # @example
933
+ # p Cookie.from_set_cookie 'http://owner-url.com', "coo%40ki+e2=blah+val2%40"
934
+ # #=> [coo@ki+e2=blah+val2@]
935
+ #
936
+ # # Fancy dump:
937
+ # # [
938
+ # # [0] #<Arachni::Element::Cookie:0x01e17250
939
+ # # attr_accessor :action = "http://owner-url.com/",
940
+ # # attr_accessor :auditable = {
941
+ # # "coo@ki e2" => "blah val2@"
942
+ # # },
943
+ # # attr_accessor :method = "get",
944
+ # # attr_accessor :url = "http://owner-url.com/",
945
+ # # attr_reader :hash = -1249755840178478661,
946
+ # # attr_reader :opts = {},
947
+ # # attr_reader :orig = {
948
+ # # "coo@ki e2" => "blah val2@"
949
+ # # },
950
+ # # attr_reader :raw = {
951
+ # # "name" => "coo@ki e2",
952
+ # # "value" => "blah val2@",
953
+ # # "version" => 0,
954
+ # # "port" => nil,
955
+ # # "discard" => nil,
956
+ # # "comment_url" => nil,
957
+ # # "expires" => nil,
958
+ # # "max_age" => nil,
959
+ # # "comment" => nil,
960
+ # # "secure" => nil,
961
+ # # "path" => "/",
962
+ # # "domain" => "owner-url.com",
963
+ # # "httponly" => false
964
+ # # }
965
+ # # >
966
+ # # ]
967
+ #
968
+ #
969
+ # @param [String] url request URL
970
+ # @param [Hash] str +Set-Cookie+ string
971
+ #
972
+ # @return [Array<Cookie>]
973
+ #
974
+ def self.from_set_cookie( url, str )
975
+ WEBrick::Cookie.parse_set_cookies( str ).flatten.uniq.map do |cookie|
976
+ cookie_hash = {}
977
+ cookie.instance_variables.each do |var|
978
+ cookie_hash[var.to_s.gsub( /@/, '' )] = cookie.instance_variable_get( var )
979
+ end
980
+ cookie_hash['expires'] = cookie.expires
981
+
982
+ cookie_hash['name'] = decode( cookie.name )
983
+ cookie_hash['value'] = decode( cookie.value )
984
+
985
+ new( url.to_s, cookie_hash )
986
+ end.flatten.compact
987
+ end
988
+ def self.parse_set_cookie( *args )
989
+ from_set_cookie( *args )
990
+ end
991
+
992
+ #
993
+ # Encodes a {String}'s reserved characters in order to prepare it for
994
+ # the 'Cookie' header field.
995
+ #
996
+ # #example
997
+ # p Cookie.encode "+;%=\0 "
998
+ # #=> "%2B%3B%25%3D%00+"
999
+ #
1000
+ # @param [String] str
1001
+ #
1002
+ # @return [String] the encoded string
1003
+ #
1004
+ def self.encode( str )
1005
+ URI.encode( str, "+;%=\0" ).gsub( ' ', '+' )
1006
+ end
1007
+ # @see .encode
1008
+ def encode( str )
1009
+ self.class.encode( str )
1010
+ end
1011
+
1012
+ #
1013
+ # Decodes a {String} encoded for the +Cookie+ header field.
1014
+ #
1015
+ # @example
1016
+ # p Cookie.decode "%2B%3B%25%3D%00+"
1017
+ # #=> "+;%=\x00 "
1018
+ #
1019
+ # @param [String] str
1020
+ #
1021
+ # @return [String] the decoded string
1022
+ #
1023
+ def self.decode( str )
1024
+ URI.decode( str.gsub( '+', ' ' ) )
1025
+ end
1026
+ # @see .decode
1027
+ def decode( str )
1028
+ self.class.decode( str )
1029
+ end
1030
+
1031
+ private
1032
+ def http_request( opts = {}, &block )
1033
+ opts[:cookies] = opts[:params].dup
1034
+ opts[:params] = {}
1035
+
1036
+ self.method.downcase.to_s != 'get' ?
1037
+ http.post( self.action, opts, &block ) : http.get( self.action, opts, &block )
1038
+ end
1039
+
1040
+ end
1041
+ end
1042
+
1043
+ Arachni::Cookie = Arachni::Element::Cookie