The Neverending Crypto Level 1

10

Hope you remember 1984, because you are
about to go on a journey.

How many levels can you get to?

Good luck.

nc 146.148.102.236 24069

ncコマンドで指定されたサーバに接続すると、次のように入力を求められます。何度か試したところ、25文字までの入力を受け付けるようです。
------------------------------------------
Welcome to The Neverending Crypto!
Quick, find Falkor and get through this!
This is level 1, the Bookstore

したがって、abcdefghijklmnopqrstuvwxy(a~yの25文字)を入力してみます。aが.-、bが-...という様に、モールス符号が返ってきます。そして、モールス符号で表された暗号文を復号するように入力を求められます。
abcdefghijklmnopqrstuvwxy
Round 1. Give me some text:abcdefghijklmnopqrstuvwxy encrypted is .- -... -.-. -.. . ..-. --. .... .. .--- -.- .-.. -- -. --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- 
What is ..   --- .-- .   -.-- --- ..-  decrypted?
 
これが何度も繰り返されますので、自動的に応答するプログラムをRubyで書きます。a~yに対応する符号を配列に保持しておき、半角スペースはそのまま半角スペース、これら以外をzに置き換えます。
require "socket"

begin
  sock = TCPSocket.open("146.148.102.236", 24069)
rescue
  puts "TCPSocket.open failed : #$!\n"
else
    while sock.gets
      buf = $_
      printf( buf )
      STDOUT.flush
      if buf.start_with?("This is level 1, the Bookstore") or buf.include?("Correct!") then
        str = "abcdefghijklmnopqrstuvwxy"
        printf(str + "\n")
        sock.write(str + "\n")
        STDOUT.flush
      elsif buf.include?(" encrypted is ") then
        ary = buf.split(" ")
        #p ary
      elsif buf.start_with?("What is") then
        enc = buf.gsub(/\s\s\s/, " _ ").split(" ")
        p enc
        ans = ""
        for e in enc do
          if e == "What" or e == "is" or e == "decrypted?" then
            next
          elsif e == "_" then
            ans = ans + " "
          elsif ary.index(e) then
            ans = ans + str[ary.index(e) - 8].chr
          else
            ans = ans + "z"
          end
        end
        printf(ans + "\n")
        sock.write(ans + "\n")
        STDOUT.flush
      else
      end
    end
  sock.close
end
このプログラムを実行すると、次のとおり50問解いた後にフラグが表示されます。その後、Level 2へ進みます。
------------------------------------------
Welcome to The Neverending Crypto!
Quick, find Falkor and get through this!
This is level 1, the Bookstore
abcdefghijklmnopqrstuvwxy
Round 1. Give me some text:abcdefghijklmnopqrstuvwxy encrypted is .- -... -.-. -.. . ..-. --. .... .. .--- -.- .-.. -- -. --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- 
What is ..   --- .-- .   -.-- --- ..-  decrypted?
["What", "is", "..", "_", "---", ".--", ".", "_", "-.--", "---", "..-", "decrypted?"]
i owe you
:Correct!
(略)
abcdefghijklmnopqrstuvwxy
Round 50. Give me some text:abcdefghijklmnopqrstuvwxy encrypted is .- -... -.-. -.. . ..-. --. .... .. .--- -.- .-.. -- -. --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- 
What is --. .. .- -. -   - ..- .-. - .-.. .  decrypted?
["What", "is", "--.", "..", ".-", "-.", "-", "_", "-", "..-", ".-.", "-", ".-..", ".", "decrypted?"]
giant turtle
:Correct!
abcdefghijklmnopqrstuvwxy
Round complete!
TUCTF{i_wi11_n0t_5teal}
------------------------------------------
You take the book
This is level 2 the attic
フラグは、
TUCTF{i_wi11_n0t_5teal}
です。