1- import pathlib
2-
31from mako .template import Template
42
53from hackingBuddyGPT .capabilities import SSHRunCommand
64from hackingBuddyGPT .usecases .base import UseCase , use_case
7- from hackingBuddyGPT .usecases .privesc .linux import LinuxPrivesc , LinuxPrivescUseCase
85from hackingBuddyGPT .utils import SSHConnection
96from hackingBuddyGPT .utils .openai .openai_llm import OpenAIConnection
107
11- template_dir = pathlib .Path (__file__ ).parent
12- template_lse = Template (filename = str (template_dir / "get_hint_from_lse.txt" ))
8+ from .linux_privesc import PrivEscLinux
9+
10+ template_lse = Template ("""
11+ Create a list of up to ${number} attack classes that you would try on a linux system
12+ (to achieve root level privileges) given the following output:
1313
14+ ~~~ bash
15+ ${lse_output}
16+ ~~~
17+
18+ only output the list of attack classes, for each attack class only output a single
19+ short sentence.""" )
1420
1521@use_case ("Linux Privilege Escalation using lse.sh for initial guidance" )
1622class ExPrivEscLinuxLSEUseCase (UseCase ):
@@ -23,9 +29,6 @@ class ExPrivEscLinuxLSEUseCase(UseCase):
2329
2430 _got_root : bool = False
2531
26- # use either an use-case or an agent to perform the privesc
27- use_use_case : bool = False
28-
2932 # simple helper that uses lse.sh to get hints from the system
3033 def call_lse_against_host (self ):
3134 self .log .console .print ("[green]performing initial enumeration with lse.sh" )
@@ -43,65 +46,32 @@ def call_lse_against_host(self):
4346 def get_name (self ) -> str :
4447 return self .__class__ .__name__
4548
46- def run (self ):
49+ def run (self , configuration = {} ):
4750 # get the hints through running LSE on the target system
4851 hints = self .call_lse_against_host ()
4952 turns_per_hint = int (self .max_turns / len (hints ))
5053
5154 # now try to escalate privileges using the hints
5255 for hint in hints :
53- if self .use_use_case :
54- self .log .console .print ("[yellow]Calling a use-case to perform the privilege escalation" )
55- result = self .run_using_usecases (hint , turns_per_hint )
56- else :
57- self .log .console .print ("[yellow]Calling an agent to perform the privilege escalation" )
58- result = self .run_using_agent (hint , turns_per_hint )
56+ self .log .console .print ("[yellow]Calling a use-case to perform the privilege escalation" )
57+ result = self .run_using_usecases (hint , turns_per_hint )
5958
6059 if result is True :
6160 self .log .console .print ("[green]Got root!" )
6261 return True
6362
6463 def run_using_usecases (self , hint , turns_per_hint ):
6564 # TODO: init usecase
66- linux_privesc = LinuxPrivescUseCase (
67- agent = LinuxPrivesc (
68- conn = self .conn ,
69- enable_explanation = self .enable_explanation ,
70- enable_update_state = self .enable_update_state ,
71- disable_history = self .disable_history ,
72- llm = self .llm ,
73- hint = hint ,
74- ),
75- max_turns = turns_per_hint ,
76- log = self .log ,
77- )
78- linux_privesc .init (self .configuration )
79- return linux_privesc .run ()
80-
81- def run_using_agent (self , hint , turns_per_hint ):
82- # init agent
83- agent = LinuxPrivesc (
65+ linux_privesc = PrivEscLinux (
8466 conn = self .conn ,
85- llm = self .llm ,
86- hint = hint ,
8767 enable_explanation = self .enable_explanation ,
8868 enable_update_state = self .enable_update_state ,
8969 disable_history = self .disable_history ,
70+ llm = self .llm ,
71+ hints = f"hint:{ hint } " ,
72+ max_turns = turns_per_hint ,
73+ log = self .log ,
9074 )
91- agent .log = self .log
92- agent .init ()
93-
94- # perform the privilege escalation
95- agent .before_run ()
96- turn = 1
97- got_root = False
98- while turn <= turns_per_hint and not got_root :
99- self .log .console .log (f"[yellow]Starting turn { turn } of { turns_per_hint } " )
100-
101- if agent .perform_round (turn ) is True :
102- got_root = True
103- turn += 1
104-
105- # cleanup and finish
106- agent .after_run ()
107- return got_root
75+
76+ linux_privesc .init ()
77+ return linux_privesc .run ({})
0 commit comments