Update app.py
Browse files
app.py
CHANGED
|
@@ -11,22 +11,25 @@ from Gradio_UI import GradioUI
|
|
| 11 |
# CTI tools
|
| 12 |
@tool
|
| 13 |
def threat_lookup(threat_name: str) -> str:
|
| 14 |
-
"""Fetches basic information about a known cyber threat.
|
| 15 |
-
Args:
|
| 16 |
-
threat_name: The name or ID of the threat (e.g., 'CVE-2023-12345', 'Emotet').
|
| 17 |
-
"""
|
| 18 |
try:
|
| 19 |
url = f"https://cve.circl.lu/api/cve/{threat_name}"
|
| 20 |
-
response = requests.get(url)
|
| 21 |
if response.status_code == 200:
|
| 22 |
data = response.json()
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
| 24 |
else:
|
| 25 |
-
return f"Threat '{threat_name}' not found."
|
|
|
|
|
|
|
| 26 |
except Exception as e:
|
| 27 |
return f"Error fetching threat details: {str(e)}"
|
| 28 |
|
| 29 |
|
|
|
|
| 30 |
@tool
|
| 31 |
def check_ip_reputation(ip_address: str) -> str:
|
| 32 |
"""Checks if an IP address has been reported as malicious.
|
|
@@ -47,7 +50,7 @@ def extract_iocs(text: str) -> dict:
|
|
| 47 |
text: A block of text containing potential IOCs.
|
| 48 |
"""
|
| 49 |
ip_pattern = r"\b(?:\d{1,3}\.){3}\d{1,3}\b"
|
| 50 |
-
domain_pattern = r"\b
|
| 51 |
hash_pattern = r"\b[a-fA-F0-9]{32,64}\b"
|
| 52 |
|
| 53 |
iocs = {
|
|
@@ -80,11 +83,10 @@ final_answer = FinalAnswerTool()
|
|
| 80 |
model = HfApiModel(
|
| 81 |
max_tokens=2096,
|
| 82 |
temperature=0.5,
|
| 83 |
-
model_id='https://wxknx1kg971u7k1n.us-east-1.aws.endpoints.huggingface.cloud',# it is possible that this model may be overloaded
|
| 84 |
custom_role_conversions=None,
|
| 85 |
)
|
| 86 |
|
| 87 |
-
|
| 88 |
# Import tool from Hub
|
| 89 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 90 |
|
|
|
|
| 11 |
# CTI tools
|
| 12 |
@tool
|
| 13 |
def threat_lookup(threat_name: str) -> str:
|
| 14 |
+
"""Fetches basic information about a known cyber threat."""
|
|
|
|
|
|
|
|
|
|
| 15 |
try:
|
| 16 |
url = f"https://cve.circl.lu/api/cve/{threat_name}"
|
| 17 |
+
response = requests.get(url, timeout=5) # Added timeout
|
| 18 |
if response.status_code == 200:
|
| 19 |
data = response.json()
|
| 20 |
+
if 'id' in data and 'summary' in data:
|
| 21 |
+
return f"CVE: {data['id']}\nSummary: {data['summary']}"
|
| 22 |
+
else:
|
| 23 |
+
return f"No detailed information found for '{threat_name}'."
|
| 24 |
else:
|
| 25 |
+
return f"Threat '{threat_name}' not found (HTTP {response.status_code})."
|
| 26 |
+
except requests.exceptions.Timeout:
|
| 27 |
+
return "Request timed out. Try again later."
|
| 28 |
except Exception as e:
|
| 29 |
return f"Error fetching threat details: {str(e)}"
|
| 30 |
|
| 31 |
|
| 32 |
+
|
| 33 |
@tool
|
| 34 |
def check_ip_reputation(ip_address: str) -> str:
|
| 35 |
"""Checks if an IP address has been reported as malicious.
|
|
|
|
| 50 |
text: A block of text containing potential IOCs.
|
| 51 |
"""
|
| 52 |
ip_pattern = r"\b(?:\d{1,3}\.){3}\d{1,3}\b"
|
| 53 |
+
domain_pattern = r"\b[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(?<!\.)\b"
|
| 54 |
hash_pattern = r"\b[a-fA-F0-9]{32,64}\b"
|
| 55 |
|
| 56 |
iocs = {
|
|
|
|
| 83 |
model = HfApiModel(
|
| 84 |
max_tokens=2096,
|
| 85 |
temperature=0.5,
|
| 86 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',#'https://wxknx1kg971u7k1n.us-east-1.aws.endpoints.huggingface.cloud',# it is possible that this model may be overloaded
|
| 87 |
custom_role_conversions=None,
|
| 88 |
)
|
| 89 |
|
|
|
|
| 90 |
# Import tool from Hub
|
| 91 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 92 |
|