Skip to content

Commit 103d03c

Browse files
Merge pull request #716 from Dhivya-Bharathy/add-ZeroScript_AI_TestExecutor
Add ZeroScript_AI_TestExecutor Notebook
2 parents 06501d7 + 3d860e4 commit 103d03c

8 files changed

+5584
-0
lines changed

examples/cookbooks/AI-CourtSimulation.ipynb

Lines changed: 1614 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
{
2+
"nbformat": 4,
3+
"nbformat_minor": 0,
4+
"metadata": {
5+
"colab": {
6+
"provenance": []
7+
},
8+
"kernelspec": {
9+
"name": "python3",
10+
"display_name": "Python 3"
11+
},
12+
"language_info": {
13+
"name": "python"
14+
}
15+
},
16+
"cells": [
17+
{
18+
"cell_type": "markdown",
19+
"source": [
20+
"# Pocky Query Tool: Automated CVE PoC Search & Validation\n",
21+
"\n",
22+
"A lightweight, web-scale agent that helps you find, filter, and fetch real-world PoC exploits — so you don't have to.\n",
23+
"\n",
24+
"**Features:**\n",
25+
"- Automatically searches multiple security-related websites\n",
26+
"- Intelligently analyzes and extracts PoC code\n",
27+
"- Automatically selects the most reliable PoC samples\n",
28+
"- Supports collection of PoCs from multiple sources"
29+
],
30+
"metadata": {
31+
"id": "BdX56iM1r5aB"
32+
}
33+
},
34+
{
35+
"cell_type": "markdown",
36+
"source": [
37+
"[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/DhivyaBharathy-web/PraisonAI/blob/main/examples/cookbooks/Pocky_Cybersecurity_PoC_Agent.ipynb)\n"
38+
],
39+
"metadata": {
40+
"id": "VW766102tUUY"
41+
}
42+
},
43+
{
44+
"cell_type": "markdown",
45+
"source": [
46+
"# Install Dependencies"
47+
],
48+
"metadata": {
49+
"id": "cBu2iXmJsVqE"
50+
}
51+
},
52+
{
53+
"cell_type": "code",
54+
"source": [
55+
"!pip install praisonaiagents exa-py python-dotenv requests beautifulsoup4"
56+
],
57+
"metadata": {
58+
"id": "VvbA3A7XsTFm"
59+
},
60+
"execution_count": null,
61+
"outputs": []
62+
},
63+
{
64+
"cell_type": "markdown",
65+
"source": [
66+
"# Set API Keys"
67+
],
68+
"metadata": {
69+
"id": "Q6B2VEkFsB32"
70+
}
71+
},
72+
{
73+
"cell_type": "code",
74+
"source": [
75+
"import os\n",
76+
"\n",
77+
"# Set your API keys here (replace with your actual keys)\n",
78+
"os.environ[\"EXA_API_KEY\"] = \"your api key\"\n",
79+
"os.environ[\"OPENAI_API_KEY\"] = \"your api key\"\n",
80+
"os.environ[\"OPENAI_BASE_URL\"] = \"https://api.openai.com/v1\" # Optional, for custom OpenAI endpoints"
81+
],
82+
"metadata": {
83+
"id": "OlOI3yc_sAkN"
84+
},
85+
"execution_count": 1,
86+
"outputs": []
87+
},
88+
{
89+
"cell_type": "markdown",
90+
"source": [
91+
"# Tools (Core Functions)"
92+
],
93+
"metadata": {
94+
"id": "1BvjjjJdsanO"
95+
}
96+
},
97+
{
98+
"cell_type": "code",
99+
"source": [
100+
"import json\n",
101+
"from openai import OpenAI\n",
102+
"from exa_py import Exa\n",
103+
"\n",
104+
"# Dummy/Minimal agent classes for notebook demo\n",
105+
"class ValidationAgent:\n",
106+
" def __init__(self, input_json):\n",
107+
" self.input_json = input_json\n",
108+
" def run(self):\n",
109+
" # Dummy validation logic for notebook demo\n",
110+
" data = json.loads(self.input_json)\n",
111+
" return True if \"attack_intent\" in data and \"poc_sample\" in data else False\n",
112+
"\n",
113+
"class AttackIntentAgent:\n",
114+
" def __init__(self, description):\n",
115+
" self.description = description\n",
116+
" def run(self):\n",
117+
" # Dummy intent extraction for notebook demo\n",
118+
" return f\"Intent for: {self.description[:50]}...\""
119+
],
120+
"metadata": {
121+
"id": "GYfAJLXOsbga"
122+
},
123+
"execution_count": 3,
124+
"outputs": []
125+
},
126+
{
127+
"cell_type": "markdown",
128+
"source": [
129+
"## YAML Prompt (Validation Example)\n",
130+
"This is the prompt used for PoC validation."
131+
],
132+
"metadata": {
133+
"id": "THrET8-psjx-"
134+
}
135+
},
136+
{
137+
"cell_type": "code",
138+
"source": [
139+
"validation_prompt = \"\"\"\n",
140+
"You are a highly skilled technical assistant with deep expertise in PoC sample validation.\n",
141+
"\n",
142+
"Given the attack intent of a CVE vulnerability and a PoC sample gathered from public sources, your task is to analyze whether the PoC correctly implements the intended attack behavior.\n",
143+
"\n",
144+
"Specifically:\n",
145+
"- Understand the CVE's attack intent, including the attack goal and the underlying exploitation mechanism.\n",
146+
"- Analyze the PoC to determine whether it is designed to achieve this intent.\n",
147+
"- Check whether the payloads, request structures, and overall logic of the PoC align with the described attack intent.\n",
148+
"- You do not need to execute the PoC. Focus on static validation through reasoning and consistency.\n",
149+
"\n",
150+
"Your output must be a JSON object with two fields:\n",
151+
"- \"valid\": a boolean indicating whether the PoC correctly reflects the attack intent.\n",
152+
"- \"reasoning\": a brief explanation of your judgment. If \"valid\" is false, the reasoning must clearly explain what is incorrect or inconsistent in the PoC compared to the attack intent, so that the PoC can be revised accordingly.\n",
153+
"\"\"\"\n",
154+
"print(validation_prompt)"
155+
],
156+
"metadata": {
157+
"id": "9q3aKl1xshrb"
158+
},
159+
"execution_count": null,
160+
"outputs": []
161+
},
162+
{
163+
"cell_type": "markdown",
164+
"source": [
165+
"# Main (Query and Validate a CVE PoC)"
166+
],
167+
"metadata": {
168+
"id": "531EZgcLsqP6"
169+
}
170+
},
171+
{
172+
"cell_type": "code",
173+
"source": [
174+
"def run_pocky_for_cve(cve_id):\n",
175+
" # Example: Simulate fetching a description and PoC (replace with real logic)\n",
176+
" description = f\"Description for {cve_id} (replace with real Exa/OpenAI search)\"\n",
177+
" poc_sample = f\"PoC code for {cve_id} (replace with real PoC search)\"\n",
178+
"\n",
179+
" # Stage 2: Attack Intent\n",
180+
" intent = AttackIntentAgent(description).run()\n",
181+
" print(f\"Attack Intent: {intent}\")\n",
182+
"\n",
183+
" # Stage 3: Validation\n",
184+
" validation_input = json.dumps({\"attack_intent\": intent, \"poc_sample\": poc_sample}, indent=2)\n",
185+
" valid = ValidationAgent(validation_input).run()\n",
186+
" print(f\"Validation Result: {valid}\")\n",
187+
" if valid:\n",
188+
" print(f\"PoC for {cve_id} is valid and ready to use.\")\n",
189+
" else:\n",
190+
" print(f\"PoC for {cve_id} failed validation.\")"
191+
],
192+
"metadata": {
193+
"id": "PQvtF-RqsrP6"
194+
},
195+
"execution_count": 5,
196+
"outputs": []
197+
},
198+
{
199+
"cell_type": "markdown",
200+
"source": [
201+
"# Example Usage"
202+
],
203+
"metadata": {
204+
"id": "XiQOiSz8su3u"
205+
}
206+
},
207+
{
208+
"cell_type": "code",
209+
"source": [
210+
"run_pocky_for_cve(\"CVE-2023-4450\")"
211+
],
212+
"metadata": {
213+
"colab": {
214+
"base_uri": "https://localhost:8080/"
215+
},
216+
"id": "39w-qpecswjw",
217+
"outputId": "cdcb3b29-7338-4e3e-b160-5f9568c194ca"
218+
},
219+
"execution_count": 6,
220+
"outputs": [
221+
{
222+
"output_type": "stream",
223+
"name": "stdout",
224+
"text": [
225+
"Attack Intent: Intent for: Description for CVE-2023-4450 (replace with real E...\n",
226+
"Validation Result: True\n",
227+
"PoC for CVE-2023-4450 is valid and ready to use.\n"
228+
]
229+
}
230+
]
231+
}
232+
]
233+
}

0 commit comments

Comments
 (0)