Functions Reference¶
按类别组织的190+个实用函数的完整参考。
File Functions¶
文件和目录操作。
file_exists(path)¶
检查文件是否存在。
file_length(path)¶
统计文件中的非空行数。
dir_length(path)¶
统计目录中的条目数。
file_contains(path, pattern)¶
检查文件是否包含指定模式。
regex_extract(path, pattern)¶
从文件中提取匹配正则表达式的行。
read_file(path)¶
读取整个文件内容。
read_lines(path)¶
将文件读取为行数组。
remove_file(path)¶
删除文件。
remove_folder(path)¶
递归删除文件夹。
rm_rf(path)¶
递归删除文件或文件夹(类似 rm -rf)。
remove_all_except(folder, keep_file)¶
删除文件夹下除指定文件外的所有内容。
create_folder(path)¶
递归创建文件夹(类似 mkdir -p)。
append_file(dest, source)¶
将源文件内容追加到目标文件。
move_file(source, dest)¶
将文件从源路径移动到目标路径。
glob(pattern)¶
列出匹配 glob 模式的文件名。
grep_string_to_file(dest, source, str)¶
将包含指定字符串的行写入目标文件。
grep_regex_to_file(dest, source, pattern)¶
将匹配正则表达式的行写入目标文件。
grep_string(source, str)¶
返回包含指定字符串的行。
grep_string("{{Output}}/urls.txt", "admin") // 返回:"https://example.com/admin\nhttps://example.com/admin/login"
grep_regex(source, pattern)¶
返回匹配正则表达式的行。
remove_blank_lines(path)¶
原地删除文件中的空行。
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)¶
使用分隔符从每行中提取指定字段,并将结果写入文件。
String Functions¶
字符串操作函数。
trim(str)¶
去除首尾空白字符。
split(str, delim)¶
按分隔符将字符串分割为数组。
join(arr, delim)¶
用分隔符连接数组元素。
replace(str, old, new)¶
将所有出现的 old 替换为 new。
contains(str, substr)¶
检查字符串是否包含子串。
starts_with(str, prefix)¶
检查字符串是否以指定前缀开头。
ends_with(str, suffix)¶
检查字符串是否以指定后缀结尾。
to_lower_case(str)¶
转换为小写。
to_upper_case(str)¶
转换为大写。
match(str, pattern)¶
检查字符串是否匹配正则表达式模式。
regex_match(pattern, str)¶
检查字符串是否匹配正则表达式(模式在前)。
cut_with_delim(input, delim, field)¶
按分隔符提取字段(从1开始索引,类似 cut)。
normalize_path(input)¶
将特殊字符(/ | : 等)替换为下划线。
normal_path(input)¶
规范化为路径友好格式(与 {{TargetSpace}} 相同)。
clean_sub(path, target?)¶
清理并去重文件中的子域名,可选地按目标域名过滤。
trim_left(input, substring)¶
从字符串左侧/开头修剪子串。
trim_right(input, substring)¶
从字符串右侧/结尾修剪子串。
trim_string(input, substring)¶
从字符串两端修剪子串。
cut_space(input, field)¶
按空白字符分割字符串并提取字段(从1开始索引)。
get_target_space(input)¶
清理并截断输入,用作项目空间安全的目标名称(与 {{TargetSpace}} 相同)。
pick_valid(v1, v2, ..., v10)¶
从给定参数中返回第一个非空值(最多10个)。
pick_valid("", "", "fallback") // 返回:"fallback"
pick_valid(target, "default.com") // 返回:target 若非空,否则 "default.com"
别名: cut 是 cut_with_delim 的别名。bash 是 exec_cmd 的别名。
Type Conversion Functions¶
数据类型转换函数。
parse_int(str)¶
将字符串解析为整数。
parse_float(str)¶
将字符串解析为浮点数。
to_string(val)¶
将值转换为字符串。
to_boolean(val)¶
将值转换为布尔值。
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_dir(path)¶
检查路径是否为现有目录。
is_git(path)¶
检查路径是否在 git 仓库内。
is_url(input)¶
检查输入是否为有效的 URL。
is_compress(path)¶
检查路径是否为压缩归档文件(.zip、.tar.gz、.tgz 等)。
detect_language(path)¶
检测源代码文件夹的主要编程语言(支持26+种语言)。
detect_language("/path/to/project") // 返回:"javascript"
detect_language("{{Output}}/repo") // 返回:"python"
Utility Functions¶
通用工具函数。
len(val)¶
获取字符串或数组的长度。
is_empty(val)¶
检查值是否为空。
is_not_empty(val)¶
检查值是否不为空。
printf(message)¶
将消息打印到标准输出。
cat_file(path)¶
将文件内容打印到标准输出。
exit(code)¶
以指定代码退出扫描。
exec_cmd(command)¶
执行 bash 命令并返回输出。
sleep(seconds)¶
暂停执行 n 秒。
command_exists(command)¶
检查命令是否存在于 PATH 中。
Logging Functions¶
带级别前缀的日志消息函数。
log_debug(message)¶
以 [DEBUG] 前缀记录调试消息。
log_info(message)¶
以 [INFO] 前缀记录信息消息。
log_warn(message)¶
以 [WARN] 前缀记录警告消息。
log_error(message)¶
以 [ERROR] 前缀记录错误消息。
Color Printing Functions¶
带颜色输出的打印消息函数。
print_green(message)¶
以绿色打印消息。
print_blue(message)¶
以蓝色打印消息。
print_yellow(message)¶
以黄色打印消息。
print_red(message)¶
以红色打印消息。
Runtime Variable Functions¶
运行时设置和获取变量。
set_var(name, value)¶
设置运行时变量以供后续检索。
get_var(name)¶
获取运行时变量的值。
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_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)¶
生成随机字母数字字符串。
uuid()¶
生成 UUID v4。
Encoding Functions¶
编码和解码数据。
base64_encode(str)¶
将字符串编码为 base64。
base64_decode(str)¶
解码 base64 字符串。
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 提取数据。
Notification Functions¶
通过多种渠道发送通知。
notify_telegram(message)¶
向配置的 Telegram 聊天发送消息。
send_telegram_file(path, caption?)¶
向 Telegram 发送文件,可选标题。
notify_webhook(message)¶
向所有配置的 webhook 发送消息。
send_webhook_event(eventType, data)¶
向所有 webhook 发送结构化事件。
notify_telegram_channel(channel, message)¶
向特定 Telegram 频道发送消息。
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_channel(channel, path)¶
将文件内容作为文本文件发送到特定 Telegram 频道。
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