# Create your Manager with your monitor attached manager = Manager(monitor, config_path="./examples/example.ini") # Set some custom configuration parameters manager["auto"] = True manager["outdir"] = "./example-results-{0}".format(time.strftime("%Y%m%d-%H%M%S")) manager["exclude"] = ["crypto"] manager["flag-format"] = r"FLAG{.*?}" # Optionally, manually register unit classes # manager.finder.register(CustomChallengeUnit) # Or load units automatically from a directory # manager.finder.find('./customunits', 'customunits.') # Start the manager (empty queue at the moment) manager.start() # Create a generic target target = manager.target("./interesting-file.txt") # Enumerate units that are applicable and queue them for evaluation for unit in manager.finder.match(target): logging.info("queuing {0} for {1}".format(unit, target)) manager.queue(unit) # A short-hand for queuing targets with all matching units: # target = manager.queue_target('./interesting-file.txt') # More targets could be queued up until you call `join` at which point the # queue would be "closed" and would cause an exception if `queue` is called.
class KatanaTest(TestCase): FLAG_FORMAT = "FLAG{.*?}" def setUp(self): """ Setup a Manager and Monitor object The Katana Unit Tests can override this method, but must call the parent. You can use this to create special temporary target files, start a web server, or anything else needed to evaluate your target. """ # This is a nasty hack os.system("rm -rf ./results 2>&1 >/dev/null") # Create the monitor and set the flag format self.monitor = Monitor() self.manager = Manager(monitor=self.monitor) self.manager["manager"]["flag-format"] = self.FLAG_FORMAT self.manager["manager"]["auto"] = "yes" # Ignore annoying resource warnings warnings.simplefilter("ignore", ResourceWarning) def tearDown(self): """ Tear down any artifacts from the last run The Katana Unit Tests can override this method, but must call the parent. You can use this method to clean up any extra temporary files that may have been created for the target or any threads/services started for unit testing. """ # Tear down our object tree del self.monitor del self.manager # This is a nasty hack os.system("rm -rf ./results 2>&1 >/dev/null") def katana_test( self, config: str, target: str, correct_flag: str, timeout: float = 10 ): """ Perform a test with the given configuration, target and flag :param config: Katana configuration file :type config: str :param target: The target for this katana test (url, filename, raw data, etc) :type target: str :param correct_flag: The correct flag which katana should find. :type correct_flag: str :param timeout: The timeout in seconds for this test, defaults to 10 :type timeout: float, optional """ if isinstance(correct_flag, bytes): correct_flag = correct_flag.decode("utf-8") # Load given configuration self.manager.read_file(io.StringIO(config)) # Queue the target and begin processing self.manager.queue_target(target) self.manager.start() # Ensure wait for completion. Error if we time out self.assertTrue(self.manager.join(timeout=timeout), "manager timed out") # Ensure we have at least 1 flag self.assertGreater(len(self.monitor.flags), 0, "no flags found") # Ensure the flag matches expected output for flag in self.monitor.flags: if flag[1] == correct_flag: return # Fail otherwise self.fail(f"correct flag not found (found: {self.monitor.flags})")