Skip to content

Commit

Permalink
Remove newlines (#675)
Browse files Browse the repository at this point in the history
* remove newlines

* Add eprint

* Small tome fixes


---------

Co-authored-by: Hulto <[email protected]>
  • Loading branch information
Micah and hulto authored Feb 27, 2024
1 parent c468a7e commit 33b6eab
Show file tree
Hide file tree
Showing 21 changed files with 118 additions and 138 deletions.
2 changes: 1 addition & 1 deletion tavern/tomes/arp_scan/main.eldritch
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ def arp_scan():
ip_res = sys.get_ip()
# Get the first IP on each interface ignoring any `127.0.0.` ips
all_ips = [ iface['ips'][0] for iface in ip_res if len(iface['ips']) > 0 and '127.0.0.' not in " ".join(iface['ips']) ]
print(f"Scanning the following networks:\n{all_ips}\n")
print(f"Scanning the following networks:\n{all_ips}")
res = pivot.arp_scan(all_ips)
print(res)

Expand Down
6 changes: 1 addition & 5 deletions tavern/tomes/cat/main.eldritch
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
def cat(path):

if file.is_file(path):
res = file.read(path)
print(res)
print("\n")
else:
print("Error: Invalid Path ("+path+")\n")
eprint(f"Error: Invalid Path '{path}'")

return

cat(input_params['path'])
print("\n")
print("\n")
2 changes: 2 additions & 0 deletions tavern/tomes/download/main.eldritch
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ def main():
input_params['dst'],
input_params['insecure'].lower() == "true"
)

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

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

download_and_execute(input_params['url'])
print("\n")
print("\n")
27 changes: 14 additions & 13 deletions tavern/tomes/file_tree/main.eldritch
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,33 @@ block_list = ["/proc","/sys","/lib","/libx32","/lib32","/lib64","/boot","/srv","


def file_list(path,tree):
tree="|\t"+tree
tree=f"|\t{tree}"
files = file.list(path)
for f in files:
file_name = f['file_name']
if path+f['file_name'] in block_list:
print("Skipping: "+path+f['file_name']+"\n")
print(f"Skipping: {path}/{file_name}")
continue
if f['type'] == "Directory":
print(tree+"|---"+path+"/"+f['file_name']+"\n")
file_list(path+"/"+f['file_name'],tree)
print(f"{tree}|---{path}/{file_name}")
file_list(f"{path}/{file_name}",tree)
if f['type'] == "Link":
print(tree+"|---"+f['file_name']+"\n")
print(f"{tree}|---{file_name}")
if f['type'] == "File":
print(tree+"|---"+f['file_name']+"\n")
print(f"{tree}|---{file_name}")

def main(path):
tree=""
if file.is_dir(path):
print(path+"\n")
print(path+"")
if path == "/":
print("It looks like you're trying to list every file on the system.\n")
print("This generates a lot of data so I'm going to exclude less helpful directories\n")
print("If you really really want everything including /proc and /sys specify \"//\"\n")
print("It looks like you're trying to list every file on the system.")
print("This generates a lot of data so I'm going to exclude less helpful directories")
print("If you really really want everything including /proc and /sys specify \"//\"")
file_list(path,tree)
elif file.is_file(path):
print("Error: Invalid Path ("+path+")\n")
eprint(f"Error: Invalid Path ({path})")

input_params['path']="/"
main(input_params['path'])
print("\n")
print("\n")
print("")
4 changes: 1 addition & 3 deletions tavern/tomes/get_env/main.eldritch
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
def get_env():
envs = sys.get_env()
for key, value in envs.items():
print("{}={}\n".format(key, value))
print(f"{key}={value}")

return

get_env()
print("\n")
print("\n")
39 changes: 25 additions & 14 deletions tavern/tomes/get_net_info/main.eldritch
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
def get_net_info():
print("Interfaces:\n\n")
for interface in sys.get_ip():
for key, value in interface.items():
if key == "ips":
for ip in value:
print("ip: {}\n".format(ip))
else:
print("{}: {}\n".format(key, value))
print("\n")
print("Hostname: " + sys.hostname())
def print_table(rows: list[list]):
"""Pretty print a table, auto adjusting width based on the row data"""
def rpad(s: str, n: int, c=" "):
return s + (n-len(s))*c
# count columns
counts = [0]*len(rows[0])
for r in rows:
for i, f in enumerate(r):
counts[i] = max(len(f), counts[i])
# Print the columns
for r in rows:
row = []
for i, c in enumerate(r):
row.append(rpad(c, counts[i]+2))
print("".join(row))

get_net_info()
print("\n")
print("\n")
def ifconfig():
print("HOSTNAME "+ sys.hostname())
rows = [["IFACE", "IP", "MAC"]]
ip_res = sys.get_ip()
for interface in ip_res:
for ip in interface['ips']:
rows.append([interface['name'], ip, interface['mac']])
print_table(rows)

ifconfig()
6 changes: 3 additions & 3 deletions tavern/tomes/get_net_info/metadata.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Get net info
description: Get the network information for the system
author: Alextibtab
name: Get Network Info
description: Get the ip and network information for the system
author: hulto
support_model: FIRST_PARTY
tactic: RECON
1 change: 0 additions & 1 deletion tavern/tomes/hostname/main.eldritch

This file was deleted.

5 changes: 0 additions & 5 deletions tavern/tomes/hostname/metadata.yml

This file was deleted.

8 changes: 0 additions & 8 deletions tavern/tomes/ifconfig/main.eldritch

This file was deleted.

5 changes: 0 additions & 5 deletions tavern/tomes/ifconfig/metadata.yml

This file was deleted.

3 changes: 1 addition & 2 deletions tavern/tomes/kill_process/main.eldritch
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
process.kill(int(input_params['pid']))
print("\n")
print("\n")
print("")
8 changes: 3 additions & 5 deletions tavern/tomes/netstat/main.eldritch
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ def print_table(rows: list[list]):
counts[i] = max(len(f), counts[i])
# Print the columns
for r in rows:
row = []
for i, c in enumerate(r):
print(rpad(c, counts[i]+2))
print("\n")
row.append(rpad(c, counts[i]+2))
print("".join(row))

def netstat():
"""Pretty print the netstat results"""
Expand All @@ -34,7 +35,6 @@ def netstat():
remote = n.get("remote_address", "")
if remote:
fields[2] = remote + ":" + str(n.get("remote_port",))

# Established = ESTAB
if fields[3] == "ESTABLISHED":
fields[3] = fields[3][:5]
Expand All @@ -46,5 +46,3 @@ def netstat():
print_table(rows)

netstat()
print("\n")
print("\n")
5 changes: 2 additions & 3 deletions tavern/tomes/persist_service/main.eldritch
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,12 @@ 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\n")
eprint("OS not supported")

persist_service(
input_params['service_name'],
input_params['service_desc'],
input_params['executable_name'],
input_params['executable_url']
)
print("\n")
print("\n")
print("")
38 changes: 20 additions & 18 deletions tavern/tomes/port_scan/main.eldritch
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
def pad_number(num):
max_len = 5 # 65535
res = str(num)
for x in range(0, max_len - len(str(num))):
res = "0{}".format(res)
return res
def lpad(s: str, n: int, c=" "):
return (n-len(s))*c + s

def rpad(s: str, n: int, c=" "):
return str(s) + (n-len(s))*c

def sort_by_ip_then_port(test_dict):
return "{}{}".format(test_dict['ip'],pad_number(test_dict['port']))
"""Sort by ip, then by port. Update the pad counts as we go to save an iteration"""
# Sort IPs numerically
ips = []
for i in test_dict['ip'].split("."):
ips.append(lpad(i, 3, "0"))
return "{}{}".format(".".join(ips), lpad(str(test_dict['port']), 5, "0"))

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")
print("IPADDR PORT STATUS")
for p in sorted(scan_res, key=sort_by_ip_then_port):
print("{}{}{}".format(
rpad(p["ip"], 16), # 16 = Max width of ip + space
rpad(str(p["port"])+"/"+p["protocol"], 10), # 10 = max width of port + / + proto
p["status"],
))

def str_to_str_list(list_str):
list_str = list_str.removeprefix('[')
Expand All @@ -24,15 +32,9 @@ def str_to_int_list(list_str):
list_str = list_str.removesuffix(']')
return [int(x) for x in list_str.split(",")]


tmp_input_cidrs = str_to_str_list(input_params['cidrs'])
tmp_input_ports = str_to_int_list(input_params['ports'])

port_scan(
tmp_input_cidrs,
tmp_input_ports,
str_to_str_list(input_params['cidrs']),
str_to_int_list(input_params['ports']),
input_params['protocol'],
int(input_params['timeout'])
)
print("\n")
print("\n")
13 changes: 6 additions & 7 deletions tavern/tomes/process_info/main.eldritch
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ def process_info(pid):
info = process.info(sys.get_pid() if pid == -1 else pid)
for key, value in info.items():
if key == "cmd":
print("cmd_args=\n")
print("cmd_args=")
for nested_value in value.split(" "):
print("\t- {}\n".format(nested_value))
print("\t- {}".format(nested_value))
elif key == "environ":
print("env_variables=\n")
print("env_variables=")
for nested_value in value.split(","):
print("\t- {}\n".format(nested_value))
print("\t- {}".format(nested_value))
else:
print("{}={}\n".format(key, value))
print("{}={}".format(key, value))

process_info(int(input_params['pid']))
print("\n")
print("\n")
print("")
48 changes: 25 additions & 23 deletions tavern/tomes/process_list/main.eldritch
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
def pad_pid(pid):
pid_column_width = 16
padding = pid_column_width - len(pid)
return pid + " "*padding

def pad_username (username):
username_column_width = 32
padding = username_column_width - len(username)
return username + " "*padding
def print_table(rows: list[list]):
"""Pretty print a table, auto adjusting width based on the row data"""
def rpad(s: str, n: int, c=" "):
return s + (n-len(s))*c
# count columns
counts = [0]*len(rows[0])
for r in rows:
for i, f in enumerate(r):
counts[i] = max(len(f), counts[i])
counts[-1] = 0
# Print the columns
for r in rows:
row = []
for i, c in enumerate(r):
row.append(rpad(c, counts[i]+2))
print("".join(row))

def process_list(cmd_substring):

Expand All @@ -15,26 +22,21 @@ def process_list(cmd_substring):

procs = process.list()

print(pad_pid("PID"))
print(pad_pid("PPID"))
print(pad_username("username"))
print("command\n")

rows = [["PID", "PPID", "USER","COMMAND"]]
for proc in procs:
if cmd_substring in proc['command']:
current_proc_command = proc['command']
if current_proc_command == "":
current_proc_command = proc['name']

current_proc_pid = str(proc['pid'])
current_proc_ppid = str(proc['ppid'])
current_proc_username = proc['username']
rows.append([
str(proc['pid']),
str(proc['ppid']),
proc['username'],
current_proc_command.replace("\n","\\n")
])

print(pad_pid(current_proc_pid))
print(pad_pid(current_proc_ppid))
print(pad_username(current_proc_username))
print(current_proc_command.replace("\n","\\n")+"\n")
print_table(rows)

process_list(input_params['cmd_substring'])
print("\n")
print("\n")
print("")
Loading

0 comments on commit 33b6eab

Please sign in to comment.