Esempio n. 1
0
    def paramsCombination(self,
                          data: dict,
                          place=PLACE.GET,
                          payloads=[],
                          hint=POST_HINT.NORMAL,
                          urlsafe='/\\'):
        """
        组合dict参数,将相关类型参数组合成requests认识的,防止request将参数进行url转义

        :param data:
        :param hint:
        :return: payloads -> list
        """
        result = []
        if place == PLACE.POST:
            if hint == POST_HINT.NORMAL:
                for key, value in data.items():
                    new_data = copy.deepcopy(data)
                    for payload in payloads:
                        new_data[key] = payload
                        result.append((key, value, payload, new_data))
            elif hint == POST_HINT.JSON:
                for payload in payloads:
                    for new_data in updateJsonObjectFromStr(data, payload):
                        result.append(('', '', payload, new_data))
        elif place == PLACE.GET:
            for payload in payloads:
                for key in data.keys():
                    temp = ""
                    for k, v in data.items():
                        if k == key:
                            temp += "{}={}{}".format(
                                k, quote(payload, safe=urlsafe),
                                DEFAULT_GET_POST_DELIMITER)
                        else:
                            temp += "{}={}{}".format(
                                k, quote(v, safe=urlsafe),
                                DEFAULT_GET_POST_DELIMITER)
                    temp = temp.rstrip(DEFAULT_GET_POST_DELIMITER)
                    result.append((key, data[key], payload, temp))
        elif place == PLACE.COOKIE:
            for payload in payloads:
                for key in data.keys():
                    temp = ""
                    for k, v in data.items():
                        if k == key:
                            temp += "{}={}{}".format(
                                k, quote(payload, safe=urlsafe),
                                DEFAULT_COOKIE_DELIMITER)
                        else:
                            temp += "{}={}{}".format(k, quote(v, safe=urlsafe),
                                                     DEFAULT_COOKIE_DELIMITER)
                    result.append((key, data[key], payload, temp))
        elif place == PLACE.URI:
            uris = splitUrlPath(data, flag="<--flag-->")
            for payload in payloads:
                for uri in uris:
                    uri = uri.replace("<--flag-->", payload)
                    result.append(("", "", payload, uri))
        return result
Esempio n. 2
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time    : 2020/4/17 2:20 PM
# @Author  : w8ay
# @File    : test_urlclean.py
import copy
from urllib.parse import urlparse, urlunparse
import os

from lib.core.common import splitUrlPath

url = "http://test.test/index.php/getlist/index/id/1/order-by/desc/"
url2 = "http://test.test/index.php/getlist/index/id/1/order-by/desc.html"

print(splitUrlPath(url))
print(splitUrlPath(url, False))
print(splitUrlPath(url2))
print(splitUrlPath(url2, False))