この大会は2021/6/11 9:00(JST)~2021/6/14 9:00(JST)に開催されました。
今回もチームで参戦。結果は6500点で841チーム中20位でした。
自分で解けた問題をWriteupとして書いておきます。
Example Problem (misc 25)
問題にフラグが書いてあった。
bcactf{this_is_a_flag}
Obligatory Discord Problem (misc 25)
Discordに入り、#announcementsチャネルのメッセージを見ると、フラグが書いてある。
bcactf{is_too_sanity_checks_two_much?}
I Can Haz Interwebz? (misc 50)
ncで接続するだけ。
$ nc misc.bcactf.com 49155 :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::: ############::::::::::::::::############ ############################## :::::::::::::::: ###################################### ######??????????????????????###### :::::::::::::: ============################========== ####??????????<>????<>????????#### :::::::::::::: ====================================== ##????<>???????????? ??<>????## :: :::::::: ====================================== ##???????????????? ;;;; ??????## ;;;; :::::: ------------================ ---- ##??????????<>???? ;;;;;;??????## ;;;;;; :::::: ----------------------------;;;; -- ##???????????????? ;;;;;; ;;;;;;;; :::::: ---------------------------- ;;;; ##???????????????? ;;;;;;;;;;;;;;;;;;;;;; :::::: ++++++++++++---------------- ;;;; ##????????????<> ;;;;;;;;;;;;;;;;;;;;;;;;;; :::: ++++++++++++++++++++++++++++++ ;;;; ##??<>?????????? ;;;;;;@@ ;;;;;;;;@@ ;;;; :::: ++++++++++++++++++++++++++++++++ ##?????????????? ;;;;;; ;;;; ;; ;;;; :::: ~~~~~~~~~~~~++++++++++++++++~~~~~~~~ ####??????<>???? ;;()();;;;;;;;;;;;;;;;()() :::: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ######???????????? ;;;;;; ;;;; :::::: $$$$$$$$$$$$~~~~~~~~~~~~~~~~$$$$$$$$ ################## ;;;;;;;;;;;;;;;;;; :::::::: $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ;;;;;; :::::::::: $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ;;;; :: ;; :::::::::: ;; :: ;;;; :::::::::::: ::::::::::::$$$$$$$$$$$$$$$$:::::: :::: :::::::::::::: :::: :::::::::::::: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: bcactf{r41nb0w_P0p_t4rT5_g0_nY4_s3Dy0Bqd6u} from https://github.com/klange/nyancat
bcactf{r41nb0w_P0p_t4rT5_g0_nY4_s3Dy0Bqd6u}
BCA Mart (binex 75)
ある程度大きい数だけ購入して、購入額をマイナスにして所持金を増やす。その後フラグを購入すればよい。
$ nc bin.bcactf.com 49153 Welcome to BCA MART! We have tons of snacks available for purchase. (Please ignore the fact we charge a markup on everything) 1) Hichew™: $2.00 2) Lays® Potato Chips: $2.00 3) Water in a Bottle: $1.00 4) Not Water© in a Bottle: $2.00 5) BCA© school merch: $20.00 6) Flag: $100.00 0) Leave You currently have $15. What would you like to buy? > 1 How many fruity pieces of goodness would you like to buy? > 10000000000000 That'll cost $-1662697472. Thanks for your purchse! 1) Hichew™: $2.00 2) Lays® Potato Chips: $2.00 3) Water in a Bottle: $1.00 4) Not Water© in a Bottle: $2.00 5) BCA© school merch: $20.00 6) Flag: $100.00 0) Leave You currently have $1662697487. What would you like to buy? > 6 How many super-cool ctf flags would you like to buy? > 1 That'll cost $100. Thanks for your purchse! bcactf{bca_store??_wdym_ive_never_heard_of_that_one_before}
bcactf{bca_store??_wdym_ive_never_heard_of_that_one_before}
Honors ABCs (binex 75)
一文字も当てずに、BOFで上書きすればよい。
$ nc bin.bcactf.com 49155 Welcome to your first class at BCA: Honors-level ABCs. Because we expect all our students to be perfect, I'm not going to teach you anything. Instead, we're going to have a quiz! And, of course, I expect all of you to know the material already. ╔════════════════════════╗ ║ THE QUIZ ║ ║ ║ ║ 1) Recite the alphabet ║ ╚════════════════════════╝ Answer for 1: zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz How did you end up here? You must have cheated! Let me recite the BCA plagarism policy. Cheating and Plagiarism Policy ============================== To plagiarize is to steal and use (the ideas or writings of another) as one’s own (American Heritage Dictionary, 1973:1001). Legally, plagiarism has been defined as the act of appropriating the literary composition of another, or parts or passages of his/her writings, or language of the same, and passing them off as the product of one’s own mind (O’Rourke v. RKO Radio Pictures: 483). The student should note that neither of these definitions includes intention or motivation—it is the act itself which constitutes plagiarism. Ignorance, naiveté or sloppiness is no excuse. Consequences for Plagiarism or Cheating --------------------------------------- 1st Offense: 1. A grade of “0” will be given for the assignment or test 2. Option to re-do assignment with the grade for the redone assignment averaged with the zero for a final average not to exceed 50%. 3. If a student is caught cheating on a test, the student may retake the test; the zero on the first test will be averaged with the score on the retake for a maximum final test grade of 50%. 4. Parent notification; required parent conference with an administrator, or designee, to determine what further action, if any, should be taken. 5. A recording of the incident is made by the building supervisor. 2nd Offense: 1. A grade of “0” will be given for the assignment or test 2. No make-up option; 3. Parent notification; required parent conference with an administrator, or designee, to determine what further action, if any, should be taken. 4. A formal recording of the incident is placed in the student’s folder. 5. A one-day out-of-school suspension is assigned. 3rd Offense: 1. Loss of course credit 2. Required parent conference with an administrator, or designee 3. Up to three-day suspension 4. Recommendation for alternative placement Plagiarism and cheating are serious offenses and the Board expects all students to be honest in the presentation and submission of their assignments, homework, test answers and any other academic works as the product of their own intellectual efforts. Any student who copies verbatim or paraphrases another’s words or ideas or who allows one’s own words or ideas to be copied verbatim or paraphrased shall be guilty of plagiarism. A student who shares his own words or ideas with another or presents another’s words or ideas and attributes them as his own is also guilty of plagiarism. Cheating is acting dishonestly or unfairly in order to gain an advantage. Acts of cheating may include the submission of work prepared by another but passing it off as one’s own or copying the work or answers of another. It is also an act or instance of sharing or allowing to be shared one’s own works, words, answers or ideas with others. For more information see Board Policy 5701. The above is copied from https://www.bergen.org/cms/lib/NJ02213295/Centricity/Domain/9/studentHandbook2020_2021-rev-9-24.pdf See, I cited my sources, so I'm obviously not plagiarising. also let me add that that's a pretty ugly url also also have the flag! bcactf{now_i_know_my_A_B_Cs!!_next_time_wont_you_cheat_with_me??} Alright, class dismissed!
bcactf{now_i_know_my_A_B_Cs!!_next_time_wont_you_cheat_with_me??}
AP ABCs (binex 100)
一文字も当てずに、BOFで上書きすればよいのは、Honors ABCsと同様。ただし、scoreを上書きする際には0x73434241(="ABCs")にする必要がある。
$ nc bin.bcactf.com 49154 Welcome to AP ABCs! Unlike the non-AP class, you get the privilege of taking the AP test. Wow, I know, so exciting right??!1 Anyways, good luck! ╔══════════════════════════════════════════╗ ║ 2021 AP® | 🌰 College Board ║ ║ ║ ║ ║ ║ ─────────────────────── ║ ║ AP Alphabet ║ ║ Free-Response Questions ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ Something about trademarks ║ ╚══════════════════════════════════════════╝ ╔══════════════════════════════════════════╗ ║ 2021 AP® Alphabet FRQs ║ ║ ║ ║ ALPHABET ║ ║ Section II ║ ║ Total Time—1 hour ║ ║ Number of Questions—1 ║ ║ ║ ║ ║ ║ 1. Recite the alphabet ║ ║ ║ ║ ──────────────────────────────────────── ║ ║ ║ ║ ║ ║ ║ ║ STOP ║ ║ END OF EXAM ║ ║ ║ ║ -2- ║ ╚══════════════════════════════════════════╝ Answer for 1: zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz You got a 1684234849 on your APs.
>>> ('%x' % 1684234849).decode('hex')[::-1] 'abcd'
この部分を"ABCz"にすればよい。
$ nc bin.bcactf.com 49154 Welcome to AP ABCs! Unlike the non-AP class, you get the privilege of taking the AP test. Wow, I know, so exciting right??!1 Anyways, good luck! ╔══════════════════════════════════════════╗ ║ 2021 AP® | 🌰 College Board ║ ║ ║ ║ ║ ║ ─────────────────────── ║ ║ AP Alphabet ║ ║ Free-Response Questions ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ Something about trademarks ║ ╚══════════════════════════════════════════╝ ╔══════════════════════════════════════════╗ ║ 2021 AP® Alphabet FRQs ║ ║ ║ ║ ALPHABET ║ ║ Section II ║ ║ Total Time—1 hour ║ ║ Number of Questions—1 ║ ║ ║ ║ ║ ║ 1. Recite the alphabet ║ ║ ║ ║ ──────────────────────────────────────── ║ ║ ║ ║ ║ ║ ║ ║ STOP ║ ║ END OF EXAM ║ ║ ║ ║ -2- ║ ╚══════════════════════════════════════════╝ Answer for 1: zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzABCDEFGHIJKLMNOPQRSTUVWXYZABCs You got a 1933787713 on your APs. Tsk tsk tsk. Cheating on the AP® tests is really bad! Let me read you the College Board policies: Section 3. Score Cancellation and Disciplinary Measures a. Score Cancellation and Disciplinary Measures. In the event that College Board or ETS determines that your scores are invalid under section 3(b) below, or you have engaged in Misconduct under section 3(c) below, we may, in our sole discretion, take one or more of the following measures (“Measures”): deny you the right to a test administration, decline to score your test, cancel your scores, ban you from taking future College Board assessments (including, without limitation, the SAT, CLEP Exam or any future AP exams), and/or share information with others as set forth in section 3(f) below. CAUTION! THE CONSEQUENCES OF CHEATING ON THE AP EXAM ARE SEVERE. ALL INSTITUTIONS TO WHICH YOU SEND AP SCORES MAY BE NOTIFIED OF YOUR MISCONDUCT. b. Invalid Scores. We may cancel your scores and/or take any of the other Measures described above if after following the procedures set forth in this section, we determine, in our sole discretion, that there is substantial evidence that your scores are invalid (“Invalid Scores”). Examples of evidence of Invalid Scores include, without limitation, discrepant handwriting, unusual answer patterns, similar essays, or other evidence that indicates these Terms and Conditions may have been violated. Before canceling your scores under this Invalid Scores section, we will notify you in writing (via email if an email address is available) and provide you with an opportunity to submit written information to us to help resolve our inquiry. If you opt for a further review by a College Board review panel, and it confirms, in its sole discretion, that your scores are invalid, we will offer you 2 options: voluntary score cancellation or arbitration as set forth in Section 8 below. This process is referred to as the “Score Validity Process”. The arbitration option is available only for tests administered in the United States and U.S. Territories. c. Misconduct. Notwithstanding section 3(b) above, if we determine, in our sole discretion, that there is overwhelming evidence that you violated these Terms and Conditions (“Misconduct”), the Score Validity Process will not apply, and we may cancel your scores and/or take any of the Measures described above. Examples of Misconduct might include having someone else assist you during the exam, having someone else take the test for you, giving assistance to another test taker during the exam, or plagiarizing, which includes submitting an exam with any material other than the exclusive product of your own work, or that includes any text, content, graphics, pictures, or other content from a third-party source. Misconduct may be established in various ways, including, without limitation, by evidence discovered after the administration. d. Testing Irregularities. We may cancel your scores if we determine, in our sole discretion, that any testing irregularity occurred (collectively, “Testing Irregularities”). Examples of Testing Irregularities include problems, irregular circumstances, or events associated with the administration of a test, and may affect one test taker or groups of test takers. Such problems include, without limitation, administrative errors (e.g., using accommodations not approved by College Board or defective equipment), network outages, system errors, evidence of possible preknowledge of secure test content, and disruptions of test administrations caused by events such as natural disasters, epidemics, wars, riots, civil disturbances, or other emergencies. When Testing Irregularities occur, we may cancel an entire administration or individual registrations, decline to score all or part of the test, or cancel scores. We may do this regardless of whether or not you caused the Testing Irregularities, benefited from them, or violated these Terms and Conditions. We may, in our sole discretion, give you a refund. This is the sole remedy that may be available to you as a result of Testing Irregularities. e. Test Taker Reporting Misconduct or Suspicious Behavior. You may confidentially report any suspected violation of these Terms and Conditions, or any suspicion concerning the security of an AP Exam administration, by immediately emailing the AP Hotline at collegeboardtestsecurity@collegeboard.org. f. College Board Sharing Information with Third Parties. We may share the results of test security investigations (including, without limitation, those relating to Misconduct described above, and other disciplinary-related information), with third parties, including with your teacher, school, any score recipient, college, higher education institution or agency, scholarship organization, admissions office, potential score recipient, government agency in the United States or abroad, parents, legal guardians, or law enforcement. College Board may also share such information with third parties that have a legitimate reason for knowing the information or who may be able to assist College Board in its investigation or who may be conducting their own investigation. College Board may respond to inquiries from any institution to which you submitted a score. If you publicize any review, investigation, or decision of College Board, College Board may make any and all details of such matter public. Shamelessly copied from https://apstudents.collegeboard.org/ap-2020-2021/about-2021-ap-exams/terms-conditions And take your flag: bcactf{bca_is_taking_APs_in_june_aaaaaaaa_wish_past_me_luck}
bcactf{bca_is_taking_APs_in_june_aaaaaaaa_wish_past_me_luck}
Digitally Encrypted 1 (rev 75)
https://github.com/hneemann/Digitalのツールで、circuit_1.digを開く。
平文がkeyとXORをして暗号化しているだけなので、XORで戻す。
from Crypto.Util.number import * ciph = [0xB6A46EE913B33E19, 0xBCA67BD510B43632, 0xA4B56AFE13AC1A1E, 0xBDAA7FE602E4775E, 0xEDF63AB850E67010] key = 0xD4C70F8A67D5456D flag = '' for i in range(len(ciph)): plain = ciph[i] ^ key flag += long_to_bytes(plain) print flag
bcactf{that_was_pretty_simple1239152735}
Storytime: The Opening Gambit (rev 75)
Ghidraでデコンパイルする。
undefined8 main(void) { long lVar1; char **ppcVar2; long in_FS_OFFSET; int local_238; char *local_228 [4]; char *local_208; char *local_200; char *local_1f8; char *local_1f0; char *local_1e8; undefined *local_1e0; char *local_1d8; char *local_1d0; long local_10; local_10 = *(long *)(in_FS_OFFSET + 0x28); lVar1 = 0x43; ppcVar2 = local_228; while (lVar1 != 0) { lVar1 = lVar1 + -1; *ppcVar2 = (char *)0x0; ppcVar2 = ppcVar2 + 1; } local_228[0] = "Baa, baa, black sheep,"; local_228[1] = "Have you any wool?"; local_228[2] = "Yes sir, yes sir,"; local_228[3] = "Three bags full."; local_208 = "One for the master,"; local_200 = "One for the dame,"; local_1f8 = "And one for the little boy"; local_1f0 = "Who lives down the lane\n"; local_1e8 = "bcactf{w0ol_m4k3s_str1ng_ziv4mk3ca91b}"; local_1e0 = &DAT_001020d6; local_1d8 = "Did you know? I almost used \"Little Miss Muffet\" for this problem."; local_1d0 = "Spiders make string too, kind of."; local_238 = 0; while (local_238 < 4) { puts(local_228[local_238]); sleepNanos(1,500000000); local_238 = local_238 + 1; } if (local_10 != *(long *)(in_FS_OFFSET + 0x28)) { /* WARNING: Subroutine does not return */ __stack_chk_fail(); } return 0; }
実行するだけでは出力されないバッファに、フラグが設定されていた。
bcactf{w0ol_m4k3s_str1ng_ziv4mk3ca91b}
A Fun Game (rev 100)
$ file Game.exe Game.exe: PE32 executable (console) Intel 80386 Mono/.Net assembly, for MS Windows
dnSpyでデコンパイルする。
namespace AFunGame { // Token: 0x02000002 RID: 2 internal class Game : if (Game.points > Game.pointsNeeded) { char[] array = "}sr3tte1_0001_epYt_yl1aUtca_tNd1d_U0y_yl1uf3p0h{ftcacb".ToCharArray(); Array.Reverse<char>(array); Console.WriteLine("Here's your flag: " + new string(array)); } else { Console.WriteLine("Well, better luck next time!"); } : } }
>>> "}sr3tte1_0001_epYt_yl1aUtca_tNd1d_U0y_yl1uf3p0h{ftcacb"[::-1] 'bcactf{h0p3fu1ly_y0U_d1dNt_actUa1ly_tYpe_1000_1ett3rs}'
bcactf{h0p3fu1ly_y0U_d1dNt_actUa1ly_tYpe_1000_1ett3rs}
Home Automation (webex 75)
ログインすると、クッキーのuserに"vampire"が設定されていることがわかる。Lightsをクリックすると、以下のメッセージが表示される。
You must be admin to turn off the lights. Currently you are "vampire".
クッキーのuserを"admin"にして、Lightsをクリックすると、フラグが表示された。
bcactf{c00k13s_s3rved_fr3sh_fr0m_th3_smart_0ven_cD7EE09kQ}
Movie-Login-1 (webex 100)
SQLインジェクション。Usernameに以下を設定し、Submitすると、フラグが表示された。
' or 1=1 -- -
bcactf{s0_y0u_f04nd_th3_fl13r?}
Wasm Protected Site 1 (webex 100)
http://web.bcactf.com:49157/main.jsを見る。
const fetchWASMCode = () => { return new Promise((res, rej) => { const req = new XMLHttpRequest(); req.onload = function () { res(req.response); } req.onerror = (err) => { console.warn('If you\'re seeing this logged, something broke'); rej(err) } req.open("GET", "./code.wasm"); req.responseType = "arraybuffer"; req.send(); }); };
ここでオープンしているhttp://web.bcactf.com:49157/code.wasmをダウンロードする。このファイルにフラグが含まれていた。
bcactf{w4sm-m4g1c-xRz5}
Agent Gerald (webex 125)
UserAgentに"Gerald"を指定して、アクセスする。
$ curl -A "Gerald" http://web.bcactf.com:49156/ <!DOCTYPE html> <html> <head> </head> <body> <h1>Welcome to the Stegosaurus Intelligence-6 Homepage</h1> <h2>Are you Agent Gerald?</h2> <img src="gerald.PNG" alt="agent gerald" style="width: 50%"></img> <h4> Welcome, Agent Gerald! Your flag is: bcactf{y0u_h@ck3d_5tegos@urus_1nt3lligence} </h4> </body> </html>
bcactf{y0u_h@ck3d_5tegos@urus_1nt3lligence}
Movie-Login-2 (webex 150)
SQLインジェクション。ただし"1", "0", "/", "="が使えない。Usernameに以下を設定し、Submitすると、フラグが表示された。
' or 2<3 -- -
bcactf{h0w_d1d_y0u_g3t_h3r3_th1s_t1m3?!?}
Movie-Login-3 (webex 200)
SQLインジェクション。ただし使えないものが増える。使えないものは以下の通り。
"and", "1", "0", "true", "false", "/", "*", "=", "xor", "null", "is", "<", ">"
Usernameに以下を設定し、Submitすると、フラグが表示された。
' or 'A' IN ('A', 'B') -- -
bcactf{gu3ss_th3r3s_n0_st0pp1ng_y0u!}
Infinite Zip (foren 75)
ひたすらzip解凍していく。最後にflag.pngが展開される。
import zipfile for i in range(999, -1, -1): fname = '%d.zip' % i with zipfile.ZipFile(fname) as f: f.extractall()
flag.pngのEXIFを見てみると、Creatorにフラグが設定されていた。
$ exiftool flag.png ExifTool Version Number : 10.80 File Name : flag.png Directory : . File Size : 56 kB File Modification Date/Time : 2021:06:11 15:33:42+09:00 File Access Date/Time : 2021:06:11 20:37:28+09:00 File Inode Change Date/Time : 2021:06:11 15:33:42+09:00 File Permissions : rwxrwxrwx File Type : PNG File Type Extension : png MIME Type : image/png Image Width : 1800 Image Height : 1200 Bit Depth : 8 Color Type : RGB with Alpha Compression : Deflate/Inflate Filter : Adaptive Interlace : Noninterlaced SRGB Rendering : Perceptual XMP Toolkit : Image::ExifTool 11.88 Creator : bcactf{z1p_1n51d3_4_z1p_4_3v3r} Image Size : 1800x1200 Megapixels : 2.2
bcactf{z1p_1n51d3_4_z1p_4_3v3r}
Zstegosaurus (foren 75)
$ zsteg zstegosaurus.png b1,r,lsb,xy .. text: "h15_n@m3_i5nt_g3rard" b4,rgb,msb,xy .. text: ["w" repeated 10 times]
bcactf{h15_n@m3_i5nt_g3rard}
Gerald's New Job (foren 100)
$ binwalk gerald.pdf DECIMAL HEXADECIMAL DESCRIPTION -------------------------------------------------------------------------------- 0 0x0 PDF document, version: "1.3" 66 0x42 Zip archive data, at least v2.0 to extract, uncompressed size: 441011, name: GeraldFlag.png 390777 0x5F679 Zip archive data, at least v2.0 to extract, uncompressed size: 367, name: __MACOSX/._GeraldFlag.png 391327 0x5F89F End of Zip archive 392072 0x5FB88 Zlib compressed data, default compression 722826 0xB078A Zlib compressed data, default compression 723219 0xB0913 End of Zip archive $ binwalk -e gerald.pdf DECIMAL HEXADECIMAL DESCRIPTION -------------------------------------------------------------------------------- 0 0x0 PDF document, version: "1.3" 66 0x42 Zip archive data, at least v2.0 to extract, uncompressed size: 441011, name: GeraldFlag.png 390777 0x5F679 Zip archive data, at least v2.0 to extract, uncompressed size: 367, name: __MACOSX/._GeraldFlag.png 391327 0x5F89F End of Zip archive 392072 0x5FB88 Zlib compressed data, default compression 722826 0xB078A Zlib compressed data, default compression 723219 0xB0913 End of Zip archive
GeraldFlag.pngが抽出でき、その画像にフラグが書いてあった。
bcactf{g3ra1d_15_a_ma5ter_p01yg1ot_0769348}
More than Meets the Eye (foren 100)
2種類のゼロ幅スペースがたくさん入っている。0, 1に置き換えデコードする。さらにデコードする際は8bitごとに末尾が0になっているので、逆順にしてデコードする。
with open('zwsp.txt', 'r') as f: data = f.read() data = data[0x16:-2] bin_flag = '' for i in range(0, len(data), 3): if data[i:i+3] == '\xe2\x80\x8b': bin_flag += '0' elif data[i:i+3] == '\xe2\x80\x8c': bin_flag += '1' else: print 'ng' flag = '' for i in range(0, len(bin_flag), 8): flag += chr(int(bin_flag[i:i+8][::-1], 2)) print flag
bcactf{z3r0_w1dth_jungl3_j82axH4}
Secure Zip (foren 100)
zipが添付されているが、パスワードがかかっているので、クラックする。
$ fcrackzip -u -D -p dict/rockyou.txt chall.zip PASSWORD FOUND!!!!: pw == dogedoge $ unzip -P dogedoge chall.zip Archive: chall.zip extracting: flag.txt extracting: homework.txt $ cat flag.txt bcactf{cr4ck1ng_z1p_p455w0rd5_15_fun_a12ca37bdacef7}
bcactf{cr4ck1ng_z1p_p455w0rd5_15_fun_a12ca37bdacef7}
Easy RSA (crypto 50)
p, qがわかっているので、そのまま復号する。
from Crypto.Util.number import * p = 251867251891350186672194341006245222227 q = 31930326592276723738691137862727489059 n = 8042203610790038807880567941309789150434698028856480378667442108515166114393 e = 65537 ct = 5247423021825776603604142516096226410262448370078349840555269847582407192135 phi = (p - 1) * (q - 1) d = inverse(e, phi) m = pow(ct, d, n) flag = long_to_bytes(m) print flag
bcactf{RSA_IS_EASY_AFTER_ALL}
(crypto 75)
四角に×のような記号が並んでいるが、文字によって微妙に異なるコードになっている。ASCII文字に置換してみる。
"ABCBD EFAAG EHCB IFJ JK" HL MNB OBPJM LHAEQB DBRFDOBO PI BAEQHLN LHAEBD GAO LFAESDHMBD DHRT GLMQBI, DBQBGLBO FA 27 UJQI 1987. HM SGL SDHMMBA GAO KDFOJRBO PI LMFRT GHMTBA SGMBDVGA, GAO SGL DBQBGLBO GL MNB WHDLM LHAEQB WDFV GLMQBI'L OBPJM GQPJV, SNBABCBD IFJ ABBO LFVBPFOI (1987). MNB LFAE SGL G SFDQOSHOB AJVPBD-FAB NHM, HAHMHGQQI HA MNB JAHMBO THAEOFV HA 1987, SNBDB HM LMGIBO GM MNB MFK FW MNB RNGDM WFD WHCB SBBTL GAO SGL MNB PBLM-LBQQHAE LHAEQB FW MNGM IBGD. HM BCBAMJGQQI MFKKBO MNB RNGDML HA 25 RFJAMDHBL, HARQJOHAE MNB JAHMBO LMGMBL GAO SBLM EBDVGAI.[6] MNB LFAE SFA PBLM PDHMHLN LHAEQB GM MNB 1988 PDHM GSGDOL. MNB VJLHR CHOBF WFD MNB LFAE NGL PBRFVB MNB PGLHL WFD MNB "DHRTDFQQHAE" HAMBDABM VBVB. HA 2008, GLMQBI SFA MNB VMC BJDFKB VJLHR GSGDO WFD PBLM GRM BCBD SHMN MNB LFAE, GL G DBLJQM FW RFQQBRMHCB CFMHAE WDFV MNFJLGAOL FW KBFKQB FA MNB HAMBDABM, OJB MF MNB KFKJQGD KNBAFVBAFA FW DHRTDFQQHAE.[7] MNB LFAE HL RFALHOBDBO GLMQBI'L LHEAGMJDB LFAE GAO HM HL FWMBA KQGIBO GM MNB BAO FW NHL QHCB RFARBDML. HA 2019, GLMQBI DBRFDOBO GAO DBQBGLBO G 'KHGAFWFDMB' CBDLHFA FW MNB LFAE WFD NHL GQPJV MNB PBLM FW VB, SNHRN WBGMJDBL G ABS KHGAF GDDGAEBVBAM.[8] LNGVBQBLLQI RFKHBO WDFV [SHTHKBOHG'L GDMHRQB FA MNB LJPUBRM](NMMKL://BA.SHTHKBOHG.FDE/SHTH/ABCBD_EFAAG_EHCB_IFJ_JK) PRGRMW{LFDDI_SB_DGA_FJM_FW_DJABL_LUDNSPE}
quipqiupで復号する。
"NEVER GONNA GIVE YOU UP" IS THE DEBUT SINGLE RECORDED BY ENGLISH SINGER AND SONGWRITER RICK ASTLEY, RELEASED ON 27 JULY 1987. IT WAS WRITTEN AND PRODUCED BY STOCK AITKEN WATERMAN, AND WAS RELEASED AS THE FIRST SINGLE FROM ASTLEY'S DEBUT ALBUM, WHENEVER YOU NEED SOMEBODY (1987). THE SONG WAS A WORLDWIDE NUMBER-ONE HIT, INITIALLY IN THE UNITED KINGDOM IN 1987, WHERE IT STAYED AT THE TOP OF THE CHART FOR FIVE WEEKS AND WAS THE BEST-SELLING SINGLE OF THAT YEAR. IT EVENTUALLY TOPPED THE CHARTS IN 25 COUNTRIES, INCLUDING THE UNITED STATES AND WEST GERMANY.[6] THE SONG WON BEST BRITISH SINGLE AT THE 1988 BRIT AWARDS. THE MUSIC VIDEO FOR THE SONG HAS BECOME THE BASIS FOR THE "RICKROLLING" INTERNET MEME. IN 2008, ASTLEY WON THE MTV EUROPE MUSIC AWARD FOR BEST ACT EVER WITH THE SONG, AS A RESULT OF COLLECTIVE VOTING FROM THOUSANDS OF PEOPLE ON THE INTERNET, DUE TO THE POPULAR PHENOMENON OF RICKROLLING.[7] THE SONG IS CONSIDERED ASTLEY'S SIGNATURE SONG AND IT IS OFTEN PLAYED AT THE END OF HIS LIVE CONCERTS. IN 2019, ASTLEY RECORDED AND RELEASED A 'PIANOFORTE' VERSION OF THE SONG FOR HIS ALBUM THE BEST OF ME, WHICH FEATURES A NEW PIANO ARRANGEMENT.[8] SHAMELESSLY COPIED FROM [WIKIPEDIA'S ARTICLE ON THE SUBJECT](HTTPS://EN.WIKIPEDIA.ORG/WIKI/NEVER_GONNA_GIVE_YOU_UP) BCACTF{SORRY_WE_RAN_OUT_OF_RUNES_SJRHWBG}
文章末にフラグが書いてあった。小文字にすると通った。
bcactf{sorry_we_ran_out_of_runes_sjrhwbg}
Cipher Mishap (crypto 75)
数値は104~131, 137。8進数としてデコードする。またYやNは大文字のフラグとして変換する。
import string def caesar(s, key): d = '' for c in s: code = ord(c) if c in string.uppercase: code = code - key if code < ord('A'): code += 26 elif c in string.lowercase: code = code - key if code < ord('a'): code += 26 d += chr(code) return d with open('text.txt', 'r') as f: enc = f.read().rstrip().split(', ') dec = '' for c in enc: code = c.split('-')[0] char = chr(int(code, 8)) if char in string.uppercase: if c.split('-')[1] == 'N': char = char.lower() dec += char flag = caesar(dec, 3) flag = 'bcactf{%s}' % flag print flag
bcactf{Should_iT_Have_BeeN_Vigenere_Instead}
Sailing Thru Decryption (crypto 75)
国際信号旗。https://ja.wikipedia.org/wiki/国際信号旗を参考に復号する。
011001110110101001110011011011010111011101110011 011110110011000101111000010111110110111100110001 011010110101111101111000001101000111000001110010 010111110110110000110011011110010011010001101010 011011100011111101111101 THEKEYISFHSKDN
2進数をデコードする。
enc = ''' 011001110110101001110011011011010111011101110011 011110110011000101111000010111110110111100110001 011010110101111101111000001101000111000001110010 010111110110110000110011011110010011010001101010 011011100011111101111101 ''' enc = enc.replace('\n', '') msg = '' for i in range(0, len(enc), 8): msg += chr(int(enc[i:i+8], 2)) print msg
実行結果は以下の通り。
gjsmws{1x_o1k_x4pr_l3y4jn?}
Vigenere暗号。FHSKDNをキーにしてhttps://www.dcode.fr/vigenere-cipherで復号する。
bcactf{1s_h1s_n4me_g3r4rd?}
Slightly Harder RSA (crypto75)
factordbでnを素因数分解する。
n = 884666943491340899394244376743 * 1070864180718820651198166458463
あとはそのまま復号する。
from Crypto.Util.number import * n = 947358141650877977744217194496965988823475109838113032726009 e = 65537 ct = 811950322931973288295794871117780672242424164631309902559564 p = 884666943491340899394244376743 q = 1070864180718820651198166458463 phi = (p - 1) * (q - 1) d = inverse(e, phi) m = pow(ct, d, n) flag = long_to_bytes(m) print flag
bcactf{rsa_factoring}
Little e (crypto 100)
eが小さく、Nが大きいため、Low Public Exponent Attackで復号する。
import gmpy from Crypto.Util.number import * e = 3 ct = 1112413624683819960899152482895461211039349964898672381675850025556800617245120168928400758297834676330400246617472191750627367991315450127361583383350639760738254818244740474313061192563860605923503717 m = gmpy.root(ct, e)[0] flag = long_to_bytes(m) print flag
bcactf{R54_N0T_50_S3CUR3_33}
RSAtrix 1 (crypto 125)
暗号化後の行列はcの値が散っているだけなので、その値を復号する。その際p, qがわかっているので、そのまま復号すればよい。
from Crypto.Util.number import * p = 35953130875571662629774552621633952493346190947047 q = 68201352784431955275947627343562102980308744031461 n = p * q e = 3 c = 1879922562037963072325125556499104095457740584077567873217970367519076380025989311243974742849996920 phi = (p - 1) * (q - 1) d = inverse(e, phi) m = pow(c, d, p * q) flag = long_to_bytes(m) print flag
bcactf{just-rsa-with-matrices-9385dax}
FNES 1 (crypto 150)
暗号処理の概要は以下の通り。
tempkey = SHA.new(int(key + int(time.time() / 10)).to_bytes(64, 'big')).digest()[0:16] cipher = ARC4.new(tempkey) ■暗号化 ・平文を入力 ・RC4暗号化→16進数で表示 ■復号 ・暗号文を入力 ・RC4復号 →target_queryと同じ場合、フラグを表示
UNIXTIMEで1の位以外が同じ場合は、同じ鍵になる。適当な平文を暗号化し、そのXORを算出する。一旦接続を切り、再接続し、算出したXORの値をtarget_queryとXORして、復号すればよい。
import socket import binascii from Crypto.Util.strxor import strxor def recvuntil(s, tail): data = '' while True: if tail in data: return data data += s.recv(1) target_query = 'Open sesame... Flag please!' s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(('crypto.bcactf.com', 49153)) data = recvuntil(s, '>>> ') print data + 'E' s.sendall('E\n') try_pt = 'a' * len(target_query) data = recvuntil(s, '>>> ') print data + try_pt s.sendall(try_pt + '\n') data = recvuntil(s, '\n').rstrip() print data data = recvuntil(s, '\n').rstrip() print data try_ct = binascii.unhexlify(data) xor_key = strxor(try_pt, try_ct) data = recvuntil(s, '>>> ') print data + 'Q' s.sendall('Q\n') data = recvuntil(s, '\n').rstrip() print data s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(('crypto.bcactf.com', 49153)) data = recvuntil(s, '>>> ') print data + 'D' s.sendall('D\n') ct = binascii.hexlify(strxor(xor_key, target_query)) data = recvuntil(s, '>>> ') print data + ct s.sendall(ct + '\n') data = recvuntil(s, '\n').rstrip() print data data = recvuntil(s, '\n').rstrip() print data
実行結果は以下の通り。
Welcome to your Friendly Neighborhood Encryption Service (FNES)! If you and a friend both run this service at the same time, you should be able to send messages to each other! Here are the steps: 1. Friends A and B connect to the server at the same time (you have about a five second margin) 2. Friend A encodes a message and sends it to Friend B 3. Friend B decodes the message, encodes their reply, and sends it to Friend A 4. Friend A decodes the reply, rinse and repeat Make sure to not make any mistakes, though, or your keystreams might come out of sync... PS: For security reasons, there are four characters you aren't allowed to encrypt. Sorry! Would you like to encrypt (E), decrypt (D), or quit (Q)? >>> E What would you like to encrypt? >>> aaaaaaaaaaaaaaaaaaaaaaaaaaa Here's your message: 4623ff590e1d0f6610ee85cf640cdf902b8650689c01ece9e1b2b8 Would you like to encrypt (E), decrypt (D), or quit (Q)? >>> Q We hope you enjoyed! Welcome to your Friendly Neighborhood Encryption Service (FNES)! If you and a friend both run this service at the same time, you should be able to send messages to each other! Here are the steps: 1. Friends A and B connect to the server at the same time (you have about a five second margin) 2. Friend A encodes a message and sends it to Friend B 3. Friend B decodes the message, encodes their reply, and sends it to Friend A 4. Friend A decodes the reply, rinse and repeat Make sure to not make any mistakes, though, or your keystreams might come out of sync... PS: For security reasons, there are four characters you aren't allowed to encrypt. Sorry! Would you like to encrypt (E), decrypt (D), or quit (Q)? >>> D What was the message? >>> 6832fb564f0f0b7410e281802b439eb7268656298d0ce8e9f3b6f8 Passphrase accepted. Here's your flag: bcactf{why-would-you-attack-your-FNES????-4x35rcg}
bcactf{why-would-you-attack-your-FNES????-4x35rcg}
RSAtrix 2 (crypto 200)
G = C * P * C^-1 M = m * G
このことから以下のように考えられる。
G^3 = C * P * C^-1 * C * P * C^-1 * C * P * C^-1 = C * P^3 * C^-1 M^e = M^3 = pow(m, 3, n) * G^3 = pow(m, 3, n) * C * P^3 * C^-1 = A C^-1 * A * C = pow(m, 3, n) * P^3
P^3を出力してみる。
[1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1] [0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0]
1となっている箇所が C^-1 * A * C の計算をすると、pow(m, 3, n)になる。p, qがわかっているので、あとはそのまま復号する。
#!/usr/bin/sage from Crypto.Util.number import * p = 94653748632775872562206813156858988240379536044871601072940225022186828970998253 q = 47982815420210848939631963090916124891858755590019708758250635504732488148835047 n = p * q e = 3 N = 23 R = Zmod(n) MS = MatrixSpace(R, N, N) s = PermutationGroupElement('(1,6,8)(2,3,4,5,7)(9,11,13,15,17,19,21,23)(10,12,14,16,18,20,22)') P = MS(s.matrix()) with seed(1): C = MS([randrange(100) for i in range(N*N)]) G = C * P * C^-1 with open('enc.txt', 'r') as f: c_matrix = MS(eval(f.read())) A = C^-1 * c_matrix * C c = int(A[0][0]) phi = (p - 1) * (q - 1) d = inverse(e, phi) m = pow(c, d, n) flag = long_to_bytes(m) print(flag)
bcactf{permutation-conjugation-magic-3x876oeu}
Rainbow Passage (crypto 225)
暗号の処理概要は以下の通り。
※実質"E"のみ選択可 ・パスワードは32バイト ・平文を入力 ・パスワードで平文を暗号化 ・pm: パスワード2バイトごとの2進数の配列 ・16バイトごとにpmで暗号化 ・m: 16バイトのリスト配列 ・c: 0のリスト配列(16要素) ・以下順に計算する。 ・i=0, pm[0], j=0, pm[0]の0番目が1の場合、c[0] ^= m[0] : ・i=0, pm[0], j=15, pm[0]の15番目が1の場合、c[15] ^= m[0] : ・i=15, pm[15], j=0, pm[15]の0番目が1の場合、c[0] ^= m[15] : ・i=15, pm[15], j=15, pm[15]の15番目が1の場合、c[15] ^= m[15] ・cを返す。
c[i]に注目し、pm[0]~pm[15]の0番目の値のブルートフォースで条件を満たすものを探す。pmの値がわかるので、pmの構成から組み立てれば、パスワードになり、それがフラグになる。
import binascii from Crypto.Util.Padding import pad def check(pt_block, ct, flg): x = 0 for i in range(len(flg)): if flg[i] == '1': x ^= ord(pt_block[i]) if x == ord(ct): return True else: return False with open('message.txt', 'r') as f: pt = f.read().rstrip() with open('enc.txt', 'r') as f: ct = f.read().rstrip() pt = pad(pt, 16) ct = binascii.unhexlify(ct) pts = [pt[i:i+16] for i in range(0, len(pt), 16)] cts = [ct[i:i+16] for i in range(0, len(ct), 16)] pm = [''] * 16 for i in range(16): for j in range(2**16): flg = bin(j)[2:].zfill(16) success = True for k in range(len(pts)): res = check(pts[k], cts[k][i], flg) if res == False: success = False break if success: for l in range(16): pm[l] += flg[l] break pwd = '' for i in range(len(pm)): pwd += chr(int(pm[i][:8], 2)) pwd += chr(int(pm[i][8:], 2)) flag = 'bcactf{%s}' % pwd print flag
bcactf{system-of-linear-equations-273de}
FNES 2 (crypto 375)
暗号処理の概要は以下の通り。
tempkey = SHA.new(int(key + int(time.time() / 10)).to_bytes(64, 'big')).digest()[0:16] ■暗号化 ・平文を入力 ・iv生成 ・AES-CBC暗号化→iv + 暗号文を16進数で表示 ■復号 ・暗号文を入力 ・AES-CBC復号 →target_queryと同じ場合、フラグを表示
target_query(T)の長さから2ブロック分の暗号が必要。
平文1ブロック目 ^ IV --(AES暗号)--> 暗号1ブロック目 平文2ブロック目 ^ 暗号1ブロック目 --(AES暗号)--> 暗号2ブロック目
方針は以下の通り。
・適当な文字列(P1)を指定し暗号化する。→暗号文: (C1) →C1[16:]を目的の暗号文の2ブロック目とする。 ・C1[0:16] ^ pad(P1[16:]) = C2 ^ pad(T[16:]) となるようなC2を目的の暗号文の1ブロック目とする。 ・上記で適当なIV(IV0)で復号する。 ・復号したデータ部分のIVと平文1ブロック目とのXORが T[:16]と目的のIVとのXORと同じになるIVを算出する。 ・目的のIVと暗号文を指定する。
import socket import binascii from Crypto.Util.Padding import pad from Crypto.Util.strxor import strxor def recvuntil(s, tail): data = '' while True: if tail in data: return data data += s.recv(1) target_query = 'Open sesame... Flag please!' s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(('crypto.bcactf.com', 49154)) data = recvuntil(s, '>>> ') print data + 'E' s.sendall('E\n') try_pt = 'a' * len(target_query) data = recvuntil(s, '>>> ') print data + try_pt s.sendall(try_pt + '\n') data = recvuntil(s, '\n').rstrip() print data data = recvuntil(s, '\n').rstrip() print data try_ct = binascii.unhexlify(data) data = recvuntil(s, '>>> ') print data + 'D' s.sendall('D\n') ct1 = try_ct[32:] xor1 = strxor(try_ct[16:32], pad(try_pt[16:], 16)) ct0 = strxor(xor1, pad(target_query[16:], 16)) try_iv = 'a' * 16 try_ct = binascii.hexlify(try_iv + ct0 + ct1) data = recvuntil(s, '>>> ') print data + try_ct s.sendall(try_ct + '\n') data = recvuntil(s, '\n').rstrip() print data data = recvuntil(s, '\n').rstrip() print data try_pt = eval('b\'' + data.replace('\'', '\\\'') + '\'') data = recvuntil(s, '>>> ') print data + 'D' s.sendall('D\n') xor0 = strxor(try_iv, try_pt[:16]) iv = strxor(xor0, target_query[:16]) ct = binascii.hexlify(iv + ct0 + ct1) data = recvuntil(s, '>>> ') print data + ct s.sendall(ct + '\n') for _ in range(4): data = recvuntil(s, '\n').rstrip() print data
実行結果は以下の通り。
Welcome to your new and improved FNES... FNES 2! As before, if you and a friend both run this service at the same time, you should be able to send messages to each other! Here are the steps: 1. Friends A and B connect to the server at the same time (you have about a five second margin) 2. Friend A encodes a message and sends it to Friend B 3. Friend B decodes the message, encodes their reply, and sends it to Friend A 4. Friend A decodes the reply, rinse and repeat PS: For security reasons, there are still some characters you aren't allowed to encrypt. Sorry! Would you like to encrypt (E), decrypt (D), or quit (Q)? >>> E What would you like to encrypt? >>> aaaaaaaaaaaaaaaaaaaaaaaaaaa Here's your message: 686024288cff6dd4617db0f8e9bb7a6969a2d81d8410bcb30040440b96c05c145c4939938ca3b981000633c9906bd300 Would you like to encrypt (E), decrypt (D), or quit (Q)? >>> D What was the message? >>> 6161616161616161616161616161616164a2de5c951db8b31244040b96c05c145c4939938ca3b981000633c9906bd300 Here's the decoded message: ~"\xae\xdc\r\xf2\x83\xc0\xf3,m\x9f\x88)OHlag please! Would you like to encrypt (E), decrypt (D), or quit (Q)? >>> D What was the message? >>> 5033aad34ce087d2f32069d0c7660e6f64a2de5c951db8b31244040b96c05c145c4939938ca3b981000633c9906bd300 Passphrase accepted. Here's your flag: bcactf{high-priestess-of-the-temple-of-apollo-49b7x}
bcactf{high-priestess-of-the-temple-of-apollo-49b7x}