Exemplo n.º 1
0
def sipEnumerator():
    value_errors = []
    conf.verb = 0

    try:
        client_ip = netifaces.ifaddresses(conf.iface)[2][0]['addr']
    except ValueError:
        value_errors.append(
            'Please specify a valid interface name with --if option.')

    message_type = options.message_type.lower(
    ) if options.message_type else "subscribe"

    user_list = [
        userName
        for userName in utilities.readFile(options.from_user).split("\n")
        if userName.isalnum()
    ]
    if len(user_list) <= 1:
        value_errors.append(
            "Error: From user not found. Please enter a valid From User list.")

    if options.target_network: target_networks = [options.target_network]
    else:
        content = utilities.readFile("ip_list.txt").split(";")
        if len(content[0]) <= 1:
            value_errors.append(
                "Error: Target IP not found. Please run SIP-NES first for detect the target IPs."
            )
        with open('ip_list.txt', 'r') as f:
            target_networks = [line.split(';')[0] for line in f.readlines()]

    utilities.check_value_errors(value_errors)
    utilities.printInital("Enumeration", conf.iface, client_ip)

    # combination of all target_networks with user_IDs
    target_network__user_id = [(target_network, user_id)
                               for target_network, user_id in
                               itertools.product(target_networks, user_list)]

    global counter
    global workQueue
    run_event = threading.Event()
    thread_join_time = 0.001
    print("running with {} threads".format(len(threadList)))
    for _ in threadList:
        thread = threading.Thread(target=sipenum_worker,
                                  args=(run_event, message_type,
                                        options.dest_port, client_ip))
        thread.daemon = True
        threads.append(thread)

    _prompt_new = "\33[38;5;6m{} user IDs will be checked for {} target networks.\nThere will be {} packages generated. Do you want to continue? (y/n)\33[0m\n"
    try:
        continue_flag = raw_input(
            _prompt_new.format(len(user_list), len(target_networks),
                               len(target_network__user_id)))
    except EOFError:
        print("STDIN is unavailable. Accepting answer as yes.")
        continue_flag = 'y'

    if continue_flag == 'y':
        for tn_ui in target_network__user_id:
            workQueue.put(tn_ui)
        for thread in threads:
            thread.start()  # invoke the 'run()' function in the class
        try:
            while not workQueue.empty():
                pass  # Wait for queue to empty<
        except KeyboardInterrupt:
            print("\nCTRL+C pressed, terminating SIP-ENUM gracefully")
        run_event.set()
        run_event.clear()
        try:
            for t in threads:
                t.join(thread_join_time)
        except KeyboardInterrupt:
            print(
                "\nCTRL+C pressed, but Mr. SIP is already trying to terminate SIP-ENUM gracefully. Please be patient."
            )
            for t in threads:
                t.join(thread_join_time)  # call the threads, finish
    elif continue_flag == 'n':
        print("\33[38;5;6mTerminating by user input\33[0m")
        run_event.set()
        run_event.clear()
        exit(0)
    else:
        print("\33[38;5;6mAnswer not understood. Please answer y/n.\33[0m")
        run_event.set()
        run_event.clear()
        exit(0)

    print(("[!] " + str(counter) + " SIP Extension Found."))
Exemplo n.º 2
0
def dosSmilator():
    value_errors = []
    conf.verb = 0

    try:
        client_ip = netifaces.ifaddresses(conf.iface)[2][0]['addr']
        client_netmask = netifaces.ifaddresses(conf.iface)[2][0]['netmask']
    except ValueError:
        value_errors.append(
            'Please specify a valid interface name with --if option.')
    message_type = options.message_type.lower(
    ) if options.message_type else "invite"

    utilities.check_value_errors(value_errors)
    utilities.promisc("on", conf.iface)
    utilities.printInital("DoS attack simulation", conf.iface, client_ip)

    i = 0
    while i < int(options.counter):
        try:
            toUser = random.choice(
                [line.rstrip('\n') for line in open(options.to_user)])
            fromUser = random.choice(
                [line.rstrip('\n') for line in open(options.from_user)])
            spUser = random.choice(
                [line.rstrip('\n') for line in open(options.sp_user)])
            userAgent = random.choice(
                [line.rstrip('\n') for line in open(options.user_agent)])

            pkt = IP(dst=options.target_network)
            client = pkt.src

            if options.random and not options.library:
                client = utilities.randomIPAddress()
            if options.manual and not options.library:
                client = random.choice([
                    line.rstrip('\n') for line in open(options.manual_ip_list)
                ])
            if options.subnet and not options.library:
                client = utilities.randomIPAddressFromNetwork(
                    client_ip, client_netmask, False)
            send_protocol = "scapy"
            if options.library:
                send_protocol = "socket"

            sip = sip_packet.sip_packet(str(message_type),
                                        str(options.target_network),
                                        str(options.dest_port), str(client),
                                        str(fromUser), str(toUser),
                                        str(userAgent), str(spUser),
                                        send_protocol)
            sip.generate_packet()
            i += 1
            utilities.printProgressBar(i, int(options.counter), "Progress: ")
        except (KeyboardInterrupt):
            utilities.promisc("off", conf.iface)
            print("Exiting traffic generation...")
            raise SystemExit

    print((
        "\033[31m[!] DoS simulation finished and {0} packet sent to {1}...\033[0m"
        .format(str(i), str(options.target_network))))
    utilities.promisc("off", conf.iface)
Exemplo n.º 3
0
def networkScanner():
    value_errors = []
    conf.verb = 0
    global counter

    try:
        client_ip = netifaces.ifaddresses(conf.iface)[2][0]['addr']
    except ValueError:
        value_errors.append(
            'Please specify a valid interface name with --if option.')

    message_type = options.message_type.lower(
    ) if options.message_type else "options"
    if options.target_network == None:
        value_errors.append(
            'Please specify a valid target network with --tn option.')
    if 'txt' in options.from_user:
        from_user = [
            userName
            for userName in utilities.readFile(options.from_user).split("\n")
            if userName.isalnum()
        ]
    else:
        from_user = [options.from_user]
    if 'txt' in options.to_user:
        to_user = [
            userName
            for userName in utilities.readFile(options.to_user).split("\n")
            if userName.isalnum()
        ]
    else:
        to_user = [options.to_user]

    if message_type == 'invite' or message_type == 'options':
        pass  # both fromUser and toUser should be accepted.
    elif message_type == 'register' or message_type == 'subscribe':
        to_user = ['']  # toUser should be omitted

    if 'txt' in options.from_user or '.txt' in options.to_user:
        print(
            "\033[33m\nYou gave a list of user names ('{}', '{}') for SIP-NES. This is yet an experimental feature. (WIP) \033[0m"
            .format(options.from_user, options.to_user))
        print(
            "\033[33mIf this was not what you wanted, specify user names with '--to' and '--from' arguments \033[0m \n"
        )

    utilities.check_value_errors(value_errors)

    if "-" in options.target_network:
        host_range = options.target_network.split("-")
        host, last = ipaddress.IPv4Address(unicode(
            host_range[0])), ipaddress.IPv4Address(unicode(host_range[1]))
        if ipaddress.IPv4Address(host) > ipaddress.IPv4Address(last):
            value_errors.append(
                "Error: Second IP address ({}) must bigger than first IP address ({})."
                .format(ipaddress.IPv4Address(host),
                        ipaddress.IPv4Address(last)))
        else:
            target_networks = [
                utilities.decimal_to_octets(host)
                for host in range(int(ipaddress.IPv4Address(host)),
                                  int(ipaddress.IPv4Address(last) + 1))
            ]
            target_network__fromUser__toUser = [
                (tn, fu, tu) for tn, fu, tu in itertools.product(
                    target_networks, from_user, to_user)
            ]
    elif "/" in options.target_network:
        target_networks = [
            host
            for host in ipaddress.IPv4Network(unicode(options.target_network),
                                              strict=False).hosts()
        ]
        target_network__fromUser__toUser = [
            (tn, fu, tu) for tn, fu, tu in itertools.product(
                target_networks, from_user, to_user)
        ]
    elif len(from_user) > 1 or len(to_user) > 1:
        print(
            "\033[33mCalculating all permutations of target network ('{}'), from user name list ('{}') and to user name list ('{}').\033[0m"
            .format(options.target_network, options.from_user,
                    options.to_user))
        print(
            "\033[33mDepending on the list sizes, this might take a long time.\033[0m \n"
        )
        target_network__fromUser__toUser = [
            (tn, fu, tu) for tn, fu, tu in itertools.product(
                [options.target_network], from_user, to_user)
        ]

    utilities.check_value_errors(value_errors)
    utilities.printInital("Network scan :", conf.iface, client_ip)

    thread_join_time = 0.01
    if '-' in options.target_network or '/' in options.target_network or (
            len(from_user) > 1 or len(to_user) > 1):  # Create new threads
        run_event = threading.Event()
        for _ in threadList:
            thread = threading.Thread(target=sipnes_worker,
                                      args=(run_event, message_type,
                                            options.dest_port, client_ip))
            thread.daemon = True
            threads.append(thread)

        _prompt_new = "\33[38;5;6m{} User names (to and from) will be checked for {} target networks.\nThere will be {} packages generated. Do you want to continue? (y/n)\33[0m\n"
        try:
            continue_flag = raw_input(
                _prompt_new.format(
                    len(from_user) + len(to_user), len(target_networks),
                    len(target_network__fromUser__toUser)))
        except EOFError:
            print("STDIN is unavailable. Accepting answer as yes.")
            continue_flag = 'y'
        if continue_flag == 'n':
            print("\33[38;5;6mTerminating by user input\33[0m")
            run_event.clear()
            exit(0)
        elif continue_flag != 'y' and continue_flag != 'n':
            print("\33[38;5;6mAnswer not understood. Please answer y/n.\33[0m")
            run_event.clear()
            exit(0)

        for tn_fu_tu in target_network__fromUser__toUser:
            workQueue.put(tn_fu_tu)
        for thread in threads:
            thread.start()
        try:
            while not workQueue.empty():
                pass
        except KeyboardInterrupt:
            print("\nCTRL+C pressed, terminating SIP-NES gracefully")
        run_event.set()
        run_event.clear()
        try:
            for t in threads:
                t.join(thread_join_time)
        except KeyboardInterrupt:
            print(
                "\nCTRL+C pressed, but Mr. SIP is already trying to terminate SIP-NES gracefully. Please be patient."
            )
            for t in threads:
                t.join(thread_join_time)  # call the threads, finish
    else:
        if len(from_user) == 1 and len(to_user) == 1:
            host = options.target_network
            sip = sip_packet.sip_packet(message_type,
                                        host,
                                        options.dest_port,
                                        client_ip,
                                        from_user=from_user[0],
                                        to_user=to_user[0],
                                        protocol="socket",
                                        wait=True)
            result = sip.generate_packet()

            if result["status"]:  # and result["response"]['code'] == 200:
                utilities.printResult(result, host, options.ip_list)
                counter += 1

    print((
        "\033[31m[!] Network scan process finished and {0} live IP address(s) found.\033[0m"
        .format(str(counter))))