はまやんはまやんはまやん

hamayanhamayan's blog

Imitation Crab [rgbCTF 2020]

CTFtime.org / rgbCTF 2020 / Imitation Crab

Imitation Crab 448 Points
Flag should be modified to fit the rgbCTF format (rgbCTF{flag}, underscores between words)
http://challenge.rgbsec.xyz:7939/
~BobbaTea#6235

キーボード入力を反映するサイト。
まねっこしてくれる。
特にめぼしいこともないので、とりあえずソースコード

ソースコード

jsコードが埋め込まれていた。

function getKey(e) {
    var location = e.location;
    var selector;
    if (location === KeyboardEvent.DOM_KEY_LOCATION_RIGHT) {
        selector = ['[data-key="' + e.keyCode + '-R"]']
    } else {
        var code = e.keyCode || e.which;
        selector = [
            '[data-key="' + code + '"]',
            '[data-char*="' + encodeURIComponent(String.fromCharCode(code)) + '"]'
        ].join(',');
    }
    return document.querySelector(selector);
}

function pressKey(char) {
    var key = document.querySelector('[data-char*="' + char.toUpperCase() + '"]');
    if (!key) {
        return console.warn('No key for', char);
    }
    console.log(char)
    // each char is converted to its decimal value

    key.setAttribute('data-pressed', 'on');
    setTimeout(function () {
        key.removeAttribute('data-pressed');
    }, 200);
}

var queue = "";

function next() {
    var c = queue[0];
    queue = queue.slice(1);
    h1.innerHTML = originalQueue.slice(0, originalQueue.length - queue.length);
    pressKey(c);
    if (queue.length) {
        setTimeout(next, Math.random() * 200 + 50);
    }
}


document.body.addEventListener('keydown', function (e) {
    var key = getKey(e);
    if (!key) {
        return console.warn('No key for', e.keyCode);
    }

    key.setAttribute('data-pressed', 'on');
});

document.body.addEventListener('keyup', function (e) {
    var key = getKey(e);
                fetch('/search', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
        },
        body: JSON.stringify({ 'char': e.keyCode }),
    })
                key && key.removeAttribute('data-pressed');

});

function size() {
    var size = keyboard.parentNode.clientWidth / 90;
    keyboard.style.fontSize = size + 'px';
    console.log(size);
}

var keyboard = document.querySelector('.keyboard');
window.addEventListener('resize', function (e) {
    size();
});
size();

/searchにリクエストを飛ばすみたいだ。
burp suiteを噛ませてhistoryを見てみると、確かに押すと、アクセスしている。
まずはこのエンドポイントを攻撃してみるか。

  • /search
    • 色々試してみるけど、何もない。
  • /robots.txt
    • 出来心でこっち見てみたら/static/export.harとあった。
  • /static/export.har
    • アクセスするとダウンロードできる

中を見て思い出した。Chromeデベロッパーツールで開けるネットワークキャプチャファイルや。
開いてみる。
1つ1つsearchリクエストがある。
嫌な予感がするけど、まあ大した量でもないので、メモる

82 71 66 67 84 70 32 72 52 82 32 70 49 76 51 83 32 52 82 51 32 50 85 80 51 82 32 85 83 51 70 85 49 32

元々のサイトでaを押してリクエストを見ると、65と書いてあった。
ASCIIか。HIDのKeyCodeかなと期待したが違った。
適当にググって出てきた以下のサイトでデコードする。
ASCII text,Hex,Binary,Decimal,Base64 converter

f:id:hamayanhamayan:20200714215351p:plain

うん。あってそう。 {}_でくっつけたら答え。