Class: ICAPrb::FilterSolutions::HashedContent

Inherits:
Object
  • Object
show all
Defined in:
lib/icaprb/filter/solution.rb

Overview

Check for hashes and block if anything matches

Constant Summary collapse

FILTER_NAME =

Name in the configuration file

'check_hashes'
MODES =

Available mod modes

[:response_mod]

Instance Method Summary collapse

Constructor Details

#initialize(_, parameters) ⇒ HashedContent

Constructor

mode

resp or req mod

parameters

All parameters given in the configuration file



66
67
68
69
70
71
72
73
# File 'lib/icaprb/filter/solution.rb', line 66

def initialize(_, parameters)
  @params = []
  file_path = parameters[0]
  File.foreach(File.expand_path(file_path)) do |line|
    line = line.chomp.gsub('\n', '').gsub('\r', '')
    @params << line
  end
end

Instance Method Details

#plugin(data) ⇒ Object

Execute plugin

data

ICAP data



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/icaprb/filter/solution.rb', line 76

def plugin(data)
  if data[:http_response_body] == nil
    ICAPrb::Filters.get_logger.debug('Nothing to hash')
    return false
  end
  hash = Digest::SHA256.hexdigest(data[:http_response_body]).to_s
  ICAPrb::Filters.get_logger.debug('Calculated hash: ' + hash.to_s)
  @params.each do |other_hash|
    if hash.eql? other_hash
      # Block by telling the user that this is blocked
      ICAPrb::Filters.get_logger.debug('Found match')
      data[:http_response_body] = '<html><body>Blocked Hash</body></html>'
      return true
    end
  end
  false
end