Exemple #1
0
    def doActualFuzz(self):
        """
        The main fuzzing loop.

        all magic is performed here
        sends results via queue to the parent
        Only called once, by the fuzzingmaster
        """
        if "DebugWithFile" in self.config:
            utils.setupSlaveLoggingWithFile(self.threadId)

        random.seed(self.initialSeed)
        logging.info("Setup fuzzing...")
        signal.signal(signal.SIGINT, signal_handler)

        targetPort = self.config["target_port"] + self.threadId
        clientManager = ClientManager(self.config, self.threadId, targetPort)
        networkServerManager = ClientFuzzerServer(self.config, targetPort)

        # start the server
        if not networkServerManager.start():
            return

        iterStats = {
            "count": 0,  # number of iterations
            "crashCount": 0,  # number of crashes, absolute
            "startTime": time.time(),
            "lastUpdateTime": time.time(),
        }
        sendDataResult = None

        print(str(self.threadId) + " Start fuzzing...")
        self.queue.put((self.threadId, 0, 0, 0))

        fuzzingIterationData = None
        while True:
            self.updateStats(iterStats)
            logging.debug("\n\n")
            logging.debug("A fuzzing loop...")

            if self.config["debug"]:
                # lets sleep a bit
                time.sleep(0.5)

            selectedInput = self.selectInput()

            fuzzingIterationData = fuzzingiterationdata.FuzzingIterationData(
                self.config, selectedInput)
            if not fuzzingIterationData.fuzzData():
                logging.error("Could not fuzz the data")
                return

            networkServerManager.setFuzzData(fuzzingIterationData)
            clientManager.execute()
            networkServerManager.handleConnection()

        networkServerManager.stop()
Exemple #2
0
class SuperAction(object):

    def __init__(self):
        self.request = None
        self.manager = ClientManager()
        self.response = None

    def process(self, request):

        current_page = request.page

        if request.action == ACTION_LOGIN:
            self.response = self.login_client(request)
        elif request.action == ACTION_LOGOUT:
            self.response = self.logout_client(current_page, request)
        elif request.action == ACTION_ACCOUNTS:
            client_name = request.parameters['name']
            accounts = self.manager.get_accounts(name=client_name)
            self.response = self.response.create_client(data=accounts)
        elif request.action == ACTION_TRANSFER:
            pass
        elif request.action == ACTION_OPEN_ACCOUNT:
            pass
        elif request.action == ACTION_CLOSE_ACCOUNT:
            pass

        return self.response

    def logout_client(self, current_page, request):
        client_name = request.parameters['name']
        if self.manager.logout(client_name):
            response = Response.create_login()
        else:
            response = Response(page=current_page)
        return response

    def login_client(self, request):
        client_name = request.parameters['name']
        client_pass = request.parameters['pass']
        if self.manager.login(client_name, client_pass):
            response = Response.create_client()
        else:
            response = Response.create_login()
        return response
def testClientManager():
    cm = ClientManager.Instance()

    # Test getting the status of multiple lights, and
    # lights that don't exist, and ones on bad clients.
    status = None
    print('SERVER TO CLIENT SYSTEM TESTING (REQUESTING)')
    status = cm.sendStatusRequest(good_addr, '100001')
    print(
        str(status['type'] == 'status') +
        ' (Make sure we got a status on valid.)')
    status = cm.sendStatusRequest(good_addr, 'doesntexist')
    print(
        str(status['type'] == 'error'
            and 'does not exist on client' in status['message']) +
        ' (non-existent light.)')
    status = cm.sendStatusRequest(bad_addr, 'doesntexist')
    print(
        str(status['type'] == 'error'
            and 'Could not connect' in status['message']) +
        ' (non-existent client and light.)')
    status = cm.sendStatusRequest(bad_addr, '100001')
    print(
        str(status['type'] == 'error'
            and 'Could not connect' in status['message']) +
        ' (non-existent client.)')

    # Try every thing that can happen when changing a light.
    print('SERVER TO CLIENT SYSTEM TESTING (EDITING)')
    # Objects to store the before and after states of a change.
    a = None
    b = None

    # The ID is still none, so a change request should error out.
    a = cm.sendChangeRequest(good_addr, base)
    print(
        str(a['type'] == 'error' and 'does not exist' in a['message']) +
        ' (Null ID)')

    # Change all lights to the base light and verify.
    base['id'] = '100001'
    a = cm.sendChangeRequest(good_addr, base)['data']
    if a != None:
        base['name'] = a['name']  # Names are not changed.
    print(str(a == base) + ' (change 100001 to base.)')
    base['id'] = '100004'
    a = cm.sendChangeRequest(good_addr, base)['data']
    if a != None:
        base['name'] = a['name']  # Names are not changed.
    print(str(a == base) + ' (change 100004 to base.)')

    # Go to the first object and try changing it.
    base['id'] = '100001'
    change['id'] = '100001'
    b = cm.sendChangeRequest(good_addr, change)['data']
    if b == None:
        print(str(False) + ' (change 100001 and verify change.)')
    else:
        print(
            str(b['r_t'][0] != base['r_t'][0]) +
            ' (change 100001 and verify change.)')

    # Moving over to the other object.
    base['id'] = '100004'
    change['id'] = '100004'
    b = cm.sendChangeRequest(good_addr, change)['data']
    if b == None:
        print(str(False) + ' (change 100004 and verify change.)')
    else:
        print(
            str(b['r_t'][0] != base['r_t'][0]) +
            ' (change 100004 and verify change.)')

    # Make sure we can make a non-change change.
    a = cm.sendStatusRequest(good_addr, change['id'])
    b = cm.sendChangeRequest(good_addr, change)['data']
    if b == None:
        print(
            str(False) +
            " (change 100004 to itself and verify that it hasn't changed'.)")
    else:
        print(
            str(b['r_t'][0] != base['r_t'][0]) +
            " (change 100004 to itself and verify that it hasn't changed'.)")

    # Check bad IDs and disconnected clients.
    base['id'] = 'nonexistent id'
    a = cm.sendChangeRequest(good_addr, base)['message']
    print(str('does not exist' in a) + ' (non-existent light)')
    a = cm.sendChangeRequest(bad_addr, base)['message']
    print(str('Could not connect' in a) + ' (non-existent client)')

    # Test light validation.
    print('LIGHT VALIDATION UNIT TESTING')
    print(str(cm.validateLight(validLight) == None) + ' (valid light.)')
    print(
        str(
            cm.validateLight(invalidLightA) ==
            'r_t does not contain only numbers.') + ' (Bad timing values.)')
    print(
        str(cm.validateLight(invalidLightC) == 'Incorrect number of keys.') +
        ' (No green channel timings.)')
    print(
        str(cm.validateLight(invalidLightD) == 'g_t is not a list.') +
        ' (g_t is not a list.)')
    print(
        str(
            cm.validateLight(invalidLightE) ==
            'Light does not contain a r_t key.') + ' (No r_t key.)')
    print(
        str(cm.validateLight(invalidLightF) == 'name is not a string.') +
        ' (name is not a string.)')
    print(
        str(cm.validateLight(invalidLightG) == 'id is not a string.') +
        ' (id is an integer list.)')
    print(
        str(cm.validateLight(invalidLightH) == 'id is not a string.') +
        ' (id is an integer.)')
    print(
        str(cm.validateLight(invalidLightI) == 'Incorrect number of keys.') +
        ' (No client key.)')
Exemple #4
0
 def __init__(self):
     self.request = None
     self.manager = ClientManager()
     self.response = None
Exemple #5
0
 def __init__(self):
     self._lm = LightManager.Instance()
     self._am = AliasManager.Instance()
     self._cm = ClientManager.Instance()