-
Notifications
You must be signed in to change notification settings - Fork 243
Modules
@trimstray edited this page Apr 26, 2018
·
7 revisions
You can file an issue about it and ask that it be added.
Together with sandmap, many modules are provided that support various scanning techniques, including NSE scripts. If you want, you can create your own module by using 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=""
version=""
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" "
Module: ${module_name}
Description
-----------
Zenmap 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> 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}" \
"${version}" \
"${#_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.