| 42 | |
| 43 | |
| 44 | def download_database(ctx: Context) -> None: |
| 45 | click.echo("Downloading getsploit database archive. Please wait...") |
| 46 | with tempfile.TemporaryDirectory() as tmpdir: |
| 47 | path = pathlib.Path(tmpdir) / "getsploit.db.zip" |
| 48 | with ( |
| 49 | ctx.client.stream("GET", "v3/archive/getsploit", follow_redirects=True) as resp, |
| 50 | ): |
| 51 | try: |
| 52 | resp.raise_for_status() |
| 53 | except httpx.HTTPStatusError as e: |
| 54 | raise click.ClickException(str(e)) |
| 55 | with ( |
| 56 | click.progressbar( |
| 57 | length=int(resp.headers["Content-Length"]), label="Reading archive" |
| 58 | ) as bar, |
| 59 | path.open("wb") as output, |
| 60 | ): |
| 61 | for chunk in resp.iter_bytes(): |
| 62 | output.write(chunk) |
| 63 | bar.update(len(chunk)) |
| 64 | with zipfile.ZipFile(path, "r") as archive: |
| 65 | archive.extractall(ctx.home_path) |
| 66 | |
| 67 | |
| 68 | def search_exploit_local(ctx: Context, query: str, limit: int) -> Iterable[Mapping[str, Any]]: |