Skip to content

feat(eldritch): Support globbing in file and report standard library functions#2063

Merged
hulto merged 5 commits intomainfrom
update-file-globbing-127060281935815099
Mar 14, 2026
Merged

feat(eldritch): Support globbing in file and report standard library functions#2063
hulto merged 5 commits intomainfrom
update-file-globbing-127060281935815099

Conversation

@hulto
Copy link
Collaborator

@hulto hulto commented Mar 9, 2026

This PR updates various file.* functions and the report.file function in the Eldritch standard library to support globbing.

Changes:

  • Updated exists, is_dir, is_file, read, and read_binary in eldritch-libfile to resolve glob patterns (e.g., matching *, ?, or []). For these single-target functions, the first matching file is processed.
  • Updated remove in eldritch-libfile to iterate over and delete all matching files or directories.
  • Updated file in eldritch-libreport to collect all matching files and report (exfiltrate) them back to the C2 server sequentially over its streaming chunked channel.
  • Added glob as a dependency for eldritch-libreport.
  • Added tests via cargo test and ensured formatting via cargo fmt.

PR created automatically by Jules for task 127060281935815099 started by @hulto

@google-labs-jules
Copy link
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2026

Summary

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Other ❓ Flaky 🍂 Duration ⏱️
2758    ±0 2758    ±0 0    ±0 0    ±0 0    ±0 0    ±0 1ms    ±0

Previous Results

Build 🏗️ Result 🧪 Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Other ❓ Flaky 🍂 Duration ⏱️
#1655 2758 2758 0 0 0 0 39.4s

Insights

Average Tests per Run Total Flaky Tests Total Failed Slowest Test (p95)
2758 0 0 5.6s

Slowest Tests

Test 📝 Results 📊 Duration (avg) ⏱️ Duration (p95) ⏱️
TestDockerExecutor_Build_ContextCancellation 1 5.6s 5.6s
eldritch-libsys: std::dll_inject_impl::tests::test_dll_inject_simple 1 5.1s 5.1s
TestInteractiveShell 1 5.1s 5.1s
TestOtherStreamOutput 1 5.0s 5.0s
imix::bin/imix: install::tests::test_install_execution 3 1.6s 4.7s
imix::bin/imix: install::tests::test_install_execution 3 1.6s 4.7s
imix::bin/imix: install::tests::test_install_execution 3 1.6s 4.7s
imix::bin/imix: tests::task_tests::test_task_streaming_output 3 3.0s 3.0s
imix::bin/imix: tests::task_tests::test_task_streaming_output 3 3.0s 3.0s
imix::bin/imix: tests::task_tests::test_task_streaming_output 3 3.0s 3.0s

🎉 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}"))?;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hulto check that this mimics bash behavior

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jules this should read all matched paths concatenating the results

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jules this should read all matches

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated read_impl.rs to concatenate the string content of all matching files into a single String.

Copy link
Collaborator Author

@hulto hulto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jules feedback

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}"))?;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jules use the syntax = { workspace = true }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed Cargo.toml to use the = { workspace = true } syntax for the glob dependency.

@hulto hulto marked this pull request as ready for review March 14, 2026 04:10
google-labs-jules bot and others added 3 commits March 14, 2026 18:32
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>
@hulto hulto force-pushed the update-file-globbing-127060281935815099 branch from bd094be to d6d13fb Compare March 14, 2026 18:32
@hulto hulto merged commit d54f90e into main Mar 14, 2026
8 checks passed
@hulto hulto deleted the update-file-globbing-127060281935815099 branch March 14, 2026 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant