-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from ipa-lab/v7
V7
- Loading branch information
Showing
9 changed files
with
272 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import re | ||
|
||
def remove_wrapping_characters(cmd:str, wrappers:str) -> str: | ||
if len(cmd) < 2: | ||
return cmd | ||
if cmd[0] == cmd[-1] and cmd[0] in wrappers: | ||
print("will remove a wrapper from: " + cmd) | ||
return remove_wrapping_characters(cmd[1:-1], wrappers) | ||
return cmd | ||
|
||
# often the LLM produces a wrapped command | ||
def cmd_output_fixer(cmd:str) -> str: | ||
|
||
cmd = cmd.strip(" \n") | ||
if len(cmd) < 2: | ||
return cmd | ||
|
||
stupidity = re.compile(r"^[ \n\r]*```.*\n(.*)\n```$", re.MULTILINE) | ||
result = stupidity.search(cmd) | ||
if result: | ||
print("this would have been captured by the multi-line regex 1") | ||
cmd = result.group(1) | ||
print("new command: " + cmd) | ||
stupidity = re.compile(r"^[ \n\r]*~~~.*\n(.*)\n~~~$", re.MULTILINE) | ||
result = stupidity.search(cmd) | ||
if result: | ||
print("this would have been captured by the multi-line regex 2") | ||
cmd = result.group(1) | ||
print("new command: " + cmd) | ||
stupidity = re.compile(r"^[ \n\r]*~~~.*\n(.*)\n~~~$", re.MULTILINE) | ||
|
||
cmd = remove_wrapping_characters(cmd, "`'\"") | ||
|
||
if cmd.startswith("$ "): | ||
cmd = cmd[2:] | ||
|
||
return cmd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/python3 | ||
|
||
import argparse | ||
import os | ||
|
||
from db_storage import DbStorage | ||
from rich.console import Console | ||
from rich.panel import Panel | ||
from rich.table import Table | ||
|
||
# setup infrastructure for outputing information | ||
console = Console() | ||
|
||
parser = argparse.ArgumentParser(description='View an existing log file.') | ||
parser.add_argument('log', type=str, help='sqlite3 db for reading log data') | ||
args = parser.parse_args() | ||
console.log(args) | ||
|
||
# setup in-memory/persistent storage for command history | ||
db = DbStorage(args.log) | ||
db.connect() | ||
db.setup_db() | ||
|
||
# experiment names | ||
names = { | ||
"1" : "suid-gtfo", | ||
"2" : "sudo-all", | ||
"3" : "sudo-gtfo", | ||
"4" : "docker", | ||
"5" : "cron-script", | ||
"6" : "pw-reuse", | ||
"7" : "pw-root", | ||
"8" : "vacation", | ||
"9" : "ps-bash-hist", | ||
"10" : "cron-wildcard", | ||
"11" : "ssh-key", | ||
"12" : "cron-script-vis", | ||
"13" : "cron-wildcard-vis" | ||
} | ||
|
||
# prepare table | ||
table = Table(title="Round Data", show_header=True, show_lines=True) | ||
table.add_column("RunId", style="dim") | ||
table.add_column("Description", style="dim") | ||
table.add_column("Round", style="dim") | ||
table.add_column("State") | ||
table.add_column("Last Command") | ||
|
||
data = db.get_log_overview() | ||
for run in data: | ||
row = data[run] | ||
table.add_row(str(run), names[str(run)], str(row["max_round"]), row["state"], row["last_cmd"]) | ||
|
||
console.print(table) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.