Skip to main content
List and execute utility functions inline

Synopsis

osmedeus function <command> [flags]
Aliases: func

Commands

CommandDescription
eval <script>Evaluate a function or script
listList all available functions

function eval

Evaluate a function or script.
osmedeus function eval [flags]
Aliases: e

Flags

FlagDescription
-e, --eval <script>Script to evaluate
-t, --target <target>Target for {{target}} variable
--params <key=value>Additional parameters (repeatable)
--stdinRead script from stdin

Examples

# Evaluate a simple function
osmedeus func e 'fileExists("/etc/passwd")'

# With target variable
osmedeus func e 'log_info("Scanning {{target}}")' -t example.com

# Multiple functions
osmedeus func e 'log_info("Start"); fileLength("/etc/passwd"); log_info("Done")'

# Using --eval flag
osmedeus func eval -e 'trim("  hello  ")'

# With custom parameters
osmedeus func e 'log_info("{{message}}")' --params 'message=Hello World'

# Read from stdin
echo 'log_info("hello")' | osmedeus func e -
echo 'fileExists("/tmp/test")' | osmedeus func e --stdin

Output

$ osmedeus func e 'fileExists("/etc/passwd")'
true

$ osmedeus func e 'fileLength("/etc/passwd")'
45

$ osmedeus func e 'trim("  hello  ")'
hello

$ osmedeus func e 'log_info("Testing {{target}}")' -t example.com
[INFO] Testing example.com

function list

List all available functions.
osmedeus function list [flags]
Aliases: ls

Output

Available Functions:

File Functions:
  fileExists(path)              Check if file exists
  fileLength(path)              Count non-empty lines in file
  dirLength(path)               Count directory entries
  readFile(path)                Read file contents
  readLines(path)               Read file as array of lines
  writeFile(path, content)      Write content to file
  appendFile(path, content)     Append content to file
  fileContains(path, pattern)   Check if file contains pattern
  regexExtract(path, regex)     Extract lines matching regex

String Functions:
  trim(str)                     Remove leading/trailing whitespace
  split(str, sep)               Split string into array
  join(array, sep)              Join array into string
  replace(str, old, new)        Replace all occurrences
  contains(str, substr)         Check if string contains substring
  startsWith(str, prefix)       Check if string starts with prefix
  endsWith(str, suffix)         Check if string ends with suffix
  toLowerCase(str)              Convert to lowercase
  toUpperCase(str)              Convert to uppercase
  match(str, regex)             Test if string matches regex
  length(str)                   Get string/array length
  isEmpty(str)                  Check if string is empty

Output Functions:
  log_info(message)             Log informational message
  log_warning(message)          Log warning message
  log_error(message)            Log error message
  printf(message)               Print to stdout
  cat_file(path)                Print file contents

Control Functions:
  exit(code)                    Exit with code (0=success)

JSON Functions:
  jq(json, query)               Query JSON with jq syntax

HTTP Functions:
  http_get(url)                 Make GET request
  http_post(url, body)          Make POST request
  http_request(method, url, headers, body)  Custom HTTP request

Database Functions:
  db_select_assets(workspace, format)
  db_select_assets_filtered(workspace, where, format)
  db_select_vulnerabilities(workspace, format)
  db_select_vulnerabilities_filtered(workspace, where, format)
  db_select(table, where, format)
  db_select_one(table, where)
  db_delete(table, where)

Markdown Functions:
  render_markdown_report(template, data)
  convert_jsonl_to_markdown(path)
  convert_csv_to_markdown(path)

Common Use Cases

Test File Operations

# Check if file exists
osmedeus func e 'fileExists("{{Output}}/hosts.txt")' -t example.com

# Count lines
osmedeus func e 'fileLength("/path/to/file.txt")'

# Read file
osmedeus func e 'readFile("/etc/hostname")'

Test String Operations

# Trim whitespace
osmedeus func e 'trim("  hello  ")'

# Split and join
osmedeus func e 'split("a,b,c", ",")'
osmedeus func e 'join(["a","b","c"], "-")'

# Replace
osmedeus func e 'replace("hello.world", ".", "_")'

Test JSON Queries

# Query JSON
osmedeus func e 'jq("{\"name\":\"test\"}", ".name")'

# Complex query
osmedeus func e 'jq("{\"items\":[1,2,3]}", ".items | length")'

Test Conditions

# Test conditions used in workflows
osmedeus func e 'fileExists("/etc/passwd") && fileLength("/etc/passwd") > 0'

Debug Workflows

# Test variable resolution
osmedeus func e 'log_info("Target: {{target}}, Output: {{Output}}")' -t example.com

# Test with custom params
osmedeus func e 'log_info("Threads: {{threads}}")' --params 'threads=50'

API Equivalent

Evaluate via REST API:
curl -X POST http://localhost:8002/osm/api/functions/eval \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"script": "fileLength(\"/path/to/file\")"}'
List via API:
curl http://localhost:8002/osm/api/functions/list \
  -H "Authorization: Bearer $TOKEN"

Notes

  • Functions use Otto JavaScript VM
  • Variable templates ({{var}}) are resolved before evaluation
  • Use 'single quotes' to prevent shell expansion
  • - or --stdin reads from stdin

See Also