watobo 0.9.12 → 0.9.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (263) hide show
  1. data/.yardopts +2 -2
  2. data/{CHANGELOG → CHANGELOG.md} +62 -0
  3. data/README.md +30 -0
  4. data/bin/nfq_server.rb +4 -3
  5. data/bin/watobo_gui.rb +1 -1
  6. data/config/ott_cache.yml +4 -0
  7. data/config/scanner.yml +1 -18
  8. data/config/sid_cache.yml +14 -0
  9. data/extras/private-hostspot.sh +17 -0
  10. data/extras/watobo-installer.sh +61 -0
  11. data/extras/watobo-transparent.sh +38 -0
  12. data/icons/BestPractice_16x16.ico +0 -0
  13. data/icons/BestPractice_24x24.ico +0 -0
  14. data/lib/watobo/adapters/data_store.rb +25 -3
  15. data/lib/watobo/adapters/file/file_store.rb +19 -11
  16. data/lib/watobo/adapters/session_store.rb +3 -2
  17. data/lib/watobo/adapters.rb +1 -1
  18. data/lib/watobo/ca.rb +1 -1
  19. data/lib/watobo/config.rb +17 -19
  20. data/lib/watobo/constants.rb +3 -2
  21. data/lib/watobo/core/active_check.rb +62 -40
  22. data/lib/watobo/core/active_checks.rb +73 -0
  23. data/lib/watobo/core/ca.rb +3 -2
  24. data/lib/watobo/core/cert_store.rb +3 -2
  25. data/lib/watobo/core/chat.rb +122 -0
  26. data/lib/watobo/core/chats.rb +301 -0
  27. data/lib/watobo/core/conversation.rb +71 -0
  28. data/lib/watobo/core/cookie.rb +9 -25
  29. data/lib/watobo/core/finding.rb +89 -0
  30. data/lib/watobo/core/findings.rb +132 -0
  31. data/lib/watobo/core/forwarding_proxy.rb +4 -2
  32. data/lib/watobo/core/fuzz_gen.rb +3 -2
  33. data/lib/watobo/core/intercept_carver.rb +24 -12
  34. data/lib/watobo/core/intercept_filter.rb +4 -3
  35. data/lib/watobo/core/interceptor.rb +9 -888
  36. data/lib/watobo/core/min_class.rb +27 -0
  37. data/lib/watobo/core/netfilter_queue.rb +3 -2
  38. data/lib/watobo/core/ott_cache.rb +156 -0
  39. data/lib/watobo/core/parameter.rb +66 -0
  40. data/lib/watobo/core/passive_check.rb +15 -22
  41. data/lib/watobo/core/passive_checks.rb +72 -0
  42. data/lib/watobo/core/passive_scanner.rb +69 -0
  43. data/lib/watobo/core/plugin.rb +33 -0
  44. data/lib/watobo/core/project.rb +40 -547
  45. data/lib/watobo/core/proxy.rb +7 -2
  46. data/lib/watobo/core/request.rb +95 -10
  47. data/lib/watobo/core/response.rb +44 -3
  48. data/lib/watobo/core/scanner.rb +6 -7
  49. data/lib/watobo/core/scanner3.rb +439 -0
  50. data/lib/watobo/core/scope.rb +106 -0
  51. data/lib/watobo/core/session.rb +106 -286
  52. data/lib/watobo/core/sid_cache.rb +121 -0
  53. data/lib/watobo/core/subscriber.rb +48 -0
  54. data/lib/watobo/core.rb +2 -2
  55. data/lib/watobo/defaults.rb +3 -2
  56. data/lib/watobo/external/diff/lcs/array.rb +1 -1
  57. data/lib/watobo/external/diff/lcs/block.rb +1 -1
  58. data/lib/watobo/external/diff/lcs/callbacks.rb +1 -1
  59. data/lib/watobo/external/diff/lcs/change.rb +1 -1
  60. data/lib/watobo/external/diff/lcs/hunk.rb +1 -1
  61. data/lib/watobo/external/diff/lcs/ldiff.rb +1 -1
  62. data/lib/watobo/external/diff/lcs/string.rb +1 -1
  63. data/lib/watobo/external/diff/lcs.rb +1 -1
  64. data/lib/watobo/external/ntlm/ntlm.rb +1 -1
  65. data/lib/watobo/externals.rb +1 -1
  66. data/lib/watobo/framework/create_project.rb +19 -12
  67. data/lib/watobo/framework/init.rb +4 -3
  68. data/lib/watobo/framework/init_modules.rb +32 -3
  69. data/lib/watobo/framework/license_text.rb +3 -2
  70. data/lib/watobo/framework/load_chat.rb +36 -0
  71. data/lib/watobo/framework.rb +2 -2
  72. data/lib/watobo/gui/about_watobo.rb +3 -2
  73. data/lib/watobo/gui/browser_preview.rb +4 -3
  74. data/lib/watobo/gui/certificate_dialog.rb +3 -2
  75. data/lib/watobo/gui/chat_diff.rb +6 -14
  76. data/lib/watobo/gui/chatviewer_frame.rb +30 -5
  77. data/lib/watobo/gui/checkboxtree.rb +13 -12
  78. data/lib/watobo/gui/checks_policy_frame.rb +8 -10
  79. data/lib/watobo/gui/client_cert_dialog.rb +8 -6
  80. data/lib/watobo/gui/confirm_scan_dialog.rb +5 -3
  81. data/lib/watobo/gui/conversation_table.rb +288 -51
  82. data/lib/watobo/gui/conversation_table_ctrl.rb +36 -3
  83. data/lib/watobo/gui/conversation_table_ctrl2.rb +416 -0
  84. data/lib/watobo/gui/csrf_token_dialog.rb +25 -33
  85. data/lib/watobo/gui/dashboard.rb +47 -45
  86. data/lib/watobo/gui/define_scope_frame.rb +27 -22
  87. data/lib/watobo/gui/differ_frame.rb +238 -0
  88. data/lib/watobo/gui/edit_comment.rb +3 -2
  89. data/lib/watobo/gui/edit_scope_dialog.rb +7 -6
  90. data/lib/watobo/gui/finding_info.rb +3 -2
  91. data/lib/watobo/gui/findings_tree.rb +101 -26
  92. data/lib/watobo/gui/full_scan_dialog.rb +5 -6
  93. data/lib/watobo/gui/fuzzer_gui.rb +51 -18
  94. data/lib/watobo/gui/goto_url_dialog.rb +92 -0
  95. data/lib/watobo/gui/hex_viewer.rb +16 -5
  96. data/lib/watobo/gui/html_viewer.rb +309 -0
  97. data/lib/watobo/gui/intercept_filter_dialog.rb +3 -2
  98. data/lib/watobo/gui/interceptor_gui.rb +5 -4
  99. data/lib/watobo/gui/interceptor_settings_dialog.rb +4 -3
  100. data/lib/watobo/gui/list_box.rb +4 -3
  101. data/lib/watobo/gui/log_file_viewer.rb +55 -0
  102. data/lib/watobo/gui/log_viewer.rb +3 -82
  103. data/lib/watobo/gui/login_wizzard.rb +3 -3
  104. data/lib/watobo/gui/main_window.rb +183 -164
  105. data/lib/watobo/gui/manual_request_editor.rb +157 -642
  106. data/lib/watobo/gui/master_pw_dialog.rb +3 -2
  107. data/lib/watobo/gui/mixins/gui_settings.rb +3 -2
  108. data/lib/watobo/gui/page_tree.rb +3 -2
  109. data/lib/watobo/gui/password_policy_dialog.rb +3 -2
  110. data/lib/watobo/gui/plugin_board.rb +103 -73
  111. data/lib/watobo/gui/preferences_dialog.rb +3 -2
  112. data/lib/watobo/gui/progress_window.rb +3 -2
  113. data/lib/watobo/gui/project_wizzard.rb +3 -2
  114. data/lib/watobo/gui/proxy_dialog.rb +3 -2
  115. data/lib/watobo/gui/quick_scan_dialog.rb +17 -32
  116. data/lib/watobo/gui/request_builder_frame.rb +134 -0
  117. data/lib/watobo/gui/request_editor.rb +14 -9
  118. data/lib/watobo/gui/rewrite_filters_dialog.rb +4 -3
  119. data/lib/watobo/gui/rewrite_rules_dialog.rb +4 -3
  120. data/lib/watobo/gui/save_chat_dialog.rb +7 -3
  121. data/lib/watobo/gui/scanner_settings_dialog.rb +4 -3
  122. data/lib/watobo/gui/select_chat_dialog.rb +15 -25
  123. data/lib/watobo/gui/session_management_dialog.rb +21 -25
  124. data/lib/watobo/gui/sites_tree.rb +5 -4
  125. data/lib/watobo/gui/status_bar.rb +3 -2
  126. data/lib/watobo/gui/table_editor.rb +398 -386
  127. data/lib/watobo/gui/tagless_viewer.rb +3 -2
  128. data/lib/watobo/gui/templates/plugin.rb +3 -2
  129. data/lib/watobo/gui/templates/plugin2.rb +4 -3
  130. data/lib/watobo/gui/templates/plugin_base.rb +168 -0
  131. data/lib/watobo/gui/text_viewer.rb +49 -3
  132. data/lib/watobo/gui/transcoder_window.rb +3 -2
  133. data/lib/watobo/gui/utils/gui_utils.rb +5 -4
  134. data/lib/watobo/gui/utils/init_icons.rb +5 -2
  135. data/lib/watobo/gui/utils/load_icons.rb +3 -2
  136. data/lib/watobo/gui/utils/load_plugins.rb +22 -5
  137. data/lib/watobo/gui/utils/master_password.rb +3 -2
  138. data/lib/watobo/gui/utils/save_default_settings.rb +7 -5
  139. data/lib/watobo/gui/utils/save_project_settings.rb +1 -1
  140. data/lib/watobo/gui/utils/save_proxy_settings.rb +4 -3
  141. data/lib/watobo/gui/utils/save_scanner_settings.rb +5 -4
  142. data/lib/watobo/gui/utils/session_history.rb +3 -2
  143. data/lib/watobo/gui/workspace_dialog.rb +3 -2
  144. data/lib/watobo/gui/www_auth_dialog.rb +4 -3
  145. data/lib/watobo/gui/xml_viewer_frame.rb +3 -2
  146. data/lib/watobo/gui.rb +6 -3
  147. data/lib/watobo/http/cookies/cookies.rb +66 -0
  148. data/lib/watobo/http/data/data.rb +68 -0
  149. data/lib/watobo/{gui/mixins/subscriber.rb → http/url/url.rb} +33 -19
  150. data/lib/watobo/http_socket/agent.rb +851 -0
  151. data/lib/watobo/http_socket/client_socket.rb +290 -0
  152. data/lib/watobo/http_socket/connection.rb +423 -0
  153. data/lib/watobo/http_socket/http_socket.rb +273 -0
  154. data/lib/watobo/http_socket/ntlm_auth.rb +152 -0
  155. data/lib/watobo/http_socket/proxy.rb +31 -0
  156. data/lib/watobo/http_socket.rb +25 -0
  157. data/lib/watobo/interceptor/proxy.rb +883 -0
  158. data/lib/watobo/interceptor/transparent.rb +37 -0
  159. data/lib/watobo/interceptor.rb +25 -0
  160. data/lib/watobo/mixins/check_info.rb +50 -0
  161. data/lib/watobo/mixins/httpparser.rb +92 -20
  162. data/lib/watobo/mixins/request_parser.rb +103 -88
  163. data/lib/watobo/mixins/shapers.rb +42 -11
  164. data/lib/watobo/mixins/transcoders.rb +61 -57
  165. data/lib/watobo/mixins.rb +3 -2
  166. data/lib/watobo/parser/html.rb +106 -0
  167. data/lib/watobo/parser.rb +22 -0
  168. data/lib/watobo/utils/check_regex.rb +3 -2
  169. data/lib/watobo/utils/copy_object.rb +3 -2
  170. data/lib/watobo/utils/crypto.rb +3 -2
  171. data/lib/watobo/utils/expand_range.rb +3 -2
  172. data/lib/watobo/utils/file_management.rb +7 -3
  173. data/lib/watobo/utils/hexprint.rb +3 -2
  174. data/lib/watobo/utils/load_chat.rb +4 -3
  175. data/lib/watobo/utils/load_icon.rb +3 -2
  176. data/lib/watobo/utils/print_debug.rb +3 -2
  177. data/lib/watobo/utils/response_builder.rb +6 -4
  178. data/lib/watobo/utils/response_hash.rb +66 -49
  179. data/lib/watobo/utils/secure_eval.rb +3 -2
  180. data/lib/watobo/utils/strings.rb +3 -2
  181. data/lib/watobo/utils/text2request.rb +4 -5
  182. data/lib/watobo/utils/url.rb +46 -0
  183. data/lib/watobo/utils.rb +3 -2
  184. data/lib/watobo.rb +13 -3
  185. data/modules/active/Apache/mod_status.rb +15 -11
  186. data/modules/active/Flash/crossdomain.rb +17 -14
  187. data/modules/active/RoR/cve_2013_015x.rb +21 -0
  188. data/modules/active/directories/dirwalker.rb +10 -16
  189. data/modules/active/discovery/fileextensions.rb +10 -7
  190. data/modules/active/discovery/http_methods.rb +8 -9
  191. data/modules/active/domino/domino_db.rb +10 -11
  192. data/modules/active/dotNET/custom_errors.rb +124 -0
  193. data/modules/active/dotNET/dotnet_files.rb +112 -0
  194. data/modules/active/fileinclusion/lfi_simple.rb +9 -7
  195. data/modules/active/jboss/jboss_basic.rb +12 -9
  196. data/modules/active/sap/its_commands.rb +10 -9
  197. data/modules/active/sap/its_service_parameter.rb +10 -9
  198. data/modules/active/sap/its_services.rb +10 -9
  199. data/modules/active/sap/its_xss.rb +11 -10
  200. data/modules/active/siebel/siebel_apps.rb +14 -16
  201. data/modules/active/sqlinjection/sql_boolean.rb +139 -75
  202. data/modules/active/sqlinjection/sqli_error.rb +9 -6
  203. data/modules/active/sqlinjection/sqli_timing.rb +13 -11
  204. data/modules/active/xml/xml_xxe.rb +134 -0
  205. data/modules/active/xss/{xss_rated.rb → xss_ng.rb} +89 -56
  206. data/modules/active/xss/xss_simple.rb +9 -6
  207. data/modules/passive/ajax.rb +85 -0
  208. data/modules/passive/autocomplete.rb +78 -0
  209. data/modules/passive/cookie_options.rb +3 -2
  210. data/modules/passive/cookie_xss.rb +3 -2
  211. data/modules/passive/detect_code.rb +7 -4
  212. data/modules/passive/detect_fileupload.rb +3 -2
  213. data/modules/passive/detect_infrastructure.rb +7 -4
  214. data/modules/passive/detect_one_time_tokens.rb +3 -2
  215. data/modules/passive/dirindexing.rb +3 -2
  216. data/modules/passive/disclosure_domino.rb +3 -2
  217. data/modules/passive/disclosure_emails.rb +3 -2
  218. data/modules/passive/disclosure_ipaddr.rb +3 -2
  219. data/modules/passive/filename_as_parameter.rb +3 -2
  220. data/modules/passive/form_spotter.rb +10 -7
  221. data/modules/passive/hidden_fields.rb +73 -0
  222. data/modules/passive/hotspots.rb +7 -4
  223. data/modules/passive/in_script_parameter.rb +3 -2
  224. data/modules/passive/multiple_server_headers.rb +4 -3
  225. data/modules/passive/possible_login.rb +3 -2
  226. data/modules/passive/redirect_url.rb +3 -2
  227. data/modules/passive/redirectionz.rb +6 -3
  228. data/modules/passive/xss_dom.rb +16 -9
  229. data/plugins/catalog/catalog.rb +119 -193
  230. data/plugins/crawler/crawler.rb +4 -3
  231. data/plugins/crawler/gui/auth_frame.rb +3 -2
  232. data/plugins/crawler/gui/crawler_gui.rb +3 -2
  233. data/plugins/crawler/gui/general_settings_frame.rb +3 -2
  234. data/plugins/crawler/gui/hooks_frame.rb +3 -2
  235. data/plugins/crawler/gui/scope_frame.rb +3 -2
  236. data/plugins/crawler/gui/settings_tabbook.rb +3 -2
  237. data/plugins/crawler/gui/status_frame.rb +3 -2
  238. data/plugins/crawler/gui.rb +3 -2
  239. data/plugins/crawler/lib/bags.rb +3 -2
  240. data/plugins/crawler/lib/constants.rb +3 -2
  241. data/plugins/crawler/lib/engine.rb +3 -2
  242. data/plugins/crawler/lib/grabber.rb +3 -2
  243. data/plugins/crawler/lib/uri_mp.rb +1 -1
  244. data/plugins/filefinder/filefinder.rb +92 -70
  245. data/plugins/sqlmap/bin/test.rb +3 -2
  246. data/plugins/sqlmap/gui/main.rb +3 -2
  247. data/plugins/sqlmap/gui/options_frame.rb +4 -3
  248. data/plugins/sqlmap/gui.rb +1 -1
  249. data/plugins/sqlmap/lib/sqlmap_ctrl.rb +3 -2
  250. data/plugins/sqlmap/sqlmap.rb +1 -1
  251. data/plugins/sslchecker/cli/sslchecker_cli.rb +1 -1
  252. data/plugins/sslchecker/gui/cipher_table.rb +17 -10
  253. data/plugins/sslchecker/gui/gui.rb +59 -56
  254. data/plugins/sslchecker/gui/sslchecker.rb +1 -1
  255. data/plugins/sslchecker/lib/check.rb +43 -18
  256. data/plugins/wshell/gui/main.rb +130 -0
  257. data/plugins/wshell/icons/wsh.ico +0 -0
  258. data/plugins/wshell/lib/core.rb +99 -0
  259. data/plugins/wshell/wshell.rb +33 -0
  260. metadata +80 -8
  261. data/README +0 -26
  262. data/lib/watobo/core/http_socket.rb +0 -161
  263. data/lib/watobo/gui/plugin/base.rb +0 -82
@@ -0,0 +1,37 @@
1
+ # .
2
+ # transparent.rb
3
+ #
4
+ # Copyright 2013 by siberas, http://www.siberas.de
5
+ #
6
+ # This file is part of WATOBO (Web Application Tool Box)
7
+ # http://watobo.sourceforge.com
8
+ #
9
+ # WATOBO is free software; you can redistribute it and/or modify
10
+ # it under the terms of the GNU General Public License as published by
11
+ # the Free Software Foundation version 2 of the License.
12
+ #
13
+ # WATOBO is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License
19
+ # along with WATOBO; if not, write to the Free Software
20
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
+ # .
22
+ # @private
23
+ module Watobo#:nodoc: all
24
+ module Interceptor
25
+ module Transparent
26
+ @nfq_drb = nil
27
+ def self.start
28
+ DRb.start_service
29
+ @nfq_drb = DRbObject.new nil, "druby://127.0.0.1:9090"
30
+ end
31
+
32
+ def self.info(data)
33
+ @nfq_drb.info(data)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,25 @@
1
+ # .
2
+ # interceptor.rb
3
+ #
4
+ # Copyright 2013 by siberas, http://www.siberas.de
5
+ #
6
+ # This file is part of WATOBO (Web Application Tool Box)
7
+ # http://watobo.sourceforge.com
8
+ #
9
+ # WATOBO is free software; you can redistribute it and/or modify
10
+ # it under the terms of the GNU General Public License as published by
11
+ # the Free Software Foundation version 2 of the License.
12
+ #
13
+ # WATOBO is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License
19
+ # along with WATOBO; if not, write to the Free Software
20
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
+ # .
22
+ %w( proxy transparent ).each do |lib|
23
+ require "watobo/interceptor/#{lib}"
24
+ end
25
+
@@ -0,0 +1,50 @@
1
+ # .
2
+ # check_info.rb
3
+ #
4
+ # Copyright 2013 by siberas, http://www.siberas.de
5
+ #
6
+ # This file is part of WATOBO (Web Application Tool Box)
7
+ # http://watobo.sourceforge.com
8
+ #
9
+ # WATOBO is free software; you can redistribute it and/or modify
10
+ # it under the terms of the GNU General Public License as published by
11
+ # the Free Software Foundation version 2 of the License.
12
+ #
13
+ # WATOBO is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License
19
+ # along with WATOBO; if not, write to the Free Software
20
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
+ # .
22
+ # @private
23
+ module Watobo#:nodoc: all
24
+ module CheckInfoMixin
25
+ module InfoMethods
26
+ def check_name
27
+
28
+ #puts self.methods.sort
29
+ info = instance_variable_get("@info")
30
+ return nil if info.nil?
31
+ return info[:check_name]
32
+ end
33
+
34
+ def check_group
35
+ info = instance_variable_get("@info")
36
+ return nil if info.nil?
37
+ return info[:check_group]
38
+ end
39
+
40
+ end
41
+
42
+ extend InfoMethods
43
+
44
+ def self.included( other )
45
+ other.extend InfoMethods
46
+ end
47
+ #:name => "#{check.info[:check_group]}|#{check.info[:check_name]}",
48
+
49
+ end
50
+ end
@@ -1,7 +1,7 @@
1
1
  # .
2
2
  # httpparser.rb
3
3
  #
4
- # Copyright 2012 by siberas, http://www.siberas.de
4
+ # Copyright 2013 by siberas, http://www.siberas.de
5
5
  #
6
6
  # This file is part of WATOBO (Web Application Tool Box)
7
7
  # http://watobo.sourceforge.com
@@ -36,9 +36,18 @@
36
36
  # fext = "php"
37
37
  # path_ext = "my/path/show.php?p=aaa&debug=true"
38
38
 
39
- module Watobo
39
+ # @private
40
+ module Watobo#:nodoc: all
40
41
  module Mixin
41
42
  module Parser
43
+
44
+ module Parameters
45
+ def each(prefs, &block)
46
+
47
+
48
+ end
49
+ end
50
+
42
51
  module Url
43
52
  include Watobo::Constants
44
53
  def file
@@ -95,6 +104,18 @@ module Watobo
95
104
  return nil
96
105
  end
97
106
  end
107
+
108
+ def method_get?
109
+ return false if method.nil?
110
+ return true if method =~ /^get$/i
111
+ return false
112
+ end
113
+
114
+ def method_post?
115
+ return false if method.nil?
116
+ return true if method =~ /^post$/i
117
+ return false
118
+ end
98
119
 
99
120
  #The path may consist of a sequence of path segments separated by a
100
121
  #single slash "/" character. Within a path segment, the characters
@@ -199,15 +220,13 @@ module Watobo
199
220
  return false
200
221
  end
201
222
 
202
- def url
203
- #@url ||= nil
223
+ def url_string
224
+ url = ''
204
225
  #return @url unless @url.nil?
205
226
  if self.first =~ /^[^[:space:]]{1,} (https?:\/\/[\-0-9a-zA-Z.]*[:0-9]{0,6}.*) HTTP\//i then
206
- @url = $1
207
- else
208
- @url = ''
227
+ url = $1
209
228
  end
210
- @url
229
+ url
211
230
  end
212
231
 
213
232
  def site
@@ -297,7 +316,7 @@ module Watobo
297
316
 
298
317
  #################### doubles
299
318
 
300
- def get_parm_names
319
+ def get_parm_names(&block)
301
320
 
302
321
  parm_names=[]
303
322
  parmlist=[]
@@ -306,7 +325,8 @@ module Watobo
306
325
  parmlist.each do |p|
307
326
  if p then
308
327
  p.gsub!(/=.*/,'')
309
- parm_names.push p
328
+ yield p if block_given?
329
+ parm_names.push p
310
330
  end
311
331
  end
312
332
 
@@ -355,9 +375,9 @@ module Watobo
355
375
  parmlist = self.last.split(/\&/)
356
376
  end
357
377
  rescue => bang
358
- puts bang
359
- puts self.last.unpack("C*").pack("C*").gsub(/[^[:print:]]/,".")
378
+ # puts self.last.unpack("C*").pack("C*").gsub(/[^[:print:]]/,".")
360
379
  if $DEBUG
380
+ puts bang
361
381
  puts bang.backtrace
362
382
 
363
383
  end
@@ -387,7 +407,7 @@ module Watobo
387
407
 
388
408
  end
389
409
 
390
- def post_parm_names
410
+ def post_parm_names(&block)
391
411
 
392
412
  parm_names=[]
393
413
  parmlist=[]
@@ -396,7 +416,9 @@ module Watobo
396
416
  parmlist.each do |p|
397
417
  if p then
398
418
  p.gsub!(/=.*/,'')
399
- parm_names.push p
419
+ p.strip!
420
+ yield p if block_given?
421
+ parm_names << p
400
422
  end
401
423
  end
402
424
 
@@ -439,17 +461,29 @@ module Watobo
439
461
  return header_values
440
462
  end
441
463
 
442
- def content_type
443
- ct = "undefined"
464
+ def content_type(default_ct='undefined')
465
+ ct = default_ct
444
466
  self.each do |line|
445
467
  break if line.strip.empty?
446
- if line =~ /^Content-Type: (.*)/i then
468
+ if line =~ /^Content-Type: ([^;]*);?/i then
447
469
  ct = $1
448
470
  break
449
471
  end
450
472
  end
451
473
  return ct.strip
452
474
  end
475
+
476
+ def content_type_ex(default_ct='undefined')
477
+ ct = default_ct
478
+ self.each do |line|
479
+ break if line.strip.empty?
480
+ if line =~ /^Content-Type: (.*)/i then
481
+ ct = $1.strip
482
+ break
483
+ end
484
+ end
485
+ return ct.strip
486
+ end
453
487
 
454
488
  def content_length
455
489
  # Note: Calculate Chunk-Encoded Content-Length
@@ -570,12 +604,37 @@ def content_encoding
570
604
 
571
605
  def body
572
606
  begin
573
- #return nil if self.nil?
607
+ return nil if self.nil? or self.length < 3
574
608
  return self.last if self[-2].strip.empty?
575
609
  rescue
576
610
  return nil
577
611
  end
578
612
  end
613
+
614
+ def body_is_text?
615
+ ct = self.content_type(nil)
616
+ if ct.nil?
617
+ return true if self.body_encoded.ascii_only?
618
+ return false
619
+ else
620
+ return true if ct =~ /text/
621
+ return false
622
+ end
623
+ end
624
+
625
+ def body_encoded
626
+ b = self.body
627
+ cs = self.charset
628
+ return nil if b.nil?
629
+ return b.unpack("C*").pack("C*") if cs.nil?
630
+ begin
631
+ return b.encode(cs, :invalid => :replace, :undef => :replace, :replace => '').unpack("C*").pack("C*")
632
+ rescue => bang
633
+ puts bang
634
+ puts bang.backtrace if $DEBUG
635
+ return b.unpack("C*").pack("C*")
636
+ end
637
+ end
579
638
 
580
639
  def responseCode
581
640
  if self.first =~ /^HTTP\/... (\d+) /
@@ -592,8 +651,9 @@ def new_cookies(&b)
592
651
  headers("Set-Cookie") do |h|
593
652
  cookie = Watobo::Cookie.new(h)
594
653
  yield cookie if block_given?
595
- nc.push cookie
654
+ nc << cookie
596
655
  end
656
+ nc
597
657
  end
598
658
 
599
659
  def status
@@ -615,6 +675,18 @@ end
615
675
  return nil
616
676
  end
617
677
  end
678
+
679
+ def charset
680
+ cs = nil
681
+ self.each do |line|
682
+ break if line.strip.empty?
683
+ if line =~ /^Content-Type: .*charset=([^;]*)/i then
684
+ cs = $1
685
+ break
686
+ end
687
+ end
688
+ return cs
689
+ end
618
690
 
619
691
  def headers(filter=nil, &b)
620
692
  begin
@@ -659,7 +731,7 @@ end
659
731
  return cookie_list
660
732
  end
661
733
 
662
- def data
734
+ def data_UNUSED
663
735
  return self.last.strip if self.last =~ /\=.*\&?/i
664
736
  return ""
665
737
  end
@@ -1,7 +1,7 @@
1
1
  # .
2
2
  # request_parser.rb
3
3
  #
4
- # Copyright 2012 by siberas, http://www.siberas.de
4
+ # Copyright 2013 by siberas, http://www.siberas.de
5
5
  #
6
6
  # This file is part of WATOBO (Web Application Tool Box)
7
7
  # http://watobo.sourceforge.com
@@ -19,7 +19,8 @@
19
19
  # along with WATOBO; if not, write to the Free Software
20
20
  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
21
  # .
22
- module Watobo
22
+ # @private
23
+ module Watobo#:nodoc: all
23
24
  module Mixins
24
25
  # This mixin can be used to parse a String or any object which supports method.to_s into a valid http request string
25
26
  module RequestParser
@@ -35,113 +36,127 @@ module Watobo
35
36
  cprefs = { :code_dlmtr => '%%' } # default delimiter for ruby code
36
37
  cprefs.update(prefs)
37
38
 
38
- pattern="(#{cprefs[:code_dlmtr]}.*?#{cprefs[:code_dlmtr]})"
39
+ #pattern="(#{cprefs[:code_dlmtr]}.*?#{cprefs[:code_dlmtr]})"
40
+ pattern = cprefs[:code_dlmtr]
39
41
  request = self.to_s
42
+ expression = ""
40
43
 
41
44
  begin
42
45
  # puts new_request
43
46
  expr = ''
44
- new_request = ''
47
+
45
48
  pos = 0
46
49
  off = 0
50
+ match = []
51
+ code_marks = []
47
52
  while pos >= 0 and pos < request.length
48
- code_offset = request.index(/#{pattern}/, pos)
49
- unless code_offset.nil?
50
- expression = request.match(/#{pattern}/, code_offset)[0]
51
- new_request << request[pos..code_offset-1]
52
- expr = expression.gsub(/%%/,"")
53
- puts "DEBUG: executing: #{expr}" if $DEBUG
54
- result = eval(expr)
55
- puts "DEBUG: got #{result.class}" if $DEBUG
56
- if result.is_a? File
57
- data = result.read
58
- result.close
59
- elsif result.is_a? String
60
- data = result
61
- elsif result.is_a? Array
62
- data = result.join
63
- else
64
- log("!!!WATOBO - expression must return String or File !!!",'')
65
- end
66
- new_request << data
67
- pos = code_offset + expression.length
53
+ code_offset = request.index(pattern, pos)
54
+
55
+ unless code_offset.nil?
56
+ new_line_index = request.index("\n", pos)
57
+ unless new_line_index.nil?
58
+ if new_line_index < code_offset
59
+ # new_request << request[match[0]..code_offset-1] unless match.empty?
60
+ match = []
61
+ # pos = code_offset
62
+ end
63
+ end
64
+ match << code_offset
65
+
66
+ if match.length == 2
67
+ code_marks << match.dup
68
+ match = []
69
+ end
70
+ pos = code_offset + pattern.length
71
+ else
72
+ break
73
+ end
74
+ end
75
+
76
+ new_request = ''
77
+ unless code_marks.empty?
78
+ code_marks.each_with_index do |cm,i|
79
+ #puts cm.to_yaml
80
+ last = i > 0 ? ( code_marks[i-1][1] + pattern.length ) : 0
81
+ new_request << request[last..cm[0]-1] if cm[0] > 0
82
+ exp_start = cm[0] + pattern.length
83
+ exp_end = cm[1] - 1
84
+
85
+ expression = request[exp_start..exp_end]
86
+ expression.strip!
87
+ next if expression.empty?
88
+ puts "DEBUG: executing: #{expression}" if $DEBUG
89
+ #result = expression.empty? ? "" : eval("#{expression}")
90
+ result = eval(expression)
91
+ puts "DEBUG: got #{result.class}" if $DEBUG
92
+ if result.is_a? File
93
+ data = result.read
94
+ result.close
95
+ elsif result.is_a? String
96
+ data = result
97
+ elsif result.is_a? Array
98
+ data = result.join
99
+ else
100
+ puts "!!!WATOBO - expression must return String or File !!!"
101
+ end
102
+ new_request << data
103
+ end
104
+ new_request << request[code_marks.last[1]+pattern.length..-2] unless code_marks.last[1] >= request.length-1
105
+
68
106
  else
69
- new_request << request[pos..-1]
70
- pos = request.length
107
+ new_request = request
71
108
  end
72
- end
109
+
73
110
  return new_request
74
111
 
75
112
  rescue SyntaxError, LocalJumpError, NameError => e
76
- raise SyntaxError, "SyntaxError in '#{expr}'"
113
+ # raise SyntaxError, "SyntaxError in '#{expression}'"
114
+ puts e
115
+ puts e.backtrace
116
+
77
117
  end
78
118
  return nil
79
119
  end
80
120
 
81
- def unchunked_UNUSED( opts = {} )
82
- options = { :update_content_length => false }
83
- options.update opts
84
- begin
85
- text = parse_code
86
- eoh = self.index("\n\n")
87
- unless eoh.nil?
88
- raw_header = text[0..eoh-1]
89
- raw_body = text[eoh+1..-1]
90
- else
91
- raw_header = text
92
- raw_body = nil
93
- end
94
-
95
- unchunked = raw_header.split("\n")
96
- unchunked.extend Watobo::Mixin::Parser::Url
97
- unchunked.extend Watobo::Mixin::Parser::Web10
98
- unchunked.extend Watobo::Mixin::Shaper::Web10
99
-
100
- unless raw_body.nil?
101
- unchunked
102
- end
103
-
104
- rescue => bang
105
- end
106
- end
107
-
121
+
108
122
  def to_request(opts={})
109
123
  options = { :update_content_length => false }
110
124
  options.update opts
125
+ body = nil
111
126
  begin
112
127
  text = parse_code
113
- result = []
114
-
115
- if text =~ /\n\n/
116
- dummy = text.split(/\n\n/)
117
- header = dummy.shift.split(/\n/)
118
- body = dummy.join("\n\n")
119
- else
120
- header = text.split(/\n/)
128
+ request = []
129
+
130
+ eoh = nil
131
+ eoh = text.index("\n\n") unless text.nil?
132
+
133
+ unless eoh.nil?
134
+ header = text.slice(0, eoh).split("\n").map{|h| "#{h}\r\n"}
135
+ body = text.slice(eoh+2, text.length-1)
136
+ else
137
+ header = text.split(/\n/).map{|h| "#{h}\r\n"}
121
138
  body = nil
122
- end
123
-
124
- header.each do |h|
125
- result.push "#{h}\r\n"
126
- end
139
+ end
140
+
141
+ request.concat header
127
142
 
128
- # result.extend Watobo::Mixin::Parser::Url
129
- # result.extend Watobo::Mixin::Parser::Web10
130
- # result.extend Watobo::Mixin::Shaper::Web10
131
- Watobo::Request.create result
143
+ #Watobo::Request.create request
144
+ request = Watobo::Request.new(request)
132
145
 
133
- ct = result.content_type
146
+ ct = request.content_type_ex
147
+ # puts ct
134
148
  # last line is without "\r\n" if text has a body
135
- if ct =~ /multipart\/form/ and body then
149
+ if ct =~ /multipart/ and body then
136
150
  #Content-Type: multipart/form-data; boundary=---------------------------3035221901842
137
151
  if ct =~ /boundary=([\-\w]+)/
138
152
  boundary = $1.strip
139
- chunks = body.split(boundary)
140
- e = chunks.pop # remove "--"
153
+ chunks = body.split(/--#{boundary}[\-]{0,2}/)
154
+ #chunks.pop # remove "--"
155
+ #puts "Multipart request has #{chunks.length} chunks"
141
156
  new_body = []
142
157
  chunks.each do |c|
143
158
  new_chunk = ''
144
- c.gsub!(/[\-]+$/,'')
159
+ #c.gsub!(/[\-]+$/,'')
145
160
  next if c.nil?
146
161
  next if c.strip.empty?
147
162
  c.strip!
@@ -162,22 +177,20 @@ module Watobo
162
177
 
163
178
  end
164
179
  body = "--#{boundary}\r\n"
165
- body += new_body.join("--#{boundary}\r\n")
166
- body += "--#{boundary}--"
180
+ body << new_body.join("--#{boundary}\r\n")
181
+ body << "--#{boundary}--\r\n"
167
182
  end
168
183
  # body.gsub!(/\n/, "\r\n") if body
169
184
 
170
185
  end
171
186
 
172
- if body then
173
- result.push "\r\n"
174
- result.push body.strip
187
+ unless body.nil?
188
+ request.push "\r\n"
189
+ request.push body.strip
175
190
  end
176
191
 
177
- result.fixupContentLength() if options[:update_content_length] == true
178
- puts ">>"
179
- puts result
180
- return result
192
+ request.fixupContentLength() if options[:update_content_length] == true
193
+ return request
181
194
  rescue => bang
182
195
  puts bang
183
196
  puts bang.backtrace
@@ -207,7 +220,8 @@ module Watobo
207
220
  end
208
221
 
209
222
 
210
- Watobo::Response.create result
223
+ #Watobo::Response.create result
224
+ result = Watobo::Response.new(result)
211
225
 
212
226
  if body then
213
227
  result.push "\r\n"
@@ -250,7 +264,8 @@ module Watobo
250
264
  # result.extend Watobo::Mixin::Parser::Url
251
265
  # result.extend Watobo::Mixin::Parser::Web10
252
266
  # result.extend Watobo::Mixin::Shaper::Web10
253
- Watobo::Request.create result
267
+ #Watobo::Request.create result
268
+ result = Watobo::Request.new(result)
254
269
 
255
270
  ct = result.content_type
256
271
  # last line is without "\r\n" if text has a body