Browse Source

made the attack use the pseudo-realistic source ports

Denis Waßmann 6 years ago
parent
commit
edc42b17ed
2 changed files with 9 additions and 6 deletions
  1. 5 2
      code/Attack/MembersMgmtCommAttack.py
  2. 4 4
      code/ID2TLib/Ports.py

+ 5 - 2
code/Attack/MembersMgmtCommAttack.py

@@ -11,6 +11,7 @@ from Attack.AttackParameters import Parameter as Param
 from Attack.AttackParameters import ParameterTypes
 # from ID2TLib import PcapFile
 # from ID2TLib.PcapFile import PcapFile
+from ID2TLib.Ports import PortSelectors
 
 class MessageType(Enum):
     """
@@ -186,7 +187,7 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
             id_src, id_dst = msg.src["ID"], msg.dst["ID"]
             ip_src, ip_dst = msg.src["IP"], msg.dst["IP"]
             mac_src, mac_dst = msg.src["MAC"], msg.dst["MAC"]
-            port_src, port_dst = int(msg.src["Port"]), int(msg.dst["Port"])
+            port_src, port_dst = int(msg.src["SrcPort"]), int(msg.dst["DstPort"])
             ttl = int(msg.src["TTL"])
 
             # update duration
@@ -517,9 +518,11 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
                 updated_msgs.append(respns_msg)
                 last_response[(req_msg.src, req_msg.dst)] = respns_msg.time
 
+        portSelector = PortSelectors.LINUX
         # create port configurations for the bots
         for bot in bot_configs:
-            bot_configs[bot]["Port"] = Generator.gen_random_server_port()
+            bot_configs[bot]["SrcPort"] = portSelector.select_port_udp()
+            bot_configs[bot]["DstPort"] = Generator.gen_random_server_port()
 
         # print(local_init_ids)
         # print(bot_configs)

+ 4 - 4
code/ID2TLib/Ports.py

@@ -36,7 +36,7 @@ class PortSelectionStrategy:
 			
 			return port
 	class random:
-		def __call__(port_range, *args):
+		def __call__(self, port_range, *args):
 			return random.randrange(port_range.start, port_range.stop)
 
 	class linux_kernel:
@@ -242,10 +242,10 @@ class PortSelectors:
 	.clone() to get your personal copy, otherwise two parts of your code might select ports on the same port-selector which
 	is something your might want to avoid.
 	"""
-	LINUX = ProtocolPortSelector(PortRanges.LINUX, PortSelectionStrategy.random)
+	LINUX = ProtocolPortSelector(PortRanges.LINUX, PortSelectionStrategy.random())
 	APPLE = ProtocolPortSelector(PortRanges.DYNAMIC_PORTS,
 			PortSelectionStrategy.sequential(),
 			PortSelectionStrategy.random())
-	FREEBSD = ProtocolPortSelector(PortRanges.FREEBSD, PortSelectionStrategy.random)
-	WINDOWS = ProtocolPortSelector(PortRanges.WINDOWS_7, PortSelectionStrategy.random) # the selection strategy is a guess as i can't find more info on it
+	FREEBSD = ProtocolPortSelector(PortRanges.FREEBSD, PortSelectionStrategy.random())
+	WINDOWS = ProtocolPortSelector(PortRanges.WINDOWS_7, PortSelectionStrategy.random()) # the selection strategy is a guess as i can't find more info on it