def retrieve_flags(self, team, round):
        from gameserver import cheapMethodFromRoundNumber, cheapMethods, GameServer, GameServerCrypto, methods

        method = cheapMethodFromRoundNumber(round)
        flagIndex = cheapMethods.index(method)
        flagId = self.get_flag_id(team, round, 0)
        flag = self.get_flag(team, round, flagIndex)
        msg = self.load(team, round, f"msg_{flagIndex}")
        paramHash = self.load(team, round, f"paramhash_{flagIndex}")
        if paramHash is None or msg is None:
            # We didn't event try to store this flag
            raise FlagMissingException(
                f"Missing flag for team {team.id} in round {round}.")

        wasReencrypted, _ = GameServer.checkFlag(team.ip, PORT, flagId, msg)
        self.store(team, round, f"fixed_{flagIndex}", wasReencrypted)

        flagIndex = methods.index("schwenk")
        flagId = self.get_flag_id(team, round, 1)
        msg = self.load(team, round, "schwenk_msg")
        paramHash = self.load(team, round, f"paramhash_{flagIndex}")
        if paramHash is None or msg is None:
            raise FlagMissingException(
                f"Missing flag for team {team.id} in round {round}.")

        _, storedParams = GameServer.checkFlag(team.ip, PORT, flagId, msg)
        storedParamHash = GameServerCrypto.parameterHash(storedParams)
        self.store(team, round, f"fixed_{flagIndex}",
                   storedParamHash != paramHash)

        return 2
    def store_flags(self, team, round):
        from gameserver import cheapMethodFromRoundNumber, cheapMethods, GameServer, GameServerCrypto, SHA512_HEX_LEN, \
            methods

        flagsStored = 0
        method = cheapMethodFromRoundNumber(round)
        flagIndex = cheapMethods.index(method)
        flagId = self.get_flag_id(team, round, 0)
        flag = self.get_flag(team, round, flagIndex)
        msg = GameServer.generatePlaintext() % flag

        # Check if the flag is already stored
        # We could in theory just try to store the flag and check for an IntegrityException from sqlite.
        # However, this approach might not work if teams tinker with their DB layout.
        flagAlreadyStored = True
        try:
            GameServer.retrieveCipher(team.ip, PORT, flagId)
        except FlagMissingException:
            flagAlreadyStored = False

        if not flagAlreadyStored:
            cipher, params, msg = GameServerCrypto.encrypt(msg, method)
            paramHash = msg[-SHA512_HEX_LEN:]
            self.store(team, round, f"paramhash_{flagIndex}", paramHash)
            self.store(team, round, f"msg_{flagIndex}", msg)
            GameServer.storeCipher(team.ip, PORT, flagId, cipher, params)
            flagsStored += 1

        flagIndex = methods.index("schwenk")
        flagId = self.get_flag_id(team, round, 1)
        flag = self.get_flag(team, round, flagIndex)
        msg = GameServer.generatePlaintext() % flag

        flagAlreadyStored = True
        try:
            GameServer.retrieveCipher(team.ip, PORT, flagId)
        except FlagMissingException:
            flagAlreadyStored = False

        if not flagAlreadyStored:
            cipher, params, msg = GameServerCrypto.schwenkNew(
                msg, skipKeyAndIV=False)
            paramHash = GameServerCrypto.parameterHash(params)
            self.store(team, round, f"paramhash_{flagIndex}", paramHash)
            self.store(team, round, "schwenk_msg",
                       msg)  # Random key + IV are added.
            GameServer.storeCipher(team.ip, PORT, flagId, cipher, params)
            flagsStored += 1

        return flagsStored
Example #3
0
    def handle_server(self, result, address: Tuple[str, int]):
        logging.debug(f"{self.__class__.__name__ } - Header belongs to server")
        server = GameServer(address, result)
        if self.storage.get_server(server):
            self.storage.update_server(server)
        else:
            self.storage.create_server(server)

        if not server.active:
            self.storage.server_shutdown(server)

        return result.get('resp', None)
Example #4
0
def server_status():
    address = ("127.0.0.1", 27910)
    result = {
        "active": True,
        "encoding": "latin1",
        "split_on": "\\",
        "status": [
            b"\\cheats\\0\\deathmatch\\1\\dmflags\\16\\fraglimit\\0",
            b"10 15 Player One\n",
        ],
    }
    return GameServer(address, result)
def server_status():
    address = ('127.0.0.1', 27910)
    result = {
        'active':
        True,
        'encoding':
        'latin1',
        'split_on':
        '\\',
        'status': [
            b'\\cheats\\0\\deathmatch\\1\\dmflags\\16\\fraglimit\\0',
            b'10 15 Player One\n'
        ]
    }
    return GameServer(address, result)
Example #6
0
def game(id):
    game = GS.get(id, GameServer())

    if (request.method == 'POST') and (request.is_json):
        data = request.get_json()
        item = int(data.get('item'))
        x = int(data.get('x'))
        y = int(data.get('y'))
        success = game.move(item, x, y)
        result = game.to_json()
        result['success'] = success

        return jsonify(result)

    return jsonify(game.to_json())
Example #7
0
                        # print(e)
                        continue
                    # No try here: At this point, we are very sure that we have decrypted correctly so far. Backtracking here would also be rather messy.
                    c_plain = c_elem.nthRoot(
                        k_b_out.toNumber() ^ xorParams[blockIndex]).toString()
                    if not isValidPlaintext(c_plain):
                        continue
                    plain = c_plain + plain
                    print("Found plaintext fragment:", c_plain)
                    bFound = True
                    break

                if not bFound:
                    raise Exception("Decryption failed.")
                remainingCipher = remainingCipher[:-bExpected - bOffset]
                k_next_out = k_b_out
                IV_next_out = IV_b_out

            return plain.decode("utf-8")


if __name__ == "__main__":
    assert len(sys.argv) >= 4, "Needs flag ids in fourth argument"
    target = sys.argv[1]
    flagIds = sys.argv[3].split(",")

    for flagId in flagIds:
        cipher, params = GameServer.retrieveCipher(target, PORT, flagId)
        if params["method"] == "schwenk":
            plain = exploit(cipher, params)
            print(plain)
        for json_row in directory_data["server_options"]:
            server_options.append(ServerOption(json_row["server_name"], json_row["server_description"],
                                               json_row["server_address"], json_row["server_port"],
                                               json_row["server_utilization"], json_row["server_capacity"],
                                               json_row["server_enabled"]))
    return server_options


if __name__ == "__main__":
    world_session = []
    world_room = []
    world_user = User.get_users()
    broker_options = []
    bind_address = "0.0.0.0"

    # broker_options = load_broker_directory_from_file()

    broker_options.append(ServerOption("Python Emulator", "Avatar ON", "192.168.1.12", 8370, 0, 20, True))

    enabled_server_functions = [FunctionRestrict.EFFECT_THOR, FunctionRestrict.EFFECT_FORCE,
                                FunctionRestrict.EFFECT_MOON, FunctionRestrict.EFFECT_LIGHTNING,
                                FunctionRestrict.AVATAR_ENABLED]

    broker_server = BrokerServer(bind_address, 8372, broker_options, world_session)
    game_server: GameServer = GameServer(bind_address, 8370, world_session, world_room, world_user)

    game_server.gs_funcrestrict = FunctionRestrict.get_function_value(enabled_server_functions)

    threading.Thread(target=broker_server.listen).start()
    threading.Thread(target=game_server.listen).start()
Example #9
0
	def actionStartGS(self):
		from gameserver import GameServer
		gs = GameServer()
		gs.run()
Example #10
0
from gameserver import GameServer
from db import DbConnection


if __name__ == "__main__":
    DbConnection()
    GameServer().run()
Example #11
0
from gameserver import GameServer

gs = GameServer(12345)
gs.start()
Example #12
0
libPath = os.path.join(path2here, 'libs')

sys.path.append(path2here)
sys.path.append(libPath)
os.chdir(path2here)

import config
from gameserver import GameServer
print(config.GAME_COMMAND)


def simpleHandler(msg):
    msg = msg.decode('utf-8')
    print(msg)
    print('simpleHandled')
    return


if __name__ == '__main__':
    game_server = GameServer()
    game_server.setHandler(simpleHandler)
    game_server.start()

    for i in range(5):
        time.sleep(1)
        game_server.send('hahaha')

    game_server.send('/stop')

    game_server.game.wait()
Example #13
0
 def __init__(self):
     pygame.display.set_caption(GAME_NAME)
     self.canvas = pygame.display.set_mode((GAME_WIDTH,GAME_HEIGHT))
     self.clock = pygame.time.Clock()
     self.server = GameServer()
     self.active_scene = start_scene