loop

Execute a set of commands in a loop, based on a condition or iteration over a list of values.

The loop command allows dynamic iteration over lists or ranges of values, executing a sequence of commands for each iteration. It provides flexibility when working with variable data such as network scans, enabling the execution of different commands depending on the results, without prior knowledge of the number of iterations.

Note

The loop command works with two primary loop conditions: iterating over a list of values (items) or iterating over a numerical range (range).

vars:
  LISTA:
    - one
    - two

commands:
  - type: loop
    cmd: "items(LISTA)"
    commands:
      - type: shell
        cmd: echo hello
      - type: debug
        cmd: $LOOP_ITEM

  - type: loop
    cmd: "range(0, 3)"
    commands:
      - type: shell
        cmd: echo "Index $LOOP_INDEX"
      - type: debug
        cmd: $LOOP_INDEX

Loop with items: This mode iterates over the elements of a list and substitutes each element into the commands. The current item is accessible as the $LOOP_ITEM variable.

Loop with range: This mode iterates over a range of integers. The current index is accessible as the $LOOP_INDEX variable.

cmd

The loop condition. This defines how the loop should iterate, either over a list or a range of values.

Type:

str

Examples:

  • items(LISTA): Iterate over the elements of a list named LISTA.

  • range(0, 10): Iterate over a range from 0 to 9.

commands

The list of commands to execute during each iteration of the loop. These commands are executed once per iteration, with loop-specific variables ($LOOP_ITEM or $LOOP_INDEX) available for substitution.

Type:

list[Command]

vars:
  LISTA:
    - port1
    - port2

commands:
  - type: loop
    cmd: "items(LISTA)"
    commands:
      - type: shell
        cmd: "nmap -p $LOOP_ITEM 10.10.10.10"
      - type: debug
        cmd: $LOOP_ITEM

In the above example, each element of LISTA (port1, port2) is substituted into the loop, and an Nmap scan is run for each port.

Example of looping over a range:

vars:
  INDEX_START: 0
  INDEX_END: 5

commands:
  - type: loop
    cmd: "range($INDEX_START, $INDEX_END)"
    commands:
      - type: shell
        cmd: echo "Index is $LOOP_INDEX"
LOOP_ITEM

In items loops, this variable holds the current item from the list being iterated over.

Type:

str

LOOP_INDEX

In range loops, this variable holds the current index of the iteration.

Type:

int