Skip to content

Commit

Permalink
Merge branch 'main' into sys_get_env
Browse files Browse the repository at this point in the history
  • Loading branch information
jabbate19 authored Aug 15, 2023
2 parents dc6ab37 + cd8d9d2 commit b9ed81f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
11 changes: 11 additions & 0 deletions docs/_docs/user-guide/eldritch.md
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,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_env", "get_ip", "get_os", "get_user", "is_linux", "is_macos", "is_windows", "shell"]
dir(sys) == ["dll_inject", "exec", "get_env", "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
5 changes: 5 additions & 0 deletions implants/lib/eldritch/src/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod exec_impl;
mod get_env_impl;
mod get_ip_impl;
mod get_os_impl;
mod get_pid_impl;
mod get_user_impl;
mod is_linux_impl;
mod is_windows_impl;
Expand Down Expand Up @@ -83,6 +84,10 @@ fn methods(builder: &mut MethodsBuilder) {
if false { println!("Ignore unused this var. _this isn't allowed by starlark. {:?}", this); }
get_ip_impl::get_ip(starlark_heap)
}
fn get_pid<'v>(this: SysLibrary, starlark_heap: &'v Heap) -> anyhow::Result<u32> {
if false { println!("Ignore unused this var. _this isn't allowed by starlark. {:?}", this); }
get_pid_impl::get_pid(starlark_heap)
}
fn get_user<'v>(this: SysLibrary, starlark_heap: &'v Heap) -> anyhow::Result<Dict<'v>> {
if false {
println!(
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());
}
}

0 comments on commit b9ed81f

Please sign in to comment.