LoginSignup
1
0

More than 1 year has passed since last update.

picoCTF 2023 Writeup

Last updated at Posted at 2023-03-31

はじめに

毎年3月ごろに行われているpicoCTFに参加してきました。
picoCTFには1年半ほど前からたまに触っていましたが、リアルタイムのpicoCTFは初参加になります。
今回は研究室のメンバーを誘い、計4人でチームを組み参加しました。結果としては全体で4000pt取ることが出来ました!
image.png

Writeup

以下、自分が解けたもので説明ができるものに関してまとめていきます。

Rules 2023

General Skills: 100pt
Read the rules of the competition and get a little bonus!

大会の規約ページに画像としてflagが置いてありました。
image.png

chrono

General Skills: 100pt
How to automate tasks to run at intervals on linux servers?

問題文から「Linux automated task」と検索すると、”cron”というワードがヒットします。

cronとは:
・job(script)を自動実行するためのデーモンプロセス
・cron設定ファイルのcrontabを置く(書く)場所は3つ挙げられる
  - /var/spool/cron/crontabs ディレクトリ内
  - /etc/crontab ファイル
  - /etc/cron.d ディレクトリ内

まず、/var/spool/cronの権限を見てみると、rootユーザ以外は読み取り権限はないようです。
image.png

次に、/etc/cron.d , /etc/crontabの権限を見てみると、その他のユーザには読み取り権限が与えられていることが分かります。

image.png
中略
image.png

/etc/crontabの中身を見てみると、フラグが書かれています。
image.png

money-ware

General Skills: 100pt
Flag format: picoCTF{Malwarename}
The first letter of the malware name should be capitalized and the rest lowercase.
Your friend just got hacked and has been asked to pay some bitcoins to 1Mz7153HMuxXTuR2R1t78mGSdzaAtNbBWX. He doesn’t seem to understand what is going on and asks you for advice. Can you identify what malware he’s being a victim of?

友達がどうやらハッキングを受けて、上記のBitcoinアドレスにビットコインを支払うように要求されたようです。そこで今回被害にあっているマルウェアの名前を特定するようです。

まず問題文で出てきたBitcoinアドレスを検索してみます。

検索結果から、Bitcoinに関するサイバー攻撃をまとめたページがヒットするので中身を読むと、Petyaという名前のマルウェアだということが分かります。

参考:https://www.cnbc.com/2017/06/28/ransomware-cyberattack-petya-bitcoin-payment.html

Permissions

General Skills: 100pt
Can you read files in the root file?

ログイン後のカレントディレクトリに、問題の答えに関係しそうなものは無い様子。
image.png

ルートディレクトリへ移動すると、challengeディレクトリがあり、答えに関係しそうなため移動してみます。
challengeディレクトリには、metadata.jsonが置いてあり、読み取り権限が与えられています。
image.png
catコマンドで中身を見てもいいですが、問題のタグからvimでファイルを開きます。
image.png

repetitions

General Skills: 100pt
Can you make sense of this file?

与えられたファイルの形式を調べると、ASCII text
catコマンドで中身を確認してみると、文末に==がるため、Base64でエンコードされていると分かります。
image.png

今回はCyberChefを使ってBase64のデコードを行っていきます。
image.png
デコードの結果、まだBase64でエンコードが出来そうです。
問題タイトルの「repetition」は「繰り返し」という意味なので、平文になるまでデコードを繰り返していきます。

1回目
image.png
2回目
image.png
3回目
image.png
4回目
image.png
5回目
image.png
6回目
image.png

useless

General Skills: 100pt
There's an interesting script in the user's home directory
The work computer is running SSH. We've been given a script which performs some basic calculations, explore the script and find a flag.

カレントディレクトリには、uselessという名前のshellスクリプトファイルが置かれています。
image.png
問題のタグには、manコマンドがあるので、uselessのマニュアルを確認してみます。
image.png
中略
image.png

Special

General Skills: 300pt
Don't power users get tired of making spelling mistakes in the shell? Not anymore! Enter Special, the Spell Checked Interface for Affecting Linux. Now, every word is properly spelled and capitalized... automatically and behind-the-scenes! Be the first to test Special in beta, and feel free to tell us all about how Special streamlines every development process that you face. When your co-workers see your amazing shell interface, just tell them: That's Special (TM)

コマンドを実行してみると、先頭が大文字になってしまい、正しく実行されません。
image.png

コマンドの先頭に実行に関係ないものを挟むことでこれを回避していきたい...

そこで、難読化シェル芸の難読化技法である"フェイク"を使用して、これを回避していきます。

難読化シェル芸とは
・内部的な動作の手続き内容・構造・データなどを、人間が理解しにくい、あるいはそのようになるよう加工
されたシェル芸のこと
シェル芸とは
・マウスも使わず、ソースコードも残さず、GUIツールを立ち上げる間もなく、あらゆる調査・計算・テキスト処理
をCLI端末へのコマンド入力一撃で終わらすこと。あるいはその時のコマンド入力のこと

引用:https://raintrees.net/news/95

例:

$ :date          # 1. dateは実行されない
$ $(:)date       # 2. dateは実行される
$ `:`date        # 3. dateは実行される

上記の2, 3のいずれかを使ってコマンドを実行します。

カレントディレクトリにはblarghというファイルorディレクトリが置かれています。(blarghのbがうまく認識されないため、fileやcdコマンドが実行できず判断できませんでした...)
image.png

そこで今までの問題から/challengeディレクトリにflagが置いてあったため、lsコマンドの代わりにfindコマンドでルートディレクトリの状況を確認します。
image.png
/challengeディレクトリmetadata.jsonが置かれているので、ファイルの中身を確認します。
image.png

Specialer

General Skills: 400pt
Reception of Special has been cool to say the least. That's why we made an exclusive version of Special, called Secure Comprehensive Interface for Affecting Linux Empirically Rad, or just 'Specialer'. With Specialer, we really tried to remove the distractions from using a shell. Yes, we took out spell checker because of everybody's complaining. But we think you will be excited about our new, reduced feature set for keeping you focused on what needs it the most. Please start an instance to test your very own copy of Specialer.

先ほどの問題Specialと違い、コマンドは認識されるが、ls, cat, findコマンド等が使用できません。
image.png

まず、使用できるコマンドを確認したいので、Tabキーを二回連続で入力して、一覧を見ます。
image.png

今回の問題ではlsコマンドが使えないので、こちらを使用せずディレクトリの一覧が分かるコマンドを調べました。
調べたところechoコマンドを使ってできるようです。使用できるコマンドの一覧にもechoが入っていたので早速試します。
image.png

カレントディレクトリにはabra ala sim の3つディレクトリがあったので、flagの手がかりが無いか調査します。

  • /home/ctf-player/abra

image.png
中身を確認するにはcatコマンドやviコマンド等を使いたいところですが使えないので、またechoを使って確認していきます。

$ echo "$(<対象のファイル名)"

上記のコマンドで代用できるようです。
abraディレクトリの2つのtxtファイルの内容はflagには関係のないものでした。

  • /home/ctf-player/ala

image.png

MatchTheRegex

Web Explotation: 100pt
How about trying to match a regular experession

テキストボックスに何かを入力するWebページのようです。
image.png

とりあえずブラウザの検証からソースコードを見てみると、コメントで^p.....F!?と書かれています。
image.png

問題タイトルから正規表現が関係しているのは一目瞭然です。
今回指定されている正規表現は^p.....F!?
指定された正規表現にマッチする例として、picoCTFppppppFが挙げることが出来ます。

これをWebサイトのテキストボックスに入力してSUBMIT。
image.png

SOAP

Web Explotation: 100pt
The web project was rushed and no security assessment was done. Can you read the /etc/passwd file?

指定されたWebページは以下の様なページになっています。
image.png

問題のタグから「XXE」が関係しているので、BurpSuiteを使ってアプローチをかけていきます。

まず、Webページ下部にある三つのカードのDetilsを押した際の通信です。Send to Repeaterを押して通信のリクエストを編集していきます。
image.png

以下のようにリクエストを書き換えてSend。
image.png

image.png

さいごに

久しぶりにCTFに参加をしましたが、CTFを始めた頃よりもスキルアップしていると感じられた結果でした。
個人的にはReverse EngineeringやBinary Exploitation系の問題がまだまだ苦手なので、継続して勉強を続けていきたいと思います。

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