Ejemplo n.º 1
0
def _setHTTPUserAgent():
    """
    @function Set the HTTP User-Agent header.
    """
    if conf.agent:
        debugMsg = "setting the HTTP User-Agent header"
        logger.debug(debugMsg)

        conf.httpHeaders[HTTP_HEADER.USER_AGENT] = conf.agent

    if conf.randomAgent:
        infoMsg = "loading random HTTP User-Agent header(s) from "
        infoMsg += "file '%s'" % paths.USER_AGENTS
        logger.log(CUSTOM_LOGGING.SYSINFO, infoMsg)
        try:
            userAgents = getFileItems(paths.USER_AGENTS)
        except IOError:
            warnMsg = "unable to read HTTP User-Agent header "
            warnMsg += "file '%s'" % paths.USER_AGENTS
            logger.log(CUSTOM_LOGGING.WARNING, warnMsg)
            return

        userAgent = random.sample(userAgents, 1)
        infoMsg = "fetched random HTTP User-Agent header from "
        infoMsg += "file '%s': '%s'" % (paths.USER_AGENTS, userAgent)
        logger.log(CUSTOM_LOGGING.SYSINFO, infoMsg)

        conf.httpHeaders[HTTP_HEADER.USER_AGENT] = userAgent
Ejemplo n.º 2
0
def _setHTTPUserAgent():
    """
    @function Set the HTTP User-Agent header.
    """
    if conf.agent:
        debugMsg = "setting the HTTP User-Agent header"
        logger.debug(debugMsg)

        conf.httpHeaders[HTTP_HEADER.USER_AGENT] = conf.agent

    if conf.randomAgent:
        infoMsg = "loading random HTTP User-Agent header(s) from "
        infoMsg += "file '%s'" % paths.USER_AGENTS
        logger.log(CUSTOM_LOGGING.SYSINFO, infoMsg)
        try:
            userAgents = getFileItems(paths.USER_AGENTS)
        except IOError:
            warnMsg = "unable to read HTTP User-Agent header "
            warnMsg += "file '%s'" % paths.USER_AGENTS
            logger.log(CUSTOM_LOGGING.WARNING, warnMsg)
            return

        userAgent = random.sample(userAgents, 1)[0]
        infoMsg = "fetched random HTTP User-Agent header from "
        infoMsg += "file '%s': '%s'" % (paths.USER_AGENTS, userAgent)
        logger.log(CUSTOM_LOGGING.SYSINFO, infoMsg)

        conf.httpHeaders[HTTP_HEADER.USER_AGENT] = userAgent
Ejemplo n.º 3
0
def _setHTTPReferer():
    """
    Set the HTTP Referer
    """

    if conf.referer:
        debugMsg = "setting the HTTP Referer header"
        logger.debug(debugMsg)

        conf.httpHeaders[HTTP_HEADER.REFERER] = conf.referer
Ejemplo n.º 4
0
def _setHTTPCookies():
    """
    Set the HTTP Cookie header
    """

    if conf.cookie:
        debugMsg = "setting the HTTP Cookie header"
        logger.debug(debugMsg)

        conf.httpHeaders[HTTP_HEADER.COOKIE] = conf.cookie
Ejemplo n.º 5
0
def _setHTTPReferer():
    """
    Set the HTTP Referer
    """

    if conf.referer:
        debugMsg = "setting the HTTP Referer header"
        logger.debug(debugMsg)

        conf.httpHeaders[HTTP_HEADER.REFERER] = conf.referer
Ejemplo n.º 6
0
def _setHTTPCookies():
    """
    Set the HTTP Cookie header
    """

    if conf.cookie:
        debugMsg = "setting the HTTP Cookie header"
        logger.debug(debugMsg)

        conf.httpHeaders[HTTP_HEADER.COOKIE] = conf.cookie
Ejemplo n.º 7
0
def update():
    if not conf.update:
        return

    success = False

    if not os.path.exists(
            os.path.join(os.path.dirname(paths.POCSUITE_ROOT_PATH), ".git")):
        err_msg = ("not a git repository. Please checkout the 'pocsuite' "
                   "repository from GitHub (e.g. 'git clone --depth 1"
                   "https://github.com/knownsec/Pocsuite.git pocsuite')")
        logger.error(err_msg)
    else:
        info_msg = ("updating pocsuite to the latest development version from "
                    "the GitHub repository")
        logger.info(info_msg)

        debug_msg = "pocsuite will try to update itself using 'git' command"
        logger.debug(debug_msg)

        dataToStdout("\r[%s] [INFO] update in progress " % time.strftime("%X"))

        try:
            # Reference:
            # http://blog.stastnarodina.com/honza-en/spot/python-unicodeencodeerror/
            process = subprocess.Popen("git checkout . && git pull %s HEAD" %
                                       GIT_REPOSITORY,
                                       shell=True,
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.PIPE,
                                       cwd=paths.POCSUITE_ROOT_PATH.encode(
                                           locale.getpreferredencoding()))
            poll_process(process, True)
            stdout, stderr = process.communicate()
            success = not process.returncode
        except (IOError, OSError) as ex:
            success = False
            stderr = "{}".format(ex)

        if success:
            info_msg = "{0} the latest revision '{1}'".format(
                "already at" if "Already" in stdout else "updated to",
                getRevisionNumber())
            logger.info(info_msg)
        else:
            if "Not a git repository" in stderr:
                err_msg = ("not a valid git repository. Please checkout the "
                           "'pocsuite' repository from GitHub "
                           "(e.g. 'git clone --depth 1 "
                           "https://github.com/knownsec/Pocsuite.git "
                           "pocsuite')")
                logger.error(err_msg)
            else:
                err_msg = "update could not be completed ('{}')".format(
                    re.sub(r"\W+", " ", stderr).strip())
                logger.error(err_msg)

    if not success:
        if IS_WIN:
            info_msg = ("for Windows platform it's recommended to use a Github"
                        "for Windows client for updating purposes "
                        "(http://windows.github.com/) or just download the "
                        "latest snapshot from {}".format(SITE))
        else:
            info_msg = ("for Linux platform it's required to install a "
                        "standard 'git' package (e.g.: "
                        "'sudo apt-get install git')")
        logger.info(info_msg)