From b9457081b0d8586bc7cd22115546b3c8d5f665b3 Mon Sep 17 00:00:00 2001 From: "Tomer Zait (realgam3)" Date: Mon, 31 Jul 2023 13:27:25 +0300 Subject: [PATCH] fix readme --- CTFDump.py | 20 ++++++-------------- README.md | 20 +++++++++++--------- requirements.txt | 2 +- 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/CTFDump.py b/CTFDump.py index 8ea8bda..e55ff8f 100644 --- a/CTFDump.py +++ b/CTFDump.py @@ -6,13 +6,14 @@ import logging from os import path from getpass import getpass +from requests import Session from bs4 import BeautifulSoup from requests.utils import CaseInsensitiveDict -from requests.sessions import urljoin, urlparse, Session +from urllib.parse import urlparse, urljoin from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter from urllib.parse import unquote -__version__ = "0.2.1" +__version__ = "0.3.0" class BadUserNameOrPasswordException(Exception): @@ -97,7 +98,7 @@ def login(self, username, password): raise NotImplementedError() def logout(self): - raise NotImplementedError() + self.session.get(urljoin(self.url, "/logout")) class CTFd(CTF): @@ -147,9 +148,6 @@ def login(self, username, password): return True return False - def logout(self): - self.session.get(urljoin(self.url, "/logout")) - def __get_file_url(self, file_name): if not file_name.startswith('/files/'): file_name = f"/files/{file_name}" @@ -190,16 +188,14 @@ def iter_challenges(self): class rCTF(CTF): def __init__(self, url): - self.url = url - self.session = Session() - self.logger = logging.getLogger(__name__) + super().__init__(url) self.BarerToken = '' @staticmethod def __get_file_url(file_info): return file_info['url'] - def login(self, team_token): + def login(self, team_token, **kwargs): team_token = unquote(team_token) headers = { 'Content-type': 'application/json', @@ -219,7 +215,6 @@ def login(self, team_token): return False def __iter_challenges(self): - headers = { 'Content-type': 'application/json', 'Accept': 'application/json', @@ -239,9 +234,6 @@ def iter_challenges(self): files=list(map(self.__get_file_url, challenge.get('files', []))) ) - def logout(self): - self.session.get(urljoin(self.url, "/logout")) - def get_credentials(username=None, password=None): username = username or os.environ.get('CTF_USERNAME', input('User/Email: ')) diff --git a/README.md b/README.md index 4ac979f..9801e76 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ CTFd Dump Tool - When you want to have an offline copy of a CTF. `python CTFDump.py -u username -p password https://demo.ctfd.io/` -> or for rCFT platform +> or for rCTF platform `python CTFDump.py -c rCTF -t [token-team] https://demo.ctfd.io/` @@ -15,17 +15,19 @@ CTFd Dump Tool - When you want to have an offline copy of a CTF. See `--help` for the complete list, but in short: -```sh +```text usage: CTFDump.py [-h] [-v] [-c {CTFd,rCTF}] [-n] [-u USERNAME] [-p PASSWORD] [-t TOKEN] url positional arguments: url ctf url (for example: https://demo.ctfd.io/) -optional arguments: - -h, --help show this help message and exit - -v, --version show program's version number and exit - -c {CTFd}, --ctf-platform {CTFd} ctf platform (default: CTFd) - -u USERNAME, --username USERNAME username (default: None) - -p PASSWORD, --password PASSWORD password (default: None) - -t TOKEN, --token TOKEN team token for rCTF (default: None) +options: + -h, --help show this help message and exit + -v, --version show program's version number and exit + -c {CTFd,rCTF}, --ctf-platform {CTFd,rCTF} + ctf platform (default: CTFd) + -n, --no-login login is not needed (default: False) + -u USERNAME, --username USERNAME username (default: None) + -p PASSWORD, --password PASSWORD password (default: None) + -t TOKEN, --token TOKEN team token for rCTF (default: None) ``` diff --git a/requirements.txt b/requirements.txt index 05560ab..c4d44d3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ requests>= 2.24.0 -beautifulsoup4>= 4.9.3 \ No newline at end of file +beautifulsoup4>= 4.9.3