Skip to content

Commit

Permalink
Add tome newlines (#400)
Browse files Browse the repository at this point in the history
* Added print new lines.

* Add EOF newline.

* rename eld to eldritch.
  • Loading branch information
hulto authored Dec 26, 2023
1 parent f3e5886 commit f130de1
Show file tree
Hide file tree
Showing 27 changed files with 98 additions and 54 deletions.
2 changes: 1 addition & 1 deletion bin/embedded_files_test/exec_script/hello_world.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
echo hello from an embedded shell script
echo hello from an embedded shell script
2 changes: 1 addition & 1 deletion bin/embedded_files_test/exec_script/hello_world.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/sh
echo "hello from an embedded shell script"
echo "hello from an embedded shell script"
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ def copy_script_and_execute():
assets.copy("exec_script/hello_world.sh","/tmp/golem_cli_test-copy_script_and_execute")
shell_res = sys.shell("chmod +x /tmp/golem_cli_test-copy_script_and_execute && /tmp/golem_cli_test-copy_script_and_execute")
print(shell_res)
print("\n")
elif sys.is_windows():
assets.copy("exec_script/hello_world.bat","C:\Windows\Temp\golem_cli_test-copy_script_and_execute")
shell_res = sys.shell("C:\Windows\Temp\golem_cli_test-copy_script_and_execute")
print(shell_res)
print("\n")


copy_script_and_execute()
copy_script_and_execute()
1 change: 0 additions & 1 deletion bin/embedded_files_test/print/main.eld

This file was deleted.

1 change: 1 addition & 0 deletions bin/embedded_files_test/print/main.eldritch
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("This script just prints")
14 changes: 9 additions & 5 deletions docs/_docs/user-guide/golem.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
---
title: Golem
tags:
tags:
- User Guide
description: Golem User Guide
permalink: user-guide/golem
---
## What is Golem

Golem is the standalone interpreter for Eldritch.
This program exists to help users get experience with the Eldritch language as well as a jumping off point if you're interested in implementing your own program using the Eldritch language.

Golem can also be used operationally as an alternative to a system native shell.
You can leverage the power of Eldritch with minimal exposure in the system process tree.

## Try it out.
## Try it out

```bash
git clone [email protected]:KCarretto/realm.git
cd realm/implants/golem
cargo run -- -i
# - or -
# - or -
cargo build --release && \
../target/debug/golem ../../tests/golem_cli_test/tomes/hello_world.tome
```

## Golem embedded files
The Eldritch interpreter can embed files at compile time. To interact with these assets use the `assets` module in eldritch. In addition to programmatic access the embedded files can be automatically executed at run time. If no other option is specified `-i` or a file path, golem will iterate over every instance of `main.eld` in the embedded assets launching each one as a separate thread. This behavior is desirable when trying to perform recon or deploy persistence quickly.

The Eldritch interpreter can embed files at compile time. To interact with these assets use the `assets` module in eldritch. In addition to programmatic access the embedded files can be automatically executed at run time. If no other option is specified `-i` or a file path, golem will iterate over every instance of `main.eldritch` in the embedded assets launching each one as a separate thread. This behavior is desirable when trying to perform recon or deploy persistence quickly.

## Golem as a stage 0

Golem can also be used as a stage 0 to load imix or other c2 agents.
This can help in a few ways such as:

Expand Down Expand Up @@ -68,4 +72,4 @@ def main():
return
run_payload()
main()
```
```
4 changes: 2 additions & 2 deletions docs/_docs/user-guide/imix.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ The imix config is as follows:
## Installation

The install subcommand executes embedded tomes similar to golem.
It will loop through all embedded files looking for main.eld
Each main.eld will execute in a new thread. This is done to allow imix to install redundantly or install additional (non dependent) tools.
It will loop through all embedded files looking for main.eldritch
Each main.eldritch will execute in a new thread. This is done to allow imix to install redundantly or install additional (non dependent) tools.

The install subcommand makes allows some variables to be passed form the user into the tomes through the -c flag.
When specified input_params['custom_config'] is set to the file path of the config specified Eg.
Expand Down
7 changes: 5 additions & 2 deletions implants/golem/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ fn main() -> anyhow::Result<()> {
None => "",
};
println!("{}", embedded_file_path);
if filename == "main.eld" {
if filename == "main.eldritch" {
let tome_path = embedded_file_path.to_string().clone();
let tome_contents_extraction_result =
match eldritch::assets::Asset::get(embedded_file_path.as_ref()) {
Expand Down Expand Up @@ -154,7 +154,10 @@ mod tests {
use super::*;
#[tokio::test]
async fn test_golem_execute_tomes_in_parallel() -> anyhow::Result<()> {
let tome_files_and_content = [("test_hello.eld".to_string(), "'hello world'".to_string())];
let tome_files_and_content = [(
"test_hello.eldritch".to_string(),
"'hello world'".to_string(),
)];
let (error_code, result) =
execute_tomes_in_parallel(tome_files_and_content.to_vec()).await?;
assert_eq!(error_code, 0);
Expand Down
7 changes: 5 additions & 2 deletions implants/imix/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub fn install_main(custom_config: Option<&str>) -> anyhow::Result<()> {
None => "",
};
println!("{}", embedded_file_path);
if filename == "main.eld" {
if filename == "main.eldritch" {
let tome_path = embedded_file_path.to_string().clone();
let tome_contents_extraction_result =
match eldritch::assets::Asset::get(embedded_file_path.as_ref()) {
Expand Down Expand Up @@ -118,7 +118,10 @@ mod tests {
use super::*;
#[tokio::test]
async fn imix_test_execute_tomes_in_parallel() -> anyhow::Result<()> {
let tome_files_and_content = [("test_hello.eld".to_string(), "'hello world'".to_string())];
let tome_files_and_content = [(
"test_hello.eldritch".to_string(),
"'hello world'".to_string(),
)];
let (error_code, result) =
execute_tomes_in_parallel(tome_files_and_content.to_vec(), None).await?;
assert_eq!(error_code, 0);
Expand Down
4 changes: 2 additions & 2 deletions implants/lib/eldritch/src/assets/list_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ mod tests {
[
"exec_script/hello_world.bat",
"exec_script/hello_world.sh",
"exec_script/main.eld",
"print/main.eld"
"exec_script/main.eldritch",
"print/main.eldritch"
]
);

Expand Down
13 changes: 11 additions & 2 deletions implants/lib/eldritch/src/assets/read_binary_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,21 @@ mod tests {

#[test]
fn test_assets_read_binary() -> anyhow::Result<()> {
let res = read_binary("print/main.eld".to_string())?;
let res = read_binary("print/main.eldritch".to_string())?;
#[cfg(not(windows))]
assert_eq!(
res,
[
112, 114, 105, 110, 116, 40, 34, 84, 104, 105, 115, 32, 115, 99, 114, 105, 112,
116, 32, 106, 117, 115, 116, 32, 112, 114, 105, 110, 116, 115, 34, 41
116, 32, 106, 117, 115, 116, 32, 112, 114, 105, 110, 116, 115, 34, 41, 10
]
);
#[cfg(windows)]
assert_eq!(
res,
[
112, 114, 105, 110, 116, 40, 34, 84, 104, 105, 115, 32, 115, 99, 114, 105, 112,
116, 32, 106, 117, 115, 116, 32, 112, 114, 105, 110, 116, 115, 34, 41, 13, 10
]
);
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions implants/lib/eldritch/src/assets/read_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ mod tests {

#[test]
fn test_assets_read() -> anyhow::Result<()> {
let res = read("print/main.eld".to_string())?;
assert_eq!(res, r#"print("This script just prints")"#);
let res = read("print/main.eldritch".to_string())?;
assert_eq!(res.trim(), r#"print("This script just prints")"#);
Ok(())
}
}
9 changes: 6 additions & 3 deletions tavern/tomes/cat/main.eldritch
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ def cat(path):
if file.is_file(path):
res = file.read(path)
print(res)
print("\n")
else:
print("Error: Invalid Path ("+path+")")
print("Error: Invalid Path ("+path+")\n")

return

cat(input_params['path'])
cat(input_params['path'])
print("\n")
print("\n")
4 changes: 3 additions & 1 deletion tavern/tomes/download_and_execute/main.eldritch
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ def download_and_execute(url):
sys.exec("powershell.exe", ["Start-Process -WindowStyle hidden ./tmp.exe"])

else:
print("OS not supported")
print("OS not supported\n")
return

download_and_execute(input_params['url'])
print("\n")
print("\n")
2 changes: 1 addition & 1 deletion tavern/tomes/example/main.eldritch
Original file line number Diff line number Diff line change
@@ -1 +1 @@
print(input_params['msg'])
print(input_params['msg'])
2 changes: 1 addition & 1 deletion tavern/tomes/example/metadata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ paramdefs:
- label: Message
name: msg
placeholder: Something to print
type: string
type: string
6 changes: 4 additions & 2 deletions tavern/tomes/file_list/main.eldritch
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ def file_list(path):
type_str = "Dir"
if f['type'] == "File":
type_str = "File"
print(f['permissions']+"\t"+f['owner']+"\t"+f['group']+"\t"+str(f['size'])+"\t"+f['modified']+"\t"+type_str+"\t"+f['file_name'])
print(f['permissions']+"\t"+f['owner']+"\t"+f['group']+"\t"+str(f['size'])+"\t"+f['modified']+"\t"+type_str+"\t"+f['file_name']+"\n")

file_list(input_params['path'])
file_list(input_params['path'])
print("\n")
print("\n")
3 changes: 3 additions & 0 deletions tavern/tomes/hostname/main.eldritch
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
print(sys.hostname())
print("\n")
print("\n")
print("\n")
6 changes: 4 additions & 2 deletions tavern/tomes/ifconfig/main.eldritch
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ def ifconfig():
ip_res = sys.get_ip()
for interface in ip_res:
for ip in interface['ips']:
print(interface['name']+"\t"+ip+"\t"+interface['mac'])
ifconfig()
print(interface['name']+"\t"+ip+"\t"+interface['mac']+"\n")
ifconfig()
print("\n")
print("\n")
20 changes: 11 additions & 9 deletions tavern/tomes/netstat/main.eldritch
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
def netstat():
nets = process.netstat()

print("----TCP----")
print("socket_type,local,remote,state,pids")
print("----TCP----\n")
print("socket_type,local,remote,state,pids\n")
for n in nets:
if str(n['socket_type']) == "TCP":
print(str(n['socket_type'])+", "+str(n['local_address'])+":"+str(n['local_port'])+", "+str(n['remote_address'])+":"+str(n['remote_port'])+", "+str(n['state'])+", "+str(n['pids']))
print("----UDP----")
print("socket_type,local,pids")
print(str(n['socket_type'])+", "+str(n['local_address'])+":"+str(n['local_port'])+", "+str(n['remote_address'])+":"+str(n['remote_port'])+", "+str(n['state'])+", "+str(n['pids'])+"\n")

print("----UDP----\n")
print("socket_type,local,pids\n")
for n in nets:
if str(n['socket_type']) == "UDP":
print(str(n['socket_type'])+", "+str(n['local_address'])+":"+str(n['local_port'])+", "+str(n['pids']))
print(str(n['socket_type'])+", "+str(n['local_address'])+":"+str(n['local_port'])+", "+str(n['pids'])+"\n")



return

netstat()
netstat()
print("\n")
print("\n")
2 changes: 1 addition & 1 deletion tavern/tomes/netstat/metadata.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
name: netstat
description: List network connections
description: List network connections
3 changes: 2 additions & 1 deletion tavern/tomes/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tomes_test

import (
"context"
"strings"
"testing"

"github.com/kcarretto/realm/tavern/internal/ent/enttest"
Expand All @@ -25,7 +26,7 @@ func TestUploadTomes(t *testing.T) {
Where(tome.Name("example")).
OnlyX(ctx)
require.NotNil(t, testTome)
assert.Equal(t, `print(input_params['msg'])`, testTome.Eldritch)
assert.Equal(t, "print(input_params['msg'])", strings.TrimSpace(testTome.Eldritch))
assert.Equal(t, `An example tome!`, testTome.Description)
assert.Equal(t, `[{"name":"msg","label":"Message","type":"string","placeholder":"Something to print"}]`, testTome.ParamDefs)
testTomeFiles, err := testTome.Files(ctx)
Expand Down
4 changes: 3 additions & 1 deletion tavern/tomes/persist_service/main.eldritch
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,13 @@ def persist_service(service_name, service_desc, executable_name, executable_url)
executable_path = "/var/root/"+executable_name
launch_daemon(service_name, executable_path, executable_url)
else:
print("OS not supported")
print("OS not supported\n")

persist_service(
input_params['service_name'],
input_params['service_desc'],
input_params['executable_name'],
input_params['executable_url']
)
print("\n")
print("\n")
7 changes: 5 additions & 2 deletions tavern/tomes/port_scan/main.eldritch
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ def port_scan(target_cidrs, ports, protocol, timeout):
scan_res = pivot.port_scan(target_cidrs, ports, protocol, timeout)
for port_res in sorted(scan_res, key=sort_by_ip_then_port):
print(port_res)
print("\n")

def str_to_str_list(list_str):
list_str = list_str.removeprefix('[')
list_str = list_str.removesuffix(']')
return list_str.split(",")

def str_to_int_list(list_str):
list_str = list_str.removeprefix('[')
list_str = list_str.removesuffix(']')
Expand All @@ -32,4 +33,6 @@ port_scan(
tmp_input_ports,
input_params['protocol'],
int(input_params['timeout'])
)
)
print("\n")
print("\n")
2 changes: 1 addition & 1 deletion tavern/tomes/port_scan/metadata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ paramdefs:
- name: timeout
type: int
label: Timeout
placeholder: "2"
placeholder: "2"
8 changes: 5 additions & 3 deletions tavern/tomes/process_list/main.eldritch
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ def process_list(cmd_substring):
if cmd_substring == '*':
cmd_substring = ''
procs = process.list()
print("PID,PPID,username,command")
print("PID,PPID,username,command\n")
for proc in procs:
if cmd_substring in proc['command']:
tmp_command = proc['command']
if tmp_command == "":
tmp_command = proc['name']
print(str(proc['pid'])+", "+str(proc['ppid'])+", "+proc['username']+", "+tmp_command)
print(str(proc['pid'])+", "+str(proc['ppid'])+", "+proc['username']+", "+tmp_command+"\n")

process_list(input_params['cmd_substring'])
process_list(input_params['cmd_substring'])
print("\n")
print("\n")
10 changes: 6 additions & 4 deletions tavern/tomes/shell_cmd/main.eldritch
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
def shell_cmd(cmd):
res = sys.shell(cmd)
print("stdout: {}".format(res['stdout']))
print("stderr: {}".format(res['stderr']))
print("status: {}".format(res['status']))
print("stdout: {}\n".format(res['stdout']))
print("stderr: {}\n".format(res['stderr']))
print("status: {}\n".format(res['status']))

shell_cmd(input_params['cmd'])
shell_cmd(input_params['cmd'])
print("\n")
print("\n")

0 comments on commit f130de1

Please sign in to comment.