|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 |
|
3 | | -import runpy |
| 3 | +import argparse |
| 4 | +import shutil |
| 5 | +import sys |
4 | 6 | from pathlib import Path |
5 | 7 |
|
6 | 8 |
|
| 9 | +EXTERNAL_DIRS = [ |
| 10 | + "bbot_active", |
| 11 | + "bbot_passive", |
| 12 | + "ffuf", |
| 13 | + "httpx", |
| 14 | + "katana", |
| 15 | + "masscan", |
| 16 | + "nessus", |
| 17 | + "nmap", |
| 18 | + "nuclei", |
| 19 | + "subdomains", |
| 20 | +] |
| 21 | + |
| 22 | +INTERNAL_DIRS = [ |
| 23 | + "ffuf", |
| 24 | + "httpx", |
| 25 | + "katana", |
| 26 | + "masscan", |
| 27 | + "nessus", |
| 28 | + "nmap", |
| 29 | + "nuclei", |
| 30 | +] |
| 31 | + |
| 32 | +AD_DIRS = [ |
| 33 | + "ad_office", |
| 34 | + "ad_pci", |
| 35 | +] |
| 36 | + |
| 37 | +MOBILE_DIRS = [ |
| 38 | + "Android", |
| 39 | + "iOS", |
| 40 | +] |
| 41 | + |
| 42 | + |
| 43 | +def usage_text(script_name: str) -> str: |
| 44 | + return ( |
| 45 | + f"Usage:\n" |
| 46 | + f" {script_name} <project-name>\n\n" |
| 47 | + f"Description:\n" |
| 48 | + f" Interactive script for creating a pentest project directory structure.\n\n" |
| 49 | + f"Options:\n" |
| 50 | + f" -h, --help Show this help message and exit\n\n" |
| 51 | + f"Example:\n" |
| 52 | + f" {script_name} ACME-Pentest-2025\n" |
| 53 | + ) |
| 54 | + |
| 55 | + |
| 56 | +def die(message: str) -> None: |
| 57 | + print(f"Error: {message}", file=sys.stderr) |
| 58 | + raise SystemExit(1) |
| 59 | + |
| 60 | + |
| 61 | +def ask_yn(prompt: str) -> bool: |
| 62 | + while True: |
| 63 | + answer = input(f"{prompt} (Y/N): ").strip() |
| 64 | + if answer.lower() == "y": |
| 65 | + return True |
| 66 | + if answer.lower() == "n": |
| 67 | + return False |
| 68 | + print("Please enter Y or N.") |
| 69 | + |
| 70 | + |
| 71 | +def validate_project_name(project_name: str) -> None: |
| 72 | + if ( |
| 73 | + not project_name |
| 74 | + or project_name in {".", "..", "/"} |
| 75 | + or "/" in project_name |
| 76 | + ): |
| 77 | + die( |
| 78 | + f"Invalid project name: '{project_name}' " |
| 79 | + "(must be a simple folder name without slashes)" |
| 80 | + ) |
| 81 | + |
| 82 | + |
| 83 | +def ensure_scoped_dirs(base_dir: Path, prefix: str, names: list[str]) -> None: |
| 84 | + target_base = base_dir / prefix if prefix else base_dir |
| 85 | + if prefix: |
| 86 | + target_base.mkdir(parents=True, exist_ok=True) |
| 87 | + for name in names: |
| 88 | + (target_base / name).mkdir(parents=True, exist_ok=True) |
| 89 | + |
| 90 | + |
| 91 | +def parse_args(argv: list[str] | None = None) -> argparse.Namespace: |
| 92 | + parser = argparse.ArgumentParser(add_help=False) |
| 93 | + parser.add_argument("project_name", nargs="?") |
| 94 | + parser.add_argument("-h", "--help", action="store_true") |
| 95 | + return parser.parse_args(argv) |
| 96 | + |
| 97 | + |
| 98 | +def main(argv: list[str] | None = None) -> int: |
| 99 | + args = parse_args(argv) |
| 100 | + script_name = Path(sys.argv[0]).name if argv is None else "maketask" |
| 101 | + |
| 102 | + if args.help: |
| 103 | + print(usage_text(script_name)) |
| 104 | + return 0 |
| 105 | + |
| 106 | + if not args.project_name: |
| 107 | + print(usage_text(script_name), file=sys.stderr) |
| 108 | + return 1 |
| 109 | + |
| 110 | + project_name = args.project_name |
| 111 | + validate_project_name(project_name) |
| 112 | + |
| 113 | + project_path = Path(project_name) |
| 114 | + print(f"[*] Creating pentest project: {project_name}") |
| 115 | + |
| 116 | + if project_path.exists(): |
| 117 | + if ask_yn(f"Directory '{project_name}' already exists. Overwrite it?"): |
| 118 | + if project_path.is_dir(): |
| 119 | + shutil.rmtree(project_path) |
| 120 | + else: |
| 121 | + project_path.unlink() |
| 122 | + else: |
| 123 | + die(f"Directory '{project_name}' already exists") |
| 124 | + |
| 125 | + project_path.mkdir(parents=True, exist_ok=True) |
| 126 | + (project_path / "Report").mkdir(parents=True, exist_ok=True) |
| 127 | + (project_path / "Screenshots").mkdir(parents=True, exist_ok=True) |
| 128 | + |
| 129 | + has_external = ask_yn("Is there External pentesting scope?") |
| 130 | + has_internal = ask_yn("Is there Internal pentesting scope?") |
| 131 | + has_ad = has_internal and ask_yn("Is this a Windows environment with Active Directory?") |
| 132 | + has_mobile = ask_yn("Is there Mobile pentesting scope?") |
| 133 | + |
| 134 | + external_prefix = "External" if has_external and has_internal else "" |
| 135 | + internal_prefix = "Internal" if has_external and has_internal else "" |
| 136 | + |
| 137 | + if has_external: |
| 138 | + ensure_scoped_dirs(project_path, external_prefix, EXTERNAL_DIRS) |
| 139 | + |
| 140 | + if has_internal: |
| 141 | + ensure_scoped_dirs(project_path, internal_prefix, INTERNAL_DIRS) |
| 142 | + if has_ad: |
| 143 | + ensure_scoped_dirs(project_path, internal_prefix, AD_DIRS) |
| 144 | + |
| 145 | + if has_mobile: |
| 146 | + ensure_scoped_dirs(project_path, "Mobile", MOBILE_DIRS) |
| 147 | + |
| 148 | + print(f"[+] Project '{project_name}' successfully created") |
| 149 | + return 0 |
| 150 | + |
| 151 | + |
7 | 152 | if __name__ == "__main__": |
8 | | - runpy.run_path(str(Path(__file__).with_name("maketask.py")), run_name="__main__") |
| 153 | + raise SystemExit(main()) |
0 commit comments