Securinets CTF Quals 2020 Writeup

この大会は2020/3/22 2:00(JST)~2020/3/23 2:00(JST)に開催されました。
今回もチームで参戦。結果は1972点で429チーム中61位でした。
自分で解けた問題をWriteupとして書いておきます。

Welcome To Securinets !

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

Securinets{PreQu@l$_2K20}

ASCII ART 0 (Misc)

$ nc 52.73.40.215 1337
Welcome to securinets CTF!
Let's play a game!
I'll tell u words words in ascii art and you should repeat them for me!
           ____   ____   _     _  _     
__      __|  _ \ |  _ \ | | __(_)| |__  
\ \ /\ / /| |_) || |_) || |/ /| || '_ \ 
 \ V  V / |  _ < |  _ < |   < | || |_) |
  \_/\_/  |_| \_\|_| \_\|_|\_\|_||_.__/ 
                                        

>wRRkib
Too late...

$ nc 52.73.40.215 1337
Welcome to securinets CTF!
Let's play a game!
I'll tell u words words in ascii art and you should repeat them for me!
       ___   _        __  __      
 ___  ( _ ) | |__   __\ \/ / _ __ 
/ __| / _ \ | |\ \ / / \  / | '__|
\__ \| (_) || | \ V /  /  \ | |   
|___/ \___/ |_|  \_/  /_/\_\|_|   
                                  

>s8lvXr        
Too late...

$ nc 52.73.40.215 1337
Welcome to securinets CTF!
Let's play a game!
I'll tell u words words in ascii art and you should repeat them for me!
             _   _ __  __ _  _    _____ 
 ____ _   _ | \ | |\ \/ /| || |  |___ / 
|_  /| | | ||  \| | \  / | || |_   |_ \ 
 / / | |_| || |\  | /  \ |__   _| ___) |
/___| \__,_||_| \_|/_/\_\   |_|  |____/ 
                                        

>zuNX43
Too late...

$ nc 52.73.40.215 1337
Welcome to securinets CTF!
Let's play a game!
I'll tell u words words in ascii art and you should repeat them for me!
        ____          ___  __        __       
  __ _ |  _ \  _ __  / _ \ \ \      / /  __ _ 
 / _` || |_) || '__|| | | | \ \ /\ / /  / _` |
| (_| ||  _ < | |   | |_| |  \ V  V /  | (_| |
 \__, ||_| \_\|_|    \___/    \_/\_/    \__, |
 |___/                                     |_|

>gRr0Wq
Too late...

$ nc 52.73.40.215 1337
Welcome to securinets CTF!
Let's play a game!
I'll tell u words words in ascii art and you should repeat them for me!
                     _    ____   _     
 _ __   _ __    ___ | |_ / ___| | |__  
| '_ \ | '_ \  / _ \| __|\___ \ | '_ \ 
| |_) || |_) ||  __/| |_  ___) || | | |
| .__/ | .__/  \___| \__||____/ |_| |_|
|_|    |_|                             

>ppetSh
Too late...

$ nc 52.73.40.215 1337
Welcome to securinets CTF!
Let's play a game!
I'll tell u words words in ascii art and you should repeat them for me!
  ___       _        ____        __        __
 ( _ )   __| |  ___ |  _ \ __  __\ \      / /
 / _ \  / _` | / _ \| |_) |\ \/ / \ \ /\ / / 
| (_) || (_| ||  __/|  _ <  >  <   \ V  V /  
 \___/  \__,_| \___||_| \_\/_/\_\   \_/\_/   
                                             

>8deRxW
Too late...

アスキーアートの文字を答えていく必要があるが、手入力では間に合わない。なるべく文字の形式を識別できるようデータを取り、辞書として持っておき、比較して対応する文字を答えていく。

import socket

letters = {
''' _ 
/ |
| |
| |
|_|
   ''': '1',
''' ____  
|___ \ 
  __) |
 / __/ 
|_____|
       ''': '2',
''' _____ 
|___ / 
  |_ \ 
 ___) |
|____/ 
       ''': '3',
''' _  _   
| || |  
| || |_ 
|__   _|
   |_|  
        ''': '4',
''' ____  
| ___| 
|___ \ 
 ___) |
|____/ 
       ''': '5',
'''  __   
 / /_  
| '_ \ 
| (_) |
 \___/ 
       ''': '6',
''' _____ 
|___  |
   / / 
  / /  
 /_/   
       ''': '7',
'''  ___  
 ( _ ) 
 / _ \ 
| (_) |
 \___/ 
       ''': '8',
'''  ___  
 / _ \ 
| (_) |
 \__, |
   /_/ 
       ''': '9',
'''    _    
   / \   
  / _ \  
 / ___ \ 
/_/   \_\\
         ''': 'A',
''' ____  
| __ ) 
|  _ \ 
| |_) |
|____/ 
       ''': 'B',
'''  ____ 
 / ___|
| |    
| |___ 
 \____|
       ''': 'C',
''' ____  
|  _ \ 
| | | |
| |_| |
|____/ 
       ''': 'D',
''' _____ 
| ____|
|  _|  
| |___ 
|_____|
       ''': 'E',
''' _____ 
|  ___|
| |_   
|  _|  
|_|    
       ''': 'F',
'''  ____ 
 / ___|
| |  _ 
| |_| |
 \____|
       ''': 'G',
''' _   _ 
| | | |
| |_| |
|  _  |
|_| |_|
       ''': 'H',
''' ___ 
|_ _|
 | | 
 | | 
|___|
     ''': 'I',
'''     _ 
    | |
 _  | |
| |_| |
 \___/ 
       ''': 'J',
''' _  __
| |/ /
| ' / 
| . \ 
|_|\_\\
      ''': 'K',
''' _     
| |    
| |    
| |___ 
|_____|
       ''': 'L',
''' __  __ 
|  \/  |
| |\/| |
| |  | |
|_|  |_|
        ''': 'M',
''' _   _ 
| \ | |
|  \| |
| |\  |
|_| \_|
       ''': 'N',
'''  ___  
 / _ \ 
| | | |
| |_| |
 \___/ 
       ''': 'O',
''' ____  
|  _ \ 
| |_) |
|  __/ 
|_|    
       ''': 'P',
'''  ___  
 / _ \ 
| | | |
| |_| |
 \__\_\\
       ''': 'Q',
''' ____  
|  _ \ 
| |_) |
|  _ < 
|_| \_\\
       ''': 'R',
''' ____  
/ ___| 
\___ \ 
 ___) |
|____/ 
       ''': 'S',
''' _____ 
|_   _|
  | |  
  | |  
  |_|  
       ''': 'T',
''' _   _ 
| | | |
| | | |
| |_| |
 \___/ 
       ''': 'U',
'''__     __
\ \   / /
 \ \ / / 
  \ V /  
   \_/   
         ''': 'V',
'''__        __
\ \      / /
 \ \ /\ / / 
  \ V  V /  
   \_/\_/   
            ''': 'W',
'''__  __
\ \/ /
 \  / 
 /  \ 
/_/\_\\
      ''': 'X',
'''__   __
\ \ / /
 \ V / 
  | |  
  |_|  
       ''': 'Y',
''' _____
|__  /
  / / 
 / /_ 
/____|
      ''': 'Z',
'''       
  __ _ 
 / _` |
| (_| |
 \__,_|
       ''': 'a',
''' _     
| |__  
| '_ \ 
| |_) |
|_.__/ 
       ''': 'b',
'''      
  ___ 
 / __|
| (__ 
 \___|
      ''': 'c',
'''     _ 
  __| |
 / _` |
| (_| |
 \__,_|
       ''': 'd',
'''      
  ___ 
 / _ \\
|  __/
 \___|
      ''': 'e',
'''  __ 
 / _|
| |_ 
|  _|
|_|  
     ''': 'f',
'''       
  __ _ 
 / _` |
| (_| |
 \__, |
 |___/ ''': 'g',
''' _     
| |__  
| '_ \ 
| | | |
|_| |_|
       ''': 'h',
''' _ 
(_)
| |
| |
|_|
   ''': 'i',
'''   _ 
  (_)
  | |
  | |
 _/ |
|__/ ''': 'j',
''' _    
| | __
| |/ /
|   < 
|_|\_\\
      ''': 'k',
''' _ 
| |
| |
| |
|_|
   ''': 'l',
'''           
 _ __ ___  
| '_ ` _ \ 
| | | | | |
|_| |_| |_|
           ''': 'm',
'''       
 _ __  
| '_ \ 
| | | |
|_| |_|
       ''': 'n',
'''       
  ___  
 / _ \ 
| (_) |
 \___/ 
       ''': 'o',
'''       
 _ __  
| '_ \ 
| |_) |
| .__/ 
|_|    ''': 'p',
'''       
  __ _ 
 / _` |
| (_| |
 \__, |
    |_|''': 'q',
'''      
 _ __ 
| '__|
| |   
|_|   
      ''': 'r',
'''     
 ___ 
/ __|
\__ \\
|___/
     ''': 's',
''' _   
| |_ 
| __|
| |_ 
 \__|
     ''': 't',
'''       
 _   _ 
| | | |
| |_| |
 \__,_|
       ''': 'u',
'''       
__   __
\ \ / /
 \ V / 
  \_/  
       ''': 'v',
'''          
__      __
\ \ /\ / /
 \ V  V / 
  \_/\_/  
          ''': 'w',
'''      
__  __
\ \/ /
 >  < 
/_/\_\\
      ''': 'x',
'''       
 _   _ 
| | | |
| |_| |
 \__, |
 |___/ ''': 'y',
'''     
 ____
|_  /
 / / 
/___|
     ''': 'z'
}

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(('52.73.40.215', 1337))

data = recvuntil(s, 'for me!\n').rstrip()
print data

for round in range(30):
    print 'Round %d' % (round + 1)
    data = recvuntil(s, '\n>')
    print data,

    data = data.split('\n')[:6]

    l = len(data[0])
    i = 0
    ans = ''
    while True:
        for j in range(3, 13):
            ascii = '\n'.join([data[k][:-1][i:i+j] for k in range(6)])
            if ascii in letters:
                ans += letters[ascii]
                i += j
                break
        if i == l - 1:
            break

    print ans
    s.sendall(ans + '\n')

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

実行結果は以下の通り。

Welcome to securinets CTF!
Let's play a game!
I'll tell u words words in ascii art and you should repeat them for me!
Round 1
 _____   ___   _      __  __  ____   _   
|_   _| / _ \ | |__  |  \/  ||  _ \ | |_ 
  | |  | (_) || '_ \ | |\/| || | | || __|
  | |   \__, || |_) || |  | || |_| || |_ 
  |_|     /_/ |_.__/ |_|  |_||____/  \__|
                                         

> T9bMDt
Round 2
 _____ _  _    _  _    __   __       
|__  /| || |  / || | __\ \ / /  __ _ 
  / / | || |_ | || |/ / \ V /  / _` |
 / /_ |__   _|| ||   <   | |  | (_| |
/____|   |_|  |_||_|\_\  |_|   \__, |
                                  |_|

> Z41kYq
Round 3
 _____  _      ___       _____      
|  ___|| |__  |_ _| ____| ____| ____
| |_   | '_ \  | | |_  /|  _|  |_  /
|  _|  | | | | | |  / / | |___  / / 
|_|    |_| |_||___|/___||_____|/___|
                                    

> FhIzEz
Round 4
 __  __   ___   _     __     __     _  _   _ 
|  \/  | / _ \ | |    \ \   / /  __| || | | |
| |\/| || | | || |     \ \ / /  / _` || |_| |
| |  | || |_| || |___   \ V /  | (_| ||  _  |
|_|  |_| \___/ |_____|   \_/    \__,_||_| |_|
                                             

> MOLVdH

        :                                          

Round 30
 _         _      ____   ___                    
| |__     / \    / ___| / _ \  _ __   _ __ ___  
| '_ \   / _ \  | |  _ | | | || '_ \ | '_ ` _ \ 
| |_) | / ___ \ | |_| || |_| || |_) || | | | | |
|_.__/ /_/   \_\ \____| \___/ | .__/ |_| |_| |_|
                              |_|               

> bAGOpm
securinets{w3ll_d0n3_g00d!!}
securinets{w3ll_d0n3_g00d!!}

ASCII ART 1 (Misc)

$ nc 52.73.40.215 1338
Welcome to securinets CTF!
Let's play a game!
I'll tell u words words in ascii art and you should repeat them for me!
  __           _  _   
 / /_     _   | || |  
| '_ \  _| |_ | || |_ 
| (_) ||_   _||__   _|
 \___/   |_|     |_|  
                      

>10
Too late...

$ nc 52.73.40.215 1338
Welcome to securinets CTF!
Let's play a game!
I'll tell u words words in ascii art and you should repeat them for me!
 ____           ___  
|___ \         / _ \ 
  __) | _____ | (_) |
 / __/ |_____| \__, |
|_____|          /_/ 
                     

>-7
Too late...

$ nc 52.73.40.215 1338
Welcome to securinets CTF!
Let's play a game!
I'll tell u words words in ascii art and you should repeat them for me!
 _        _____ 
/ |__/\__|___ / 
| |\    /  |_ \ 
| |/_  _\ ___) |
|_|  \/  |____/ 
                

>3
 ____           __   
| ___|         / /_  
|___ \  _____ | '_ \ 
 ___) ||_____|| (_) |
|____/         \___/ 
                     

>-1
Too late...

$ nc 52.73.40.215 1338
Welcome to securinets CTF!
Let's play a game!
I'll tell u words words in ascii art and you should repeat them for me!
 _____         ____  
|___  |   _   |___ \ 
   / /  _| |_   __) |
  / /  |_   _| / __/ 
 /_/     |_|  |_____|
                     

>9
  __       __ _____ 
 / /_     / /|___ / 
| '_ \   / /   |_ \ 
| (_) | / /   ___) |
 \___/ /_/   |____/ 
                    

>2
 _____         __   
|___ / __/\__ / /_  
  |_ \ \    /| '_ \ 
 ___) |/_  _\| (_) |
|____/   \/   \___/ 
                    

>18
 _____     __ _____ 
|___  |   / /|___ / 
   / /   / /   |_ \ 
  / /   / /   ___) |
 /_/   /_/   |____/ 
                    

>2
Too late...

今度も ASCII ART 0 と同じようにして計算だけすればよい。

import socket

letters = {
''' _ 
/ |
| |
| |
|_|
   ''': '1',
''' ____  
|___ \ 
  __) |
 / __/ 
|_____|
       ''': '2',
''' _____ 
|___ / 
  |_ \ 
 ___) |
|____/ 
       ''': '3',
''' _  _   
| || |  
| || |_ 
|__   _|
   |_|  
        ''': '4',
''' ____  
| ___| 
|___ \ 
 ___) |
|____/ 
       ''': '5',
'''  __   
 / /_  
| '_ \ 
| (_) |
 \___/ 
       ''': '6',
''' _____ 
|___  |
   / / 
  / /  
 /_/   
       ''': '7',
'''  ___  
 ( _ ) 
 / _ \ 
| (_) |
 \___/ 
       ''': '8',
'''  ___  
 / _ \ 
| (_) |
 \__, |
   /_/ 
       ''': '9',
'''       
   _   
 _| |_ 
|_   _|
  |_|  
       ''': '+',
'''       
       
 _____ 
|_____|
       
       ''': '-',
'''      
__/\__
\    /
/_  _\\
  \/  
      ''': '*',
'''    __
   / /
  / / 
 / /  
/_/   
      ''': '/'
}

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(('52.73.40.215', 1338))

data = recvuntil(s, 'for me!\n').rstrip()
print data

for round in range(100):
    print 'Round %d' % (round + 1)
    data = recvuntil(s, '\n>')
    print data,

    data = data.split('\n')[:6]

    l = len(data[0])
    i = 0
    ans = ''
    while True:
        for j in range(3, 13):
            ascii = '\n'.join([data[k][:-1][i:i+j] for k in range(6)])
            if ascii in letters:
                ans += letters[ascii]
                i += j
                break
        if i == l - 1:
            break

    ans = str(eval(ans))
    print ans
    s.sendall(ans + '\n')

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

実行結果は以下の通り。

Welcome to securinets CTF!
Let's play a game!
I'll tell u words words in ascii art and you should repeat them for me!
Round 1
 ____          _  _   
| ___|    _   | || |  
|___ \  _| |_ | || |_ 
 ___) ||_   _||__   _|
|____/   |_|     |_|  
                      

> 9
Round 2
 _  _            ___  
| || |          / _ \ 
| || |_  _____ | (_) |
|__   _||_____| \__, |
   |_|            /_/ 
                      

> -5
Round 3
 _  _           ____  
| || |         |___ \ 
| || |_  _____   __) |
|__   _||_____| / __/ 
   |_|         |_____|
                      

> 2
Round 4
  ___          _  _   
 / _ \    _   | || |  
| (_) | _| |_ | || |_ 
 \__, ||_   _||__   _|
   /_/   |_|     |_|  
                      

> 13
Round 5
 ____          _ 
| ___|        / |
|___ \  _____ | |
 ___) ||_____|| |
|____/        |_|
                 

> 4

        :

Round 100
 _         ___  
/ |__/\__ ( _ ) 
| |\    / / _ \ 
| |/_  _\| (_) |
|_|  \/   \___/ 
                

> 8
securinets{th1s_w4s_g00d_r1ght??}
securinets{th1s_w4s_g00d_r1ght??}