Skip to content

Modules

@trimstray edited this page May 19, 2018 · 7 revisions

Welcome to the Sandmap wiki!

You can file an issue about it and ask that it be added.


Internal modules

Sandmap supports the NSE scripts provided with Nmap. This is transparent for the user. Together with sandmap, many modules are provided that support various scanning techniques, including NSE scripts.

External modules

You can also provide external NSE modules that are in the data/nse_external directory. From version v1.1.1 there are 4 NSE scripts available:

git submodule
 34579f2b0f6110a934c1fc9527e21551a5016528 data/nse_external/michenriksen (heads/master)
 441c7a6d6c004356fd20314552d94b1f21ae62f1 data/nse_external/s4n7h0 (heads/master)
 391d88e547af1ee223bf4e5a865dfe012c7f859f data/nse_external/vulners (v1.2-release)
 a7938fb82952dc1bdda7757fdc0fc06c314d6543 data/nse_external/vulscan (heads/master)

In order to download them when cloning the repository, add the --recursive parameter to git command.

Build own modules

If you want to create your own module use the following scheme:

#!/usr/bin/env bash

# shellcheck shell=bash

# ``````````````````````````````````````````````````````````````````````````````
# Function name: sample()
#
# Description:
#   Sample module template.
#
# Usage:
#   sample
#
# Examples:
#   sample
#

function sample() {

  # shellcheck disable=SC2034
  local _FUNCTION_ID="sample"
  local _STATE=0

  # User variables:
  # - module_name: store module name
  # - module_args: store module arguments

  export _module_show=
  export _module_help=
  export _module_opts=
  export _module_commands=

  # shellcheck disable=SC2034
  _module_variables=()

  # shellcheck disable=SC2034
  author=""
  contact=""
  description="Sample module template"

  # shellcheck disable=SC2034,SC2154
  _module_cfg="${_modules}/${module_name}.cfg"

  touch "$_module_cfg"

  # shellcheck disable=SC2034,SC2154
  _module_help=$(printf "%s: \\e[1;32m%s\\e[m" "
  Module" "${module_name}")

  _module_help+=$(printf "%s" "

    Description
    -----------

      Sample predefined commands.

    Commands
    --------

      help    <module>                display module or NSE help
      show    <key>                   display module or profile info
      config  <key>                   show module configuration
      set     <key>                   set module variable value
      use     <module>                reuse module (changed env)
      pushd   <key>|init|show|flush   command line commands stack
      search  <key>                   search key in all commands
      init    <alias|id> [--args]     run profile

      Options:

        <key>                         key value
        <value>                       profile alias or id

")

  # shellcheck disable=SC2154
  if [[ "$_mstate" -eq 0 ]] ; then

    if [[ -e "$_module_cfg" ]] && [[ -s "$_module_cfg" ]] ; then

      # shellcheck disable=SC1090
      source "$_module_cfg"

    else

      # shellcheck disable=SC2034
      _module_variables=()

      if [[ "${#_module_variables[@]}" -ne 0 ]] ; then

        printf "_module_variables=(\"%s\")\\n" "${_module_variables[@]}" > "$_module_cfg"

      fi

      _mstate=1

    fi

  else

    # shellcheck disable=SC1090
    source "$_module_cfg"

  fi

  # In the given commands you can use variables from the CLI config
  # command or the etc/main.cfg file.

  # shellcheck disable=SC2034
  _module_commands=(\
  #
  # "Intense scan;\
  # ;intense;-T4 -A -v" \
  #
  "Short module description;\
  ;sample_scan;<params>" \
  )

  # shellcheck disable=SC2034,SC2154
  _module_show=(\
      "${module_name}" \
      "${#_module_commands[@]}" \
      "${author}" \
      "${contact}" \
      "${description}" \
      )

  # shellcheck disable=SC2034
  export _module_opts=(\
  "$_module_help")

  return $_STATE

}

The module schema file is enclosed in the template/ directory of the project.

Clone this wiki locally