【无标题】

<

Nuclei 进阶—深入理解 Workflows、Matchers 和 Extractors

开发 开发工具
本篇我重点讲解一下Nuclei中的三个概念,Workflows、Mathcer和Extractors。这些内容将有助于帮助大家编写更为复杂和高效的检测脚本!

前面的文章中介绍了nuclei的基础使用方法,可以参考文章:

​POC模拟攻击利器——Nuclei入门(一)​

接下来我重点讲解一下nuclei中的三个概念,Workflows、Mathcer和Extractors。这些内容将有助于帮助大家编写更为复杂和高效的检测脚本!

workflows

Workflows允许用户自定义模板的执行顺序,这是使用nuclei最高效的方式,官方推荐用户使用自定义Workflows进而缩短扫描时间,提升扫描效率!

  • 基础工作流

例如,定义workflow 扫描files目录下如下yaml:

复制
workflows:- template: files/git-config.yaml- template: files/svn-config.yaml- template: files/env-file.yaml- template: files/backup-files.yaml- tags: xss,ssrf,cve,lfi
          
          
  • 1.
  • 条件工作流

首先确认springboot-detect.yaml是否正确执行,如果OK,则运行subtemplates下的template,实例如下:

复制
id: springboot-workflowinfo:name: Springboot Security Checksauthor: dwisiswant0workflows:- template: security-misconfiguration/springboot-detect.yamlsubtemplates:- template: cves/CVE-2018-1271.yaml- template: cves/CVE-2018-1271.yaml- template: cves/CVE-2020-5410.yaml- template: vulnerabilities/springboot-actuators-jolokia-xxe.yaml- template: vulnerabilities/springboot-h2-db-rce.yaml
          
          
  • 1.

运行workflows。

nuclei -list http_urls.txt -w workflows/my-workflow.yaml。

Matchers

Mathcer顾明思议,就是提供了一些规则,来对响应结果进行比较匹配!常用有六种类型的。

mathcer,如下所示:

  • status Integer Comparisons of Part
  • size Content Length of Part
  • word Part for a protocol
  • regex Part for a protocol
  • binary Part for a protocol
  • dsl Part for a protocol

例如想对响应码进行比较匹配,写法如下:

复制
matchers:# Match the status codes- type: status# Some status codes we want to matchstatus:- 200
          
          
  • 1.

想对响应码进行复杂的匹配时,可以使用dsl。

复制
matchers:- type: dsldsl:- "len(body)<1024 && status_code==200"- "contains(toupper(body), md5(cookie))"
          
          
  • 1.

上个实例的含义是匹配响应体长度小于1024 并且状态码是200。

判断大写的body中是否包括cookie的md5sum。

使用condition: and\or 可以对多个条件进行匹配,默认多个条件是and的关系。

官方实例如下:

复制
matchers:# Match the body word- type: word# Some words we want to matchwords:- "[core]"- "[config]"# Both words must be found in the response bodycondition: and# We want to match request body (default)part: body
          
          
  • 1.

详情请参考:

https://nuclei.projectdiscovery.io/templating-guide/operators/matchers/。

Extractors

Extractors 也是对结果进行校验,与matchers相比,它可以把满足规则的内容显示出来,同样他也有不同类型的Extractors,如下所示:

1. regex - Extract data from response based on a Regular Expression。

2. kval - Extract key: value/key=value formatted data from Response Header/Cookie。

3. json - Extract data from JSON based response in JQ like syntax。

4. xpath - Extract xpath based data from HTML Response。

例如:

复制
extractors:- type: xpath # type of the extractorattribute: href # attribute value to extract (optional)xpath:- "/html/body/div/p[2]/a" # xpath value for extraction
          
          
  • 1.

5. dsl - Extract data from the response based on a DSL expressions。

详情请参考:

https://nuclei.projectdiscovery.io/templating-guide/operators/extractors/。

由于使用nuclei时间尚浅,关于Extractors和Matchers,个人感觉使用差别不是很大!

二者都是对结果的校验,与matchers相比,Extractors它可以把满足规则的内容显示出来!如果大家需要编写复杂的响应校验,那么就需要花时间多研究dsl了。

如何从nuclei中受益

当使用了nuclei一段时间后,个人觉得其实使用nuclei最有价值的就是里面各种template,我们可以查看各个template的脚本来学习攻击方法,而且还可以根据里面的reference 来查看漏洞的详情,这个特别有助于安全知识的相关积累!至于攻击请求的发送,这个其实就容易很多了,我们是否使用nuclei其实都无所谓的,举个简单的例子,关于CVE-2020-9484的 yaml脚本定义如下:

复制
id: CVE-2020-9484info:name: Apache Tomcat Remote Command Executionauthor: dwisiswant0severity: highdescription: |When using Apache Tomcat versions 10.0.0-M1 to 10.0.0-M4, 9.0.0.M1 to 9.0.34, 8.5.0 to 8.5.54 and 7.0.0 to 7.0.103 ifa) an attacker is able to control the contents and name of a file on the server; andb) the server is configured to use the PersistenceManager with a FileStore; andc) the PersistenceManager is configured with sessionAttributeValueClassNameFilter="null" (the default unless a SecurityManager is used) or a sufficiently lax filter to allow the attacker provided object to be deserialized; andd) the attacker knows the relative file path from the storage location used by FileStore to the file the attacker has control over; then, using a specifically crafted request, the attacker will be able to trigger remote code execution via deserialization of the file under their control.Note that all of conditions a) to d) must be true for the attack to succeed.reference:- http://packetstormsecurity.com/files/157924/Apache-Tomcat-CVE-2020-9484-Proof-Of-Concept.html- https://nvd.nist.gov/vuln/detail/CVE-2020-9484- https://lists.apache.org/thread.html/r77eae567ed829da9012cadb29af17f2df8fa23bf66faf88229857bb1%40%3Cannounce.tomcat.apache.org%3E- https://lists.apache.org/thread.html/rf70f53af27e04869bdac18b1fc14a3ee529e59eb12292c8791a77926@%3Cusers.tomcat.apache.org%3Eclassification:cvss-metrics: CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:Hcvss-score: 7cve-id: CVE-2020-9484cwe-id: CWE-502tags: cve,cve2020,apache,tomcat,rcerequests:- method: GETheaders:Cookie: "JSESSIONID=../../../../../usr/local/tomcat/groovy"path:- "{{BaseURL}}/index.jsp"matchers-condition: andmatchers:- type: statusstatus:- 500- type: wordpart: bodywords:- "Exception"- "ObjectInputStream"- "PersistentManagerBase"condition: and
          
          
  • 1.

这个脚本中,最容易的可能就是requests:部分攻击脚本代码,我们用jmeter 或者自己写代码的方式完全可以轻松模拟!而description:部分以及reference:部分才是我们需要重点研究的对象!也是我们深入理解poc攻击的最佳实例!深入理解CLASSPATH

类路径,也就是CLASSPATH是Java&8482;对Java初学者来说是最复杂也最令人头痛的部分之一,但熟练掌握类路径对成为一名专业Java程序员来说却又十分关键。在本文中,ElliotteRustyHarold为您阐述了类路径和源路径的复杂性,并向您展示了如何在Windows中熟练掌握它们。

2010-06-01 15:25:27

Java CLASSPATH

2020-07-21 08:26:08

Spring Security 过滤器

2017-08-08 09:15:41

前端 JavaScript 页面渲染

2021-09-24 08:10:40

Java 语言 Java 基础

2021-10-15 09:19:17

Android SharedPrefe 分析源码

2021-09-08 06:51:52

Android Retrofit 原理

2021-09-15 07:31:33

Android 窗口 管理

2012-08-31 10:00:12

Hadoop 云计算 群集网络

2012-11-08 14:47:52

Hadoop集群

2013-07-31 10:04:42

hadoop Hadoop集群 集群和网络

2011-07-18 14:38:44

子查询 外部查询

2021-09-18 06:56:01

Java CAS 机制

2021-08-24 07:53:28

Android Activity 生命周期

2017-04-25 15:30:23

堆栈 函数 JavaScript

2017-03-28 21:39:41

Errors Stack trace 代码

2017-01-10 08:48:21

2017-08-15 13:05:58

Serverless 架构 开发运维
点赞
收藏

51CTO技术栈公众号

51CTO技术栈公众号

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值