2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

DailyAlpacaHack day15

2
Posted at

day15 wirte up

This program prints the flag after sleeping for 75 years. It means you have to wait until the year 2100 to get the flag!

触ってみた感じ

ファイルをダウンロードしてみるとELFだったのでいったん実行してみた

 ./print_flag
 
bash: ./print_flag: Permission denied

権限がなくて実行できなかった

ls -l ./print_flag

-rw-r--r-- 1 aki aki 16136 Dec 14 16:01 ./print_flag

ls -lで属性表示したら所有者は自分だったけど実行権限はないらしい
chmodコマンドで権限を付与する

chmod +x ./print_flag

もう一度実行

./print_flag

I'll sleep for 75 years...

問題文通り2100年にならないとだめらしい

解き方

ELFなのでとりあえずGhidraに入れてコードを確認する。

main.
undefined8 main(void)

{
  puts("I\'ll sleep for 75 years...");
  sleep(0x8d12cea0);
  show_flag();
  return 0;
}

sleep関数は()の中だけ処理を待機する
今回の場合

sleep(0x8d12cea0)     //0x8d12cea0 = 2365580960 秒(約75年)

つまり実際に75年待たされた後show_flagが実行される

絶対待てない

なので、どうにかしてsleepの処理をスキップしたい

実際の手順(gdbを使う場合)

1.gdbでファイルを実行

bush.
gdb ./print_flag

2.breakポイントを設定する

今回はsleep関数の中に入ってその処理を終わらせたいのでbreakポイントをsleepに設定する

gdb.
break sleep

3.プログラムを実行

gdb.
run

コマンドの結果は以下のようになる

gdb.
I'll sleep for 75 years...

もしrunを実行して上のように表示されない場合、実行権限がない可能性が高い。
以下を実行して権限を付与して再度実行してみると解決する

bush.
chmod +x ./print_flag

4.sleepをスキップして実行を続ける

sleep()の実行結果をreturn 0で強制的に終了させる
そのあと、continueで実行を続ける

gdb.
return 0
continue

sleep()の処理が終了してshow_flagが実行されてフラグが出力される

Alpaca{G00d_Morning_AlpacaH4ck!}
2
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?