Class: Aikido::Zen::Scanners::PathTraversalScanner
- Inherits:
-
Object
- Object
- Aikido::Zen::Scanners::PathTraversalScanner
- Defined in:
- lib/aikido/zen/scanners/path_traversal_scanner.rb
Class Method Summary collapse
-
.call(filepath:, sink:, context:, operation:) ⇒ Aikido::Zen::Attacks::PathTraversalAttack?
Checks if the user introduced input is trying to access other path using Path Traversal kind of attacks.
- .skips_on_nil_context? ⇒ Boolean
Instance Method Summary collapse
- #attack? ⇒ Boolean
-
#initialize(filepath, input) ⇒ PathTraversalScanner
constructor
A new instance of PathTraversalScanner.
Constructor Details
#initialize(filepath, input) ⇒ PathTraversalScanner
Returns a new instance of PathTraversalScanner.
39 40 41 42 |
# File 'lib/aikido/zen/scanners/path_traversal_scanner.rb', line 39 def initialize(filepath, input) @filepath = filepath.downcase @input = input.downcase end |
Class Method Details
.call(filepath:, sink:, context:, operation:) ⇒ Aikido::Zen::Attacks::PathTraversalAttack?
Checks if the user introduced input is trying to access other path using Path Traversal kind of attacks.
user input is detected to be attempting a Path Traversal Attack, or nil if not.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/aikido/zen/scanners/path_traversal_scanner.rb', line 22 def self.call(filepath:, sink:, context:, operation:) context.payloads.each do |payload| next unless new(filepath, payload.value.to_s).attack? return Attacks::PathTraversalAttack.new( sink: sink, input: payload, filepath: filepath, context: context, operation: "#{sink.operation}.#{operation}", stack: Aikido::Zen.clean_stack_trace ) end nil end |
.skips_on_nil_context? ⇒ Boolean
8 9 10 |
# File 'lib/aikido/zen/scanners/path_traversal_scanner.rb', line 8 def self.skips_on_nil_context? true end |
Instance Method Details
#attack? ⇒ Boolean
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/aikido/zen/scanners/path_traversal_scanner.rb', line 44 def attack? # Single character are ignored because they don't pose a big threat return false if @input.length <= 1 # We ignore cases where the user input is longer than the file path. # Because the user input can't be part of the file path. return false if @input.length > @filepath.length # We ignore cases where the user input is not part of the file path. return false unless @filepath.include?(@input) if PathTraversal::Helpers.include_unsafe_path_parts?(@filepath) && PathTraversal::Helpers.include_unsafe_path_parts?(@input) return true end # Check for absolute path traversal PathTraversal::Helpers.start_with_unsafe_path?(@filepath, @input) end |