#!/usr/bin/env python3 import requests import sys import re from bs4 import BeautifulSoup import mimetypes import os from libsixel.encoder import Encoder URL = "https://www.google.com/recaptcha/api/fallback?k=6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc" s = requests.Session() s.headers[ "User-Agent" ] = "Mozilla/5.0 (X11; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0" s.headers["Referer"] = "https://boards.4chan.org/" r = s.get(URL) board = input("Enter board: ") thread = input("Enter thread: ") print("Enter reply (CTRL+D/EOF when finished): ") reply = sys.stdin.read() file = input("Upload file? [Y/N]: ")[0].lower() soup = BeautifulSoup(r.content, "html.parser") msg = soup.select(".fbc-imageselect-message-text > div") print("".join(msg[-1].text)) img = "https://www.google.com%s" % soup.select(".fbc-imageselect-payload")[0]["src"] c = soup.select(".fbc-imageselect-payload")[0]["src"].split("=")[1].split("&")[-2] encoder = Encoder() with open("captcha.png", "wb") as cap: cap.write(s.get(img).content) encoder.encode("captcha.png") os.remove("captcha.png") data = input("Selection: ") data = re.findall("\d", data) data = [int(d) - 1 for d in data] r = s.post(URL, data={"c": c, "response": data}) soup = BeautifulSoup(r.content, "html.parser") c = soup.select(".fbc-verification-token > textarea")[0].get_text() try: r = s.get("https://boards.4chan.org/%s/thread/%s" % (board, thread)) soup = BeautifulSoup(r.content, "html.parser") size = soup.select("script")[0].contents[0].split(",")[4].split("=")[-1].strip() data = { "MAX_FILE_SIZE": size, "mode": "regist", "pwd": "", "resto": thread, "name": "", "email": "", "com": reply, "g-recaptcha-response": c if c is not None else "", } if file == "y": path = input("Path to file: ") r = s.post( "https://sys.4chan.org/%s/post" % board, data=data, files={ "upfile": ( os.path.basename(path), open(path, "rb"), mimetypes.guess_type(path, strict=False)[0], ) }, ) else: r = s.post( "https://sys.4chan.org/%s/post" % board, data=data, files={"upfile": ("", "", "")}, ) except: print("You failed the captcha")