Here’s the solution for a programming challenge I did during SECCON 2017.

Introduction

The challenge is a programming challenge, we get greeted with a three.js cube with 6 textures, one for each faces with a QR-Code on them. Using zbar to read them, we will see this message:

[SECCON 2017 Online CTF                                   ]
[No. 1 / 50                                               ]
[Qubic Rube                                               ]
[Next URL is:                                             ]
[Have fun!                                                ]
[http://qubicrube.pwn.seccon.jp:33654/02c286df1bbd7923d1f7]

Going to that page will redirect us to a page with another challenge:

Seems like we are going to code a rubiks solver.

Idea

After seeing some other write-ups for this challenge, it seems like there’s a way to scramble the cube enough to give the solution with enough permutations. My solution is a little bit different in the fact that I am going to solve it using a rubiks solver rather than using a brute-forcy way.

The different difficulties I encountered during the challenge development:

  • The color opposites of the cubes weren’t always the same (generally white is supposed to be at the opposite of yellow, red <> orange and blue <> green), but it wasn’t always the case and I lost some time because of that.
  • Sometimes the center of the cube wasn’t properly rotated, so I had to add a little bit more operations at the end of the script to try 3 other cube combinations and try to read a QR-code.

The code

  • Download the images for the 6 faces (or use local versions)
  • Crop the images into 9 pieces
  • Read the center color for each faces
  • Send it to a rubiks solver, here I am using the python library “kociemba”.
  • Create the different essential moves R (right), L (left), U (up), D (down), F (front) and B (back).
    • I could’ve optimised a little bit the code here by creating inverse move but decided to just to the move 3 times when seeing a quote (Ex: R') and 2 times when I encounter a 2 (Ex: R2).
  • Parse the solver’s output and use the different moves created
  • Put the pieces back together
  • Launch zbar on each of them 4 times (rotating the center piece)

Dany Bach

A generic security blog by a pentester.
Belgium, Paris and now Leeds