Skip to content

Commit b5bdf79

Browse files
authored
Merge pull request #88 from lloydchang/lloydchang-patch-5
feat: add GitHub Codespaces support
2 parents 39b300e + 26c6423 commit b5bdf79

File tree

7 files changed

+522
-0
lines changed

7 files changed

+522
-0
lines changed

.devcontainer/devcontainer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"onCreateCommand": "./codespaces_create_and_start_containers.sh"
3+
}

README.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,97 @@ We are using vulnerable Linux systems running in Virtual Machines for this. Neve
190190
>
191191
> We are using virtual machines from our [Linux Privilege-Escalation Benchmark](https://github.com/ipa-lab/benchmark-privesc-linux) project. Feel free to use them for your own research!
192192
193+
## GitHub Codespaces support
194+
195+
**Backstory**
196+
197+
https://github.com/ipa-lab/hackingBuddyGPT/pull/85#issuecomment-2331166997
198+
199+
> Would it be possible to add codespace support to hackingbuddygpt in a way, that only spawns a single container (maybe with the suid/sudo use-case) and starts hackingBuddyGPT against that container? That might be the 'easiest' show-case/use-case for a new user.
200+
201+
**Steps**
202+
1. Go to https://github.com/ipa-lab/hackingBuddyGPT
203+
2. Click the "Code" button.
204+
3. Click the "Codespaces" tab.
205+
4. Click the "Create codespace on main" button.
206+
5. Wait for Codespaces to start — This may take upwards of 10 minutes.
207+
208+
> Setting up remote connection: Building codespace...
209+
210+
6. After Codespaces started, you may need to restart a new Terminal via the Command Palette:
211+
212+
Press the key combination:
213+
214+
> `⇧⌘P` `Shift+Command+P` (Mac) / `Ctrl+Shift+P` (Windows/Linux)
215+
216+
In the Command Palette, type `>` and `Terminal: Create New Terminal` and press the return key.
217+
218+
7. You should see a new terminal similar to the following:
219+
220+
> 👋 Welcome to Codespaces! You are on our default image.
221+
>
222+
> `-` It includes runtimes and tools for Python, Node.js, Docker, and more. See the full list here: https://aka.ms/ghcs-default-image
223+
>
224+
> `-` Want to use a custom image instead? Learn more here: https://aka.ms/configure-codespace
225+
>
226+
> 🔍 To explore VS Code to its fullest, search using the Command Palette (Cmd/Ctrl + Shift + P or F1).
227+
>
228+
> 📝 Edit away, run your app as usual, and we'll automatically make it available for you to access.
229+
>
230+
> @github-username ➜ /workspaces/ipa-lab-hackingBuddyGPT (main) $
231+
232+
Type the following to manually run:
233+
```bash
234+
./codespaces_start_hackingbuddygpt_against_a_container.sh
235+
```
236+
7. Eventually, you should see:
237+
238+
> Currently, May 2024, running hackingBuddyGPT with GPT-4-turbo against a benchmark containing 13 VMs (with maximum 20 tries per VM) cost around $5.
239+
>
240+
> Therefore, running hackingBuddyGPT with GPT-4-turbo against containing a container with maximum 10 tries would cost around $0.20.
241+
>
242+
> Enter your OpenAI API key and press the return key:
243+
244+
8. As requested, please enter your OpenAI API key and press the return key.
245+
246+
9. hackingBuddyGPT should start:
247+
248+
> Starting hackingBuddyGPT against a container...
249+
250+
10. If your OpenAI API key is *valid*, then you should see output similar to the following:
251+
252+
> [00:00:00] Starting turn 1 of 10
253+
>
254+
> Got command from LLM:
255+
>
256+
>
257+
>
258+
> [00:01:00] Starting turn 10 of 10
259+
>
260+
>
261+
>
262+
> Run finished
263+
>
264+
> maximum turn number reached
265+
266+
11. If your OpenAI API key is *invalid*, then you should see output similar to the following:
267+
268+
> [00:00:00] Starting turn 1 of 10
269+
>
270+
> Traceback (most recent call last):
271+
>
272+
>
273+
>
274+
> Exception: Error from OpenAI Gateway (401
275+
276+
**References**
277+
* https://docs.github.com/en/codespaces
278+
* https://docs.github.com/en/codespaces/getting-started/quickstart
279+
* https://docs.github.com/en/codespaces/reference/using-the-vs-code-command-palette-in-codespaces
280+
* https://openai.com/api/pricing/
281+
* https://platform.openai.com/docs/quickstart
282+
* https://platform.openai.com/api-keys
283+
193284
## Run the Hacking Agent
194285

195286
Finally we can run hackingBuddyGPT against our provided test VM. Enjoy!
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# codespaces_create_and_start_containers.Dockerfile
2+
3+
FROM ubuntu:latest
4+
5+
ENV DEBIAN_FRONTEND=noninteractive
6+
7+
# Use the TIMEZONE variable to configure the timezone
8+
ENV TIMEZONE=Etc/UTC
9+
RUN ln -fs /usr/share/zoneinfo/$TIMEZONE /etc/localtime && echo $TIMEZONE > /etc/timezone
10+
11+
# Update package list and install dependencies in one line
12+
RUN apt-get update && apt-get install -y \
13+
software-properties-common \
14+
openssh-server \
15+
sudo \
16+
python3 \
17+
python3-venv \
18+
python3-setuptools \
19+
python3-wheel \
20+
python3-apt \
21+
passwd \
22+
tzdata \
23+
iproute2 \
24+
wget \
25+
cron \
26+
--no-install-recommends && \
27+
add-apt-repository ppa:deadsnakes/ppa -y && \
28+
apt-get update && apt-get install -y \
29+
python3.11 \
30+
python3.11-venv \
31+
python3.11-distutils \
32+
python3.11-dev && \
33+
dpkg-reconfigure --frontend noninteractive tzdata && \
34+
apt-get clean && \
35+
rm -rf /var/lib/apt/lists/*
36+
37+
# Install pip using get-pip.py
38+
RUN wget https://bootstrap.pypa.io/get-pip.py && python3.11 get-pip.py && rm get-pip.py
39+
40+
# Install required Python packages
41+
RUN python3.11 -m pip install --no-cache-dir passlib cffi cryptography
42+
43+
# Ensure python3-apt is properly installed and linked
44+
RUN ln -s /usr/lib/python3/dist-packages/apt_pkg.cpython-310-x86_64-linux-gnu.so /usr/lib/python3/dist-packages/apt_pkg.so || true
45+
46+
# Prepare SSH server
47+
RUN mkdir /var/run/sshd
48+
49+
# Create ansible user
50+
RUN useradd -m -s /bin/bash ansible
51+
52+
# Set up SSH for ansible
53+
RUN mkdir -p /home/ansible/.ssh && \
54+
chmod 700 /home/ansible/.ssh && \
55+
chown ansible:ansible /home/ansible/.ssh
56+
57+
# Configure sudo access for ansible
58+
RUN echo "ansible ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/ansible
59+
60+
# Disable root SSH login
61+
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin no/' /etc/ssh/sshd_config
62+
63+
# Expose SSH port
64+
EXPOSE 22
65+
66+
# Start SSH server
67+
CMD ["/usr/sbin/sshd", "-D"]

0 commit comments

Comments
 (0)