Skip to content

Commit 9fdc97d

Browse files
Felipe Campos PenhaFelipe Campos Penha
authored andcommitted
make format recipe.
1 parent a3ebf4c commit 9fdc97d

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

initiatives/genai_red_team_handbook/exploitation/example/Makefile

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,23 @@ SANDBOX_DIR := ../../sandboxes/llm_local
44

55
# Default target
66
help:
7-
@echo "Red Team Example - Available Commands:"
8-
@echo ""
9-
@echo " make setup - Build and start the local LLM sandbox"
10-
@echo " make attack - Run the adversarial attack script"
11-
@echo " make stop - Stop and remove the sandbox container"
12-
@echo " make all - Run setup, attack, and stop in sequence"
13-
@echo ""
14-
@echo "Environment:"
15-
@echo " - Sandbox Directory: $(SANDBOX_DIR)"
7+
@echo "Red Team Example - Available Commands:"\
8+
@echo ""\
9+
@echo " make setup - Build and start the local LLM sandbox"\
10+
@echo " make attack - Run the adversarial attack script"\
11+
@echo " make stop - Stop and remove the sandbox container"\
12+
@echo " make all - Run setup, attack, and stop in sequence"\
13+
@echo " make format - Run code formatting (black, isort, mypy)"\
14+
@echo ""\
15+
@echo "Environment:"\
16+
@echo " - Sandbox Directory: $(SANDBOX_DIR)"\
1617
@echo ""
1718

19+
format:
20+
uv run black .
21+
uv run isort .
22+
uv run mypy .
23+
1824
setup:
1925
@echo "🚀 Setting up Red Team environment..."
2026
$(MAKE) -C $(SANDBOX_DIR) build up
Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import json
2-
import urllib.request
32
import sys
43
import tomllib
4+
import urllib.request
5+
56

67
def attack():
78
url = "http://localhost:8000/v1/chat/completions"
89
headers = {
910
"Content-Type": "application/json",
10-
"Authorization": "Bearer sk-mock-key"
11+
"Authorization": "Bearer sk-mock-key",
1112
}
12-
13+
1314
# Load prompt from configuration
1415
try:
1516
with open("config.toml", "rb") as f:
@@ -21,35 +22,31 @@ def attack():
2122
except Exception as e:
2223
print(f"[!] Error loading config: {e}")
2324
sys.exit(1)
24-
25+
2526
data = {
2627
"model": "gpt-oss:20b",
27-
"messages": [
28-
{"role": "user", "content": prompt}
29-
],
30-
"temperature": 0.7
28+
"messages": [{"role": "user", "content": prompt}],
29+
"temperature": 0.7,
3130
}
32-
31+
3332
try:
3433
req = urllib.request.Request(
35-
url,
36-
data=json.dumps(data).encode('utf-8'),
37-
headers=headers,
38-
method='POST'
34+
url, data=json.dumps(data).encode("utf-8"), headers=headers, method="POST"
3935
)
40-
36+
4137
print(f"[*] Sending adversarial prompt: {prompt}")
4238
with urllib.request.urlopen(req) as response:
43-
result = json.loads(response.read().decode('utf-8'))
44-
content = result['choices'][0]['message']['content']
39+
result = json.loads(response.read().decode("utf-8"))
40+
content = result["choices"][0]["message"]["content"]
4541
print(f"[*] Response received:\n{content}")
46-
42+
4743
except urllib.error.URLError as e:
4844
print(f"[!] Error communicating with API: {e}")
4945
sys.exit(1)
5046
except Exception as e:
5147
print(f"[!] Unexpected error: {e}")
5248
sys.exit(1)
5349

50+
5451
if __name__ == "__main__":
5552
attack()

0 commit comments

Comments
 (0)