Пример #1
0
def payload2curl(p):
    lines = re.compile("[\n\r]+").split(p.decode('utf-8'))
    start_line = re.search("^([A-Z]+) ([^ ]+) (HTTP\/[0-9\/]+)", lines[0])
    method = start_line.group(1)
    url = start_line.group(2)
    version = start_line.group(3)  # Never used

    if method not in VALID_METHODS:
        return

    del lines[0]
    headers = []
    for line in lines:
        if ":" in line:
            headers.append("-H '{}'".format(line.encode('utf-8')))
        if "Host:" in line:
            host_header = re.search("^Host:(.*)", line)
            host_name = host_header.group(1)
    for b in HOSTNAME_BLACK:
        if b in host_name.lower():
            return
    proto_host = 'http://{}/'.format(host_name.strip())
    if not url.startswith(proto_host):
        url = "{}{}".format(proto_host, url[1:] if url[0] == "/" else url)
    curl = "curl '{}' \\\n -X {} \\\n ".format(url, method)
    curl += " \\\n ".join(headers)
    return curl
Пример #2
0
def payload2curl(p):
    lines = re.compile("[\n\r]+").split(p.decode('utf-8', errors='ignore'))
    start_line = re.search("^([A-Z]+) ([^ ]+) (HTTP\/[0-9\/]+)", lines[0])
    if start_line is None:
        return 0
    method = start_line.group(1)
    url = start_line.group(2)
    version = start_line.group(3)  # Never used

    del lines[0]
    headers = []
    for line in lines:
        line = line.replace('\\', '\\\\').replace('"',
                                                  '\\"').replace('$', '\\$')
        if ":" in line:
            headers.append("-H \"{}\"".format(line))
        if "Host:" in line:
            host_header = re.search("^Host: (.*)", line)
            host_name = host_header.group(1)

    proto_host = 'http://{}/'.format(host_name)
    if not url.startswith(proto_host):
        url = "{}{}".format(proto_host, url[1:] if url[0] == "/" else url)
    url = url.replace('\\', '\\\\').replace('"', '\\"').replace('$', '\\$')
    curl = "curl \"{}\" \\\n -X {} \\\n ".format(url, method)
    curl += " \\\n ".join(headers)
    return curl
Пример #3
0
def payload2curl(p):
    lines = re.compile("[\n\r]+").split(p.decode())
    start_line = re.search("^([A-Z]+) ([^ ]+) (HTTP\/[0-9\/]+)", lines[0])
    method = start_line.group(1)
    url = start_line.group(2)
    version = start_line.group(3)  # Never used

    del lines[0]
    headers = []
    for line in lines:
        if ":" in line:
            headers.append("-H '{}'".format(line))
        if "Host:" in line:
            host_header = re.search("^Host: (.*)", line)
            host_name = host_header.group(1)

    if host_name not in url:
        url = "http://{}/{}".format(host_name, url)
    curl = "curl '{}' \\\n -X {} \\\n".format(url, method)
    curl += " \\\n".join(headers)
    return curl