Created
December 24, 2019 11:22
-
-
Save MilyMilo/7f34da3aff0594743daa623ca84d6ba4 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 os | |
import socket | |
import string | |
import random | |
# requirements.txt: | |
# pyzbar (pip) + zbar-gtk (dnf) | |
# Pillow | |
# isbnlib | |
import isbnlib | |
from PIL import Image | |
from pyzbar.pyzbar import decode | |
def get_filename(n): | |
return ''.join(random.choices(string.ascii_uppercase + string.digits, k=n)) | |
host = "34.89.220.233" | |
port = 6010 | |
last_path = "" | |
try: | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.connect((host, port)) | |
try: | |
print("[+] Connected!") | |
if not os.path.exists(".tmp/"): | |
os.makedirs(".tmp/") | |
while True: | |
image_data = s.recv(1024).strip() | |
path = ".tmp/" + get_filename(4) | |
last_path = path | |
with open(path, "w+b") as out: | |
out.write(image_data) | |
decoded = decode(Image.open(path)) | |
isbn = str(decoded[0].data, encoding="utf-8") | |
book = isbnlib.meta(isbn)['Title'] | |
print("Found book:", book) | |
s.send(bytes(book, encoding="utf-8")) | |
res = str(s.recv(6), encoding="utf-8") # Good! | |
os.unlink(path) | |
except KeyboardInterrupt: | |
print("\n[+] ^C Received, closing connection") | |
s.close() | |
except EOFError: | |
print("\n[+] ^D Received, closing connection") | |
s.close() | |
except socket.error: | |
if os.path.isfile(last_path): | |
print("[+] Connection dropped, reading flag...") | |
with open(last_path, "r+") as flag_file: | |
flag = flag_file.readline() | |
print(f"[+] Flag: {flag}") | |
else: | |
print("[-] Connection dropped, but no flag") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment