watobo 0.9.21 → 0.9.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +46 -1
- data/bin/nfq_server.rb +0 -9
- data/bin/watobo_gui.rb +3 -13
- data/custom-views/prettify-json.rb +9 -18
- data/icons/watobo.ico +0 -0
- data/icons/watobo.ico.old +0 -0
- data/lib/watobo.rb +10 -19
- data/lib/watobo/adapters.rb +5 -14
- data/lib/watobo/adapters/data_store.rb +50 -59
- data/lib/watobo/adapters/file/file_store.rb +287 -296
- data/lib/watobo/adapters/file/marshal_store.rb +293 -296
- data/lib/watobo/adapters/session_store.rb +5 -14
- data/lib/watobo/ca.rb +1 -10
- data/lib/watobo/config.rb +197 -206
- data/lib/watobo/constants.rb +0 -9
- data/lib/watobo/core.rb +3 -12
- data/lib/watobo/core/active_check.rb +72 -135
- data/lib/watobo/core/active_checks.rb +49 -58
- data/lib/watobo/core/ca.rb +369 -389
- data/lib/watobo/core/cert_store.rb +34 -43
- data/lib/watobo/core/chat.rb +92 -101
- data/lib/watobo/core/chats.rb +271 -280
- data/lib/watobo/core/client_cert_store.rb +106 -35
- data/lib/watobo/core/conversation.rb +48 -57
- data/lib/watobo/core/cookie.rb +23 -32
- data/lib/watobo/core/egress_handlers.rb +98 -0
- data/lib/watobo/core/finding.rb +66 -75
- data/lib/watobo/core/findings.rb +107 -114
- data/lib/watobo/core/forwarding_proxy.rb +13 -22
- data/lib/watobo/core/fuzz_gen.rb +0 -9
- data/lib/watobo/core/intercept_carver.rb +166 -177
- data/lib/watobo/core/intercept_filter.rb +235 -244
- data/lib/watobo/core/interceptor.rb +98 -107
- data/lib/watobo/core/min_class.rb +4 -13
- data/lib/watobo/core/netfilter_queue.rb +170 -179
- data/lib/watobo/core/ott_cache.rb +132 -141
- data/lib/watobo/core/parameter.rb +43 -52
- data/lib/watobo/core/passive_check.rb +103 -102
- data/lib/watobo/core/passive_checks.rb +48 -57
- data/lib/watobo/core/passive_scanner.rb +54 -55
- data/lib/watobo/core/plugin.rb +11 -20
- data/lib/watobo/core/project.rb +3 -9
- data/lib/watobo/core/proxy.rb +43 -52
- data/lib/watobo/core/request.rb +125 -123
- data/lib/watobo/core/response.rb +44 -53
- data/lib/watobo/core/scanner.rb +0 -9
- data/lib/watobo/core/scanner3.rb +405 -414
- data/lib/watobo/core/scope.rb +83 -92
- data/lib/watobo/core/session.rb +1043 -1026
- data/lib/watobo/core/sid_cache.rb +98 -107
- data/lib/watobo/core/subscriber.rb +25 -34
- data/lib/watobo/defaults.rb +21 -30
- data/lib/watobo/external/diff/lcs.rb +0 -9
- data/lib/watobo/external/diff/lcs/array.rb +0 -9
- data/lib/watobo/external/diff/lcs/block.rb +0 -9
- data/lib/watobo/external/diff/lcs/callbacks.rb +0 -9
- data/lib/watobo/external/diff/lcs/change.rb +0 -9
- data/lib/watobo/external/diff/lcs/hunk.rb +0 -9
- data/lib/watobo/external/diff/lcs/ldiff.rb +0 -9
- data/lib/watobo/external/diff/lcs/string.rb +0 -9
- data/lib/watobo/externals.rb +6 -15
- data/lib/watobo/framework.rb +4 -13
- data/lib/watobo/framework/create_project.rb +60 -69
- data/lib/watobo/framework/init.rb +0 -9
- data/lib/watobo/framework/init_modules.rb +0 -9
- data/lib/watobo/framework/license_text.rb +28 -37
- data/lib/watobo/framework/load_chat.rb +13 -22
- data/lib/watobo/gui.rb +132 -123
- data/lib/watobo/gui/about_watobo.rb +0 -9
- data/lib/watobo/gui/browser_preview.rb +0 -9
- data/lib/watobo/gui/certificate_dialog.rb +0 -9
- data/lib/watobo/gui/chat_diff.rb +0 -9
- data/lib/watobo/gui/chatviewer_frame.rb +73 -72
- data/lib/watobo/gui/checkboxtree.rb +0 -9
- data/lib/watobo/gui/checks_policy_frame.rb +0 -9
- data/lib/watobo/gui/client_cert_dialog.rb +96 -87
- data/lib/watobo/gui/confirm_scan_dialog.rb +0 -9
- data/lib/watobo/gui/conversation_table.rb +158 -164
- data/lib/watobo/gui/conversation_table_ctrl.rb +207 -216
- data/lib/watobo/gui/conversation_table_ctrl2.rb +373 -382
- data/lib/watobo/gui/csrf_token_dialog.rb +0 -9
- data/lib/watobo/gui/custom_viewer.rb +374 -383
- data/lib/watobo/gui/dashboard.rb +296 -303
- data/lib/watobo/gui/define_scope_frame.rb +0 -9
- data/lib/watobo/gui/differ_frame.rb +215 -224
- data/lib/watobo/gui/edit_comment.rb +0 -9
- data/lib/watobo/gui/edit_scope_dialog.rb +0 -9
- data/lib/watobo/gui/export_dialog.rb +104 -113
- data/lib/watobo/gui/finding_info.rb +0 -9
- data/lib/watobo/gui/findings_tree.rb +210 -217
- data/lib/watobo/gui/full_scan_dialog.rb +0 -9
- data/lib/watobo/gui/fuzzer_gui.rb +1295 -1313
- data/lib/watobo/gui/fxsave_thread.rb +14 -0
- data/lib/watobo/gui/goto_url_dialog.rb +70 -79
- data/lib/watobo/gui/hex_viewer.rb +0 -9
- data/lib/watobo/gui/html_viewer.rb +287 -296
- data/lib/watobo/gui/intercept_filter_dialog.rb +188 -197
- data/lib/watobo/gui/interceptor_gui.rb +1041 -1051
- data/lib/watobo/gui/interceptor_settings_dialog.rb +0 -9
- data/lib/watobo/gui/json_viewer.rb +287 -0
- data/lib/watobo/gui/list_box.rb +101 -110
- data/lib/watobo/gui/log_file_viewer.rb +32 -41
- data/lib/watobo/gui/log_viewer.rb +83 -88
- data/lib/watobo/gui/login_wizzard.rb +0 -9
- data/lib/watobo/gui/main_window.rb +587 -618
- data/lib/watobo/gui/manual_request_editor.rb +620 -565
- data/lib/watobo/gui/master_pw_dialog.rb +0 -9
- data/lib/watobo/gui/mixins/gui_settings.rb +29 -38
- data/lib/watobo/gui/page_tree.rb +217 -226
- data/lib/watobo/gui/password_policy_dialog.rb +0 -9
- data/lib/watobo/gui/plugin_board.rb +0 -9
- data/lib/watobo/gui/preferences_dialog.rb +0 -9
- data/lib/watobo/gui/progress_window.rb +17 -27
- data/lib/watobo/gui/project_wizzard.rb +0 -9
- data/lib/watobo/gui/proxy_dialog.rb +1 -10
- data/lib/watobo/gui/quick_scan_dialog.rb +0 -9
- data/lib/watobo/gui/request_builder_frame.rb +102 -111
- data/lib/watobo/gui/request_editor.rb +181 -137
- data/lib/watobo/gui/rewrite_filters_dialog.rb +394 -403
- data/lib/watobo/gui/rewrite_rules_dialog.rb +372 -381
- data/lib/watobo/gui/save_chat_dialog.rb +140 -149
- data/lib/watobo/gui/scanner_settings_dialog.rb +0 -9
- data/lib/watobo/gui/select_chat_dialog.rb +0 -9
- data/lib/watobo/gui/session_management_dialog.rb +0 -9
- data/lib/watobo/gui/sites_tree.rb +0 -9
- data/lib/watobo/gui/status_bar.rb +0 -9
- data/lib/watobo/gui/table_editor.rb +0 -9
- data/lib/watobo/gui/tagless_viewer.rb +0 -9
- data/lib/watobo/gui/templates/plugin.rb +0 -9
- data/lib/watobo/gui/templates/plugin2.rb +92 -100
- data/lib/watobo/gui/templates/plugin_base.rb +144 -153
- data/lib/watobo/gui/text_viewer.rb +0 -9
- data/lib/watobo/gui/transcoder_window.rb +0 -9
- data/lib/watobo/gui/utils/gui_utils.rb +0 -9
- data/lib/watobo/gui/utils/init_icons.rb +86 -95
- data/lib/watobo/gui/utils/load_icons.rb +33 -42
- data/lib/watobo/gui/utils/load_plugins.rb +116 -119
- data/lib/watobo/gui/utils/master_password.rb +68 -77
- data/lib/watobo/gui/utils/save_default_settings.rb +113 -122
- data/lib/watobo/gui/utils/save_project_settings.rb +0 -9
- data/lib/watobo/gui/utils/save_proxy_settings.rb +41 -50
- data/lib/watobo/gui/utils/save_scanner_settings.rb +18 -27
- data/lib/watobo/gui/utils/session_history.rb +112 -121
- data/lib/watobo/gui/workspace_dialog.rb +0 -9
- data/lib/watobo/gui/www_auth_dialog.rb +0 -9
- data/lib/watobo/gui/xml_viewer_frame.rb +0 -9
- data/lib/watobo/http.rb +4 -13
- data/lib/watobo/http/cookies/cookies.rb +26 -35
- data/lib/watobo/http/data/data.rb +45 -54
- data/lib/watobo/http/data/json.rb +47 -55
- data/lib/watobo/http/url/url.rb +38 -47
- data/lib/watobo/http/xml/xml.rb +124 -130
- data/lib/watobo/interceptor.rb +3 -12
- data/lib/watobo/interceptor/proxy.rb +742 -739
- data/lib/watobo/interceptor/transparent.rb +22 -24
- data/lib/watobo/mixins.rb +10 -19
- data/lib/watobo/mixins/check_info.rb +27 -36
- data/lib/watobo/mixins/httpparser.rb +613 -637
- data/lib/watobo/mixins/request_parser.rb +88 -97
- data/lib/watobo/mixins/shapers.rb +515 -529
- data/lib/watobo/mixins/transcoders.rb +3 -11
- data/lib/watobo/parser.rb +1 -10
- data/lib/watobo/parser/html.rb +83 -92
- data/lib/watobo/patch_fxruby_setfocus.rb +26 -0
- data/lib/watobo/sockets.rb +3 -12
- data/lib/watobo/sockets/agent.rb +828 -837
- data/lib/watobo/sockets/client_socket.rb +308 -312
- data/lib/watobo/sockets/connection.rb +401 -410
- data/lib/watobo/sockets/http_socket.rb +11 -13
- data/lib/watobo/sockets/ntlm_auth.rb +129 -138
- data/lib/watobo/utils.rb +10 -19
- data/lib/watobo/utils/check_regex.rb +0 -9
- data/lib/watobo/utils/copy_object.rb +0 -9
- data/lib/watobo/utils/crypto.rb +0 -9
- data/lib/watobo/utils/expand_range.rb +23 -32
- data/lib/watobo/utils/export_xml.rb +97 -106
- data/lib/watobo/utils/file_management.rb +9 -11
- data/lib/watobo/utils/hexprint.rb +9 -18
- data/lib/watobo/utils/load_chat.rb +0 -9
- data/lib/watobo/utils/load_icon.rb +0 -9
- data/lib/watobo/utils/ntlm.rb +866 -875
- data/lib/watobo/utils/print_debug.rb +12 -21
- data/lib/watobo/utils/response_builder.rb +90 -99
- data/lib/watobo/utils/response_hash.rb +0 -9
- data/lib/watobo/utils/secure_eval.rb +0 -9
- data/lib/watobo/utils/strings.rb +10 -19
- data/lib/watobo/utils/text2request.rb +0 -9
- data/lib/watobo/utils/url.rb +23 -32
- data/lib/watobo/utils/utf16.rb +11 -20
- data/modules/active/Apache/mod_status.rb +0 -9
- data/modules/active/Apache/multiview.rb +151 -160
- data/modules/active/Flash/crossdomain.rb +0 -9
- data/modules/active/JWT/jwt_oauth2_none.rb +111 -0
- data/modules/active/cq5/cq5_default_selectors.rb +106 -115
- data/modules/active/cq5/cqp_user_enumeration.rb +125 -134
- data/modules/active/directories/dirwalker.rb +0 -9
- data/modules/active/discovery/fileextensions.rb +0 -9
- data/modules/active/discovery/http_methods.rb +0 -9
- data/modules/active/discovery/jsmapfiles.rb +79 -0
- data/modules/active/domino/domino_db.rb +68 -76
- data/modules/active/dotNET/custom_errors.rb +102 -111
- data/modules/active/dotNET/dotnet_files.rb +90 -99
- data/modules/active/fileinclusion/lfi_simple.rb +0 -9
- data/modules/active/jboss/jboss_basic.rb +0 -9
- data/modules/active/sap/business_objects.rb +51 -60
- data/modules/active/sap/its_commands.rb +0 -9
- data/modules/active/sap/its_service_parameter.rb +0 -9
- data/modules/active/sap/its_services.rb +0 -9
- data/modules/active/sap/its_xss.rb +0 -9
- data/modules/active/shell_shock/shell_shock.rb +139 -148
- data/modules/active/siebel/siebel_apps.rb +160 -169
- data/modules/active/sqlinjection/sql_boolean.rb +0 -9
- data/modules/active/sqlinjection/sql_numerical.rb +198 -0
- data/modules/active/sqlinjection/sqli_error.rb +0 -9
- data/modules/active/sqlinjection/sqli_timing.rb +220 -229
- data/modules/active/struts2/default_handler_ognl.rb +106 -115
- data/modules/active/struts2/include_params_ognl.rb +105 -114
- data/modules/active/xml/xml_xxe.rb +112 -123
- data/modules/active/xss/xss_ng.rb +214 -223
- data/modules/active/xss/xss_simple.rb +0 -9
- data/modules/passive/ajax.rb +68 -77
- data/modules/passive/autocomplete.rb +56 -65
- data/modules/passive/cookie_options.rb +0 -9
- data/modules/passive/cookie_xss.rb +0 -9
- data/modules/passive/detect_code.rb +0 -9
- data/modules/passive/detect_fileupload.rb +0 -9
- data/modules/passive/detect_infrastructure.rb +0 -9
- data/modules/passive/detect_one_time_tokens.rb +0 -9
- data/modules/passive/dirindexing.rb +0 -9
- data/modules/passive/disclosure_domino.rb +55 -64
- data/modules/passive/disclosure_emails.rb +0 -9
- data/modules/passive/disclosure_ipaddr.rb +55 -53
- data/modules/passive/filename_as_parameter.rb +0 -9
- data/modules/passive/form_spotter.rb +0 -9
- data/modules/passive/hidden_fields.rb +50 -59
- data/modules/passive/hotspots.rb +0 -9
- data/modules/passive/in_script_parameter.rb +0 -9
- data/modules/passive/json_web_token.rb +93 -0
- data/modules/passive/multiple_server_headers.rb +0 -9
- data/modules/passive/possible_login.rb +0 -9
- data/modules/passive/redirect_url.rb +0 -9
- data/modules/passive/redirectionz.rb +0 -9
- data/modules/passive/sap-headers.rb +56 -65
- data/modules/passive/xss_dom.rb +0 -9
- data/plugins/aem/aem.rb +11 -20
- data/plugins/aem/gui/main.rb +118 -127
- data/plugins/aem/gui/tree_view.rb +171 -180
- data/plugins/aem/lib/agent.rb +130 -138
- data/plugins/aem/lib/dispatcher.rb +45 -51
- data/plugins/aem/lib/engine.rb +177 -186
- data/plugins/catalog/catalog.rb +345 -355
- data/plugins/crawler/crawler.rb +4 -13
- data/plugins/crawler/gui.rb +5 -14
- data/plugins/crawler/gui/auth_frame.rb +270 -279
- data/plugins/crawler/gui/crawler_gui.rb +271 -276
- data/plugins/crawler/gui/general_settings_frame.rb +96 -105
- data/plugins/crawler/gui/hooks_frame.rb +80 -89
- data/plugins/crawler/gui/scope_frame.rb +50 -59
- data/plugins/crawler/gui/settings_tabbook.rb +38 -47
- data/plugins/crawler/gui/status_frame.rb +59 -68
- data/plugins/crawler/lib/bags.rb +18 -27
- data/plugins/crawler/lib/constants.rb +11 -20
- data/plugins/crawler/lib/engine.rb +488 -497
- data/plugins/crawler/lib/grabber.rb +68 -77
- data/plugins/crawler/lib/status.rb +71 -80
- data/plugins/crawler/lib/uri_mp.rb +12 -21
- data/plugins/filefinder/filefinder.rb +326 -333
- data/plugins/sqlmap/bin/test.rb +78 -87
- data/plugins/sqlmap/gui.rb +4 -13
- data/plugins/sqlmap/gui/main.rb +218 -227
- data/plugins/sqlmap/gui/options_frame.rb +97 -106
- data/plugins/sqlmap/lib/sqlmap_ctrl.rb +90 -100
- data/plugins/sqlmap/sqlmap.rb +2 -11
- data/plugins/sslchecker/cli/sslchecker_cli.rb +0 -9
- data/plugins/sslchecker/gui/cipher_table.rb +246 -254
- data/plugins/sslchecker/gui/gui.rb +258 -264
- data/plugins/sslchecker/gui/sslchecker.rb +4 -13
- data/plugins/sslchecker/lib/check.rb +127 -133
- data/plugins/wshell/gui/main.rb +119 -117
- data/plugins/wshell/lib/core.rb +38 -88
- data/plugins/wshell/wshell.rb +11 -20
- metadata +170 -164
@@ -1,14 +1,5 @@
|
|
1
|
-
#.
|
2
|
-
# client_socket.rb
|
3
|
-
#.
|
4
|
-
# Copyright 2014 by siberas, http://www.siberas.de
|
5
|
-
# This file is part of WATOBO (Web Application Tool Box) http://watobo.sourceforge.com
|
6
|
-
# WATOBO is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation version 2 of the License.
|
7
|
-
# WATOBO is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
8
|
-
# You should have received a copy of the GNU General Public License along with WATOBO; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
9
|
-
|
10
1
|
# @private
|
11
|
-
module Watobo#:nodoc: all
|
2
|
+
module Watobo #:nodoc: all
|
12
3
|
module HTTPSocket
|
13
4
|
class ClientSocket
|
14
5
|
attr_accessor :port
|
@@ -16,6 +7,7 @@ module Watobo#:nodoc: all
|
|
16
7
|
attr_accessor :host
|
17
8
|
attr_accessor :site
|
18
9
|
attr_accessor :ssl
|
10
|
+
|
19
11
|
def write(data)
|
20
12
|
@socket.write data
|
21
13
|
@socket.flush
|
@@ -27,16 +19,16 @@ module Watobo#:nodoc: all
|
|
27
19
|
|
28
20
|
def close
|
29
21
|
begin
|
30
|
-
|
22
|
+
#if socket.class.to_s =~ /SSLSocket/
|
31
23
|
if @socket.respond_to? :shutdown
|
32
24
|
@socket.shutdown(Socket::SHUT_RDWR)
|
33
25
|
end
|
34
26
|
# finally close it
|
35
27
|
if @socket.respond_to? :close
|
36
|
-
|
28
|
+
@socket.close
|
37
29
|
elsif @socket.respond_to? :sysclose
|
38
30
|
socket.io.shutdown(Socket::SHUT_RDWR)
|
39
|
-
|
31
|
+
@socket.sysclose
|
40
32
|
end
|
41
33
|
return true
|
42
34
|
rescue => bang
|
@@ -69,15 +61,15 @@ module Watobo#:nodoc: all
|
|
69
61
|
begin
|
70
62
|
unless @initial_request.nil?
|
71
63
|
request = @initial_request.copy
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
64
|
+
|
65
|
+
#puts "\n>> Request RAW:"
|
66
|
+
#puts request
|
67
|
+
#puts "\n>> Request RAW (HEX):"
|
68
|
+
#puts request.join.unpack("H*")[0]
|
69
|
+
|
78
70
|
@initial_request = nil
|
79
71
|
clean_request request
|
80
|
-
|
72
|
+
return request
|
81
73
|
end
|
82
74
|
|
83
75
|
request = read_header
|
@@ -87,24 +79,24 @@ module Watobo#:nodoc: all
|
|
87
79
|
@persistent = !request.connection_close?
|
88
80
|
|
89
81
|
clen = request.content_length
|
90
|
-
if
|
82
|
+
if clen > 0 then
|
91
83
|
body = ""
|
92
84
|
Watobo::HTTPSocket.read_body(@socket) do |data|
|
93
85
|
body << data
|
94
86
|
break if body.length == clen
|
95
87
|
end
|
96
|
-
|
97
|
-
|
98
|
-
|
88
|
+
|
89
|
+
puts "* CLEN = #{clen} - read body (#{body.length})"
|
90
|
+
request << body
|
99
91
|
end
|
100
92
|
rescue => bang
|
101
93
|
puts bang
|
102
94
|
end
|
103
|
-
|
95
|
+
|
104
96
|
puts "\n>> Request RAW:"
|
105
97
|
puts request
|
106
98
|
puts "\n>> Request RAW (HEX):"
|
107
|
-
|
99
|
+
# puts request.unpack("H*")[0]
|
108
100
|
|
109
101
|
clean_request request
|
110
102
|
|
@@ -125,7 +117,7 @@ module Watobo#:nodoc: all
|
|
125
117
|
@initial_request = req
|
126
118
|
@persistent = false
|
127
119
|
|
128
|
-
|
120
|
+
# TODO: Fake Certs Should be global accessable
|
129
121
|
|
130
122
|
end
|
131
123
|
|
@@ -137,6 +129,8 @@ module Watobo#:nodoc: all
|
|
137
129
|
ra = socket.remote_address
|
138
130
|
cport = ra.ip_port
|
139
131
|
caddr = ra.ip_address
|
132
|
+
#puts cport
|
133
|
+
#puts caddr
|
140
134
|
|
141
135
|
optval = [1, 500_000].pack("I_2")
|
142
136
|
# socket.setsockopt Socket::SOL_SOCKET, Socket::SO_RCVTIMEO, optval
|
@@ -149,8 +143,9 @@ module Watobo#:nodoc: all
|
|
149
143
|
|
150
144
|
if Watobo::Interceptor::Proxy.transparent?
|
151
145
|
|
152
|
-
|
153
|
-
|
146
|
+
|
147
|
+
ci = Watobo::Interceptor::Transparent.info({'host' => caddr, 'port' => cport})
|
148
|
+
unless ci.nil? or ci['target'].empty? or ci['cn'].empty?
|
154
149
|
puts "SSL-REQUEST FROM #{caddr}:#{cport}"
|
155
150
|
|
156
151
|
ctx = Watobo::CertStore.acquire_ssl_ctx ci['target'], ci['cn']
|
@@ -171,9 +166,6 @@ module Watobo#:nodoc: all
|
|
171
166
|
puts bang.backtrace
|
172
167
|
return nil, session
|
173
168
|
end
|
174
|
-
else
|
175
|
-
puts ci['host']
|
176
|
-
puts ci['cn']
|
177
169
|
end
|
178
170
|
end
|
179
171
|
|
@@ -187,13 +179,15 @@ module Watobo#:nodoc: all
|
|
187
179
|
return nil
|
188
180
|
end
|
189
181
|
|
182
|
+
return nil if request.empty?
|
183
|
+
|
190
184
|
if Watobo::Interceptor::Proxy.transparent?
|
191
185
|
#puts "> get hostname ..."
|
192
186
|
thn = nil
|
193
187
|
request.each do |l|
|
194
188
|
if l =~ /^Host: (.*)/
|
195
|
-
|
196
|
-
|
189
|
+
thn = $1.strip
|
190
|
+
# puts ">> #{thn}"
|
197
191
|
end
|
198
192
|
end
|
199
193
|
# puts session.class
|
@@ -201,45 +195,44 @@ module Watobo#:nodoc: all
|
|
201
195
|
# puts request.first
|
202
196
|
# puts ">>"
|
203
197
|
if session.is_a? OpenSSL::SSL::SSLSocket
|
204
|
-
request.first.gsub!(/(^[^[:space:]]{1,}) (.*) (HTTP.*)/i,"\\1 https://#{thn}\\2 \\3") unless request.first =~ /^[^[:space:]]{1,} http/
|
198
|
+
request.first.gsub!(/(^[^[:space:]]{1,}) (.*) (HTTP.*)/i, "\\1 https://#{thn}\\2 \\3") unless request.first =~ /^[^[:space:]]{1,} http/
|
205
199
|
else
|
206
|
-
request.first.gsub!(/(^[^[:space:]]{1,}) (.*) (HTTP.*)/i,"\\1 http://#{thn}\\2 \\3") unless request.first =~ /^[^[:space:]]{1,} http/
|
200
|
+
request.first.gsub!(/(^[^[:space:]]{1,}) (.*) (HTTP.*)/i, "\\1 http://#{thn}\\2 \\3") unless request.first =~ /^[^[:space:]]{1,} http/
|
207
201
|
end
|
208
|
-
|
202
|
+
#puts request.first
|
209
203
|
end
|
210
204
|
|
211
205
|
if request.first =~ /^CONNECT (.*):(\d{1,5}) HTTP\/1\./ then
|
212
206
|
target = $1
|
213
207
|
tport = $2
|
214
208
|
# puts request.first
|
215
|
-
#print "\n* CONNECT: #{
|
209
|
+
# print "\n* CONNECT: #{target} on port #{tport}\n"
|
216
210
|
site = "#{target}:#{tport}"
|
217
211
|
#puts "CONNECT #{site}"
|
218
212
|
|
219
213
|
socket.print "HTTP/1.0 200 Connection established\r\n" +
|
220
|
-
|
221
|
-
|
222
|
-
|
214
|
+
#"Proxy-connection: Keep-alive\r\n" +
|
215
|
+
"Proxy-agent: WATOBO-Proxy/1.1\r\n" +
|
216
|
+
"\r\n"
|
223
217
|
bscount = 0 # bad handshake counter
|
224
218
|
# puts "* wait for ssl handshake ..."
|
225
219
|
begin
|
226
|
-
# site = "#{target}:#{tport}"
|
227
220
|
unless @fake_certs.has_key? site
|
228
221
|
puts "CREATE NEW CERTIFICATE FOR >> #{site} <<"
|
229
222
|
cn = Watobo::HTTPSocket.get_ssl_cert_cn(target, tport)
|
230
223
|
puts "CN=#{cn}"
|
231
224
|
|
232
225
|
cert = {
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
226
|
+
:hostname => cn,
|
227
|
+
:type => 'server',
|
228
|
+
:user => 'watobo',
|
229
|
+
:email => 'root@localhost',
|
237
230
|
}
|
238
231
|
|
239
232
|
cert_file, key_file = Watobo::CA.create_cert cert
|
240
233
|
@fake_certs[site] = {
|
241
|
-
|
242
|
-
|
234
|
+
:cert => OpenSSL::X509::Certificate.new(File.read(cert_file)),
|
235
|
+
:key => OpenSSL::PKey::RSA.new(File.read(key_file))
|
243
236
|
}
|
244
237
|
end
|
245
238
|
ctx = OpenSSL::SSL::SSLContext.new()
|
@@ -257,7 +250,7 @@ module Watobo#:nodoc: all
|
|
257
250
|
ctx.timeout = 10
|
258
251
|
|
259
252
|
ssl_socket = OpenSSL::SSL::SSLSocket.new(socket, ctx)
|
260
|
-
ssl_socket.setsockopt(
|
253
|
+
ssl_socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, 1)
|
261
254
|
# ssl_socket.sync_close = true
|
262
255
|
ssl_socket.sync = true
|
263
256
|
# puts ssl_socket.methods.sort
|
@@ -287,12 +280,12 @@ module Watobo#:nodoc: all
|
|
287
280
|
end
|
288
281
|
|
289
282
|
else
|
290
|
-
|
283
|
+
# puts "* create request object"
|
291
284
|
request = Watobo::Request.new(request)
|
292
|
-
|
293
|
-
|
285
|
+
site = request.site
|
286
|
+
#puts request
|
294
287
|
end
|
295
|
-
|
288
|
+
|
296
289
|
#puts "CLIENT REQUEST:"
|
297
290
|
#puts request
|
298
291
|
|
@@ -300,14 +293,14 @@ module Watobo#:nodoc: all
|
|
300
293
|
|
301
294
|
unless request.nil?
|
302
295
|
clen = request.content_length
|
303
|
-
if
|
296
|
+
if clen > 0 then
|
304
297
|
body = ""
|
305
298
|
Watobo::HTTPSocket.read_body(session) do |data|
|
306
299
|
body << data
|
307
300
|
break if body.length == clen
|
308
301
|
end
|
309
|
-
|
310
|
-
|
302
|
+
|
303
|
+
request << body unless body.empty?
|
311
304
|
end
|
312
305
|
connection = ClientSocket.new(session, request)
|
313
306
|
else
|
@@ -342,115 +335,118 @@ module Watobo#:nodoc: all
|
|
342
335
|
request.remove_header "^If\-"
|
343
336
|
request.remove_header "^Expect.*continue"
|
344
337
|
|
345
|
-
|
338
|
+
request.unzip!
|
339
|
+
|
340
|
+
# request.remove_header("^Accept-Encoding")
|
346
341
|
end
|
347
342
|
|
348
343
|
end
|
349
344
|
|
350
|
-
class ClientSocket_ORIG
|
351
|
-
attr_accessor :port
|
352
|
-
attr_accessor :address
|
353
|
-
attr_accessor :host
|
354
|
-
attr_accessor :site
|
355
|
-
attr_accessor :ssl
|
356
|
-
|
345
|
+
class ClientSocket_ORIG
|
346
|
+
attr_accessor :port
|
347
|
+
attr_accessor :address
|
348
|
+
attr_accessor :host
|
349
|
+
attr_accessor :site
|
350
|
+
attr_accessor :ssl
|
351
|
+
|
352
|
+
def write(data)
|
357
353
|
@socket.write data
|
358
|
-
@socket.flush
|
354
|
+
@socket.flush
|
359
355
|
end
|
360
356
|
|
361
357
|
def flush
|
362
358
|
@socket.flush
|
363
|
-
end
|
359
|
+
end
|
364
360
|
|
365
|
-
def close
|
366
|
-
begin
|
367
|
-
|
368
|
-
if @socket.respond_to? :shutdown
|
369
|
-
@socket.shutdown(Socket::SHUT_RDWR)
|
361
|
+
def close
|
362
|
+
begin
|
363
|
+
#if socket.class.to_s =~ /SSLSocket/
|
364
|
+
if @socket.respond_to? :shutdown
|
365
|
+
@socket.shutdown(Socket::SHUT_RDWR)
|
370
366
|
end
|
371
367
|
# finally close it
|
372
|
-
if @socket.respond_to? :close
|
373
|
-
|
368
|
+
if @socket.respond_to? :close
|
369
|
+
@socket.close
|
374
370
|
elsif @socket.respond_to? :sysclose
|
375
371
|
socket.io.shutdown(Socket::SHUT_RDWR)
|
376
|
-
|
377
|
-
end
|
378
|
-
return true
|
379
|
-
rescue => bang
|
380
|
-
puts bang
|
381
|
-
puts bang.backtrace if $DEBUG
|
382
|
-
end
|
383
|
-
false
|
384
|
-
end
|
385
|
-
|
386
|
-
def read_header
|
387
|
-
request = []
|
388
|
-
Watobo::HTTPSocket.read_client_header(@socket) do |line|
|
389
|
-
request << line
|
390
|
-
end
|
391
|
-
|
392
|
-
return nil if request.empty?
|
393
|
-
unless request.first =~ /(^[^[:space:]]{1,}) http/
|
394
|
-
request.first.gsub!(/(^[^[:space:]]{1,})( )(\/.*)/, "\\1 https://#{@site}\\3")
|
395
|
-
end
|
396
|
-
|
397
|
-
Watobo::Request.new(request)
|
398
|
-
end
|
399
|
-
|
400
|
-
def ssl?
|
401
|
-
@ssl == true
|
402
|
-
end
|
403
|
-
|
404
|
-
def request
|
405
|
-
begin
|
406
|
-
unless @initial_request.nil?
|
407
|
-
request = @initial_request.copy
|
408
|
-
@initial_request = nil
|
409
|
-
|
372
|
+
@socket.sysclose
|
373
|
+
end
|
374
|
+
return true
|
375
|
+
rescue => bang
|
376
|
+
puts bang
|
377
|
+
puts bang.backtrace if $DEBUG
|
378
|
+
end
|
379
|
+
false
|
380
|
+
end
|
381
|
+
|
382
|
+
def read_header
|
383
|
+
request = []
|
384
|
+
Watobo::HTTPSocket.read_client_header(@socket) do |line|
|
385
|
+
request << line
|
386
|
+
end
|
387
|
+
|
388
|
+
return nil if request.empty?
|
389
|
+
unless request.first =~ /(^[^[:space:]]{1,}) http/
|
390
|
+
request.first.gsub!(/(^[^[:space:]]{1,})( )(\/.*)/, "\\1 https://#{@site}\\3")
|
391
|
+
end
|
392
|
+
|
393
|
+
Watobo::Request.new(request)
|
394
|
+
end
|
395
|
+
|
396
|
+
def ssl?
|
397
|
+
@ssl == true
|
398
|
+
end
|
399
|
+
|
400
|
+
def request
|
401
|
+
begin
|
402
|
+
unless @initial_request.nil?
|
403
|
+
request = @initial_request.copy
|
404
|
+
@initial_request = nil
|
405
|
+
return request
|
410
406
|
end
|
411
407
|
|
412
408
|
request = read_header
|
413
409
|
|
414
|
-
return nil if request.nil?
|
415
|
-
|
416
|
-
clen = request.content_length
|
417
|
-
if
|
418
|
-
body = ""
|
419
|
-
Watobo::HTTPSocket.read_body(@socket) do |data|
|
420
|
-
body += data
|
421
|
-
break if body.length == clen
|
422
|
-
end
|
423
|
-
|
424
|
-
end
|
425
|
-
rescue => bang
|
426
|
-
puts bang
|
410
|
+
return nil if request.nil?
|
411
|
+
|
412
|
+
clen = request.content_length
|
413
|
+
if clen > 0 then
|
414
|
+
body = ""
|
415
|
+
Watobo::HTTPSocket.read_body(@socket) do |data|
|
416
|
+
body += data
|
417
|
+
break if body.length == clen
|
418
|
+
end
|
419
|
+
request << body
|
420
|
+
end
|
421
|
+
rescue => bang
|
422
|
+
puts bang
|
427
423
|
end
|
428
424
|
|
429
|
-
puts request
|
430
|
-
|
431
|
-
request
|
432
|
-
end
|
433
|
-
|
434
|
-
def initialize(socket, req=nil)
|
435
|
-
@socket = socket
|
436
|
-
@port = nil
|
437
|
-
@address = nil
|
438
|
-
@host = nil
|
439
|
-
@site = nil
|
440
|
-
@ssl = false
|
441
|
-
@initial_request = req
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
end
|
446
|
-
|
447
|
-
def self.connect(socket)
|
448
|
-
request = []
|
449
|
-
@fake_certs ||= {}
|
450
|
-
@dh_key ||= Watobo::CA.dh_key
|
451
|
-
|
452
|
-
ra = socket.remote_address
|
453
|
-
cport = ra.ip_port
|
425
|
+
puts request
|
426
|
+
|
427
|
+
request
|
428
|
+
end
|
429
|
+
|
430
|
+
def initialize(socket, req=nil)
|
431
|
+
@socket = socket
|
432
|
+
@port = nil
|
433
|
+
@address = nil
|
434
|
+
@host = nil
|
435
|
+
@site = nil
|
436
|
+
@ssl = false
|
437
|
+
@initial_request = req
|
438
|
+
|
439
|
+
# TODO: Fake Certs Should be global accessable
|
440
|
+
|
441
|
+
end
|
442
|
+
|
443
|
+
def self.connect(socket)
|
444
|
+
request = []
|
445
|
+
@fake_certs ||= {}
|
446
|
+
@dh_key ||= Watobo::CA.dh_key
|
447
|
+
|
448
|
+
ra = socket.remote_address
|
449
|
+
cport = ra.ip_port
|
454
450
|
caddr = ra.ip_address
|
455
451
|
|
456
452
|
optval = [1, 500_000].pack("I_2")
|
@@ -458,177 +454,177 @@ module Watobo#:nodoc: all
|
|
458
454
|
#socket.setsockopt Socket::SOL_SOCKET, Socket::SO_SNDTIMEO, optval
|
459
455
|
socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
460
456
|
#socket.setsockopt Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, 1
|
461
|
-
socket.sync = true
|
462
|
-
|
463
|
-
session = socket
|
464
|
-
|
465
|
-
if Watobo::Interceptor::Proxy.transparent?
|
466
|
-
|
467
|
-
ci = Watobo::Interceptor::Transparent.info({
|
468
|
-
unless ci['target'].empty? or ci['cn'].empty?
|
469
|
-
puts "SSL-REQUEST FROM #{caddr}:#{cport}"
|
470
|
-
|
471
|
-
ctx = Watobo::CertStore.acquire_ssl_ctx ci['target'], ci['cn']
|
472
|
-
|
473
|
-
begin
|
474
|
-
ssl_socket = OpenSSL::SSL::SSLSocket.new(socket, ctx)
|
475
|
-
#ssl_socket.setsockopt( Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, 1)
|
476
|
-
# ssl_socket.sync_close = true
|
477
|
-
ssl_socket.sync = true
|
478
|
-
# puts ssl_socket.methods.sort
|
479
|
-
session = ssl_socket.accept
|
480
|
-
rescue OpenSSL::SSL::SSLError => e
|
481
|
-
puts ">> SSLError"
|
482
|
-
puts e
|
483
|
-
return nil, session
|
484
|
-
rescue => bang
|
485
|
-
puts bang
|
486
|
-
puts bang.backtrace
|
487
|
-
return nil, session
|
488
|
-
end
|
489
|
-
else
|
490
|
-
puts ci['host']
|
491
|
-
puts ci['cn']
|
492
|
-
end
|
493
|
-
end
|
494
|
-
|
495
|
-
begin
|
496
|
-
Watobo::HTTPSocket.read_header(session) do |line|
|
497
|
-
request << line
|
457
|
+
socket.sync = true
|
458
|
+
|
459
|
+
session = socket
|
460
|
+
|
461
|
+
if Watobo::Interceptor::Proxy.transparent?
|
462
|
+
|
463
|
+
ci = Watobo::Interceptor::Transparent.info({'host' => caddr, 'port' => cport})
|
464
|
+
unless ci['target'].empty? or ci['cn'].empty?
|
465
|
+
puts "SSL-REQUEST FROM #{caddr}:#{cport}"
|
466
|
+
|
467
|
+
ctx = Watobo::CertStore.acquire_ssl_ctx ci['target'], ci['cn']
|
468
|
+
|
469
|
+
begin
|
470
|
+
ssl_socket = OpenSSL::SSL::SSLSocket.new(socket, ctx)
|
471
|
+
#ssl_socket.setsockopt( Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, 1)
|
472
|
+
# ssl_socket.sync_close = true
|
473
|
+
ssl_socket.sync = true
|
474
|
+
# puts ssl_socket.methods.sort
|
475
|
+
session = ssl_socket.accept
|
476
|
+
rescue OpenSSL::SSL::SSLError => e
|
477
|
+
puts ">> SSLError"
|
478
|
+
puts e
|
479
|
+
return nil, session
|
480
|
+
rescue => bang
|
481
|
+
puts bang
|
482
|
+
puts bang.backtrace
|
483
|
+
return nil, session
|
484
|
+
end
|
485
|
+
else
|
486
|
+
puts ci['host']
|
487
|
+
puts ci['cn']
|
488
|
+
end
|
489
|
+
end
|
490
|
+
|
491
|
+
begin
|
492
|
+
Watobo::HTTPSocket.read_header(session) do |line|
|
493
|
+
request << line
|
498
494
|
end
|
499
495
|
rescue => bang
|
500
496
|
puts bang
|
501
497
|
puts bang.backtrace if $DEBUG
|
502
498
|
return nil
|
503
|
-
end
|
504
|
-
|
505
|
-
if Watobo::Interceptor::Proxy.transparent?
|
506
|
-
#puts "> get hostname ..."
|
507
|
-
thn = nil
|
508
|
-
request.each do |l|
|
509
|
-
if l =~ /^Host: (.*)/
|
510
|
-
|
511
|
-
|
512
|
-
end
|
513
|
-
end
|
514
|
-
# puts session.class
|
515
|
-
# puts "* fix request line ..."
|
516
|
-
# puts request.first
|
517
|
-
# puts ">>"
|
518
|
-
if session.is_a? OpenSSL::SSL::SSLSocket
|
519
|
-
request.first.gsub!(/(^[^[:space:]]{1,}) (.*) (HTTP.*)/i,"\\1 https://#{thn}\\2 \\3") unless request.first =~ /^[^[:space:]]{1,} http/
|
520
|
-
else
|
521
|
-
request.first.gsub!(/(^[^[:space:]]{1,}) (.*) (HTTP.*)/i,"\\1 http://#{thn}\\2 \\3") unless request.first =~ /^[^[:space:]]{1,} http/
|
522
|
-
end
|
523
|
-
|
524
|
-
end
|
525
|
-
|
526
|
-
if request.first =~ /^CONNECT (.*):(\d{1,5}) HTTP\/1\./ then
|
527
|
-
target = $1
|
528
|
-
tport = $2
|
529
|
-
# puts request.first
|
530
|
-
#print "\n* CONNECT: #{method} #{target} on port #{tport}\n"
|
531
|
-
site = "#{target}:#{tport}"
|
532
|
-
#puts "CONNECT #{site}"
|
533
|
-
|
534
|
-
socket.print "HTTP/1.0 200 Connection established\r\n" +
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
bscount = 0 # bad handshake counter
|
539
|
-
# puts "* wait for ssl handshake ..."
|
540
|
-
begin
|
541
|
-
|
542
|
-
unless @fake_certs.has_key? site
|
543
|
-
puts "CREATE NEW CERTIFICATE FOR >> #{site} <<"
|
544
|
-
cn = Watobo::HTTPSocket.get_ssl_cert_cn(target, tport)
|
545
|
-
puts "CN=#{cn}"
|
546
|
-
|
547
|
-
cert = {
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
}
|
553
|
-
|
554
|
-
cert_file, key_file = Watobo::CA.create_cert cert
|
555
|
-
@fake_certs[site] = {
|
556
|
-
|
557
|
-
|
558
|
-
}
|
559
|
-
end
|
560
|
-
ctx = OpenSSL::SSL::SSLContext.new()
|
561
|
-
|
562
|
-
#ctx.cert = @cert
|
563
|
-
ctx.cert = @fake_certs[site][:cert]
|
564
|
-
# @ctx.key = OpenSSL::PKey::DSA.new(File.read(key_file))
|
565
|
-
#ctx.key = @key
|
566
|
-
ctx.key = @fake_certs[site][:key]
|
567
|
-
ctx.tmp_dh_callback = proc { |*args|
|
568
|
-
@dh_key
|
569
|
-
}
|
570
|
-
|
571
|
-
ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
572
|
-
ctx.timeout = 10
|
573
|
-
|
574
|
-
ssl_socket = OpenSSL::SSL::SSLSocket.new(socket, ctx)
|
575
|
-
ssl_socket.setsockopt(
|
576
|
-
# ssl_socket.sync_close = true
|
577
|
-
ssl_socket.sync = true
|
578
|
-
# puts ssl_socket.methods.sort
|
579
|
-
|
580
|
-
ssl_session = ssl_socket.accept
|
581
|
-
rescue => bang
|
582
|
-
puts bang
|
583
|
-
puts bang.backtrace if $DEBUG
|
584
|
-
|
585
|
-
return nil
|
586
|
-
|
587
|
-
end
|
588
|
-
session = ssl_session
|
589
|
-
request = nil
|
590
|
-
else
|
591
|
-
|
592
|
-
request = Watobo::Request.new(request)
|
593
|
-
|
594
|
-
|
595
|
-
end
|
596
|
-
|
597
|
-
begin
|
598
|
-
|
599
|
-
unless request.nil?
|
600
|
-
clen = request.content_length
|
601
|
-
if
|
602
|
-
body = ""
|
603
|
-
Watobo::HTTPSocket.read_body(session) do |data|
|
604
|
-
body += data
|
605
|
-
break if body.length == clen
|
606
|
-
end
|
607
|
-
|
608
|
-
end
|
609
|
-
connection = ClientSocket.new(session, request)
|
610
|
-
else
|
611
|
-
connection = ClientSocket.new(session)
|
612
|
-
end
|
613
|
-
|
614
|
-
connection.ssl = true if session.class.to_s =~ /ssl/i
|
615
|
-
|
616
|
-
# ra = session.remote_address
|
617
|
-
# connection.port = ra.ip_port
|
618
|
-
# connection.address = ra.ip_address
|
619
|
-
# connection.site = site
|
620
|
-
|
621
|
-
connection.port = cport
|
622
|
-
connection.address = caddr
|
623
|
-
connection.site = site
|
624
|
-
rescue => bang
|
625
|
-
puts bang
|
626
|
-
puts bang.backtrace
|
627
|
-
end
|
628
|
-
connection
|
629
|
-
end
|
630
|
-
|
499
|
+
end
|
500
|
+
|
501
|
+
if Watobo::Interceptor::Proxy.transparent?
|
502
|
+
#puts "> get hostname ..."
|
503
|
+
thn = nil
|
504
|
+
request.each do |l|
|
505
|
+
if l =~ /^Host: (.*)/
|
506
|
+
thn = $1.strip
|
507
|
+
# puts ">> #{thn}"
|
508
|
+
end
|
509
|
+
end
|
510
|
+
# puts session.class
|
511
|
+
# puts "* fix request line ..."
|
512
|
+
# puts request.first
|
513
|
+
# puts ">>"
|
514
|
+
if session.is_a? OpenSSL::SSL::SSLSocket
|
515
|
+
request.first.gsub!(/(^[^[:space:]]{1,}) (.*) (HTTP.*)/i, "\\1 https://#{thn}\\2 \\3") unless request.first =~ /^[^[:space:]]{1,} http/
|
516
|
+
else
|
517
|
+
request.first.gsub!(/(^[^[:space:]]{1,}) (.*) (HTTP.*)/i, "\\1 http://#{thn}\\2 \\3") unless request.first =~ /^[^[:space:]]{1,} http/
|
518
|
+
end
|
519
|
+
#puts request.first
|
520
|
+
end
|
521
|
+
|
522
|
+
if request.first =~ /^CONNECT (.*):(\d{1,5}) HTTP\/1\./ then
|
523
|
+
target = $1
|
524
|
+
tport = $2
|
525
|
+
# puts request.first
|
526
|
+
#print "\n* CONNECT: #{method} #{target} on port #{tport}\n"
|
527
|
+
site = "#{target}:#{tport}"
|
528
|
+
#puts "CONNECT #{site}"
|
529
|
+
|
530
|
+
socket.print "HTTP/1.0 200 Connection established\r\n" +
|
531
|
+
#"Proxy-connection: Keep-alive\r\n" +
|
532
|
+
"Proxy-agent: WATOBO-Proxy/1.1\r\n" +
|
533
|
+
"\r\n"
|
534
|
+
bscount = 0 # bad handshake counter
|
535
|
+
# puts "* wait for ssl handshake ..."
|
536
|
+
begin
|
537
|
+
# site = "#{target}:#{tport}"
|
538
|
+
unless @fake_certs.has_key? site
|
539
|
+
puts "CREATE NEW CERTIFICATE FOR >> #{site} <<"
|
540
|
+
cn = Watobo::HTTPSocket.get_ssl_cert_cn(target, tport)
|
541
|
+
puts "CN=#{cn}"
|
542
|
+
|
543
|
+
cert = {
|
544
|
+
:hostname => cn,
|
545
|
+
:type => 'server',
|
546
|
+
:user => 'watobo',
|
547
|
+
:email => 'root@localhost',
|
548
|
+
}
|
549
|
+
|
550
|
+
cert_file, key_file = Watobo::CA.create_cert cert
|
551
|
+
@fake_certs[site] = {
|
552
|
+
:cert => OpenSSL::X509::Certificate.new(File.read(cert_file)),
|
553
|
+
:key => OpenSSL::PKey::RSA.new(File.read(key_file))
|
554
|
+
}
|
555
|
+
end
|
556
|
+
ctx = OpenSSL::SSL::SSLContext.new()
|
557
|
+
|
558
|
+
#ctx.cert = @cert
|
559
|
+
ctx.cert = @fake_certs[site][:cert]
|
560
|
+
# @ctx.key = OpenSSL::PKey::DSA.new(File.read(key_file))
|
561
|
+
#ctx.key = @key
|
562
|
+
ctx.key = @fake_certs[site][:key]
|
563
|
+
ctx.tmp_dh_callback = proc { |*args|
|
564
|
+
@dh_key
|
565
|
+
}
|
566
|
+
|
567
|
+
ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
568
|
+
ctx.timeout = 10
|
569
|
+
|
570
|
+
ssl_socket = OpenSSL::SSL::SSLSocket.new(socket, ctx)
|
571
|
+
ssl_socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, 1)
|
572
|
+
# ssl_socket.sync_close = true
|
573
|
+
ssl_socket.sync = true
|
574
|
+
# puts ssl_socket.methods.sort
|
575
|
+
|
576
|
+
ssl_session = ssl_socket.accept
|
577
|
+
rescue => bang
|
578
|
+
puts bang
|
579
|
+
puts bang.backtrace if $DEBUG
|
580
|
+
|
581
|
+
return nil
|
582
|
+
|
583
|
+
end
|
584
|
+
session = ssl_session
|
585
|
+
request = nil
|
586
|
+
else
|
587
|
+
# puts "* create request object"
|
588
|
+
request = Watobo::Request.new(request)
|
589
|
+
site = request.site
|
590
|
+
#puts request
|
591
|
+
end
|
592
|
+
|
593
|
+
begin
|
594
|
+
|
595
|
+
unless request.nil?
|
596
|
+
clen = request.content_length
|
597
|
+
if clen > 0 then
|
598
|
+
body = ""
|
599
|
+
Watobo::HTTPSocket.read_body(session) do |data|
|
600
|
+
body += data
|
601
|
+
break if body.length == clen
|
602
|
+
end
|
603
|
+
request << body unless body.empty?
|
604
|
+
end
|
605
|
+
connection = ClientSocket.new(session, request)
|
606
|
+
else
|
607
|
+
connection = ClientSocket.new(session)
|
608
|
+
end
|
609
|
+
|
610
|
+
connection.ssl = true if session.class.to_s =~ /ssl/i
|
611
|
+
|
612
|
+
# ra = session.remote_address
|
613
|
+
# connection.port = ra.ip_port
|
614
|
+
# connection.address = ra.ip_address
|
615
|
+
# connection.site = site
|
616
|
+
|
617
|
+
connection.port = cport
|
618
|
+
connection.address = caddr
|
619
|
+
connection.site = site
|
620
|
+
rescue => bang
|
621
|
+
puts bang
|
622
|
+
puts bang.backtrace
|
623
|
+
end
|
624
|
+
connection
|
625
|
+
end
|
626
|
+
|
631
627
|
end
|
632
628
|
|
633
|
-
end
|
634
|
-
end
|
629
|
+
end
|
630
|
+
end
|