Created
December 3, 2020 14:36
-
-
Save 74l35rUnn3r/32e809da6701b36b54156d72799eb82e to your computer and use it in GitHub Desktop.
This file contains 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 re | |
import requests | |
import time | |
import random | |
import string | |
from pyquery import PyQuery as pq | |
def decode_service_code(_svc : str, _r : str) -> str: | |
_r_key = 'yL/M=zNa0bcPQdReSfTgUhViWjXkYIZmnpo+qArOBs1Ct2D3uE4Fv5G6wHl78xJ9K' | |
_r = re.sub('[^A-Za-z0-9+/=]', '', _r) | |
tmp = '' | |
i = 0 | |
for a in [_r[i * 4:(i + 1) * 4] for i in range((len(_r) + 3) // 4)]: | |
t, f, d, h = [_r_key.find(x) for x in a] | |
tmp += chr(t << 2 | f >> 4) | |
if d != 64: | |
tmp += chr((15 & f) << 4 | (d >> 2)) | |
if h != 64: | |
tmp += chr((3 & d) << 6 | h) | |
_r = str(int(tmp[0]) + 4) + tmp[1:] | |
if int(tmp[0]) > 5: | |
_r = str(int(tmp[0]) - 5) + tmp[1:] | |
_r = [float(x) for x in _r.split(',')] | |
t = '' | |
for i in range(len(_r)): | |
t += chr(int(2 * (_r[i] - i - 1) / (13 - i - 1))) | |
return _svc[0:len(_svc) - 10] + t | |
def rndStr(len): | |
return ''.join(random.choice(string.ascii_letters) for i in range(len)) | |
def board_write(gall_id : str, title : str, body : str, proxy : str = '') -> str: | |
timeout = 30 | |
s = requests.Session() | |
s.headers.update({ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36" }) | |
if proxy: | |
s.proxies = { "https": "https://" + proxy } | |
r1 = s.get('https://gall.dcinside.com/board/write/?id=' + gall_id, timeout=timeout) | |
time.sleep(2) | |
_d = pq(r1.text) | |
data = dict(_d('#write').serialize_dict()) | |
data['name'] = 'ㅇㅇ' | |
data['password'] = rndStr(8) | |
data['subject'] = title | |
data['mode'] = 'W' | |
data['use_html'] = 'Y' | |
s.headers.update({ | |
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', | |
'Host': 'gall.dcinside.com', | |
'Origin': 'https://gall.dcinside.com', | |
'Referer': 'https://gall.dcinside.com/board/write/?id=' + gall_id, | |
'Sec-Fetch-Mode': 'cors', | |
'Sec-Fetch-Site': 'same-origin', | |
'X-Requested-With': 'XMLHttpRequest' | |
}) | |
r2 = s.post('https://gall.dcinside.com/block/block/', data=data, timeout=timeout) | |
if r2.text == '': | |
return 'block key empty' | |
time.sleep(2) | |
_r = _d('script[type="text/javascript"]').filter(lambda i, e: 'var _r =' in pq(e).text()).text() | |
_r = _r[13:_r.find("');")] | |
data['service_code'] = decode_service_code(_d('input[name="service_code"]').val(), _r) | |
data['block_key'] = r2.text | |
data['memo'] = body | |
data['code'] = 'undefined' | |
data['bgm'] = 0 | |
#print(json.dumps(data, indent=2, ensure_ascii=False)) | |
r3 = s.post('https://gall.dcinside.com/board/forms/article_submit', data=data, timeout=timeout) | |
#print(data['user_ip'], r3.text) | |
return r3.text | |
#print(board_write('programming', 'test', 'test',)) # '127.0.0.1:8080')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment