Skip to content

Commit 64af3eb

Browse files
committed
split dump command
1 parent 375a673 commit 64af3eb

5 files changed

Lines changed: 48 additions & 16 deletions

File tree

src/powerpwn/cli/arguments.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,17 @@ def module_gui(sub_parser: argparse.ArgumentParser):
1313

1414
def module_dump(sub_parser: argparse.ArgumentParser):
1515
dump_parser = sub_parser.add_parser(
16-
"dump",
16+
"dump", description="Dump content for all available connection from recon", help="Dump content for all available connection from recon"
17+
)
18+
dump_parser.add_argument("-c", "--clear-cache", action="store_true", help="Clear local disk cache")
19+
dump_parser.add_argument("--cache-path", default=CACHE_PATH, help="Path to store collected resources and data.")
20+
dump_parser.add_argument("-t", "--tenant", required=False, type=str, help="Tenant id to connect.")
21+
dump_parser.add_argument("-g", "--gui", action="store_true", help="Run local server for gui.")
22+
23+
24+
def module_recon(sub_parser: argparse.ArgumentParser):
25+
dump_parser = sub_parser.add_parser(
26+
"recon",
1727
description="Recon for available data connections and dump their content",
1828
help="Recon for available data connections and dump their content.",
1929
)
@@ -126,6 +136,7 @@ def parse_arguments():
126136
command_subparsers = parser.add_subparsers(help="command", dest="command")
127137

128138
module_dump(command_subparsers)
139+
module_recon(command_subparsers)
129140
module_gui(command_subparsers)
130141
module_backdoor(command_subparsers)
131142
module_nocodemalware(command_subparsers)

src/powerpwn/cli/runners.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,7 @@ def __init_command_token(args, scope: str) -> str:
2828
return acquire_token(scope=scope, tenant=args.tenant)
2929

3030

31-
def run_dump_command(args):
32-
_run_collect_resources_command(args)
33-
_run_collect_data_command(args)
34-
logger.info(f"Dump is completed in {args.cache_path}")
35-
36-
if args.gui:
37-
logger.info("Going to run local server for gui")
38-
run_gui_command(args)
39-
40-
41-
def _run_collect_resources_command(args):
31+
def run_recon_command(args):
4232
# cache
4333
if args.clear_cache:
4434
try:
@@ -52,14 +42,29 @@ def _run_collect_resources_command(args):
5242
entities_fetcher = ResourcesCollector(token=token, cache_path=args.cache_path)
5343
entities_fetcher.collect_and_cache()
5444

45+
logger.info(f"Recon is completed in {args.cache_path}/resources")
46+
47+
if args.gui:
48+
logger.info("Going to run local server for gui")
49+
run_gui_command(args)
50+
5551

5652
def run_gui_command(args):
5753
Gui().run(cache_path=args.cache_path)
5854

5955

60-
def _run_collect_data_command(args):
56+
def run_dump_command(args):
6157
token = __init_command_token(args, API_HUB_SCOPE)
62-
DataCollector(token=token, cache_path=args.cache_path).collect()
58+
is_data_collected = DataCollector(token=token, cache_path=args.cache_path).collect()
59+
if not is_data_collected:
60+
logger.info("No data dumped. Please run recon first.")
61+
return None
62+
63+
logger.info(f"Dump is completed in {args.cache_path}/data")
64+
65+
if args.gui:
66+
logger.info("Going to run local server for gui")
67+
run_gui_command(args)
6368

6469

6570
def run_backdoor_flow_command(args):

src/powerpwn/main.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44

55
from powerpwn.cli.arguments import parse_arguments
66
from powerpwn.cli.const import LOGGER_NAME
7-
from powerpwn.cli.runners import run_backdoor_flow_command, run_dump_command, run_gui_command, run_nocodemalware_command, run_phishing_command
7+
from powerpwn.cli.runners import (
8+
run_backdoor_flow_command,
9+
run_dump_command,
10+
run_gui_command,
11+
run_nocodemalware_command,
12+
run_phishing_command,
13+
run_recon_command,
14+
)
815

916
logger = logging.getLogger(LOGGER_NAME)
1017

@@ -22,6 +29,8 @@ def main():
2229

2330
if command == "dump":
2431
run_dump_command(args)
32+
elif command == "recon":
33+
run_recon_command(args)
2534
elif command == "gui":
2635
run_gui_command(args)
2736
elif command == "backdoor":

src/powerpwn/powerdump/collect/data_collectors/data_collector.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ def __init__(self, cache_path: str, token: str) -> None:
1717
self.__session = init_session(token=token)
1818
self.__data_collectors = [ConnectionsDataCollector]
1919

20-
def collect(self) -> None:
20+
def collect(self) -> bool:
21+
environment_ids = get_environment_ids(self.__cache_path)
22+
if len(environment_ids) == 0:
23+
return False
24+
2125
for env_id in get_environment_ids(self.__cache_path):
2226
env_dumps_root_dir = env_collected_data_path(env_id, self.__cache_path)
2327
if os.path.isdir(env_dumps_root_dir):
@@ -26,3 +30,4 @@ def collect(self) -> None:
2630
for data_collector in self.__data_collectors:
2731
data_collector_instance = data_collector(self.__cache_path)
2832
data_collector_instance.collect(self.__session, env_id, env_dumps_root_dir)
33+
return True

src/powerpwn/powerdump/utils/model_loaders.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ def load_connectors(cache_path: str, env_id: Optional[str] = None) -> Generator[
102102

103103

104104
def get_environment_ids(cache_path: str) -> List[str]:
105+
if not os.path.exists(cache_path):
106+
return []
105107
return os.listdir(entities_path(cache_path))
106108

107109

0 commit comments

Comments
 (0)