Documentation Index
Fetch the complete documentation index at: https://docs.xray.cool/llms.txt
Use this file to discover all available pages before exploring further.
函数原型
func (s1 string) bsubmatches(b1 bytes) map[string]string
参数介绍
命名捕获组
- 在使用submatch的时候,会与一个正则语法,“命名捕获组”一同使用:
(?P<name>pattern)
- 其中 name 是捕获组的名称,pattern 是要匹配的模式。捕获组是一种可以将匹配的文本捕获并在后续操作中使用的机制。
- 在yaml中,我们将name化作map的key,pattern匹配到的内容化作value,也就是说,在一段正则中,可以存在多个命名捕获组,例如:
"^SSH-([\\d.]+)-OpenSSH_(?P<version0>[\\w._-]+) Debian-(?P<version1>\\S*maemo\\S*)\\r?\\n"
- 可以看到上方的例子中的
\w、\d、\n等都被替换成了\\w、\\d、\\n,这是因为需要规避yaml的转译
-
Response
HTTP/1.1 200 OK
Server: nginx
Date: Sat, 07 Jan 2023 10:41:06 GMT
Content-Type: text/html; charset=utf-8
Connection: close
Vary: Accept-Encoding
Cache-Control: no-cache
Token: aver258wniuv15ngfverw378cas
Content-Length: 85
<!DOCTYPE html>
<html>
<head>
<title>123</title>
</head>
<body>
version: 1.8.1
</body>
</html>
-
可以编写如下脚本判断版本:
name: poc-yaml-test
transport: http
rules:
r0:
request:
method: GET
path: /
follow_redirects: false
expression: response.status == 200 && "(?P<version>\\d\\.\\d\\.\\d\\.)".bsubmatch(response.body)["version"].versionEqual("1.8.1")
expression: r0()
detail:
author: test
links:
- test.test
-
如果是要提供给下一个规则,则可以使用output:
name: poc-yaml-openssl-cve-2022-3602-3786
transport: http
rules:
r0:
request:
method: GET
path: /
follow_redirects: false
expression: response.status == 200
expression: r0()
output:
token: '"Token: (?<token>\\w*)".bsubmatch(response.raw_header)["token"]'
r1:
request:
method: GET
path: /{{token}}
follow_redirects: false
expression: response.status == 200
expression: r0()
detail:
author: test
links:
- test.test
-
其中上述的token还可以拆分成serach和token,也就是:
search: '"Token: (?<token>\\w*)".bsubmatch(response.raw_header)'
token: search["token"]