Kaynağa Gözat

add support for src_ip ranges

add support for src_ip ranges and long lists
generate mac for each ip if more ips than macs
add testcases for one attacker and src_ip range
Stefano Acquaviti 6 yıl önce
ebeveyn
işleme
428d985809
2 değiştirilmiş dosya ile 14 ekleme ve 0 silme
  1. 2 0
      code/Attack/DDoSAttack.py
  2. 12 0
      code/Test/test_DDoSAttack.py

+ 2 - 0
code/Attack/DDoSAttack.py

@@ -98,6 +98,8 @@ class DDoSAttack(BaseAttack.BaseAttack):
             mac_source_list = [mac_source_list]
 
         if (num_attackers is None) or (num_attackers is 0):
+            if len(ip_source_list) > len(mac_source_list):
+                mac_source_list.extend(self.generate_random_mac_address(len(ip_source_list)-len(mac_source_list)))
             num_attackers = min(len(ip_source_list), len(mac_source_list))
 
         # Initialize parameters

+ 12 - 0
code/Test/test_DDoSAttack.py

@@ -7,6 +7,8 @@ sha_basic_ddos = 'd30a14ba0568cb9c3be0db6a6d8e5d68b703d995015fc2215bfa150a8aff8b
 sha_num_attackers_ddos = '0de1ac89bb02e0163a31a0215d59ef2e2d819ffb904f8a99be1ecb52a568a392'
 sha_dest_mac_length_zero_ddos = '55720bc3aa43a6abad2db1bd1f9c7ff71cb50f11ca5f17995b24184678c18226'
 sha_mss_none_ddos = 'd30a14ba0568cb9c3be0db6a6d8e5d68b703d995015fc2215bfa150a8aff8b2a'
+sha_one_attacker_ddos = '8bb7798e85cff15b91c5ee2c0bb65f01ff3097a417bdd2e58a540f89d542bea9'
+sha_ip_range_ddos = 'bef5deb3cc7ee7537a90a85323cf885cf5a0431e15ae7001c0c762afc643e7a6'
 
 # TODO: improve coverage
 
@@ -32,5 +34,15 @@ class UnitTestDDoS(Test.ID2TAttackTest):
     def test_ddos_mss_none(self, mock_mss, mock_get_attacker_config):
         self.checksum_test([['DDoSAttack']], sha_mss_none_ddos)
 
+    @mock.patch('ID2TLib.Utility.get_attacker_config', side_effect=Lib.get_attacker_config)
+    def test_ddos_one_attacker(self, mock_get_attacker_config):
+        self.checksum_test([['DDoSAttack', 'ip.src=1.1.1.1']],
+                           sha_one_attacker_ddos)
+
+    @mock.patch('ID2TLib.Utility.get_attacker_config', side_effect=Lib.get_attacker_config)
+    def test_ddos_ip_range(self, mock_get_attacker_config):
+        self.checksum_test([['DDoSAttack', 'ip.src=1.1.1.1-1.1.1.10']],
+                           sha_ip_range_ddos)
+
     def test_ddos_order(self):
         self.order_test([['DDoSAttack', 'attackers.count=5']])