watobo 0.9.14 → 0.9.15
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +29 -0
- data/config/interceptor.yml +1 -0
- data/lib/watobo/core/active_check.rb +1 -2
- data/lib/watobo/core/client_cert_store.rb +47 -0
- data/lib/watobo/core/scanner3.rb +124 -88
- data/lib/watobo/core/session.rb +52 -47
- data/lib/watobo/core.rb +1 -11
- data/lib/watobo/gui/chatviewer_frame.rb +5 -3
- data/lib/watobo/gui/checkboxtree.rb +59 -14
- data/lib/watobo/gui/checks_policy_frame.rb +1 -5
- data/lib/watobo/gui/client_cert_dialog.rb +260 -96
- data/lib/watobo/gui/conversation_table.rb +7 -1
- data/lib/watobo/gui/conversation_table_ctrl2.rb +14 -5
- data/lib/watobo/gui/edit_comment.rb +1 -1
- data/lib/watobo/gui/main_window.rb +40 -5
- data/lib/watobo/gui/manual_request_editor.rb +10 -8
- data/lib/watobo/gui/quick_scan_dialog.rb +8 -6
- data/lib/watobo/gui/scanner_settings_dialog.rb +1 -0
- data/lib/watobo/gui/text_viewer.rb +5 -3
- data/lib/watobo/http/cookies/cookies.rb +3 -1
- data/lib/watobo/http_socket/agent.rb +1 -1
- data/lib/watobo/http_socket/client_socket.rb +409 -98
- data/lib/watobo/http_socket/connection.rb +1 -1
- data/lib/watobo/http_socket/http_socket.rb +47 -39
- data/lib/watobo/interceptor/proxy.rb +41 -212
- data/lib/watobo/mixins/httpparser.rb +17 -16
- data/lib/watobo/mixins/shapers.rb +3 -7
- data/lib/watobo.rb +2 -1
- data/modules/active/domino/domino_db.rb +5 -7
- data/modules/active/struts2/default_handler_ognl.rb +128 -0
- data/modules/active/struts2/include_params_ognl.rb +127 -0
- data/modules/passive/ajax.rb +5 -3
- data/modules/passive/detect_infrastructure.rb +2 -3
- data/modules/passive/dirindexing.rb +8 -6
- data/modules/passive/disclosure_emails.rb +13 -14
- data/modules/passive/disclosure_ipaddr.rb +13 -13
- data/modules/passive/hotspots.rb +6 -4
- data/modules/passive/in_script_parameter.rb +25 -19
- data/modules/passive/redirectionz.rb +1 -1
- data/modules/passive/sap-headers.rb +78 -0
- data/modules/passive/xss_dom.rb +5 -3
- data/plugins/catalog/catalog.rb +7 -2
- data/plugins/crawler/gui/auth_frame.rb +20 -5
- data/plugins/crawler/gui/crawler_gui.rb +56 -9
- data/plugins/crawler/lib/engine.rb +12 -14
- data/plugins/filefinder/dbs/sap.db +157 -0
- metadata +23 -2
@@ -28,13 +28,11 @@ module Watobo#:nodoc: all
|
|
28
28
|
attr_accessor :host
|
29
29
|
attr_accessor :site
|
30
30
|
attr_accessor :ssl
|
31
|
-
|
32
|
-
|
33
31
|
def write(data)
|
34
32
|
@socket.write data
|
35
33
|
@socket.flush
|
36
34
|
end
|
37
|
-
|
35
|
+
|
38
36
|
def flush
|
39
37
|
@socket.flush
|
40
38
|
end
|
@@ -42,15 +40,15 @@ module Watobo#:nodoc: all
|
|
42
40
|
def close
|
43
41
|
begin
|
44
42
|
#if socket.class.to_s =~ /SSLSocket/
|
45
|
-
if @socket.respond_to? :
|
46
|
-
#socket.io.shutdown(2)
|
47
|
-
@socket.sysclose
|
48
|
-
elsif @socket.respond_to? :shutdown
|
43
|
+
if @socket.respond_to? :shutdown
|
49
44
|
@socket.shutdown(Socket::SHUT_RDWR)
|
50
45
|
end
|
51
46
|
# finally close it
|
52
47
|
if @socket.respond_to? :close
|
53
|
-
|
48
|
+
@socket.close
|
49
|
+
elsif @socket.respond_to? :sysclose
|
50
|
+
socket.io.shutdown(Socket::SHUT_RDWR)
|
51
|
+
@socket.sysclose
|
54
52
|
end
|
55
53
|
return true
|
56
54
|
rescue => bang
|
@@ -65,7 +63,7 @@ module Watobo#:nodoc: all
|
|
65
63
|
Watobo::HTTPSocket.read_client_header(@socket) do |line|
|
66
64
|
request << line
|
67
65
|
end
|
68
|
-
|
66
|
+
|
69
67
|
return nil if request.empty?
|
70
68
|
unless request.first =~ /(^[^[:space:]]{1,}) http/
|
71
69
|
request.first.gsub!(/(^[^[:space:]]{1,})( )(\/.*)/, "\\1 https://#{@site}\\3")
|
@@ -79,33 +77,43 @@ module Watobo#:nodoc: all
|
|
79
77
|
end
|
80
78
|
|
81
79
|
def request
|
80
|
+
@persistent = false
|
82
81
|
begin
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
82
|
+
unless @initial_request.nil?
|
83
|
+
request = @initial_request.copy
|
84
|
+
@initial_request = nil
|
85
|
+
clean_request request
|
86
|
+
return request
|
87
|
+
end
|
88
|
+
|
89
|
+
request = read_header
|
90
|
+
|
91
|
+
return nil if request.nil?
|
92
|
+
|
93
|
+
@persistent = !request.connection_close?
|
94
|
+
|
95
|
+
clen = request.content_length
|
96
|
+
if clen > 0 then
|
97
|
+
body = ""
|
98
|
+
Watobo::HTTPSocket.read_body(@socket) do |data|
|
99
|
+
body += data
|
100
|
+
break if body.length == clen
|
101
|
+
end
|
102
|
+
request << body
|
99
103
|
end
|
100
|
-
request << body
|
101
|
-
end
|
102
104
|
rescue => bang
|
103
105
|
puts bang
|
104
106
|
end
|
105
107
|
|
108
|
+
clean_request request
|
109
|
+
|
106
110
|
request
|
107
111
|
end
|
108
112
|
|
113
|
+
def send_response(response)
|
114
|
+
|
115
|
+
end
|
116
|
+
|
109
117
|
def initialize(socket, req=nil)
|
110
118
|
@socket = socket
|
111
119
|
@port = nil
|
@@ -114,7 +122,8 @@ module Watobo#:nodoc: all
|
|
114
122
|
@site = nil
|
115
123
|
@ssl = false
|
116
124
|
@initial_request = req
|
117
|
-
|
125
|
+
@persistent = false
|
126
|
+
|
118
127
|
# TODO: Fake Certs Should be global accessable
|
119
128
|
|
120
129
|
end
|
@@ -127,71 +136,372 @@ module Watobo#:nodoc: all
|
|
127
136
|
ra = socket.remote_address
|
128
137
|
cport = ra.ip_port
|
129
138
|
caddr = ra.ip_address
|
130
|
-
|
139
|
+
|
131
140
|
optval = [1, 500_000].pack("I_2")
|
132
|
-
socket.setsockopt Socket::SOL_SOCKET, Socket::SO_RCVTIMEO, optval
|
133
|
-
socket.setsockopt Socket::SOL_SOCKET, Socket::SO_SNDTIMEO, optval
|
134
|
-
socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
135
|
-
socket.setsockopt Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, 1
|
136
|
-
socket.sync = true
|
141
|
+
# socket.setsockopt Socket::SOL_SOCKET, Socket::SO_RCVTIMEO, optval
|
142
|
+
# socket.setsockopt Socket::SOL_SOCKET, Socket::SO_SNDTIMEO, optval
|
143
|
+
socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
144
|
+
# socket.setsockopt Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, 1
|
145
|
+
socket.sync = true
|
137
146
|
|
138
147
|
session = socket
|
139
|
-
|
148
|
+
|
140
149
|
if Watobo::Interceptor::Proxy.transparent?
|
141
150
|
|
142
|
-
|
143
|
-
|
144
|
-
|
151
|
+
ci = Watobo::Interceptor::Transparent.info({ 'host' => caddr, 'port' => cport } )
|
152
|
+
unless ci['target'].empty? or ci['cn'].empty?
|
153
|
+
puts "SSL-REQUEST FROM #{caddr}:#{cport}"
|
154
|
+
|
155
|
+
ctx = Watobo::CertStore.acquire_ssl_ctx ci['target'], ci['cn']
|
156
|
+
|
157
|
+
begin
|
158
|
+
ssl_socket = OpenSSL::SSL::SSLSocket.new(socket, ctx)
|
159
|
+
#ssl_socket.setsockopt( Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, 1)
|
160
|
+
# ssl_socket.sync_close = true
|
161
|
+
ssl_socket.sync = true
|
162
|
+
# puts ssl_socket.methods.sort
|
163
|
+
session = ssl_socket.accept
|
164
|
+
rescue OpenSSL::SSL::SSLError => e
|
165
|
+
puts ">> SSLError"
|
166
|
+
puts e
|
167
|
+
return nil, session
|
168
|
+
rescue => bang
|
169
|
+
puts bang
|
170
|
+
puts bang.backtrace
|
171
|
+
return nil, session
|
172
|
+
end
|
173
|
+
else
|
174
|
+
puts ci['host']
|
175
|
+
puts ci['cn']
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
begin
|
180
|
+
Watobo::HTTPSocket.read_header(session) do |line|
|
181
|
+
request << line
|
182
|
+
end
|
183
|
+
rescue => bang
|
184
|
+
puts bang
|
185
|
+
puts bang.backtrace if $DEBUG
|
186
|
+
return nil
|
187
|
+
end
|
188
|
+
|
189
|
+
if Watobo::Interceptor::Proxy.transparent?
|
190
|
+
#puts "> get hostname ..."
|
191
|
+
thn = nil
|
192
|
+
request.each do |l|
|
193
|
+
if l =~ /^Host: (.*)/
|
194
|
+
thn = $1.strip
|
195
|
+
# puts ">> #{thn}"
|
196
|
+
end
|
197
|
+
end
|
198
|
+
# puts session.class
|
199
|
+
# puts "* fix request line ..."
|
200
|
+
# puts request.first
|
201
|
+
# puts ">>"
|
202
|
+
if session.is_a? OpenSSL::SSL::SSLSocket
|
203
|
+
request.first.gsub!(/(^[^[:space:]]{1,}) (.*) (HTTP.*)/i,"\\1 https://#{thn}\\2 \\3") unless request.first =~ /^[^[:space:]]{1,} http/
|
204
|
+
else
|
205
|
+
request.first.gsub!(/(^[^[:space:]]{1,}) (.*) (HTTP.*)/i,"\\1 http://#{thn}\\2 \\3") unless request.first =~ /^[^[:space:]]{1,} http/
|
206
|
+
end
|
207
|
+
#puts request.first
|
208
|
+
end
|
145
209
|
|
146
|
-
|
210
|
+
if request.first =~ /^CONNECT (.*):(\d{1,5}) HTTP\/1\./ then
|
211
|
+
target = $1
|
212
|
+
tport = $2
|
213
|
+
# puts request.first
|
214
|
+
#print "\n* CONNECT: #{method} #{target} on port #{tport}\n"
|
215
|
+
site = "#{target}:#{tport}"
|
216
|
+
#puts "CONNECT #{site}"
|
147
217
|
|
218
|
+
socket.print "HTTP/1.0 200 Connection established\r\n" +
|
219
|
+
#"Proxy-connection: Keep-alive\r\n" +
|
220
|
+
"Proxy-agent: WATOBO-Proxy/1.1\r\n" +
|
221
|
+
"\r\n"
|
222
|
+
bscount = 0 # bad handshake counter
|
223
|
+
# puts "* wait for ssl handshake ..."
|
148
224
|
begin
|
225
|
+
# site = "#{target}:#{tport}"
|
226
|
+
unless @fake_certs.has_key? site
|
227
|
+
puts "CREATE NEW CERTIFICATE FOR >> #{site} <<"
|
228
|
+
cn = Watobo::HTTPSocket.get_ssl_cert_cn(target, tport)
|
229
|
+
puts "CN=#{cn}"
|
230
|
+
|
231
|
+
cert = {
|
232
|
+
:hostname => cn,
|
233
|
+
:type => 'server',
|
234
|
+
:user => 'watobo',
|
235
|
+
:email => 'root@localhost',
|
236
|
+
}
|
237
|
+
|
238
|
+
cert_file, key_file = Watobo::CA.create_cert cert
|
239
|
+
@fake_certs[site] = {
|
240
|
+
:cert => OpenSSL::X509::Certificate.new(File.read(cert_file)),
|
241
|
+
:key => OpenSSL::PKey::RSA.new(File.read(key_file))
|
242
|
+
}
|
243
|
+
end
|
244
|
+
ctx = OpenSSL::SSL::SSLContext.new()
|
245
|
+
|
246
|
+
#ctx.cert = @cert
|
247
|
+
ctx.cert = @fake_certs[site][:cert]
|
248
|
+
# @ctx.key = OpenSSL::PKey::DSA.new(File.read(key_file))
|
249
|
+
#ctx.key = @key
|
250
|
+
ctx.key = @fake_certs[site][:key]
|
251
|
+
ctx.tmp_dh_callback = proc { |*args|
|
252
|
+
@dh_key
|
253
|
+
}
|
254
|
+
|
255
|
+
ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
256
|
+
ctx.timeout = 10
|
257
|
+
|
149
258
|
ssl_socket = OpenSSL::SSL::SSLSocket.new(socket, ctx)
|
150
|
-
|
151
|
-
#
|
259
|
+
ssl_socket.setsockopt( Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, 1)
|
260
|
+
# ssl_socket.sync_close = true
|
152
261
|
ssl_socket.sync = true
|
153
262
|
# puts ssl_socket.methods.sort
|
154
|
-
|
155
|
-
|
156
|
-
puts ">> SSLError"
|
157
|
-
puts e
|
158
|
-
return nil, session
|
263
|
+
|
264
|
+
ssl_session = ssl_socket.accept
|
159
265
|
rescue => bang
|
160
266
|
puts bang
|
161
|
-
puts bang.backtrace
|
162
|
-
|
267
|
+
puts bang.backtrace if $DEBUG
|
268
|
+
|
269
|
+
return nil
|
270
|
+
|
163
271
|
end
|
272
|
+
session = ssl_session
|
273
|
+
request = nil
|
164
274
|
else
|
165
|
-
|
166
|
-
|
275
|
+
# puts "* create request object"
|
276
|
+
request = Watobo::Request.new(request)
|
277
|
+
site = request.site
|
278
|
+
#puts request
|
279
|
+
end
|
280
|
+
|
281
|
+
begin
|
282
|
+
|
283
|
+
unless request.nil?
|
284
|
+
clen = request.content_length
|
285
|
+
if clen > 0 then
|
286
|
+
body = ""
|
287
|
+
Watobo::HTTPSocket.read_body(session) do |data|
|
288
|
+
body += data
|
289
|
+
break if body.length == clen
|
290
|
+
end
|
291
|
+
request << body unless body.empty?
|
292
|
+
end
|
293
|
+
connection = ClientSocket.new(session, request)
|
294
|
+
else
|
295
|
+
connection = ClientSocket.new(session)
|
296
|
+
end
|
297
|
+
|
298
|
+
connection.ssl = true if session.class.to_s =~ /ssl/i
|
299
|
+
|
300
|
+
# ra = session.remote_address
|
301
|
+
# connection.port = ra.ip_port
|
302
|
+
# connection.address = ra.ip_address
|
303
|
+
# connection.site = site
|
304
|
+
|
305
|
+
connection.port = cport
|
306
|
+
connection.address = caddr
|
307
|
+
connection.site = site
|
308
|
+
rescue => bang
|
309
|
+
puts bang
|
310
|
+
puts bang.backtrace
|
311
|
+
end
|
312
|
+
connection
|
313
|
+
end
|
314
|
+
|
315
|
+
private
|
316
|
+
|
317
|
+
# clean request removes unneccessary headers
|
318
|
+
# e.g., hop_by_hop headers
|
319
|
+
def clean_request(request)
|
320
|
+
# puts request
|
321
|
+
request.remove_header "Connection"
|
322
|
+
request.remove_header "Proxy\-Connection"
|
323
|
+
request.remove_header "If\-"
|
324
|
+
|
325
|
+
request.remove_header("^Accept-Encoding")
|
326
|
+
end
|
327
|
+
|
328
|
+
end
|
329
|
+
|
330
|
+
class ClientSocket_ORIG
|
331
|
+
attr_accessor :port
|
332
|
+
attr_accessor :address
|
333
|
+
attr_accessor :host
|
334
|
+
attr_accessor :site
|
335
|
+
attr_accessor :ssl
|
336
|
+
def write(data)
|
337
|
+
@socket.write data
|
338
|
+
@socket.flush
|
339
|
+
end
|
340
|
+
|
341
|
+
def flush
|
342
|
+
@socket.flush
|
343
|
+
end
|
344
|
+
|
345
|
+
def close
|
346
|
+
begin
|
347
|
+
#if socket.class.to_s =~ /SSLSocket/
|
348
|
+
if @socket.respond_to? :shutdown
|
349
|
+
@socket.shutdown(Socket::SHUT_RDWR)
|
350
|
+
end
|
351
|
+
# finally close it
|
352
|
+
if @socket.respond_to? :close
|
353
|
+
@socket.close
|
354
|
+
elsif @socket.respond_to? :sysclose
|
355
|
+
socket.io.shutdown(Socket::SHUT_RDWR)
|
356
|
+
@socket.sysclose
|
357
|
+
end
|
358
|
+
return true
|
359
|
+
rescue => bang
|
360
|
+
puts bang
|
361
|
+
puts bang.backtrace if $DEBUG
|
167
362
|
end
|
363
|
+
false
|
168
364
|
end
|
169
|
-
|
170
|
-
|
171
|
-
|
365
|
+
|
366
|
+
def read_header
|
367
|
+
request = []
|
368
|
+
Watobo::HTTPSocket.read_client_header(@socket) do |line|
|
172
369
|
request << line
|
173
370
|
end
|
174
|
-
|
371
|
+
|
372
|
+
return nil if request.empty?
|
373
|
+
unless request.first =~ /(^[^[:space:]]{1,}) http/
|
374
|
+
request.first.gsub!(/(^[^[:space:]]{1,})( )(\/.*)/, "\\1 https://#{@site}\\3")
|
375
|
+
end
|
376
|
+
|
377
|
+
Watobo::Request.new(request)
|
378
|
+
end
|
379
|
+
|
380
|
+
def ssl?
|
381
|
+
@ssl == true
|
382
|
+
end
|
383
|
+
|
384
|
+
def request
|
385
|
+
begin
|
386
|
+
unless @initial_request.nil?
|
387
|
+
request = @initial_request.copy
|
388
|
+
@initial_request = nil
|
389
|
+
return request
|
390
|
+
end
|
391
|
+
|
392
|
+
request = read_header
|
393
|
+
|
394
|
+
return nil if request.nil?
|
395
|
+
|
396
|
+
clen = request.content_length
|
397
|
+
if clen > 0 then
|
398
|
+
body = ""
|
399
|
+
Watobo::HTTPSocket.read_body(@socket) do |data|
|
400
|
+
body += data
|
401
|
+
break if body.length == clen
|
402
|
+
end
|
403
|
+
request << body
|
404
|
+
end
|
405
|
+
rescue => bang
|
406
|
+
puts bang
|
407
|
+
end
|
408
|
+
|
409
|
+
puts request
|
410
|
+
|
411
|
+
request
|
412
|
+
end
|
413
|
+
|
414
|
+
def initialize(socket, req=nil)
|
415
|
+
@socket = socket
|
416
|
+
@port = nil
|
417
|
+
@address = nil
|
418
|
+
@host = nil
|
419
|
+
@site = nil
|
420
|
+
@ssl = false
|
421
|
+
@initial_request = req
|
422
|
+
|
423
|
+
# TODO: Fake Certs Should be global accessable
|
424
|
+
|
425
|
+
end
|
426
|
+
|
427
|
+
def self.connect(socket)
|
428
|
+
request = []
|
429
|
+
@fake_certs ||= {}
|
430
|
+
@dh_key ||= Watobo::CA.dh_key
|
431
|
+
|
432
|
+
ra = socket.remote_address
|
433
|
+
cport = ra.ip_port
|
434
|
+
caddr = ra.ip_address
|
435
|
+
|
436
|
+
optval = [1, 500_000].pack("I_2")
|
437
|
+
#socket.setsockopt Socket::SOL_SOCKET, Socket::SO_RCVTIMEO, optval
|
438
|
+
#socket.setsockopt Socket::SOL_SOCKET, Socket::SO_SNDTIMEO, optval
|
439
|
+
socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
440
|
+
#socket.setsockopt Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, 1
|
441
|
+
socket.sync = true
|
442
|
+
|
443
|
+
session = socket
|
444
|
+
|
175
445
|
if Watobo::Interceptor::Proxy.transparent?
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
446
|
+
|
447
|
+
ci = Watobo::Interceptor::Transparent.info({ 'host' => caddr, 'port' => cport } )
|
448
|
+
unless ci['target'].empty? or ci['cn'].empty?
|
449
|
+
puts "SSL-REQUEST FROM #{caddr}:#{cport}"
|
450
|
+
|
451
|
+
ctx = Watobo::CertStore.acquire_ssl_ctx ci['target'], ci['cn']
|
452
|
+
|
453
|
+
begin
|
454
|
+
ssl_socket = OpenSSL::SSL::SSLSocket.new(socket, ctx)
|
455
|
+
#ssl_socket.setsockopt( Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, 1)
|
456
|
+
# ssl_socket.sync_close = true
|
457
|
+
ssl_socket.sync = true
|
458
|
+
# puts ssl_socket.methods.sort
|
459
|
+
session = ssl_socket.accept
|
460
|
+
rescue OpenSSL::SSL::SSLError => e
|
461
|
+
puts ">> SSLError"
|
462
|
+
puts e
|
463
|
+
return nil, session
|
464
|
+
rescue => bang
|
465
|
+
puts bang
|
466
|
+
puts bang.backtrace
|
467
|
+
return nil, session
|
468
|
+
end
|
469
|
+
else
|
470
|
+
puts ci['host']
|
471
|
+
puts ci['cn']
|
182
472
|
end
|
183
473
|
end
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
474
|
+
|
475
|
+
begin
|
476
|
+
Watobo::HTTPSocket.read_header(session) do |line|
|
477
|
+
request << line
|
478
|
+
end
|
479
|
+
rescue => bang
|
480
|
+
puts bang
|
481
|
+
puts bang.backtrace if $DEBUG
|
482
|
+
return nil
|
483
|
+
end
|
484
|
+
|
485
|
+
if Watobo::Interceptor::Proxy.transparent?
|
486
|
+
#puts "> get hostname ..."
|
487
|
+
thn = nil
|
488
|
+
request.each do |l|
|
489
|
+
if l =~ /^Host: (.*)/
|
490
|
+
thn = $1.strip
|
491
|
+
# puts ">> #{thn}"
|
492
|
+
end
|
493
|
+
end
|
494
|
+
# puts session.class
|
495
|
+
# puts "* fix request line ..."
|
496
|
+
# puts request.first
|
497
|
+
# puts ">>"
|
498
|
+
if session.is_a? OpenSSL::SSL::SSLSocket
|
499
|
+
request.first.gsub!(/(^[^[:space:]]{1,}) (.*) (HTTP.*)/i,"\\1 https://#{thn}\\2 \\3") unless request.first =~ /^[^[:space:]]{1,} http/
|
500
|
+
else
|
501
|
+
request.first.gsub!(/(^[^[:space:]]{1,}) (.*) (HTTP.*)/i,"\\1 http://#{thn}\\2 \\3") unless request.first =~ /^[^[:space:]]{1,} http/
|
502
|
+
end
|
503
|
+
#puts request.first
|
192
504
|
end
|
193
|
-
#puts request.first
|
194
|
-
end
|
195
505
|
|
196
506
|
if request.first =~ /^CONNECT (.*):(\d{1,5}) HTTP\/1\./ then
|
197
507
|
target = $1
|
@@ -202,13 +512,13 @@ module Watobo#:nodoc: all
|
|
202
512
|
#puts "CONNECT #{site}"
|
203
513
|
|
204
514
|
socket.print "HTTP/1.0 200 Connection established\r\n" +
|
205
|
-
"Proxy-connection: Keep-alive\r\n" +
|
515
|
+
#"Proxy-connection: Keep-alive\r\n" +
|
206
516
|
"Proxy-agent: WATOBO-Proxy/1.1\r\n" +
|
207
517
|
"\r\n"
|
208
518
|
bscount = 0 # bad handshake counter
|
209
519
|
# puts "* wait for ssl handshake ..."
|
210
520
|
begin
|
211
|
-
|
521
|
+
# site = "#{target}:#{tport}"
|
212
522
|
unless @fake_certs.has_key? site
|
213
523
|
puts "CREATE NEW CERTIFICATE FOR >> #{site} <<"
|
214
524
|
cn = Watobo::HTTPSocket.get_ssl_cert_cn(target, tport)
|
@@ -258,39 +568,39 @@ module Watobo#:nodoc: all
|
|
258
568
|
session = ssl_session
|
259
569
|
request = nil
|
260
570
|
else
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
571
|
+
# puts "* create request object"
|
572
|
+
request = Watobo::Request.new(request)
|
573
|
+
site = request.site
|
574
|
+
#puts request
|
265
575
|
end
|
266
|
-
|
576
|
+
|
267
577
|
begin
|
268
578
|
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
579
|
+
unless request.nil?
|
580
|
+
clen = request.content_length
|
581
|
+
if clen > 0 then
|
582
|
+
body = ""
|
583
|
+
Watobo::HTTPSocket.read_body(session) do |data|
|
584
|
+
body += data
|
585
|
+
break if body.length == clen
|
586
|
+
end
|
587
|
+
request << body unless body.empty?
|
276
588
|
end
|
277
|
-
|
589
|
+
connection = ClientSocket.new(session, request)
|
590
|
+
else
|
591
|
+
connection = ClientSocket.new(session)
|
278
592
|
end
|
279
|
-
connection = ClientSocket.new(session, request)
|
280
|
-
else
|
281
|
-
connection = ClientSocket.new(session)
|
282
|
-
end
|
283
593
|
|
284
|
-
|
594
|
+
connection.ssl = true if session.class.to_s =~ /ssl/i
|
595
|
+
|
596
|
+
# ra = session.remote_address
|
597
|
+
# connection.port = ra.ip_port
|
598
|
+
# connection.address = ra.ip_address
|
599
|
+
# connection.site = site
|
285
600
|
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
# connection.site = site
|
290
|
-
|
291
|
-
connection.port = cport
|
292
|
-
connection.address = caddr
|
293
|
-
connection.site = site
|
601
|
+
connection.port = cport
|
602
|
+
connection.address = caddr
|
603
|
+
connection.site = site
|
294
604
|
rescue => bang
|
295
605
|
puts bang
|
296
606
|
puts bang.backtrace
|
@@ -299,5 +609,6 @@ module Watobo#:nodoc: all
|
|
299
609
|
end
|
300
610
|
|
301
611
|
end
|
612
|
+
|
302
613
|
end
|
303
614
|
end
|