Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

解答 #2

Closed
mururu opened this issue Apr 24, 2021 · 7 comments
Closed

解答 #2

mururu opened this issue Apr 24, 2021 · 7 comments

Comments

@mururu
Copy link
Member

mururu commented Apr 24, 2021

#1 の続きです

とりあえず go tool nm のシグネチャが わからないぞ?

$ go tool nm
usage: go tool nm [options] file...
  -n
      an alias for -sort address (numeric),
      for compatibility with other nm commands
  -size
      print symbol size in decimal between address and type
  -sort {address,name,none,size}
      sort output in the given order (default name)
      size orders from largest to smallest
  -type
      print symbol type after name

ほうファイルを渡せばいいのか。とりあえず gocon2021_office_hour をわたしてみるか

$ go tool nm gocon2021_office_hour
  4df6f8 r $f64.3eb0000000000000
  4df700 r $f64.3f847ae147ae147b
  4df708 r $f64.3fd0000000000000
  4df710 r $f64.3fd3333333333333
  4df718 r $f64.3fe0000000000000
  4df720 r $f64.3fe3333333333333
  4df728 r $f64.3fec000000000000
  4df730 r $f64.3fee666666666666
  4df738 r $f64.3ff0000000000000
  4df740 r $f64.3ff199999999999a
  ....

なんか大量に出てきたぞ?
grep っていってたからこのなかからなにか取り出すのか…?
うーんとりあえず gocon とかでみてみるか

root@e642118fb5d2:/go/src/app# go tool nm gocon2021_office_hour | grep gocon
  540560 D github.com/kanmu/gocon_2021_kanmu..inittask
  49bb60 T github.com/kanmu/gocon_2021_kanmu.New
  49bc60 T type..eq.github.com/kanmu/gocon_2021_kanmu.LetsRunThisCommand_strings_gocon2021_office_hour_grep_question

ん…? LetsRunThisCommand_strings_gocon2021_office_hour_grep_question
おお!Let's Run This Command!?これはあやしい!
strings_gocon2021_office_hour_grep_question を実行するんだろうけど…
gocon2021_office_hour はリポジトリ名で grep はたぶんあの grep だとすると strings ってなんだ?
(ぐぐってみたら)strings っていうコマンドあるやんけ!

$ strings gocon2021_office_hour | grep question
P*gocon_2021_kanmu.LetsRunThisCommand_strings_gocon2021_office_hour_grep_question
  *************  question: what is the international standard of credit card messaging? The answer is ISOxxxx  ***************  000102030405060708091011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798990w
type..eq.github.com/kanmu/gocon_2021_kanmu.LetsRunThisCommand_strings_gocon2021_office_hour_grep_question
github.com/kanmu/gocon_2021_kanmu.(*LetsRunThisCommand_strings_gocon2021_office_hour_grep_question).Run
type..eq.github.com/kanmu/gocon_2021_kanmu.LetsRunThisCommand_strings_gocon2021_office_hour_grep_question

ん?おおおおお
question: what is the international standard of credit card messaging? The answer is ISOxxxx
これか!ISOxxxx が答えっぽいけど、英語わらないから what is the international standard of credit card messaging ISO で検索してみよ
お、ISO8583 っていうのが出てきた!これが答えか!

$ ./gocon2021_office_hour
Enter your answer 答えを入力してください: ISO8583

最後のメッセージはご自身で確認してみてください 🏅

@mururu mururu changed the title 回答 解答 Apr 24, 2021
@summerwind
Copy link

自分は次のような流れでした。最初は strings コマンドを知らなかったので苦戦しました。勉強になりました!

  1. /etc 配下を見て Debian 系なのを把握
  2. とりあえず less を apt でインストールしてファイルを読む
  3. なんか ELF 関係しそうだから file コマンドとかで見る
  4. objdump の出力を見て、gocon とかで検索する
  5. ヒットした文字がヒントっぽかったので、それにしたがって strings コマンドを実行する
  6. ヒントが表示されたので、スポンサーセッションの資料を読んで確認する
  7. 正解!

@ymotongpoo
Copy link

ymotongpoo commented Apr 24, 2021

私の場合

とりあえずコレ実行しろってあるからDockerイメージ起動するかあ

$ docker run -it ghcr.io/kanmu/gocon2021-office-hour:latest /bin/bash

Unable to find image 'ghcr.io/kanmu/gocon2021-office-hour:latest' locally
latest: Pulling from kanmu/gocon2021-office-hour
bd8f6a7501cc: Pull complete 
44718e6d535d: Pull complete 
efe9738af0cb: Pull complete 
f37aabde37b8: Pull complete 
c4c446e03742: Pull complete 
77ce91079a9a: Pull complete 
62b51a704e67: Pull complete 
338bf636f119: Pull complete 
86eb2bd6489b: Pull complete 
50d43cc9d96b: Pull complete 
Digest: sha256:13dd95fafc25ff7395298918c03b7c1682a7fc0fcb540b798cc8c6db4381343b
Status: Downloaded newer image for ghcr.io/kanmu/gocon2021-office-hour:latest
root@e89f41b9e369:/go/src/app# ls -la
total 1968
drwxr-xr-x 1 root root    4096 Apr 24 01:27 .
drwxrwxrwx 1 root root    4096 Apr 24 01:11 ..
-rw-r--r-- 1 root root      89 Apr 24 00:51 MEMO
-rwxr-xr-x 1 root root 2002618 Apr 24 01:27 gocon2021_office_hour

なんだこれ、実行バイナリしかないな。とりあえずMEMO見よ。

root@e89f41b9e369:/go/src/app# cat MEMO
何回失敗しても諦めないで!
Don't give up no matter how many times you fail!

なんだこれ!!!煽りか!!!!!とりあえずバイナリ実行してみるか。

root@e89f41b9e369:/go/src/app# ./gocon2021_office_hour 
Enter your answer 答えを入力してください: 

は????ノーヒントじゃん!!!どうせ文字列比較してんだろ??じゃあもう strings コマンドで中身見て無理やり回答するわ

root@e89f41b9e369:/go/src/app# strings ./gocon2021_office_hour | more

とりあえずなんか "Enter your answer 答えを入力してください:" という文字列で聞いてるからその前後とかにあるんじゃないの?ということで more の中で "answer" で検索する

...
found bad pointer in Go heap (incorrect use of unsafe or cgo?)runtime: internal error: misuse of lockOSThread
/unlockOSThreadruntime.SetFinalizer: pointer not at beginning of allocated blockstrconv: internal error: extF
loat.FixedDecimal called with n == 0Success! 
bytes.Buffer: UnreadByte: previous operation was not a successful readtoo many concurrent operations on a sin
gle file or socket (max 1048575)reflect.Value.Interface: cannot return value obtained from unexported field o
r methodgo tool ~~~ 
 `go tool` 
  *************  question: what is the international standard of credit card messaging? The answer is ISOxxxx
  ***************  000102030405060708091011121314151617181920212223242526272829303132333435363738394041424344
4546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989
90w
path	github.com/kanmu/gocon2021_office_hour
mod	github.com/kanmu/gocon2021_office_hour	(devel)	
dep	github.com/kanmu/gocon_2021_kanmu	v0.0.0-20210423233826-5e134f8d4bbe	h1:1A5Tjkr273Y5UaQFZJ
zn66viN1SfZ5C7TtxgKCdxo88=
...

え、なんか "question" とか書いてあるし、これさっき @pongzu さんが発表してたやつじゃん。あのISOの番号なんだっけ?

これ を見る。

root@e89f41b9e369:/go/src/app# ./gocon2021_office_hour        
Enter your answer 答えを入力してください: ISO8583
Success! 正解です!すごい、おめでとうございます!

@achiku
Copy link
Member

achiku commented Apr 24, 2021

ファイルの確認。

root@aa22261b14b1:/go/src/app# file MEMO
bash: file: command not found

file コマンドが無いので入れる。apt-get update した後に以下。

root@aa22261b14b1:/go/src/app# apt-get install file
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libmagic-mgc libmagic1
The following NEW packages will be installed:
  file libmagic-mgc libmagic1
0 upgraded, 3 newly installed, 0 to remove and 2 not upgraded.
Need to get 426 kB of archives.
After this operation, 5771 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://deb.debian.org/debian buster/main amd64 libmagic-mgc amd64 1:5.35-4+deb10u2 [242 kB]
Get:2 http://deb.debian.org/debian buster/main amd64 libmagic1 amd64 1:5.35-4+deb10u2 [118 kB]
Get:3 http://deb.debian.org/debian buster/main amd64 file amd64 1:5.35-4+deb10u2 [66.4 kB]
Fetched 426 kB in 0s (1523 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package libmagic-mgc.
(Reading database ... 15439 files and directories currently installed.)
Preparing to unpack .../libmagic-mgc_1%3a5.35-4+deb10u2_amd64.deb ...
Unpacking libmagic-mgc (1:5.35-4+deb10u2) ...
Selecting previously unselected package libmagic1:amd64.
Preparing to unpack .../libmagic1_1%3a5.35-4+deb10u2_amd64.deb ...
Unpacking libmagic1:amd64 (1:5.35-4+deb10u2) ...
Selecting previously unselected package file.
Preparing to unpack .../file_1%3a5.35-4+deb10u2_amd64.deb ...
Unpacking file (1:5.35-4+deb10u2) ...
Setting up libmagic-mgc (1:5.35-4+deb10u2) ...
Setting up libmagic1:amd64 (1:5.35-4+deb10u2) ...
Setting up file (1:5.35-4+deb10u2) ...
Processing triggers for libc-bin (2.28-10) ...

どういうファイルか確認。MEMOは cat できそう。 gocon2021_office_hour はGoのバイナリ。

root@aa22261b14b1:/go/src/app# file MEMO
MEMO: UTF-8 Unicode text
root@aa22261b14b1:/go/src/app# file gocon2021_office_hour
gocon2021_office_hour: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, Go BuildID=9KmAMAHx3cicuw5XsOjg/HrfhE7epBpEI4D0S_9f7/rDVdLYmZoXZzT7ojoLm0/5hRXwGIwsdIhIUXwgW9k, not stripped
root@aa22261b14b1:/go/src/app#

MEMOの内容確認。

root@aa22261b14b1:/go/src/app# cat MEMO
何回失敗しても諦めないで!
Don't give up no matter how many times you fail!

ほう。一旦実行ファイルを動かしてみる。

root@aa22261b14b1:/go/src/app# ./gocon2021_office_hour
Enter your answer 答えを入力してください:
Failed 残念
Enter your answer 答えを入力してください: ^[/
Failed 残念
Enter your answer 答えを入力してください: asdfa
Failed 残念
Enter your answer 答えを入力してください: asdf

何かを比較している気がするので strings で中身を確認してみる。

root@aa22261b14b1:/go/src/app# strings gocon2021_office_hour > aa.txt

less が入ってなかったので apt-get で入れて中身を検索。 Failed 残念 Enter your answer 辺りか?それっぽいもの見つからないなぁと思って眺めていたら以下の部分を発見した。

  *************  question: what is the international standard of credit card messaging? The answer is ISOxxxx  ***************  000102030405060708091011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798990w

これはアレねという事で以下でクリア。

root@aa22261b14b1:/go/src/app# ./gocon2021_office_hour
Enter your answer 答えを入力してください: ISO8583
Success! 正解です!すごい、おめでとうございます!
root@aa22261b14b1:/go/src/app#

@makiuchi-d
Copy link

だいたいみなさんと同じ方法でした。

そこまで難易度高くないだろうから、きっとバイナリに埋まってると決め打ちして、
stringsにかけたのをlessにパイプで、としたらlessがなかったので、
docker cpで手元に持ってきて読みました。

ざっと眺めてたら運良くThe answer is ISOxxxxを見つけて、
@pongzu さんの発表中に見てたWikipediaのURLをブラウザの履歴から探してクリア。

@DQNEO
Copy link

DQNEO commented Apr 24, 2021

力づくでガチャガチャやったらノーヒントで解けました

  • 当該コンテナに gdb とかバイナリ解析用ツールが何も入ってないので、「これじゃ無理だ」と思って自分の docker container (https://github.com/DQNEO/go-samples/tree/master/gocon2021) にバイナリをコピー
  • gdb ./gocon2021_office_hour
  • 「たぶん Println の後にScanがあって、その後数値比較してるだろう、cmp 命令を探そう」と思って main.main の中をステップ実行してみるも、どうやら思ってるコードとちょっと違う (fmt.Fprint 呼び出しが複数個あるし、分岐命令も何個かある)
  • cmp 命令の引数に使われている 0 やら 5 やらを試してみたがダメ
  • 諦めきれず、main.main の中をガチャガチャステップ実行して、取っ掛かりが欲しいので fmt.Fprint にブレークポイントをはってみた
  • Fprint 呼び出し時のスタックメモリの中身を1個ずつダンプしてみた

何かキラッと光る金塊を発見

image

ヒントの英文をググったら答えがあった

@hiroakis
Copy link
Member

hiroakis commented Apr 24, 2021

以下の思考で調べました。

まずはMEMOを見てみよう。

root@9a9d8bafa1ef:/go/src/app# cat MEMO
何回失敗しても諦めないで!
Don't give up no matter how many times you fail!

はい。ではいったん動かしてみよう。

root@9a9d8bafa1ef:/go/src/app# ./gocon2021_office_hour
Enter your answer 答えを入力してください:

なるほど...ファイル自体を調べないと。 ​file で調べてみる。

root@9a9d8bafa1ef:/go/src/app# file gocon2021_office_hour
bash: file: command not found

ない。ないけど go のバイナリであることは問題内容から自明なのでまあいいか...。strings で回答ぽいもの埋め込まれていないか見てみよう。

root@9a9d8bafa1ef:/go/src/app# strings gocon2021_office_hour | less
bash: less: command not found

おっと less もない。であれば more で。

root@9a9d8bafa1ef:/go/src/app# strings gocon2021_office_hour | more

xxxxxxxxxxxx
xxxxxxxxxxxx
xxxxxxxxxxxx
...

長いな...。ではここでこの問題は比較的短時間で解くことができるようお膳立てされているゲームと考える。回答につながるかもしれないそれっぽいキーワード、 kanmu, gocon, ctf でひっかけてみる。

root@9a9d8bafa1ef:/go/src/app# strings gocon2021_office_hour | grep -i kanmu
github.com/kanmu/gocon_2021_kanmu.(*LetsRunThisCommand_strings_gocon2021_office_hour_grep_question).Run

なんかあった。ではそのように。

root@9a9d8bafa1ef:/go/src/app# strings gocon2021_office_hour | grep question
P*gocon_2021_kanmu.LetsRunThisCommand_strings_gocon2021_office_hour_grep_question
 ​*************  question: what is the international standard of credit card messaging? The answer is ISOxxxx  ***************

発見。クリア

@nobishino
Copy link

以下の手順でした。だいたい誘導されたとおりに解いたと思います!楽しかったです!

  • まず実行してみる→適当に入力してEnter→Fail とりあえず何をすればゴールなのかはわかった
  • MEMOを見た方が良さそう
  • もしかして何回もEnterしてたらクリアできるのでは→そんなことはなくてヒントが出てきた
  • 諦めるなって書いてあるしヒントが出てきたくらいで諦めるのは早いのでは?! と考えてEnter長押し→何も得られず
  • go tool objdumpgo tool nmのどちらかっぽい。objdumpの方からは何もわからず
  • kanmuとかで検索したらヒント行LetsRunThisCommand_strings_gocon2021_office_hour_grep_questionが出てきた
  • stringsというコマンドがあることを知らないので意味がよくわからずしばらく迷走する
  • もしかしてstringsというコマンドがあるのか?と思い当たり実行してみるとなんか出てきた。
  • 午前中のセッションを聞いていたので何を聞かれているか思い当たりクリア

@mururu mururu closed this as completed Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants