-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add flow
support in template (i.e javascript scripting)
#4015
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tarunKoyalwar
changed the title
add template flow (js scripting)
WIP: add template flow (js scripting)
Aug 1, 2023
TODO
|
http({hide: true})
|
POC
$ chaos -silent -d hackerone.com | dnsx -silent -json | jq -r '. | .a | select( . != null ) | .[]' | sort -u | uniq | go run . -t ~/test-templates/vhost-enum-flow.yaml
__ _
____ __ _______/ /__ (_)
/ __ \/ / / / ___/ / _ \/ /
/ / / / /_/ / /__/ / __/ /
/_/ /_/\__,_/\___/_/\___/_/ v3.0.0-dev
projectdiscovery.io
[INF] Current nuclei version: v3.0.0-dev (development)
[INF] Current nuclei-templates version: v9.6.1 (latest)
[INF] New templates added in latest release: 198
[INF] Templates loaded for current scan: 1
[INF] Targets loaded for current scan: 20
[INF] Running httpx on input host
[INF] Found 20 URL from httpx
[vhost-enum-flow] [http] [info] https://104.16.99.52/ [VHOST: www.hackerone.com, SC: 200, CL: 177235]
[vhost-enum-flow] [http] [info] https://104.16.99.52/ [VHOST: api.hackerone.com, SC: 200, CL: 8486]
[vhost-enum-flow] [http] [info] https://185.199.109.153/ [VHOST: githubusercontent.com, SC: 404, CL: 9115]
[vhost-enum-flow] [http] [info] https://185.199.108.153/ [VHOST: githubusercontent.com, SC: 404, CL: 9115]
[vhost-enum-flow] [http] [info] https://185.199.109.153/ [VHOST: githubusercontent.com, SC: 404, CL: 9115]
[vhost-enum-flow] [http] [info] https://185.199.108.153/ [VHOST: githubusercontent.com, SC: 404, CL: 9115]
[vhost-enum-flow] [http] [info] https://52.60.160.16/ [VHOST: ec2-52-60-160-16.ca-central-1.compute.amazonaws.com., SC: 404, CL: 9783]
[vhost-enum-flow] [http] [info] https://185.199.111.153/ [VHOST: github.com, SC: 404, CL: 9115]
[vhost-enum-flow] [http] [info] https://185.199.109.153/ [VHOST: cdn-185-199-109-153.github.com., SC: 404, CL: 9623]
[vhost-enum-flow] [http] [info] https://52.60.165.183/ [VHOST: uberflip.com, SC: 404, CL: 9594]
[vhost-enum-flow] [http] [info] https://35.170.195.217/ [VHOST: ec2-35-170-195-217.compute-1.amazonaws.com., SC: 403, CL: 520]
[vhost-enum-flow] [http] [info] https://52.203.118.248/ [VHOST: freshdesk.com, SC: 404, CL: 1129]
[vhost-enum-flow] [http] [info] https://185.199.111.153/ [VHOST: github.com, SC: 404, CL: 9115]
[vhost-enum-flow] [http] [info] https://44.218.44.151/ [VHOST: ec2-44-218-44-151.compute-1.amazonaws.com., SC: 403, CL: 520]
[vhost-enum-flow] [http] [info] https://185.199.109.153/ [VHOST: github.io, SC: 301, CL: 0]
[vhost-enum-flow] [http] [info] https://104.16.99.52/ [VHOST: hackerone.com, SC: 302, CL: 92]
[vhost-enum-flow] [http] [info] https://3.98.63.202/ [VHOST: ec2-3-98-63-202.ca-central-1.compute.amazonaws.com., SC: 404, CL: 9780]
[vhost-enum-flow] [http] [info] https://185.199.109.153/ [VHOST: github.io, SC: 301, CL: 0]
[vhost-enum-flow] [http] [info] https://185.199.108.153/ [VHOST: cdn-185-199-108-153.github.com., SC: 404, CL: 9623]
[vhost-enum-flow] [http] [info] https://185.199.111.153/ [VHOST: www.github.com, SC: 404, CL: 9575]
[vhost-enum-flow] [http] [info] https://3.229.75.209/ [VHOST: ec2-3-229-75-209.compute-1.amazonaws.com., SC: 403, CL: 520]
[vhost-enum-flow] [http] [info] https://185.199.109.153/ [VHOST: github.com, SC: 404, CL: 9115]
[vhost-enum-flow] [http] [info] https://185.199.111.153/ [VHOST: githubusercontent.com, SC: 404, CL: 9115]
[vhost-enum-flow] [http] [info] https://185.199.108.153/ [VHOST: github.io, SC: 301, CL: 0]
[vhost-enum-flow] [http] [info] https://185.199.109.153/ [VHOST: github.com, SC: 404, CL: 9115]
[vhost-enum-flow] [http] [info] https://185.199.111.153/ [VHOST: githubusercontent.com, SC: 404, CL: 9115]
[vhost-enum-flow] [http] [info] https://185.199.108.153/ [VHOST: github.io, SC: 301, CL: 0]
[vhost-enum-flow] [http] [info] https://52.60.160.16/ [VHOST: uberflip.com, SC: 404, CL: 9588]
[vhost-enum-flow] [http] [info] https://52.60.165.183/ [VHOST: ec2-52-60-165-183.ca-central-1.compute.amazonaws.com., SC: 404, CL: 9797]
[vhost-enum-flow] [http] [info] https://185.199.109.153/ [VHOST: www.github.com, SC: 404, CL: 9575]
[vhost-enum-flow] [http] [info] https://185.199.108.153/ [VHOST: github.com, SC: 404, CL: 9115]
[vhost-enum-flow] [http] [info] https://185.199.108.153/ [VHOST: github.com, SC: 404, CL: 9115]
[vhost-enum-flow] [http] [info] https://52.203.118.248/ [VHOST: ec2-52-203-118-248.compute-1.amazonaws.com., SC: 403, CL: 520]
[vhost-enum-flow] [http] [info] https://35.170.195.217/ [VHOST: freshdesk.com, SC: 404, CL: 1127]
[vhost-enum-flow] [http] [info] https://3.98.63.202/ [VHOST: uberflip.com, SC: 404, CL: 9601]
[vhost-enum-flow] [http] [info] https://44.218.44.151/ [VHOST: freshdesk.com, SC: 404, CL: 1127]
[vhost-enum-flow] [http] [info] https://185.199.108.153/ [VHOST: www.github.com, SC: 404, CL: 9575]
[vhost-enum-flow] [http] [info] https://185.199.111.153/ [VHOST: cdn-185-199-111-153.github.com., SC: 404, CL: 9623]
[vhost-enum-flow] [http] [info] https://3.229.75.209/ [VHOST: freshdesk.com, SC: 404, CL: 1127]
[vhost-enum-flow] [http] [info] https://185.199.111.153/ [VHOST: github.io, SC: 301, CL: 0]
[vhost-enum-flow] [http] [info] https://52.60.160.16/ [VHOST: uberflip.com, SC: 404, CL: 9589]
[vhost-enum-flow] [http] [info] https://104.16.100.52/ [VHOST: hackerone.com, SC: 302, CL: 92]
[vhost-enum-flow] [http] [info] https://52.60.165.183/ [VHOST: uberflip.com, SC: 404, CL: 9594]
[vhost-enum-flow] [http] [info] https://185.199.111.153/ [VHOST: github.io, SC: 301, CL: 0]
[vhost-enum-flow] [http] [info] https://104.16.100.52/ [VHOST: www.hackerone.com, SC: 200, CL: 177235]
[vhost-enum-flow] [http] [info] https://3.98.63.202/ [VHOST: uberflip.com, SC: 404, CL: 9589]
[vhost-enum-flow] [http] [info] https://104.16.100.52/ [VHOST: api.hackerone.com, SC: 200, CL: 8486]
[vhost-enum-flow] [http] [info] https://35.169.15.7/ [VHOST: ec2-35-169-15-7.compute-1.amazonaws.com., SC: 403, CL: 520]
[vhost-enum-flow] [http] [info] https://35.169.15.7/ [VHOST: freshdesk.com, SC: 404, CL: 1127]
[vhost-enum-flow] [http] [info] https://185.199.110.153/ [VHOST: www.github.com, SC: 404, CL: 9575]
[vhost-enum-flow] [http] [info] https://185.199.110.153/ [VHOST: githubusercontent.com, SC: 404, CL: 9115]
[vhost-enum-flow] [http] [info] https://185.199.110.153/ [VHOST: githubusercontent.com, SC: 404, CL: 9115]
[vhost-enum-flow] [http] [info] https://185.199.110.153/ [VHOST: cdn-185-199-110-153.github.com., SC: 404, CL: 9623]
[vhost-enum-flow] [http] [info] https://185.199.110.153/ [VHOST: github.io, SC: 301, CL: 0]
[vhost-enum-flow] [http] [info] https://185.199.110.153/ [VHOST: github.io, SC: 301, CL: 0]
[vhost-enum-flow] [http] [info] https://185.199.110.153/ [VHOST: github.com, SC: 404, CL: 9115]
[vhost-enum-flow] [http] [info] https://185.199.110.153/ [VHOST: github.com, SC: 404, CL: 9115] |
example template using most/all featuresid: vhost-enum-flow
info:
name: vhost enum flow
author: tarunKoyalwar
severity: info
description: |
vhost enumeration by extracting potential vhost names from ssl certificate and dns ptr records
flow: |
let uniq = new Dedupe();
ssl();
dns();
uniq.Add(template["ptrValue"])
uniq.Add(template["ssl_subject_cn"]);
uniq.Add(template["ssl_subject_an"]);
for (let vhost of uniq.Values()) {
vhost = vhost.replace("*.", "")
set("vhost", vhost);
http();
}
ssl:
- address: "{{Host}}:{{Port}}"
dns:
- name: "{{FQDN}}"
type: PTR
extractors:
- type: regex
name: ptrValue
internal: true
group: 1
regex:
- "IN\tPTR\t(.+)"
http:
- raw:
- |
GET / HTTP/1.1
Host: {{trim_suffix(vhost, ".")}}
matchers:
- type: status
negative: true
status:
- 400
- 502
extractors:
- type: dsl
dsl:
- '"VHOST: " + vhost + ", SC: " + status_code + ", CL: " + content_length' |
PR Changelog
|
Template for #3700id: vpc-logging-not-enabled
info:
name: VPC flow logging Not enabled
author: princechaddha
severity: low
description: |
Checks if the Amazon CloudWatch alarmed is enabled for Sign In without MFA
reference:
- https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeVpcs.html
- https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeFlowLogs.html
remediation: Enabling VPC Flow Logs
tags: cloud,devops,aws,amazon,vpc,ec2,logging
self-contained: true
signature: aws
variables:
service: ec2
regions:
- us-west-1
- us-east-1
flow: |
for(let region of iterate(template["regions"])){
set("region",region);
http("extract-vpcs");
for(let vpcId of iterate(template["vpcs"])){
set("vpcId",vpcId);
http("extract-flow-logs");
}
}
http:
- id: extract-vpcs
raw:
- |
POST https://{{service}}.{{region}}.amazonaws.com/ HTTP/1.1
Host: {{service}}.{{region}}.amazonaws.com
Content-Type: application/x-www-form-urlencoded; charset=utf-8
User-Agent: aws-cli/2.9.15 Python/3.11.1 Darwin/22.3.0 source/arm64 prompt/off command/ec2.describe-vpcs
Action=DescribeVpcs&Version=2016-11-15
extractors:
- type: regex
name: vpcs
part: body
internal: true
group: 1
regex:
- '<vpcId>([a-z-0-9]+)<\/vpcId>'
- id: extract-flow-logs
raw:
- |
POST https://{{service}}.{{region}}.amazonaws.com/ HTTP/1.1
Host: {{service}}.{{region}}.amazonaws.com
Content-Type: application/x-www-form-urlencoded; charset=utf-8
User-Agent: aws-cli/2.9.15 Python/3.11.1 Darwin/22.3.0 source/arm64 prompt/off command/ec2.describe-flow-logs
Action=DescribeFlowLogs&Version=2016-11-15&Filter.1.Name=resource-id&Filter.1.Value.1={{vpcId}}
iterate-all: true
matchers-condition: and
matchers:
- type: word
part: body
words:
- "</DescribeFlowLogsResponse>"
- type: word
words:
- "<flowLogId>"
negative: true
extractors:
- type: dsl
dsl:
- '"VPC flow logging is not enabled for " + vpcId + " in " + region + " region"'
DemoWithout Override from Cli $ go run . -t ~/test-templates/vpc-logging-not-enabled.yaml
__ _
____ __ _______/ /__ (_)
/ __ \/ / / / ___/ / _ \/ /
/ / / / /_/ / /__/ / __/ /
/_/ /_/\__,_/\___/_/\___/_/ v3.0.0-dev
projectdiscovery.io
[INF] Current nuclei version: v3.0.0-dev (development)
[INF] Current nuclei-templates version: v9.6.1 (latest)
[INF] New templates added in latest release: 198
[INF] Templates loaded for current scan: 1
[vpc-logging-not-enabled] [http] [low] https://ec2.us-west-1.amazonaws.com/ [VPC flow logging is not enabled for vpc-0a7b0a4148d2b5c14 in us-west-1 region]
[vpc-logging-not-enabled] [http] [low] https://ec2.us-east-1.amazonaws.com/ [VPC flow logging is not enabled for vpc-0cc801e39bf787771 in us-east-1 region]
[vpc-logging-not-enabled] [http] [low] https://ec2.us-east-1.amazonaws.com/ [VPC flow logging is not enabled for vpc-072e8d17809966803 in us-east-1 region] With Override from CLI using -var flag $ go run . -t ~/test-templates/vpc-logging-not-enabled.yaml -V "regions=regions.txt" -lfa
__ _
____ __ _______/ /__ (_)
/ __ \/ / / / ___/ / _ \/ /
/ / / / /_/ / /__/ / __/ /
/_/ /_/\__,_/\___/_/\___/_/ v3.0.0-dev
projectdiscovery.io
[INF] Current nuclei version: v3.0.0-dev (development)
[INF] Current nuclei-templates version: v9.6.1 (latest)
[INF] New templates added in latest release: 198
[INF] Templates loaded for current scan: 1
[vpc-logging-not-enabled] [http] [low] https://ec2.us-east-1.amazonaws.com/ [VPC flow logging is not enabled for vpc-072e8d17809966803 in us-east-1 region]
[vpc-logging-not-enabled] [http] [low] https://ec2.us-east-1.amazonaws.com/ [VPC flow logging is not enabled for vpc-0cc801e39bf787771 in us-east-1 region]
[vpc-logging-not-enabled] [http] [low] https://ec2.us-west-1.amazonaws.com/ [VPC flow logging is not enabled for vpc-0a7b0a4148d2b5c14 in us-west-1 region]
[vpc-logging-not-enabled] [http] [low] https://ec2.ap-south-1.amazonaws.com/ [VPC flow logging is not enabled for vpc-047617a9feaf980c0 in ap-south-1 region] regions.txt
|
created follow up issue for adding for request annotation as suggested by @Mzack9999 |
tarunKoyalwar
changed the title
WIP: add template flow (js scripting)
add Aug 25, 2023
flow
support in template (i.e javascript scripting)
tarunKoyalwar
added
the
Status: Review Needed
The issue has a PR attached to it which needs to be reviewed
label
Aug 25, 2023
Mzack9999
approved these changes
Aug 29, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
Few observations:
- The mechanism for scoping context variables via
set
seems a bit counter-intuitive, as the variable is scoped instead for the whole template. Quoting Advanced Scripting Engine #641 (comment) I think a declarative approach is more intuitive and readable, from the previous work:
args = {
'server': server,
}
http(args);
http("another-id", args)
Regardless, awesome job!
Ice3man543
approved these changes
Aug 31, 2023
ehsandeep
approved these changes
Aug 31, 2023
ehsandeep
added
Type: Enhancement
Most issues will probably ask for additions or changes.
and removed
Status: Review Needed
The issue has a PR attached to it which needs to be reviewed
labels
Aug 31, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposed changes
Complete Documentation of flow is available at https://github.com/projectdiscovery/nuclei/tree/feat-nuclei-template-flow/v2/pkg/tmplexec/flow#readme
example flow templates are available in integration_test at https://github.com/projectdiscovery/nuclei/tree/feat-nuclei-template-flow/integration_tests/flow
nuclei/v2/pkg/tmplexec/flow/README.md
Lines 1 to 319 in f5ac33a
Checklist