From 7761c970a2056b9a89bf410c64680d2fdf75ff9f Mon Sep 17 00:00:00 2001 From: HAHWUL Date: Wed, 10 Jan 2024 23:28:32 +0900 Subject: [PATCH 1/8] Update lint config --- .ameba.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.ameba.yml b/.ameba.yml index 98636018..75bff492 100644 --- a/.ameba.yml +++ b/.ameba.yml @@ -6,3 +6,6 @@ Metrics/CyclomaticComplexity: MaxComplexity: 40 Enabled: true Severity: Warning + +Lint/RedundantWithIndex: + Enabled: false \ No newline at end of file From 2d0a0d1f25789a31072bc36251324b0dd23911c2 Mon Sep 17 00:00:00 2001 From: HAHWUL Date: Wed, 10 Jan 2024 23:29:58 +0900 Subject: [PATCH 2/8] Add ony-url format (#217) --- spec/unit_test/models/output_builder_spec.cr | 5 +++++ src/analyzer/analyzers/analyzer_example.cr | 2 +- src/models/noir.cr | 3 +++ src/noir.cr | 2 +- src/output_builder/only-url.cr | 12 ++++++++++++ 5 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 src/output_builder/only-url.cr diff --git a/spec/unit_test/models/output_builder_spec.cr b/spec/unit_test/models/output_builder_spec.cr index fe35ab90..617c1315 100644 --- a/spec/unit_test/models/output_builder_spec.cr +++ b/spec/unit_test/models/output_builder_spec.cr @@ -41,4 +41,9 @@ describe "Initialize" do object = OutputBuilderOas3.new options object.output_file.should eq("output.json") end + + it "OutputBuilderOnlyUrl" do + object = OutputBuilderOnlyUrl.new options + object.output_file.should eq("output.json") + end end diff --git a/src/analyzer/analyzers/analyzer_example.cr b/src/analyzer/analyzers/analyzer_example.cr index 230b891b..69445100 100644 --- a/src/analyzer/analyzers/analyzer_example.cr +++ b/src/analyzer/analyzers/analyzer_example.cr @@ -8,7 +8,7 @@ class AnalyzerExample < Analyzer next if File.directory?(path) if File.exists?(path) File.open(path, "r", encoding: "utf-8", invalid: :skip) do |file| - file.each_line.with_index do |line, index| + file.each_line.with_index do |_, _| # For example (Add endpoint to result) # endpoint = Endpoint.new("/", "GET") # details = Details.new(PathInfo.new(path, index + 1)) diff --git a/src/models/noir.cr b/src/models/noir.cr index 46d9e014..b9e86bc2 100644 --- a/src/models/noir.cr +++ b/src/models/noir.cr @@ -173,6 +173,9 @@ class NoirRunner when "oas3" buidler = OutputBuilderOas3.new @options buidler.print @endpoints + when "only-url" + builder = OutputBuilderOnlyUrl.new @options + builder.print @endpoints else builder = OutputBuilderCommon.new @options builder.print @endpoints diff --git a/src/noir.cr b/src/noir.cr index 83b32965..e0a1de95 100644 --- a/src/noir.cr +++ b/src/noir.cr @@ -20,7 +20,7 @@ OptionParser.parse do |parser| parser.separator "\n Output:".colorize(:blue) - parser.on "-f FORMAT", "--format json", "Set output format \n[plain/json/yaml/markdown-table/curl/httpie/oas2/oas3]" { |var| noir_options[:format] = var } + parser.on "-f FORMAT", "--format json", "Set output format\n * plain json yaml markdown-table\n * curl httpie only-url\n * oas2 oas3" { |var| noir_options[:format] = var } parser.on "-o PATH", "--output out.txt", "Write result to file" { |var| noir_options[:output] = var } parser.on "--set-pvalue VALUE", "Specifies the value of the identified parameter" { |var| noir_options[:set_pvalue] = var } parser.on "--include-path", "Include file path in the plain result" do diff --git a/src/output_builder/only-url.cr b/src/output_builder/only-url.cr new file mode 100644 index 00000000..c0501043 --- /dev/null +++ b/src/output_builder/only-url.cr @@ -0,0 +1,12 @@ +require "../models/output_builder" +require "../models/endpoint" + +class OutputBuilderOnlyUrl < OutputBuilder + def print(endpoints : Array(Endpoint)) + endpoints.each do |endpoint| + baked = bake_endpoint(endpoint.url, endpoint.params) + r_url = baked[:url].colorize(:light_yellow).toggle(@is_color) + ob_puts "#{r_url}" + end + end +end From 48bb92f8d352bd03fa0bc0cb6c77066ef4e12dc4 Mon Sep 17 00:00:00 2001 From: HAHWUL Date: Wed, 10 Jan 2024 23:33:00 +0900 Subject: [PATCH 3/8] Update lint and Example --- .ameba.yml | 6 +++++- src/analyzer/analyzers/analyzer_example.cr | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.ameba.yml b/.ameba.yml index 75bff492..5b4bc8b1 100644 --- a/.ameba.yml +++ b/.ameba.yml @@ -8,4 +8,8 @@ Metrics/CyclomaticComplexity: Severity: Warning Lint/RedundantWithIndex: - Enabled: false \ No newline at end of file + Enabled: false + +Lint/UnusedArgument: + Excluded: + - "src/analyzer/analyzers/analyzer_example.cr" \ No newline at end of file diff --git a/src/analyzer/analyzers/analyzer_example.cr b/src/analyzer/analyzers/analyzer_example.cr index 69445100..230b891b 100644 --- a/src/analyzer/analyzers/analyzer_example.cr +++ b/src/analyzer/analyzers/analyzer_example.cr @@ -8,7 +8,7 @@ class AnalyzerExample < Analyzer next if File.directory?(path) if File.exists?(path) File.open(path, "r", encoding: "utf-8", invalid: :skip) do |file| - file.each_line.with_index do |_, _| + file.each_line.with_index do |line, index| # For example (Add endpoint to result) # endpoint = Endpoint.new("/", "GET") # details = Details.new(PathInfo.new(path, index + 1)) From 85f7568cb2d9bd5aab9fd5dde26668661a881516 Mon Sep 17 00:00:00 2001 From: HAHWUL Date: Wed, 10 Jan 2024 23:41:55 +0900 Subject: [PATCH 4/8] Update description of help message --- src/noir.cr | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/noir.cr b/src/noir.cr index 83b32965..294fd054 100644 --- a/src/noir.cr +++ b/src/noir.cr @@ -34,16 +34,16 @@ OptionParser.parse do |parser| end parser.separator "\n Deliver:".colorize(:blue) - parser.on "--send-req", "Send the results to the web request" { |_| noir_options[:send_req] = "yes" } - parser.on "--send-proxy http://proxy..", "Send the results to the web request via http proxy" { |var| noir_options[:send_proxy] = var } - parser.on "--send-es http://es..", "Send the results to elasticsearch" { |var| noir_options[:send_es] = var } - parser.on "--with-headers X-Header:Value", "Add Custom Headers to be Used in Deliver" do |var| + parser.on "--send-req", "Send results to a web request" { |_| noir_options[:send_req] = "yes" } + parser.on "--send-proxy http://proxy..", "Send results to a web request via an HTTP proxy" { |var| noir_options[:send_proxy] = var } + parser.on "--send-es http://es..", "Send results to Elasticsearch" { |var| noir_options[:send_es] = var } + parser.on "--with-headers X-Header:Value", "Add custom headers to be included in the delivery" do |var| noir_options[:send_with_headers] += "#{var}::NOIR::HEADERS::SPLIT::" end - parser.on "--use-matchers string", "Delivers URLs that match a specific condition" do |var| + parser.on "--use-matchers string", "Send URLs that match specific conditions to the Deliver" do |var| noir_options[:use_matchers] += "#{var}::NOIR::MATCHER::SPLIT::" end - parser.on "--use-filters string", "Excludes URLs that match a specific condition" do |var| + parser.on "--use-filters string", "Exclude URLs that match specified conditions and send the rest to Deliver" do |var| noir_options[:use_filters] += "#{var}::NOIR::FILTER::SPLIT::" end From 312ae40401e058ab6e6fb803a80ebcf82d8f184d Mon Sep 17 00:00:00 2001 From: HAHWUL Date: Thu, 11 Jan 2024 00:05:07 +0900 Subject: [PATCH 5/8] Add only-* formats (#217) --- spec/unit_test/models/output_builder_spec.cr | 15 ++++++++++++++ src/models/noir.cr | 9 +++++++++ src/noir.cr | 2 +- src/output_builder/only-cookie.cr | 19 ++++++++++++++++++ src/output_builder/only-header.cr | 19 ++++++++++++++++++ src/output_builder/only-param.cr | 21 ++++++++++++++++++++ 6 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 src/output_builder/only-cookie.cr create mode 100644 src/output_builder/only-header.cr create mode 100644 src/output_builder/only-param.cr diff --git a/spec/unit_test/models/output_builder_spec.cr b/spec/unit_test/models/output_builder_spec.cr index 617c1315..69d994f3 100644 --- a/spec/unit_test/models/output_builder_spec.cr +++ b/spec/unit_test/models/output_builder_spec.cr @@ -46,4 +46,19 @@ describe "Initialize" do object = OutputBuilderOnlyUrl.new options object.output_file.should eq("output.json") end + + it "OutputBuilderOnlyParam" do + object = OutputBuilderOnlyParam.new options + object.output_file.should eq("output.json") + end + + it "OutputBuilderOnlyHeader" do + object = OutputBuilderOnlyHeader.new options + object.output_file.should eq("output.json") + end + + it "OutputBuilderOnlyCookie" do + object = OutputBuilderOnlyCookie.new options + object.output_file.should eq("output.json") + end end diff --git a/src/models/noir.cr b/src/models/noir.cr index b9e86bc2..d9628fe2 100644 --- a/src/models/noir.cr +++ b/src/models/noir.cr @@ -176,6 +176,15 @@ class NoirRunner when "only-url" builder = OutputBuilderOnlyUrl.new @options builder.print @endpoints + when "only-param" + builder = OutputBuilderOnlyParam.new @options + builder.print @endpoints + when "only-header" + builder = OutputBuilderOnlyHeader.new @options + builder.print @endpoints + when "only-cookie" + builder = OutputBuilderOnlyCookie.new @options + builder.print @endpoints else builder = OutputBuilderCommon.new @options builder.print @endpoints diff --git a/src/noir.cr b/src/noir.cr index a4d03237..47c6129f 100644 --- a/src/noir.cr +++ b/src/noir.cr @@ -20,7 +20,7 @@ OptionParser.parse do |parser| parser.separator "\n Output:".colorize(:blue) - parser.on "-f FORMAT", "--format json", "Set output format\n * plain json yaml markdown-table\n * curl httpie only-url\n * oas2 oas3" { |var| noir_options[:format] = var } + parser.on "-f FORMAT", "--format json", "Set output format\n * plain json yaml markdown-table\n * curl httpie oas2 oas3\n * only-url only-param only-header only-cookie" { |var| noir_options[:format] = var } parser.on "-o PATH", "--output out.txt", "Write result to file" { |var| noir_options[:output] = var } parser.on "--set-pvalue VALUE", "Specifies the value of the identified parameter" { |var| noir_options[:set_pvalue] = var } parser.on "--include-path", "Include file path in the plain result" do diff --git a/src/output_builder/only-cookie.cr b/src/output_builder/only-cookie.cr new file mode 100644 index 00000000..76ca42b4 --- /dev/null +++ b/src/output_builder/only-cookie.cr @@ -0,0 +1,19 @@ +require "../models/output_builder" +require "../models/endpoint" + +class OutputBuilderOnlyCookie < OutputBuilder + def print(endpoints : Array(Endpoint)) + cookies = [] of String + endpoints.each do |endpoint| + endpoint.params.each do |param| + if param.param_type == "cookie" + cookies << param.name + end + end + end + + cookies.uniq.each do |cookie| + puts cookie.colorize(:light_green).toggle(@is_color) + end + end +end diff --git a/src/output_builder/only-header.cr b/src/output_builder/only-header.cr new file mode 100644 index 00000000..d8eb97c8 --- /dev/null +++ b/src/output_builder/only-header.cr @@ -0,0 +1,19 @@ +require "../models/output_builder" +require "../models/endpoint" + +class OutputBuilderOnlyHeader < OutputBuilder + def print(endpoints : Array(Endpoint)) + headers = [] of String + endpoints.each do |endpoint| + endpoint.params.each do |param| + if param.param_type == "header" + headers << param.name + end + end + end + + headers.uniq.each do |header| + puts header.colorize(:light_green).toggle(@is_color) + end + end +end diff --git a/src/output_builder/only-param.cr b/src/output_builder/only-param.cr new file mode 100644 index 00000000..a6688765 --- /dev/null +++ b/src/output_builder/only-param.cr @@ -0,0 +1,21 @@ +require "../models/output_builder" +require "../models/endpoint" + +class OutputBuilderOnlyParam < OutputBuilder + def print(endpoints : Array(Endpoint)) + common_params = [] of String + targets = ["query", "json", "form"] + + endpoints.each do |endpoint| + endpoint.params.each do |param| + if targets.includes? param.param_type + common_params << param.name + end + end + end + + common_params.uniq.each do |common_param| + puts common_param.colorize(:light_green).toggle(@is_color) + end + end +end From 2df547c4c9639f6fde20af8158cc7ff6d50c72a6 Mon Sep 17 00:00:00 2001 From: HAHWUL Date: Thu, 11 Jan 2024 23:49:22 +0900 Subject: [PATCH 6/8] =?UTF-8?q?=F0=9F=91=A5=20Add=20author?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shard.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/shard.yml b/shard.yml index 29cb8903..6fef23a6 100644 --- a/shard.yml +++ b/shard.yml @@ -3,6 +3,7 @@ version: 0.12.0 authors: - hahwul + - ksg97031 targets: noir: From 68499815c111b2b0269b23fa1b412f9060971599 Mon Sep 17 00:00:00 2001 From: HAHWUL Date: Fri, 12 Jan 2024 23:06:47 +0900 Subject: [PATCH 7/8] Add output format (jsonl / #217) --- README.md | 16 +++++++++------- spec/unit_test/models/output_builder_spec.cr | 5 +++++ src/models/noir.cr | 7 +++++-- src/noir.cr | 2 +- src/output_builder/jsonl.cr | 10 ++++++++++ 5 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 src/output_builder/jsonl.cr diff --git a/README.md b/README.md index e000d372..fc320084 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,9 @@ Usage: noir Output: -f FORMAT, --format json Set output format - [plain/json/yaml/markdown-table/curl/httpie/oas2/oas3] + * plain yaml json jsonl markdown-table + * curl httpie oas2 oas3 + * only-url only-param only-header only-cookie -o PATH, --output out.txt Write result to file --set-pvalue VALUE Specifies the value of the identified parameter --include-path Include file path in the plain result @@ -105,12 +107,12 @@ Usage: noir --no-log Displaying only the results Deliver: - --send-req Send the results to the web request - --send-proxy http://proxy.. Send the results to the web request via http proxy - --send-es http://es.. Send the results to elasticsearch - --with-headers X-Header:Value Add Custom Headers to be Used in Deliver - --use-matchers string Delivers URLs that match a specific condition - --use-filters string Excludes URLs that match a specific condition + --send-req Send results to a web request + --send-proxy http://proxy.. Send results to a web request via an HTTP proxy + --send-es http://es.. Send results to Elasticsearch + --with-headers X-Header:Value Add custom headers to be included in the delivery + --use-matchers string Send URLs that match specific conditions to the Deliver + --use-filters string Exclude URLs that match specified conditions and send the rest to Deliver Technologies: -t TECHS, --techs rails,php Specify the technologies to use diff --git a/spec/unit_test/models/output_builder_spec.cr b/spec/unit_test/models/output_builder_spec.cr index 69d994f3..ddebdd8b 100644 --- a/spec/unit_test/models/output_builder_spec.cr +++ b/spec/unit_test/models/output_builder_spec.cr @@ -61,4 +61,9 @@ describe "Initialize" do object = OutputBuilderOnlyCookie.new options object.output_file.should eq("output.json") end + + it "OutputBuilderJsonl" do + object = OutputBuilderJsonl.new options + object.output_file.should eq("output.json") + end end diff --git a/src/models/noir.cr b/src/models/noir.cr index d9628fe2..8aa306da 100644 --- a/src/models/noir.cr +++ b/src/models/noir.cr @@ -154,10 +154,13 @@ class NoirRunner def report case options[:format] - when "json" - puts @endpoints.to_json when "yaml" puts @endpoints.to_yaml + when "json" + puts @endpoints.to_json + when "jsonl" + builder = OutputBuilderJsonl.new @options + builder.print @endpoints when "markdown-table" builder = OutputBuilderMarkdownTable.new @options builder.print @endpoints diff --git a/src/noir.cr b/src/noir.cr index 47c6129f..6ed0f326 100644 --- a/src/noir.cr +++ b/src/noir.cr @@ -20,7 +20,7 @@ OptionParser.parse do |parser| parser.separator "\n Output:".colorize(:blue) - parser.on "-f FORMAT", "--format json", "Set output format\n * plain json yaml markdown-table\n * curl httpie oas2 oas3\n * only-url only-param only-header only-cookie" { |var| noir_options[:format] = var } + parser.on "-f FORMAT", "--format json", "Set output format\n * plain yaml json jsonl markdown-table\n * curl httpie oas2 oas3\n * only-url only-param only-header only-cookie" { |var| noir_options[:format] = var } parser.on "-o PATH", "--output out.txt", "Write result to file" { |var| noir_options[:output] = var } parser.on "--set-pvalue VALUE", "Specifies the value of the identified parameter" { |var| noir_options[:set_pvalue] = var } parser.on "--include-path", "Include file path in the plain result" do diff --git a/src/output_builder/jsonl.cr b/src/output_builder/jsonl.cr new file mode 100644 index 00000000..49f1672f --- /dev/null +++ b/src/output_builder/jsonl.cr @@ -0,0 +1,10 @@ +require "../models/output_builder" +require "../models/endpoint" + +class OutputBuilderJsonl < OutputBuilder + def print(endpoints : Array(Endpoint)) + endpoints.each do |endpoint| + ob_puts endpoint.to_json + end + end +end From a7ab5fe39017d70d7156525df688e5a21a9238af Mon Sep 17 00:00:00 2001 From: HAHWUL Date: Fri, 12 Jan 2024 23:19:46 +0900 Subject: [PATCH 8/8] Release v0.12.1 --- shard.yml | 2 +- src/noir.cr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/shard.yml b/shard.yml index 6fef23a6..dbbed94d 100644 --- a/shard.yml +++ b/shard.yml @@ -1,5 +1,5 @@ name: noir -version: 0.12.0 +version: 0.12.1 authors: - hahwul diff --git a/src/noir.cr b/src/noir.cr index 6ed0f326..f81e141a 100644 --- a/src/noir.cr +++ b/src/noir.cr @@ -6,7 +6,7 @@ require "./options.cr" require "./techs/techs.cr" module Noir - VERSION = "0.12.0" + VERSION = "0.12.1" end noir_options = default_options()