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

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

#addHeader(header, value) ⇒ Object Also known as: add_header



130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/watobo/mixins/shapers.rb', line 130

def addHeader(header, value)
  self_copy = []
  self_copy.concat(self.headers)
  self_copy.push "#{header}: #{value}\r\n"

  unless self.body.nil?
    self_copy.push "\r\n"
    #self_copy.concat(self.body)
    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_lengthObject



277
278
279
280
281
282
# File 'lib/watobo/mixins/shapers.rb', line 277

def fix_content_length
  return false if self.body.nil?
  # had trouble with length calculation of binary data in multipart request          
  blen = self.body.force_encoding("ASCII-8BIT").length
  set_header("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

#fixupContentLengthObject



331
332
333
334
# File 'lib/watobo/mixins/shapers.rb', line 331

def fixupContentLength
  self.unchunk
  self.fix_content_length
end

#fixupContentLength_UNUSEDObject



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
    # puts "Transfer-Encoding = TE_CHUNKED"
    # puts self.body
    self.removeHeader("Transfer-Encoding")
    self.addHeader("Content-Length", "0")
    new_r = []
    new_r.concat self.headers
    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
    # puts "= FIXED ="
    # puts self.headers
  elsif te == TE_NONE then
    self.fix_content_length
  end

end

#removeBodyObject



160
161
162
# File 'lib/watobo/mixins/shapers.rb', line 160

def removeBody
  self.pop if self[-2].strip.empty?
end

#removeHeader(header) ⇒ Object Also known as: remove_header

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 removeHeader(header)
  begin

    while i = headers.index { |h| h =~ /#{header}/i }
      self.delete_at i
    end

  rescue => bang
    puts bang
    puts bang.backtrace if $DEBUG
    puts self
    puts "====="
  end
end

#removeHeader_OLD(header) ⇒ Object



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 removeHeader_OLD(header)
  #  p "REMOVE HEADER: #{header}"
  begin
    self_copy = []
    eoh = false
    self.each do |line|
      puts self if line.nil?
      if not eoh == true then
        if not line =~ /#{header}/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

#removeURIObject



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 /")
    # puts "* Removed URI: #{uri}"
    # puts self.first
    return uri
  else
    return nil
  end
  #self.first.gsub!(/^(.*)(https?:\/\/[\-0-9a-zA-Z.]*[:0-9]{0,6}\/)/,"\\1/")
end

#removeUrlParmsObject

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}"
  # get end-of-path-index
  eop_index = line.rindex(/[^ HTTP]\//)
  # get start of parms
  sop_index = line.index(/(\?|&)/, eop_index)
  # find end-of-url
  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

#replace_header(header, value) ⇒ Object



269
270
271
# File 'lib/watobo/mixins/shapers.rb', line 269

def replace_header(header, 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.first.gsub!(/^\w*/, "#{method} #{uri}#{rest}")
    self.shift
    self.unshift "#{method} #{uri}#{rest} #{http}\r\n"
    return self.first
  else
    return nil
  end
  #self.first.gsub!(/^(.*)(https?:\/\/[\-0-9a-zA-Z.]*[:0-9]{0,6}\/)/,"\\1/")
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?
    #puts "rewrite_body ... #{pattern} - #{content}"
    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)
  set_header("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)
  set_header("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

#set_header(header, value) ⇒ Object Also known as: setHeader



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 set_header(header, value)
  begin
    new_header = "#{header}: #{value}\r\n"
    self.each_with_index do |h, i|
      if h =~ /^#{Regexp.quote(header)}:/i
        self[i] = new_header
        return true
      end

      if h.strip.empty? or i == self.length-1
        self.insert(i, new_header)
        return true
      end
    end
  rescue => bang
    puts bang
  end
  return false
end

#setData(data) ⇒ Object

sets post data



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}")
  #  puts "HTTPVersion fixed: #{self.first}"
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)
  #puts path
  if self.first =~ /(.*#{path})/ then
    new_r = $1 << "?" << parm_string
  end
  self.first.gsub!(/(.*) (HTTP\/.*)/, "#{new_r} \\2")
end

#strip_pathObject



46
47
48
# File 'lib/watobo/mixins/shapers.rb', line 46

def strip_path()
  self.first.gsub!(/([^\?]*\/)(.*) (HTTP.*)/i, "\\1# \\3")
end