forked from realgam3/CTFDump
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCTFDump.py
88 lines (73 loc) · 2.48 KB
/
CTFDump.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import logging
import os
import sys
from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser
from core import __version__
from ctfs import CTFs
def main(args=None):
if args is None:
args = sys.argv[1:]
# Initial parsing to get the platform
platform = ",".join(CTFs.keys())
initial_parser = ArgumentParser(
usage=f"%(prog)s {platform} <url> [-h] [-v] [-n] [-F] [-S LIMITSIZE]",
formatter_class=ArgumentDefaultsHelpFormatter,
add_help=False,
)
initial_parser.add_argument("ctfs", choices=CTFs.keys(), help="ctf platform")
initial_args, _ = initial_parser.parse_known_args(args)
# Add platform-specific arguments
if CTFs.get(initial_args.ctfs) == None:
print("Invalid platform")
initial_parser.print_help()
exit(1)
ctfs = CTFs.get(initial_args.ctfs)
parser = ArgumentParser(
usage=f"%(prog)s {{{initial_args.ctfs}}} <url> [-h] [-v] [-n] [-F] [-S LIMITSIZE] ",
formatter_class=ArgumentDefaultsHelpFormatter,
)
ctfs.apply_argparser(parser)
# Add global arguments
parser.add_argument("ctfs")
parser.add_argument("url", help="ctf url (for example: https://demo.ctfd.io/)")
parser.add_argument(
"-v",
"--version",
action="version",
version="%(prog)s {ver}".format(ver=__version__),
)
parser.add_argument(
"-n", "--no-login", action="store_true", help="login is not needed"
)
parser.add_argument(
"-F", "--force", help="ignore the config file", action="store_true"
)
parser.add_argument(
"-S",
"--limitsize",
type=int,
help="limit size of download file in Mb",
default=100,
)
sys_args = vars(parser.parse_args(args))
# Configure Logger
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s %(levelname)s %(message)s",
datefmt="%d-%m-%y %H:%M:%S",
)
ctf = ctfs(sys_args["url"], sys_args["limitsize"], sys_args["force"])
ctf.login(
sys_args,
no_login=(sys_args["no_login"] or os.environ.get("CTF_NO_LOGIN")),
)
# check available config
if ctf.load_config():
logging.info("Config file found, updating challenges")
ctf.update()
else:
ctf.save()
if not sys_args["no_login"] or not os.environ.get("CTF_NO_LOGIN"):
ctf.logout()
if __name__ == "__main__":
main()