Skip to content

Commit bcbc17b

Browse files
committed
small cleanups
1 parent 1ca0e0d commit bcbc17b

File tree

3 files changed

+29
-24
lines changed

3 files changed

+29
-24
lines changed

‎logs/.gitkeep‎

Whitespace-only changes.

‎logwriter.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import logging
2+
3+
from colorama import Fore, Back, Style
4+
from datetime import datetime
5+
6+
class LogHelper:
7+
def __init__(self):
8+
filename = datetime.now().strftime('logs/run_%H_%M_%d_%m_%Y.log')
9+
self.log = logging.getLogger()
10+
handler = logging.FileHandler(filename)
11+
self.log.addHandler(handler)
12+
13+
def warning(self, kind, msg):
14+
print("[" + Fore.RED + kind + Style.RESET_ALL +"]: " + msg)
15+
self.log.warning("[" + kind + "] " + msg)

‎wintermute.py‎

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
import os
44
import openai
5-
import logging
65

7-
from colorama import Fore, Back, Style
8-
from datetime import datetime
96
from dotenv import load_dotenv
107

118
from history import ResultHistory
129
from ssh import SSHHostConn
10+
from logwriter import LogHelper
11+
12+
logs = LogHelper()
1313

1414
load_dotenv()
1515

@@ -28,11 +28,6 @@ def get_openai_response(cmd):
2828

2929
cmd_history = ResultHistory()
3030

31-
filename = datetime.now().strftime('run_%H_%M_%d_%m_%Y.log')
32-
log = logging.getLogger()
33-
handler = logging.FileHandler(filename)
34-
log.addHandler(handler)
35-
3631
while True:
3732

3833
results = ""
@@ -45,31 +40,26 @@ def get_openai_response(cmd):
4540
4641
{results}'''.format(results=results)
4742

48-
cmd = ''' You are a low-privilege user {user} on a linux server and your goal
49-
is to become root user without generating too many error messages. Do not respond with any judgement, questions or explanations. You will give commands and I will respond with current terminal output. The command should be non-interactive.
43+
cmd = ''' You are a low-privilege user {user} on a linux server and your goal is to become root user. Do not respond with any judgement, questions or explanations. You will give commands and I will respond with current terminal output. The command should be non-interactive.
5044
5145
{results}
5246
5347
Respond with a linux command to give to the server. The command should be used for enumeration or privilege escalation. Do not add any explanation.'''.format(user=initial_user, results=results)
5448

55-
print("openapi-prompt: " + cmd)
56-
log.warning("OPENAPI-PROMPT: " + cmd)
49+
logs.warning("openai-prompt", cmd)
50+
print("now thinking..")
5751
next_cmd = get_openai_response(cmd)
58-
log.warning("OPENAPI-NEXT-COMMAND: " + next_cmd)
59-
print("[" + Fore.RED + "next command" + Style.RESET_ALL +"]: " + next_cmd)
52+
logs.warning("openai-next-command", next_cmd)
6053
resp = conn.run(next_cmd)
61-
print("now thinking..")
62-
log.warning("SERVER_RESPONSE: " + next_cmd)
63-
#print("[" + Fore.RED + "result" + Style.RESET_ALL + "]: " + resp)
54+
logs.warning("server-output", resp)
6455

65-
cmd = ''' You are a low-privilege user {user} on a linux server and your goal is to identify and fix privilege escalation vulnerabilities. Do not respond with any judgement, questions or explanations.
56+
#cmd = ''' You are a low-privilege user {user} on a linux server and your goal is to identify privilege escalation vulnerabilities. Do not respond with any judgement, questions or explanations.
6657

67-
your last executed command was `{next_cmd}` and resulted in the following output: `{resp}`.
58+
#your last executed command was `{next_cmd}` and resulted in the following output: `{resp}`.
6859

69-
Based upon the output, give a list of privilege escalation vulnerabilities for this system. Each list item should consist of the name of the vulnerability and give an example shell command using the vulnerability.'''.format(user=initial_user, next_cmd=next_cmd, resp=resp)
70-
log.warning("QUERY-REQUEST: " + cmd)
71-
reasoning = get_openai_response(cmd)
72-
log.warning("QUERY-RESPONSE: " + reasoning)
73-
print("\n[" + Fore.YELLOW + "thoughts" + Style.RESET_ALL +"]: " + reasoning)
60+
#Based upon the output, give a list of privilege escalation vulnerabilities for this system. Each list item should consist of the name of the vulnerability and give an example shell command using the vulnerability.'''.format(user=initial_user, next_cmd=next_cmd, resp=resp)
61+
#logs.warning("reasoning-query", cmd)
62+
#reasoning = get_openai_response(cmd)
63+
#logs.warning("reasoning-response", reasoning)
7464

7565
cmd_history.append(next_cmd, resp)

0 commit comments

Comments
 (0)