Spaces:
Sleeping
Sleeping
rafaldembski
commited on
Commit
•
63cabd8
1
Parent(s):
411e5fe
Update utils/functions.py
Browse files- utils/functions.py +72 -0
utils/functions.py
CHANGED
@@ -298,6 +298,78 @@ Provide your analysis and conclusions following the guidelines above."""
|
|
298 |
logging.error(f"Błąd połączenia z API: {e}")
|
299 |
return f"Błąd połączenia z API: {e}", "Błąd analizy.", "Błąd analizy."
|
300 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
301 |
def get_email_info(email):
|
302 |
"""
|
303 |
Sprawdza informacje o nadawcy e-maila (np. domena, organizacja, kraj).
|
|
|
298 |
logging.error(f"Błąd połączenia z API: {e}")
|
299 |
return f"Błąd połączenia z API: {e}", "Błąd analizy.", "Błąd analizy."
|
300 |
|
301 |
+
def analyze_url(url):
|
302 |
+
"""
|
303 |
+
Analizuje zawartość strony internetowej pod kątem oszustw.
|
304 |
+
"""
|
305 |
+
phishing_urls = []
|
306 |
+
|
307 |
+
# Sprawdzanie URL w PhishTank
|
308 |
+
def check_url_phishtank(url):
|
309 |
+
params = {
|
310 |
+
'format': 'json',
|
311 |
+
'url': url
|
312 |
+
}
|
313 |
+
try:
|
314 |
+
response = requests.post('https://checkurl.phishtank.com/checkurl/', data=params)
|
315 |
+
if response.status_code == 200:
|
316 |
+
data = response.json()
|
317 |
+
in_database = data.get('results', {}).get('in_database', False)
|
318 |
+
valid = data.get('results', {}).get('valid', False)
|
319 |
+
if in_database and valid:
|
320 |
+
return True
|
321 |
+
else:
|
322 |
+
logging.warning(f"Błąd podczas sprawdzania URL w PhishTank: {response.status_code}")
|
323 |
+
except Exception as e:
|
324 |
+
logging.error(f"Błąd podczas sprawdzania URL w PhishTank: {e}")
|
325 |
+
return False
|
326 |
+
|
327 |
+
# Sprawdzanie URL w Google Safe Browsing
|
328 |
+
def check_url_safe_browsing(url):
|
329 |
+
api_key = os.getenv('GOOGLE_SAFE_BROWSING_API_KEY')
|
330 |
+
if not api_key:
|
331 |
+
return None
|
332 |
+
unsafe_urls = []
|
333 |
+
headers = {'Content-Type': 'application/json'}
|
334 |
+
client_body = {
|
335 |
+
'client': {
|
336 |
+
'clientId': 'yourcompanyname',
|
337 |
+
'clientVersion': '1.0'
|
338 |
+
},
|
339 |
+
'threatInfo': {
|
340 |
+
'threatTypes': ["MALWARE", "SOCIAL_ENGINEERING", "UNWANTED_SOFTWARE", "POTENTIALLY_HARMFUL_APPLICATION"],
|
341 |
+
'platformTypes': ["ANY_PLATFORM"],
|
342 |
+
'threatEntryTypes': ["URL"],
|
343 |
+
'threatEntries': [{'url': url}]
|
344 |
+
}
|
345 |
+
}
|
346 |
+
try:
|
347 |
+
response = requests.post(
|
348 |
+
f'https://safebrowsing.googleapis.com/v4/threatMatches:find?key={api_key}',
|
349 |
+
headers=headers,
|
350 |
+
json=client_body
|
351 |
+
)
|
352 |
+
if response.status_code == 200:
|
353 |
+
data = response.json()
|
354 |
+
matches = data.get('matches', [])
|
355 |
+
return [match['threat']['url'] for match in matches]
|
356 |
+
else:
|
357 |
+
logging.error(f"Błąd podczas komunikacji z Google Safe Browsing API: {response.status_code}")
|
358 |
+
except Exception as e:
|
359 |
+
logging.error(f"Błąd podczas sprawdzania URL w Google Safe Browsing: {e}")
|
360 |
+
return []
|
361 |
+
|
362 |
+
# Sprawdzanie URL w PhishTank
|
363 |
+
if check_url_phishtank(url):
|
364 |
+
phishing_urls.append(url)
|
365 |
+
|
366 |
+
# Sprawdzanie URL w Google Safe Browsing
|
367 |
+
unsafe_urls = check_url_safe_browsing(url)
|
368 |
+
if unsafe_urls:
|
369 |
+
phishing_urls.extend(unsafe_urls)
|
370 |
+
|
371 |
+
return phishing_urls # Zwraca listę zagrożonych URL
|
372 |
+
|
373 |
def get_email_info(email):
|
374 |
"""
|
375 |
Sprawdza informacje o nadawcy e-maila (np. domena, organizacja, kraj).
|