From ca6a96ac0793b3aa199fff9676081110f5773671 Mon Sep 17 00:00:00 2001 From: "Mariusz B. / mgeeky" Date: Fri, 26 Mar 2021 20:47:56 +0100 Subject: [PATCH] Fixed some issues. --- red-teaming/C3-Client/c3-client.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/red-teaming/C3-Client/c3-client.py b/red-teaming/C3-Client/c3-client.py index 55fa718..9f84e31 100644 --- a/red-teaming/C3-Client/c3-client.py +++ b/red-teaming/C3-Client/c3-client.py @@ -36,6 +36,8 @@ commands = { ] } +serverValidated = False + # BackendCommons.h: enum class Command : std::uint16_t commandsMap = { 'AddDevice' : 0, @@ -92,6 +94,8 @@ def printJson(data): print(json.dumps(data, sort_keys=True, indent=4)) def getRequest(url, rawResp = False, stream = False): + global serverValidated + auth = None if config['httpauth']: user, _pass = config['httpauth'].split(':') @@ -103,11 +107,24 @@ def getRequest(url, rawResp = False, stream = False): try: resp = requests.get(fullurl, headers=headers, auth=auth, stream = stream, timeout = 5) + + if not serverValidated: + try: + gateways = requests.get(config["host"] + '/api/gateway', headers=headers, auth=auth, stream = stream, timeout = 5) + if gateways.status_code < 200 or gateways.status_code > 300: + raise Exception() + + serverValidated = True + except: + Logger.fatal('Server could not be validated. Are you sure your Host value points to a valid C3 webcontroller URL?') + except requests.exceptions.ConnectTimeout as e: Logger.fatal(f'Connection with {config["host"]} timed-out.') except Exception as e: Logger.fatal(f'GET request failed ({url}): {e}') + Logger.dbg(f'First 512 bytes of response:\n{resp.text[:512]}') + if rawResp: return resp