./redteamer

Core concepts

Language

RedTeamer Language

This page explains the HCL based RedTeamer Language and its syntax.


Overview

The RedTeamer language defines actions using blocks. Each block consists of:

  • A block type
  • Any number of labels, but typically zero or one
  • A body containing arguments and/or nested blocks

Inside a block:

  • Arguments assign values to names
  • Expressions represent these values (literal or computed)
  • Execution order depends on block relationships, not the sequence in the file

Blocks

Blocks follow this structure:

<BLOCK TYPE> "<BLOCK LABEL>" {
  <NAME> = <VALUE>  # Argument
}

Example

action "dir_enumeration" {
  with     = "core/tools/gobuster/dir.rtmod.hcl"
  base_url = "http://192.168.0.155/"
  wordlist = "/usr/share/wordlists/dirb/common.txt"
}

In this example:

  • The block type is action, which defines an action
  • "dir_enumeration" is a block label, uniquely identifying this instance
  • The block contains arguments (with, base_url, wordlist)

Block Labels

Block labels:

  • Identify specific instances of a block
  • Are enclosed in double quotes (")
  • Can include letters, numbers, underscores (_), and hyphens (-)

✅ Valid Block Labels:

action "example_scan" { 
  with     = "core/tools/gobuster/dir.rtmod.hcl"
  base_url = "http://192.168.0.155/"  
  wordlist = "/usr/share/wordlists/dirb/common.txt"
}

action "nmap_scan" {
  with     = "core/tools/nmap/scan.rtmod.hcl"
  target = "127.0.0.1"
  ports  = "80,443"
}

🚫 Invalid Block Labels:

action "example@scan" {  # Invalid: space and special character (@)
  with     = "core/tools/gobuster/dir.rtmod.hcl"
  base_url = "http://192.168.0.155/"
}

action "123target#1" {  # Invalid: starts with a number, special character (#)
  with   = "core/tools/gobuster/dir.rtmod.hcl"
  target = "127.0.0.1"
}

Meta-Arguments

Meta-arguments modify how blocks are created and executed. These include:

  • for_each: Creates a block for each element in a collection
  • count: Creates multiple block instances
  • when: Conditionally executes a block

Warning: Do not use for_each and count together in the same block. Choose one based on your needs.

for_each

Creates a block for each item in a collection. Each block instance can access the individual element using each.value.

action "gobuster_dir" {
  with     = "core/tools/gobuster/dir.rtmod.hcl"
  for_each = toset(["192.168.0.155", "192.168.0.156"])
  base_url = "http://${each.value}/"
  wordlist = "/usr/share/wordlists/dirb/common.txt"
}

Referencing Blocks with for_each

Use the block type and label with each.key or each.value:

output "gobuster_results" {
  value = action.gobuster_dir["192.168.0.155"].results
}

count

Creates multiple instances of a block.

action "gobuster_dir" {
  with     = "core/tools/gobuster/dir.rtmod.hcl"
  count    = 3
  base_url = "http://192.168.0.155/"
  wordlist = "/usr/share/wordlists/dirb/common.txt"
}

Referencing Blocks with count

Use an index to reference instances:

output "gobuster_first_instance_results" {
  value = action.gobuster_dir[0].results
}

when

Executes a block only if the condition is true.

action "gobuster_dir" "example" {
  with     = "core/tools/gobuster/dir.rtmod.hcl"
  when     = var.is_enabled
  base_url = "http://192.168.0.155/"
  wordlist = "/usr/share/wordlists/dirb/common.txt"
}

Arguments

Arguments assign values within a block. Values can be:

  • Literal values (fixed values like "text" or 42)
  • Expressions (computed values)
<IDENTIFIER> = <EXPRESSION>
target       = "127.0.0.1"

Identifiers

Valid Identifiers:

  • Contain letters, numbers, underscores (_), and hyphens (-)
  • Cannot start with a number
base_url     = "http://192.168.0.155/"  # Valid
timeout      = 30  # Valid
max-retries  = 5  # Valid
wordlist_path = "/usr/share/wordlists/dirb/common.txt"  # Valid

Invalid Identifiers:

123url       = "http://192.168.0.155/"  # Invalid: starts with a number
base url     = "http://192.168.0.155/"  # Invalid: space in name
base@url     = "http://192.168.0.155/"  # Invalid: special character (@)
base-url$    = "http://192.168.0.155/"  # Invalid: special character ($)

Expressions

Expressions assign values to arguments.

Literal Expressions:

target  = "127.0.0.1"  # String
timeout = 30           # Number
enabled = true         # Boolean

Computed Expressions:

timeout = 20 + 10                                   # Arithmetic expression
target  = var.hostname                              # Variable reference
url     = "${var.protocol}://${var.host}:${var.port}"  # String interpolation

Comments

Use comments to explain code. RedTeamer supports:

  • # and // for single-line comments
  • /* */ for multi-line comments
// Single-line comment using

# Single-line comment using
action "gobuster_dir" {
  with     = "core/tools/gobuster/dir.rtmod.hcl"
  base_url = "http://192.168.0.155/"  # Inline comment
}

/* 
  Multi-line comment
  Spans multiple lines
*/

Character Encoding

  • UTF-8 is required for module files
  • Non-ASCII characters are allowed in identifiers, comments, and string literals

Line Endings

  • Unix-style (LF) is preferred for consistency
  • Windows-style (CRLF) is also supported
Previous
License