pURL.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:pURL 作者: redteamsecurity 项目源码 文件源码
def assembleRequest(data, method, URL, safe, headerDict, proxyDict, verbose):


    # connect to the API endpoint, and send the data that was given
    # note the response variable will hold all of the information received back from the server
    try:
        if method == "GET":
            response = requests.get(URL, data, headers=headerDict,proxies=proxyDict, verify=safe)
        elif method == "POST":
            response = requests.post(URL, data, headers=headerDict, verify=safe, proxies=proxyDict)
        elif method == "PUT":
            response = requests.put(URL, data, headers=headerDict, verify=safe, proxies=proxyDict)
        elif method == "DELETE":
            response = requests.delete(URL, headers=headerDict, verify=safe, proxies=proxyDict)
        elif method == "OPTIONS":
            response = requests.options(URL, verify=safe, proxies=proxyDict)
        elif method == "HEAD":
            response = requests.head(URL, verify=safe, proxies=proxyDict)

        else:
            print "method not currently supported"
            print "current methods: GET, POST, PUT, DELETE, OPTIONS, HEAD"
            sys.exit()

        print ""
        # print response code (i.e. 404, 500, 200)
        print response.status_code
        if verbose:
            # response headers are saved as a dictionary. Loop through the dictionary and print information.
            for i in response.headers:
                print i + ":", response.headers[i]
            print ""
            # output response body
            print response.content
        else:
            pass
        print ""
        print ""

    except requests.exceptions.Timeout:
        print "Connection timeout - make sure a WAF or firewall rule is not blocking traffic."
    except requests.exceptions.TooManyRedirects:
        print "Too many redirects - URL may be bad"
    except requests.exceptions.SSLError:
        print "could not verify HTTPS certificate."
        print 'pURL tries to verify HTTPS certificates. If using a proxy try "--unsafe"'
    except requests.exceptions.RequestException as e:
        print e
    except Exception, e:
        print "catastrophic failure see below for details"
        print e
        sys.exit(1)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号