aszx87410 / ctf-writeups

ctf writeups

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

H@cktivityCon 2021 CTF - OTP Samsher

aszx87410 opened this issue · comments

commented

Description

Your fingers too slow to smash, tbh.

截圖 2021-09-20 上午11 04 52

Writeup

We need to keep inputing the code on the image, so just create an automation script and do OCR.

The problem is, the OCR library is not that accurate, my solution is to use a fallback language and hope it works.

const puppeteer = require('puppeteer');
const path = require('path')
const fs = require('fs')
const pageUrl = 'http://challenge.ctf.games:31205/';

const { createWorker, PSM } = require('tesseract.js');

const worker = createWorker();
const worker2 = createWorker();
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));

(async () => {
  await worker.load();
  await worker.loadLanguage('eng');
  await worker.initialize('eng');
  await worker.setParameters({
    tessedit_char_whitelist: "0123456789"
  });

  await worker2.load();
  await worker2.loadLanguage('chi_tra');
  await worker2.initialize('chi_tra');
  await worker2.setParameters({
    tessedit_char_whitelist: "0123456789"
  });

  const browser = await puppeteer.launch({
    headless: false
  });
  const page = await browser.newPage();
  await page.goto(pageUrl);
  send()
  
  async function send() {
    let { data: { text } } = await worker.recognize('http://challenge.ctf.games:31205/static/otp.png');
    console.log('text:'+text)
    if (text.length !== 9) {
      const result = await worker2.recognize('http://challenge.ctf.games:31205/static/otp.png');
      text = result.data.text
      console.log('text again:'+text)
    }
    await page.evaluate((text) => {
      document.querySelector('input[name=otp_entry]').value = text
      document.querySelector('input[type=submit]').click()
    }, text)
    await page.waitForNavigation();
    send()
  }
})();