Class: Aspisec::Module — Documentation by YARD 0.9.36

# Class: Aspisec::Module

Inherits:
  Object
  - Object
  - Aspisec::Module
  show all

Defined in:
  lib-ruby/aspisec/module.rb

## Overview

Generic module class that will be inherited in all modules instances

## Direct Known Subclasses

Aspisec::Modules::Amass, Aspisec::Modules::Bloodhound, Aspisec::Modules::Crackmapexec, Aspisec::Modules::Dbgate, Aspisec::Modules::Ffuf, Aspisec::Modules::Filezilla, Aspisec::Modules::Hashcat, Aspisec::Modules::HomeHistoryFiles, Aspisec::Modules::John, Aspisec::Modules::JwtTool, Aspisec::Modules::Lsassy, Aspisec::Modules::Manspider, Aspisec::Modules::Metasploit, Aspisec::Modules::Mobsf, Aspisec::Modules::MongodbCompass, Aspisec::Modules::MongodbMongosh, Aspisec::Modules::Ncrack, Aspisec::Modules::Netexec, Aspisec::Modules::Recaf, Aspisec::Modules::Remmina, Aspisec::Modules::Semgrep, Aspisec::Modules::Spiderfoot, Aspisec::Modules::Sqlmap, Aspisec::Modules::Theharvester, Aspisec::Modules::Weevely, Aspisec::Modules::Whatwaf

## Defined Under Namespace

Classes: Location

## Instance Attribute Summary collapse

- #base ⇒ Pathname readonly

  The base location (directory) where the tool data is stored.

- #conf ⇒ Hash readonly

  The configuration for the tool.

- #locations_list ⇒ Array<String> readonly

  List of locations (name).

- #name ⇒ String readonly

  The name of the tool.

## Instance Method Summary collapse

- #check_config ⇒ Object

  Raise an issue if the module configuration is missing.

- #enabled? ⇒ true|false

  Is this module enabled?.

- #initialize(conf, tool_name, logger: nil) ⇒ Module constructor

  Not meant to be used directly but to be inherited in modules instead.

- #locations ⇒ Array<Location>

  Returns all locations available for the tool.

## Constructor Details

### #initialize(conf, tool_name, logger: nil) ⇒ `Module`

Not meant to be used directly but to be inherited in modules instead

Examples:

    conf = Aspisec::Config.new.conf
    # you should never do that as you'll get incomplete data and features
    sqlmap = Aspisec::Module.new(conf, 'sqlmap')
    # rather call the sqlmap module that will inherit this class
    sqlmap = Aspisec::Modules::Sqlmap.new(conf)

Parameters:

- conf (`Aspisec::Config`) —

  an instance of the global configuration

- tool_name (`String`) —

  The name of the tool. It must match the configuration key.

- logger (`TTY::Logger`) (defaults to: `nil`) —

  logger instance. See Logger.
  If none is provided, a default logger with log level 2 is created.
  See Logger::LOG_LEVEL.

    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    # File 'lib-ruby/aspisec/module.rb', line 43

    def initialize(conf, tool_name, logger: nil)
      @logger = logger || Aspisec::Logger.new.logger
      @name = tool_name
      @logger.debug("Module #{@name} was loaded", app: @name)
      @conf = conf['tools'][tool_name]
      check_config
      @base = Pathname.new(@conf.dig('location', 'base'))
      @enabled = @conf.fetch('enabled', true)
      @locations_list = []
    end

## Instance Attribute Details

### #base ⇒ `Pathname` (readonly)

The base location (directory) where the tool data is stored.

Returns:

- (`Pathname`) —

  file path

    29
    30
    31
    # File 'lib-ruby/aspisec/module.rb', line 29

    def base
      @base
    end

### #conf ⇒ `Hash` (readonly)

The configuration for the tool.
Sub-tree under `tools > tool_name` of Config#conf.

Returns:

- (`Hash`)

    14
    15
    16
    # File 'lib-ruby/aspisec/module.rb', line 14

    def conf
      @conf
    end

### #locations_list ⇒ `Array<String>` (readonly)

List of locations (name).
Returns something only on module instances like Aspisec::Modules::Sqlmap.
Will be empty for Aspisec::Module.
For a list of objects, rather use #locations.

Returns:

- (`Array<String>`)

    25
    26
    27
    # File 'lib-ruby/aspisec/module.rb', line 25

    def locations_list
      @locations_list
    end

### #name ⇒ `String` (readonly)

The name of the tool.

Returns:

- (`String`) —

  tool name

    18
    19
    20
    # File 'lib-ruby/aspisec/module.rb', line 18

    def name
      @name
    end

## Instance Method Details

### #check_config ⇒ `Object`

Raise an issue if the module configuration is missing

    55
    56
    57
    58
    59
    60
    61
    62
    # File 'lib-ruby/aspisec/module.rb', line 55

    def check_config
      return unless @conf.nil?

      message = "Configuration for module #{@name} is missing. " \
                'You may use an old version of the configuration file.'
      @logger.error(message, app: @name)
      raise 'Missing configuration for the current module.'
    end

### #enabled? ⇒ `true|false`

Is this module enabled?

Returns:

- (`true|false`)

    66
    67
    68
    # File 'lib-ruby/aspisec/module.rb', line 66

    def enabled?
      @enabled
    end

### #locations ⇒ `Array<Location>`

Returns all locations available for the tool.
It returns a list Location objects unline #locations_list that returns
only strings (location names).

Returns:

- (`Array<Location>`)

    74
    75
    76
    77
    78
    79
    80
    # File 'lib-ruby/aspisec/module.rb', line 74

    def locations
      # Re-compute what's already cumputed and stored in properties
      # @locations_list.map { |loc| Location.new(@conf, loc) }
      # Access properties rather than re-computing
      # Using send() is safe here because the input is a hadrcaoded whitelist
      @locations_list.map { |loc| send(loc) }
    end