-
Notifications
You must be signed in to change notification settings - Fork 141
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
Showing
7 changed files
with
120 additions
and
1 deletion.
There are no files selected for viewing
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
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
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
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,65 @@ | ||
# -*- coding: utf-8 | ||
u"""BGP Abuse Detection detection module for SecureTea IDS. | ||
Project: | ||
╔═╗┌─┐┌─┐┬ ┬┬─┐┌─┐╔╦╗┌─┐┌─┐ | ||
╚═╗├┤ │ │ │├┬┘├┤ ║ ├┤ ├─┤ | ||
╚═╝└─┘└─┘└─┘┴└─└─┘ ╩ └─┘┴ ┴ | ||
Author: Aman Singh <[email protected]> , June 16 2021 | ||
Version: 1.1 | ||
Module: SecureTea | ||
""" | ||
|
||
import scapy.all as scapy | ||
import scapy.contrib.bgp as bgp | ||
from securetea import logger | ||
|
||
class BGP_Abuse(object): | ||
"""BGP Abuse class.""" | ||
|
||
def __init__(self, debug=False): | ||
""" | ||
Initialize BGP Abuse class. | ||
Args: | ||
debug (bool): Log on terminal or not | ||
Raises: | ||
None | ||
Returns: | ||
None | ||
""" | ||
# Initialize logger | ||
self.logger = logger.SecureTeaLogger( | ||
__name__, | ||
debug=debug | ||
) | ||
|
||
def detect_bgp_abuse(self, pkt): | ||
""" | ||
Detect BGP Abuse Attacks by observing set flags and BGPPathAttributes | ||
Types of attack detected:- | ||
1) Blind Disruption | ||
Args: | ||
pkt (scapy_object): Packet to dissect and observe | ||
Raises: | ||
None | ||
Returns: | ||
None | ||
""" | ||
|
||
# Blind Disruption Detection | ||
if (pkt.haslayer(scapy.IP) | ||
and pkt.haslayer(scapy.TCP)): | ||
if('RA' in str(pkt[scapy.TCP].flags)): | ||
self.logger.log( | ||
"Possible BGP Abuse,Blind Disruption attack detected.", | ||
logtype="warning" | ||
) | ||
|
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
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,48 @@ | ||
# -*- coding: utf-8 -*- | ||
import unittest | ||
from securetea.lib.ids.r2l_rules.bgp_abuse import BGP_Abuse | ||
import scapy.all as scapy | ||
from securetea.logger import SecureTeaLogger | ||
|
||
try: | ||
# if python 3.x.x | ||
from unittest.mock import patch | ||
except ImportError: # python 2.x.x | ||
from mock import patch | ||
|
||
|
||
class TestBGP_Abuse(unittest.TestCase): | ||
""" | ||
Test class for SecureTea IDS BGP_Abuse Detection. | ||
""" | ||
|
||
def setUp(self): | ||
""" | ||
Setup class for BGP_Abuse. | ||
""" | ||
# Create scapy packet (valid attack) | ||
self.pkt = scapy.IP(src="10.0.2.15", | ||
dst="200.10.10.1") \ | ||
/ scapy.TCP(dport=53, sport=179, flags="RA", seq=123, ack=456) | ||
|
||
# Create a scapy packet (invalid attack) | ||
self.pkt2 = scapy.IP(src="10.0.2.15", | ||
dst="200.10.10.1") \ | ||
/ scapy.TCP(dport=53, sport=179, seq=123, ack=456) | ||
|
||
# Create BGP Abuse object | ||
self.bgp_abuse_obj = BGP_Abuse() | ||
|
||
@patch.object(SecureTeaLogger, 'log') | ||
def test_detect_bgp_abuse(self, mock_log): | ||
""" | ||
Test detect_bgp_abuse. | ||
""" | ||
# Case 1: When condition for bgp abuse is invalid | ||
self.bgp_abuse_obj.detect_bgp_abuse(self.pkt2) | ||
self.assertFalse(mock_log.called) | ||
|
||
# Case 2: When condition for bgp abuse is valid | ||
self.bgp_abuse_obj.detect_bgp_abuse(self.pkt) | ||
mock_log.assert_called_with("Possible BGP Abuse,Blind Disruption attack detected.", | ||
logtype="warning") |
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