-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathanalysis.py
More file actions
40 lines (36 loc) · 1.67 KB
/
Copy pathanalysis.py
File metadata and controls
40 lines (36 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import pandas as pd
import requests
import streamlit as st
def detect_brute_force(df):
brute_force_df = df[df['path'].str.contains('login', case=False) & df['status'].isin([401, 403])]
brute_force_group = brute_force_df.groupby(['ip', 'path']).size().reset_index(name='count')
return brute_force_group[brute_force_group['count'] > 5]
def detect_sql_injection(df):
sql_keywords = ['SELECT', 'UNION', 'DROP', 'INSERT', 'UPDATE', 'DELETE', 'WHERE', 'OR', 'AND']
df['potential_sql_injection'] = df['path'].str.contains('|'.join(sql_keywords), case=False, na=False) | \
df['referrer'].str.contains('|'.join(sql_keywords), case=False, na=False)
return df[df['potential_sql_injection']]
def detect_xss(df):
xss_patterns = ['<script>', 'javascript:', 'onerror=', 'onload=']
df['potential_xss'] = df['path'].str.contains('|'.join(xss_patterns), case=False, na=False) | \
df['referrer'].str.contains('|'.join(xss_patterns), case=False, na=False)
return df[df['potential_xss']]
def check_abuseipdb(ip, api_key):
try:
headers = {
'Accept': 'application/json',
'Key': api_key
}
params = {
'ipAddress': ip,
'maxAgeInDays': '90'
}
response = requests.get('https://api.abuseipdb.com/api/v2/check', headers=headers, params=params)
if response.status_code == 200:
return response.json()['data']
else:
st.error(f"Error checking IP {ip}: {response.text}")
return None
except Exception as e:
st.error(f"An error occurred while checking IP {ip}: {str(e)}")
return None