43 lines
1.7 KiB
Python
43 lines
1.7 KiB
Python
|
|
"""只读探测生产环境 /api/charge-orders(验证同一解码缺陷是否在生产同样存在)"""
|
|||
|
|
import base64, hashlib, hmac, json, ssl, time, urllib.request, urllib.error, pymysql
|
|||
|
|
|
|||
|
|
JWT_SECRET = "787789e8eb1f3a10e81596f8219a20aa3c34102acacba2a5ed14bbb1d16ec833"
|
|||
|
|
BASE = "https://app.anzhizhichong.com/api/pms"
|
|||
|
|
|
|||
|
|
|
|||
|
|
def b64(b):
|
|||
|
|
return base64.urlsafe_b64encode(b).rstrip(b"=").decode()
|
|||
|
|
|
|||
|
|
|
|||
|
|
def sign(sub, phone):
|
|||
|
|
now = int(time.time())
|
|||
|
|
seg = b64(json.dumps({"alg": "HS256", "typ": "JWT"}, separators=(",", ":")).encode()) + "." + \
|
|||
|
|
b64(json.dumps({"sub": sub, "phone": phone, "exp": now + 600, "iat": now},
|
|||
|
|
separators=(",", ":")).encode())
|
|||
|
|
return seg + "." + b64(hmac.new(JWT_SECRET.encode(), seg.encode(), hashlib.sha256).digest())
|
|||
|
|
|
|||
|
|
|
|||
|
|
def call(path, token):
|
|||
|
|
req = urllib.request.Request(BASE + path, headers={"Authorization": "Bearer " + token})
|
|||
|
|
ctx = ssl.create_default_context()
|
|||
|
|
ctx.check_hostname = False
|
|||
|
|
ctx.verify_mode = ssl.CERT_NONE
|
|||
|
|
try:
|
|||
|
|
with urllib.request.urlopen(req, timeout=20, context=ctx) as r:
|
|||
|
|
return r.status, r.read().decode("utf-8", "replace")[:300]
|
|||
|
|
except urllib.error.HTTPError as e:
|
|||
|
|
return e.code, e.read().decode("utf-8", "replace")[:300]
|
|||
|
|
|
|||
|
|
|
|||
|
|
c = pymysql.connect(host="10.8.0.252", user="root", password="Hbhyg731024@", database="pms")
|
|||
|
|
cur = c.cursor()
|
|||
|
|
cur.execute("SELECT id, phone, role FROM users WHERE role >= 2 ORDER BY id LIMIT 5")
|
|||
|
|
admins = cur.fetchall()
|
|||
|
|
c.close()
|
|||
|
|
print("prod super admins:", admins)
|
|||
|
|
uid, phone, _ = admins[0]
|
|||
|
|
tok = sign(uid, phone)
|
|||
|
|
for p in ("/charge-orders?page=1&page_size=2", "/users?page=1&page_size=2",
|
|||
|
|
"/charge-records?page=1&page_size=2", "/batteries?page=1&page_size=2"):
|
|||
|
|
print(p, "->", call(p, tok))
|