Skip to content

Commit 0ef5076

Browse files
committed
added global token store and tokens function with prep helper functions for future eldritch methods
1 parent a9f110a commit 0ef5076

5 files changed

Lines changed: 391 additions & 0 deletions

File tree

docs/_docs/user-guide/eldritch.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,6 +1628,56 @@ sys.shell("ls /nofile")
16281628
}
16291629
```
16301630

1631+
### sys.tokens
1632+
1633+
`sys.tokens(pid: Option<int>) -> List<Dict>`
1634+
1635+
The **sys.tokens** method lists tokens. With no arguments, returns all tokens in the global store. With a PID, returns the process token info including user and privileges.
1636+
1637+
**Stored tokens** (no args): Each dict has `active` (bool), `id` (int), `source` (str).
1638+
1639+
**Process tokens** (with pid): Each dict has `user` (str, e.g. `"CORP\\admin"`), `pid` (int), `privileges` (list of `"PrivilegeName=enabled|disabled"`).
1640+
1641+
```python
1642+
$> sys.tokens()
1643+
1644+
| active | id | source |
1645+
| ------ | -- | ------------------- |
1646+
| True | 1 | impersonate:pid:700 |
1647+
1648+
$> pprint(sys.tokens(pid=700))
1649+
1650+
[
1651+
{
1652+
"pid": 700,
1653+
"privileges": [
1654+
"SeAssignPrimaryTokenPrivilege=disabled",
1655+
"SeIncreaseQuotaPrivilege=disabled",
1656+
"SeTcbPrivilege=enabled",
1657+
"SeSecurityPrivilege=disabled",
1658+
"SeTakeOwnershipPrivilege=disabled",
1659+
"SeLoadDriverPrivilege=disabled",
1660+
"SeProfileSingleProcessPrivilege=enabled",
1661+
"SeIncreaseBasePriorityPrivilege=enabled",
1662+
"SeCreatePermanentPrivilege=enabled",
1663+
"SeBackupPrivilege=disabled",
1664+
"SeRestorePrivilege=disabled",
1665+
"SeShutdownPrivilege=disabled",
1666+
"SeDebugPrivilege=enabled",
1667+
"SeAuditPrivilege=enabled",
1668+
"SeSystemEnvironmentPrivilege=disabled",
1669+
"SeChangeNotifyPrivilege=enabled",
1670+
"SeUndockPrivilege=disabled",
1671+
"SeManageVolumePrivilege=disabled",
1672+
"SeImpersonatePrivilege=enabled",
1673+
"SeCreateGlobalPrivilege=enabled",
1674+
"SeTrustedCredManAccessPrivilege=disabled"
1675+
],
1676+
"user": "NT AUTHORITY\\SYSTEM"
1677+
}
1678+
]
1679+
```
1680+
16311681
### sys.write_reg
16321682

16331683
`sys.write_reg(path: str, regname: str, regtype: str, regvalue: any) -> Bool`

implants/lib/eldritch/stdlib/eldritch-libsys/src/fake.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,17 @@ impl SysLibrary for SysLibraryFake {
113113
Ok(map)
114114
}
115115

116+
fn tokens(&self, _pid: Option<i64>) -> Result<Vec<BTreeMap<String, Value>>, String> {
117+
let mut entry = BTreeMap::new();
118+
entry.insert("id".into(), Value::Int(1));
119+
entry.insert(
120+
"source".into(),
121+
Value::String("impersonate:explorer.exe".into()),
122+
);
123+
entry.insert("active".into(), Value::Bool(true));
124+
Ok(vec![entry])
125+
}
126+
116127
fn write_reg(
117128
&self,
118129
_path: String,

implants/lib/eldritch/stdlib/eldritch-libsys/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,20 @@ pub trait SysLibrary {
179179
/// - `Dict`: Output containing `stdout`, `stderr`, and `status`.
180180
fn shell(&self, cmd: String) -> Result<BTreeMap<String, Value>, String>;
181181

182+
#[eldritch_method]
183+
/// Lists tokens in the global store, or enumerates a process token.
184+
///
185+
/// With no arguments, returns all stored tokens from global token store calls.
186+
/// With a PID, returns the process token info including user and privileges.
187+
///
188+
/// **Parameters**
189+
/// - `pid` (`Option<int>`): Process ID to query, or None for stored tokens.
190+
///
191+
/// **Returns**
192+
/// - `List<Dict>`: Token info. Stored: `{active, id, source}`.
193+
/// Process: `{user, pid, privileges}`.
194+
fn tokens(&self, pid: Option<i64>) -> Result<Vec<BTreeMap<String, Value>>, String>;
195+
182196
#[eldritch_method]
183197
/// Writes a value to the Windows Registry.
184198
///

implants/lib/eldritch/stdlib/eldritch-libsys/src/std.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ mod is_windows_impl;
2222
mod list_users_impl;
2323
mod reg_utils;
2424
mod shell_impl;
25+
pub mod tokens_impl;
2526
mod write_reg_impl;
2627

2728
#[derive(Debug)]
@@ -108,6 +109,10 @@ impl SysLibrary for StdSysLibrary {
108109
shell_impl::shell(cmd).map_err(|e| e.to_string())
109110
}
110111

112+
fn tokens(&self, pid: Option<i64>) -> Result<Vec<BTreeMap<String, Value>>, String> {
113+
tokens_impl::tokens(pid)
114+
}
115+
111116
fn write_reg(
112117
&self,
113118
path: String,

0 commit comments

Comments
 (0)