diff --git a/.gitignore b/.gitignore index 5f5eab193..de3ebd698 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ /target/ tests/create_file_dll/target/ tests/create_file_dll/Cargo.lock -cmd/implants/eldritch/target/ +cmd/implants/lib/eldritch/target/ cmd/implants/target/ cmd/implants/Cargo.lock diff --git a/docs/_docs/dev-guide/eldritch.md b/docs/_docs/dev-guide/eldritch.md index b0ba9b9cd..40e0e189b 100644 --- a/docs/_docs/dev-guide/eldritch.md +++ b/docs/_docs/dev-guide/eldritch.md @@ -49,7 +49,7 @@ The module.function describe your function and edge cases. ``` #### Eldritch definition -`implants/Eldritch/src/module.rs` +`implants/lib/eldritch/src/module.rs` Add a function definition here, where `module.rs` is the name of the module you selected above. This is how the Eldritch language is made aware that your function exists. Add the import for your functions implementation at the top, try to keep these in alphabetical order for readability. @@ -76,7 +76,7 @@ You may notice that some functions follow the pattern: This pattern is only used for none type returns since we're returning Starlark None. Returning like this in the module file is more streamlined than having each module return a special starlark type. ### Eldritch Implementation -`implants/Eldritch/src/module/function_impl.rs` +`implants/lib/eldritch/src/module/function_impl.rs` Add your function implementation here, where `/module/` is the name of the module you selected above and `/function_impl.rs` is the name of your function with `_impl.rs` appended after it. This should match what's been put in the module file. This file will contain the actual implementation, helper functions, and unit tests for your function. diff --git a/implants/Cargo.toml b/implants/Cargo.toml index 8d8366135..ac4a4b12c 100644 --- a/implants/Cargo.toml +++ b/implants/Cargo.toml @@ -1,11 +1,56 @@ [workspace] members = [ "imix", - "eldritch", "golem", - "pkg/tavern", + "lib/eldritch", + "lib/tavern", ] +[workspace.dependencies] +allocative = { git = "https://github.com/facebookexperimental/starlark-rust", rev = "acf638430a00ca3855862e8c669670e1adaa42aa" } +allocative_derive = { git = "https://github.com/facebookexperimental/starlark-rust", rev = "acf638430a00ca3855862e8c669670e1adaa42aa" } +anyhow = "1.0.65" +assert_cmd = "2.0.6" +async-recursion = "1.0.0" +async-trait = "0.1.68" +chrono = "0.4.24" +clap = "3.2.23" +default-net = "0.13.1" +derive_more = "0.99.17" +eldritch = { path = "./lib/eldritch" } +eval = "0.4.3" +flate2 = "1.0.24" +gazebo = "0.8.1" +graphql_client = "0.12.0" +httptest = "0.15.4" +itertools = "0.10" +lsp-types = "0.93.0" +nix = "0.26.1" +openssl = "0.10" +predicates = "2.1" +rand = "0.8.5" +regex = "1.5.5" +reqwest = "0.11.4" +rust-embed = "6.6.0" +serde = "1.0" +serde_json = "1.0.87" +sha256 = "1.0.3" +starlark = { git = "https://github.com/facebookexperimental/starlark-rust", rev = "acf638430a00ca3855862e8c669670e1adaa42aa" } +structopt = "0.3.23" +sys-info = "0.9.1" +sysinfo = "0.28.4" +tar = "0.4.38" +tavern = { path = "./lib/tavern" } +tempfile = "3.3.0" +tera = "1.17.1" +thiserror = "1.0.30" +tokio = "1.19.1" +tokio-stream = "0.1.9" +tokio-test = "*" +uuid = "1.3.0" +whoami = "1.3.0" +windows-sys = "0.45.0" + [profile.release] strip = true # Automatically strip symbols from the binary. opt-level = "z" # Optimize for size. diff --git a/implants/eldritch/Cargo.toml b/implants/eldritch/Cargo.toml deleted file mode 100644 index 61552daae..000000000 --- a/implants/eldritch/Cargo.toml +++ /dev/null @@ -1,40 +0,0 @@ -[package] -name = "eldritch" -version = "0.1.0" -edition = "2021" - -[dependencies] -starlark = { git = "https://github.com/facebookexperimental/starlark-rust", rev = "acf638430a00ca3855862e8c669670e1adaa42aa" } -allocative = { git = "https://github.com/facebookexperimental/starlark-rust", rev = "acf638430a00ca3855862e8c669670e1adaa42aa" } -allocative_derive = { git = "https://github.com/facebookexperimental/starlark-rust", rev = "acf638430a00ca3855862e8c669670e1adaa42aa" } -tempfile = "3.3.0" -anyhow = "1.0.65" -derive_more = "0.99.17" -sha256 = "1.0.3" -sysinfo = "0.28.4" -regex = "1.5.5" -reqwest = { version = "0.11.0" , features = ["blocking", "stream"] } -httptest = "0.15.4" -tokio = { version = "1.19.1" , features = ["macros", "rt-multi-thread"] } -async-recursion = "1.0.0" -tokio-stream = "0.1.9" -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" -flate2 = "1.0.24" -tar = "0.4.38" -tera = "1.17.1" -gazebo = "0.8.1" -nix = "0.26.1" -eval = "0.4.3" -rust-embed="6.6.0" - -[dependencies.windows-sys] -version = "0.45.0" -features = [ - "Win32_Foundation", - "Win32_System_LibraryLoader", - "Win32_System_Threading", - "Win32_System_Memory", - "Win32_System_Diagnostics_Debug", - "Win32_Security", -] diff --git a/implants/eldritch/rust-toolchain b/implants/eldritch/rust-toolchain deleted file mode 100644 index a2339e003..000000000 --- a/implants/eldritch/rust-toolchain +++ /dev/null @@ -1,2 +0,0 @@ -[toolchain] -channel = "nightly-2023-03-29" diff --git a/implants/golem/Cargo.toml b/implants/golem/Cargo.toml index d256db696..94060bc9c 100644 --- a/implants/golem/Cargo.toml +++ b/implants/golem/Cargo.toml @@ -4,21 +4,21 @@ version = "0.1.0" edition = "2021" [dependencies] -eldritch = { path = "../eldritch" } -tokio = { version = "1.19.1" , features = ["macros"] } -clap = { version = "3.2.23" } -starlark = { git = "https://github.com/facebookexperimental/starlark-rust", rev = "acf638430a00ca3855862e8c669670e1adaa42aa" } -anyhow = "1.0.65" -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0.87" -structopt = "0.3.23" -gazebo = "0.8.1" -itertools = "0.10" -thiserror = "1.0.30" -lsp-types = "0.93.0" -rust-embed = { version = "6.6.0" } +eldritch = { workspace = true } +tokio = { workspace = true, features = ["macros"] } +clap = { workspace = true } +starlark = { workspace = true } +anyhow = { workspace = true } +serde = { workspace = true, features = ["derive"] } +serde_json = { workspace = true } +structopt = { workspace = true } +gazebo = { workspace = true } +itertools = { workspace = true } +thiserror = { workspace = true } +lsp-types = { workspace = true } +rust-embed = { workspace = true } [dev-dependencies] -assert_cmd = "2.0.6" -predicates = "2.1" -tempfile = "3.3.0" +assert_cmd = { workspace = true } +predicates = { workspace = true} +tempfile = { workspace = true } diff --git a/implants/golem/rust-toolchain b/implants/golem/rust-toolchain deleted file mode 100644 index e317e9277..000000000 --- a/implants/golem/rust-toolchain +++ /dev/null @@ -1,2 +0,0 @@ -[toolchain] -channel = "nightly-2022-11-03" \ No newline at end of file diff --git a/implants/golem/tests/cli.rs b/implants/golem/tests/cli.rs index afd7489c4..3452be463 100644 --- a/implants/golem/tests/cli.rs +++ b/implants/golem/tests/cli.rs @@ -30,7 +30,7 @@ fn test_golem_main_syntax_fail() -> anyhow::Result<()> { cmd.arg("../../tests/golem_cli_test/syntax_fail.tome"); cmd.assert() .failure() - .stderr(predicate::str::contains("[TASK ERROR] ../../tests/golem_cli_test/syntax_fail.tome: error: Parse error: unexpected string literal 'win' here")); + .stderr(predicate::str::contains("[TASK ERROR] ../../tests/golem_cli_test/syntax_fail.tome: [eldritch] Unable to parse eldritch tome: error: Parse error: unexpected string literal \'win\' here")); Ok(()) } diff --git a/implants/imix/Cargo.toml b/implants/imix/Cargo.toml index 70c0780b5..238b72e2f 100644 --- a/implants/imix/Cargo.toml +++ b/implants/imix/Cargo.toml @@ -4,22 +4,22 @@ version = "0.1.0" edition = "2021" [dependencies] -eldritch = { path = "../eldritch" } -clap = { version = "3.0" } -rand = "0.8.5" -openssl = { version = "0.10", features = ["vendored"] } -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" -reqwest = { version = "0.11.4" , features = ["blocking", "stream", "json"] } -tokio = { version = "1", features = ["full"] } -anyhow = "1.0.65" -chrono = { version = "0.4.23" , features = ["serde"] } -whoami = "1.3.0" -uuid = { version = "1.3.0", features = ["v4","fast-rng"] } -default-net = "0.13.1" -sys-info = "0.9.1" -tavern = { path = "../pkg/tavern" } +anyhow = { workspace = true } +chrono = { workspace = true , features = ["serde"] } +clap = { workspace = true } +default-net = { workspace = true } +eldritch = { workspace = true } +openssl = { workspace = true, features = ["vendored"] } +rand = {workspace = true} +reqwest = { workspace = true, features = ["blocking", "stream", "json"] } +serde = { workspace = true, features = ["derive"] } +serde_json = {workspace = true} +sys-info = { workspace = true } +tavern = { workspace = true } +tokio = { workspace = true, features = ["full"] } +uuid = { workspace = true, features = ["v4","fast-rng"] } +whoami = { workspace = true } [dev-dependencies] -httptest = "0.15.4" -tempfile = "3.3.0" +httptest = { workspace = true } +tempfile = { workspace = true } diff --git a/implants/imix/rust-toolchain b/implants/imix/rust-toolchain deleted file mode 100644 index e317e9277..000000000 --- a/implants/imix/rust-toolchain +++ /dev/null @@ -1,2 +0,0 @@ -[toolchain] -channel = "nightly-2022-11-03" \ No newline at end of file diff --git a/implants/imix/src/main.rs b/implants/imix/src/main.rs index 33931c676..b302c0228 100644 --- a/implants/imix/src/main.rs +++ b/implants/imix/src/main.rs @@ -329,22 +329,26 @@ async fn main_loop(config_path: String, run_once: bool) -> Result<()> { res.push(new_res_line); // Send task response } - let task_response_exec_finished_at = match exec_future.1.future_join_handle.is_finished() { + let task_is_finished = exec_future.1.future_join_handle.is_finished(); + let task_response_exec_finished_at = match task_is_finished { true => Some(Utc::now()), false => None, }; - let task_response = SubmitTaskResultInput { - task_id: exec_future.1.graphql_task.id.clone(), - exec_started_at: exec_future.1.start_time, - exec_finished_at: task_response_exec_finished_at, - output: res.join("\n"), - error: None, - }; - let res = tavern_client.submit_task_result(task_response).await; - let _submit_task_result = match res { - Ok(local_val) => local_val, - Err(local_err) => if debug { println!("Failed to submit task resluts:\n{}", local_err.to_string()) }, - }; + // If the task is finished or there's new data send a task_result. + if task_is_finished || res.len() > 0 { + let task_response = SubmitTaskResultInput { + task_id: exec_future.1.graphql_task.id.clone(), + exec_started_at: exec_future.1.start_time, + exec_finished_at: task_response_exec_finished_at, + output: res.join("\n"), + error: None, + }; + let res = tavern_client.submit_task_result(task_response).await; + let _submit_task_result = match res { + Ok(local_val) => local_val, + Err(local_err) => if debug { println!("Failed to submit task resluts:\n{}", local_err.to_string()) }, + }; + } // Only re-insert the runnine exec futures if !exec_future.1.future_join_handle.is_finished() { @@ -380,6 +384,7 @@ pub fn main() -> Result<(), imix::Error> { let runtime = tokio::runtime::Builder::new_multi_thread() + .worker_threads(128) .enable_all() .build() .unwrap(); diff --git a/implants/lib/README.md b/implants/lib/README.md new file mode 100644 index 000000000..56429b5e6 --- /dev/null +++ b/implants/lib/README.md @@ -0,0 +1,3 @@ +# Overview + +Code shared by multiple implants can be defined in the `lib` folder. diff --git a/implants/eldritch/.gitignore b/implants/lib/eldritch/.gitignore similarity index 100% rename from implants/eldritch/.gitignore rename to implants/lib/eldritch/.gitignore diff --git a/implants/lib/eldritch/Cargo.toml b/implants/lib/eldritch/Cargo.toml new file mode 100644 index 000000000..e88517c0a --- /dev/null +++ b/implants/lib/eldritch/Cargo.toml @@ -0,0 +1,39 @@ +[package] +name = "eldritch" +version = "0.1.0" +edition = "2021" + +[dependencies] +allocative = { workspace = true } +allocative_derive = { workspace = true } +anyhow = { workspace = true } +async-recursion = { workspace = true } +derive_more = { workspace = true } +eval = { workspace = true } +flate2 = { workspace = true } +gazebo = { workspace = true } +nix = { workspace = true } +regex = { workspace = true } +reqwest = { workspace = true , features = ["blocking", "stream"] } +rust-embed = { workspace = true } +serde = { version = "1.0", features = ["derive"] } +serde_json = { workspace = true } +sha256 = { workspace = true } +starlark = { workspace = true } +sysinfo = { workspace = true } +tar = { workspace = true } +tempfile = { workspace = true } +tera = { workspace = true } +tokio = { workspace = true , features = ["macros", "rt-multi-thread"] } +tokio-stream = { workspace = true } +windows-sys = { workspace = true, features = [ + "Win32_Foundation", + "Win32_System_LibraryLoader", + "Win32_System_Threading", + "Win32_System_Memory", + "Win32_System_Diagnostics_Debug", + "Win32_Security", +]} + +[dev-dependencies] +httptest = { workspace = true } diff --git a/implants/eldritch/README.md b/implants/lib/eldritch/README.md similarity index 50% rename from implants/eldritch/README.md rename to implants/lib/eldritch/README.md index 0cca28a54..9f26f14bd 100644 --- a/implants/eldritch/README.md +++ b/implants/lib/eldritch/README.md @@ -1,10 +1,10 @@ # Build ``` -cd ./implants/eldritch/ +cd ./implants/lib/eldritch/ cargo build ``` # Test ``` -cd ./implants/eldritch/ +cd ./implants/lib/eldritch/ cargo test ``` diff --git a/implants/eldritch/build.rs b/implants/lib/eldritch/build.rs similarity index 86% rename from implants/eldritch/build.rs rename to implants/lib/eldritch/build.rs index 40ae0c7c8..6b0b3a53a 100644 --- a/implants/eldritch/build.rs +++ b/implants/lib/eldritch/build.rs @@ -9,7 +9,7 @@ fn build_tests_create_file_dll(){ // Get the path of the create_file_dll workspace member let cargo_root = env!("CARGO_MANIFEST_DIR"); - let relative_path_to_test_dll = "..\\..\\tests\\create_file_dll\\"; + let relative_path_to_test_dll = "..\\..\\..\\tests\\create_file_dll\\"; let test_dll_path = Path::new(cargo_root).join(relative_path_to_test_dll); assert!(test_dll_path.is_dir()); @@ -25,7 +25,7 @@ fn build_tests_create_file_dll(){ .filter_map(|line| line.ok()) .for_each(|line| println!("cargo dll build: {}", line)); - let relative_path_to_test_dll_file = "..\\..\\tests\\create_file_dll\\target\\debug\\create_file_dll.dll"; + let relative_path_to_test_dll_file = "..\\..\\..\\tests\\create_file_dll\\target\\debug\\create_file_dll.dll"; let test_dll_path = Path::new(cargo_root).join(relative_path_to_test_dll_file); assert!(test_dll_path.is_file()); } diff --git a/implants/eldritch/src/assets.rs b/implants/lib/eldritch/src/assets.rs similarity index 94% rename from implants/eldritch/src/assets.rs rename to implants/lib/eldritch/src/assets.rs index c10621a40..064385afc 100644 --- a/implants/eldritch/src/assets.rs +++ b/implants/lib/eldritch/src/assets.rs @@ -14,12 +14,12 @@ use rust_embed::RustEmbed; #[cfg(debug_assertions)] #[derive(RustEmbed)] -#[folder = "../../tests/embedded_files_test"] +#[folder = "../../../tests/embedded_files_test"] pub struct Asset; #[cfg(not(debug_assertions))] #[derive(RustEmbed)] -#[folder = "../../implants/golem/embed_files_golem_prod"] +#[folder = "../../../implants/golem/embed_files_golem_prod"] pub struct Asset; diff --git a/implants/eldritch/src/assets/copy_impl.rs b/implants/lib/eldritch/src/assets/copy_impl.rs similarity index 100% rename from implants/eldritch/src/assets/copy_impl.rs rename to implants/lib/eldritch/src/assets/copy_impl.rs diff --git a/implants/eldritch/src/assets/list_impl.rs b/implants/lib/eldritch/src/assets/list_impl.rs similarity index 100% rename from implants/eldritch/src/assets/list_impl.rs rename to implants/lib/eldritch/src/assets/list_impl.rs diff --git a/implants/eldritch/src/file.rs b/implants/lib/eldritch/src/file.rs similarity index 100% rename from implants/eldritch/src/file.rs rename to implants/lib/eldritch/src/file.rs diff --git a/implants/eldritch/src/file/append_impl.rs b/implants/lib/eldritch/src/file/append_impl.rs similarity index 100% rename from implants/eldritch/src/file/append_impl.rs rename to implants/lib/eldritch/src/file/append_impl.rs diff --git a/implants/eldritch/src/file/compress_impl.rs b/implants/lib/eldritch/src/file/compress_impl.rs similarity index 100% rename from implants/eldritch/src/file/compress_impl.rs rename to implants/lib/eldritch/src/file/compress_impl.rs diff --git a/implants/eldritch/src/file/copy_impl.rs b/implants/lib/eldritch/src/file/copy_impl.rs similarity index 100% rename from implants/eldritch/src/file/copy_impl.rs rename to implants/lib/eldritch/src/file/copy_impl.rs diff --git a/implants/eldritch/src/file/download_impl.rs b/implants/lib/eldritch/src/file/download_impl.rs similarity index 100% rename from implants/eldritch/src/file/download_impl.rs rename to implants/lib/eldritch/src/file/download_impl.rs diff --git a/implants/eldritch/src/file/exists_impl.rs b/implants/lib/eldritch/src/file/exists_impl.rs similarity index 100% rename from implants/eldritch/src/file/exists_impl.rs rename to implants/lib/eldritch/src/file/exists_impl.rs diff --git a/implants/eldritch/src/file/hash_impl.rs b/implants/lib/eldritch/src/file/hash_impl.rs similarity index 100% rename from implants/eldritch/src/file/hash_impl.rs rename to implants/lib/eldritch/src/file/hash_impl.rs diff --git a/implants/eldritch/src/file/is_dir_impl.rs b/implants/lib/eldritch/src/file/is_dir_impl.rs similarity index 100% rename from implants/eldritch/src/file/is_dir_impl.rs rename to implants/lib/eldritch/src/file/is_dir_impl.rs diff --git a/implants/eldritch/src/file/is_file_impl.rs b/implants/lib/eldritch/src/file/is_file_impl.rs similarity index 100% rename from implants/eldritch/src/file/is_file_impl.rs rename to implants/lib/eldritch/src/file/is_file_impl.rs diff --git a/implants/eldritch/src/file/mkdir_impl.rs b/implants/lib/eldritch/src/file/mkdir_impl.rs similarity index 100% rename from implants/eldritch/src/file/mkdir_impl.rs rename to implants/lib/eldritch/src/file/mkdir_impl.rs diff --git a/implants/eldritch/src/file/moveto_impl.rs b/implants/lib/eldritch/src/file/moveto_impl.rs similarity index 100% rename from implants/eldritch/src/file/moveto_impl.rs rename to implants/lib/eldritch/src/file/moveto_impl.rs diff --git a/implants/eldritch/src/file/read_impl.rs b/implants/lib/eldritch/src/file/read_impl.rs similarity index 100% rename from implants/eldritch/src/file/read_impl.rs rename to implants/lib/eldritch/src/file/read_impl.rs diff --git a/implants/eldritch/src/file/remove_impl.rs b/implants/lib/eldritch/src/file/remove_impl.rs similarity index 100% rename from implants/eldritch/src/file/remove_impl.rs rename to implants/lib/eldritch/src/file/remove_impl.rs diff --git a/implants/eldritch/src/file/replace_all_impl.rs b/implants/lib/eldritch/src/file/replace_all_impl.rs similarity index 100% rename from implants/eldritch/src/file/replace_all_impl.rs rename to implants/lib/eldritch/src/file/replace_all_impl.rs diff --git a/implants/eldritch/src/file/replace_impl.rs b/implants/lib/eldritch/src/file/replace_impl.rs similarity index 100% rename from implants/eldritch/src/file/replace_impl.rs rename to implants/lib/eldritch/src/file/replace_impl.rs diff --git a/implants/eldritch/src/file/template_impl.rs b/implants/lib/eldritch/src/file/template_impl.rs similarity index 100% rename from implants/eldritch/src/file/template_impl.rs rename to implants/lib/eldritch/src/file/template_impl.rs diff --git a/implants/eldritch/src/file/timestomp_impl.rs b/implants/lib/eldritch/src/file/timestomp_impl.rs similarity index 100% rename from implants/eldritch/src/file/timestomp_impl.rs rename to implants/lib/eldritch/src/file/timestomp_impl.rs diff --git a/implants/eldritch/src/file/write_impl.rs b/implants/lib/eldritch/src/file/write_impl.rs similarity index 100% rename from implants/eldritch/src/file/write_impl.rs rename to implants/lib/eldritch/src/file/write_impl.rs diff --git a/implants/eldritch/src/lib.rs b/implants/lib/eldritch/src/lib.rs similarity index 86% rename from implants/eldritch/src/lib.rs rename to implants/lib/eldritch/src/lib.rs index 852047347..9c33772f1 100644 --- a/implants/eldritch/src/lib.rs +++ b/implants/lib/eldritch/src/lib.rs @@ -61,29 +61,38 @@ impl PrintHandler for StdPrintHandler { pub fn eldritch_run(tome_filename: String, tome_contents: String, tome_parameters: Option, print_handler: &(dyn PrintHandler)) -> anyhow::Result { // Boilder plate - let ast: AstModule; - match AstModule::parse( + let ast = match AstModule::parse( &tome_filename, tome_contents.as_str().to_owned(), &Dialect::Standard ) { - Ok(res) => ast = res, - Err(err) => return Err(err), - } + Ok(res) => res, + Err(err) => return Err(anyhow::anyhow!("[eldritch] Unable to parse eldritch tome: {}: {} {}", err.to_string(), tome_filename.as_str(), tome_contents.as_str())), + }; let tome_params_str: String = match tome_parameters { - Some(param_string) => param_string, + Some(local_param_string) => match local_param_string.as_str() { + "" => "{}".to_string(), // If we get "" as our params update it to "{}" + _ => local_param_string // Otherwise return our string. + }, None => "{}".to_string(), }; - let globals = get_eldritch()?; + let globals = match get_eldritch() { + Ok(local_globals) => local_globals, + Err(local_error) => return Err(anyhow::anyhow!("[eldritch] Failed to get_eldritch globals: {}", local_error.to_string())), + }; let module: Module = Module::new(); let res: SmallMap = SmallMap::new(); let mut input_params: Dict = Dict::new(res); - let parsed: serde_json::Value = serde_json::from_str(&tome_params_str)?; + let parsed: serde_json::Value = match serde_json::from_str(&tome_params_str){ + Ok(local_value) => local_value, + Err(local_err) => return Err(anyhow::anyhow!("[eldritch] Error decoding tome_params to JSON: {}: {}", local_err.to_string(), tome_params_str)), + }; + let param_map: serde_json::Map = match parsed.as_object() { Some(tmp_param_map) => tmp_param_map.clone(), None => Map::new(), @@ -125,7 +134,10 @@ pub fn eldritch_run(tome_filename: String, tome_contents: String, tome_parameter }; new_value = Value::new_int(tmp_value); } - let hashed_key = new_key.to_value().get_hashed()?; + let hashed_key = match new_key.to_value().get_hashed() { + Ok(local_hashed_key) => local_hashed_key, + Err(local_error) => return Err(anyhow::anyhow!("[eldritch] Failed to create hashed key for key {}: {}", new_key.to_string(), local_error.to_string())), + }; input_params.insert_hashed(hashed_key, new_value); } @@ -136,7 +148,7 @@ pub fn eldritch_run(tome_filename: String, tome_contents: String, tome_parameter let res: Value = match eval.eval_module(ast, &globals) { Ok(eval_val) => eval_val, - Err(eval_error) => return Err(anyhow::anyhow!("Eldritch eval_module failed:\n{}", eval_error)), + Err(eval_error) => return Err(anyhow::anyhow!("[eldritch] Eldritch eval_module failed:\n{}", eval_error)), }; Ok(res.to_str()) diff --git a/implants/eldritch/src/pivot.rs b/implants/lib/eldritch/src/pivot.rs similarity index 100% rename from implants/eldritch/src/pivot.rs rename to implants/lib/eldritch/src/pivot.rs diff --git a/implants/eldritch/src/pivot/arp_scan_impl.rs b/implants/lib/eldritch/src/pivot/arp_scan_impl.rs similarity index 100% rename from implants/eldritch/src/pivot/arp_scan_impl.rs rename to implants/lib/eldritch/src/pivot/arp_scan_impl.rs diff --git a/implants/eldritch/src/pivot/bind_proxy_impl.rs b/implants/lib/eldritch/src/pivot/bind_proxy_impl.rs similarity index 100% rename from implants/eldritch/src/pivot/bind_proxy_impl.rs rename to implants/lib/eldritch/src/pivot/bind_proxy_impl.rs diff --git a/implants/eldritch/src/pivot/ncat_impl.rs b/implants/lib/eldritch/src/pivot/ncat_impl.rs similarity index 100% rename from implants/eldritch/src/pivot/ncat_impl.rs rename to implants/lib/eldritch/src/pivot/ncat_impl.rs diff --git a/implants/eldritch/src/pivot/port_forward_impl.rs b/implants/lib/eldritch/src/pivot/port_forward_impl.rs similarity index 100% rename from implants/eldritch/src/pivot/port_forward_impl.rs rename to implants/lib/eldritch/src/pivot/port_forward_impl.rs diff --git a/implants/eldritch/src/pivot/port_scan_impl.rs b/implants/lib/eldritch/src/pivot/port_scan_impl.rs similarity index 100% rename from implants/eldritch/src/pivot/port_scan_impl.rs rename to implants/lib/eldritch/src/pivot/port_scan_impl.rs diff --git a/implants/eldritch/src/pivot/smb_exec_impl.rs b/implants/lib/eldritch/src/pivot/smb_exec_impl.rs similarity index 100% rename from implants/eldritch/src/pivot/smb_exec_impl.rs rename to implants/lib/eldritch/src/pivot/smb_exec_impl.rs diff --git a/implants/eldritch/src/pivot/ssh_exec_impl.rs b/implants/lib/eldritch/src/pivot/ssh_exec_impl.rs similarity index 100% rename from implants/eldritch/src/pivot/ssh_exec_impl.rs rename to implants/lib/eldritch/src/pivot/ssh_exec_impl.rs diff --git a/implants/eldritch/src/pivot/ssh_password_spray_impl.rs b/implants/lib/eldritch/src/pivot/ssh_password_spray_impl.rs similarity index 100% rename from implants/eldritch/src/pivot/ssh_password_spray_impl.rs rename to implants/lib/eldritch/src/pivot/ssh_password_spray_impl.rs diff --git a/implants/eldritch/src/process.rs b/implants/lib/eldritch/src/process.rs similarity index 100% rename from implants/eldritch/src/process.rs rename to implants/lib/eldritch/src/process.rs diff --git a/implants/eldritch/src/process/kill_impl.rs b/implants/lib/eldritch/src/process/kill_impl.rs similarity index 100% rename from implants/eldritch/src/process/kill_impl.rs rename to implants/lib/eldritch/src/process/kill_impl.rs diff --git a/implants/eldritch/src/process/list_impl.rs b/implants/lib/eldritch/src/process/list_impl.rs similarity index 100% rename from implants/eldritch/src/process/list_impl.rs rename to implants/lib/eldritch/src/process/list_impl.rs diff --git a/implants/eldritch/src/process/name_impl.rs b/implants/lib/eldritch/src/process/name_impl.rs similarity index 100% rename from implants/eldritch/src/process/name_impl.rs rename to implants/lib/eldritch/src/process/name_impl.rs diff --git a/implants/eldritch/src/sys.rs b/implants/lib/eldritch/src/sys.rs similarity index 100% rename from implants/eldritch/src/sys.rs rename to implants/lib/eldritch/src/sys.rs diff --git a/implants/eldritch/src/sys/dll_inject_impl.rs b/implants/lib/eldritch/src/sys/dll_inject_impl.rs similarity index 97% rename from implants/eldritch/src/sys/dll_inject_impl.rs rename to implants/lib/eldritch/src/sys/dll_inject_impl.rs index e5a64cf40..ef592c8fa 100644 --- a/implants/eldritch/src/sys/dll_inject_impl.rs +++ b/implants/lib/eldritch/src/sys/dll_inject_impl.rs @@ -98,7 +98,7 @@ mod tests { // Get the path to our test dll file. let cargo_root = env!("CARGO_MANIFEST_DIR"); - let relative_path_to_test_dll = "..\\..\\tests\\create_file_dll\\target\\debug\\create_file_dll.dll"; + let relative_path_to_test_dll = "..\\..\\..\\tests\\create_file_dll\\target\\debug\\create_file_dll.dll"; let test_dll_path = Path::new(cargo_root).join(relative_path_to_test_dll); assert!(test_dll_path.is_file()); diff --git a/implants/eldritch/src/sys/exec_impl.rs b/implants/lib/eldritch/src/sys/exec_impl.rs similarity index 100% rename from implants/eldritch/src/sys/exec_impl.rs rename to implants/lib/eldritch/src/sys/exec_impl.rs diff --git a/implants/eldritch/src/sys/is_linux_impl.rs b/implants/lib/eldritch/src/sys/is_linux_impl.rs similarity index 100% rename from implants/eldritch/src/sys/is_linux_impl.rs rename to implants/lib/eldritch/src/sys/is_linux_impl.rs diff --git a/implants/eldritch/src/sys/is_macos_impl.rs b/implants/lib/eldritch/src/sys/is_macos_impl.rs similarity index 100% rename from implants/eldritch/src/sys/is_macos_impl.rs rename to implants/lib/eldritch/src/sys/is_macos_impl.rs diff --git a/implants/eldritch/src/sys/is_windows_impl.rs b/implants/lib/eldritch/src/sys/is_windows_impl.rs similarity index 100% rename from implants/eldritch/src/sys/is_windows_impl.rs rename to implants/lib/eldritch/src/sys/is_windows_impl.rs diff --git a/implants/eldritch/src/sys/shell_impl.rs b/implants/lib/eldritch/src/sys/shell_impl.rs similarity index 100% rename from implants/eldritch/src/sys/shell_impl.rs rename to implants/lib/eldritch/src/sys/shell_impl.rs diff --git a/implants/lib/tavern/Cargo.toml b/implants/lib/tavern/Cargo.toml new file mode 100644 index 000000000..f6268522d --- /dev/null +++ b/implants/lib/tavern/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "tavern" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[features] +default = ["http"] +http = ["dep:reqwest"] + +[dependencies] +anyhow = { workspace = true } +async-trait = { workspace = true } +chrono = { workspace = true, features = ["serde"] } +graphql_client = { workspace = true } +reqwest = { workspace = true, optional = true, features = ["blocking", "stream", "json"] } +serde = { workspace = true, features = ["derive"] } +serde_json = { workspace = true } +tokio = { workspace = true, features = ["full"] } + +[dev-dependencies] +httptest = { workspace = true } +tokio-test = { workspace = true } \ No newline at end of file diff --git a/implants/pkg/tavern/README.md b/implants/lib/tavern/README.md similarity index 100% rename from implants/pkg/tavern/README.md rename to implants/lib/tavern/README.md diff --git a/implants/pkg/tavern/codegen.sh b/implants/lib/tavern/codegen.sh similarity index 100% rename from implants/pkg/tavern/codegen.sh rename to implants/lib/tavern/codegen.sh diff --git a/implants/pkg/tavern/graphql/mutations.graphql b/implants/lib/tavern/graphql/mutations.graphql similarity index 100% rename from implants/pkg/tavern/graphql/mutations.graphql rename to implants/lib/tavern/graphql/mutations.graphql diff --git a/implants/pkg/tavern/graphql/schema.graphql b/implants/lib/tavern/graphql/schema.graphql similarity index 100% rename from implants/pkg/tavern/graphql/schema.graphql rename to implants/lib/tavern/graphql/schema.graphql diff --git a/implants/pkg/tavern/src/http.rs b/implants/lib/tavern/src/http.rs similarity index 100% rename from implants/pkg/tavern/src/http.rs rename to implants/lib/tavern/src/http.rs diff --git a/implants/pkg/tavern/src/lib.rs b/implants/lib/tavern/src/lib.rs similarity index 100% rename from implants/pkg/tavern/src/lib.rs rename to implants/lib/tavern/src/lib.rs diff --git a/implants/pkg/tavern/src/mutations.rs b/implants/lib/tavern/src/mutations.rs similarity index 100% rename from implants/pkg/tavern/src/mutations.rs rename to implants/lib/tavern/src/mutations.rs diff --git a/implants/pkg/tavern/src/scalars.rs b/implants/lib/tavern/src/scalars.rs similarity index 100% rename from implants/pkg/tavern/src/scalars.rs rename to implants/lib/tavern/src/scalars.rs diff --git a/implants/pkg/README.md b/implants/pkg/README.md deleted file mode 100644 index 577e6eb19..000000000 --- a/implants/pkg/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Overview - -Code shared by multiple implants can be defined in the `pkg` folder. diff --git a/implants/pkg/tavern/Cargo.toml b/implants/pkg/tavern/Cargo.toml deleted file mode 100644 index 4182bc72f..000000000 --- a/implants/pkg/tavern/Cargo.toml +++ /dev/null @@ -1,24 +0,0 @@ -[package] -name = "tavern" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[features] -default = ["http"] -http = ["dep:reqwest"] - -[dependencies] -graphql_client = "0.12.0" -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" -reqwest = { version = "0.11.4" , optional = true, features = ["blocking", "stream", "json"] } -anyhow = "1.0.55" -async-trait = "0.1.68" -tokio = { version = "1", features = ["full"] } -chrono = { version = "0.4.24", features = ["serde"] } - -[dev-dependencies] -tokio-test = "*" -httptest = "0.15.4" \ No newline at end of file diff --git a/tavern/generate.go b/tavern/generate.go index 336bc929f..42552e93e 100644 --- a/tavern/generate.go +++ b/tavern/generate.go @@ -4,5 +4,5 @@ package main //go:generate /bin/sh -c "cd ./graphql && go run -mod=mod github.com/99designs/gqlgen" //go:generate /bin/sh -c "cat ./graphql/schema/* > ./graphql/schema.graphql" -//go:generate /bin/sh -c "cp ./graphql/schema.graphql ../implants/pkg/tavern/graphql/schema.graphql" -//go:generate /bin/sh -c "cd ../implants/pkg/tavern && ./codegen.sh" +//go:generate /bin/sh -c "cp ./graphql/schema.graphql ../implants/lib/tavern/graphql/schema.graphql" +//go:generate /bin/sh -c "cd ../implants/lib/tavern && ./codegen.sh"