[angstromctf2023]shortcircuit write up

zzsla·2023년 4월 27일
0
post-thumbnail

문제 정보

Bzzt

문제

문제에 들어가면 Username과 Password 입력칸이 있고, 옆에 Login버튼이 있다.

분석

해당 문제 코드를 보게 되면 head쪽에 script가 있고, 거기에 익숙한 flag의 형식이 있는 것을 볼 수 있다.

script쪽만 따로 본다.

 const swap = (x) => {
                let t = x[0]
                x[0] = x[3]
                x[3] = t

                t = x[2]
                x[2] = x[1]
                x[1] = t

                t = x[1]
                x[1] = x[3]
                x[3] = t

                t = x[3]
                x[3] = x[2]
                x[2] = t

                return x
            }

            const chunk = (x, n) => {
                let ret = []

                for(let i = 0; i < x.length; i+=n){
                    ret.push(x.substring(i,i+n))
                }

                return ret
            }

            const check = (e) => {
                if (document.forms[0].username.value === "admin"){
                    if(swap(chunk(document.forms[0].password.value, 30)).join("") == "7e08250c4aaa9ed206fd7c9e398e2}actf{cl1ent_s1de_sucks_544e67ef12024523398ee02fe7517fffa92516317199e454f4d2bdb04d9e419ccc7"){
                        location.href="/win.html"
                    }
                    else{
                        document.getElementById("msg").style.display = "block"
                    }
                }
            }

const check를 보면 username.valueadmin이 들어가야 하고, 그 다음 위에 암호화(swap,chunk)를 한 뒤에 암호화된 flag값이 나오면 login이 된다.

취약점

const swap를 보면 0,1,2,3으로 나누어져 있는 것이 swap가 한 번 했을 때 2,3,1,0로 변경된다. 근데 이 swap형식은 몇 번 돌리면 다시 값이 돌아오기 때문에 swap를 돌리면 된다.
0123 -> 2310
2310 -> 1032
1032 -> 3201
3201 -> 0123

익스플로잇

크롬 개발자도구에 콘솔에 들어와서 document.forms[0].password.value = "7e08250c4aaa9ed206fd7c9e398e2}actf{cl1ent_s1de_sucks_544e67ef12024523398ee02fe7517fffa92516317199e454f4d2bdb04d9e419ccc7" 를 넣어준다.
그 뒤에 swap(chunk(document.forms[0].password.value, 30)).join("") 를 넣어서 swap된 값을 얻는다.
swap된 값을 다시 document.forms[0].password.value에 넣어주고 다시 반복해 주면 된다. 그러면 flag를 얻을 수 있다.

actf{cl1ent_s1de_sucks_544e67e6317199e454f4d2bdb04d9e419ccc7f12024523398ee02fe7517fffa92517e08250c4aaa9ed206fd7c9e398e2}

profile
[README]newbi security hacker :p

0개의 댓글