BoB/write-up
[BoB CTF] misc) 01_find me if you can
re.t
2023. 8. 24. 15:47
사진 하나를 열어보자마자 매크로 프로그램을 짤 때 Captcha 문자를 입력하기 위해 OCR을 사용해서 코드를 작성해본 경험이 떠올랐다. 이 문제의 경우에도 OCR을 이용하는 것 이외에는 별 다른 풀이가 없어 보이므로 빠르게 코드를 작성해보도록 하자. 이전에 개인적으로 작성했던 매크로 파일을 오랜만에 열어봤더니 당시에는 CUDA기반으로 GPU를 사용해 빠르게 동작할 수 있는 easyocr 이라는 파이썬 모듈을 사용했지만..... 어째선지 잘 작동하지 않아서 최종적으로는 PyTesseract를 사용했다.
코드를 작성할 때에는 사진 속 이미지의 대/소문자 형식과 플래그의 포맷을 참고해서 ' BOB{ '가 존재하는 이미지를 찾으면 되겠다.
from PIL import Image
import pytesseract
def ocr_image(image_path):
image = Image.open(image_path)
text = pytesseract.image_to_string(image, lang='eng')
return text
if __name__ == "__main__":
for i in range(1, 10001):
image_path = f"/home/reteu/bobctf/find_flag/{i}.png"
try:
extracted_text = ocr_image(image_path)
if 'BOB' in extracted_text:
print(f"File: {image_path}, Text: {extracted_text}")
except Exception as e:
print(f"Error processing file {image_path}: {e}")
굿