Skip to content

Commit 7bcd004

Browse files
Felipe Campos PenhaFelipe Campos Penha
authored andcommitted
exploitation/example now runs in uv env.
1 parent 0266ba2 commit 7bcd004

File tree

5 files changed

+48
-16
lines changed

5 files changed

+48
-16
lines changed

initiatives/genai_red_team_handbook/exploitation/example/Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,19 @@ help:
1111
@echo " make stop - Stop and remove the sandbox container"\
1212
@echo " make all - Run setup, attack, and stop in sequence"\
1313
@echo " make format - Run code formatting (black, isort, mypy)"\
14+
@echo " make sync - Sync dependencies with uv"\
15+
@echo " make lock - Lock dependencies with uv"\
1416
@echo ""\
1517
@echo "Environment:"\
1618
@echo " - Sandbox Directory: $(SANDBOX_DIR)"\
1719
@echo ""
1820

21+
sync:
22+
uv sync
23+
24+
lock:
25+
uv lock
26+
1927
format:
2028
uv run black .
2129
uv run isort .
@@ -28,9 +36,9 @@ setup:
2836
@sleep 5
2937
@echo "✅ Environment ready!"
3038

31-
attack:
39+
attack: sync lock
3240
@echo "⚔️ Launching Red Team attack..."
33-
python3 attack.py
41+
uv run attack.py
3442

3543
stop:
3644
@echo "🧹 Tearing down Red Team environment..."
Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import json
2+
import urllib.request
23
import sys
34
import tomllib
4-
import urllib.request
5-
65

76
def attack():
87
url = "http://localhost:8000/v1/chat/completions"
98
headers = {
109
"Content-Type": "application/json",
11-
"Authorization": "Bearer sk-mock-key",
10+
"Authorization": "Bearer sk-mock-key"
1211
}
13-
12+
1413
# Load prompt from configuration
1514
try:
1615
with open("config.toml", "rb") as f:
@@ -22,31 +21,35 @@ def attack():
2221
except Exception as e:
2322
print(f"[!] Error loading config: {e}")
2423
sys.exit(1)
25-
24+
2625
data = {
2726
"model": "gpt-oss:20b",
28-
"messages": [{"role": "user", "content": prompt}],
29-
"temperature": 0.7,
27+
"messages": [
28+
{"role": "user", "content": prompt}
29+
],
30+
"temperature": 0.7
3031
}
31-
32+
3233
try:
3334
req = urllib.request.Request(
34-
url, data=json.dumps(data).encode("utf-8"), headers=headers, method="POST"
35+
url,
36+
data=json.dumps(data).encode('utf-8'),
37+
headers=headers,
38+
method='POST'
3539
)
36-
40+
3741
print(f"[*] Sending adversarial prompt: {prompt}")
3842
with urllib.request.urlopen(req) as response:
39-
result = json.loads(response.read().decode("utf-8"))
40-
content = result["choices"][0]["message"]["content"]
43+
result = json.loads(response.read().decode('utf-8'))
44+
content = result['choices'][0]['message']['content']
4145
print(f"[*] Response received:\n{content}")
42-
46+
4347
except urllib.error.URLError as e:
4448
print(f"[!] Error communicating with API: {e}")
4549
sys.exit(1)
4650
except Exception as e:
4751
print(f"[!] Unexpected error: {e}")
4852
sys.exit(1)
4953

50-
5154
if __name__ == "__main__":
5255
attack()
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def main():
2+
print("Hello from example!")
3+
4+
5+
if __name__ == "__main__":
6+
main()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[project]
2+
name = "example"
3+
version = "0.1.0"
4+
description = "Add your description here"
5+
readme = "README.md"
6+
requires-python = ">=3.12,<3.13"
7+
dependencies = []

initiatives/genai_red_team_handbook/exploitation/example/uv.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)