TAMUctf 19 Writeup

この大会は2019/2/23 9:00(JST)~2019/3/4 9:00(JST)に開催されました。

Howdy! (Misc)



Who am I? (Misc)


$ dig tamuctf.com

; <<>> DiG 9.10.3-P4-Ubuntu <<>> tamuctf.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 49250
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

; EDNS: version: 0, flags:; MBZ: 0005 , udp: 512
;tamuctf.com.			IN	A

tamuctf.com.		5	IN	A

;; Query time: 151 msec
;; WHEN: Sat Feb 23 09:31:59 JST 2019
;; MSG SIZE  rcvd: 56

Who do I trust? (Misc)


Let's Encrypt Authority X3

0_Network_Enumeration (ReadingRainbow)


-.- (Crypto)


morse = {
    'di-dah': 'A',
    'dah-di-di-dit': 'B',
    'dah-di-dah-dit': 'C',
    'dah-di-dit': 'D',
    'dit': 'E',
    'di-di-dah-dit': 'F',
    'dah-dah-dit': 'G',
    'di-di-di-dit': 'H',
    'di-dit': 'I',
    'di-dah-dah-dah': 'J',
    'dah-di-dah': 'K',
    'di-dah-di-dit': 'L',
    'dah-dah': 'M',
    'dah-dit': 'N',
    'dah-dah-dah': 'O',
    'di-dah-dah-dit': 'P',
    'dah-dah-di-dah': 'Q',
    'di-dah-dit': 'R',
    'di-di-dit': 'S',
    'dah': 'T',
    'di-di-dah': 'U',
    'di-di-di-dah': 'V',
    'di-dah-dah': 'W',
    'dah-di-dah-dah': 'Y',
    'dah-dah-di-dit': 'Z',
    'di-dah-dah-dah-dah': '1',
    'di-di-dah-dah-dah': '2',
    'di-di-di-dah-dah': '3',
    'di-di-di-di-dah': '4',
    'di-di-di-di-dit': '5',
    'dah-di-di-di-dit': '6',
    'dah-dah-di-di-dit': '7',
    'dah-dah-dah-di-dit': '8',
    'dah-dah-dah-dah-dit': '9',
    'dah-dah-dah-dah-dah': '0'

with open('flag.txt', 'r') as f:
    data = f.read()

codes = data.split(' ')
dec = ''
for code in codes:
    dec += morse[code]
print dec.lower()

msg =  dec[2:].decode('hex')
print msg



Wp*lXtGQ8e8qnmMYU*svFHkjIt*RQ&JpZvjm!%%KDkfp#^N9fk4dU4lB3rToT0PZQmCQEKYB4ZMv*!Fk8l%bjqlPMfIGma%%FzG gigem{C1icK_cl1CK-y0u_h4v3_m4I1} uv4vzKZt4yomiDShLm8QEFnUtwJ@NuOYfX&8u@Gn!1%Tqv0VcRzV!j!vuup8BjdNIqE5w#$%V4UZOYZ2z7T25t7&xL@WO7410QI



RSAaaay (Crypto)


2531257 = 509 * 4973


from Crypto.Util.number import inverse

def n_to_str(n):
    str_n = str(n)
    s = ''
    tmp = ''
    for i in range(len(str_n)):
        tmp += str_n[i]
        if int(tmp) > 31 and int(tmp) < 127:
            s += chr(int(tmp))
            tmp = ''
    return s

n = 2531257
p = 509
q = 4973
e = 43
list_c = map(int, '906851 991083 1780304 2380434 438490 356019 921472 822283 817856 556932 2102538 2501908 2211404 991083 1562919 38268'.split(' '))

phi = (p - 1) * (q - 1)
d = inverse(e, phi)

flag = ''
for c in list_c:
    m = pow(c, d, n)
    flag += n_to_str(m)

print flag

Mike's Marvelous Mystery Curves (Crypto)

通信パケットのNo.4と11に-----BEGIN CERTIFICATE-----で始まるデータがある。エクスポートして、中身を見ようとしたが、見れない。BASE64デコードしてみると、テキストで以下のような内容だった。

        Version: 3 (0x2)
        Serial Number:
    Signature Algorithm: base64
        Issuer: C = US, ST = Texas, L = College Station, O = Texas A&M University, OU = tamuCTF, CN = Alice, emailAddress = alice@tamuctf.edu
            Not Before: Oct  9 13:08:12 2018 GMT
            Not After : Nov  8 13:08:12 2018 GMT
        Subject: C = US, ST = Texas, L = College Station, O = Texas A&M University, OU = tamuCTF, CN = Alice, emailAddress = alice@tamuctf.edu
        Subject Public Key Info:
            Public Key Algorithm: id-ecPublicKey
                ASN1 OID: badPrime96v4
                CURVE: JustNo
                    Field Type: prime-field
        X509v3 extensions:
            X509v3 Subject Key Identifier: 
            X509v3 Authority Key Identifier: 

            X509v3 Basic Constraints: critical
    Signature Algorithm: ecdsa-with-SHA256

        Version: 3 (0x2)
        Serial Number:
    Signature Algorithm: ecdsa-with-SHA256
        Issuer: C = US, ST = Texas, L = College Station, O = Texas A&M University, OU = tamuCTF, CN = Bob, emailAddress = bob@tamuctf.edu
            Not Before: Oct  9 13:15:35 2018 GMT
            Not After : Nov  8 13:15:35 2018 GMT
        Subject: C = US, ST = Texas, L = College Station, O = Texas A&M University, OU = tamuCTF, CN = Bob, emailAddress = bob@tamuctf.edu
        Subject Public Key Info:
            Public Key Algorithm: id-ecPublicKey
                ASN1 OID: badPrime96v4
                CURVE: JustNo
                    Field Type: prime-field
        X509v3 extensions:
            X509v3 Subject Key Identifier: 
            X509v3 Authority Key Identifier: 

            X509v3 Basic Constraints: critical
    Signature Algorithm: ecdsa-with-SHA256


# solve.sage
p = 412220184797
A = 10717230661382162362098424417014722231813
B = 22043581253918959176184702399480186312
G = (56797798272, 349018778637)

F = FiniteField(p)
E = EllipticCurve(F, [A,B])
G = E.point(G)

pub_A = (61801292647, 228288385004)
pub_A = E.point(pub_A)
pub_B = (196393473219, 35161195210)
pub_B = E.point(pub_B)

factors, exponents = zip(*factor(E.order()))
primes = [factors[i] ^ exponents[i] for i in range(len(factors))]
dlogs = []
for fac in primes:
    t = int(G.order()) / int(fac)
    dlog = discrete_log(t*pub_A, t*G, operation='+')
    dlogs += [dlog]

n_A = crt(dlogs,primes)

key = pub_B * n_A
key = str(key[0]) + str(key[1])
print key



あとはTCP Streamから暗号データを抽出して、復号するだけ。AES-CBCなのでIVが必要だが、よく暗号データの先頭16バイトがIVになっているので、それを使う。

from Crypto.Cipher import AES

with open('msg.enc', 'rb') as f:
    data = f.read()

iv = data[:16]
enc = data[16:]

key = '130222573707242246159397'
aes = AES.new(key, AES.MODE_CBC, iv)

dec = aes.decrypt(enc)
print dec


 study was a total mess, like the results  of  an
explosion  in  a  public  library.  The  old  man frowned as they
stepped in.

"Terribly unfortunate," he said, "a diode  blew  in  one  of  the
life-support  computers.  When  we  tried  to revive our cleaning
staff we discovered they'd been dead for nearly  thirty  thousand
years.  Who's  going to clear away the bodies, that's what I want
to know. Look why don't you sit yourself down over there and  let
me plug you in?"

He gestured Arthur towards a chair which looked as if it had been
made out of the rib cage of a stegosaurus.

"It was made out of the rib cage of a stegosaurus," explained the
old  man as he pottered about fishing bits of wire out from under
tottering piles of paper  and  drawing  instruments.  "Here,"  he
said,  "hold  these," and passed a couple of stripped wire end to

The instant he took hold of them a  bird  flew  straight  through

He was suspended in mid-air and  totally  invisible  to  himself.
Beneath him was a pretty treelined city square, and all around it
as far as the eye could see were white concrete buildings of airy
spacious  design  but  somewhat  the  worse  for wear - many were
cracked and stained with rain. Today however the sun was shining,
a  fresh  breeze  danced lightly through the trees, and the odd
sensation that all the buildings were quietly humming was
probably caused by the fact that the square and all the streets
around it were thronged with cheerful excited people. Somewhere a
band  was playing, brightly coloured flags were fluttering in the
breeze and the spirit of carnival was in the air.

Arthur felt extraordinarily lonely stuck up in the air  above  it
all without so much as a body to his name, but before he had time
to reflect on this a voice rang out across the square and  called
for everyone's attention.

A man standing on a brightly dressed  dais  before  the  building
which  clearly dominated the square was addressing the crowd over
a Tannoy.

"O people waiting in the Shadow of Deep Thought!" he  cried  out.
"Honoured Descendants of Vroomfondel and Majikthise, the Greatest
and Most Truly Interesting Pundits the Universe  has  ever  known
... The Time of Waiting is over!"

Wild cheers broke out amongst the  crowd.  Flags,  streamers  and
wolf whistles sailed through the air. The narrower streets looked
rather like centipedes rolled over on their backs and frantically
waving their legs in the air.

"Seven and a half million years our  race  has  waited  for  this
Great  and  Hopefully  Enlightening Day!" cried the cheer leader.
"The Day of the Answer!"

Hurrahs burst from the ecstatic crowd.

"Never again," cried the man, "never again will we wake up in the
morning  and  think Who am I? What is my purpose in life? Does it
really, cosmically speaking, matter if I don't get up and  go  to
work?  For today we will finally learn once and for all the plain
and simple answer to all these nagging little problems  of  Life,
the Universe and Everything!"

As the crowd erupted once again,  Arthur  found  himself  gliding
through the air and down towards one of the large stately windows
on the first floor of the building behind the dais from which the
speaker was addressing the crowd.

He experienced a moment's panic as  he  sailed  straight  through
towards  the  window,  which  passed when a second or so later he
found  he  had  gone  right  through  the  solid  glass   without
apparently touching it.

No one in the room remarked on his  peculiar  arrival,  which  is
hardly  surprising  as  he wasn't there. He began to realize that
the whole experience  was  merely  a  recorded  projection  which
knocked six-track seventy-millimetre into a cocked hat.

The room was much as Slartibartfast had described  it.  In  seven
and  a  half  million  years  it  had  been well looked after and
cleaned regularly every century or so. The ultramahagony desk was
worn  at  the edges, the carpet a little faded now, but the large
computer terminal sat in sparkling glory on  the  desk's  leather
top, as bright as if it had been constructed yesterday.
Two severely dressed men sat respectfully before the terminal and

"The time is nearly upon us," said one, and Arthur was  surprised
to  see a word suddenly materialize in thin air just by the man's
neck. The word was Loonquawl, and it flashed a  couple  of  times
and  the  disappeared again. Before Arthur was able to assimilate
this the other man spoke and the word  Phouchg  appeared  by  his

"Seventy-five thousand generations ago, our  ancestors  set  this
program in motion," the second man said, "and in all that time we
will be the first to hear the computer speak."

"An awesome prospect, Phouchg," agreed the first man, and  Arthur
suddenly   realized   that  he  was  watching  a  recording  with

"We are the ones who will hear," said Phouchg, "the answer to the
great question of Life ...!"

"The Universe ...!" said Loonquawl.

"And Everything ...!"

"Shhh," said Loonquawl with  a  slight  gesture,  "I  think  Deep
Thought is preparing to speak!"

There was a moment's expectant pause whilst panels slowly came to
life  on  the  front  of  the  console. Lights flashed on and off
experimentally and settled down into a  businesslike  pattern.  A
soft low hum came from the communication channel.

"Good morning," said Deep Thought at last.

"Er ... Good morning, O Deep Thought," said Loonquawl  nervously,
"do you have ... er, that is ..."

"An answer for you?" interrupted Deep Thought majestically. "Yes.
I have."

The two men shivered with expectancy. Their waiting had not  been
in vain.

"There really is one?" breathed Phouchg.

"There really is one," confirmed Deep Thought.

"To Everything? To the great Question of Life, the  Universe  and


Both of the men had been trained for this moment, their lives had
been  a  preparation  for  it, they had been selected at birth as
those who would witness  the  answer,  but  even  so  they  found
themselves gasping and squirming like excited children.

"And you're ready to give it to us?" urged Loonquawl.
"I am."


"Now," said Deep Thought.

They both licked their dry lips.

"Though I don't think," added Deep Thought, "that you're going to
like it."

"Doesn't matter!" said Phouchg. "We must know it! Now!"

"Now?" inquired Deep Thought.

"Yes! Now ..."

"Alright," said the computer and settled into silence again.  The
two men fidgeted. The tension was unbearable.

"You're really not going to like it," observed Deep Thought.

"Tell us!"

"Alright," said Deep Thought. "The Answer to the  Great  Question

"Yes ...!"

"Of Life, the Universe and Everything ..." said Deep Thought.

"Yes ...!"

"Is ..." said Deep Thought, and paused.

"Yes ...!"

"Is ..."

"Yes ...!!!...?"

gigem{Forty-two_said_Deep_Thought}, with infinite majesty and calm.

It was a long time before anyone spoke.

Out of the corner of his eye Phouchg could see the sea  of  tense
expectant faces down in the square outside.

"We're going to get lynched aren't we?" he whispered.

"It was a tough assignment," said Deep Thought mildly.

"Forty-two!" yelled Loonquawl. "Is that all you've  got  to  show
for seven and a half million years' work?"
"I checked it very thoroughly,"  said  the  computer,  "and  that
quite  definitely is the answer. I think the problem, to be quite
honest with you, is that you've never  actually  known  what  the
question is."

"But it was the Great Question! The Ultimate  Question  of  Life,
the Universe and Everything!" howled Loonquawl.

"Yes," said Deep Thought with the air of one  who  suffers  fools
gladly, "but what actually is it?"

A slow stupefied silence crept over the men as they stared at the
computer and then at each other.

"Well, you know, it's just Everything ... Everything ..." offered
Phouchg weakly.

"Exactly!" said Deep Thought. "So  once  you  do  know  what  the
question actually is, you'll know what the answer means."

"Oh terrific," muttered Phouchg flinging aside his  notebook  and
wiping away a tiny tear.

"Look, alright, alright," said Loonquawl, "can  you  just  please
tell us the Question?"

"The Ultimate Question?"


"Of Life, the Universe, and Everything?"


Deep Thought pondered this for a moment.

"Tricky," he said.

"But can you do it?" cried Loonquawl.

Deep Thought pondered this for another long moment.

Finally: "No," he said firmly.

Both men collapsed on to their chairs in despair.

"But I'll tell you who can," said Deep Thought.

They both looked up sharply.

"Who?" "Tell us!"

Suddenly Arthur began to feel his apparently  non-existent  scalp
begin  to  crawl as he found himself moving slowly but inexorably
forward towards the console, but it was only a dramatic  zoom  on
the part of whoever had made the recording he assumed.

"I speak of none other than the computer that is  to  come  after
me,"  intoned  Deep  Thought,  his voice regaining its accustomed
declamatory  tones.  "A   computer   whose   merest   operational
parameters  I  am not worthy to calculate - and yet I will design
it for you. A computer which can calculate the  Question  to  the
Ultimate   Answer,   a  computer  of  such  infinite  and  subtle
complexity that organic  life  itself  shall  form  part  of  its
operational  matrix.  And  you yourselves shall take on new forms
and go down into the computer to  navigate  its  ten-million-year
program!  Yes!  I shall design this computer for you. And I shall
name it also unto you. And it shall be called ... The Earth."

Phouchg gaped at Deep Thought.

"What a dull name," he said and great incisions appeared down the
length  of  his  body.  Loonquawl too suddenly sustained horrific
gashed from nowhere. The Computer console blotched  and  cracked,
the  walls  flickered  and  crumbled and the room crashed upwards
into its own ceiling ...

Slartibartfast was standing in front of Arthur  holding  the  two

"End of the tape," he explained.