ISSessions CTF 2021 Programming - Image1

Mar 31, 2021 | 1 minute read


Bad CAPTCHA, I’m a robot.


For this, I knew I had to use some sort of OCR that was smart enough to handle the graphic changing and inputting a raw image.

Tesseract it is!

import pytesseract
import requests
import cv2
from lxml import html
import hashlib

def image1():
    s = requests.session()
    pytesseract.pytesseract.tesseract_cmd = r'F:\Program Files\Tesseract-OCR\tesseract.exe'
    url = ""
    page = s.get(url)
    tree = html.fromstring(page.content)
    htmlimg = tree.xpath('///img[@alt="captch challenge graphic"]/@src')
    imgfile = requests.get(url + htmlimg[0])

    file = open("prog1.gif", "wb")

    img = cv2.VideoCapture("prog1.gif")
    ret, frame =
    text = (pytesseract.image_to_string(frame)).strip()
    resp = s.get(url + "?answer=" + text)

This python code works as follows:

  • Initialize Tesseract’s home
  • Get the full page contents
  • Strip out the src attribute from the image
  • Download the image
  • Write it to a file locally
  • Create an OpenCV video capture, since this is a gif file, and grab the first frame only
  • Print out the text read from the image by Tesseract, just as a debug
  • Send it back to the server
  • ….
  • Profit??? aka, Flag.