From 40b4d292286ad1ed433264be44e37563757585ca Mon Sep 17 00:00:00 2001 From: DastInDark <2350416+hitenkoku@users.noreply.github.com> Date: Sun, 25 Sep 2022 17:55:24 +0900 Subject: [PATCH 01/10] to add feature of version latest hayabusa version number renamed update rule --- src/options/{update_rules.rs => update.rs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/options/{update_rules.rs => update.rs} (100%) diff --git a/src/options/update_rules.rs b/src/options/update.rs similarity index 100% rename from src/options/update_rules.rs rename to src/options/update.rs From d015beda032786e6d80144d52870dbfc6979dbc8 Mon Sep 17 00:00:00 2001 From: DastInDark <2350416+hitenkoku@users.noreply.github.com> Date: Sun, 25 Sep 2022 18:01:46 +0900 Subject: [PATCH 02/10] refactoring --- src/options/mod.rs | 2 +- src/options/update.rs | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/options/mod.rs b/src/options/mod.rs index f63dd2b9..1f123528 100644 --- a/src/options/mod.rs +++ b/src/options/mod.rs @@ -1,3 +1,3 @@ pub mod level_tuning; pub mod profile; -pub mod update_rules; +pub mod update; diff --git a/src/options/update.rs b/src/options/update.rs index 6d501777..a740d88c 100644 --- a/src/options/update.rs +++ b/src/options/update.rs @@ -16,9 +16,9 @@ use std::fs::create_dir; use termcolor::{BufferWriter, ColorChoice}; -pub struct UpdateRules {} +pub struct Update {} -impl UpdateRules { +impl Update { /// update rules(hayabusa-rules subrepository) pub fn update_rules(rule_path: &str) -> Result { let mut result; @@ -35,14 +35,14 @@ impl UpdateRules { ) .ok(); // execution git clone of hayabusa-rules repository when failed open hayabusa repository. - result = UpdateRules::clone_rules(Path::new(rule_path)); + result = Update::clone_rules(Path::new(rule_path)); } else if hayabusa_rule_repo.is_ok() { // case of exist hayabusa-rules repository - UpdateRules::_repo_main_reset_hard(hayabusa_rule_repo.as_ref().unwrap())?; + Update::_repo_main_reset_hard(hayabusa_rule_repo.as_ref().unwrap())?; // case of failed fetching origin/main, git clone is not executed so network error has occurred possibly. - prev_modified_rules = UpdateRules::get_updated_rules(rule_path, &prev_modified_time); + prev_modified_rules = Update::get_updated_rules(rule_path, &prev_modified_time); prev_modified_time = fs::metadata(rule_path).unwrap().modified().unwrap(); - result = UpdateRules::pull_repository(&hayabusa_rule_repo.unwrap()); + result = Update::pull_repository(&hayabusa_rule_repo.unwrap()); } else { // case of no exist hayabusa-rules repository in rules. // execute update because submodule information exists if hayabusa repository exists submodule information. @@ -61,7 +61,7 @@ impl UpdateRules { for mut submodule in submodules { submodule.update(true, None)?; let submodule_repo = submodule.open()?; - if let Err(e) = UpdateRules::pull_repository(&submodule_repo) { + if let Err(e) = Update::pull_repository(&submodule_repo) { AlertMessage::alert(&format!("Failed submodule update. {}", e)).ok(); is_success_submodule_update = false; } @@ -80,13 +80,13 @@ impl UpdateRules { ) .ok(); // execution git clone of hayabusa-rules repository when failed open hayabusa repository. - result = UpdateRules::clone_rules(rules_path); + result = Update::clone_rules(rules_path); } } if result.is_ok() { let updated_modified_rules = - UpdateRules::get_updated_rules(rule_path, &prev_modified_time); - result = UpdateRules::print_diff_modified_rule_dates( + Update::get_updated_rules(rule_path, &prev_modified_time); + result = Update::print_diff_modified_rule_dates( prev_modified_rules, updated_modified_rules, ); @@ -254,7 +254,7 @@ impl UpdateRules { #[cfg(test)] mod tests { - use crate::options::update_rules::UpdateRules; + use crate::options::update::Update; use std::time::SystemTime; #[test] @@ -262,12 +262,12 @@ mod tests { let prev_modified_time: SystemTime = SystemTime::UNIX_EPOCH; let prev_modified_rules = - UpdateRules::get_updated_rules("test_files/rules/level_yaml", &prev_modified_time); + Update::get_updated_rules("test_files/rules/level_yaml", &prev_modified_time); assert_eq!(prev_modified_rules.len(), 5); let target_time: SystemTime = SystemTime::now(); let prev_modified_rules2 = - UpdateRules::get_updated_rules("test_files/rules/level_yaml", &target_time); + Update::get_updated_rules("test_files/rules/level_yaml", &target_time); assert_eq!(prev_modified_rules2.len(), 0); } } From 161f146eee5efdf7d1d558718bad096fd4027f50 Mon Sep 17 00:00:00 2001 From: DastInDark <2350416+hitenkoku@users.noreply.github.com> Date: Sun, 25 Sep 2022 19:01:15 +0900 Subject: [PATCH 03/10] to request at html hayabusa release page add cargo reqwest --- Cargo.lock | 245 +++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + 2 files changed, 246 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index e07add2c..638bbbfe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -262,6 +262,16 @@ version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbdcdcb6d86f71c5e97409ad45898af11cbc995b4ee8112d59095a28d376c935" +[[package]] +name = "core-foundation" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "core-foundation-sys" version = "0.8.3" @@ -508,6 +518,15 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a246d82be1c9d791c5dfde9a2bd045fc3cbba3fa2b11ad558f27d01712f00569" +[[package]] +name = "encoding_rs" +version = "0.8.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b" +dependencies = [ + "cfg-if", +] + [[package]] name = "env_logger" version = "0.7.1" @@ -659,6 +678,18 @@ version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4e5aa3de05362c3fb88de6531e6296e85cde7739cccad4b9dfeeb7f6ebce56bf" +[[package]] +name = "futures-io" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbf4d2a7a308fd4578637c0b17c7e1c7ba127b8f6ba00b29f717e9655d85eb68" + +[[package]] +name = "futures-sink" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b20ba5a92e727ba30e72834706623d94ac93a725410b6a6b6fbc1b07f7ba56" + [[package]] name = "futures-task" version = "0.3.24" @@ -672,9 +703,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90" dependencies = [ "futures-core", + "futures-io", "futures-task", + "memchr", "pin-project-lite", "pin-utils", + "slab", ] [[package]] @@ -709,6 +743,25 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" +[[package]] +name = "h2" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca32592cf21ac7ccab1825cd87f6c9b3d9022c44d086172ed0966bec8af30be" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "hashbrown" version = "0.12.3" @@ -752,6 +805,7 @@ dependencies = [ "quick-xml", "rand", "regex", + "reqwest", "serde", "serde_derive", "serde_json", @@ -846,18 +900,33 @@ dependencies = [ "futures-channel", "futures-core", "futures-util", + "h2", "http", "http-body", "httparse", "httpdate", "itoa 1.0.3", "pin-project-lite", + "socket2", "tokio", "tower-service", "tracing", "want", ] +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes", + "hyper", + "native-tls", + "tokio", + "tokio-native-tls", +] + [[package]] name = "iana-time-zone" version = "0.1.50" @@ -912,6 +981,12 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ea37f355c05dde75b84bba2d767906ad522e97cd9e2eef2be7a4ab7fb442c06" +[[package]] +name = "ipnet" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b" + [[package]] name = "is_elevated" version = "0.1.2" @@ -1107,6 +1182,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "mime" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" + [[package]] name = "miniz_oxide" version = "0.5.4" @@ -1128,6 +1209,24 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "native-tls" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd7e2f3618557f980e0b17e8856252eee3c97fa12c54dff0ca290fb6266ca4a9" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + [[package]] name = "nodrop" version = "0.1.14" @@ -1520,6 +1619,43 @@ dependencies = [ "winapi", ] +[[package]] +name = "reqwest" +version = "0.11.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "431949c384f4e2ae07605ccaa56d1d9d2ecdb5cadd4f9577ccfab29f2e5149fc" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "hyper", + "hyper-tls", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "serde", + "serde_json", + "serde_urlencoded", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", +] + [[package]] name = "rpmalloc" version = "0.2.2" @@ -1584,12 +1720,45 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "schannel" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" +dependencies = [ + "lazy_static", + "windows-sys", +] + [[package]] name = "scopeguard" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "security-framework" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bc1bb97804af6631813c55739f771071e0f2ed33ee20b68c86ec505d906356c" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "semver" version = "0.9.0" @@ -1645,6 +1814,18 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa 1.0.3", + "ryu", + "serde", +] + [[package]] name = "sha1" version = "0.6.1" @@ -1716,6 +1897,15 @@ dependencies = [ "walkdir", ] +[[package]] +name = "slab" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" +dependencies = [ + "autocfg", +] + [[package]] name = "smallvec" version = "1.9.0" @@ -2026,6 +2216,30 @@ dependencies = [ "syn", ] +[[package]] +name = "tokio-native-tls" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bb2e075f03b3d66d8d8785356224ba688d2906a371015e225beeb65ca92c740" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", + "tracing", +] + [[package]] name = "tower-service" version = "0.3.2" @@ -2175,6 +2389,18 @@ dependencies = [ "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23639446165ca5a5de86ae1d8896b737ae80319560fbaa4c2887b7da6e7ebd7d" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "wasm-bindgen-macro" version = "0.2.83" @@ -2204,6 +2430,16 @@ version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" +[[package]] +name = "web-sys" +version = "0.3.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "winapi" version = "0.3.9" @@ -2278,6 +2514,15 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" +[[package]] +name = "winreg" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" +dependencies = [ + "winapi", +] + [[package]] name = "winstructs" version = "0.3.0" diff --git a/Cargo.toml b/Cargo.toml index 20401c76..8c6df239 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,6 +39,7 @@ lock_api = "0.4.*" crossbeam-utils = "0.8.*" num-format = "*" comfy-table = "6.*" +reqwest = {version = "0.11.*", features = ["blocking", "json"]} [build-dependencies] static_vcruntime = "2.*" From 58ec9001f823042e28b08515e962d6810c3cb403 Mon Sep 17 00:00:00 2001 From: DastInDark <2350416+hitenkoku@users.noreply.github.com> Date: Sun, 25 Sep 2022 19:02:34 +0900 Subject: [PATCH 04/10] added version check function. --- src/main.rs | 28 ++++++++++++++++++++++++++-- src/options/update.rs | 11 +++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5da1b162..6a6539c3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,7 +19,7 @@ use hayabusa::detections::pivot::PIVOT_KEYWORD; use hayabusa::detections::rule::{get_detection_keys, RuleNode}; use hayabusa::omikuji::Omikuji; use hayabusa::options::profile::PROFILES; -use hayabusa::options::{level_tuning::LevelTuning, update_rules::UpdateRules}; +use hayabusa::options::{level_tuning::LevelTuning, update::Update}; use hayabusa::{afterfact::after_fact, detections::utils}; use hayabusa::{detections::configs, timeline::timelines::Timeline}; use hayabusa::{detections::utils::write_color_buffer, filter}; @@ -118,7 +118,31 @@ impl App { } if configs::CONFIG.read().unwrap().args.update_rules { - match UpdateRules::update_rules( + // エラーが出た場合はインターネット接続がそもそもできないなどの問題点もあるためエラー等の出力は行わない + let latest_version_data = if let Ok(data) = Update::get_latest_hayabusa_version(){ + data + } else { + None + }; + let now_version = configs::CONFIG.read().unwrap().app.get_version().unwrap(); + if latest_version_data.is_some() && now_version != latest_version_data.as_ref().unwrap_or(&now_version.to_string()) { + write_color_buffer( + &BufferWriter::stdout(ColorChoice::Always), + None, + &format!("There is a new version of Hayabusa: {}", latest_version_data.unwrap()), + true, + ) + .ok(); + write_color_buffer( + &BufferWriter::stdout(ColorChoice::Always), + None, + "You can download it at https://github.com/Yamato-Security/hayabusa/releases", + true, + ) + .ok(); + } + + match Update::update_rules( configs::CONFIG.read().unwrap().args.rules.to_str().unwrap(), ) { Ok(output) => { diff --git a/src/options/update.rs b/src/options/update.rs index a740d88c..ebaf2b6b 100644 --- a/src/options/update.rs +++ b/src/options/update.rs @@ -19,6 +19,17 @@ use termcolor::{BufferWriter, ColorChoice}; pub struct Update {} impl Update { + + /// get latest hayabusa version number. + pub fn get_latest_hayabusa_version() -> Result, Box> { + let res = reqwest::blocking::get("https://api.github.com/repos/Yamato-Security/hayabusa/releases/latest")?.json::>()?; + if let Some(o) = res.get("tag_name") { + Ok(Some(o.to_owned())) + } else { + Ok(None) + } + } + /// update rules(hayabusa-rules subrepository) pub fn update_rules(rule_path: &str) -> Result { let mut result; From 608f6a18df79537a3d0dd6cb1e462ac4c3d44876 Mon Sep 17 00:00:00 2001 From: DastInDark <2350416+hitenkoku@users.noreply.github.com> Date: Sun, 25 Sep 2022 19:03:10 +0900 Subject: [PATCH 05/10] cargo fmt --- src/main.rs | 21 ++++++++++++++------- src/options/update.rs | 15 +++++++-------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6a6539c3..59d731e4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -119,17 +119,25 @@ impl App { if configs::CONFIG.read().unwrap().args.update_rules { // エラーが出た場合はインターネット接続がそもそもできないなどの問題点もあるためエラー等の出力は行わない - let latest_version_data = if let Ok(data) = Update::get_latest_hayabusa_version(){ + let latest_version_data = if let Ok(data) = Update::get_latest_hayabusa_version() { data } else { None }; let now_version = configs::CONFIG.read().unwrap().app.get_version().unwrap(); - if latest_version_data.is_some() && now_version != latest_version_data.as_ref().unwrap_or(&now_version.to_string()) { + if latest_version_data.is_some() + && now_version + != latest_version_data + .as_ref() + .unwrap_or(&now_version.to_string()) + { write_color_buffer( &BufferWriter::stdout(ColorChoice::Always), None, - &format!("There is a new version of Hayabusa: {}", latest_version_data.unwrap()), + &format!( + "There is a new version of Hayabusa: {}", + latest_version_data.unwrap() + ), true, ) .ok(); @@ -141,10 +149,9 @@ impl App { ) .ok(); } - - match Update::update_rules( - configs::CONFIG.read().unwrap().args.rules.to_str().unwrap(), - ) { + + match Update::update_rules(configs::CONFIG.read().unwrap().args.rules.to_str().unwrap()) + { Ok(output) => { if output != "You currently have the latest rules." { write_color_buffer( diff --git a/src/options/update.rs b/src/options/update.rs index ebaf2b6b..61d19180 100644 --- a/src/options/update.rs +++ b/src/options/update.rs @@ -19,10 +19,12 @@ use termcolor::{BufferWriter, ColorChoice}; pub struct Update {} impl Update { - /// get latest hayabusa version number. pub fn get_latest_hayabusa_version() -> Result, Box> { - let res = reqwest::blocking::get("https://api.github.com/repos/Yamato-Security/hayabusa/releases/latest")?.json::>()?; + let res = reqwest::blocking::get( + "https://api.github.com/repos/Yamato-Security/hayabusa/releases/latest", + )? + .json::>()?; if let Some(o) = res.get("tag_name") { Ok(Some(o.to_owned())) } else { @@ -95,12 +97,9 @@ impl Update { } } if result.is_ok() { - let updated_modified_rules = - Update::get_updated_rules(rule_path, &prev_modified_time); - result = Update::print_diff_modified_rule_dates( - prev_modified_rules, - updated_modified_rules, - ); + let updated_modified_rules = Update::get_updated_rules(rule_path, &prev_modified_time); + result = + Update::print_diff_modified_rule_dates(prev_modified_rules, updated_modified_rules); } result } From d0ebe4b74d00c3bd1d46d1339bdac94f50fbf12b Mon Sep 17 00:00:00 2001 From: DastInDark <2350416+hitenkoku@users.noreply.github.com> Date: Sun, 25 Sep 2022 20:49:37 +0900 Subject: [PATCH 06/10] fixed cargo crate --- Cargo.lock | 63 +++--------------------------------------------------- 1 file changed, 3 insertions(+), 60 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 638bbbfe..e268df93 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -251,7 +251,7 @@ dependencies = [ "encode_unicode 0.3.6", "libc", "once_cell", - "terminal_size 0.1.17", + "terminal_size", "unicode-width", "winapi", ] @@ -540,27 +540,6 @@ dependencies = [ "termcolor", ] -[[package]] -name = "errno" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" -dependencies = [ - "errno-dragonfly", - "libc", - "winapi", -] - -[[package]] -name = "errno-dragonfly" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" -dependencies = [ - "cc", - "libc", -] - [[package]] name = "error-chain" version = "0.12.4" @@ -811,7 +790,7 @@ dependencies = [ "serde_json", "static_vcruntime", "termcolor", - "terminal_size 0.2.1", + "terminal_size", "tokio", "yaml-rust", ] @@ -975,12 +954,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "io-lifetimes" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ea37f355c05dde75b84bba2d767906ad522e97cd9e2eef2be7a4ab7fb442c06" - [[package]] name = "ipnet" version = "2.5.0" @@ -1072,7 +1045,7 @@ dependencies = [ "rayon", "regex", "tempfile", - "terminal_size 0.1.17", + "terminal_size", ] [[package]] @@ -1133,12 +1106,6 @@ version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" -[[package]] -name = "linux-raw-sys" -version = "0.0.46" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4d2456c373231a208ad294c33dc5bff30051eafd954cd4caae83a712b12854d" - [[package]] name = "lock_api" version = "0.4.9" @@ -1685,20 +1652,6 @@ dependencies = [ "semver 0.9.0", ] -[[package]] -name = "rustix" -version = "0.35.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af895b90e5c071badc3136fc10ff0bcfc98747eadbaf43ed8f214e07ba8f8477" -dependencies = [ - "bitflags", - "errno", - "io-lifetimes", - "libc", - "linux-raw-sys", - "windows-sys", -] - [[package]] name = "rustversion" version = "1.0.9" @@ -2066,16 +2019,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "terminal_size" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8440c860cf79def6164e4a0a983bcc2305d82419177a0e0c71930d049e3ac5a1" -dependencies = [ - "rustix", - "windows-sys", -] - [[package]] name = "textwrap" version = "0.15.1" From 1abaf48d934f6765dfde3eb74cfb9b0d71521627 Mon Sep 17 00:00:00 2001 From: DastInDark <2350416+hitenkoku@users.noreply.github.com> Date: Sun, 25 Sep 2022 20:50:03 +0900 Subject: [PATCH 07/10] fixed get function of latest hayabusa version data #710 --- src/main.rs | 6 +++--- src/options/update.rs | 17 +++++++++++------ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index 59d731e4..c30bcbdb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -124,19 +124,19 @@ impl App { } else { None }; - let now_version = configs::CONFIG.read().unwrap().app.get_version().unwrap(); + let now_version = &format!("v{}",configs::CONFIG.read().unwrap().app.get_version().unwrap()); if latest_version_data.is_some() && now_version != latest_version_data .as_ref() - .unwrap_or(&now_version.to_string()) + .unwrap_or(now_version) { write_color_buffer( &BufferWriter::stdout(ColorChoice::Always), None, &format!( "There is a new version of Hayabusa: {}", - latest_version_data.unwrap() + latest_version_data.unwrap().replace('\"',"") ), true, ) diff --git a/src/options/update.rs b/src/options/update.rs index 61d19180..97d3fee5 100644 --- a/src/options/update.rs +++ b/src/options/update.rs @@ -1,3 +1,4 @@ +use serde_json::Value; use crate::detections::message::AlertMessage; use crate::detections::utils::write_color_buffer; use crate::filter; @@ -21,15 +22,19 @@ pub struct Update {} impl Update { /// get latest hayabusa version number. pub fn get_latest_hayabusa_version() -> Result, Box> { - let res = reqwest::blocking::get( + let res = reqwest::blocking::Client::new().get( "https://api.github.com/repos/Yamato-Security/hayabusa/releases/latest", - )? - .json::>()?; - if let Some(o) = res.get("tag_name") { - Ok(Some(o.to_owned())) - } else { + ).header("User-Agent", "HayabusaUpdateChecker") + .header("Accept", "application/vnd.github.v3+json").send()?; + let text = res.text()?; + let json_res:Value = serde_json::from_str(&text)?; + + if json_res["tag_name"].is_null() { Ok(None) + } else { + Ok(Some(json_res["tag_name"].to_string())) } + } /// update rules(hayabusa-rules subrepository) From 703673c6683c7388c64a5b9179c4b06a722aca25 Mon Sep 17 00:00:00 2001 From: DastInDark <2350416+hitenkoku@users.noreply.github.com> Date: Sun, 25 Sep 2022 20:51:18 +0900 Subject: [PATCH 08/10] cargo fmt --- src/main.rs | 12 ++++++------ src/options/update.rs | 16 ++++++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main.rs b/src/main.rs index c30bcbdb..5392b339 100644 --- a/src/main.rs +++ b/src/main.rs @@ -124,19 +124,19 @@ impl App { } else { None }; - let now_version = &format!("v{}",configs::CONFIG.read().unwrap().app.get_version().unwrap()); + let now_version = &format!( + "v{}", + configs::CONFIG.read().unwrap().app.get_version().unwrap() + ); if latest_version_data.is_some() - && now_version - != latest_version_data - .as_ref() - .unwrap_or(now_version) + && now_version != latest_version_data.as_ref().unwrap_or(now_version) { write_color_buffer( &BufferWriter::stdout(ColorChoice::Always), None, &format!( "There is a new version of Hayabusa: {}", - latest_version_data.unwrap().replace('\"',"") + latest_version_data.unwrap().replace('\"', "") ), true, ) diff --git a/src/options/update.rs b/src/options/update.rs index 97d3fee5..0fa81367 100644 --- a/src/options/update.rs +++ b/src/options/update.rs @@ -1,10 +1,10 @@ -use serde_json::Value; use crate::detections::message::AlertMessage; use crate::detections::utils::write_color_buffer; use crate::filter; use crate::yaml::ParseYaml; use chrono::{DateTime, Local, TimeZone}; use git2::Repository; +use serde_json::Value; use std::fs::{self}; use std::path::Path; @@ -22,19 +22,19 @@ pub struct Update {} impl Update { /// get latest hayabusa version number. pub fn get_latest_hayabusa_version() -> Result, Box> { - let res = reqwest::blocking::Client::new().get( - "https://api.github.com/repos/Yamato-Security/hayabusa/releases/latest", - ).header("User-Agent", "HayabusaUpdateChecker") - .header("Accept", "application/vnd.github.v3+json").send()?; + let res = reqwest::blocking::Client::new() + .get("https://api.github.com/repos/Yamato-Security/hayabusa/releases/latest") + .header("User-Agent", "HayabusaUpdateChecker") + .header("Accept", "application/vnd.github.v3+json") + .send()?; let text = res.text()?; - let json_res:Value = serde_json::from_str(&text)?; + let json_res: Value = serde_json::from_str(&text)?; if json_res["tag_name"].is_null() { Ok(None) - } else { + } else { Ok(Some(json_res["tag_name"].to_string())) } - } /// update rules(hayabusa-rules subrepository) From d7c678e023d3a4030a99ee6fe83e66a0c6d721df Mon Sep 17 00:00:00 2001 From: DastInDark <2350416+hitenkoku@users.noreply.github.com> Date: Sun, 25 Sep 2022 20:54:30 +0900 Subject: [PATCH 09/10] updated changelog #710 --- CHANGELOG-Japanese.md | 4 +++- CHANGELOG.md | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG-Japanese.md b/CHANGELOG-Japanese.md index 296b665b..a4230cb0 100644 --- a/CHANGELOG-Japanese.md +++ b/CHANGELOG-Japanese.md @@ -1,11 +1,13 @@ # 変更点 -## 1.x.x [2022/XX/XX] +## 1.7.0 [2022/XX/XX] **新機能:** **改善:** +- ルール更新オプション(`-u`)を利用したときにHayabusaの新バージョンがないかを確認し、表示するようにした。 (#710) (@hitenkoku) + **バグ修正:** ## v1.6.0 [2022/09/16] diff --git a/CHANGELOG.md b/CHANGELOG.md index 52eb2549..5d79c130 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,13 @@ # Changes -## 1.x.x [2022/XX/XX] +## 1.7.0 [2022/XX/XX] **New Features:** **Enhancements:** +- Added display new version of Hayabusa when updating. (#710) (@hitenkoku) + **Bug Fixes:** ## v1.6.0 [2022/09/16] From e62e5fa6f6f58068ec168b0a4ecb63309ff2fc46 Mon Sep 17 00:00:00 2001 From: DastInDark <2350416+hitenkoku@users.noreply.github.com> Date: Mon, 26 Sep 2022 19:25:43 +0900 Subject: [PATCH 10/10] changed output new version hayabusa data --- src/main.rs | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/src/main.rs b/src/main.rs index d1e384ce..981ff7c9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -128,27 +128,6 @@ impl App { "v{}", configs::CONFIG.read().unwrap().app.get_version().unwrap() ); - if latest_version_data.is_some() - && now_version != latest_version_data.as_ref().unwrap_or(now_version) - { - write_color_buffer( - &BufferWriter::stdout(ColorChoice::Always), - None, - &format!( - "There is a new version of Hayabusa: {}", - latest_version_data.unwrap().replace('\"', "") - ), - true, - ) - .ok(); - write_color_buffer( - &BufferWriter::stdout(ColorChoice::Always), - None, - "You can download it at https://github.com/Yamato-Security/hayabusa/releases", - true, - ) - .ok(); - } match Update::update_rules(configs::CONFIG.read().unwrap().args.rules.to_str().unwrap()) { @@ -168,6 +147,33 @@ impl App { } } println!(); + if latest_version_data.is_some() + && now_version + != &latest_version_data + .as_ref() + .unwrap_or(now_version) + .replace('\"', "") + { + write_color_buffer( + &BufferWriter::stdout(ColorChoice::Always), + None, + &format!( + "There is a new version of Hayabusa: {}", + latest_version_data.unwrap().replace('\"', "") + ), + true, + ) + .ok(); + write_color_buffer( + &BufferWriter::stdout(ColorChoice::Always), + None, + "You can download it at https://github.com/Yamato-Security/hayabusa/releases", + true, + ) + .ok(); + } + println!(); + return; } // 実行時のexeファイルのパスをベースに変更する必要があるためデフォルトの値であった場合はそのexeファイルと同一階層を探すようにする