spacepaste

  1.  
  2. #!/usr/bin/env python3
  3. import requests
  4. import sys
  5. import re
  6. from bs4 import BeautifulSoup
  7. import mimetypes
  8. import os
  9. from libsixel.encoder import Encoder
  10. URL = "https://www.google.com/recaptcha/api/fallback?k=6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc"
  11. s = requests.Session()
  12. s.headers[
  13. "User-Agent"
  14. ] = "Mozilla/5.0 (X11; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0"
  15. s.headers["Referer"] = "https://boards.4chan.org/"
  16. r = s.get(URL)
  17. board = input("Enter board: ")
  18. thread = input("Enter thread: ")
  19. print("Enter reply (CTRL+D/EOF when finished): ")
  20. reply = sys.stdin.read()
  21. file = input("Upload file? [Y/N]: ")[0].lower()
  22. soup = BeautifulSoup(r.content, "html.parser")
  23. msg = soup.select(".fbc-imageselect-message-text > div")
  24. print("".join(msg[-1].text))
  25. img = "https://www.google.com%s" % soup.select(".fbc-imageselect-payload")[0]["src"]
  26. c = soup.select(".fbc-imageselect-payload")[0]["src"].split("=")[1].split("&")[-2]
  27. encoder = Encoder()
  28. with open("captcha.png", "wb") as cap:
  29. cap.write(s.get(img).content)
  30. encoder.encode("captcha.png")
  31. os.remove("captcha.png")
  32. data = input("Selection: ")
  33. data = re.findall("\d", data)
  34. data = [int(d) - 1 for d in data]
  35. r = s.post(URL, data={"c": c, "response": data})
  36. soup = BeautifulSoup(r.content, "html.parser")
  37. c = soup.select(".fbc-verification-token > textarea")[0].get_text()
  38. try:
  39. r = s.get("https://boards.4chan.org/%s/thread/%s" % (board, thread))
  40. soup = BeautifulSoup(r.content, "html.parser")
  41. size = soup.select("script")[0].contents[0].split(",")[4].split("=")[-1].strip()
  42. data = {
  43. "MAX_FILE_SIZE": size,
  44. "mode": "regist",
  45. "pwd": "",
  46. "resto": thread,
  47. "name": "",
  48. "email": "",
  49. "com": reply,
  50. "g-recaptcha-response": c if c is not None else "",
  51. }
  52. if file == "y":
  53. path = input("Path to file: ")
  54. r = s.post(
  55. "https://sys.4chan.org/%s/post" % board,
  56. data=data,
  57. files={
  58. "upfile": (
  59. os.path.basename(path),
  60. open(path, "rb"),
  61. mimetypes.guess_type(path, strict=False)[0],
  62. )
  63. },
  64. )
  65. else:
  66. r = s.post(
  67. "https://sys.4chan.org/%s/post" % board,
  68. data=data,
  69. files={"upfile": ("", "", "")},
  70. )
  71. except:
  72. print("You failed the captcha")
  73.