[Python] upload file using PycURL – Penetration Testing

PycURL is a Python interface to libcurl, the multiprotocol file transfer library. Similarly to the urllib Python module, PycURL can be used to fetch objects identified by a URL from a Python program. Beyond simple fetches however PycURL exposes most of the functionality of libcurl, including:

Speed – libcurl is very fast and PycURL, being a thin wrapper above libcurl, is very fast as well. PycURL was benchmarkedto be several times faster than requests.

Features including multiple protocol support, SSL, authentication and proxy options. PycURL supports most of libcurl’s callbacks.

Multi and share interfaces.

Sockets used for network operations, permitting integration of PycURL into the application’s I/O loop (e.g., using Tornado).


Python 2.6, 2.7 or 3.1 through 3.6.

libcurl 7.19.0 or better.


Download source and binary distributions from PyPI or Bintray. Binary wheels are now available for 32 and 64 bit Windows versions.

Please see INSTALL.rst for installation instructions. If installing from a Git checkout, please follow instruction in the Git Checkout section of INSTALL.rst.


import pycurl
import StringIO

def do_http_request(method, url, post_data=”, upload_file=None):
ch = pycurl.Curl()
buf = StringIO.StringIO()
ch.setopt(ch.URL, url)
ch.setopt(ch.CUSTOMREQUEST, method)
if upload_file != None:
ch.setopt(ch.HTTPPOST, [(‘file’, (ch.FORM_FILE, upload_file[‘file_path’], \
ch.FORM_FILENAME, upload_file[‘file_name’]))])
if method == self.METHOD_POST:
ch.setopt(ch.POSTFIELDS, urlencode(post_data))

ch.setopt(ch.TIMEOUT, 30)
ch.setopt(ch.WRITEFUNCTION, buf.write)
content = buf.getvalue()
return content

The above code is written in a library with pycurl http request to call a generic function.

upload_file is a dict type requires two key, file_path (specify the file path to upload) and file_name (file name specified after the upload).

ch.FORM_FILE : Specifies the path to the file you want to upload

ch.FORM_FILENAME : Specifies the name of the file you want to upload

The post [Python] upload file using PycURL appeared first on Penetration Testing.


Deixe um comentário

Preencha os seus dados abaixo ou clique em um ícone para log in:

Logotipo do WordPress.com

Você está comentando utilizando sua conta WordPress.com. Sair /  Alterar )

Foto do Google+

Você está comentando utilizando sua conta Google+. Sair /  Alterar )

Imagem do Twitter

Você está comentando utilizando sua conta Twitter. Sair /  Alterar )

Foto do Facebook

Você está comentando utilizando sua conta Facebook. Sair /  Alterar )


Conectando a %s