Przeglądaj źródła

made list of available attacks dynamic

Jonathan Speth 6 lat temu
rodzic
commit
8cf1b4e7e8
1 zmienionych plików z 10 dodań i 5 usunięć
  1. 10 5
      code/Core/AttackController.py

+ 10 - 5
code/Core/AttackController.py

@@ -53,15 +53,20 @@ class AttackController:
             :return: The best matching attack in case one was found
             """
 
-            # TODO: get list dynamically from module names
-            list_of_attacks = ('DDoSAttack', 'EternalBlueExploit', 'FTPWinaXeExploit', 'JoomlaRegPrivExploit',
-                               'MS17ScanAttack', 'PortscanAttack', 'SalityBotnet', 'SMBLorisAttack', 'SMBScanAttack',
-                               'SQLiAttack')
+            import pkgutil
+            import Attack
+
+            # Find all attacks, exclude some classes
+            package = Attack
+            available_attacks = []
+            for _, name, __ in pkgutil.iter_modules(package.__path__):
+                if name != 'BaseAttack' and name != 'AttackParameters':
+                    available_attacks.append(name)
 
             input_name = input_name.lower()
             highest_sim = 0.0
             highest_sim_attack = None
-            for attack in list_of_attacks:
+            for attack in available_attacks:
                 # Compares input with one of the available attacks
                 # Makes comparison with lowercase version with generic 'attack' and 'exploit' ending removed
                 similarity = difflib.SequenceMatcher(None, input_name,