diff --git a/.ameba.yml b/.ameba.yml index 98636018..5b4bc8b1 100644 --- a/.ameba.yml +++ b/.ameba.yml @@ -6,3 +6,10 @@ Metrics/CyclomaticComplexity: MaxComplexity: 40 Enabled: true Severity: Warning + +Lint/RedundantWithIndex: + Enabled: false + +Lint/UnusedArgument: + Excluded: + - "src/analyzer/analyzers/analyzer_example.cr" \ No newline at end of file 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/shard.yml b/shard.yml index 29cb8903..dbbed94d 100644 --- a/shard.yml +++ b/shard.yml @@ -1,8 +1,9 @@ name: noir -version: 0.12.0 +version: 0.12.1 authors: - hahwul + - ksg97031 targets: noir: diff --git a/spec/unit_test/models/output_builder_spec.cr b/spec/unit_test/models/output_builder_spec.cr index fe35ab90..ddebdd8b 100644 --- a/spec/unit_test/models/output_builder_spec.cr +++ b/spec/unit_test/models/output_builder_spec.cr @@ -41,4 +41,29 @@ 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 + + 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 + + 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 46d9e014..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 @@ -173,6 +176,18 @@ class NoirRunner when "oas3" buidler = OutputBuilderOas3.new @options buidler.print @endpoints + 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 83b32965..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() @@ -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 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 @@ -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 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 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 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