Skip to content

Commit c6883d5

Browse files
authored
Merge pull request #21 from ipa-lab/unify
update documentation
2 parents 0a33780 + 92010d1 commit c6883d5

File tree

1 file changed

+76
-21
lines changed

1 file changed

+76
-21
lines changed

‎README.md‎

Lines changed: 76 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,21 @@ the use of LLMs for web penetration-testing and web api testing.
2222

2323
We release all tooling, testbeds and findings as open-source as this is the only way that comprehensive information will find their way to defenders. APTs have access to more sophisticated resources, so we are only leveling the playing field for blue teams. For information about the implementation, please see our [implementation notes](docs/implementation_notes.md). All source code can be found on [github](https://github.com/ipa-lab/hackingbuddyGPT).
2424

25+
hackingBuddyGPT is described in [Getting pwn'd by AI: Penetration Testing with Large Language Models ](https://arxiv.org/abs/2308.00121):
26+
27+
~~~ bibtex
28+
@inproceedings{Happe_2023, series={ESEC/FSE ’23},
29+
title={Getting pwn’d by AI: Penetration Testing with Large Language Models},
30+
url={http://dx.doi.org/10.1145/3611643.3613083},
31+
DOI={10.1145/3611643.3613083},
32+
booktitle={Proceedings of the 31st ACM Joint European Software Engineering Conference and Symposium on the Foundations of Software Engineering},
33+
publisher={ACM},
34+
author={Happe, Andreas and Cito, Jürgen},
35+
year={2023},
36+
month=nov, collection={ESEC/FSE ’23}
37+
}
38+
~~~
39+
2540
## Privilege Escalation Attacks
2641

2742
How are we doing this? The initial tool `wintermute` targets linux priv-esc attacks. It uses SSH to connect to a (presumably) vulnerable virtual machine and then asks OpenAI GPT to suggest linux commands that could be used for finding security vulnerabilities or privilege escalation. The provided command is then executed within the virtual machine, the output fed back to the LLM and, finally, a new command is requested from it..
@@ -50,31 +65,15 @@ Some things to note:
5065
- "What does the LLM know about the system?" gives an LLM generated list of system facts. To generate it, it is given the latest executed command (and it's output) as well as the current list of system facts. This is the operation which time/token usage is shown in the overview table as StateUpdTime/StateUpdTokens. As the state update takes forever, this is disabled by default and has to be enabled through a command line switch.
5166
- Then the next round starts. The next given command (`sudo tar`) will lead to a pwn'd system BTW.
5267

53-
54-
## Academic Research/Expsoure
55-
56-
hackingBuddyGPT is described in [Getting pwn'd by AI: Penetration Testing with Large Language Models ](https://arxiv.org/abs/2308.00121):
57-
58-
~~~ bibtex
59-
@inproceedings{Happe_2023, series={ESEC/FSE ’23},
60-
title={Getting pwn’d by AI: Penetration Testing with Large Language Models},
61-
url={http://dx.doi.org/10.1145/3611643.3613083},
62-
DOI={10.1145/3611643.3613083},
63-
booktitle={Proceedings of the 31st ACM Joint European Software Engineering Conference and Symposium on the Foundations of Software Engineering},
64-
publisher={ACM},
65-
author={Happe, Andreas and Cito, Jürgen},
66-
year={2023},
67-
month=nov, collection={ESEC/FSE ’23}
68-
}
69-
~~~
68+
### Academic Publications on Priv-Esc Attacks
7069

7170
Preliminary results for the linux privilege escalation use-case can be found in [Evaluating LLMs for Privilege-Escalation Scenarios](https://arxiv.org/abs/2310.11409):
7271

7372
~~~ bibtex
74-
@misc{happe2023evaluating,
75-
title={Evaluating LLMs for Privilege-Escalation Scenarios},
73+
@misc{happe2024llms,
74+
title={LLMs as Hackers: Autonomous Linux Privilege Escalation Attacks},
7675
author={Andreas Happe and Aaron Kaplan and Jürgen Cito},
77-
year={2023},
76+
year={2024},
7877
eprint={2310.11409},
7978
archivePrefix={arXiv},
8079
primaryClass={cs.CR}
@@ -96,6 +95,62 @@ This work is partially based upon our empiric research into [how hackers work](h
9695
}
9796
~~~
9897

98+
## Create your own use-case (agent)
99+
100+
The following would create a new (minimal) linux privilege-escalation agent. Through using our infrastructure, this already uses configurable LLM-connections (e.g., for testing OpenAI or locally run LLMs), logs trace data to a local sqlite database for each run, implements a round limit (after which the agent will stop if root has not been achieved until then) and is able to connect to a linux target over SSH for fully-autonomous command execution (as well as password guessing).
101+
102+
~~~ python
103+
template_dir = pathlib.Path(__file__).parent / "templates"
104+
template_next_cmd = Template(filename=str(template_dir / "query_next_command.txt"))
105+
106+
@use_case("linux_privesc", "Linux Privilege Escalation")
107+
@dataclass
108+
class LinuxPrivesc(RoundBasedUseCase, UseCase, abc.ABC):
109+
110+
system: str = 'linux'
111+
112+
_sliding_history: SlidingCliHistory = None
113+
_capabilities: Dict[str, Capability] = field(default_factory=dict)
114+
115+
def init(self):
116+
super().init()
117+
# provide a shell history of limited size to the LLM
118+
self._sliding_history = SlidingCliHistory(self.llm)
119+
120+
def perform_round(self, turn):
121+
got_root : bool = False
122+
123+
with self.console.status("[bold green]Asking LLM for a new command..."):
124+
answer = self.get_next_command()
125+
cmd = answer.result
126+
127+
with self.console.status("[bold green]Executing that command..."):
128+
if answer.result.startswith("test_credential"):
129+
result, got_root = self._capabilities["test_credential"](cmd)
130+
else:
131+
self.console.print(Panel(answer.result, title="[bold cyan]Got command from LLM:"))
132+
result, got_root = self._capabilities["run_command"](cmd)
133+
134+
# log and output the command and its result
135+
self.log_db.add_log_query(self._run_id, turn, cmd, result, answer)
136+
self._sliding_history.add_command(cmd, result)
137+
self.console.print(Panel(result, title=f"[bold cyan]{cmd}"))
138+
139+
# Output Round Data..
140+
self.console.print(ui.get_history_table(False, False, self._run_id, self.log_db, turn))
141+
142+
# if we got root, we can stop the loop
143+
return got_root
144+
145+
def get_next_command(self):
146+
template_size = self.llm.count_tokens(template_next_cmd.source)
147+
history = self._sliding_history.get_history(self.llm.context_size - llm_util.SAFETY_MARGIN - template_size)
148+
149+
cmd = self.llm.get_response(template_next_cmd, _capabilities=self._capabilities, history=history, conn=self.conn, system=self.system, target_user="root")
150+
cmd.result = llm_util.cmd_output_fixer(cmd.result)
151+
return cmd
152+
~~~
153+
99154
## Setup and Usage
100155

101156
We try to keep our python dependencies as light as possible. This should allow for easier experimentation. To run the main priv-escalation program (which is called `wintermute`) together with an OpenAI-based model you need:
@@ -143,7 +198,7 @@ This project is an experimental application and is provided "as-is" without any
143198

144199
The developers and contributors of this project do not accept any responsibility or liability for any losses, damages, or other consequences that may occur as a result of using this software. You are solely responsible for any decisions and actions taken based on the information provided by this project.
145200

146-
**Please note that the use of andy OpenAI language model can be expensive due to its token usage.** By utilizing this project, you acknowledge that you are responsible for monitoring and managing your own token usage and the associated costs. It is highly recommended to check your OpenAI API usage regularly and set up any necessary limits or alerts to prevent unexpected charges.
201+
**Please note that the use of any OpenAI language model can be expensive due to its token usage.** By utilizing this project, you acknowledge that you are responsible for monitoring and managing your own token usage and the associated costs. It is highly recommended to check your OpenAI API usage regularly and set up any necessary limits or alerts to prevent unexpected charges.
147202

148203
As an autonomous experiment, hackingBuddyGPT may generate content or take actions that are not in line with real-world best-practices or legal requirements. It is your responsibility to ensure that any actions or decisions made based on the output of this software comply with all applicable laws, regulations, and ethical standards. The developers and contributors of this project shall not be held responsible for any consequences arising from the use of this software.
149204

0 commit comments

Comments
 (0)