金盾2016 Writeup – [Web] GSA2016

題目

有一個網站GSA2016, 要我們闖進去找Flag

提示

SEO

解題

網站打開後就看到一張圖然後就沒了

但在source中發現了下面這段javascript, 看樣子是用來載入圖片用的

function update(n, f) {
            $.ajax({
                url: 'ShowPhoto.ashx',
                type: 'POST',
                data: f,
                cache: false,
                success: function (data) {
                    $('#m').html('<img class="img-rounded" src="data:image/png;base64,' + data + '" />');
                },
                error: function (errorText) {
                    alert("Wwoops something went wrong !");
                }
            });
        }
        update("kobe-bryant.png", '{"file_name":"a29iZS1icnlhbnQucG5n"}');

從 js 中可以發現他呼叫了 ShowPhoto.ashx 來取得資源, 參數是檔名的base64, 回傳結果也是 base64

Aspx的網站通常都有 web.config 這個設定檔, 因此將其 base64 encode 後向 ShowPhoto.ashx 請求資源

但並這麼做並沒有得到任何內容, 可能猜測的目錄不對, 改送 ../web.config 接著就得到 Web.config 內容

在 Web.config 中發現有用資訊

<!-- Flag file -->
<add key="keyfile" value="54fb3bd9d6052999fbf5bbd397f483d2af35461fec3c1a8886f52109950aeea611a58ddf7c17efb80f7a754272dbd4955d9b974ee506db6e499e5b162fa78480.key" />

看樣子只要猜到檔案位置就收工了, 這時候想到 Aspx 通常會將一些資料放在 App_Data, 因此向 ShowPhoto.ashx 取得這個檔案, Flag Get!

Flag

Live in the present moment!

註記

題目一開始給的提示 SEO 是提示我們去看 robots.txt 這個檔案, 其中 Disallow: App_Data 暗示檔案位置

QiwiCTF2016 Writeup – [Web] javascript

題目

網頁中提供一個欄位讓使用者輸入 Key, 程式會驗證是否正確
而這把 key 就是 這題的 flag.

過程

該檢查函數資料如下

eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}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6D|79|35|37|2F|78|71|51|53|55|6B|50'.split('|'),0,{}))

我們可以透過以下兩種方法解開 packer
1. 透過 unPacker
2. 將 eval 改為 console.log 然後執行, 重複這個動作直到內容完全解開

解開後我們可以得到下列的結果

function encode(str) 
    {
        var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
        var encoded = [];
        var c = 0;
        while (c < str.length) 
        {
                var b0 = str.charCodeAt(c++);
                var b1 = str.charCodeAt(c++);
                var b2 = str.charCodeAt(c++);
                var buf = (b0 << 16) + ((b1 || 0) << 8) + (b2 || 0);
                var i0 = (buf & (63 << 18)) >> 18;
                var i1 = (buf & (63 << 12)) >> 12;
                var i2 = isNaN(b1) ? 64 : (buf & (63 << 6)) >> 6;
                var i3 = isNaN(b2) ? 64 : (buf & 63);
                encoded[encoded.length] = chars.charAt(i0);
                encoded[encoded.length] = chars.charAt(i1);
                encoded[encoded.length] = chars.charAt(i2);
                encoded[encoded.length] = chars.charAt(i3);

    }
        return encoded.join('');

}
if (encode(ctf.password.value) == "ajR2NHNjcjFwdF9fXzBiZnVzYzR0MTBu")
    {
    alert("That right!");
}
else
    {
    alert("Wrong password!");
}

當中可以得知程式會判斷輸入值encode後是否為 ajR2NHNjcjFwdF9fXzBiZnVzYzR0MTBu
接著觀察 encode 的動作方式, 然後就發現他其實是 base64 encode

Flag

j4v4scr1pt___0bfusc4t10n