コード例 #1
0
    def _parse_mongodb(self, sj: dict, task: IscoutTask, level: int,
                       portinfo: PortInfo):
        """
        解析mongodb的banner和一些其他的信息
        总之就是port里的信息
        :param sj:
        :param task:
        :param level:
        :param portinfo:
        :return:
        """
        res = False
        if not sj.__contains__("data") or not sj["data"].__contains__(
                "mongodb"):
            return
        try:
            sjmongodb = sj['data']['mongodb']
            succ = sjmongodb["status"]
            if succ != "success":
                return

            protocol = sjmongodb["protocol"]
            if protocol != "mongodb":
                return

            if portinfo.service != protocol:
                portinfo.service = protocol

            self._get_port_timestamp(sjmongodb, portinfo)

            # 开始构建mongodb的banner

            mres = sjmongodb.get('result')
            if mres is None:
                return
            mdata = MongoDB()
            ismaster = mres.get('is_master')
            mdata.is_master = ismaster
            buildinfo = mres.get('build_info')
            mdata.build_info = buildinfo
            # 因为port里面有version,所以对version赋值
            version = buildinfo.get('version')
            portinfo.version = version

            portinfo.banner = mdata.build_banner()
            # mongodb的banner
            mdata.banner = portinfo.banner
            res = True
            portinfo.set_mongodb(mdata)

        except:
            self._logger.error(
                f"Parse mongodb protocal error, err:{traceback.format_exc()}")
        return res
コード例 #2
0
    def _parse_redis(self, sj: dict, task: IscoutTask, level: int,
                     portinfo: PortInfo):
        """
        解析redis的banner和一些其他的信息
        总之就是port里的信息
        :param sj:
        :param task:
        :param level:
        :param portinfo:
        :return:
        """
        res = False
        if not sj.__contains__("data") or not sj["data"].__contains__("redis"):
            return
        try:
            sjredis = sj['data']['redis']
            succ = sjredis["status"]
            if succ != "success":
                return

            protocol = sjredis["protocol"]
            if protocol != "redis":
                return

            if portinfo.service != protocol:
                portinfo.service = protocol

            self._get_port_timestamp(sjredis, portinfo)

            # 开始构建redis的banner
            result = sjredis.get('result', {})
            rdata = Redis()
            rdata.info_response = result.pop('info_response', None)

            rdata.ping_response = result.pop('ping_response', None)
            portinfo.banner = rdata.build_banner()
            rdata.banner = portinfo.banner

            portinfo.version = result.pop('version')
            portinfo.os = result.pop('os')
            portinfo.extrainfo = json.dumps(result)
            res = True
            portinfo.set_redis(rdata)

        except:
            self._logger.error(
                f"Parse redis protocal error, err:{traceback.format_exc()}")
        return res