def test_default_arguments_for_collector_producer(self): """ Test the correct default initialization. """ self.init_db() workspace = "unittest" # Initialize collector producer commands_queue = queue.Queue() producer = CollectorProducer(self._engine, commands_queue) parser = CollectorProducer.get_argument_parser(description="") collector_group = CollectorProducer.add_collector_argument_group( parser) producer.add_argparser_arguments(collector_group) # create database with self._engine.session_scope() as session: self.create_workspace(session=session, workspace=workspace) args = parser.parse_args(["-w", workspace]) arguments = vars(args) producer.init(arguments) # Check settings self.assertEqual(1, producer._number_of_threads) self.assertEqual(workspace, producer._workspace) self.assertIsNone(producer._vhost) self.assertListEqual([], producer._included_items) self.assertListEqual([], producer._excluded_items) self.assertListEqual([], producer._restart_statuses) self.assertFalse(producer._strict_open) self.assertIsNone(producer._delay_min) self.assertIsNone(producer._delay_max) self.assertFalse(producer._continue_execution) self.assertFalse(producer._print_commands) self.assertFalse(producer._analyze_results)
def test_set_arguments_for_collector_producer(self): """ Test the correct initialization using user-specific configurations. """ self.init_db() workspace = "unittest" # Initialize collector producer commands_queue = queue.Queue() producer = CollectorProducer(self._engine, commands_queue) parser = CollectorProducer.get_argument_parser(description="") collector_group = CollectorProducer.add_collector_argument_group( parser) producer.add_argparser_arguments(collector_group) # create database with self._engine.session_scope() as session: self.create_workspace(session=session, workspace=workspace) args = parser.parse_args([ "-w", workspace, "--testing", "-S", "--vhost", VhostChoice.domain.name, "--tld", "--debug", "--strict", "--analyze", "--filter", "127.0.0.1", "+127.0.0.2", "--threads", "10", "-D", "5", "-M", "10", "--restart", CommandStatus.failed.name, CommandStatus.terminated.name, "--continue", "--proxychains" ]) arguments = vars(args) producer.init(arguments) # Check settings self.assertEqual(10, producer._number_of_threads) self.assertEqual(workspace, producer._workspace) self.assertEqual(VhostChoice.domain, producer._vhost) self.assertListEqual(["127.0.0.2"], producer._included_items) self.assertListEqual(["127.0.0.1"], producer._excluded_items) self.assertListEqual([CommandStatus.failed, CommandStatus.terminated], producer._restart_statuses) self.assertTrue(producer._strict_open) self.assertEqual(5, producer._delay_min) self.assertEqual(10, producer._delay_max) self.assertTrue(producer._continue_execution) self.assertTrue(producer._print_commands) self.assertTrue(producer._analyze_results)
def test_set_arguments_for_collector_producer(self): """ whoishost is a collector that has timeout, delay_min, and delay_max set. this unittest checks whether all kiscollect arguments are applied on the collector. """ self.init_db() workspace = "unittest" # Initialize collector producer commands_queue = queue.Queue() producer = CollectorProducer(self._engine, commands_queue) parser = CollectorProducer.get_argument_parser(description="") collector_group = CollectorProducer.add_collector_argument_group( parser) producer.add_argparser_arguments(collector_group) # create database with self._engine.session_scope() as session: self.create_workspace(session=session, workspace=workspace) with tempfile.TemporaryDirectory() as temp_dir: password_file = os.path.join(temp_dir, "passwords.txt") user_file = os.path.join(temp_dir, "users.txt") combo_file = os.path.join(temp_dir, "combo.txt") wordlist_file = os.path.join(temp_dir, "wordlist.txt") args = parser.parse_args([ "-w", workspace, "--whoishost", "-o", temp_dir, "-t", "5", "--hashes", "--http-proxy", "https://127.0.0.1:8080", "--cookies", "JSESSIONID=a", "--dns-server", "8.8.8.8", "--user-agent", "wget/3.8", "--password", "Password123", "-P", password_file, "-d", "red.local", "-u", "testuser", "-U", user_file, "-C", combo_file, "--proxychains", "--analyze", "--filter", "127.0.0.1", "+127.0.0.2", "--tld", "-L", wordlist_file, "-S" ]) arguments = vars(args) producer.init(arguments) # Check configuration self.assertEqual(1, len(producer._selected_collectors)) self.assertEqual("whoishost", producer._selected_collectors[0].name) self.assertEqual( 510, producer._selected_collectors[0].instance.priority) self.assertEqual( 30, producer._selected_collectors[0].instance._timeout) self.assertEqual("whoishost", producer._selected_collectors[0].instance._name) self.assertFalse( producer._selected_collectors[0].instance._active_collector) self.assertEqual( temp_dir, producer._selected_collectors[0].instance._output_dir) self.assertEqual( 5, producer._selected_collectors[0].instance._number_of_threads) self.assertTrue(producer._selected_collectors[0].instance._hashes) self.assertEqual( "127.0.0.1:8080", producer._selected_collectors[0].instance._http_proxy.netloc) self.assertListEqual( ["JSESSIONID=a"], producer._selected_collectors[0].instance._cookies) self.assertEqual( 2, producer._selected_collectors[0].instance._min_delay) self.assertEqual( 5, producer._selected_collectors[0].instance._max_delay) self.assertEqual( 1, producer._selected_collectors[0].instance._max_threads) self.assertEqual( "8.8.8.8", producer._selected_collectors[0].instance._dns_server) self.assertEqual( "wget/3.8", producer._selected_collectors[0].instance._user_agent) self.assertEqual( "Password123", producer._selected_collectors[0].instance._password) self.assertEqual( password_file, producer._selected_collectors[0].instance._password_file) self.assertEqual("red.local", producer._selected_collectors[0].instance._domain) self.assertEqual("testuser", producer._selected_collectors[0].instance._user) self.assertEqual( user_file, producer._selected_collectors[0].instance._user_file) self.assertEqual( combo_file, producer._selected_collectors[0].instance._combo_file) self.assertTrue( producer._selected_collectors[0].instance._proxychains) self.assertTrue(producer._selected_collectors[0].instance._analyze) self.assertListEqual( ["127.0.0.2"], producer._selected_collectors[0].instance._whitelist_filter) self.assertListEqual( ["127.0.0.1"], producer._selected_collectors[0].instance._blacklist_filter) self.assertTrue( producer._selected_collectors[0].instance._scan_tld) self.assertListEqual( [wordlist_file], producer._selected_collectors[0].instance._wordlist_files) self.assertTrue( producer._selected_collectors[0].instance._print_commands) self.assertEqual( "nobody", producer._selected_collectors[0].instance.exec_user.pw_name)
def test_force_timout_for_collector_whoishost(self): """ whoishost is a collector that has timeout, delay_min, and delay_max set. if a user specifies a default timeout, then the collector's default timeout is overwritten. """ self.init_db() workspace = "unittest" # Initialize collector producer commands_queue = queue.Queue() producer = CollectorProducer(self._engine, commands_queue) parser = CollectorProducer.get_argument_parser(description="") collector_group = CollectorProducer.add_collector_argument_group( parser) producer.add_argparser_arguments(collector_group) # create database with self._engine.session_scope() as session: self.create_workspace(session=session, workspace=workspace) args = parser.parse_args(["-w", workspace, "--whoishost", "-T", "60"]) arguments = vars(args) producer.init(arguments) # Check configuration self.assertEqual(1, len(producer._selected_collectors)) self.assertEqual("whoishost", producer._selected_collectors[0].name) self.assertEqual(510, producer._selected_collectors[0].instance.priority) self.assertEqual(60, producer._selected_collectors[0].instance._timeout) self.assertEqual("whoishost", producer._selected_collectors[0].instance._name) self.assertFalse( producer._selected_collectors[0].instance._active_collector) self.assertIsNone( producer._selected_collectors[0].instance._output_dir) self.assertEqual( 1, producer._selected_collectors[0].instance._number_of_threads) self.assertFalse(producer._selected_collectors[0].instance._hashes) self.assertIsNone( producer._selected_collectors[0].instance._http_proxy) self.assertListEqual( [], producer._selected_collectors[0].instance._cookies) self.assertEqual(2, producer._selected_collectors[0].instance._min_delay) self.assertEqual(5, producer._selected_collectors[0].instance._max_delay) self.assertEqual( 1, producer._selected_collectors[0].instance._max_threads) self.assertIsNone( producer._selected_collectors[0].instance._dns_server) self.assertIsNone( producer._selected_collectors[0].instance._user_agent) self.assertIsNone(producer._selected_collectors[0].instance._password) self.assertIsNone( producer._selected_collectors[0].instance._password_file) self.assertIsNone(producer._selected_collectors[0].instance._user) self.assertIsNone(producer._selected_collectors[0].instance._domain) self.assertIsNone(producer._selected_collectors[0].instance._user_file) self.assertIsNone( producer._selected_collectors[0].instance._combo_file) self.assertFalse( producer._selected_collectors[0].instance._proxychains) self.assertFalse(producer._selected_collectors[0].instance._analyze) self.assertListEqual( [], producer._selected_collectors[0].instance._whitelist_filter) self.assertListEqual( [], producer._selected_collectors[0].instance._blacklist_filter) self.assertFalse(producer._selected_collectors[0].instance._scan_tld) self.assertListEqual( [], producer._selected_collectors[0].instance._wordlist_files) self.assertFalse( producer._selected_collectors[0].instance._print_commands) self.assertEqual( "nobody", producer._selected_collectors[0].instance.exec_user.pw_name)
if __name__ == "__main__": try: engine = Engine() DeclarativeBase.metadata.bind = engine.engine commands_queue = queue.Queue() producer = CollectorProducer(engine, commands_queue) epilog='''---- USE CASES ---- use cases can be obtained from the following wiki page: https://github.com/chopicalqui/KaliIntelligenceSuite/wiki/KIS-Use-Cases#kiscollect ''' parser = CollectorProducer.get_argument_parser(description=__doc__, epilog=epilog) collector_group = CollectorProducer.add_collector_argument_group(parser) producer.add_argparser_arguments(collector_group) args = parser.parse_args() # Check KIS' database status and version engine.perform_preflight_check(appy_patches=True, ask_user=True) if os.geteuid() != 0 and not args.print_commands: config = Collector() print("{} must be executed with root privileges. afterwards, it is possible to execute " "individual commands with lower privileged users like 'nobody'".format(sys.argv[0]), file=sys.stderr) sys.exit(1) if args.list: engine.print_workspaces() sys.exit(1) with tempfile.TemporaryDirectory() as temp_dir: if args.testing: engine.production = False