Esempio n. 1
0
def ws_handler(event, context):
    try:
        params = getParams(event)
        result = {}
        port = int(params.get('port', 443))
        username = params.get('username', 'admin')
        password = params.get('password', 'admin')
        path = params.get('path', '')

        if test_auth(params['host'], port=port, path=path, user=username, secret=password):
            result[port] = True
            status = 200
        else:
            status = 401
            result[port] = False

        response = {
            "statusCode": status,
            "body": {
                'host': params['host'],
                'username': username,
                'password': password,
                'result': result
            }
        }

        send_to_connection(event['requestContext']['connectionId'], response)
    except Exception as ex:
        send_to_connection(event['requestContext']['connectionId'], {
            "statusCode": 500,
            'error': str(ex)
        })
Esempio n. 2
0
 def decorator_wrapper(event, context):
     params = getParams(event).keys()
     for param in required_params:
         if param in params:
             continue
         print({"message": "{} is required".format(param)})
         return invalid_request(
             {"message": "{} is required".format(param)})
     return validated_function(event, context)
Esempio n. 3
0
 def decorator_wrapper(event, context):
     params = getParams(event).keys()
     for param in params:
         if param not in allowed_params:
             print({
                 "message":
                 "{} is not an allowed parameter".format(param)
             })
             return invalid_request({
                 "message":
                 "{} is not an allowed parameter".format(param)
             })
     return validated_function(event, context)
Esempio n. 4
0
def handler(event, context):
    try:
        params = getParams(event)
        port = int(params.get('port', 22))
        username = params.get('username', 'root')
        password = params.get('password', 'password')

        if test_auth(params['host'], port=port, user=username,
                     secret=password):
            return success(data=None)
        else:
            return unauthorized(data=None)
    except Exception as ex:
        return internal_server_error({"statusCode": 500, 'error': str(ex)})
Esempio n. 5
0
 def decorator_wrapper(event, context):
     params = getParams(event)
     if params[param] not in allowed_values:
         print({
             "message":
             "{} is not an a valid value for parameter {}".format(
                 params[param], param)
         })
         return invalid_request({
             "message":
             "{} is not an a valid value for parameter {}".format(
                 params[param], param)
         })
     return validated_function(event, context)
Esempio n. 6
0
def handler(event, context):
    try:
        params = getParams(event)
        port = int(params['port'])
        timeout = int(params.get('timeout', 5))
        if isOpen(params['host'], port, timeout=timeout):
            result = True
        else:
            result = False

        response = {'host': params['host'], 'port': port, 'open': result}

        return success(response)
    except Exception as ex:
        return internal_server_error({'error': str(ex), 'context': event})
Esempio n. 7
0
def handler(event, context):
    try:
        params = getParams(event)
        port = int(params.get('port', 80))
        username = params.get('username', None)
        password = params.get('password', None)
        path = params.get('path', '/')
        badstring = params.get('badstring', None)

        status = test_path(params['host'], port=port, path=path,
                           user=username, secret=password, badstring=badstring)
        if status != 404:
            return success(data={'path': path, 'status': status})
        else:
            return not_found(data=None)

    except Exception as ex:
        return internal_server_error({
            "statusCode": 500,
            'error': str(ex)
        })