示例#1
0
    def evalScript(self, script, tag=None):
        if log.ThugOpts.verbose or log.ThugOpts.debug:
            log.info(script)

        result = 0

        try:
            log.JSClassifier.classify(
                log.ThugLogging.url
                if log.ThugOpts.local else log.last_url_fetched, script)

            if log.ThugOpts.code_logging:
                log.ThugLogging.add_code_snippet(script, 'Javascript',
                                                 'Contained_Inside')
        except Exception:
            pass

        if tag:
            self.doc.current = tag
        else:
            try:
                body = self.doc.body
            except Exception:
                # This code is for when you are desperate :)
                body = self.doc.getElementsByTagName('body')[0]

            if body and body.tag.contents:
                self.doc.current = body.tag.contents[-1]
            else:
                self.doc.current = self.doc.doc.contents[-1]

        with self.context as ctxt:
            try:
                ast = AST(script, self)
            except Exception:
                log.warning(traceback.format_exc())
                return result

            if log.ThugOpts.Personality.isIE():
                cc = CCInterpreter()
                script = cc.run(script)

            shellcode = Shellcode.Shellcode(self, ctxt, ast, script)
            result = shellcode.run()

        log.ThugLogging.ContextAnalyzer.analyze(self)
        return result
示例#2
0
文件: Window.py 项目: byinarie/thug
    def evalScript(self, script, tag=None):
        result = 0

        try:
            log.JSClassifier.classify(
                '[Local analysis]' if log.ThugOpts.local else self.url, script)

            if log.ThugOpts.code_logging:
                log.ThugLogging.add_code_snippet(script, 'Javascript',
                                                 'Contained_Inside')
        except:  # pylint:disable=bare-except
            pass

        if tag:
            self.doc.current = tag
        else:
            try:
                body = self.doc.body
            except:  # pylint:disable=bare-except
                # This code is for when you are desperate :)
                body = self.doc.getElementsByTagName('body')[0]

            if body and body.tag.contents:
                self.doc.current = body.tag.contents[-1]
            else:
                self.doc.current = self.doc.doc.contents[-1]

        with self.context as ctxt:
            try:
                ast = AST(self, script)
            except:  # pylint:disable=bare-except
                log.debug(traceback.format_exc())
                return result

            if log.ThugOpts.Personality.isIE():
                cc = CCInterpreter()
                script = cc.run(script)

            shellcode = Shellcode.Shellcode(self, ctxt, ast, script)
            result = shellcode.run()

        return result