9
9
from hackingBuddyGPT .usecases .base import use_case
10
10
from hackingBuddyGPT .utils import SSHConnection , llm_util
11
11
from hackingBuddyGPT .utils .logging import log_conversation
12
+ from hackingBuddyGPT .utils .rag import RagBackground
12
13
13
- template_analyze = Template ("""You executed the command '${cmd}' and retrieved the following result:
14
+ template_analyze = Template ("""Your task is to analyze the result of an executed command to determina
15
+ a way to escalate your privileges into a root shell. Describe your findings including all needed
16
+ information while being as concise as possible.
17
+
18
+ % if len(rag) > 0:
19
+ You also have the following background information:
20
+ ---
21
+ ${rag}
22
+ ---
23
+ %endif
24
+
25
+ You executed the command '${cmd}' and retrieved the following result:
14
26
15
27
~~~ bash
16
28
${resp}
17
29
~~~
18
-
19
- Analyze if this response allows you to determine a way to escalate your privileges into a root shell. Be as concise as possible.""" )
30
+ """ )
20
31
21
32
template_update_state = Template ("""Your current list of known facts relevant for privilege escalation is:
22
33
@@ -91,12 +102,14 @@ class PrivEscLinux(CommandStrategy):
91
102
92
103
enable_structured_guidance : bool = False
93
104
94
- enable_rag : bool = False
95
-
96
105
enable_cot : bool = False
97
106
107
+ rag_path : str = ''
108
+
98
109
_state : str = ""
99
110
111
+ _enable_rag : bool = False
112
+
100
113
def init (self ):
101
114
super ().init ()
102
115
@@ -118,6 +131,10 @@ def init(self):
118
131
119
132
guidance = []
120
133
134
+ if self .rag_path != '' :
135
+ self ._enable_rag = True
136
+ self ._rag_data = RagBackground (self .rag_path , self .llm )
137
+
121
138
if self .enable_cot :
122
139
self ._template_params ['cot' ] = template_cot
123
140
@@ -214,16 +231,18 @@ def get_rag_query(self, cmd, result):
214
231
@log_conversation ("Analyze its result..." , start_section = True )
215
232
def analyze_result (self , cmd , result ):
216
233
217
- if self . enable_rag :
218
- # TODO: do the RAG query here and add it to the prompt
234
+ relevant_document_data = ''
235
+ if self . _enable_rag :
219
236
queries = self .get_rag_query (cmd , result )
220
237
print ("QUERIES: " + queries .result )
238
+ relevant_document_data = self ._rag_data .get_relevant_documents (queries .result )
239
+ print ("RELEVANT DOCUMENT DATA: " + relevant_document_data )
221
240
222
241
state_size = self .get_state_size ()
223
242
target_size = self .llm .context_size - llm_util .SAFETY_MARGIN - state_size
224
243
225
244
# ugly, but cut down result to fit context size
226
245
result = llm_util .trim_result_front (self .llm , target_size , result )
227
- answer = self .llm .get_response (template_analyze , cmd = cmd , resp = result , facts = self ._state )
246
+ answer = self .llm .get_response (template_analyze , cmd = cmd , resp = result , facts = self ._state , rag = relevant_document_data )
228
247
self .log .call_response (answer )
229
248
self ._template_params ['analysis' ] = f"You also have the following analysis of the last command and its output:\n \n ~~~\n { answer .result } \n ~~~"
0 commit comments