-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b9e58b
commit 28a657f
Showing
10 changed files
with
709 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import pandas as pd | ||
import sys | ||
import os | ||
|
||
|
||
# Get the filename from the command line argument | ||
filename = sys.argv[1] | ||
|
||
# Construct the airodump output CSV file path | ||
csv_file = os.path.join("Captures", f"{filename}_airodump.csv") | ||
|
||
# Check if the file exists | ||
if not os.path.isfile(csv_file): | ||
print(f"File not found: {csv_file}") | ||
sys.exit(1) | ||
|
||
# Load the CSV file | ||
df = pd.read_csv(csv_file) | ||
|
||
# Find the index of the row containing 'Station MAC' | ||
station_mac_index = df[df['BSSID'] == 'Station MAC'].index[0] | ||
|
||
# Keep only the rows before 'Station MAC' | ||
df_cleaned = df.iloc[:station_mac_index] | ||
|
||
# Strip any leading/trailing whitespace from column names | ||
df_cleaned.columns = df_cleaned.columns.str.strip() | ||
|
||
# Save the cleaned DataFrame back to CSV | ||
df_cleaned.to_csv(csv_file, index=False) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import json | ||
import pandas as pd | ||
import sys | ||
import os | ||
|
||
def create_bssid_subsets(json_data): | ||
bssid_subsets = [] | ||
|
||
for packet in json_data: | ||
try: | ||
frame_details = { | ||
"bssid": 0, | ||
"frame.time_delta": 0, | ||
"frame.time_delta_displayed": 0, | ||
"frame.time_relative": 0, | ||
"frame.len": 0, | ||
"frame.cap_len": 0, | ||
"radiotap.present.rate": 0, | ||
"radiotap.present.dbm_antsignal": 0, | ||
"radiotap.present.antenna": 0, | ||
"radiotap.present.rtap_ns": 0, | ||
"radiotap.present.ext": 0, | ||
"radiotap.datarate": 0, | ||
"radiotap.dbm_antsignal": 0, | ||
"wlan.fc.type_subtype": 0, | ||
"wlan.fc.type": 0, | ||
"wlan.fc.subtype": 0, | ||
"wlan.fc.ds": 0, | ||
"wlan.duration": 0, | ||
"wlan.frag": 0, | ||
"wlan.seq": 0, | ||
"wlan.ba.control.ackpolicy": 0, | ||
"wlan.qos.tid": 0, | ||
"wlan.qos.priority": 0, | ||
"data.len": 0 | ||
} | ||
|
||
# Check if 'wlan.bssid' exists before accessing it | ||
if "_source" in packet and "layers" in packet["_source"] and "wlan" in packet["_source"]["layers"] and "wlan.bssid" in packet["_source"]["layers"]["wlan"]: | ||
frame_details["bssid"] = packet["_source"]["layers"]["wlan"]["wlan.bssid"] | ||
|
||
# Update dictionary with actual values if available | ||
frame_details["frame.time_delta"] = packet["_source"]["layers"]["frame"].get("frame.time_delta", 0) | ||
frame_details["frame.time_delta_displayed"] = packet["_source"]["layers"]["frame"].get("frame.time_delta_displayed", 0) | ||
frame_details["frame.time_relative"] = packet["_source"]["layers"]["frame"].get("frame.time_relative", 0) | ||
frame_details["frame.len"] = packet["_source"]["layers"]["frame"].get("frame.len", 0) | ||
frame_details["frame.cap_len"] = packet["_source"]["layers"]["frame"].get("frame.cap_len", 0) | ||
|
||
frame_details["radiotap.present.rate"] = packet["_source"]["layers"]["radiotap"]["radiotap.present"]["radiotap.present.word_tree"].get("radiotap.present.rate", 0) | ||
frame_details["radiotap.present.dbm_antsignal"] = packet["_source"]["layers"]["radiotap"]["radiotap.present"]["radiotap.present.word_tree"].get("radiotap.present.dbm_antsignal", 0) | ||
frame_details["radiotap.present.antenna"] = packet["_source"]["layers"]["radiotap"]["radiotap.present"]["radiotap.present.word_tree"].get("radiotap.present.antenna", 0) | ||
frame_details["radiotap.present.rtap_ns"] = packet["_source"]["layers"]["radiotap"]["radiotap.present"]["radiotap.present.word_tree"].get("radiotap.present.rtap_ns", 0) | ||
frame_details["radiotap.present.ext"] = packet["_source"]["layers"]["radiotap"]["radiotap.present"]["radiotap.present.word_tree"].get("radiotap.present.ext", 0) | ||
frame_details["radiotap.datarate"] = packet["_source"]["layers"]["radiotap"].get("radiotap.datarate", 0) | ||
frame_details["radiotap.dbm_antsignal"] = packet["_source"]["layers"]["radiotap"].get("radiotap.dbm_antsignal", 0) | ||
|
||
frame_details["wlan.fc.type_subtype"] = packet["_source"]["layers"]["wlan"].get("wlan.fc.type_subtype", 0) | ||
frame_details["wlan.fc.type"] = packet["_source"]["layers"]["wlan"]["wlan.fc_tree"].get("wlan.fc.type", 0) | ||
frame_details["wlan.fc.subtype"] = packet["_source"]["layers"]["wlan"]["wlan.fc_tree"].get("wlan.fc.subtype", 0) | ||
frame_details["wlan.fc.ds"] = packet["_source"]["layers"]["wlan"]["wlan.fc_tree"]["wlan.flags_tree"].get("wlan.fc.ds", 0) | ||
frame_details["wlan.duration"] = packet["_source"]["layers"]["wlan"].get("wlan.duration", 0) | ||
frame_details["wlan.frag"] = packet["_source"]["layers"]["wlan"].get("wlan.frag", 0) | ||
frame_details["wlan.seq"] = packet["_source"]["layers"]["wlan"].get("wlan.seq", 0) | ||
|
||
compressed_blockack = packet["_source"]["layers"]["wlan"].get("Compressed BlockAck Response", None) | ||
if compressed_blockack: | ||
frame_details["wlan.ba.control.ackpolicy"] = compressed_blockack.get("wlan.ba.control_tree", {}).get("wlan.ba.control.ackpolicy", 0) | ||
|
||
frame_details["wlan.qos.tid"] = packet["_source"]["layers"]["wlan"].get("wlan.qos_tree", {}).get("wlan.qos.tid", 0) | ||
frame_details["wlan.qos.priority"] = packet["_source"]["layers"]["wlan"].get("wlan.qos_tree", {}).get("wlan.qos.priority", 0) | ||
frame_details["data.len"] = packet["_source"]["layers"].get("data", {}).get("data.len", 0) | ||
|
||
bssid_subsets.append(frame_details) | ||
|
||
except KeyError as e: | ||
print(f"Error accessing packet details: {e}") | ||
|
||
return bssid_subsets | ||
|
||
def main(): | ||
# Get the JSON filename from command-line argument | ||
if len(sys.argv) != 2: | ||
print("Usage: python3 pcapercsv.py <filename>") | ||
sys.exit(1) | ||
|
||
json_filename = sys.argv[1] | ||
json_filepath = os.path.join("Captures",json_filename + '.json') | ||
|
||
try: | ||
with open(json_filepath, 'r') as f: | ||
data = json.load(f) | ||
|
||
bssid_subsets = create_bssid_subsets(data) | ||
df = pd.DataFrame(bssid_subsets) | ||
|
||
#Checking Captuers directory exists | ||
os.makedirs("Captures", exist_ok=True) | ||
|
||
csv_filename = os.path.join("Captures",json_filename + '.csv') | ||
df.to_csv(csv_filename, index=False) | ||
print(f"CSV file saved successfully as {csv_filename}!") | ||
|
||
except FileNotFoundError: | ||
print(f"Error: File '{json_filepath}' not found.") | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import json | ||
import pandas as pd | ||
import sys | ||
import os | ||
|
||
def create_bssid_subsets(json_data): | ||
bssid_subsets = [] | ||
|
||
for packet in json_data: | ||
try: | ||
frame_details = { | ||
"bssid": 0, | ||
"frame.time_delta": 0, | ||
"frame.time_delta_displayed": 0, | ||
"frame.time_relative": 0, | ||
"frame.len": 0, | ||
"frame.cap_len": 0, | ||
"radiotap.present.rate": 0, | ||
"radiotap.present.dbm_antsignal": 0, | ||
"radiotap.present.antenna": 0, | ||
"radiotap.present.rtap_ns": 0, | ||
"radiotap.present.ext": 0, | ||
"radiotap.datarate": 0, | ||
"radiotap.dbm_antsignal": 0, | ||
"wlan.fc.type_subtype": 0, | ||
"wlan.fc.type": 0, | ||
"wlan.fc.subtype": 0, | ||
"wlan.fc.ds": 0, | ||
"wlan.duration": 0, | ||
"wlan.frag": 0, | ||
"wlan.seq": 0, | ||
"wlan.ba.control.ackpolicy": 0, | ||
"wlan.qos.tid": 0, | ||
"wlan.qos.priority": 0, | ||
"data.len": 0 | ||
} | ||
|
||
# Check if 'wlan.bssid' exists before accessing it | ||
if "_source" in packet and "layers" in packet["_source"] and "wlan" in packet["_source"]["layers"] and "wlan.bssid" in packet["_source"]["layers"]["wlan"]: | ||
frame_details["bssid"] = packet["_source"]["layers"]["wlan"]["wlan.bssid"] | ||
|
||
# Update dictionary with actual values if available | ||
frame_details["frame.time_delta"] = packet["_source"]["layers"]["frame"].get("frame.time_delta", 0) | ||
frame_details["frame.time_delta_displayed"] = packet["_source"]["layers"]["frame"].get("frame.time_delta_displayed", 0) | ||
frame_details["frame.time_relative"] = packet["_source"]["layers"]["frame"].get("frame.time_relative", 0) | ||
frame_details["frame.len"] = packet["_source"]["layers"]["frame"].get("frame.len", 0) | ||
frame_details["frame.cap_len"] = packet["_source"]["layers"]["frame"].get("frame.cap_len", 0) | ||
|
||
frame_details["radiotap.present.rate"] = packet["_source"]["layers"]["radiotap"]["radiotap.present"]["radiotap.present.word_tree"].get("radiotap.present.rate", 0) | ||
frame_details["radiotap.present.dbm_antsignal"] = packet["_source"]["layers"]["radiotap"]["radiotap.present"]["radiotap.present.word_tree"].get("radiotap.present.dbm_antsignal", 0) | ||
frame_details["radiotap.present.antenna"] = packet["_source"]["layers"]["radiotap"]["radiotap.present"]["radiotap.present.word_tree"].get("radiotap.present.antenna", 0) | ||
frame_details["radiotap.present.rtap_ns"] = packet["_source"]["layers"]["radiotap"]["radiotap.present"]["radiotap.present.word_tree"].get("radiotap.present.rtap_ns", 0) | ||
frame_details["radiotap.present.ext"] = packet["_source"]["layers"]["radiotap"]["radiotap.present"]["radiotap.present.word_tree"].get("radiotap.present.ext", 0) | ||
frame_details["radiotap.datarate"] = packet["_source"]["layers"]["radiotap"].get("radiotap.datarate", 0) | ||
frame_details["radiotap.dbm_antsignal"] = packet["_source"]["layers"]["radiotap"].get("radiotap.dbm_antsignal", 0) | ||
|
||
frame_details["wlan.fc.type_subtype"] = packet["_source"]["layers"]["wlan"].get("wlan.fc.type_subtype", 0) | ||
frame_details["wlan.fc.type"] = packet["_source"]["layers"]["wlan"]["wlan.fc_tree"].get("wlan.fc.type", 0) | ||
frame_details["wlan.fc.subtype"] = packet["_source"]["layers"]["wlan"]["wlan.fc_tree"].get("wlan.fc.subtype", 0) | ||
frame_details["wlan.fc.ds"] = packet["_source"]["layers"]["wlan"]["wlan.fc_tree"]["wlan.flags_tree"].get("wlan.fc.ds", 0) | ||
frame_details["wlan.duration"] = packet["_source"]["layers"]["wlan"].get("wlan.duration", 0) | ||
frame_details["wlan.frag"] = packet["_source"]["layers"]["wlan"].get("wlan.frag", 0) | ||
frame_details["wlan.seq"] = packet["_source"]["layers"]["wlan"].get("wlan.seq", 0) | ||
|
||
compressed_blockack = packet["_source"]["layers"]["wlan"].get("Compressed BlockAck Response", None) | ||
if compressed_blockack: | ||
frame_details["wlan.ba.control.ackpolicy"] = compressed_blockack.get("wlan.ba.control_tree", {}).get("wlan.ba.control.ackpolicy", 0) | ||
|
||
frame_details["wlan.qos.tid"] = packet["_source"]["layers"]["wlan"].get("wlan.qos_tree", {}).get("wlan.qos.tid", 0) | ||
frame_details["wlan.qos.priority"] = packet["_source"]["layers"]["wlan"].get("wlan.qos_tree", {}).get("wlan.qos.priority", 0) | ||
frame_details["data.len"] = packet["_source"]["layers"].get("data", {}).get("data.len", 0) | ||
|
||
bssid_subsets.append(frame_details) | ||
|
||
except KeyError as e: | ||
print(f"Error accessing packet details: {e}") | ||
|
||
return bssid_subsets | ||
|
||
def main(): | ||
# Get the JSON filename from command-line argument | ||
if len(sys.argv) != 2: | ||
print("Usage: python3 pcapercsv.py <filename>") | ||
sys.exit(1) | ||
|
||
json_filename = sys.argv[1] | ||
json_filepath = os.path.join("Captures",json_filename + '.json') | ||
|
||
try: | ||
with open(json_filepath, 'r') as f: | ||
data = json.load(f) | ||
|
||
bssid_subsets = create_bssid_subsets(data) | ||
df = pd.DataFrame(bssid_subsets) | ||
|
||
#Checking Captuers directory exists | ||
os.makedirs("Captures", exist_ok=True) | ||
|
||
csv_filename = os.path.join("Captures",json_filename + '.csv') | ||
df.to_csv(csv_filename, index=False) | ||
print(f"CSV file saved successfully as {csv_filename}!") | ||
|
||
except FileNotFoundError: | ||
print(f"Error: File '{json_filepath}' not found.") | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import pickle | ||
import pandas as pd | ||
import sys | ||
import os | ||
|
||
def main(): | ||
# Get the filename from the command-line arguments | ||
if len(sys.argv) != 2: | ||
print("Usage: python3 pickler.py <filename>") | ||
sys.exit(1) | ||
|
||
filename = sys.argv[1] | ||
csv_filepath = os.path.join("Captures", f"{filename}.csv") | ||
airodump_filepath = os.path.join("Captures", f"{filename}_airodump.csv") | ||
|
||
# Load the pickle file | ||
with open('Model/random_forest_model.pkl', 'rb') as file: | ||
model = pickle.load(file) | ||
|
||
try: | ||
# Load the CSV files | ||
df_main = pd.read_csv(csv_filepath) | ||
df_airodump = pd.read_csv(airodump_filepath) | ||
|
||
# Clean the 'airodump' DataFrame: strip whitespace and select 'BSSID' and 'ESSID' columns | ||
df_airodump['BSSID'] = df_airodump['BSSID'].str.strip() | ||
df_airodump['ESSID'] = df_airodump['ESSID'].str.strip() | ||
|
||
# Filter df_main based on type_subtype | ||
df_main = df_main[df_main['wlan.fc.type_subtype'].isin(['0x0008', '0x0005'])] | ||
|
||
# Convert hexadecimal strings to numeric (integer) values | ||
df_main['wlan.fc.type_subtype'] = df_main['wlan.fc.type_subtype'].apply(lambda x: int(x, 16)) | ||
df_main['wlan.fc.ds'] = df_main['wlan.fc.ds'].apply(lambda x: int(x, 16)) | ||
|
||
# Drop rows where 'bssid' value is 0 | ||
df_main = df_main[df_main['bssid'] != '0'] | ||
|
||
# Keep a copy of the 'bssid' column for later use | ||
bssid_column = df_main['bssid'].copy() | ||
|
||
# Drop the 'bssid' column from df_main for prediction | ||
df_main = df_main.drop(columns=['bssid']) | ||
|
||
# Predict the target variable using the model | ||
predictions = model.predict(df_main) | ||
|
||
# Identify the BSSIDs of evil twin instances | ||
evil_twin_bssids = bssid_column[predictions == 'evil_twin'].unique() | ||
|
||
# Check if there are any evil twins | ||
if evil_twin_bssids.size == 0: | ||
print("\nThere is NO Evil Twin in the Search.\n") | ||
# Consider all BSSIDs as normal if no evil twins | ||
normal_bssid_column = bssid_column.unique() | ||
else: | ||
print("\nBSSID of Evil Twin Instances:") | ||
for bssid in evil_twin_bssids: | ||
bssid_upper = bssid.upper() | ||
df_evil_twin_bssid = df_airodump[df_airodump['BSSID'] == bssid_upper] | ||
if not df_evil_twin_bssid.empty: | ||
essid = df_evil_twin_bssid['ESSID'].values[0] | ||
else: | ||
essid = "Unknown" | ||
print(f"BSSID: {bssid} | SSID: {essid}") | ||
|
||
# Remove BSSIDs that are considered evil twins from normal BSSIDs | ||
normal_bssid_column = bssid_column[~bssid_column.isin(evil_twin_bssids)].unique() | ||
|
||
# Merge df_airodump with normal BSSID to get corresponding ESSIDs | ||
df_normal = df_airodump[df_airodump['BSSID'].isin(normal_bssid_column)] | ||
|
||
print("\nUnique BSSID Normal Instances:\n") | ||
for bssid in normal_bssid_column: | ||
bssid_upper = bssid.upper() | ||
df_normal_bssid = df_airodump[df_airodump['BSSID'] == bssid_upper] | ||
if not df_normal_bssid.empty: | ||
essid = df_normal_bssid['ESSID'].values[0] | ||
else: | ||
essid = "Unknown" | ||
print(f"BSSID: {bssid} | SSID: {essid}") | ||
|
||
except FileNotFoundError: | ||
print(f"Error: File '{csv_filepath}' or '{airodump_filepath}' not found.") | ||
except Exception as e: | ||
print(f"An error occurred: {e}") | ||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.