Skip to content

Commit 4afb80a

Browse files
committed
BGP Abuse Added
1 parent d617971 commit 4afb80a

7 files changed

Lines changed: 120 additions & 1 deletion

File tree

securetea/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from .lib.ids.r2l_rules import r2l_engine
2929
from .lib.ids.r2l_rules import syn_flood
3030
from .lib.ids.r2l_rules import dns_amp
31+
from .lib.ids.r2l_rules import bgp_abuse
3132
from .lib.ids.r2l_rules.wireless import deauth
3233
from .lib.ids.r2l_rules.wireless import fake_access
3334
from .lib.ids.r2l_rules.wireless import hidden_node

securetea/lib/ids/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from .r2l_rules import r2l_engine
1111
from .r2l_rules import syn_flood
1212
from .r2l_rules import dns_amp
13+
from .r2l_rules import bgp_abuse
1314
from .r2l_rules.wireless import deauth
1415
from .r2l_rules.wireless import fake_access
1516
from .r2l_rules.wireless import hidden_node

securetea/lib/ids/r2l_rules/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from . import r2l_engine
99
from . import syn_flood
1010
from . import dns_amp
11+
from . import bgp_abuse
1112
from .wireless import deauth
1213
from .wireless import fake_access
1314
from .wireless import hidden_node
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# -*- coding: utf-8
2+
u"""BGP Abuse Detection detection module for SecureTea IDS.
3+
4+
Project:
5+
╔═╗┌─┐┌─┐┬ ┬┬─┐┌─┐╔╦╗┌─┐┌─┐
6+
╚═╗├┤ │ │ │├┬┘├┤ ║ ├┤ ├─┤
7+
╚═╝└─┘└─┘└─┘┴└─└─┘ ╩ └─┘┴ ┴
8+
Author: Aman Singh <dun930n.m45732@gmail.com> , June 16 2021
9+
Version: 1.1
10+
Module: SecureTea
11+
12+
"""
13+
14+
import scapy.all as scapy
15+
import scapy.contrib.bgp as bgp
16+
from securetea import logger
17+
18+
class BGP_Abuse(object):
19+
"""BGP Abuse class."""
20+
21+
def __init__(self, debug=False):
22+
"""
23+
Initialize BGP Abuse class.
24+
25+
Args:
26+
debug (bool): Log on terminal or not
27+
28+
Raises:
29+
None
30+
31+
Returns:
32+
None
33+
"""
34+
# Initialize logger
35+
self.logger = logger.SecureTeaLogger(
36+
__name__,
37+
debug=debug
38+
)
39+
40+
def detect_bgp_abuse(self, pkt):
41+
"""
42+
Detect BGP Abuse Attacks by observing set flags and BGPPathAttributes
43+
44+
Types of attack detected:-
45+
1) Blind Disruption
46+
47+
Args:
48+
pkt (scapy_object): Packet to dissect and observe
49+
50+
Raises:
51+
None
52+
53+
Returns:
54+
None
55+
"""
56+
57+
# Blind Disruption Detection
58+
if (pkt.haslayer(scapy.IP)
59+
and pkt.haslayer(scapy.TCP)):
60+
if('RA' in str(pkt[scapy.TCP].flags)):
61+
self.logger.log(
62+
"Possible BGP Abuse,Blind Disruption attack detected.",
63+
logtype="warning"
64+
)
65+

securetea/lib/ids/r2l_rules/r2l_engine.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from securetea.lib.ids.r2l_rules.syn_flood import SynFlood
2020
from securetea.lib.ids.r2l_rules.land_attack import LandAttack
2121
from securetea.lib.ids.r2l_rules.dns_amp import DNS_Amplification
22+
from securetea.lib.ids.r2l_rules.bgp_abuse import BGP_Abuse
2223
from securetea.lib.ids.r2l_rules.wireless.deauth import Deauth
2324
from securetea.lib.ids.r2l_rules.wireless.fake_access import FakeAccessPoint
2425
from securetea.lib.ids.r2l_rules.wireless.hidden_node import HiddenNode
@@ -51,6 +52,7 @@ def __init__(self, debug=False, interface=None):
5152
self.ddos = DDoS(debug=debug)
5253
self.syn_flood = SynFlood(debug=debug)
5354
self.dns_amp = DNS_Amplification(debug=debug)
55+
self.bgp_abuse = BGP_Abuse(debug=debug)
5456
# Wireless
5557
self.deauth = Deauth(debug=debug)
5658
self.fake_access = FakeAccessPoint(debug=debug)
@@ -80,6 +82,7 @@ def run(self, pkt):
8082
self.ddos.classify_ddos(pkt)
8183
self.syn_flood.detect_syn_flood(pkt)
8284
self.dns_amp.detect_dns_amplification(pkt)
85+
self.bgp_abuse.detect_bgp_abuse(pkt)
8386
# Wireless
8487
self.deauth.detect_deauth(pkt)
8588
self.fake_access.detect_fake_ap(pkt)

test/test_bgp_abuse.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# -*- coding: utf-8 -*-
2+
import unittest
3+
from securetea.lib.ids.r2l_rules.bgp_abuse import BGP_Abuse
4+
import scapy.all as scapy
5+
from securetea.logger import SecureTeaLogger
6+
7+
try:
8+
# if python 3.x.x
9+
from unittest.mock import patch
10+
except ImportError: # python 2.x.x
11+
from mock import patch
12+
13+
14+
class TestBGP_Abuse(unittest.TestCase):
15+
"""
16+
Test class for SecureTea IDS BGP_Abuse Detection.
17+
"""
18+
19+
def setUp(self):
20+
"""
21+
Setup class for BGP_Abuse.
22+
"""
23+
# Create scapy packet (valid attack)
24+
self.pkt = scapy.IP(src="10.0.2.15",
25+
dst="200.10.10.1") \
26+
/ scapy.TCP(dport=53, sport=179, flags="RA", seq=123, ack=456)
27+
28+
# Create a scapy packet (invalid attack)
29+
self.pkt2 = scapy.IP(src="10.0.2.15",
30+
dst="200.10.10.1") \
31+
/ scapy.TCP(dport=53, sport=179, seq=123, ack=456)
32+
33+
# Create BGP Abuse object
34+
self.bgp_abuse_obj = BGP_Abuse()
35+
36+
@patch.object(SecureTeaLogger, 'log')
37+
def test_detect_bgp_abuse(self, mock_log):
38+
"""
39+
Test detect_bgp_abuse.
40+
"""
41+
# Case 1: When condition for bgp abuse is invalid
42+
self.bgp_abuse_obj.detect_bgp_abuse(self.pkt2)
43+
self.assertFalse(mock_log.called)
44+
45+
# Case 2: When condition for bgp abuse is valid
46+
self.bgp_abuse_obj.detect_bgp_abuse(self.pkt)
47+
mock_log.assert_called_with("Possible BGP Abuse,Blind Disruption attack detected.",
48+
logtype="warning")

test/test_dns_amp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def setUp(self):
3232
/ scapy.UDP(dport=53) \
3333
/ scapy.DNS(rd=1, qd=scapy.DNSQR(qname="google.com", qtype="ANY"))
3434

35-
# Create LandAttack object
35+
# Create DNS Amplification object
3636
self.dns_amp_obj = DNS_Amplification()
3737

3838
@patch.object(SecureTeaLogger, 'log')

0 commit comments

Comments
 (0)