Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys.get_pid() #272

Merged
merged 4 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/_docs/user-guide/eldritch.md
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,17 @@ An example is below:
}
```

### sys.get_pid
`sys.get_pid() -> int`

The <b>sys.get_pid</b> method returns the process ID of the current process.
An example is below:

```json
$> sys.get_pid()
123456
```

### sys.get_user
`sys.get_user() -> Dict`

Expand Down
2 changes: 1 addition & 1 deletion implants/lib/eldritch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ mod tests {
r#"
dir(file) == ["append", "compress", "copy", "download", "exists", "hash", "is_dir", "is_file", "list", "mkdir", "read", "remove", "rename", "replace", "replace_all", "template", "timestomp", "write"]
dir(process) == ["kill", "list", "name"]
dir(sys) == ["dll_inject", "exec", "get_ip", "get_os", "get_user", "is_linux", "is_macos", "is_windows", "shell"]
dir(sys) == ["dll_inject", "exec", "get_ip", "get_os", "get_pid", "get_user", "is_linux", "is_macos", "is_windows", "shell"]
dir(pivot) == ["arp_scan", "bind_proxy", "ncat", "port_forward", "port_scan", "smb_exec", "ssh_exec", "ssh_password_spray"]
dir(assets) == ["copy","list","read","read_binary"]
"#,
Expand Down
19 changes: 19 additions & 0 deletions implants/lib/eldritch/src/sys/get_pid_impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use anyhow::Result;
use std::process;
use starlark::values::Heap;

pub fn get_pid(starlark_heap: &Heap) -> Result<u32> {
Ok(process::id())
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_sys_get_pid() {
let starlark_heap = Heap::new();
let res = get_pid(&starlark_heap).unwrap();
assert_eq!(res, process::id());
}
}
Loading