Browse Source

add get_win_size

Jens Keim 6 years ago
parent
commit
2e442294ea
4 changed files with 25 additions and 9 deletions
  1. 1 2
      code/Attack/DDoSAttack.py
  2. 3 0
      code/ID2TLib/Statistics.py
  3. 11 0
      code/Test/Lib.py
  4. 10 7
      code/Test/test_DDoS.py

+ 1 - 2
code/Attack/DDoSAttack.py

@@ -170,8 +170,7 @@ class DDoSAttack(BaseAttack.BaseAttack):
         attack_duration = self.get_param_value(Param.ATTACK_DURATION)
         pkts_num = int(pps * attack_duration)
 
-        source_win_sizes = self.statistics.process_db_query(
-                "SELECT DISTINCT winSize FROM tcp_win ORDER BY RANDOM() LIMIT "+str(pkts_num)+";")
+        source_win_sizes = self.statistics.get_rnd_win_size(pkts_num)
 
         destination_win_dist = self.statistics.get_win_distribution(ip_destination)
         if len(destination_win_dist) > 0:

+ 3 - 0
code/ID2TLib/Statistics.py

@@ -557,6 +557,9 @@ class Statistics:
         else:
             return None
 
+    def get_rnd_win_size(self, pkts_num):
+        return self.statistics.process_db_query(
+            "SELECT DISTINCT winSize FROM tcp_win ORDER BY RANDOM() LIMIT "+str(pkts_num)+";")
 
     def get_statistics_database(self):
         """

+ 11 - 0
code/Test/Lib.py

@@ -67,3 +67,14 @@ def get_x86_nop(count, side_effect_free, char_filter):
     :return: a count of \x90
     """
     return b'\x90' * count
+
+
+def get_win_size(pkts_num):
+    result = []
+    for i in range(0, pkts_num):
+        result.append(10)
+    return result
+
+
+def get_rnd_short():
+    return 10

+ 10 - 7
code/Test/test_DDoS.py

@@ -1,27 +1,30 @@
-import os
 import unittest
 import unittest.mock as mock
+from scapy.layers.inet import RandShort
 
+from ID2TLib.Statistics import Statistics
 from Test.GenericTest import GenericTest
-from Test.Lib import test_pcap_ips
+from Test.Lib import get_win_size, get_rnd_short
 
 # FIXME: create new hashes
-sha_one_attacker = ''
+sha_two_attackers = '77da7d909d7f2c86922fc663a2834e8de6c565943d307e9a1146b8cf656b5164'
 
 
 # seeds: for 5, 23 for 10, 27 for 16, 31 for 1
 class UnitTestDDoS(GenericTest):
-    def test_one_attacker(self):
+
+    @mock.patch.object(Statistics, 'get_rnd_win_size', side_effect=get_win_size)
+    #@mock.patch.object(RandShort, '__init__', side_effect=get_rnd_short)
+    def test_two_attackers(self, mock_get_rnd_win_size):
         self.generic_test([['DDoSAttack',
                             'attack.duration=10',
-                            'attackers.count=1',
                             'inject.after-pkt=1',
-                            'ip.src=192.168.189.143',
+                            'ip.src=192.168.189.143,192.168.189.144',
                             'ip.dst=192.168.189.1',
                             'packets.per-second=10',
                             'victim.buffer=1000'
                             ]],
-                          sha_one_attacker)
+                          sha_two_attackers)
 
 
 if __name__ == '__main__':