From 90a50ed2d3e7037eb64856cc5c5b0861f2c6a6f6 Mon Sep 17 00:00:00 2001 From: HAHWUL Date: Fri, 1 Nov 2024 23:12:31 +0900 Subject: [PATCH 1/3] Refactor config initializer and options parser This commit refactors the `ConfigInitializer` class and the `run_options_parser` method in the `options.cr` file. In the `ConfigInitializer` class, the exception handling for creating the config file and reading the config file has been simplified. The previous code had unnecessary print statements and did not handle exceptions properly. Now, the code simply rescues any exception without printing any error messages. In the `options.cr` file, the case statements for generating completion scripts have been modified. The previous code printed instructions on how to save the completion scripts, but those instructions have been removed. Additionally, the `banner` method in the `noir.cr` file has been removed as it was not being used. These changes improve the readability and maintainability of the code. Signed-off-by: HAHWUL --- src/config_initializer.cr | 7 +------ src/noir.cr | 4 +--- src/options.cr | 4 +--- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/config_initializer.cr b/src/config_initializer.cr index fbebd191..797382d6 100644 --- a/src/config_initializer.cr +++ b/src/config_initializer.cr @@ -25,9 +25,7 @@ class ConfigInitializer # Create the config file if it doesn't exist File.write(@config_file, generate_config_file) unless File.exists?(@config_file) - rescue e : Exception - puts "Failed to create config directory or file: #{e.message}" - puts "Using default config." + rescue end def read_config @@ -71,9 +69,6 @@ class ConfigInitializer final_options = default_options.merge(symbolized_hash) { |_, _, new_val| new_val } final_options rescue e : Exception - puts "Failed to read config file: #{e.message}" - puts "Using default config." - default_options end end diff --git a/src/noir.cr b/src/noir.cr index cdbd7f46..31402f1a 100644 --- a/src/noir.cr +++ b/src/noir.cr @@ -9,9 +9,6 @@ module Noir VERSION = "0.18.0" end -# Print banner -banner() - # Run options parser noir_options = run_options_parser() @@ -57,6 +54,7 @@ if noir_options["exclude_codes"] != "" end # Run Noir +banner() app = NoirRunner.new noir_options start_time = Time.monotonic diff --git a/src/options.cr b/src/options.cr index 25c08a57..a5852121 100644 --- a/src/options.cr +++ b/src/options.cr @@ -133,13 +133,10 @@ def run_options_parser case var when "zsh" puts generate_zsh_completion_script - STDERR.puts "\n> Instructions: Copy the content above and save it in the zsh-completion directory as _noir".colorize(:yellow) when "bash" puts generate_bash_completion_script - STDERR.puts "\n> Instructions: Copy the content above and save it in the .bashrc file as noir.".colorize(:yellow) when "fish" puts generate_fish_completion_script - STDERR.puts "\n> Instructions: Copy the content above and save it in the fish-completion directory as noir.fish".colorize(:yellow) else puts "ERROR: Invalid completion type.".colorize(:yellow) puts "e.g., noir --generate-completion zsh" @@ -164,6 +161,7 @@ def run_options_parser end parser.separator "\n OTHERS:".colorize(:blue) parser.on "-h", "--help", "Show help" do + banner() puts parser puts "" puts "EXAMPLES:" From fc90c6f3af7284116c993705837bd6901719bcc8 Mon Sep 17 00:00:00 2001 From: HAHWUL Date: Fri, 1 Nov 2024 23:19:19 +0900 Subject: [PATCH 2/3] Refactor content matching logic in passive scan detection Signed-off-by: HAHWUL --- src/passive_scan/detect.cr | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/passive_scan/detect.cr b/src/passive_scan/detect.cr index 0862120f..b451d838 100644 --- a/src/passive_scan/detect.cr +++ b/src/passive_scan/detect.cr @@ -51,9 +51,17 @@ module NoirPassiveScan when "regex" case matcher.condition when "and" + begin matcher.patterns && matcher.patterns.all? { |pattern| content.match(Regex.new(pattern.to_s)) } + rescue + false + end when "or" + begin matcher.patterns && matcher.patterns.any? { |pattern| content.match(Regex.new(pattern.to_s)) } + rescue + false + end else false end From 196e3eb356d6fa8284c6f0be33bc06e6dd14c0f5 Mon Sep 17 00:00:00 2001 From: HAHWUL Date: Fri, 1 Nov 2024 23:20:34 +0900 Subject: [PATCH 3/3] Release v0.18.1 Signed-off-by: HAHWUL --- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- shard.yml | 2 +- snap/snapcraft.yaml | 2 +- src/noir.cr | 2 +- src/passive_scan/detect.cr | 6 +++--- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 12b53740..ef68e5b7 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -23,7 +23,7 @@ If applicable, add screenshots to help explain your problem. **Versions** - OS: [e.g. macos, linux] - - Version [e.g. v0.18.0] + - Version [e.g. v0.18.1] **Additional context** Add any other context about the problem here. diff --git a/shard.yml b/shard.yml index ae13032e..02a9853a 100644 --- a/shard.yml +++ b/shard.yml @@ -1,6 +1,6 @@ # Project Metadata name: noir -version: 0.18.0 +version: 0.18.1 authors: - hahwul - ksg97031 diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 419ed1cf..509ef861 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,6 +1,6 @@ name: noir base: core20 -version: 0.18.0 +version: 0.18.1 summary: Attack surface detector that identifies endpoints by static analysis. description: | Noir is an open-source project specializing in identifying attack surfaces for enhanced whitebox security testing and security pipeline. diff --git a/src/noir.cr b/src/noir.cr index 31402f1a..d4e1e712 100644 --- a/src/noir.cr +++ b/src/noir.cr @@ -6,7 +6,7 @@ require "./options.cr" require "./techs/techs.cr" module Noir - VERSION = "0.18.0" + VERSION = "0.18.1" end # Run options parser diff --git a/src/passive_scan/detect.cr b/src/passive_scan/detect.cr index b451d838..f2552f0d 100644 --- a/src/passive_scan/detect.cr +++ b/src/passive_scan/detect.cr @@ -52,13 +52,13 @@ module NoirPassiveScan case matcher.condition when "and" begin - matcher.patterns && matcher.patterns.all? { |pattern| content.match(Regex.new(pattern.to_s)) } + matcher.patterns && matcher.patterns.all? { |pattern| content.match(Regex.new(pattern.to_s)) } rescue false - end + end when "or" begin - matcher.patterns && matcher.patterns.any? { |pattern| content.match(Regex.new(pattern.to_s)) } + matcher.patterns && matcher.patterns.any? { |pattern| content.match(Regex.new(pattern.to_s)) } rescue false end