본문 바로가기
분류 전/CTF

[Sunshine] beepboop 풀이

by jwcs 2023. 10. 14.
728x90

https://github.com/D13David/ctf-writeups/tree/main/sunshinectf23/crypto/beepboop

 

Help! My IOT device has gone sentient!

All I wanted to know was the meaning of 42!

It's also waving its arms up and down, and I...

oh no! It's free!

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

Automated Challenge Instructions Detected failure in challenge upload. Original author terminated. Please see attached file BeepBoop for your flag... human.

Author: N/A

BeepBoop

문제를 이렇게 설명하고 있다.

 

beep beep beep beep boop beep boop beep beep boop boop beep beep boop boop beep beep boop boop beep boop beep beep beep beep boop boop beep beep beep beep boop beep boop boop boop boop beep boop boop beep boop boop boop beep beep boop beep beep boop boop beep boop beep boop boop beep boop boop beep beep boop boop boop beep boop boop boop beep beep boop beep beep boop boop beep beep boop beep boop beep boop boop boop boop beep boop beep beep boop boop boop beep boop boop beep beep boop boop beep beep beep beep boop beep boop boop beep boop boop boop beep beep boop boop beep beep boop boop boop beep boop boop boop beep beep boop beep beep beep boop beep boop boop beep boop beep boop boop boop beep beep boop beep beep boop boop beep boop beep boop boop beep boop boop beep beep boop boop boop beep boop boop boop beep beep boop beep beep boop boop beep beep boop beep boop beep boop boop boop boop beep boop beep beep boop boop boop beep boop boop beep beep boop boop beep beep beep beep boop beep boop boop beep boop boop boop beep beep boop boop beep beep boop boop boop beep boop boop boop beep beep boop beep beep beep boop beep boop boop beep boop beep boop boop boop beep beep boop beep beep boop boop beep boop beep boop boop beep boop boop beep beep boop boop boop beep boop boop boop beep beep boop beep beep boop boop beep beep boop beep boop beep boop boop boop boop beep boop beep beep boop boop boop beep boop boop beep beep boop boop beep beep beep beep boop beep boop boop beep boop boop boop beep beep boop boop beep beep boop boop boop beep boop boop boop beep beep boop beep beep boop boop boop boop boop beep boop

제공되는 파일을 열어보면 이런 것을 제공해준다.

 

beep과 boop만 있다. 마치 0과 1처럼 보인다.

 

bits=cipher.replace("beep","0").replace("boop","1").replace(" ","")

따라서 위의 코드로 0과 1로 바꿔주고 띄어쓰기를 없애줬다.

 

0000101001100110011010000110000101111011011100100110101101100111011100100110010101111010011101100110000101101110011001110111001000101101011100100110101101100111011100100110010101111010011101100110000101101110011001110111001000101101011100100110101101100111011100100110010101111010011101100110000101101110011001110111001001111101

그러면 위와같이 바뀐다. 이것을 문자열로 바꿔보자.

 

cipher_dec = int(bits, 2)
text=cipher_dec.to_bytes((cipher_dec.bit_length()+7)//8, 'big').decode()

to_bytes() 함수를 사용했다. 이 함수는 int.to_bytes(length, byteorder, signed=False) 와 같은 형식을 따른다.

 

따라서 bit를 int로 바꿔주고 암호문 길이에 맞춰 length 값을 설정해주었다. +7을 해주고 8로 나눠주는 이유는 만약에 9비트를 가지고 있다면 1바이트만큼만 할당해줄 것이다. 따라서 2바이트로 할당해주기 위해 7을 더해주는 것이다.

 

엔디안 방식도 정해주어야 한다. 빅 엔디안 방식으로 저장하고 있으며, 리틀 엔디안 방식과의 차이는 따로 찾아보길 바란다.

 

이렇게 바이트로 바뀐 값을 디코딩 해서 text 변수에 값을 저장해주자.

 

fha{rkgrezvangr-rkgrezvangr-rkgrezvangr}

그럼 위와 같은 값이 나온다. 마치 rot13으로 알파벳 값이 치환된 것으로 보인다. 따라서 rot13을 해주자.

 

alphabet="abcdefghijklmnopqrstuvwxyz"

text_list=list(text) #파이썬에서 문자열은 불변(immutable) 객체이므로 리스트로 변환해서 인덱스 값을 처리해주어야 한다
for i in range(len(text)):
    if text_list[i] in alphabet:
        index=alphabet.index(text[i])
        text_list[i]=alphabet[(index+13)%26]

text=''.join(text_list)
print(text)

위와 같이 알파벳 값을 찾아 13만큼 값을 더해서 나타내주었다.

 

cipher="beep beep beep beep boop beep boop beep beep boop boop beep beep boop boop beep beep boop boop beep boop beep beep beep beep boop boop beep beep beep beep boop beep boop boop boop boop beep boop boop beep boop boop boop beep beep boop beep beep boop boop beep boop beep boop boop beep boop boop beep beep boop boop boop beep boop boop boop beep beep boop beep beep boop boop beep beep boop beep boop beep boop boop boop boop beep boop beep beep boop boop boop beep boop boop beep beep boop boop beep beep beep beep boop beep boop boop beep boop boop boop beep beep boop boop beep beep boop boop boop beep boop boop boop beep beep boop beep beep beep boop beep boop boop beep boop beep boop boop boop beep beep boop beep beep boop boop beep boop beep boop boop beep boop boop beep beep boop boop boop beep boop boop boop beep beep boop beep beep boop boop beep beep boop beep boop beep boop boop boop boop beep boop beep beep boop boop boop beep boop boop beep beep boop boop beep beep beep beep boop beep boop boop beep boop boop boop beep beep boop boop beep beep boop boop boop beep boop boop boop beep beep boop beep beep beep boop beep boop boop beep boop beep boop boop boop beep beep boop beep beep boop boop beep boop beep boop boop beep boop boop beep beep boop boop boop beep boop boop boop beep beep boop beep beep boop boop beep beep boop beep boop beep boop boop boop boop beep boop beep beep boop boop boop beep boop boop beep beep boop boop beep beep beep beep boop beep boop boop beep boop boop boop beep beep boop boop beep beep boop boop boop beep boop boop boop beep beep boop beep beep boop boop boop boop boop beep boop"
bits=cipher.replace("beep","0").replace("boop","1").replace(" ","")
print(bits)

cipher_dec = int(bits, 2)
text=cipher_dec.to_bytes((cipher_dec.bit_length()+7)//8, 'big').decode()
print(text)
#print((65).to_bytes(1,'big').decode()) #A
#print((16706).to_bytes(2,'big').decode()) #AB
#print(text.to_bytes((text.bit_length()+7)//8, 'little').decode())

alphabet="abcdefghijklmnopqrstuvwxyz"

text_list=list(text) #파이썬에서 문자열은 불변(immutable) 객체이므로 리스트로 변환해서 인덱스 값을 처리해주어야 한다
for i in range(len(text)):
    if text_list[i] in alphabet:
        index=alphabet.index(text[i])
        text_list[i]=alphabet[(index+13)%26]

text=''.join(text_list)
print(text)

완성 코드

 

짜잔

728x90
반응형

'분류 전 > CTF' 카테고리의 다른 글

[2024 IS_LAB CTF] Under Construction 풀이  (0) 2024.02.05
[2024 IS_LAB CTF] Robots 풀이  (0) 2024.02.05
[Sunshine] Hotdog Stand 풀이  (0) 2023.10.10
[Sunshine] BeepBoop Blog 풀이  (0) 2023.10.10
[ASIS] hello 풀이  (2) 2023.10.02