Ukraine gains access to EU emergency cyber response for major attacks
Back to Tutorials
techTutorialbeginner

Ukraine gains access to EU emergency cyber response for major attacks

June 15, 202654 views5 min read

Learn how to build a basic cyber incident response system using Python and network monitoring tools, similar to the EU's emergency cyber support for Ukraine.

Introduction

In today's interconnected world, cyber attacks can cripple critical infrastructure and disrupt essential services. The European Union has recognized this threat and created the EU Cybersecurity Reserve to help member states defend against major cyber incidents. Now, Ukraine has been granted access to this emergency cyber response system. This tutorial will guide you through setting up a basic cyber incident response framework using open-source tools that mirror the principles behind the EU's cybersecurity initiatives.

This tutorial will teach you how to create a simple cyber incident response system using Python and basic network monitoring tools. You'll learn how to detect suspicious network activity, log events, and trigger alerts - all fundamental concepts used in systems like the EU Cybersecurity Reserve.

Prerequisites

To follow this tutorial, you'll need:

  • A computer with Python 3.6 or higher installed
  • Basic understanding of command line operations
  • Internet connection for downloading packages
  • Text editor (like VS Code or Notepad++)

Step-by-Step Instructions

1. Install Required Python Packages

First, we need to install the necessary Python packages for our cyber incident response system. Open your command line interface and run:

pip install scapy python-dateutil

Why this step? Scapy is a powerful Python library for network packet manipulation, which we'll use to monitor network traffic. The python-dateutil package helps with date and time handling in our logs.

2. Create the Main Incident Response Script

Create a new file called cyber_response.py in your preferred text editor. This will be our main script that monitors for suspicious activity.

import time
import logging
from datetime import datetime
from scapy.all import sniff, IP

# Configure logging
logging.basicConfig(
    filename='cyber_incident.log',
    level=logging.INFO,
    format='%(asctime)s - %(levelname)s - %(message)s'
)

# Define suspicious patterns
SUSPICIOUS_PORTS = [21, 22, 23, 135, 139, 445, 3389]  # Common attack ports

# Function to process packets
def process_packet(packet):
    # Check if packet has IP layer
    if IP in packet:
        src_ip = packet[IP].src
        dst_ip = packet[IP].dst
        
        # Check for suspicious ports
        if packet.haslayer('TCP'):
            dst_port = packet['TCP'].dport
            if dst_port in SUSPICIOUS_PORTS:
                log_message = f'SUSPICIOUS ACTIVITY DETECTED: {src_ip} -> {dst_ip}:{dst_port}'
                logging.warning(log_message)
                print(f'ALERT: {log_message}')
        
        # Log normal traffic
        else:
            log_message = f'NORMAL TRAFFIC: {src_ip} -> {dst_ip}'
            logging.info(log_message)

# Start monitoring
print('Starting cyber incident monitoring...')
print('Press Ctrl+C to stop')

try:
    sniff(prn=process_packet, store=0)
except KeyboardInterrupt:
    print('\nMonitoring stopped.')

Why this step? This script sets up a basic network monitor that can detect suspicious port activity. It logs events and alerts you when potentially malicious traffic is detected, similar to how large-scale systems like the EU Cybersecurity Reserve identify threats.

3. Test Your System

Save your cyber_response.py file and run it:

python cyber_response.py

Allow the script to run for a few minutes. It will start monitoring your network traffic and logging events. You should see output like:

Starting cyber incident monitoring...
Press Ctrl+C to stop
NORMAL TRAFFIC: 192.168.1.1 -> 192.168.1.254
ALERT: SUSPICIOUS ACTIVITY DETECTED: 10.0.0.5 -> 192.168.1.1:445

Why this step? Testing ensures your system works correctly before deploying it in a real environment. The script will help you understand how network monitoring works and how alerts are generated.

4. Create a Simple Alert System

Let's enhance our script to send simple email alerts when suspicious activity is detected. First, install the email package:

pip install secure-smtplib

Then modify your script to include email alerts:

import smtplib
from email.mime.text import MIMEText

# Email configuration (modify these values)
EMAIL_CONFIG = {
    'smtp_server': 'smtp.gmail.com',
    'smtp_port': 587,
    'sender_email': '[email protected]',
    'sender_password': 'your_app_password',
    'recipient_email': '[email protected]'
}

# Function to send email alert
def send_alert(message):
    try:
        msg = MIMEText(message)
        msg['Subject'] = 'Cyber Security Alert'
        msg['From'] = EMAIL_CONFIG['sender_email']
        msg['To'] = EMAIL_CONFIG['recipient_email']
        
        server = smtplib.SMTP(EMAIL_CONFIG['smtp_server'], EMAIL_CONFIG['smtp_port'])
        server.starttls()
        server.login(EMAIL_CONFIG['sender_email'], EMAIL_CONFIG['sender_password'])
        server.send_message(msg)
        server.quit()
        
        print('Alert email sent successfully')
    except Exception as e:
        print(f'Failed to send email: {e}')

# Update the process_packet function to include email alerts
# (Add this to your existing process_packet function)
if dst_port in SUSPICIOUS_PORTS:
    log_message = f'SUSPICIOUS ACTIVITY DETECTED: {src_ip} -> {dst_ip}:{dst_port}'
    logging.warning(log_message)
    print(f'ALERT: {log_message}')
    send_alert(log_message)  # Send email alert

Why this step? Email alerts are crucial for immediate response to security threats. This mimics how large-scale systems notify security teams of potential incidents.

5. Set Up Log Analysis Script

Create a separate file called analyze_logs.py to analyze your security logs:

import re
from collections import Counter

# Read and analyze the log file
with open('cyber_incident.log', 'r') as f:
    log_content = f.read()

# Extract suspicious activity lines
suspicious_lines = re.findall(r'SUSPICIOUS ACTIVITY DETECTED:.*', log_content)

# Count occurrences by IP
ip_counts = Counter([line.split()[4] for line in suspicious_lines])

print('Suspicious activity summary:')
for ip, count in ip_counts.most_common():
    print(f'{ip}: {count} incidents')

Why this step? Log analysis is essential for identifying patterns and understanding attack trends. This simple analysis helps security teams prioritize their response efforts.

Summary

In this tutorial, you've learned how to create a basic cyber incident response system using Python and network monitoring tools. You've built:

  • A network traffic monitor that detects suspicious activity
  • A logging system that records all network events
  • An email alert system that notifies security teams
  • A log analysis tool to identify attack patterns

While this is a simplified version of what large-scale systems like the EU Cybersecurity Reserve provide, it demonstrates the fundamental concepts behind modern cybersecurity monitoring. These tools help organizations detect and respond to threats quickly, just like the EU's emergency cyber support system helps member states respond to major cyber incidents.

Remember to always follow proper security practices when implementing these systems in real environments, and consider additional features like firewall integration, advanced threat detection, and regular system updates for production use.

Source: TNW Neural

Related Articles