feat(eldritch): Support globbing in file and report standard library functions#2063
feat(eldritch): Support globbing in file and report standard library functions#2063
Conversation
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Summary
Previous Results
Insights
Slowest Tests
🎉 No failed tests in this run. | 🍂 No flaky tests in this run. Github Test Reporter by CTRF 💚 🔄 This comment has been updated |
| pub fn is_dir(path: String) -> Result<bool, String> { | ||
| Ok(Path::new(&path).is_dir()) | ||
| if path.contains('*') || path.contains('?') || path.contains('[') { | ||
| let mut paths = glob(&path).map_err(|e| format!("Invalid glob pattern {path}: {e}"))?; |
There was a problem hiding this comment.
@hulto check that this mimics bash behavior
There was a problem hiding this comment.
@jules bash errors when checking if a glob is dir. We should duplicate this behavior.
Explicitly error with globbing not supported for multiple paths if paths len is > 1
There was a problem hiding this comment.
Updated is_dir_impl.rs to error if a glob pattern resolves to multiple paths, effectively matching bash's behavior.
| fs::read(&path).map_err(|e| format!("Failed to read file {path}: {e}")) | ||
| let target_path = if path.contains('*') || path.contains('?') || path.contains('[') { | ||
| let mut paths = glob(&path).map_err(|e| format!("Invalid glob pattern {path}: {e}"))?; | ||
| if let Some(Ok(first_match)) = paths.next() { |
There was a problem hiding this comment.
@jules this should read all matched paths concatenating the results
There was a problem hiding this comment.
Updated read_binary_impl.rs to concatenate all matching files into a single Vec<u8>.
| fs::read_to_string(&path).map_err(|e| format!("Failed to read file {path}: {e}")) | ||
| let target_path = if path.contains('*') || path.contains('?') || path.contains('[') { | ||
| let mut paths = glob(&path).map_err(|e| format!("Invalid glob pattern {path}: {e}"))?; | ||
| if let Some(Ok(first_match)) = paths.next() { |
There was a problem hiding this comment.
Updated read_impl.rs to concatenate the string content of all matching files into a single String.
| pub fn is_dir(path: String) -> Result<bool, String> { | ||
| Ok(Path::new(&path).is_dir()) | ||
| if path.contains('*') || path.contains('?') || path.contains('[') { | ||
| let mut paths = glob(&path).map_err(|e| format!("Invalid glob pattern {path}: {e}"))?; |
There was a problem hiding this comment.
@jules bash errors when checking if a glob is dir. We should duplicate this behavior.
Explicitly error with globbing not supported for multiple paths if paths len is > 1
| Ok(Path::new(&path).is_file()) | ||
| if path.contains('*') || path.contains('?') || path.contains('[') { | ||
| let mut paths = glob(&path).map_err(|e| format!("Invalid glob pattern {path}: {e}"))?; | ||
| if let Some(Ok(first_match)) = paths.next() { |
There was a problem hiding this comment.
@jules bash errors when checking if a glob is file. We should duplicate this behavior.
Explicitly error with globbing not supported for multiple paths if paths len is > 1
There was a problem hiding this comment.
Updated is_file_impl.rs to error if a glob pattern resolves to multiple paths, matching bash's behavior.
| pb = { workspace = true, optional = true } | ||
| nix = { workspace = true, optional = true } | ||
| spin = { version = "0.10.0", features = ["rwlock"] } | ||
| glob.workspace = true |
There was a problem hiding this comment.
@jules use the syntax = { workspace = true }
There was a problem hiding this comment.
Fixed Cargo.toml to use the = { workspace = true } syntax for the glob dependency.
Updated standard library functions in `eldritch-libfile` (`read`, `read_binary`, `exists`, `is_dir`, `is_file`, `remove`) and `eldritch-libreport` (`file`) to support globbing natively using the `glob` crate. - For operations like `read` and `is_dir`/`is_file`, the first matching file from the glob pattern is used. - For `remove`, all files/directories matching the pattern are deleted. - For `report.file`, all matching files are sequentially exfiltrated over the existing streaming channel to the C2. - The `glob` crate was added as a workspace dependency to `eldritch-libreport`. Co-authored-by: hulto <7121375+hulto@users.noreply.github.com>
- Updated `file.read` to return the concatenated string contents of all files matching a glob pattern. - Updated `file.read_binary` to return the concatenated bytes of all files matching a glob pattern. Co-authored-by: hulto <7121375+hulto@users.noreply.github.com>
- `is_dir` and `is_file` now return an error explicitly stating "Globbing not supported for multiple paths" if a glob pattern resolves to > 1 file. This mirrors bash behavior.
- Updated `eldritch-libreport/Cargo.toml` to use `glob = { workspace = true }` syntax.
Co-authored-by: hulto <7121375+hulto@users.noreply.github.com>
bd094be to
d6d13fb
Compare
This PR updates various
file.*functions and thereport.filefunction in the Eldritch standard library to support globbing.Changes:
exists,is_dir,is_file,read, andread_binaryineldritch-libfileto resolve glob patterns (e.g., matching*,?, or[]). For these single-target functions, the first matching file is processed.removeineldritch-libfileto iterate over and delete all matching files or directories.fileineldritch-libreportto collect all matching files and report (exfiltrate) them back to the C2 server sequentially over its streaming chunked channel.globas a dependency foreldritch-libreport.cargo testand ensured formatting viacargo fmt.PR created automatically by Jules for task 127060281935815099 started by @hulto