Inspiration

The inspiration of this project comes from a competition I participated in earlier this year, called NCAE Cybergames. It is a beginner-level blue team competition where a team is given a network to configure and secure while performing active defense and intrusion detection against a red team of hackers. Some time during the competition, a red teamer was getting into the FTP server I was on, and I couldn't figure out how. So I wrote to his terminal using the "write" command, challenged him to rock-paper-scissors, and he accepted. I won, and I killed his shell, and we all thought it was pretty funny during and after the competition. So I decided to make a more streamlined version of this game in a python script, for fun.

What it does

For one, this script requires sudo privileges to run. What it does is it checks the system for anyone else logged in, and it takes note of their terminal. This game requires at least 1 other person to be logged in. It prompts the user to select an opponent to challenge, and then asks the user to choose between "rock, paper, or scissors." It then writes to the opponent, asking the same question, but locking in their answer by means of creating a file in a special folder in /tmp. The answers are compared, and a win condition is chosen. If the user wins, the opponent is kicked off their terminal. If the opponent wins, the user is kicked.

How I built it

I programmed this project entirely in Visual Studio Code. I used the 'subprocess' module in python in order to run UNIX commands. Some of the commands used are 'w', 'ps', 'write', and 'kill'. I tested it by running an ssh server on my machine, and I created two test users that would be playing the game, test0 and test1. I tested it by having two terminals open at the same time, logging in through ssh, running the script on one user, and observing the output.

Challenges I ran into

One challenge I ran into while making this is how I would get the input of the opponent, because I only wanted the script to be dependent on one person running it. I tried to make it so that the output was captured when the opponent used the "write" command. However, this output is not possible to capture because it is written to a "psuedo-terminal", at least not without having a deep understanding of how terminals work, or using a lower-level language. In the end, I opted to prompt the opponent to just create a file, something that any user with any permissions can do.

Accomplishments that I'm proud of

An accomplishment I'm proud of was easily being able to integrate objects into my project, something I haven't done before in my projects.

What I learned

I learned a lot about objects, the 'subprocess' module, I learned more about how terminals work, and I learned more about certain commands, such as 'write' and 'w'.

What's next for Hacker Rock-Paper-Scissors

I think it would be funny if red teamers or blue teamers used it in competitions. If not, I think it was a really fun project to work on regardless. At some point, I would like to learn more about how UNIX terminals work, and see if I can capture the opponent's output through "write". Moreso, I would like to become proficient in bash so that I could reprogram the entire thing in bash and remove python as a dependency. I hope this project inspires other people to make similar multiplayer terminal games!

Built With

Share this project:

Updates