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

hamayanhamayan's blog

$Echo [NahamCon 2021 CTF]

何かを書くとそれを即座にEchoしてくれる。 Echoコマンドだろうのでコマンドインジェクションかな?

$([command])を試してみると、 Hey mate, you seem to be using some characters that makes me wanna throw it back in your face >:( 怒られた。

使えない記号を確認するとほとんど使えないのだが、以下の記号は使えるようだった。

`
<
.
/
`id`

を試すと、うまくいく。

ls ../をするとflag.txtというものがあるので、cat ../flag.txtとすると Man that's a mouthful to echo, what even? のように言われる。 ほう?

cat index.phpをすると、なぜかコードの一部が漏洩する

 ?~\\\\]/', $to_echo)) { 
        print "Hey mate, you seem to be using some characters that makes me wanna throw it back in your face >:("; 
    } elseif ($to_echo=="cat") { 
        print "Meowwww... Well you asked for a cat didn't you? That's the best impression you're gonna get :/"; 
    } elseif (strlen($to_echo) > 15) { 
        print "Man that's a mouthful to echo, what even?"; 
    } else {
        system($cmd);
    }
} else { 
    print "Alright, what would you have me say?"; 
}

?>

文字数制限か。確かにcat ../flag.txtだと17文字だ。 そういえば<が使えたな… < ../flag.txtでフラグゲット。 flag{1beadaf44586ea4aba2ea9a00c5b6d91} なぜ…