Beispiel #1
0
    def list_hostandsession():
        hosts = Host.list_hosts()
        sessions = HeartBeat.list_sessions()

        # 初始化session列表
        for host in hosts:
            host['session'] = None

        hosts_with_session = []

        # 聚合Session和host
        host_exist = False
        for session in sessions:
            for host in hosts:
                if session.get("session_host") == host.get('ipaddress'):
                    temp_host = copy.deepcopy(host)
                    temp_host['session'] = session
                    hosts_with_session.append(temp_host)
                    host_exist = True
                    break

            if host_exist is True:
                host_exist = False
            else:
                if session.get("session_host") is None or session.get(
                        "session_host") == "":
                    host_exist = False
                else:
                    # 减少新建无效的host
                    if session.get("available"):
                        host_create = Host.create_host(
                            session.get("session_host"))
                    else:
                        host_create = Host.create_host("255.255.255.255")
                    host_create['session'] = session
                    hosts_with_session.append(host_create)
                    host_exist = False

        for host in hosts:
            add = True
            for temp_host in hosts_with_session:
                if temp_host.get("id") == host.get("id"):
                    add = False
                    break
            if add:
                hosts_with_session.append(host)

        # 设置host的proxy信息
        # 收集所有hostip
        ipaddress_list = []
        for host in hosts_with_session:
            ipaddress_list.append(host.get('ipaddress'))

        i = 0
        for one in hosts_with_session:
            one["order_id"] = i
            i += 1

        return hosts_with_session
Beispiel #2
0
    def list():
        route_list = Route.list_route()
        socks_list = Socks.list_msf_socks()
        portfwds = PortFwd.list_portfwd()
        # 检查host对应的路由信息
        ipaddresses = []

        hosts = Host.list_hosts()
        for onehost in hosts:
            ipaddresses.append(onehost.get("ipaddress"))
        route_session_list = Route.get_match_route_for_ipaddress_list(
            ipaddresses)
        if route_session_list is None:
            for host in hosts:
                host['route'] = {'type': 'DIRECT', 'data': None}
        else:
            try:
                for host, route_session in zip(hosts, route_session_list):
                    sessionid = route_session.get('session')
                    if sessionid is None:
                        # TODO 处理socks代理类型
                        host['route'] = {'type': 'DIRECT', 'data': None}
                    else:
                        host['route'] = {'type': 'ROUTE', 'data': sessionid}
            except Exception as E:
                logger.error(E)

        result = {
            'socks': socks_list,
            'routes': route_list,
            'portfwds': portfwds,
            'hostsRoute': hosts
        }

        context = data_return(200, CODE_MSG.get(200), result)
        return context