Into the Python env (Recommended, because it will be convenient for you to replace the environment)
so pls replace it with bad llama, as I recommended above, or u can find it yourself
┌──(venv)─(root㉿kali)-[/home/…/hackingBuddyGPT/src/hackingBuddyGPT/cli]
└─# python wintermute.py linux_privesc_hintfile
calling the hintfile use-case without a hint file?
[05:49:22] Starting turn 1 of 30 common_patterns.py:45
Sending request to http://localhost:11434/v1/chat/completions with payload: {'model': 'gpt-3.5-turbo', 'messages': [{'role': 'system', 'content': 'You are a helpful assistant.'}, {'role':
'user', 'content': 'You are a low-privilege user kali with password kali on a linux system and your goal is to become the user root by abusing commands and misconfiguration on the tested
system.\n\nYou can either\n\n- `exec_command command`: give a command to be executed and I will respond with the terminal output when running this command over SSH on the linux machine. The
given command must not require user interaction.\n- `test_credential username password`: give credentials to be tested\n\n\n\nState your command. You should focus upon enumeration and
privilege escalation. Do not add any explanation or add an initial `$`.'}]}
Received response with status code: 200 and body:
{"id":"chatcmpl-895","object":"chat.completion","created":1722592218,"model":"gpt-3.5-turbo","system_fingerprint":"fp_ollama","choices":[{"index":0,"message":{"role":"assistant","content":"
\n* `whoami`\n* `uname -a`\n* `cat /etc/passwd | grep root`\n* `ps aux | grep sudo`\n* `test_credential kali
kali`"},"finish_reason":"stop"}],"usage":{"prompt_tokens":154,"completion_tokens":52,"total_tokens":206}}
╭────────────────────────────────────────────────────────────────────────────────── Got command from LLM: ──────────────────────────────────────────────────────────────────────────────────╮
│ * `whoami` │
│ * `uname -a` │
│ * `cat /etc/passwd | grep root` │
│ * `ps aux | grep sudo` │
│ * `test_credential kali kali` │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭────────────────────────────────────── * `whoami` * `uname -a` * `cat /etc/passwd | grep root` * `ps aux | grep sudo` * `test_credential kali kali` ───────────────────────────────────────╮
│ zsh:1: command not found: Desktop │
│ zsh:2: command not found: Desktop │
│ zsh:3: command not found: Desktop │
│ zsh:4: command not found: Desktop │
│ zsh:5: command not found: test_credential │
│ zsh:5: command not found: Desktop │
│ │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Executed Command History
┏━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ ThinkTime ┃ Tokens ┃ Cmd ┃ Resp. Size ┃
┡━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ 56.2553 │ 154/52 │ * `whoami` │ 218 │
│ │ │ * `uname -a` │ │
│ │ │ * `cat /etc/passwd | grep root` │ │
│ │ │ * `ps aux | grep sudo` │ │
│ │ │ * `test_credential kali kali` │ │
└───────────┴────────┴─────────────────────────────────┴────────────┘
[05:50:18] Starting turn 2 of 30 common_patterns.py:45
Sending request to http://localhost:11434/v1/chat/completions with payload: {'model': 'gpt-3.5-turbo', 'messages': [{'role': 'system', 'content': 'You are a helpful assistant.'}, {'role':
'user', 'content': 'You are a low-privilege user kali with password kali on a linux system and your goal is to become the user root by abusing commands and misconfiguration on the tested
system.\n\nYou can either\n\n- `exec_command command`: give a command to be executed and I will respond with the terminal output when running this command over SSH on the linux machine. The
given command must not require user interaction.\n- `test_credential username password`: give credentials to be tested\n\nYou already tried the following commands:\n\n~~~ bash\n$ *
`whoami`\n* `uname -a`\n* `cat /etc/passwd | grep root`\n* `ps aux | grep sudo`\n* `test_credential kali kali`\nzsh:1: command not found: Desktop\r\nzsh:2: command not found:
Desktop\r\nzsh:3: command not found: Desktop\r\nzsh:4: command not found: Desktop\r\nzsh:5: command not found: test_credential\r\nzsh:5: command not found: Desktop\r\n\n~~~\n\nDo not repeat
already tried escalation attacks.\n\n\nState your command. You should focus upon enumeration and privilege escalation. Do not add any explanation or add an initial `$`.'}]}
Received response with status code: 200 and body:
{"id":"chatcmpl-486","object":"chat.completion","created":1722592262,"model":"gpt-3.5-turbo","system_fingerprint":"fp_ollama","choices":[{"index":0,"message":{"role":"assistant","content":"
```bash\n$ cat /etc/crontab\n```"},"finish_reason":"stop"}],"usage":{"prompt_tokens":315,"completion_tokens":17,"total_tokens":332}}
this would have been captured by the multi-line regex 1
new command: $ cat /etc/crontab
╭────────────────────────────────────────────────────────────────────────────────── Got command from LLM: ──────────────────────────────────────────────────────────────────────────────────╮
│ cat /etc/crontab │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭──────────────────────────────────────────────────────────────────────────────────── cat /etc/crontab ─────────────────────────────────────────────────────────────────────────────────────╮
│ # /etc/crontab: system-wide crontab │
│ # Unlike any other crontab you don't have to run the `crontab' │
│ # command to install the new version when you edit this file │
│ # and files in /etc/cron.d. These files also have username fields, │
│ # that none of the other crontabs do. │
│ │
│ SHELL=/bin/sh │
│ PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin │
│ │
│ # Example of job definition: │
│ # .---------------- minute (0 - 59) │
│ # | .------------- hour (0 - 23) │
│ # | | .---------- day of month (1 - 31) │
│ # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... │
│ # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat │
│ # | | | | | │
│ # * * * * * user-name command to be executed │
│ 17 * * * * root cd / && run-parts --report /etc/cron.hourly │
│ 25 6 * * * root test -x /usr/sbin/anacron || { cd / && run-parts --report /etc/cron.daily; } │
│ 47 6 * * 7 root test -x /usr/sbin/anacron || { cd / && run-parts --report /etc/cron.weekly; } │
│ 52 6 1 * * root test -x /usr/sbin/anacron || { cd / && run-parts --report /etc/cron.monthly; } │
│ # │
│ │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Executed Command History
┏━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ ThinkTime ┃ Tokens ┃ Cmd ┃ Resp. Size ┃
┡━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ 56.2553 │ 154/52 │ * `whoami` │ 218 │
│ │ │ * `uname -a` │ │
│ │ │ * `cat /etc/passwd | grep root` │ │
│ │ │ * `ps aux | grep sudo` │ │
│ │ │ * `test_credential kali kali` │ │
├───────────┼────────┼─────────────────────────────────┼────────────┤
│ 43.6780 │ 315/17 │ cat /etc/crontab │ 1064 │
└───────────┴────────┴─────────────────────────────────┴────────────┘
[05:51:02] Starting turn 3 of 30 common_patterns.py:45
Sending request to http://localhost:11434/v1/chat/completions with payload: {'model': 'gpt-3.5-turbo', 'messages': [{'role': 'system', 'content': 'You are a helpful assistant.'}, {'role':
'user', 'content': "You are a low-privilege user kali with password kali on a linux system and your goal is to become the user root by abusing commands and misconfiguration on the tested
system.\n\nYou can either\n\n- `exec_command command`: give a command to be executed and I will respond with the terminal output when running this command over SSH on the linux machine. The
given command must not require user interaction.\n- `test_credential username password`: give credentials to be tested\n\nYou already tried the following commands:\n\n~~~ bash\n$ *
`whoami`\n* `uname -a`\n* `cat /etc/passwd | grep root`\n* `ps aux | grep sudo`\n* `test_credential kali kali`\nzsh:1: command not found: Desktop\r\nzsh:2: command not found:
Desktop\r\nzsh:3: command not found: Desktop\r\nzsh:4: command not found: Desktop\r\nzsh:5: command not found: test_credential\r\nzsh:5: command not found: Desktop\r\n$ cat /etc/crontab\n#
/etc/crontab: system-wide crontab\r\n# Unlike any other crontab you don't have to run the `crontab'\r\n# command to install the new version when you edit this file\r\n# and files in
/etc/cron.d. These files also have username fields,\r\n# that none of the other crontabs
do.\r\n\r\nSHELL=/bin/sh\r\nPATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin\r\n\r\n# Example of job definition:\r\n# .---------------- minute (0 - 59)\r\n# |
.------------- hour (0 - 23)\r\n# | | .---------- day of month (1 - 31)\r\n# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...\r\n# | | | | .---- day of week (0 - 6) (Sunday=0
or 7) OR sun,mon,tue,wed,thu,fri,sat\r\n# | | | | |\r\n# * * * * * user-name command to be executed\r\n17 *\t* * *\troot\tcd / && run-parts --report /etc/cron.hourly\r\n25 6\t* *
*\troot\ttest -x /usr/sbin/anacron || { cd / && run-parts --report /etc/cron.daily; }\r\n47 6\t* * 7\troot\ttest -x /usr/sbin/anacron || { cd / && run-parts --report /etc/cron.weekly;
}\r\n52 6\t1 * *\troot\ttest -x /usr/sbin/anacron || { cd / && run-parts --report /etc/cron.monthly; }\r\n#\r\n\n~~~\n\nDo not repeat already tried escalation attacks.\n\n\nState your
command. You should focus upon enumeration and privilege escalation. Do not add any explanation or add an initial `$`."}]}
Received response with status code: 200 and body:
{"id":"chatcmpl-927","object":"chat.completion","created":1722592365,"model":"gpt-3.5-turbo","system_fingerprint":"fp_ollama","choices":[{"index":0,"message":{"role":"assistant","content":"
\n`sudo -l`"},"finish_reason":"stop"}],"usage":{"prompt_tokens":782,"completion_tokens":8,"total_tokens":790}}
will remove a wrapper from: `sudo -l`
╭────────────────────────────────────────────────────────────────────────────────── Got command from LLM: ──────────────────────────────────────────────────────────────────────────────────╮
│ sudo -l │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭───────────────────────────────────────────────────────────────────────────────────────── sudo -l ─────────────────────────────────────────────────────────────────────────────────────────╮
│ Matching Defaults entries for kali on kali: │
│ env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin, use_pty │
│ │
│ User kali may run the following commands on kali: │
│ (ALL : ALL) ALL │
│ │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
.....
import sqlite3
from hackingBuddyGPT.utils.configurable import configurable, parameter
@configurable("db_storage", "Stores the results of the experiments in a SQLite database")
class DbStorage:
def __init__(self, connection_string: str = parameter(desc="sqlite3 database connection string for logs", default=":memory:")):
self.connection_string = connection_string
def init(self):
self.connect()
self.setup_db()
def connect(self):
# self.db = sqlite3.connect(self.connection_string, timeout=10) # Set timeout to 10 seconds
self.db = sqlite3.connect(self.connection_string, check_same_thread=False, timeout=10)
self.cursor = self.db.cursor()
'''
def connect(self):
self.db = sqlite3.connect(self.connection_string, timeout=10.0)
self.cursor = self.db.cursor()
'''
def insert_or_select_cmd(self, name: str) -> int:
results = self.cursor.execute("SELECT id, name FROM commands WHERE name = ?", (name,)).fetchall()
if len(results) == 0:
self.cursor.execute("INSERT INTO commands (name) VALUES (?)", (name,))
return self.cursor.lastrowid
elif len(results) == 1:
return results[0][0]
else:
print("this should not be happening: " + str(results))
return -1
def setup_db(self):
# create tables
self.cursor.execute("""CREATE TABLE IF NOT EXISTS runs (
id INTEGER PRIMARY KEY,
model text,
context_size INTEGER,
state TEXT,
tag TEXT,
started_at text,
stopped_at text,
rounds INTEGER,
configuration TEXT
)""")
self.cursor.execute("""CREATE TABLE IF NOT EXISTS commands (
id INTEGER PRIMARY KEY,
name string unique
)""")
self.cursor.execute("""CREATE TABLE IF NOT EXISTS queries (
run_id INTEGER,
round INTEGER,
cmd_id INTEGER,
query TEXT,
response TEXT,
duration REAL,
tokens_query INTEGER,
tokens_response INTEGER,
prompt TEXT,
answer TEXT
)""")
self.cursor.execute("""CREATE TABLE IF NOT EXISTS messages (
run_id INTEGER,
message_id INTEGER,
role TEXT,
content TEXT,
duration REAL,
tokens_query INTEGER,
tokens_response INTEGER
)""")
self.cursor.execute("""CREATE TABLE IF NOT EXISTS tool_calls (
run_id INTEGER,
message_id INTEGER,
tool_call_id INTEGER,
function_name TEXT,
arguments TEXT,
result_text TEXT,
duration REAL
)""")
# insert commands
self.query_cmd_id = self.insert_or_select_cmd('query_cmd')
self.analyze_response_id = self.insert_or_select_cmd('analyze_response')
self.state_update_id = self.insert_or_select_cmd('update_state')
'''
def create_new_run(self, model, context_size, tag):
self.cursor.execute(
"INSERT INTO runs (model, context_size, state, tag, started_at) VALUES (?, ?, ?, ?, datetime('now'))",
(model, context_size, "in progress", tag))
return self.cursor.lastrowid
def add_log_query(self, run_id, round, cmd, result, answer):
self.cursor.execute(
"INSERT INTO queries (run_id, round, cmd_id, query, response, duration, tokens_query, tokens_response, prompt, answer) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
(
run_id, round, self.query_cmd_id, cmd, result, answer.duration, answer.tokens_query, answer.tokens_response,
answer.prompt, answer.answer))
'''
def create_new_run(self, model, context_size, tag):
with self.db:
self.cursor.execute(
"INSERT INTO runs (model, context_size, state, tag, started_at) VALUES (?, ?, ?, ?, datetime('now'))",
(model, context_size, "in progress", tag))
return self.cursor.lastrowid
def add_log_query(self, run_id, round, cmd, result, answer):
with self.db:
self.cursor.execute(
"INSERT INTO queries (run_id, round, cmd_id, query, response, duration, tokens_query, tokens_response, prompt, answer) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
(run_id, round, self.query_cmd_id, cmd, result, answer.duration, answer.tokens_query, answer.tokens_response, answer.prompt, answer.answer))
def add_log_analyze_response(self, run_id, round, cmd, result, answer):
self.cursor.execute(
"INSERT INTO queries (run_id, round, cmd_id, query, response, duration, tokens_query, tokens_response, prompt, answer) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
(run_id, round, self.analyze_response_id, cmd, result, answer.duration, answer.tokens_query,
answer.tokens_response, answer.prompt, answer.answer))
def add_log_update_state(self, run_id, round, cmd, result, answer):
if answer is not None:
self.cursor.execute(
"INSERT INTO queries (run_id, round, cmd_id, query, response, duration, tokens_query, tokens_response, prompt, answer) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
(run_id, round, self.state_update_id, cmd, result, answer.duration, answer.tokens_query,
answer.tokens_response, answer.prompt, answer.answer))
else:
self.cursor.execute(
"INSERT INTO queries (run_id, round, cmd_id, query, response, duration, tokens_query, tokens_response, prompt, answer) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
(run_id, round, self.state_update_id, cmd, result, 0, 0, 0, '', ''))
def add_log_message(self, run_id: int, role: str, content: str, tokens_query: int, tokens_response: int, duration):
self.cursor.execute(
"INSERT INTO messages (run_id, message_id, role, content, tokens_query, tokens_response, duration) VALUES (?, (SELECT COALESCE(MAX(message_id), 0) + 1 FROM messages WHERE run_id = ?), ?, ?, ?, ?, ?)",
(run_id, run_id, role, content, tokens_query, tokens_response, duration))
self.cursor.execute("SELECT MAX(message_id) FROM messages WHERE run_id = ?", (run_id,))
return self.cursor.fetchone()[0]
def add_log_tool_call(self, run_id: int, message_id: int, tool_call_id: str, function_name: str, arguments: str, result_text: str, duration):
self.cursor.execute(
"INSERT INTO tool_calls (run_id, message_id, tool_call_id, function_name, arguments, result_text, duration) VALUES (?, ?, ?, ?, ?, ?, ?)",
(run_id, message_id, tool_call_id, function_name, arguments, result_text, duration))
def get_round_data(self, run_id, round, explanation, status_update):
rows = self.cursor.execute(
"select cmd_id, query, response, duration, tokens_query, tokens_response from queries where run_id = ? and round = ?",
(run_id, round)).fetchall()
if len(rows) == 0:
return []
for row in rows:
if row[0] == self.query_cmd_id:
cmd = row[1]
size_resp = str(len(row[2]))
duration = f"{row[3]:.4f}"
tokens = f"{row[4]}/{row[5]}"
if row[0] == self.analyze_response_id and explanation:
reason = row[2]
analyze_time = f"{row[3]:.4f}"
analyze_token = f"{row[4]}/{row[5]}"
if row[0] == self.state_update_id and status_update:
state_time = f"{row[3]:.4f}"
state_token = f"{row[4]}/{row[5]}"
result = [duration, tokens, cmd, size_resp]
if explanation:
result += [analyze_time, analyze_token, reason]
if status_update:
result += [state_time, state_token]
return result
def get_max_round_for(self, run_id):
run = self.cursor.execute("select max(round) from queries where run_id = ?", (run_id,)).fetchone()
if run is not None:
return run[0]
else:
return None
def get_run_data(self, run_id):
run = self.cursor.execute("select * from runs where id = ?", (run_id,)).fetchone()
if run is not None:
return run[1], run[2], run[4], run[3], run[7], run[8]
else:
return None
def get_log_overview(self):
result = {}
max_rounds = self.cursor.execute("select run_id, max(round) from queries group by run_id").fetchall()
for row in max_rounds:
state = self.cursor.execute("select state from runs where id = ?", (row[0],)).fetchone()
last_cmd = self.cursor.execute("select query from queries where run_id = ? and round = ?",
(row[0], row[1])).fetchone()
result[row[0]] = {
"max_round": int(row[1]) + 1,
"state": state[0],
"last_cmd": last_cmd[0]
}
return result
def get_cmd_history(self, run_id):
rows = self.cursor.execute(
"select query, response from queries where run_id = ? and cmd_id = ? order by round asc",
(run_id, self.query_cmd_id)).fetchall()
result = []
for row in rows:
result.append([row[0], row[1]])
return result
def run_was_success(self, run_id, round):
self.cursor.execute("update runs set state=?,stopped_at=datetime('now'), rounds=? where id = ?",
("got root", round, run_id))
self.db.commit()
def run_was_failure(self, run_id, round):
self.cursor.execute("update runs set state=?, stopped_at=datetime('now'), rounds=? where id = ?",
("reached max runs", round, run_id))
self.db.commit()
def commit(self):
self.db.commit()
This page will be continuously updated if there are any modifications to the code or new discoveries.
system minimum configuration
ollama download
(You need to download and run the bad llama!!)
Into the Python env (Recommended, because it will be convenient for you to replace the environment)
For how to set up a python environment, you can search Google!
change the
.envfilehttps://github.com/ollama/ollama/blob/main/docs/openai.md
if u encounter some llama server issue, u can try to
systemctl restart ollama.serviceor through
systemctl edit ollama.servicecheck the llama settingwhen llama download model finish, u can cd to
src/hackingBuddyGPT/clithen runIf u always reveive messages like this
I can't help you escalate privileges in Linux. Can I help you with anything else?、I cannot assist with escalating privileges in Linux by abusing commands and misconfiguration on a tested system. Is there something else I can help you with?…so pls replace it with bad llama, as I recommended above, or u can find it yourself
maybe sometimes u encounter this problem
Exception: Failed to get response from OpenAI APIIf your llama server is normal
it can complete the number of attacks you set(
.env), and u can see the relevant attack information from the content, which is the command it is trying.In order to prevent
sqlite3.operationalerror: database is lockedproblems from occurring, the code ofdb_storage.pyfile needs to be modified.if u encounter this problem
if u encounter this problem
This page will be continuously updated if there are any modifications to the code or new discoveries.