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)
Esempio n. 2
0
 def create_collector_producer(self,
                               command_queue: queue.Queue = None
                               ) -> CollectorProducer:
     """
     This method creates an instance of the CollectorProducer class
     """
     return CollectorProducer(engine=self._engine,
                              command_queue=command_queue,
                              **self._arguments)
Esempio n. 3
0
 def create_commands(self, collectors: List[ArgParserModule]):
     """
     Creates commands based on the provided list of collectors
     """
     for module in collectors:
         if not module.instance:
             module.create_instance(engine=self._engine, **self._arguments)
         module.collector_type_info = CollectorProducer.get_collector_types(
             module, vhost=self._vhost)
     producer = self.create_collector_producer()
     producer.selected_collectors.extend(collectors)
     producer._create()
Esempio n. 4
0
 def create_collector_instance(self,
                               arg_parse_module: ArgParserModule = None,
                               collector_class: type = None,
                               collector_name: str = None) -> BaseCollector:
     """
     This method creates a collector instance based on the given class and name
     """
     if arg_parse_module:
         arg_parse_module.create_instance(**self._arguments)
         arg_parse_module.collector_type_info = CollectorProducer.get_collector_types(
             arg_parse_module, vhost=self._vhost)
         result = arg_parse_module
     else:
         result = collector_class(engine=self._engine,
                                  name=collector_name,
                                  **self._arguments)
     return result
Esempio n. 5
0
 def create_execute_commands(self, collectors: List[ArgParserModule]):
     """
     Creates and executes commands based on the provided list of collectors
     """
     command_queue = queue.Queue()
     for module in collectors:
         if not module.instance:
             module.create_instance(engine=self._engine, **self._arguments)
         module.collector_type_info = CollectorProducer.get_collector_types(
             module, vhost=self._vhost)
     producer = self.create_collector_producer(command_queue=command_queue)
     producer.selected_collectors.extend(collectors)
     consumer = CollectorConsumer(engine=self._engine,
                                  commands_queue=command_queue,
                                  producer_thread=producer)
     consumer.start()
     producer.start()
     producer.join()
 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)
from database.config import Collector
from database.config import BaseConfig
from view.console import KisCollectConsole
from database.utils import Engine
from database.utils import DeclarativeBase
from collectors.os.collector import CollectorProducer
from database.model import DatabaseVersionMismatchError
from database.model import DatabaseUninitializationError


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()