⬆️ ⬇️

PHDays III CTF: An Inside Look (Part 1)

On May 23 and 24, 2013, within the framework of the annual international forum on practical information security, Positive Hack Days III, one of the largest competitions on the principle of Capture the Flag - PHDays III CTF was held. This year, a lot of energy was spent on organizing the competition, and the result did not leave anyone indifferent. After this event, we decided to talk about how the preparation for the competition was going and present the view from behind the scenes.



CTF is an information security competition in a format similar to a team game. Each team is provided with its own network infrastructure with pre-installed vulnerable services. Teams must study the services, look for vulnerabilities in them and, using them, attack the services of their rivals. At the same time, they need to maintain their own services in working condition and correct errors in them in order to protect themselves from the attacks of rivals.



When making a successful attack on an enemy service, the team receives some secret data, called the "flag". The flag is evidence of a successful attack. Also, in addition to services, teams are given a set of pre-prepared tasks that can bring additional flags.

')

Begin preparation



Having a great experience of participation and organization of CTF-competitions, we understood that the main thing for the competition is tasks. However, without a good “wrapper” - legends, the game world, fascinating rules and visual components that ensure the immersion of both players and spectators — the competition would be little more interesting than the Olympiad in mathematics.



First of all, it was decided to work out the legend and the rules, and then use them as a starting point for creating the tasks themselves. In an attempt to link together the freshly baked game components, we decided to learn more about the process of creating games.



After developing the concept of a legend, came through game mechanics. First of all, we decided on the format of the competition: it was supposed to be a mixed CTF with regular Jeopardy CTF, services (classic CTF) and innovation - tasks with a limited time to solve and constantly increasing price of points, which we called “boss tasks” . This format, it seems to us, makes it possible to widely evaluate the skills of the participants and brings dynamism to the game.



Next, it was necessary to understand what players can do with tasks and what they get for it. Terms such as the essence of the game, the activity and the involvement of players have surfaced. By drawing entities on the board and defining actions on them, we were finally able to fix the rules. It remains only to determine the balance of the game - the distribution of points for tasks and internal game resources of players.



We started with setting priorities in solving various types of tasks - services and tasks. We needed to decide who is the winner for us - the team that decided all tasks, or the team that completely analyzed all the services, wrote exploits to them and fixed the vulnerabilities in their services. We also needed to compare among themselves any partial solutions of tasks or services. Ranking allowed to create a balanced system of assessments of tasks, which in turn gave the teams the freedom to choose tactics when solving the entire CTF.



An important point in the development of CTF was the fact that the Positive Hack Days forum, within which the competition was to take place, is not limited to the battle of hackers, which means we have a large audience of people who may be interested in what is happening on the game, not to mention the fans teams.



In order not to leave anyone aside, there was a need for a system that visually reflected the course of the game, and also so that there was an immersion in the world we had invented. In fact, this system should visualize game events in the viewer in almost real time. And since we are talking about the game, the system should look like a game: colorful pictures of the world, stylish heroes, beautiful special effects and uneven (as far as possible) events. One muse visited us all: we want the game to look like Heroes of Might and Magic, affecting more than one generation. And it would be perfect if we could run it on various mobile platforms! ..



Special thanks to Maxim Korobtsev ( gametrek.ru ) for his great help in developing a unique game design and CTF rules.



Rules and game mechanics



In addition to the legend, in the first weeks of brainstorming, original game mechanics and rules of the game appeared, adding to the process of solving tasks a bit of strategy. We tried to develop the mechanics in such a way that the players always had a choice of several strategies for playing the game, each of which could lead them to victory.

The game set includes:





Purpose of the game: to collect as much gold as possible. The most “well-off” team wins.





Schematic display of game mechanics (option 1)



Essence of the game:



  1. Round - a five-minute interval of game time. At the end of each round there is a miscalculation of the events of the game, as well as updating the flags in the services.
  2. A flag is some secret information that can be found in services, tasks or bosses.
  3. Gold is an element of the secondary subgroup of the first group of the sixth period of the periodic table of chemical elements of DI Mendeleev with atomic number 79. Also, the type of game points that determines the position of the team in the ranking.
  4. A resource is a type of game points obtained from performing actions on team services. Each service brings its own kind of resources.


Types of resources (in order of increasing cost):





Resource Actions:





1. Service - a vulnerable application with a flag that is updated once per round and that belongs to one of the teams.

Actions on command services:





The number of points that teams receive for services is calculated using the following formulas:





2. Generic service is a vulnerable application, with a flag that is updated once per round and does not belong to any team.



Actions on shared services:





3. Task - this is a previously prepared task with one flag, which requires certain skills to solve it.



Actions on task:





4. A boss is a previously prepared task with one flag, with a limited lifetime (3 hours), variable remuneration and requiring certain skills to solve it.



Each round from all teams collects some amount of gold (tax), which is put in the piggy bank boss.



Actions on bosses:





5. Skill (skill) - the type of game points that show:





Skill Types:





Skill actions:





6. Achivka (reward) - reward, outstanding team for the fulfillment of certain requirements. In total, the game can get 42 types of awards.





Schematic display of game mechanics (option 2)



Network infrastructure



When the rules of the game were ready and everyone already had an idea about how the competition would take place and what was needed for it from a technical point of view, the design of the network infrastructure began.



Design



According to all the canons of the genre, the design began with the assignment of requirements based on rules, game mechanics and common sense, and only after that it was possible to proceed directly to the design of the network.



Each team must have its own subnet, and requests from one subnet to another must be hidden behind NAT, so that players cannot distinguish the attacks of opponents from requests of the jury system based on the IP address.



In addition to command subnets, there should be a separate segment for hosting interactive tasks and common services. Moreover, it is necessary that the service could obtain information about the subnet from which the request was sent in order to identify the command.



By default, players' access to all tasks should be limited, but immediately after the team purchases a certain task, the entire subnet should have access to it.



The gaming infrastructure must also include a segment belonging to the jury. It houses the Juray system, a web server with a user interface, the server part of the visualizer, as well as computers from which the entire gameplay is configured and monitored. From this subnet should be open access to all tasks, services and commands. And, of course, for all subnets should be free access to the Internet.



Implementation



The Cisco Catalyst 3750X 24 switch, located in the server room, was selected as the network core. The Cisco ASA 5510 firewall was connected to it, which also served as the default gateway for all segments of the CTF network (teams, tasks, services, jury). He distributed IP addresses (DHCP) for all computers on the network, provided IP address translation (NAT), restricted access to tasks, and also provided access to the Internet.



A Cisco Catalyst 3750G 24 switch was connected to the core of the network. D-Link DES-1008E switches of ten teams and a jury were connected to each network, each of which belonged to its own segment (VLAN).



Also, two powerful servers were connected to the main router for interactive tasks, common services and a jury system:



1. 2 processors, 4 cores, 64Gb RAM, 1Tb HDD.

It was raised by VMware ESXi with two virtual machines. The first was the server version of Ubuntu 13.04 with a set of Jury services:





The second was the service of the visualizer running Windows 7.



2. 2 processors, 6 cores, 128Gb RAM, 1Tb HDD.

It also ran VMware ESXi, which had 36 virtual machines running:







Gaming network layout



General project architecture



As soon as the legend and rules were ready, it was necessary to begin designing the overall system architecture. Next will be described the device site as a whole, as well as each individual component.





Schematic representation of the overall project architecture



The main element is the Jury System - a system that processes all game logic. Its tasks include the handling of game events and the scoring of teams. All other parts are external interfaces rather than independent subsystems.



Flag Acceptor Interface - the flag receiving interface. It is a subsystem of the Jury System; presented in this diagram to display the ability of teams to hand over flags stolen from both common services and from services of opponents.



MongoDB is a game state database. It stores and updates all the current state of the game: points scored by teams, task status (open or closed for each of the teams), complete descriptions of the tasks and bosses themselves, duration of the game, etc.



User Interface (UI) is a user interface of commands implemented as a web application. According to the rules of the game, teams can open tasks, buy / sell resources, solve tasks, receive information about the current rating, etc. The UI is responsible for this functionality. As the initial data for display data from MongoDB are taken. Processing requests from users is implemented through RPC, built in turn on AMQP.



Visualizer is a gameplay visualization system that accumulates and displays game events. Since not all information can be transmitted via events, the system takes some data from the system state to MongoDB.



Network Access Interface - interface to control access to tasks. At the beginning of the game, all tasks are not available to teams. As soon as the team opens any task, it opens access to it using this interface.



Jurey system



As described above, the Jury System (the jury system) is responsible for rendering the game logic. When designing it, we tried to achieve the following goals:



  1. Correct implementation of the rules of the game . You can not give any of the participants any cheater. The most important thing for us was the observance of the rules of the game.
  2. Stability of work. During the game, participants should not have difficulty working with the jury system. Sudden drops can lead to an imbalance of the whole game: the chances will not be equal and the competition will not be objective. For this reason, to achieve stable performance, we spent a lot of effort on testing.



    For safety net, we created a special system for restoring the state of the game after the fall of the jury system.
  3. Work speed From the experience of CTF games, we knew that the delay in responses from the system could be fatal for the team, especially if the task was decided at the last minute. The faster the system processes the request from the user, the faster the team can proceed to the next task.
  4. Security. Along with the correct observance of the rules, an important aspect was also the security of the entire system. The game was attended not by simple programmers, but by real hackers. It was impossible to prevent the illegal accrual of points or unauthorized access :)


Objectives are marked, now you can paint the tasks of the Jury system:

1. Processing rounds





2. Processing user requests





3. Reception of flags from services from teams





4. Processing bosses logic





5. Rewarding the team with achivki







Architecture of the jurei system



Interfaces for working with external components:





Essence of the game:





The processing of logic over game entities is assumed by “game managers”. I would like to mention some of their implementation features.





To check the serviceability of services, CTF organizers pre-write special programs, checkers. Services are usually completely abstract and vary from competition to competition, so in order to have a universal interface for working with checkers. Checkers are launched in separate processes with the following command line parameters: {GET or PUT} command, which determines what action to take - put a flag on the service or check its availability, the IP address of the server on which the service with the flag is checked, the flag itself. Upon completion, the checker must return the completion status:





Since for one round you need to perform 2 actions for checkers - GET and PUT, they run for all teams 2 times per round: PUT - in the first quarter of a round with a random delay inside the quarter, GET - in the third quarter of a round with a random delay inside the quarter. At the time of launching the checkers for the execution of the PUT command, completion of all checkers that had not had time to work by that time was also completed. The status of the service in this case will display the error of the checker.



Architectural checkers are launched immediately on all services and on all commands, so checking services is the most resource-intensive task of the entire system. Therefore, special attention should be paid to writing checkers - they should work out as quickly as possible and use as few resources as possible. In general, from the point of view of programming, everything is as always :)



The remaining components are not of particular interest. The only thing I would like to note is the game recovery system after the fall. To implement this functionality, many game variables had to be saved to an external base. Since most of the data was already saved in MongoDB, it was decided to add the functionality to save the remaining ones and restore them from the database.



Finally, it is worth noting a few words about the implementation of the Juryan system. The entire system was written in C ++, as it was the most popular language among the system development team. In addition, the author is piously convinced that the same code written in Python will work more slowly. Qt was chosen as the development framework as the most convenient for the developers selected for the project.



Continuation



Authors: slim_d0g blackzert muodov ki11obyte Asperka



PS The PHDays website contains an interesting article analyzing gameplay.

Source: https://habr.com/ru/post/186310/



All Articles