Module: Watobo::Mixin::Shaper::Web10

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



94
95
96
97
98
99
100
101
# File 'lib/watobo/mixins/shapers.rb', line 94

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



86
87
88
89
90
91
92
# File 'lib/watobo/mixins/shapers.rb', line 86

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



103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/watobo/mixins/shapers.rb', line 103

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



78
79
80
81
82
83
84
# File 'lib/watobo/mixins/shapers.rb', line 78

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



334
335
336
337
338
339
340
341
342
343
344
345
# File 'lib/watobo/mixins/shapers.rb', line 334

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



260
261
262
263
264
265
266
267
268
# File 'lib/watobo/mixins/shapers.rb', line 260

def fix_content_length
  return false if self.body.nil?
  set_header("Content-Length" , body.length.to_s )
#          eoh_index = self.length - 2
#          self.map!{ |x|
#            x.gsub!(/^(Content-Length: )(\d+)/, "\\1#{self.body.length.to_s}") if self.index(x) <= eoh_index
#            x
#          }
end

#fix_session(pattern, value) ⇒ Object



256
257
258
# File 'lib/watobo/mixins/shapers.rb', line 256

def fix_session(pattern,value)

end

#fixupContentLengthObject



317
318
319
320
# File 'lib/watobo/mixins/shapers.rb', line 317

def fixupContentLength
  self.unchunk
  self.fix_content_length
end

#fixupContentLength_UNUSEDObject



270
271
272
273
274
275
276
277
278
279
280
281
282
283
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
# File 'lib/watobo/mixins/shapers.rb', line 270

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



133
134
135
# File 'lib/watobo/mixins/shapers.rb', line 133

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



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/watobo/mixins/shapers.rb', line 183

def removeHeader(header)
  begin
    matches = []
    headers.each_with_index do |h,i|
      next if i == 0
      matches << i if h =~ /#{header}/i
    end
    matches.map{ |m| self.delete_at(m) }
  
  rescue => bang
    puts bang
    puts bang.backtrace if $DEBUG
    puts self
    puts "====="
  end
end

#removeHeader_OLD(header) ⇒ Object



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/watobo/mixins/shapers.rb', line 223

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



120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/watobo/mixins/shapers.rb', line 120

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



205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/watobo/mixins/shapers.rb', line 205

def removeUrlParms
  line = self.shift
  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?
  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



33
34
35
36
# File 'lib/watobo/mixins/shapers.rb', line 33

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



252
253
254
# File 'lib/watobo/mixins/shapers.rb', line 252

def replace_header(header, value)

end

#replace_post_parm(parm, value) ⇒ Object



28
29
30
31
# File 'lib/watobo/mixins/shapers.rb', line 28

def replace_post_parm(parm,value)
  parm_quoted = Regexp.quote(parm)
  self.last.gsub!(/([?&]{0,1})#{parm_quoted}=([^&]*)(&{0,1})/i, "\\1#{parm}=#{value}\\3")
end

#replaceElement(new_element) ⇒ Object



52
53
54
55
# File 'lib/watobo/mixins/shapers.rb', line 52

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

#replaceFileExt(new_file) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/watobo/mixins/shapers.rb', line 42

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



38
39
40
# File 'lib/watobo/mixins/shapers.rb', line 38

def replaceMethod(new_method)
  self.first.gsub!(/^[^[:space:]]{1,}/i, "#{new_method}")
end

#replaceQuery(new_query) ⇒ Object



61
62
63
64
# File 'lib/watobo/mixins/shapers.rb', line 61

def replaceQuery(new_query)
  new_query.gsub!(/^\//, "")
  self.first.gsub!(/(.*\/)(.*) (HTTP.*)/i,"\\1#{new_query} \\3")
end

#replaceURL(new_url) ⇒ Object



57
58
59
# File 'lib/watobo/mixins/shapers.rb', line 57

def replaceURL(new_url)
  self.first.gsub!(/(^[^[:space:]]{1,})(.*) (HTTP.*)/i,"\\1 #{new_url} \\3")
end

#restoreURI(uri) ⇒ Object



164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/watobo/mixins/shapers.rb', line 164

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



155
156
157
158
159
160
161
162
# File 'lib/watobo/mixins/shapers.rb', line 155

def rewrite_body(pattern, content)
  if self[-2].strip.empty?
    puts "rewrite_body ... #{pattern} - #{content}"
    b = self.pop
    b.gsub!(/#{pattern}/i, content)
  self << b
  end
end

#set_body(content) ⇒ Object



146
147
148
149
150
151
152
153
# File 'lib/watobo/mixins/shapers.rb', line 146

def set_body(content)
  if self[-2].strip.empty?
  self.pop
  else
    self << "\r\n"
  end
  self << content
end

#set_content_length(length) ⇒ Object



348
349
350
# File 'lib/watobo/mixins/shapers.rb', line 348

def set_content_length(length)
  set_header("Content-Length", length)     
end

#set_content_type(ctype) ⇒ Object



352
353
354
# File 'lib/watobo/mixins/shapers.rb', line 352

def set_content_type(ctype)
  set_header("Content-Type", ctype)
end

#set_header(header, value) ⇒ Object



356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
# File 'lib/watobo/mixins/shapers.rb', line 356

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
        h.replace(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

#set_header_UNUSED(header, value) ⇒ Object



137
138
139
140
141
142
143
144
# File 'lib/watobo/mixins/shapers.rb', line 137

def set_header_UNUSED(header, value)
  self.each do |h|
    break if h.strip.empty?
    if h =~ /^#{header}:/
      h.replace "#{header}: #{value}\r\n"             
    end
  end
end

#setData(data) ⇒ Object

sets post data



377
378
379
380
381
382
383
384
385
386
# File 'lib/watobo/mixins/shapers.rb', line 377

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



70
71
72
73
74
75
76
# File 'lib/watobo/mixins/shapers.rb', line 70

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



394
395
396
397
# File 'lib/watobo/mixins/shapers.rb', line 394

def setHTTPVersion(version)
  self.first.gsub!(/HTTP\/(.*)$/, "HTTP\/#{version}")
#  puts "HTTPVersion fixed: #{self.first}"
end

#setMethod(method) ⇒ Object Also known as: set_method, method=



388
389
390
# File 'lib/watobo/mixins/shapers.rb', line 388

def setMethod(method)
  self.first.gsub!(/(^[^[:space:]]{1,}) /, "#{method} ")
end

#setRawQueryParms(parm_string) ⇒ Object



322
323
324
325
326
327
328
329
330
331
332
# File 'lib/watobo/mixins/shapers.rb', line 322

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



66
67
68
# File 'lib/watobo/mixins/shapers.rb', line 66

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