-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsv_analyzer.py
More file actions
35 lines (29 loc) · 1.1 KB
/
Copy pathcsv_analyzer.py
File metadata and controls
35 lines (29 loc) · 1.1 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
import pandas as pd
import re
def extract_features(query):
query = str(query)
features = {
'length': len(query),
'single_quotes': query.count("'"),
'double_quotes': query.count('"'),
'dashes': query.count('--'),
'semicolons': query.count(';'),
'asterisks': query.count('*'),
'spaces': query.count(' '),
'keywords': len(re.findall(r'(SELECT|UNION|INSERT|DELETE|UPDATE|DROP|WHERE|AND|OR|FROM|SLEEP|HEX|CHR)', query, re.I))
}
return features
# Load your dataset
print("Loading BCCC-SFU-SQLInj-2023.csv...")
df = pd.read_csv('BCCC-SFU-SQLInj-2023.csv')
# Extract features
print("Analyzing data and extracting features...")
feature_list = df['Data'].apply(extract_features).apply(pd.Series)
# Combine original data with new features
result = pd.concat([df, feature_list], axis=1)
# Save the results
output_file = 'analyzed_dataset.csv'
result.to_csv(output_file, index=False)
print(f"Analysis complete! Results saved to {output_file}")
print("\nFirst 5 rows of analysis:")
print(result[['Data', 'length', 'single_quotes', 'keywords']].head())