Enables importing the results obtained from running sqlmap to a PostgreSQL or sqlite database, facilitating searches with greater ease
| 10 | |
| 11 | |
| 12 | class MainConsole(cmd2.Cmd): |
| 13 | """Enables importing the results obtained from running sqlmap to a PostgreSQL |
| 14 | or sqlite database, facilitating searches with greater ease |
| 15 | """ |
| 16 | def __init__(self, *args, **kwargs) -> None: |
| 17 | super().__init__(*args, **kwargs, allow_cli_args=False, auto_load_commands=False) |
| 18 | cmd = Color.format("[yellow]>[blue]>[red]>[reset]") |
| 19 | prompt = Color.format("[yellow]mapXp[blue]lo[red]re[reset]") |
| 20 | self._default_prompt = f'{prompt} {cmd} ' |
| 21 | |
| 22 | self.prompt = self._default_prompt |
| 23 | self.register_postcmd_hook(self._postcmd) |
| 24 | self.debug=True |
| 25 | self._results = [] |
| 26 | self._core = DataManager() |
| 27 | self._filter_options = Settings.filter_options |
| 28 | self._args = args |
| 29 | self._commands = [] |
| 30 | |
| 31 | use_parser = Cmd2ArgumentParser(add_help=locale.get("help_import")) |
| 32 | |
| 33 | subparser = use_parser.add_subparsers(dest='module') |
| 34 | |
| 35 | import_parser = subparser.add_parser('import', help='Import module') |
| 36 | config_parser = subparser.add_parser('config', help='Config Module') |
| 37 | |
| 38 | config_parser.add_argument('section',choices=list(Settings.setting.keys()), default=None, nargs='?') |
| 39 | |
| 40 | import_parser.add_argument('--database', help="Database to be imported from sqlmap") |
| 41 | import_parser.add_argument('--input',help="Path of the site extracted from sqlmap (before /dump)") |
| 42 | import_parser.add_argument('--delimiter', help="sqlmap Output File Delimiter") |
| 43 | import_parser.add_argument('--dbms', choices=['postgres','sqlite'], help="Set DBMS to import data") |
| 44 | |
| 45 | |
| 46 | def _load_module(self, arg=None) -> None: |
| 47 | module = None |
| 48 | for command in self._commands: |
| 49 | self.do_back(command["module"]) |
| 50 | |
| 51 | if not hasattr(arg, 'module'): |
| 52 | module = QueryCommandSet(arg) |
| 53 | elif arg.module == 'import': |
| 54 | module = ImportCommand() |
| 55 | elif arg.module == 'config': |
| 56 | module = ConfigCommandSet(arg, section=arg.section) |
| 57 | |
| 58 | if module is not None: |
| 59 | self._commands.append({"module":arg.module if hasattr(arg,'module') else 'main', "command":module, "args": arg}) |
| 60 | self.register_command_set(module) |
| 61 | |
| 62 | def _postcmd(self, data: cmd2.plugin.PostcommandData) -> cmd2.plugin.PostcommandData: |
| 63 | self.prompt = self._default_prompt |
| 64 | for command in self._commands: |
| 65 | self.prompt+=command["module"]+Color.format("[green]>[reset] ") |
| 66 | |
| 67 | if len(self._commands)== 0: |
| 68 | self._load_module(None) |
| 69 | return data |