|
1 | | -import click |
2 | | -from pymobiledevice3.cli.cli_common import Command |
3 | | -from pymobiledevice3.lockdown_service_provider import LockdownServiceProvider |
| 1 | +from typing import Annotated, Optional |
4 | 2 |
|
5 | | -from harlogger.sniffers import Filters, HostSnifferProfile, MobileSnifferProfile, SnifferPreference |
6 | | - |
7 | | - |
8 | | -@click.group() |
9 | | -def cli(): |
10 | | - pass |
11 | | - |
12 | | - |
13 | | -@cli.group() |
14 | | -def mobile(): |
15 | | - """ Mobile sniffing options """ |
16 | | - pass |
| 3 | +import typer |
| 4 | +from pymobiledevice3.cli.cli_common import ServiceProviderDep |
| 5 | +from typer_injector import InjectingTyper |
17 | 6 |
|
| 7 | +from harlogger.sniffers import Filters, HostSnifferProfile, MobileSnifferProfile, SnifferPreference |
18 | 8 |
|
19 | | -@mobile.command('profile', cls=Command) |
20 | | -@click.option('pids', '-p', '--pid', type=click.INT, multiple=True, help='filter pid list') |
21 | | -@click.option('--color/--no-color', default=True) |
22 | | -@click.option('process_names', '-pn', '--process-name', multiple=True, help='filter process name list') |
23 | | -@click.option('images', '-i', '--image', multiple=True, help='filter image list') |
24 | | -@click.option('--request/--no-request', is_flag=True, default=True, help='show requests') |
25 | | -@click.option('--response/--no-response', is_flag=True, default=True, help='show responses') |
26 | | -@click.option('-u', '--unique', is_flag=True, help='show only unique requests per image/pid/method/uri combination') |
27 | | -@click.option('--black-list/--white-list', default=True, is_flag=True) |
28 | | -def mobile_profile(service_provider: LockdownServiceProvider, pids, process_names, color, request, response, images, |
29 | | - unique, black_list): |
| 9 | +cli = InjectingTyper( |
| 10 | + help="Monitor HTTP traffic on given macOS/iOS devices.", |
| 11 | + no_args_is_help=True, |
| 12 | +) |
| 13 | +mobile = InjectingTyper(help="Mobile sniffing options") |
| 14 | +cli.add_typer(mobile, name="mobile") |
| 15 | + |
| 16 | + |
| 17 | +@mobile.command("profile") |
| 18 | +def mobile_profile( |
| 19 | + service_provider: ServiceProviderDep, |
| 20 | + pids: Annotated[Optional[list[int]], typer.Option("-p", "--pid", help="filter pid list")] = None, |
| 21 | + process_names: Annotated[ |
| 22 | + Optional[list[str]], |
| 23 | + typer.Option("-pn", "--process-name", help="filter process name list"), |
| 24 | + ] = None, |
| 25 | + color: Annotated[bool, typer.Option("--color/--no-color")] = True, |
| 26 | + request: Annotated[bool, typer.Option("--request/--no-request", help="show requests")] = True, |
| 27 | + response: Annotated[bool, typer.Option("--response/--no-response", help="show responses")] = True, |
| 28 | + images: Annotated[Optional[list[str]], typer.Option("-i", "--image", help="filter image list")] = None, |
| 29 | + unique: Annotated[ |
| 30 | + bool, |
| 31 | + typer.Option("-u", "--unique", help="show only unique requests per image/pid/method/uri combination"), |
| 32 | + ] = False, |
| 33 | + black_list: Annotated[bool, typer.Option("--black-list/--white-list")] = True, |
| 34 | +): |
30 | 35 | """ |
31 | 36 | Sniff using CFNetworkDiagnostics.mobileconfig profile. |
32 | 37 |
|
33 | 38 | This requires the specific Apple profile to be installed for the sniff to work. |
34 | 39 | """ |
35 | 40 | filters = Filters(pids, process_names, images, black_list) |
36 | | - MobileSnifferProfile(service_provider, filters=filters, request=request, response=response, color=color, |
37 | | - unique=unique).sniff() |
38 | | - |
39 | | - |
40 | | -@mobile.command('preference', cls=Command) |
41 | | -@click.option('-o', '--out', type=click.File('w'), help='file to store the har entries into upon exit (ctrl+c)') |
42 | | -@click.option('pids', '-p', '--pid', type=click.INT, multiple=True, help='filter pid list') |
43 | | -@click.option('--color/--no-color', default=True) |
44 | | -@click.option('process_names', '-pn', '--process-name', multiple=True, help='filter process name list') |
45 | | -@click.option('images', '-i', '--image', multiple=True, help='filter image list') |
46 | | -@click.option('--request/--no-request', is_flag=True, default=True, help='show requests') |
47 | | -@click.option('--response/--no-response', is_flag=True, default=True, help='show responses') |
48 | | -@click.option('-u', '--unique', is_flag=True, help='show only unique requests per image/pid/method/uri combination') |
49 | | -@click.option('--black-list/--white-list', default=True, is_flag=True) |
50 | | -def mobile_preference(service_provider: LockdownServiceProvider, out, pids, process_names, images, request, response, |
51 | | - color, unique, black_list): |
| 41 | + MobileSnifferProfile( |
| 42 | + service_provider, filters=filters, request=request, response=response, color=color, unique=unique |
| 43 | + ).sniff() |
| 44 | + |
| 45 | + |
| 46 | +@mobile.command("preference") |
| 47 | +def mobile_preference( |
| 48 | + service_provider: ServiceProviderDep, |
| 49 | + out: Annotated[ |
| 50 | + Optional[typer.FileTextWrite], |
| 51 | + typer.Option("-o", "--out", help="file to store the har entries into upon exit (ctrl+c)"), |
| 52 | + ] = None, |
| 53 | + pids: Annotated[Optional[list[int]], typer.Option("-p", "--pid", help="filter pid list")] = None, |
| 54 | + process_names: Annotated[ |
| 55 | + Optional[list[str]], |
| 56 | + typer.Option("-pn", "--process-name", help="filter process name list"), |
| 57 | + ] = None, |
| 58 | + color: Annotated[bool, typer.Option("--color/--no-color")] = True, |
| 59 | + images: Annotated[Optional[list[str]], typer.Option("-i", "--image", help="filter image list")] = None, |
| 60 | + request: Annotated[bool, typer.Option("--request/--no-request", help="show requests")] = True, |
| 61 | + response: Annotated[bool, typer.Option("--response/--no-response", help="show responses")] = True, |
| 62 | + unique: Annotated[ |
| 63 | + bool, |
| 64 | + typer.Option("-u", "--unique", help="show only unique requests per image/pid/method/uri combination"), |
| 65 | + ] = False, |
| 66 | + black_list: Annotated[bool, typer.Option("--black-list/--white-list")] = True, |
| 67 | +): |
52 | 68 | """ |
53 | 69 | Sniff using the secret com.apple.CFNetwork.plist configuration. |
54 | 70 |
|
55 | 71 | This sniff includes the request/response body as well but requires the device to be jailbroken for |
56 | 72 | the sniff to work |
57 | 73 | """ |
58 | 74 | filters = Filters(pids, process_names, images, black_list) |
59 | | - SnifferPreference(service_provider, filters=filters, request=request, response=response, out=out, color=color, |
60 | | - unique=unique).sniff() |
61 | | - |
62 | | - |
63 | | -@cli.command('profile') |
64 | | -@click.option('pids', '-p', '--pid', type=click.INT, multiple=True, help='filter pid list') |
65 | | -@click.option('--color/--no-color', default=True) |
66 | | -@click.option('process_names', '-pn', '--process-name', multiple=True, help='filter process name list') |
67 | | -@click.option('images', '-i', '--image', multiple=True, help='filter image list') |
68 | | -@click.option('--request/--no-request', is_flag=True, default=True, help='show requests') |
69 | | -@click.option('--response/--no-response', is_flag=True, default=True, help='show responses') |
70 | | -@click.option('-u', '--unique', is_flag=True, help='show only unique requests per image/pid/method/uri combination') |
71 | | -@click.option('--black-list/--white-list', default=True, is_flag=True) |
72 | | -def host_profile(pids, process_names, color, request, response, images, unique, black_list): |
| 75 | + SnifferPreference( |
| 76 | + service_provider, filters=filters, request=request, response=response, out=out, color=color, unique=unique |
| 77 | + ).sniff() |
| 78 | + |
| 79 | + |
| 80 | +@cli.command("profile") |
| 81 | +def host_profile( |
| 82 | + pids: Annotated[Optional[list[int]], typer.Option("-p", "--pid", help="filter pid list")] = None, |
| 83 | + process_names: Annotated[ |
| 84 | + Optional[list[str]], |
| 85 | + typer.Option("-pn", "--process-name", help="filter process name list"), |
| 86 | + ] = None, |
| 87 | + color: Annotated[bool, typer.Option("--color/--no-color")] = True, |
| 88 | + request: Annotated[bool, typer.Option("--request/--no-request", help="show requests")] = True, |
| 89 | + response: Annotated[bool, typer.Option("--response/--no-response", help="show responses")] = True, |
| 90 | + images: Annotated[Optional[list[str]], typer.Option("-i", "--image", help="filter image list")] = None, |
| 91 | + unique: Annotated[ |
| 92 | + bool, |
| 93 | + typer.Option("-u", "--unique", help="show only unique requests per image/pid/method/uri combination"), |
| 94 | + ] = False, |
| 95 | + black_list: Annotated[bool, typer.Option("--black-list/--white-list")] = True, |
| 96 | +): |
73 | 97 | """ |
74 | 98 | Sniff using CFNetworkDiagnostics.mobileconfig profile. |
75 | 99 |
|
76 | 100 | This requires the specific Apple profile to be installed for the sniff to work. |
77 | 101 | """ |
78 | 102 | filters = Filters(pids, process_names, images, black_list) |
79 | | - HostSnifferProfile(filters=filters, request=request, response=response, color=color, |
80 | | - unique=unique).sniff() |
| 103 | + HostSnifferProfile(filters=filters, request=request, response=response, color=color, unique=unique).sniff() |
81 | 104 |
|
82 | 105 |
|
83 | | -if __name__ == '__main__': |
| 106 | +if __name__ == "__main__": |
84 | 107 | cli() |
0 commit comments