Module: Watobo::Mixin::Shaper::Web10
- Includes:
- Constants
- Defined in:
- lib/watobo/mixins/shapers.rb
Constant Summary
Constants included
from Constants
Constants::AC_GROUP_APACHE, Constants::AC_GROUP_DOMINO, Constants::AC_GROUP_ENUMERATION, Constants::AC_GROUP_FILE_INCLUSION, Constants::AC_GROUP_FLASH, Constants::AC_GROUP_GENERIC, Constants::AC_GROUP_JBOSS, Constants::AC_GROUP_JOOMLA, Constants::AC_GROUP_SAP, Constants::AC_GROUP_SQL, Constants::AC_GROUP_TYPO3, Constants::AC_GROUP_XSS, Constants::AUTH_TYPE_BASIC, Constants::AUTH_TYPE_DIGEST, Constants::AUTH_TYPE_NONE, Constants::AUTH_TYPE_NTLM, Constants::AUTH_TYPE_UNKNOWN, Constants::CHAT_SOURCE_AUTO_SCAN, Constants::CHAT_SOURCE_FUZZER, Constants::CHAT_SOURCE_INTERCEPT, Constants::CHAT_SOURCE_MANUAL, Constants::CHAT_SOURCE_MANUAL_SCAN, Constants::CHAT_SOURCE_PROXY, Constants::CHAT_SOURCE_UNDEF, Constants::DEFAULT_PORT_HTTP, Constants::DEFAULT_PORT_HTTPS, Constants::FINDING_TYPE_HINT, Constants::FINDING_TYPE_INFO, Constants::FINDING_TYPE_UNDEFINED, Constants::FINDING_TYPE_VULN, Constants::FIRST_TIME_FILE, Constants::GUI_REGULAR_FONT_SIZE, Constants::GUI_SMALL_FONT_SIZE, Constants::ICON_PATH, Constants::LOG_DEBUG, Constants::LOG_INFO, Constants::SCAN_CANCELED, Constants::SCAN_FINISHED, Constants::SCAN_PAUSED, Constants::SCAN_STARTED, Constants::TE_CHUNKED, Constants::TE_COMPRESS, Constants::TE_DEFLATE, Constants::TE_GZIP, Constants::TE_IDENTITY, Constants::TE_NONE, Constants::VULN_RATING_CRITICAL, Constants::VULN_RATING_HIGH, Constants::VULN_RATING_INFO, Constants::VULN_RATING_LOW, Constants::VULN_RATING_MEDIUM, Constants::VULN_RATING_UNDEFINED
Instance Method Summary
collapse
-
#add_get_parm(parm, value) ⇒ Object
-
#add_post_parm(parm, value) ⇒ Object
-
#addHeader(header, value) ⇒ Object
(also: #add_header)
-
#appendDir(dir) ⇒ Object
-
#appendQueryParms(parms) ⇒ Object
-
#fix_content_length ⇒ Object
-
#fix_session(pattern, value) ⇒ Object
-
#fixupContentLength ⇒ Object
-
#fixupContentLength_UNUSED ⇒ Object
-
#removeBody ⇒ Object
-
#removeHeader(header) ⇒ Object
(also: #remove_header)
R E M O V E _ H E A D E R.
-
#removeHeader_OLD(header) ⇒ Object
-
#removeURI ⇒ Object
-
#removeUrlParms ⇒ Object
removeUrlParms Function: Remove all parameter within the URL.
-
#replace_get_parm(parm, value) ⇒ Object
-
#replace_header(header, value) ⇒ Object
-
#replace_post_parm(parm, value) ⇒ Object
-
#replaceElement(new_element) ⇒ Object
-
#replaceFileExt(new_file) ⇒ Object
-
#replaceMethod(new_method) ⇒ Object
-
#replaceQuery(new_query) ⇒ Object
-
#replaceURL(new_url) ⇒ Object
-
#restoreURI(uri) ⇒ Object
-
#rewrite_body(pattern, content) ⇒ Object
-
#set_body(content) ⇒ Object
-
#set_content_length(length) ⇒ Object
-
#set_content_type(ctype) ⇒ Object
-
#set_file_extension(nxt, *prefs) ⇒ Object
set a new file extension, e.g.
-
#set_header(header, value) ⇒ Object
(also: #setHeader)
-
#setData(data) ⇒ Object
-
#setDir(dir) ⇒ Object
-
#setHTTPVersion(version) ⇒ Object
-
#setMethod(method) ⇒ Object
(also: #set_method, #method=)
-
#setRawQueryParms(parm_string) ⇒ Object
-
#strip_path ⇒ Object
Instance Method Details
#add_get_parm(parm, value) ⇒ Object
121
122
123
124
125
126
127
128
|
# File 'lib/watobo/mixins/shapers.rb', line 121
def add_get_parm(parm, value)
line = self.shift
new_p = "&"
new_p = "?" if not self.element =~ /\?/
new_p += parm
line.gsub!(/( HTTP\/.*)/, "#{new_p}=#{value}\\1")
self.unshift(line)
end
|
#add_post_parm(parm, value) ⇒ Object
113
114
115
116
117
118
119
|
# File 'lib/watobo/mixins/shapers.rb', line 113
def add_post_parm(parm, value)
line = self.last
return false if line !~ /=/
line += "&#{parm}=#{value}"
self.pop
self.push line
end
|
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
# File 'lib/watobo/mixins/shapers.rb', line 130
def (, value)
self_copy = []
self_copy.concat(self.)
self_copy.push "#{}: #{value}\r\n"
unless self.body.nil?
self_copy.push "\r\n"
self_copy.push self.body
end
self.replace(self_copy)
end
|
#appendDir(dir) ⇒ Object
105
106
107
108
109
110
111
|
# File 'lib/watobo/mixins/shapers.rb', line 105
def appendDir(dir)
dir.strip!
dir.gsub!(/^\//, "")
dir << "/" unless dir =~ /\/$/
self.first.gsub!(/(^[^[:space:]]{1,} https?:\/\/[\-0-9a-zA-Z.]*[:0-9]{0,6}.*\/).*( HTTP\/.*)/, "\\1#{dir}\\2")
end
|
#appendQueryParms(parms) ⇒ Object
348
349
350
351
352
353
354
355
356
357
358
359
|
# File 'lib/watobo/mixins/shapers.rb', line 348
def appendQueryParms(parms)
return if parms.nil?
return if parms == ''
puts self.first
puts self.file_ext
pref = (self.file_ext =~ /\?/) ? '&' : '?'
puts "append query parms"
self.first.gsub!(/(.*) (HTTP\/.*)/, "\\1#{pref}#{parms} \\2")
end
|
#fix_content_length ⇒ Object
277
278
279
280
281
282
|
# File 'lib/watobo/mixins/shapers.rb', line 277
def fix_content_length
return false if self.body.nil?
blen = self.body.force_encoding("ASCII-8BIT").length
("Content-Length", blen)
end
|
#fix_session(pattern, value) ⇒ Object
273
274
275
|
# File 'lib/watobo/mixins/shapers.rb', line 273
def fix_session(pattern, value)
end
|
#fixupContentLength ⇒ Object
331
332
333
334
|
# File 'lib/watobo/mixins/shapers.rb', line 331
def fixupContentLength
self.unchunk
self.fix_content_length
end
|
#fixupContentLength_UNUSED ⇒ Object
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
|
# File 'lib/watobo/mixins/shapers.rb', line 284
def fixupContentLength_UNUSED
te = self.transferEncoding
if te == TE_CHUNKED then
self.("Transfer-Encoding")
self.("Content-Length", "0")
new_r = []
new_r.concat self.
new_r.push "\r\n"
bytes_to_read = 0
body = []
is_new_chunk = false
off = 0
new_body = ''
body_orig = self.body
puts body_orig.class
while body_orig[off..-1] =~ /^([0-9a-fA-F]{1,6})\r\n/
len_raw = "#{$1}"
len = len_raw.hex
chunk_start = off + len_raw.length + 2
chunk_end = chunk_start + len
break if len == 0
new_body.chomp!
new_body += "#{body_orig[chunk_start..chunk_end]}"
off = chunk_end + 2
end
new_r.push new_body
self.replace(new_r)
self.fix_content_length
elsif te == TE_NONE then
self.fix_content_length
end
end
|
#removeBody ⇒ Object
160
161
162
|
# File 'lib/watobo/mixins/shapers.rb', line 160
def removeBody
self.pop if self[-2].strip.empty?
end
|
R E M O V E _ H E A D E R
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
# File 'lib/watobo/mixins/shapers.rb', line 201
def ()
begin
while i = .index { |h| h =~ /#{}/i }
self.delete_at i
end
rescue => bang
puts bang
puts bang.backtrace if $DEBUG
puts self
puts "====="
end
end
|
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
# File 'lib/watobo/mixins/shapers.rb', line 240
def ()
begin
self_copy = []
eoh = false
self.each do |line|
puts self if line.nil?
if not eoh == true then
if not line =~ /#{}/i
self_copy.push line unless line.nil?
end
else
self_copy.push line unless line.nil?
end
if line and line.strip.empty? then
eoh = true
end
end
self.replace(self_copy)
rescue => bang
puts bang
puts bang.backtrace if $DEBUG
puts self
puts "====="
end
end
|
#removeURI ⇒ Object
147
148
149
150
151
152
153
154
155
156
157
158
|
# File 'lib/watobo/mixins/shapers.rb', line 147
def removeURI
if self.first =~ /(^[^[:space:]]{1,}) (https?:\/\/[\-0-9a-zA-Z.]*[:0-9]{0,6}\/)/ then
uri = $2
self.first.gsub!(/(^[^[:space:]]{1,}) (#{Regexp.quote(uri)})/, "\\1 /")
return uri
else
return nil
end
end
|
#removeUrlParms ⇒ Object
removeUrlParms Function: Remove all parameter within the URL
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
# File 'lib/watobo/mixins/shapers.rb', line 221
def removeUrlParms
line = self.shift
return false if line.nil?
new_line = "#{line}"
eop_index = line.rindex(/[^ HTTP]\//)
sop_index = line.index(/(\?|&)/, eop_index)
eou_index = line.index(/ HTTP/)
unless sop_index.nil? or eou_index.nil?
new_line = line[0..sop_index-1]
new_line += line[eou_index..-1]
end
self.unshift new_line
end
|
#replace_get_parm(parm, value) ⇒ Object
13
14
15
16
|
# File 'lib/watobo/mixins/shapers.rb', line 13
def replace_get_parm(parm, value)
parm_quoted = Regexp.quote(parm)
self.first.gsub!(/([?&]{1})#{parm_quoted}=([^ &]*)(&{0,1})/i, "\\1#{parm}=#{value}\\3")
end
|
269
270
271
|
# File 'lib/watobo/mixins/shapers.rb', line 269
def (, value)
end
|
#replace_post_parm(parm, value) ⇒ Object
8
9
10
11
|
# File 'lib/watobo/mixins/shapers.rb', line 8
def replace_post_parm(parm, value)
parm_quoted = Regexp.quote(parm)
self.last.gsub!(/([?&]{1}|^)#{parm_quoted}=([^&]*)(&{0,1})/i, "\\1#{parm}=#{value}\\3")
end
|
#replaceElement(new_element) ⇒ Object
32
33
34
35
|
# File 'lib/watobo/mixins/shapers.rb', line 32
def replaceElement(new_element)
new_element.gsub!(/^\//, "")
self.first.gsub!(/([^\?]*\/)(.*) (HTTP.*)/i, "\\1#{new_element} \\3")
end
|
#replaceFileExt(new_file) ⇒ Object
22
23
24
25
26
27
28
29
30
|
# File 'lib/watobo/mixins/shapers.rb', line 22
def replaceFileExt(new_file)
begin
file = new_file.strip
file.gsub!(/^\//, "")
self.first.gsub!(/([^\?]*\/)(.*) (HTTP.*)/i, "\\1#{file} \\3")
rescue => bang
puts bang
end
end
|
#replaceMethod(new_method) ⇒ Object
18
19
20
|
# File 'lib/watobo/mixins/shapers.rb', line 18
def replaceMethod(new_method)
self.first.gsub!(/^[^[:space:]]{1,}/i, "#{new_method}")
end
|
#replaceQuery(new_query) ⇒ Object
41
42
43
44
|
# File 'lib/watobo/mixins/shapers.rb', line 41
def replaceQuery(new_query)
new_query.gsub!(/^\//, "")
self.first.gsub!(/(.*\/)(.*) (HTTP.*)/i, "\\1#{new_query} \\3")
end
|
#replaceURL(new_url) ⇒ Object
37
38
39
|
# File 'lib/watobo/mixins/shapers.rb', line 37
def replaceURL(new_url)
self.first.gsub!(/(^[^[:space:]]{1,}) (.*) (HTTP.*)/i, "\\1 #{new_url} \\3")
end
|
#restoreURI(uri) ⇒ Object
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
# File 'lib/watobo/mixins/shapers.rb', line 182
def restoreURI(uri)
if self.first =~ /(^[^[:space:]]{1,}) \/(.*) (HTTP\/.*)/ then
method = $1
rest = $2
http = $3.strip
self.shift
self.unshift "#{method} #{uri}#{rest} #{http}\r\n"
return self.first
else
return nil
end
end
|
#rewrite_body(pattern, content) ⇒ Object
173
174
175
176
177
178
179
180
|
# File 'lib/watobo/mixins/shapers.rb', line 173
def rewrite_body(pattern, content)
if self.has_body?
b = self.pop
b.gsub!(/#{pattern}/i, content)
self << b
end
end
|
#set_body(content) ⇒ Object
164
165
166
167
168
169
170
171
|
# File 'lib/watobo/mixins/shapers.rb', line 164
def set_body(content)
if self[-2].strip.empty?
self.pop
else
self << "\r\n"
end
self << content
end
|
#set_content_length(length) ⇒ Object
361
362
363
|
# File 'lib/watobo/mixins/shapers.rb', line 361
def set_content_length(length)
("Content-Length", length)
end
|
#set_content_type(ctype) ⇒ Object
365
366
367
|
# File 'lib/watobo/mixins/shapers.rb', line 365
def set_content_type(ctype)
("Content-Type", ctype)
end
|
#set_file_extension(nxt, *prefs) ⇒ Object
set a new file extension, e.g. mysite.html to mysite.php if no extension nor a file is given, the new extension will only be appended note: the first leading dot will be removed possible preferences are:
:keep_query => keeps query parameters
default-set is empty
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/watobo/mixins/shapers.rb', line 65
def set_file_extension(nxt, *prefs)
return self.first if nxt.nil?
nxt.gsub!(/^\./, '')
s = "#{self.first}"
fend = nil
pend = nil
pstart = s.index('?')
pend = s.rindex(/ HTTP\//)
fend = (pstart - 1) unless pstart.nil?
fend = (pend - 1) if fend.nil?
return self.first if fend.nil?
fstart = s.rindex('/', fend)
unless s[fstart-1] == '/'
fstart += 1 unless fstart.nil?
else
fstart = fend
end
fname = s[fstart..fend]
fname.gsub!(/\..*/, '')
fname << ".#{nxt}"
ns = s[0..fstart-1]
ns << fname
if prefs.include? :keep_query
unless pstart.nil?
ns << s[pstart..pend]
end
end
ns << s[pend..-1]
self.first.replace ns
end
|
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
|
# File 'lib/watobo/mixins/shapers.rb', line 369
def (, value)
begin
= "#{}: #{value}\r\n"
self.each_with_index do |h, i|
if h =~ /^#{Regexp.quote()}:/i
self[i] =
return true
end
if h.strip.empty? or i == self.length-1
self.insert(i, )
return true
end
end
rescue => bang
puts bang
end
return false
end
|
#setData(data) ⇒ Object
392
393
394
395
396
397
398
399
400
401
|
# File 'lib/watobo/mixins/shapers.rb', line 392
def setData(data)
return if data.nil?
if self.has_body?
self.pop
self.push data
else
self.push("\r\n")
self.push data
end
end
|
#setDir(dir) ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/watobo/mixins/shapers.rb', line 50
def setDir(dir)
dir.strip!
dir.gsub!(/^\/+/, "")
dir.gsub!(/\/+$/, "")
dir += "/" unless dir == ''
self.first.gsub!(/(^[^[:space:]]{1,} https?:\/\/[\-0-9a-zA-Z.]*[:0-9]{0,6}\/)(.*)( HTTP\/.*)/, "\\1#{dir}\\3")
end
|
#setHTTPVersion(version) ⇒ Object
411
412
413
414
|
# File 'lib/watobo/mixins/shapers.rb', line 411
def setHTTPVersion(version)
self.first.gsub!(/HTTP\/(.*)$/, "HTTP\/#{version}")
end
|
#setMethod(method) ⇒ Object
Also known as:
set_method, method=
403
404
405
406
|
# File 'lib/watobo/mixins/shapers.rb', line 403
def setMethod(method)
m = method.is_a?(Symbol) ? method.to_s.upcase : method
self.first.gsub!(/(^[^[:space:]]{1,}) /, "#{m} ")
end
|
#setRawQueryParms(parm_string) ⇒ Object
336
337
338
339
340
341
342
343
344
345
346
|
# File 'lib/watobo/mixins/shapers.rb', line 336
def setRawQueryParms(parm_string)
return nil if parm_string.nil?
return nil if parm_string == ''
new_r = ""
path = Regexp.quote(self.path)
if self.first =~ /(.*#{path})/ then
new_r = $1 << "?" << parm_string
end
self.first.gsub!(/(.*) (HTTP\/.*)/, "#{new_r} \\2")
end
|
#strip_path ⇒ Object
46
47
48
|
# File 'lib/watobo/mixins/shapers.rb', line 46
def strip_path()
self.first.gsub!(/([^\?]*\/)(.*) (HTTP.*)/i, "\\1# \\3")
end
|