forked from kirill97pussydestroyer/2ch_wipe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
192 lines (168 loc) · 6.39 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import requests
import base64
import time
import sys
import threading
import io
import PIL.Image
import random
import string
import collections
import os
import socket
import json
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
TIMEOUT = 5
class CaptchaSolver_anticaptcha:
def __init__(self, key):
self.api = "https://api.anti-captcha.com/"
self.key = key
print("Solver 'anti-captcha' initialized with key: " + self.key)
def solve(self, image):
task = {}
task["type"] = "ImageToTextTask"
task["body"] = base64.b64encode(image).decode("utf-8")
task["phrase"] = False
task["case"] = False
task["numeric"] = 1
task["math"] = False
task["minLength"] = 6
task["maxLength"] = 6
data = requests.post(self.api + "createTask", json={"clientKey": self.key, "task": task}, verify=False).json()
if (data["errorId"] == 0):
while True:
response = requests.post(self.api + "getTaskResult", json={"clientKey" : self.key, "taskId" : str(data["taskId"])}, verify=False).json()
if (response["status"] == "ready"):
return response["solution"]["text"]
time.sleep(3)
class CaptchaSolver_rucaptcha:
def __init__(self, key):
self.api = "https://rucaptcha.com/"
self.key = key
print("Solver 'rucaptcha' initialized with key: " + self.key)
def solve(self, image):
data = requests.post(self.api + "in.php", data={"key": self.key, "method": "base64", "body": base64.b64encode(image).decode("utf-8"), "numeric": 1, "min_len": 6, "max_len": 6, "json": 1}, verify=False).json()
if (data["status"] == 1):
while True:
response = requests.get(self.api + "res.php?key=" + self.key + "&action=get&id=" + data["request"] + "&json=1", verify=False).json()
if (response["status"] == 1):
return response["request"]
time.sleep(3)
class Captcha:
def __init__(self, proxy, agent, board, thread, solver):
self.api = "https://2ch.hk/api/captcha/2chaptcha/"
self.proxy = proxy
self.agent = agent
self.board = board
self.thread = thread
self.solver = solver
captcha = requests.get(self.api + "id?board=" + self.board + "&thread=" + self.thread, proxies=self.proxy, headers=self.agent, timeout=TIMEOUT, verify=False).json()
self.id = captcha["id"]
self.image = requests.get(self.api + "image/" + self.id, proxies=self.proxy, headers=self.agent, timeout=TIMEOUT, verify=False).content
def solve(self):
print(self.proxy["http"], "solving captcha")
self.value = self.solver.solve(self.image)
return (None, self.id), (None, self.value)
def verify(self):
return requests.get(self.api + "check/" + self.id + '?value=' + self.value, proxies=self.proxy, headers=self.agent, verify=False).json()["result"] == 1
class Post:
def __init__(self, proxy, agent, board, thread, solver):
self.proxy = {"http": proxy, "https": proxy}
self.agent = {"User-Agent": agent}
self.board = board
self.thread = thread
self.solver = solver
self.params = {}
self.params["task"] = (None, "post")
self.params["board"] = (None, self.board)
self.params["thread"] = (None, self.thread)
self.params["captcha_type"] = (None, "2chaptcha")
def prepare(self):
try:
self.params["2chaptcha_id"], self.params["2chaptcha_value"] = Captcha(self.proxy, self.agent, self.board, self.thread, self.solver).solve()
print(self.proxy["http"], "solved")
return True
except Exception as e:
# print(e)
return False
def set_subject(self, text):
self.params["subject"] = (None, text)
def set_text(self, text):
self.params["comment"] = (None, text)
def set_image(self, file_name, file_name_displayed):
image = PIL.Image.open(file_name).convert("RGB")
width, height = image.size
for x in range(random.randint(1, 10)): image.putpixel((random.randint(0, width-1), random.randint(0, height-1)), (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)))
image = image.crop((0 + random.randint(0, 10), 0 + random.randint(0, 10), width-1 - random.randint(0, 10), height-1 - random.randint(0, 10)))
image_bytes = io.BytesIO()
image.save(image_bytes, "JPEG", quality=60 + random.randint(10, 30), optimize=bool(random.getrandbits(1)), progressive=bool(random.getrandbits(1)))
image.close()
self.params["formimages"] = (file_name_displayed, image_bytes.getvalue(), "image")
def clear_image(self):
self.params["formimages"] = ()
def send(self):
response = {}
try:
print(self.proxy["http"], "posting")
response = requests.post("https://2ch.hk/makaba/posting.fcgi?json=1", files=self.params, proxies=self.proxy, headers=self.agent, timeout=TIMEOUT, verify=False).json()
return response["Error"] == None, response
except Exception as e:
# print(e)
return False, response
class Wiper:
def __init__(self, board, thread):
print("Wiper started")
self.proxies = [proxy[:-1] for proxy in open("proxies").readlines()]
random.shuffle(self.proxies);
self.agents = [agent[:-1] for agent in open("useragents").readlines()]
self.board = board
self.thread = thread
self.solver = CaptchaSolver_anticaptcha("anti-captcha.com api key")
# self.solver = CaptchaSolver_rucaptcha("rucaptcha.com api key")
def send_post(self):
if (len(self.proxies) == 0): return False
proxy = self.proxies.pop(0)
agent = random.choice(self.agents)
response = {"Error": "proxy"}
try:
post = Post(proxy, agent, self.board, self.thread, self.solver)
while True:
if (post.prepare()):
post.set_text("**ALLO YOBA ETO TI**")
post.set_image("./yoba.png", "blob")
success, response = post.send()
if (success):
post_id = 0
try:
post_id = response["Target"]
except:
post_id = response["Num"]
print(proxy + " - success. Post id: " + str(post_id))
self.proxies.push(proxy)
break
else:
print(proxy, "posting failed -", response)
try:
if ((response["Error"] != 6) and (response["Error"] != 4)): raise
except:
self.proxies.push(proxy)
raise
except Exception as e:
pass
# print(proxy, "-", response, e)
return True
def wipe(self, thread_count):
class WiperThread(threading.Thread):
def __init__(self, wiper):
threading.Thread.__init__(self)
self.wiper = wiper
def run(self):
while self.wiper.send_post(): pass
threads = []
for i in range(thread_count):
threads.append(WiperThread(self))
threads[-1].start()
for thread in threads:
thread.join()
Wiper(sys.argv[1], sys.argv[2]).wipe(int(sys.argv[3]))