Browse Source

handle lists in FTPExploit
removed now unnecessary handling of most_used_ip list in FTPExploit(now in function in statistics)
removed now unnecessary testcase for that list-handling

Stefano Acquaviti 6 years ago
parent
commit
7ec1729372
2 changed files with 6 additions and 15 deletions
  1. 6 8
      code/Attack/FTPWinaXeExploit.py
  2. 0 7
      code/Test/test_FTPWinaXeExploit.py

+ 6 - 8
code/Attack/FTPWinaXeExploit.py

@@ -9,7 +9,7 @@ from Attack import BaseAttack
 from Attack.AttackParameters import Parameter as Param
 from Attack.AttackParameters import ParameterTypes
 from ID2TLib.Utility import update_timestamp, generate_source_port_from_platform, get_rnd_x86_nop, forbidden_chars,\
-    get_rnd_bytes , check_payload_len
+    get_rnd_bytes , check_payload_len, handle_most_used_outputs
 
 logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
 # noinspection PyPep8
@@ -52,11 +52,9 @@ class FTPWinaXeExploit(BaseAttack.BaseAttack):
         # PARAMETERS: initialize with default values
         # (values are overwritten if user specifies them)
         most_used_ip_address = self.statistics.get_most_used_ip_address()
-        if isinstance(most_used_ip_address, list):
-            most_used_ip_address = most_used_ip_address[0]
 
         # The most used IP class in background traffic
-        most_used_ip_class = self.statistics.process_db_query("most_used(ipClass)")
+        most_used_ip_class = handle_most_used_outputs(self.statistics.process_db_query("most_used(ipClass)"))
         attacker_ip = self.generate_random_ipv4_address(most_used_ip_class)
         self.add_param_value(Param.IP_DESTINATION, attacker_ip)
         self.add_param_value(Param.MAC_DESTINATION, self.generate_random_mac_address())
@@ -91,7 +89,7 @@ class FTPWinaXeExploit(BaseAttack.BaseAttack):
                 mss_prob_dict = Lea.fromValFreqsDict(mss_dist)
                 mss_value = mss_prob_dict.random()
             else:
-                mss_value = self.statistics.process_db_query("most_used(mssValue)")
+                mss_value = handle_most_used_outputs(self.statistics.process_db_query("most_used(mssValue)"))
 
             # Set TTL based on TTL distribution of IP address
             ttl_dist = self.statistics.get_ttl_distribution(ip_address)
@@ -99,7 +97,7 @@ class FTPWinaXeExploit(BaseAttack.BaseAttack):
                 ttl_prob_dict = Lea.fromValFreqsDict(ttl_dist)
                 ttl_value = ttl_prob_dict.random()
             else:
-                ttl_value = self.statistics.process_db_query("most_used(ttlValue)")
+                ttl_value = handle_most_used_outputs(self.statistics.process_db_query("most_used(ttlValue)"))
 
             # Set Window Size based on Window Size distribution of IP address
             win_dist = self.statistics.get_win_distribution(ip_address)
@@ -107,7 +105,7 @@ class FTPWinaXeExploit(BaseAttack.BaseAttack):
                 win_prob_dict = Lea.fromValFreqsDict(win_dist)
                 win_value = win_prob_dict.random()
             else:
-                win_value = self.statistics.process_db_query("most_used(winSize)")
+                win_value = handle_most_used_outputs(self.statistics.process_db_query("most_used(winSize)"))
 
             return mss_value, ttl_value, win_value
 
@@ -134,7 +132,7 @@ class FTPWinaXeExploit(BaseAttack.BaseAttack):
         # Create random victim if specified
         if self.get_param_value(Param.IP_SOURCE_RANDOMIZE):
             # The most used IP class in background traffic
-            most_used_ip_class = self.statistics.process_db_query("most_used(ipClass)")
+            most_used_ip_class = handle_most_used_outputs(self.statistics.process_db_query("most_used(ipClass)"))
             ip_victim = self.generate_random_ipv4_address(most_used_ip_class, 1)
             mac_victim = self.generate_random_mac_address()
 

+ 0 - 7
code/Test/test_FTPWinaXeExploit.py

@@ -27,13 +27,6 @@ class UnitTestFTPWinaXeExploit(GenericTest.GenericTest):
     def test_ftp_basic(self, mock_get_rnd_x86_nop, mock_get_rnd_bytes):
         self.generic_test([['FTPWinaXeExploit']], sha_ftp_basic)
 
-    @mock.patch('ID2TLib.Utility.get_rnd_bytes', side_effect=Lib.get_bytes)
-    @mock.patch('ID2TLib.Utility.get_rnd_x86_nop', side_effect=Lib.get_x86_nop)
-    @mock.patch('ID2TLib.Statistics.Statistics.get_most_used_ip_address')
-    def test_ftp_most_used_ips(self,mock_most_used_ip_address, mock_get_rnd_x86_nop, mock_get_rnd_bytes):
-        mock_most_used_ip_address.return_value = Lib.test_pcap_ips
-        self.generic_test([['FTPWinaXeExploit']], sha_ftp_most_used_ip)
-
     @mock.patch('ID2TLib.Utility.get_rnd_bytes', side_effect=Lib.get_bytes)
     @mock.patch('ID2TLib.Utility.get_rnd_x86_nop', side_effect=Lib.get_x86_nop)
     @mock.patch('ID2TLib.Statistics.Statistics.get_mac_address')