Code snippets

Hopefully the list of small code samples will help other people that cope with the same problems I ran into (before writing these).
All snippets have been tested on Ubuntu unless specified otherwise.

Docker Multicompiler

This is a small set of scripts I wrote to easily compile a C program using various compilers and versions. For each version it creates a Docker image based on the Ubuntu 18.04 image, to try and make the environment as similar as possible. Oh, and it was easier to implement that way.
Please use an up-to-date version of bash as some used functionality is relatively recent.

Q: Why a new container for each version?    A: Lack of trust

  1. To specify which compilers to use and what versions, there is a compilers.conf file where every odd line specifies the compiler and the even line afterwards specifies the versions, delimited by a space.
    Note that the script (ab)uses aptitudes naming convention of "<compiler> - <version>". If this is not the case, the vanilla script doesn't work.
  2. tl;dr: To make a Docker image for each version specified in the conf file, simply run the script ./

    This may take a while, but should make an appropriate name for each image (the tag is compiler:version). If this name is already in use, it will override the current image.
    If a different version of Ubuntu is required, please change the version name and the repositories inside the top bit of
  3. tl;dr: To compile, run ./ <path_to_binary>

    This will create a new directory inside the current directory, called after the name of the file to compile. Inside this directory, more subdirectories will be made for each compiler+version. Inside these directories, 3 files will be generated, corresponding to the 3 optimisation modes (hardcoded a -O<num> loop). Furthermore, the -s option is given to the script to create a stripped binary, but this is obviously easily removed. Currently it only supports single files to be compiled, but feel free to edit the script or to ping me if you need the functionality of the script. This script automatically removes the containers after it compiled, but will not remove the images.
  4. tl;dr: When you are done and want to remove all the images, ./ can be run. This will remove all the Docker images that correspond to the naming convention (compiler:version).

    It does not track the Docker images being made but simply reads out the conf file. Thus, it will not remove the image if the tag has been manually changed and will delete images with a name corresponding to a combination inside the conf file.
    Note for Mac users: The (standard) mac version of Docker is currently still leaking memory. Creating this many images and containers may pose a problem to your hard disk until you remove the main file (and hence remove all images and containers).
    This main file is usually here: ~/Library/Containers/com.docker.docker/Data/vms/0/Docker.qcow2

Download here

Cookie stealer

More than once, Web CTFs have a challenge where you have to add a piece of Javascript to steal their cookies/session. I found myself scripting the same code over and over again to capture the cookie into some log file to find out I had made a stupid mistake or whatsoever. To be done once and for all, I wrote a versatile script here to create an easy multi-user token-based system that simply captures GET requests.

Local link

Assembly Pattern Matching

For a project a while ago, I was exploring how to fingerprint certain pieces of code after compilation to (x86/x86-64) code. This code uses a regular expression-like language to do pattern matching on binaries. This is only tested on x86 and x86-64 binaries thus far.

Github link