Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

H@cktivityCon 2021 CTF - OTP Samsher #41

Open
aszx87410 opened this issue Sep 20, 2021 · 0 comments
Open

H@cktivityCon 2021 CTF - OTP Samsher #41

aszx87410 opened this issue Sep 20, 2021 · 0 comments
Labels

Comments

@aszx87410
Copy link
Owner

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()
  }
})();
@aszx87410 aszx87410 added the Misc label Sep 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant