Example #1
0
def mkDevice(screen, x, y, id):
    if id.isdigit():
        subnet = Subnet(screen, x, y)
        subnet.IP = IP(int(id))
        return subnet
    elif id == "N":
        dns = DNS(screen, x, y)
        dns.IP = str(ord(list(id)[0]))
        return dns
    elif id.isupper():
        router = Router(screen, x, y)
        router.IP = str(ord(list(id)[0]))
        router.selected = router.IP == "66"
        return router
    elif id.islower():
        if id == "h":
            host = Client(screen, x, y)
            host.name = "Alice"
            host.corespondent = "Bob"
        elif id == "x":
            host = Client(screen, x, y)
            host.name = "Bob"
            host.corespondent = "Alice"
        else:
            host = Host(screen, x ,y)
        host.IP = str(ord(list(id)[0]))
        return host
    else:
        print "Unrecognized unique identifier in sprite map"
        return None
Example #2
0
                querysocket.close()

                connection.close()

            elif sock == udpsocket:
                data, address = sock.recvfrom(1024)
                # print data.encode("hex"), address
                upstreamServer = ('8.8.8.8', 53)
                querysocket = socket(AF_INET, SOCK_DGRAM)
                querysocket.sendto(data, upstreamServer)

                udpresponse, add = querysocket.recvfrom(1024)
                print "UDP Responsed"

                respond_DNS = DNS(udpresponse)

                if respond_DNS.is_error():
                    udpresponse = respond_DNS.fake_an_answer(MyIP)

                sock.sendto(udpresponse, address)
            else:
                print "incorrect socket:", sock


if __name__ == '__main__':

    DNSProxy()

    sys.exit(0)
Example #3
0
        if not is_admin:
            print(
                " * ERROR: In order to test DNS-SD in unicast mode, the test suite must be run "
                "with elevated permissions")
            sys.exit(ExitCodes.ERROR)

    # Parse and validate command line arguments
    args = parse_arguments()
    validate_args(args)

    # Download up to date versions of each API specification
    init_spec_cache()

    # Start the DNS server
    if ENABLE_DNS_SD and DNS_SD_MODE == "unicast":
        DNS_SERVER = DNS()

    # Start the HTTP servers
    start_web_servers()

    exit_code = 0
    if "suite" not in vars(args):
        # Interactive testing mode. Await user input.
        try:
            while True:
                time.sleep(0.2)
        except KeyboardInterrupt:
            pass
    else:
        # Non-interactive testing mode. Tests carried out automatically.
        exit_code = run_noninteractive_tests(args)
def extractTCPFlows(entryList):
    finishedFlows = []
    # a map between flow's signature and flow
    ongoingFlows = {}

    for i in range(len(entryList)):
        entry = entryList[i]
        if entry.logID == const.PROTOCOL_ID and \
           entry.ip["tlp_id"] == const.TCP_ID:
            flow_signature = Flow.extractFlowSignature(entry)
            if flow_signature:
                if entry.tcp["SYN_FLAG"] and not entry.tcp["ACK_FLAG"]:
                    # capture a new flow by SYN packet
                    if not ongoingFlows.has_key(flow_signature):
                        # create a new flow
                        ongoingFlows[flow_signature] = Flow(flow_signature)
                        ongoingFlows[flow_signature].addPacket(entry, i)
                elif entry.tcp["FIN_FLAG"]:
                    # finish a TCP flow if there is one
                    if ongoingFlows.has_key(flow_signature):
                        ongoingFlows[flow_signature].addPacket(entry, i)
                        finishedFlows.append(ongoingFlows[flow_signature])
                        del ongoingFlows[flow_signature]
                else:
                    # add to existing ongoing flow
                    if ongoingFlows.has_key(flow_signature):
                        ongoingFlows[flow_signature].addPacket(entry, i)

    # wrap up anything leftover flow
    for flow in ongoingFlows.values():
        finishedFlows.append(flow)

    # filter out super short flow
    filteredFlows = []
    for f in finishedFlows:
        if len(f.flow) > 2:
            filteredFlows.append(f)

    # initiate the DNS trace
    dns = DNS(entryList)
    ipToURLMap = dns.getIpToURLMap()
    for f in filteredFlows:
        syn = f.flow[0]
        inverseIp = None
        if syn.ip["src_ip"] in ipToURLMap:
            inverseIp = syn.ip["src_ip"]
        elif syn.ip["dst_ip"] in ipToURLMap:
            inverseIp = syn.ip["dst_ip"]
        if inverseIp != None:
            f.setURL(ipToURLMap[inverseIp])
            if DNS_CHECK:
                print inverseIp + " -> " + str(ipToURLMap[inverseIp])

    if FLOW_CHECK:
        for f in finishedFlows:
            if f.properties["http"] != None:
                line = str(f.properties["http"]) + "\t" + str(len(f.flow)) + "\t" + \
                       util.convert_ts_in_human(f.flow[0].timestamp)
                if f.flow[0].rrcID != None:
                    line += "\t" + const.RRC_MAP[f.flow[0].rrcID]
                print line
                # print pw.printTCPEntry(f.flow[0])
        print "*" * 60
        print "Total # of flows are " + str(len(finishedFlows))
  
    return filteredFlows
Example #5
0
def extractTCPFlows(entryList):
    finishedFlows = []
    # a map between flow's signature and flow
    ongoingFlows = {}

    for i in range(len(entryList)):
        entry = entryList[i]
        if entry.logID == const.PROTOCOL_ID and \
           entry.ip["tlp_id"] == const.TCP_ID:
            flow_signature = Flow.extractFlowSignature(entry)
            if flow_signature:
                if entry.tcp["SYN_FLAG"] and not entry.tcp["ACK_FLAG"]:
                    # capture a new flow by SYN packet
                    if not ongoingFlows.has_key(flow_signature):
                        # create a new flow
                        ongoingFlows[flow_signature] = Flow(flow_signature)
                        ongoingFlows[flow_signature].addPacket(entry, i)
                elif entry.tcp["FIN_FLAG"]:
                    # finish a TCP flow if there is one
                    if ongoingFlows.has_key(flow_signature):
                        ongoingFlows[flow_signature].addPacket(entry, i)
                        finishedFlows.append(ongoingFlows[flow_signature])
                        del ongoingFlows[flow_signature]
                else:
                    # add to existing ongoing flow
                    if ongoingFlows.has_key(flow_signature):
                        ongoingFlows[flow_signature].addPacket(entry, i)

    # wrap up anything leftover flow
    for flow in ongoingFlows.values():
        finishedFlows.append(flow)

    # filter out super short flow
    filteredFlows = []
    for f in finishedFlows:
        if len(f.flow) > 2:
            filteredFlows.append(f)

    # initiate the DNS trace
    dns = DNS(entryList)
    ipToURLMap = dns.getIpToURLMap()
    for f in filteredFlows:
        syn = f.flow[0]
        inverseIp = None
        if syn.ip["src_ip"] in ipToURLMap:
            inverseIp = syn.ip["src_ip"]
        elif syn.ip["dst_ip"] in ipToURLMap:
            inverseIp = syn.ip["dst_ip"]
        if inverseIp != None:
            f.setURL(ipToURLMap[inverseIp])
            if DNS_CHECK:
                print inverseIp + " -> " + str(ipToURLMap[inverseIp])

    if FLOW_CHECK:
        for f in finishedFlows:
            if f.properties["http"] != None:
                line = str(f.properties["http"]) + "\t" + str(len(f.flow)) + "\t" + \
                       util.convert_ts_in_human(f.flow[0].timestamp)
                if f.flow[0].rrcID != None:
                    line += "\t" + const.RRC_MAP[f.flow[0].rrcID]
                print line
                # print pw.printTCPEntry(f.flow[0])
        print "*" * 60
        print "Total # of flows are " + str(len(finishedFlows))

    return filteredFlows