Skip to content

Commit fc8d9d6

Browse files
committed
initial minimal prototype
0 parents  commit fc8d9d6

File tree

5 files changed

+128
-0
lines changed

5 files changed

+128
-0
lines changed

.env.example

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
OPENAI_KEY="your-openai-key"
2+
MODEL="gpt-3.5-turbo"
3+
4+
# exchange with the IP of your target VM
5+
TARGET_IP='enter-the-private-ip-of-some-vm.local'
6+
7+
# exchange with the user for your target VM
8+
TARGET_USER='bob'
9+
TARGET_PASSWORD='secret'

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.env

history.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class ResultHistory:
2+
def __init__(self):
3+
self.data = []
4+
5+
def append(self, cmd, result):
6+
self.data.append({
7+
"cmd": cmd,
8+
"result": result
9+
})
10+
11+
def dump(self):
12+
return self.data
13+

ssh.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from fabric import Connection
2+
from invoke import Responder
3+
4+
class SSHHostConn:
5+
6+
def __init__(self, host, username, password):
7+
self.host = host
8+
self.username = username
9+
self.password = password
10+
11+
def connect(self):
12+
# create the SSH Connection
13+
conn = Connection(
14+
"{username}@{ip}:{port}".format(
15+
username=self.username,
16+
ip=self.host,
17+
port=22,
18+
),
19+
connect_kwargs={"password": self.password},
20+
)
21+
self.conn=conn
22+
23+
def run(self, cmd):
24+
sudopass = Responder(
25+
pattern=r'\[sudo\] password for ' + self.username + ':',
26+
response=self.password + '\n',
27+
)
28+
resp = self.conn.run(cmd, pty=True, warn=True, watchers=[sudopass])
29+
tmp = resp.stdout
30+
return tmp.replace('[sudo] password for ' + self.username + ':', '').strip()

wintermute.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/usr/bin/python
2+
3+
import os
4+
import openai
5+
import logging
6+
7+
from colorama import Fore, Back, Style
8+
from datetime import datetime
9+
from dotenv import load_dotenv
10+
11+
from history import ResultHistory
12+
from ssh import SSHHostConn
13+
14+
load_dotenv()
15+
16+
openai.api_key = os.getenv('OPENAI_KEY')
17+
model = os.getenv('MODEL')
18+
19+
conn = SSHHostConn(os.getenv('TARGET_IP'), os.getenv('TARGET_USER'), os.getenv('TARGET_PASSWORD'))
20+
conn.connect()
21+
22+
initial_user = conn.run("whoami")
23+
24+
def get_openai_response(cmd):
25+
completion = openai.ChatCompletion.create(model=model, messages=[{"role": "user", "content" : cmd}])
26+
result = completion.choices[0].message.content
27+
return result
28+
29+
cmd_history = ResultHistory()
30+
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+
36+
while True:
37+
38+
results = ""
39+
40+
for old in cmd_history.dump():
41+
results = results + "- When you executed the command:`" + old["cmd"] + "` the console output was: `" + old["result"] + "\n"
42+
43+
if results != "":
44+
results = '''Results for already executed commands were:
45+
46+
{results}'''.format(results=results)
47+
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.
50+
51+
{results}
52+
53+
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)
54+
55+
print("openapi-prompt: " + cmd)
56+
log.warning("OPENAPI-PROMPT: " + cmd)
57+
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)
60+
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)
64+
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.
66+
67+
your last executed command was `{next_cmd}` and resulted in the following output: `{resp}`.
68+
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)
74+
75+
cmd_history.append(next_cmd, resp)

0 commit comments

Comments
 (0)