Created
May 4, 2015 16:10
-
-
Save chitoge/6889adfa3948e2346697 to your computer and use it in GitHub Desktop.
VolgaCTF YACST
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import wave | |
import requests | |
import base64 | |
from bs4 import BeautifulSoup | |
import os | |
sess = requests.Session() | |
samp = [] | |
def solveCaptcha(x): | |
res = '' | |
for i in xrange(10): | |
x = x.replace(samp[i], str(i)) | |
return x | |
# get samples | |
for i in xrange(10): | |
print ('[*] Getting sample for %d...' % i) | |
rep = requests.get('http://yacst.2015.volgactf.ru/samples/%d.wav' % i) | |
f = open('tmp.wav', 'wb') | |
f.write(rep.content) | |
f.close() | |
# convert from MU-LAW to MS PCM | |
os.system('ffmpeg -i tmp.wav -c:a pcm_s16le -f wav -y -v quiet tmp2.wav') | |
f = wave.open('tmp2.wav', 'rb') | |
au = f.readframes(1000000) | |
samp.append(au) | |
f.close() | |
# log in | |
print '[*] Initiate session' | |
sess.get('http://yacst.2015.volgactf.ru/') | |
# do | |
for i in range(5): | |
rep = sess.get('http://yacst.2015.volgactf.ru/captcha', headers={'Referer': 'http://yacst.2015.volgactf.ru/'}) | |
f = open('tmp.wav', 'wb') | |
f.write(rep.content) | |
f.close() | |
# convert | |
os.system('ffmpeg -i tmp.wav -c:a pcm_s16le -f wav -y -v quiet tmp2.wav') | |
f = wave.open('tmp2.wav', 'rb') | |
au = f.readframes(1000000) | |
res = solveCaptcha(au) | |
print '[*] Solve = ', res | |
rep = sess.post('http://yacst.2015.volgactf.ru/captcha', data={'captcha': res}, headers={'Referer': 'http://yacst.2015.volgactf.ru/'}) | |
soup = BeautifulSoup(rep.text) | |
print soup.get_text() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment