Created
April 29, 2018 14:07
-
-
Save reyvand/8009962b49f8a9cd27a587316504e482 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 shutil | |
import requests as r | |
from base64 import * | |
from qrtools import QR | |
from PIL import Image, ImageOps | |
from bs4 import BeautifulSoup as bs | |
morseAlphabet = { | |
"A": ".-", | |
"B": "-...", | |
"C": "-.-.", | |
"D": "-..", | |
"E": ".", | |
"F": "..-.", | |
"G": "--.", | |
"H": "....", | |
"I": "..", | |
"J": ".---", | |
"K": "-.-", | |
"L": ".-..", | |
"M": "--", | |
"N": "-.", | |
"O": "---", | |
"P": ".--.", | |
"Q": "--.-", | |
"R": ".-.", | |
"S": "...", | |
"T": "-", | |
"U": "..-", | |
"V": "...-", | |
"W": ".--", | |
"X": "-..-", | |
"Y": "-.--", | |
"Z": "--..", | |
"1" : ".----", | |
"2" : "..---", | |
"3" : "...--", | |
"4" : "....-", | |
"5" : ".....", | |
"6" : "-....", | |
"7" : "--...", | |
"8" : "---..", | |
"9" : "----.", | |
"0" : "-----" | |
} | |
inverseMorseAlphabet = dict((v, k) for (k, v) in morseAlphabet.items()) #mbalik key sama value di dictionary morseAlphabet | |
s = r.Session() | |
url = "http://35.197.134.203:8021/index.php" | |
image = bs(s.get('http://35.197.134.203:8021/index.php').text, 'html.parser').find('img')['src'].split(',')[1] #cari base64 dari gambar | |
with open('qrdata.png','wb') as f: | |
f.write(b64decode(image)) #simpen gambar ke file | |
anu = Image.open('qrdata.png') #mbukak gambar yang udah disave | |
heem = ImageOps.invert(anu) #invert gambar | |
heem.save('jadian.png') #save gambar | |
qr = QR() | |
qr.decode("D:\ctf\B2P\qr\jadian.png") #decode qr | |
data = qr.data | |
result = ''.join(inverseMorseAlphabet[x] for x in data.split(' ')) #translate morse ke huruf | |
#submit jawaban | |
print s.post(url, data={'solution':result}, headers={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0', 'Referer':'http://35.197.134.203:8021/index.php'}).text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment