Tags: misc 


# Insane Bolt Writeup

### **TLDR**

Connect to instance, take in input as a grid, run BFS to get shortest paths, and send to standard input.

## Initial

When we connect to the Docker Instance, we are given two options.

![Starting Prompt](https://raw.githubusercontent.com/jontay999/CTF-writeups/master/HackTheBox/UniQual2021/Misc/Insane-Bolts/images/1.png)

It is a command line game where you have to input the shortest path for the robot to reach the diamond via instructions DLR (Down, Left, Right). For some reason Up was not needed in this game.

![Basic Idea](https://raw.githubusercontent.com/jontay999/CTF-writeups/master/HackTheBox/UniQual2021/Misc/Insane-Bolts/images/2.png)

From the grid given, it can be seen that the valid path always passes through a bolt at every step

## First Try

At first, I thought I could slowly play the game but after a while I realised this was not meant to be brute-forced played normally.

There is a time limit, approximately 10-15 seconds, that if exceeded, would end the game. One mistake and the game would end as well. There are also a minimum of 500 levels to be completed which requires scripting

![Shouldn't be brute forced](https://raw.githubusercontent.com/jontay999/CTF-writeups/master/HackTheBox/UniQual2021/Misc/Insane-Bolts/images/3.png)

## Main Idea

The problem was a classic shortest path problem which could be solved via Breadth First Search.

The main steps were to

- Connect to the Docker instance provided
- Transform the command line output and parse into a matrix
- Make the BFS function that would output the shortest path
- Send the Shortest Path as input

Code is in [insane-bolts.py](https://github.com/jontay999/CTF-writeups/tree/master/HackTheBox/UniQual2021/Misc/Insane-Bolts/insane-bolts.py)

## Tools Used

- `pexpect` module from python to read and write to standard input and ouput.
- `nc` command to connect to instance

## Success

After collecting 500 diamonds, the final flag was outputted.

Original writeup (https://github.com/jontay999/CTF-writeups/tree/master/HackTheBox/UniQual2021/Misc/Insane-Bolts).