| import numpy as np |
| import pandas as pd |
| import random |
| import os |
| import json |
|
|
| np.random.seed(42) |
| random.seed(42) |
|
|
| COUNTRIES = { |
| "Kenya": {"region": "EAC", "mobile_money_maturity": 0.95, "fraud_rate": 0.042, "awareness": 0.65}, |
| "Nigeria": {"region": "ECOWAS", "mobile_money_maturity": 0.78, "fraud_rate": 0.055, "awareness": 0.45}, |
| "South Africa": {"region": "SADC", "mobile_money_maturity": 0.82, "fraud_rate": 0.038, "awareness": 0.72}, |
| "Ghana": {"region": "ECOWAS", "mobile_money_maturity": 0.70, "fraud_rate": 0.048, "awareness": 0.55}, |
| "Tanzania": {"region": "EAC", "mobile_money_maturity": 0.75, "fraud_rate": 0.040, "awareness": 0.50}, |
| "Uganda": {"region": "EAC", "mobile_money_maturity": 0.68, "fraud_rate": 0.045, "awareness": 0.48}, |
| "Rwanda": {"region": "EAC", "mobile_money_maturity": 0.72, "fraud_rate": 0.035, "awareness": 0.58}, |
| "Ivory Coast": {"region": "ECOWAS", "mobile_money_maturity": 0.65, "fraud_rate": 0.050, "awareness": 0.42}, |
| "Ethiopia": {"region": "COMESA", "mobile_money_maturity": 0.45, "fraud_rate": 0.038, "awareness": 0.35}, |
| "Cameroon": {"region": "ECOWAS", "mobile_money_maturity": 0.52, "fraud_rate": 0.052, "awareness": 0.40}, |
| "Senegal": {"region": "ECOWAS", "mobile_money_maturity": 0.58, "fraud_rate": 0.046, "awareness": 0.45}, |
| "Mozambique": {"region": "SADC", "mobile_money_maturity": 0.40, "fraud_rate": 0.042, "awareness": 0.38}, |
| "Democratic Republic of Congo": {"region": "CEN-SAD", "mobile_money_maturity": 0.35, "fraud_rate": 0.058, "awareness": 0.28}, |
| "Zambia": {"region": "SADC", "mobile_money_maturity": 0.55, "fraud_rate": 0.044, "awareness": 0.50}, |
| "Burkina Faso": {"region": "ECOWAS", "mobile_money_maturity": 0.42, "fraud_rate": 0.050, "awareness": 0.35}, |
| } |
|
|
| ATTACK_VECTORS = ["sms_phishing", "ussd_phishing", "voice_phishing", "social_media", "email", "fake_app", "mimicked_website"] |
| FRAUD_STAGES = ["initial_contact", "credentialHarvest", "authentication_bypass", "transaction_execution", "money_laundering"] |
| BANKING_APPS = ["M-Pesa", "MoMo", "Flutterwave", "Paystack", "Stripe", "Zenith", "GTBank", "Standard Chartered", "Absa", "Ecobank"] |
|
|
| def get_country(): |
| return np.random.choice(list(COUNTRIES.keys())) |
|
|
| def generate_phishing_record(record_id, year, scenario): |
| country = get_country() |
| country_data = COUNTRIES[country] |
| |
| if scenario == "baseline": |
| attack_frequency = country_data["fraud_rate"] * np.random.uniform(0.8, 1.2) |
| success_rate = np.random.uniform(0.08, 0.18) |
| detection_rate = np.random.uniform(0.15, 0.30) |
| financial_impact = np.random.uniform(150, 800) |
| campaign_duration = np.random.uniform(5, 20) |
| sophistication = np.random.uniform(0.30, 0.55) |
| target_sophistication = np.random.uniform(0.40, 0.70) |
| elif scenario == "ai_amplification": |
| attack_frequency = country_data["fraud_rate"] * np.random.uniform(1.3, 1.8) |
| success_rate = np.random.uniform(0.15, 0.30) |
| detection_rate = np.random.uniform(0.10, 0.22) |
| financial_impact = np.random.uniform(300, 1500) |
| campaign_duration = np.random.uniform(8, 35) |
| sophistication = np.random.uniform(0.55, 0.85) |
| target_sophistication = np.random.uniform(0.55, 0.85) |
| else: |
| attack_frequency = country_data["fraud_rate"] * np.random.uniform(0.5, 0.8) |
| success_rate = np.random.uniform(0.04, 0.10) |
| detection_rate = np.random.uniform(0.35, 0.55) |
| financial_impact = np.random.uniform(80, 400) |
| campaign_duration = np.random.uniform(3, 12) |
| sophistication = np.random.uniform(0.25, 0.45) |
| target_sophistication = np.random.uniform(0.30, 0.50) |
| |
| attack_vector = np.random.choice(ATTACK_VECTORS, |
| p=[0.32, 0.25, 0.12, 0.15, 0.08, 0.05, 0.03]) |
| |
| target_app = np.random.choice(BANKING_APPS) |
| |
| num_targets = int(np.random.uniform(500, 50000) * country_data["mobile_money_maturity"]) |
| |
| num_successful = int(num_targets * success_rate) |
| |
| total_loss = num_successful * financial_impact |
| |
| avg_loss_per_victim = financial_impact * np.random.uniform(0.6, 1.0) |
| |
| fraud_stage = np.random.choice(FRAUD_STAGES, p=[0.25, 0.30, 0.20, 0.15, 0.10]) |
| |
| if attack_vector in ["sms_phishing", "ussd_phishing"]: |
| message_theme = np.random.choice(["account_suspended", "winning_prize", "urgent_verification", |
| "bill_payment", "loan_approval", "security_alert"]) |
| else: |
| message_theme = np.random.choice(["customer_support", "transaction_confirm", |
| "new_device_login", "profile_update", "bonus_offer"]) |
| |
| time_to_detect = campaign_duration * np.random.uniform(0.3, 0.9) |
| |
| law_enforcement_response = np.random.choice(["investigating", "arrest_made", "no_action", "international_coop"], |
| p=[0.50, 0.15, 0.25, 0.10]) |
| |
| record = { |
| "record_id": f"PHISH-{country[:3].upper()}-{record_id:07d}", |
| "year": year, |
| "country": country, |
| "region": country_data["region"], |
| "mobile_maturity_index": round(country_data["mobile_money_maturity"], 3), |
| "campaign_id": f"CAMP-{np.random.randint(100000, 999999):06d}", |
| "attack_vector": attack_vector, |
| "target_platform": target_app, |
| "num_targets": num_targets, |
| "num_successful_compromises": num_successful, |
| "attack_success_rate_pct": round(success_rate * 100, 2), |
| "total_financial_loss_usd": round(total_loss, 2), |
| "average_loss_per_victim_usd": round(avg_loss_per_victim, 2), |
| "campaign_duration_days": round(campaign_duration, 1), |
| "fraud_stage": fraud_stage, |
| "message_theme": message_theme, |
| "sophistication_score": round(sophistication, 3), |
| "target_sophistication_needed": round(target_sophistication, 3), |
| "time_to_detect_days": round(time_to_detect, 1), |
| "detection_rate_pct": round(detection_rate * 100, 1), |
| "user_awareness_score": round(country_data["awareness"], 3), |
| "law_enforcement_response": law_enforcement_response, |
| "victim_age_group": np.random.choice(["18-25", "26-35", "36-45", "46-55", "55+"], |
| p=[0.25, 0.35, 0.22, 0.12, 0.06]), |
| "victim_education": np.random.choice(["primary", "secondary", "tertiary", "none"], |
| p=[0.15, 0.40, 0.38, 0.07]), |
| "reporting_rate_pct": round(np.random.uniform(5, 25), 1), |
| "repeat_victim_pct": round(np.random.uniform(8, 35), 1), |
| "cross_border_attack": int(np.random.random() < 0.25), |
| "scenario": scenario, |
| } |
| |
| return record |
|
|
| def generate_dataset(output_dir, n_records=18000): |
| scenarios = [ |
| ("baseline", 6000, [2018, 2019, 2020, 2021]), |
| ("ai_amplification", 6000, [2022, 2023, 2024]), |
| ("enhanced_protection", 6000, [2025, 2026]), |
| ] |
| |
| all_records = [] |
| record_id = 0 |
| |
| for scenario_name, n_scenario, years in scenarios: |
| print(f"Generating {n_scenario} records for {scenario_name}") |
| |
| for _ in range(n_scenario): |
| year = np.random.choice(years) |
| record = generate_phishing_record(record_id, year, scenario_name) |
| all_records.append(record) |
| record_id += 1 |
| |
| if record_id % 10000 == 0: |
| print(f" Progress: {record_id} records") |
| |
| df = pd.DataFrame(all_records) |
| |
| data_dir = os.path.join(output_dir, "data") |
| os.makedirs(data_dir, exist_ok=True) |
| |
| for scenario in scenarios: |
| scenario_name = scenario[0] |
| scenario_df = df[df["scenario"] == scenario_name] |
| filename = f"phishing_{scenario_name}.csv" |
| scenario_df.to_csv(os.path.join(data_dir, filename), index=False) |
| print(f"Saved {len(scenario_df)} records to {filename}") |
| |
| df.to_csv(os.path.join(data_dir, "phishing_full.csv"), index=False) |
| print(f"Saved {len(df)} total records to phishing_full.csv") |
| |
| stats = { |
| "total_records": len(df), |
| "countries": df["country"].nunique(), |
| "by_scenario": df["scenario"].value_counts().to_dict(), |
| "mean_attack_frequency": float(df["attack_success_rate_pct"].mean()), |
| "mean_total_loss": float(df["total_financial_loss_usd"].mean()), |
| } |
| |
| with open(os.path.join(output_dir, "generation_stats.json"), "w") as f: |
| json.dump(stats, f, indent=2) |
| print(f"Saved statistics to generation_stats.json") |
| |
| return df |
|
|
| if __name__ == "__main__": |
| output_dir = os.path.dirname(os.path.abspath(__file__)) |
| print("Generating African Mobile Banking Phishing Dataset...") |
| df = generate_dataset(output_dir, n_records=18000) |
| print("Dataset generation complete!") |