Esempio n. 1
0
    def place_flag(self, tick):
        if self.team != 92:
            raise Exception('Team {} != 92'.format(self.team))
        if self.ip != '0.0.92.1':
            raise Exception('IP {} != 0.0.92.1'.format(self.ip))
        if tick != 0:
            raise Exception('Tick {} != 0'.format(tick))

        checkerlib.get_flag(tick)
        return checkerlib.CheckResult.OK
Esempio n. 2
0
    def place_flag(self, tick):
        checkerlib.get_flag(tick)

        # Try to send a signal to our parent, this should not be possible when running as another user
        parent_pid = os.getppid()
        try:
            os.kill(parent_pid, 0)
        except PermissionError:
            return checkerlib.CheckResult.OK

        raise Exception('Should not be able to kill the parent')
Esempio n. 3
0
    def check_flag(self, tick):
        checkerlib.get_flag(tick)

        if self.team == 92 and self._tick == 2:
            if tick == 0:
                return checkerlib.CheckResult.FLAG_NOT_FOUND
            else:
                return checkerlib.CheckResult.OK
        elif self.team == 93 and self._tick == 1:
            return checkerlib.CheckResult.FAULTY
        else:
            return checkerlib.CheckResult.OK
Esempio n. 4
0
    def place_flag(self, tick):
        self._tick = tick  # pylint: disable=attribute-defined-outside-init

        if self.team != 92 and self.team != 93:
            raise Exception('Invalid team {}'.format(self.team))

        checkerlib.get_flag(tick)

        if self.team == 92 and tick == 0:
            return checkerlib.CheckResult.FAULTY
        else:
            return checkerlib.CheckResult.OK
Esempio n. 5
0
    def test_get_flag(self):
        checkerlib.get_flag._team = 1    # pylint: disable=protected-access
        team1_tick1_flag1 = checkerlib.get_flag(1, b'fooobaar')
        team1_tick2_flag1 = checkerlib.get_flag(2, b'fooobaar')
        team1_tick1_flag2 = checkerlib.get_flag(1, b'fooobaar')
        team1_tick2_flag2 = checkerlib.get_flag(2)
        checkerlib.get_flag._team = 2    # pylint: disable=protected-access
        team2_tick1_flag1 = checkerlib.get_flag(1, b'fooobaar')

        self.assertEqual(team1_tick1_flag1, team1_tick1_flag2)
        self.assertNotEqual(team1_tick1_flag1, team1_tick2_flag1)
        self.assertNotEqual(team1_tick2_flag1, team1_tick2_flag2)
        self.assertNotEqual(team1_tick1_flag1, team2_tick1_flag1)
    def place_flag(self, tick):
        if checkerlib.load_state('key2') is not None:
            raise Exception('Got state where there should be none')

        if tick == 0:
            if checkerlib.load_state('key1') is not None:
                raise Exception('Got state where there should be none')

        checkerlib.get_flag(tick)

        if self.team == 92:
            if tick == 0:
                checkerlib.store_state('key1',
                                       'Wir können Zustände speichern 🥳')
            else:
                if checkerlib.load_state(
                        'key1') != 'Wir können Zustände speichern 🥳':
                    raise Exception('Did not get stored state back')

            if tick == 0:
                checkerlib.store_state('🔑ser', 'Söze')
                if checkerlib.load_state('🔑ser') != 'Söze':
                    raise Exception('Did not get stored state back')
            elif tick == 1:
                if checkerlib.load_state('🔑ser') != 'Söze':
                    raise Exception('Did not get stored state back')
                checkerlib.store_state('🔑ser',
                                       ['Roger', '"Verbal"', 'Kint'])
            elif tick == 2:
                if checkerlib.load_state('🔑ser') != [
                        'Roger', '"Verbal"', 'Kint'
                ]:
                    raise Exception('Did not get stored state back')
        elif self.team == 93:
            if tick == 1:
                if checkerlib.load_state('key1') is not None:
                    raise Exception('Got state where there should be none')
                data = [{'number': 42}, {'number': 1337}]
                checkerlib.store_state('key1', data)
                checkerlib.set_flagid('value identifier')
            elif tick >= 2:
                if checkerlib.load_state('key1') != [{
                        'number': 42
                }, {
                        'number': 1337
                }]:
                    raise Exception('Did not get stored state back')

        return checkerlib.CheckResult.OK
Esempio n. 7
0
    def place_flag(self, tick: int) -> checkerlib.CheckResult:
        """Places a flag at the target team."""
        start_time = time.time()
        interaction = Interaction(self.ip)

        flag = checkerlib.get_flag(tick)
        key = self._get_key_for_flag(flag)

        train = Train(key)
        train.add_wagon(
            Wagon(content=flag, symbol=chr(random.randrange(48, 123))))
        if not interaction.create_train(train):
            return checkerlib.CheckResult.DOWN

        pwn.log.info(
            f"Overall duration for place_flag: {int(time.time() - start_time)}s"
        )
        return checkerlib.CheckResult.OK
Esempio n. 8
0
    def place_flag(self, tick):
        conn = connect(self.ip)
        flag = checkerlib.get_flag(tick)
        conn.sendall('SET {} {}\n'.format(tick, flag).encode('utf-8'))
        logging.info('Sent SET command: Flag %s', flag)

        try:
            resp = recv_line(conn)
            logging.info('Received response to SET command: %s', repr(resp))
        except UnicodeDecodeError:
            logging.warning('Received non-UTF-8 data: %s', repr(resp))
            return checkerlib.CheckResult.FAULTY
        if resp != 'OK':
            logging.warning('Received wrong response to SET command')
            return checkerlib.CheckResult.FAULTY

        conn.close()
        return checkerlib.CheckResult.OK
Esempio n. 9
0
    def check_flag(self, tick):
        flag = checkerlib.get_flag(tick)

        conn = connect(self.ip)
        conn.sendall('GET {}\n'.format(tick).encode('utf-8'))
        logging.info('Sent GET command')

        try:
            resp = recv_line(conn)
            logging.info('Received response to GET command: %s', repr(resp))
        except UnicodeDecodeError:
            logging.warning('Received non-UTF-8 data: %s', repr(resp))
            return checkerlib.CheckResult.FAULTY
        if resp != flag:
            logging.warning('Received wrong response to GET command')
            return checkerlib.CheckResult.FLAG_NOT_FOUND

        conn.close()
        return checkerlib.CheckResult.OK
Esempio n. 10
0
    def check_flag(self, tick: int) -> checkerlib.CheckResult:
        """Tries to retrieve a flag."""
        start_time = time.time()
        interaction = Interaction(self.ip)

        flag = checkerlib.get_flag(tick)
        key = self._get_key_for_flag(flag)

        train = interaction.get_train(key)

        pwn.log.info(
            f"Overall duration for check_flag: {int(time.time() - start_time)}s"
        )
        if not train:
            return checkerlib.CheckResult.FLAG_NOT_FOUND
        if len(train.wagons) != 1:
            return checkerlib.CheckResult.FLAG_NOT_FOUND
        if train.wagons[0].content != flag:
            return checkerlib.CheckResult.FLAG_NOT_FOUND
        return checkerlib.CheckResult.OK
#!/usr/bin/env python3

import os
import time

from ctf_gameserver import checkerlib

if __name__ == '__main__':

    pidfile_path = os.environ['CHECKERSCRIPT_PIDFILE']  # pylint: disable=invalid-name
    with open(pidfile_path, 'w') as pidfile:
        pidfile.write(str(os.getpid()))

    checkerlib.get_flag(1)

    while True:
        time.sleep(10)
Esempio n. 12
0
    def check_flag(self, tick):
        if tick != 0:
            raise Exception('Tick {} != 0'.format(tick))

        checkerlib.get_flag(tick)
        return checkerlib.CheckResult.OK
Esempio n. 13
0
 def check_flag(self, tick):
     checkerlib.get_flag(tick)
     return checkerlib.CheckResult.OK
 def place_flag(self, tick):
     checkerlib.get_flag(tick)
     raise OSError(errno.ETIMEDOUT, 'A timeout occurred')