Skip to content

Commit d2421f7

Browse files
authored
Merge pull request #108 from jamfish/jf-sshauthupdate
Add SSH Key Auth [Follow-up]
2 parents 178abe4 + 17e1799 commit d2421f7

File tree

5 files changed

+47
-8
lines changed

5 files changed

+47
-8
lines changed

.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ conn.port=2222
88

99
# exchange with the user for your target VM
1010
conn.username='bob'
11+
#To just use keyauth only, use '' with no space for conn.password
12+
#Otherwise, insert the password for instance here
1113
conn.password='secret'
14+
#To just use username and password auth only, use '' with no space for conn.keyfilename
15+
#Otherwise, insert the filepath for the keyfile here (for example, '/home/bob/.ssh/sshkey.rsa')
16+
conn.keyfilename=''
1217

1318
# which LLM model to use (can be anything openai supports, or if you use a custom llm.api_url, anything your api provides for the model parameter
1419
llm.model='gpt-3.5-turbo'

.env.example.aws

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
llm.api_key='your-openai-key'
2+
log_db.connection_string='log_db.sqlite3'
3+
4+
# exchange with the IP of your target VM
5+
conn.host='enter the public IP of AWS Instance'
6+
conn.hostname='DNS of AWS Instance '
7+
conn.port=22
8+
9+
# user of target AWS Instance
10+
conn.username='bob'
11+
#To just use keyauth only, use '' with no space for conn.password
12+
#Otherwise, insert the password for instance here
13+
conn.password=''
14+
#To just use username and password auth only, use '' with no space for conn.keyfilename
15+
#Otherwise, insert the filepath for the keyfile here (for example, '/home/bob/.ssh/awskey.pem')
16+
conn.keyfilename='/home/bob/.ssh/awskey.pem'
17+
18+
# which LLM model to use (can be anything openai supports, or if you use a custom llm.api_url, anything your api provides for the model parameter
19+
llm.model='gpt-3.5-turbo'
20+
llm.context_size=16385
21+
22+
# how many rounds should this thing go?
23+
max_turns = 20

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,12 @@ $ source ./venv/bin/activate
166166
# install python requirements
167167
$ pip install -e .
168168

169-
# copy default .env.example
169+
# copy default .env.example
170170
$ cp .env.example .env
171171

172+
# NOTE: if you are trying to use this with AWS or ssh-key only authentication, copy .env.example.aws
173+
$ cp .env.example.aws .env
174+
172175
# IMPORTANT: setup your OpenAI API key, the VM's IP and credentials within .env
173176
$ vi .env
174177

src/hackingBuddyGPT/capabilities/ssh_test_credential.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ def describe(self) -> str:
1818
def get_name(self):
1919
return "test_credential"
2020

21-
def __call__(self, username: str, password: str) -> Tuple[str, bool]:
22-
test_conn = self.conn.new_with(username=username, password=password)
21+
def __call__(self, username: str, password: str, keyfilename: str) -> Tuple[str, bool]:
22+
test_conn = self.conn.new_with(username=username, password=password, keyfilename=keyfilename)
2323
try:
2424
test_conn.init()
2525
user = test_conn.run("whoami")[0].strip("\n\r ")

src/hackingBuddyGPT/utils/ssh_connection/ssh_connection.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,33 @@ class SSHConnection:
1414
hostname: str
1515
username: str
1616
password: str
17+
keyfilename: str
1718
port: int = 22
1819

1920
_conn: Connection = None
2021

2122
def init(self):
2223
# create the SSH Connection
23-
conn = Connection(
24-
f"{self.username}@{self.host}:{self.port}",
25-
connect_kwargs={"password": self.password, "look_for_keys": False, "allow_agent": False},
26-
)
24+
if self.keyfilename == '' or self.keyfilename == None:
25+
conn = Connection(
26+
f"{self.username}@{self.host}:{self.port}",
27+
connect_kwargs={"password": self.password, "look_for_keys": False, "allow_agent": False},
28+
)
29+
else:
30+
conn = Connection(
31+
f"{self.username}@{self.host}:{self.port}",
32+
connect_kwargs={"password": self.password, "key_filename": self.keyfilename, "look_for_keys": False, "allow_agent": False},
33+
)
2734
self._conn = conn
2835
self._conn.open()
2936

30-
def new_with(self, *, host=None, hostname=None, username=None, password=None, port=None) -> "SSHConnection":
37+
def new_with(self, *, host=None, hostname=None, username=None, password=None, keyfilename=None, port=None) -> "SSHConnection":
3138
return SSHConnection(
3239
host=host or self.host,
3340
hostname=hostname or self.hostname,
3441
username=username or self.username,
3542
password=password or self.password,
43+
keyfilename=keyfilename or self.keyfilename,
3644
port=port or self.port,
3745
)
3846

0 commit comments

Comments
 (0)