Skip to content

Instantly share code, notes, and snippets.

@hhc0null
Created October 10, 2015 06:47
Show Gist options
  • Save hhc0null/690c10958649bf90c8eb to your computer and use it in GitHub Desktop.
Save hhc0null/690c10958649bf90c8eb to your computer and use it in GitHub Desktop.
A Writeup for rev200 on "#04 Hokkaido CTF 勉強会"(http://doctf.connpass.com/event/20842/)

rev200のwriteup

Author: hhc0null
 本文は#04 Hokkaido CTF 勉強会で出されたrev200のwriteupである.

概要

 最適化はかかっていないが, stripコマンドによりシンボル情報が欠除したELF x86のバイナリを解析するという問題. この問題は主に以下のようなことを行っている.

** // TODO **

各処理について

 ここでは, それぞれの処理がどのようなことを行っているかを観察する.

** // TODO **

解法

 ソルバを書くと, 次のようなコードとなる.

#!/usr/bin/env python2


encoded_flag = "\x88\x09\xd8\x39\xb9\xdc\xa9\x29\x09\xc9\x39\xa9\x88"
flag_length = len(encoded_flag)

tmp = [None]*flag_length
for i, b in enumerate(map(ord, encoded_flag)):
    swapped = ((b << 4 & 0xf0)|(b >> 4 & 0xf))
    tmp[(flag_length-1) - i] = swapped ^ 0xff
decoded_flag = "".join(map(chr, tmp))

print "key{%s}"%(decoded_flag)

総括

 以下に元々のコードを示す.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
    char *input = argv[1];

    if(argc < 2) {
        printf("Usage: %s <input>\n", argv[0]);
        exit(EXIT_SUCCESS);
    }

    char buf[0x80] = {};
    char tmp;

    int len;

    len = strlen(input);
    for(int i = 0; i < len; i++) {
        tmp = input[(len-1)-i]^0xff;
        buf[i] = (tmp << 4 & 0xf0)|(tmp >> 4 & 0xf);
    }

    if(memcmp(buf, "\x88\x09\xd8\x39\xb9\xdc\xa9\x29\x09\xc9\x39\xa9\x88", strlen("\x88\x09\xd8\x39\xb9\xdc\xa9\x29\x09\xc9\x39\xa9\x88")) == 0) {
        puts("Congratz!");
        printf("Here is key{%s}\n", argv[1]);
    } else {
        puts("Wrong.");
    }

    return 0;
}

最後にflagを示しておこう.

flag: key{welcome2dlrow}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment