Skip to content

Instantly share code, notes, and snippets.

@skyzh
Last active January 7, 2021 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skyzh/23f719b8f162a943fab96a80e19c5f85 to your computer and use it in GitHub Desktop.
Save skyzh/23f719b8f162a943fab96a80e19c5f85 to your computer and use it in GitHub Desktop.
import requests
from pathlib import Path
import time
import re
import base64
from lxml import etree
import os
from io import BytesIO
def gen_random_file(size):
buf = BytesIO()
for i in range(int(size / 4096)):
buf.write(os.urandom(4096))
buf.seek(0)
return buf
if __name__ == '__main__':
log = open("upload.log", "a")
cookies = {
"_forum_session": "",
"_t": "",
"authentication_data": "",
"_bypass_cache": "true"
}
s = requests.Session()
s.headers.update(
{"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.2 Safari/605.1.15"})
s.cookies.update(cookies)
total = 0
i = 0
while True:
i += 1
csrf = s.get('https://shuiyuan.sjtu.edu.cn/')
root = etree.HTML(csrf.text)
csrf_token = root.xpath('//meta[@name="csrf-token"]/@content')[0]
s.headers.update({"x-csrf-token": csrf_token,
"x-requested-with": "XMLHttpRequest"})
fname = f"random{i}.zip"
files = { "files[]": (fname, gen_random_file(49 * 1024 * 1024)) }
values = {"for_private_message": True, "type": "composer"}
r = s.post('https://shuiyuan.sjtu.edu.cn/uploads.json?client_id=<try upload one file and fill client id>',
files=files, data=values)
obj = r.json()
total += int(obj["filesize"])
print(f"upload status: {r.status_code}, total: {total / 1024 / 1024}MB, message: {obj}")
log.write(f"{obj['id']}, {obj['url']}, {obj['short_url']}\n")
log.flush()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment