示例#1
0
    def prepare_fuzzing(self, depth: int):
        # define necessary variables
        fuzz_data = FuzzData()
        nets: list = fuzz_data.get_ospf_networks()
        statespace = Statespace(depth, nets)
        properties: dict = pp.parse_properties(fuzz_data)
        fib = Fib(fuzz_data)

        # set fuzzing approach state variables
        self.search_plan = statespace.get_neighbor_heuristic_plan(
            properties["reachability"], fuzz_data)
        self.search_stats = statespace.get_fuzzing_stats()
        fw.write_search_plan(self.search_plan)
        self.transition = StateTransition.PartialRevert(fuzz_data)
        self.verification = Ver.Verification(properties, fib, fuzz_data)
示例#2
0
def find_heuristic_links(properties: dict, max_depth,
                         fuzz_data: FuzzData) -> list:
    links = []
    topo = fuzz_data.get_topo()
    topo_name = topo["meta"]["name"]
    topo_containers = topo["containers"]

    for prop in properties.values():
        prop_links = set([])
        src_container = prop["container_name"].split("-")[1]

        src_links = find_container_links(src_container, topo_containers,
                                         topo_name)

        if len(src_links) > max_depth:
            links.append([])
            continue
        else:
            prop_links.update(src_links)

        for src_link in src_links:
            neighbor_name = get_neighbor_name(src_link, src_container)
            neighbor_links = find_container_links(neighbor_name,
                                                  topo_containers, topo_name)

            if len(neighbor_links) >= max_depth:
                continue
            else:
                prop_links.update(neighbor_links)

        links.append(list(prop_links))

    return links
示例#3
0
def find_property_hops(prop: dict, fib: Fib, fuzz_data: FuzzData) -> list:
    """ Find the networks associated with each property

    :return: a set of IP addresses (without a netmask)
    """
    src_dev: str = prop["container_name"]
    dest_network: str = prop["dest_sim_net"]

    nets = []

    while True:
        next_hops: list = fib.find_next_hops(src_dev, dest_network)

        if next_hops == []:
            # container is directly connected to destination network
            break
        elif next_hops is None:
            print(clr("No path to {}".format(dest_network), 'red'))
            break
        else:
            src_dev = fuzz_data.find_ip_device(next_hops[0])

            if not src_dev:
                print(
                    clr(
                        "Next hop {} not present {}".format(
                            src_dev, dest_network), 'red'))
                break

            nets.extend(next_hops)

    return nets
示例#4
0
def parse_iso_props(raw_iso_props: list, fuzz_data: FuzzData) -> dict:
    iso_properties = dict()
    topo: dict = fuzz_data.get_topo()
    ospf_links = fuzz_data.get_ospf_networks()

    for idx, raw_property in enumerate(raw_iso_props, start=1):
        iso_prop = dict()
        dest_sim_ip, dest_sim_net = fuzz_data.get_nat_ip(raw_property["dest"])

        iso_prop["src_name"] = prepend_topo(topo["meta"]["name"], raw_property["src"])
        iso_prop["dest_sim_net"] = dest_sim_net
        iso_prop["trap_ips"] = find_trap_ips(raw_property["traps"], topo,
                                             ospf_links, fuzz_data)

        iso_properties.update({idx: iso_prop})

    return iso_properties
示例#5
0
def find_trap_ips(trap_nodes: list, topo: dict, ospf_links, fuzz_data: FuzzData) -> list:
    trap_ips = []
    topo_name = fuzz_data.get_topo()["meta"]["name"]

    for trap_node in trap_nodes:
        node_ifaces = find_container_ifaces(topo, trap_node)
        trap_ips.extend(find_ospf_ips(node_ifaces, ospf_links, topo_name, fuzz_data))

    return trap_ips
示例#6
0
def find_ospf_ips(node_ifaces: list, ospf_links, topo_name, fuzz_data: FuzzData) -> list:
    ospf_ips = []

    for iface in node_ifaces:
        sim_net_name = prepend_topo(topo_name, iface["network"])

        if sim_net_name in ospf_links:
            orig_ip = str(ipaddress.IPv4Interface(iface["ipaddr"]).ip)
            dest_sim_ip, dest_sim_net = fuzz_data.get_nat_ip(orig_ip)
            ospf_ips.append(dest_sim_ip)

    return ospf_ips
示例#7
0
def heuristic(max_depth: int, properties: dict, fuzz_data: FuzzData):
    """ Makes a search plan based on a heuristic """
    ospf_links = fuzz_data.get_ospf_networks()

    heuristic_links: list = find_heuristic_links(properties, max_depth,
                                                 fuzz_data)
    pretty_print_property_links(heuristic_links)

    heuristic_subplan: list = gen_heuristic_subplan(max_depth, heuristic_links)
    heuristic_plan: list = gen_full_plan(max_depth, heuristic_subplan,
                                         ospf_links)

    return heuristic_plan
示例#8
0
文件: fib.py 项目: PetarMI/thesis-eth
 def __init__(self, fuzz_data: FuzzData):
     self.dev2vm = fuzz_data.get_dev2vm()
     self.fib = self.prepare_fib()