跳转至

Functions Reference

按类别组织的190+个实用函数的完整参考。

File Functions

文件和目录操作。

file_exists(path)

检查文件是否存在。

file_exists("/path/to/file.txt")  // 返回:true 或 false

file_length(path)

统计文件中的非空行数。

file_length("{{Output}}/hosts.txt")  // 返回:42

dir_length(path)

统计目录中的条目数。

dir_length("{{Output}}/screenshots")  // 返回:15

file_contains(path, pattern)

检查文件是否包含指定模式。

file_contains("{{Output}}/urls.txt", "admin")  // 返回:true 或 false

regex_extract(path, pattern)

从文件中提取匹配正则表达式的行。

regex_extract("{{Output}}/urls.txt", ".*api.*")  // 返回:["https://api.example.com", ...]

read_file(path)

读取整个文件内容。

read_file("{{Output}}/config.json")  // 返回:文件内容(字符串)

read_lines(path)

将文件读取为行数组。

read_lines("{{Output}}/subdomains.txt")  // 返回:["sub1.example.com", "sub2.example.com", ...]

remove_file(path)

删除文件。

remove_file("{{Output}}/temp.txt")  // 返回:true 或 false

remove_folder(path)

递归删除文件夹。

remove_folder("{{Output}}/cache")  // 返回:true 或 false

rm_rf(path)

递归删除文件或文件夹(类似 rm -rf)。

rm_rf("{{Output}}/tmp")  // 返回:true 或 false

remove_all_except(folder, keep_file)

删除文件夹下除指定文件外的所有内容。

remove_all_except("{{Output}}", "{{Output}}/keep.txt")  // 返回:true 或 false

create_folder(path)

递归创建文件夹(类似 mkdir -p)。

create_folder("{{Output}}/new-folder")  // 返回:true 或 false

append_file(dest, source)

将源文件内容追加到目标文件。

append_file("{{Output}}/all.txt", "{{Output}}/part.txt")  // 返回:true 或 false

move_file(source, dest)

将文件从源路径移动到目标路径。

move_file("{{Output}}/raw.txt", "{{Output}}/processed.txt")  // 返回:true 或 false

glob(pattern)

列出匹配 glob 模式的文件名。

glob("{{Output}}/*.txt")  // 返回:["file1.txt", "file2.txt", ...]

grep_string_to_file(dest, source, str)

将包含指定字符串的行写入目标文件。

grep_string_to_file("{{Output}}/admin-urls.txt", "{{Output}}/urls.txt", "admin")  // 返回:true 或 false

grep_regex_to_file(dest, source, pattern)

将匹配正则表达式的行写入目标文件。

grep_regex_to_file("{{Output}}/api-urls.txt", "{{Output}}/urls.txt", ".*api.*")  // 返回:true 或 false

grep_string(source, str)

返回包含指定字符串的行。

grep_string("{{Output}}/urls.txt", "admin")  // 返回:"https://example.com/admin\nhttps://example.com/admin/login"

grep_regex(source, pattern)

返回匹配正则表达式的行。

grep_regex("{{Output}}/urls.txt", ".*api.*")  // 返回:匹配行(字符串)

remove_blank_lines(path)

原地删除文件中的空行。

remove_blank_lines("{{Output}}/urls.txt")  // 返回:true 或 false

chunk_file(input, lines_per_chunk, output)

将文件分割成每 N 行的块,写入编号的输出文件。

chunk_file("{{Output}}/urls.txt", 1000, "{{Output}}/chunks/urls")
// 创建:urls-0.txt, urls-1.txt, ...
// 返回:true 或 false

cut_to_file(input_file, delim, field, output_file)

使用分隔符从每行中提取指定字段,并将结果写入文件。

cut_to_file("{{Output}}/data.csv", ",", 2, "{{Output}}/column2.txt")  // 返回:true 或 false

String Functions

字符串操作函数。

trim(str)

去除首尾空白字符。

trim("  hello world  ")  // 返回:"hello world"

split(str, delim)

按分隔符将字符串分割为数组。

split("a,b,c", ",")  // 返回:["a", "b", "c"]

join(arr, delim)

用分隔符连接数组元素。

join(["a", "b", "c"], "-")  // 返回:"a-b-c"

replace(str, old, new)

将所有出现的 old 替换为 new。

replace("hello world", "world", "there")  // 返回:"hello there"

contains(str, substr)

检查字符串是否包含子串。

contains("hello world", "world")  // 返回:true

starts_with(str, prefix)

检查字符串是否以指定前缀开头。

starts_with("hello", "hel")  // 返回:true

ends_with(str, suffix)

检查字符串是否以指定后缀结尾。

ends_with("hello.txt", ".txt")  // 返回:true

to_lower_case(str)

转换为小写。

to_lower_case("HELLO")  // 返回:"hello"

to_upper_case(str)

转换为大写。

to_upper_case("hello")  // 返回:"HELLO"

match(str, pattern)

检查字符串是否匹配正则表达式模式。

match("test123", "[0-9]+")  // 返回:true

regex_match(pattern, str)

检查字符串是否匹配正则表达式(模式在前)。

regex_match("[0-9]+", "test123")  // 返回:true

cut_with_delim(input, delim, field)

按分隔符提取字段(从1开始索引,类似 cut)。

cut_with_delim("a:b:c", ":", 2)  // 返回:"b"

normalize_path(input)

将特殊字符(/ | : 等)替换为下划线。

normalize_path("test/path:file")  // 返回:"test_path_file"

normal_path(input)

规范化为路径友好格式(与 {{TargetSpace}} 相同)。

normal_path("https://example.com/path")  // 返回:"example.com_path"

clean_sub(path, target?)

清理并去重文件中的子域名,可选地按目标域名过滤。

clean_sub("{{Output}}/subdomains.txt", "example.com")  // 返回:true 或 false

trim_left(input, substring)

从字符串左侧/开头修剪子串。

trim_left("https://example.com", "https://")  // 返回:"example.com"

trim_right(input, substring)

从字符串右侧/结尾修剪子串。

trim_right("example.com/", "/")  // 返回:"example.com"

trim_string(input, substring)

从字符串两端修剪子串。

trim_string("---hello---", "---")  // 返回:"hello"

cut_space(input, field)

按空白字符分割字符串并提取字段(从1开始索引)。

cut_space("hello world foo", 2)  // 返回:"world"

get_target_space(input)

清理并截断输入,用作项目空间安全的目标名称(与 {{TargetSpace}} 相同)。

get_target_space("https://example.com/path")  // 返回:"example.com_path"

pick_valid(v1, v2, ..., v10)

从给定参数中返回第一个非空值(最多10个)。

pick_valid("", "", "fallback")  // 返回:"fallback"
pick_valid(target, "default.com")  // 返回:target 若非空,否则 "default.com"

别名: cutcut_with_delim 的别名。bashexec_cmd 的别名。

Type Conversion Functions

数据类型转换函数。

parse_int(str)

将字符串解析为整数。

parse_int("42")  // 返回:42

parse_float(str)

将字符串解析为浮点数。

parse_float("3.14")  // 返回:3.14

to_string(val)

将值转换为字符串。

to_string(123)  // 返回:"123"

to_boolean(val)

将值转换为布尔值。

to_boolean("true")  // 返回:true
to_boolean(1)       // 返回:true

Type Detection Functions

输入类型检测函数。

get_types(input)

检测输入类型:file、folder、cidr、ip、url、domain 或 string。

get_types("192.168.1.0/24")     // 返回:"cidr"
get_types("example.com")        // 返回:"domain"
get_types("https://example.com") // 返回:"url"
get_types("/etc/passwd")        // 返回:"file"

is_file(path)

检查路径是否为现有文件。

is_file("/tmp/data.txt")  // 返回:true 或 false

is_dir(path)

检查路径是否为现有目录。

is_dir("/tmp/output")  // 返回:true 或 false

is_git(path)

检查路径是否在 git 仓库内。

is_git("/path/to/project")  // 返回:true 或 false

is_url(input)

检查输入是否为有效的 URL。

is_url("https://example.com")  // 返回:true
is_url("not-a-url")            // 返回:false

is_compress(path)

检查路径是否为压缩归档文件(.zip、.tar.gz、.tgz 等)。

is_compress("archive.tar.gz")  // 返回:true
is_compress("file.txt")        // 返回:false

detect_language(path)

检测源代码文件夹的主要编程语言(支持26+种语言)。

detect_language("/path/to/project")  // 返回:"javascript"
detect_language("{{Output}}/repo")   // 返回:"python"

Utility Functions

通用工具函数。

len(val)

获取字符串或数组的长度。

len("hello")   // 返回:5
len([1, 2, 3]) // 返回:3

is_empty(val)

检查值是否为空。

is_empty("")      // 返回:true
is_empty("hello") // 返回:false

is_not_empty(val)

检查值是否不为空。

is_not_empty("test")  // 返回:true
is_not_empty("")      // 返回:false

printf(message)

将消息打印到标准输出。

printf("Scan started for " + target)

cat_file(path)

将文件内容打印到标准输出。

cat_file("{{Output}}/results.txt")

exit(code)

以指定代码退出扫描。

exit(0)  // 成功
exit(1)  // 错误

exec_cmd(command)

执行 bash 命令并返回输出。

exec_cmd("whoami")  // 返回:"root"
exec_cmd("date")    // 返回:"Mon Jan 20 10:30:00 UTC 2025"

sleep(seconds)

暂停执行 n 秒。

sleep(5)  // 暂停5秒

command_exists(command)

检查命令是否存在于 PATH 中。

command_exists("nmap")   // 返回:true 或 false
command_exists("nuclei") // 返回:true 或 false

Logging Functions

带级别前缀的日志消息函数。

log_debug(message)

[DEBUG] 前缀记录调试消息。

log_debug("Processing target: " + target)

log_info(message)

[INFO] 前缀记录信息消息。

log_info("Scan completed successfully")

log_warn(message)

[WARN] 前缀记录警告消息。

log_warn("Rate limit approaching")

log_error(message)

[ERROR] 前缀记录错误消息。

log_error("Failed to connect to target")

Color Printing Functions

带颜色输出的打印消息函数。

以绿色打印消息。

print_green("Success!")

以蓝色打印消息。

print_blue("Processing {{Target}}")

以黄色打印消息。

print_yellow("Warning: Rate limit hit")

以红色打印消息。

print_red("Error occurred")

Runtime Variable Functions

运行时设置和获取变量。

set_var(name, value)

设置运行时变量以供后续检索。

set_var("api_url", "https://api.example.com")

get_var(name)

获取运行时变量的值。

get_var("api_url")  // 返回:"https://api.example.com"

HTTP Functions

HTTP 请求和网络操作函数。

http_request(url, method, headers, body)

完全控制地发起 HTTP 请求。

http_request("https://api.example.com/data", "POST",
  {"Authorization": "Bearer token", "Content-Type": "application/json"},
  '{"key":"value"}')
// 返回:{statusCode: 200, body: "...", headers: {...}}

http_get(url)

HTTP GET 请求,返回结构化响应。

http_get("https://api.example.com/data")
// 返回:{statusCode: 200, body: "...", headers: {...}}

http_post(url, body)

HTTP POST 请求,返回结构化响应。

http_post("https://api.example.com/submit", '{"key":"value"}')
// 返回:{statusCode: 200, body: "...", headers: {...}}

get_ip(domain_or_url)

将域名或 URL 解析为 IP 地址。

get_ip("example.com")              // 返回:"93.184.216.34"
get_ip("https://example.com/path") // 返回:"93.184.216.34"(自动解析 URL)

Generation Functions

生成随机值。

random_string(length)

生成随机字母数字字符串。

random_string(16)  // 返回:"aB3xY9kLm2nP7qRs"

uuid()

生成 UUID v4。

uuid()  // 返回:"550e8400-e29b-41d4-a716-446655440000"

Encoding Functions

编码和解码数据。

base64_encode(str)

将字符串编码为 base64。

base64_encode("hello")  // 返回:"aGVsbG8="

base64_decode(str)

解码 base64 字符串。

base64_decode("aGVsbG8=")  // 返回:"hello"

Data Query Functions

查询结构化数据。

jq(jsonData, query)

使用 jq 语法提取数据。

jq('{"name":"test","version":"1.0"}', '.name')  // 返回:"test"
jq('{"items":[1,2,3]}', '.items[]')             // 返回:[1, 2, 3]
jq('{"a":{"b":"c"}}', '.a.b')                   // 返回:"c"

jq_from_file(path, query)

从 JSON 文件中使用 jq 提取数据。

jq_from_file("{{Output}}/data.json", ".results[].url")

Notification Functions

通过多种渠道发送通知。

notify_telegram(message)

向配置的 Telegram 聊天发送消息。

notify_telegram("Scan completed for {{Target}}")  // 返回:true 或 false

send_telegram_file(path, caption?)

向 Telegram 发送文件,可选标题。

send_telegram_file("{{Output}}/report.pdf", "Scan report for {{Target}}")  // 返回:true 或 false

notify_webhook(message)

向所有配置的 webhook 发送消息。

notify_webhook("Scan completed for {{Target}}")  // 返回:true 或 false

send_webhook_event(eventType, data)

向所有 webhook 发送结构化事件。

send_webhook_event("scan_complete", {target: "{{Target}}", status: "success"})  // 返回:true 或 false

notify_telegram_channel(channel, message)

向特定 Telegram 频道发送消息。

notify_telegram_channel("alerts", "Critical finding on {{Target}}")  // 返回:true 或 false

send_telegram_file_channel(channel, path, caption?)

向特定 Telegram 频道发送文件,可选标题。

send_telegram_file_channel("reports", "{{Output}}/report.pdf", "Report for {{Target}}")  // 返回:true 或 false

notify_message_as_file_telegram(path)

将文件内容作为文本文件发送到 Telegram。

notify_message_as_file_telegram("{{Output}}/summary.txt")  // 返回:true 或 false

notify_message_as_file_telegram_channel(channel, path)

将文件内容作为文本文件发送到特定 Telegram 频道。

notify_message_as_file_telegram_channel("reports", "{{Output}}/summary.txt")  // 返回:true 或 false

Event Generation Functions

为事件系统生成结构化事件。

generate_event(workspace, topic, source, data_type, data)

生成结构化事件并发送到服务器/webhook。

// 简单字符串数据
generate_event("{{Workspace}}", "discovery", "subdomain-scan", "domain", "api.example.com")

// 复杂对象数据
generate_event("{{Workspace}}", "vulnerability", "nuclei", "finding", {
  url: "https://example.com/admin",
  severity: "critical",
  template: "CVE-2024-1234"
})
// 返回:true(始终为 true - 如果服务器不可用,事件将排队)

参数:

  • workspace - 项目空间名称(必填,使用 {{Workspace}}
  • topic - 事件类别(例如 "discovery"、"vulnerability")
  • source - 事件来源(例如 "amass"、"nuclei")
  • data_type - 数据类型(例如 "domain"、"url"、"finding")
  • data - T