Пример #1
0
def run(target='192.168.1.1',
        ports=[
            21, 22, 23, 25, 80, 110, 111, 135, 139, 443, 445, 554, 993, 995,
            1433, 1434, 3306, 3389, 8000, 8008, 8080, 8888
        ]):
    """
    Run a portscan against a target hostname/IP address

    `Optional`
    :param str target: Valid IPv4 address
    :param list ports: Port numbers to scan on target host
    :returns: Results in a nested dictionary object in JSON format

    Returns onlne targets & open ports as key-value pairs in dictionary (JSON) object

    """
    global tasks
    global threads
    global results
    if not util.ipv4(target):
        raise ValueError("target is not a valid IPv4 address")
    if _ping(target):
        for port in ports:
            tasks.put_nowait((_scan, (target, port)))
        for i in range(1, tasks.qsize()):
            threads['portscan-%d' % i] = _threader()
        for t in threads:
            threads[t].join()
        return json.dumps(results[target])
    else:
        return "Target offline"
Пример #2
0
def run(target='127.0.0.1', subnet=False, ports=[21,22,23,25,80,110,111,135,139,443,445,993,995,1433,1434,3306,3389,8000,8008,8080,8888]):    
    """
    Run a portscan against a target hostname/IP address
        
    :param str target: Valid IPv4 address
    :param list ports: Port numbers to scan on target host
    :returns: Results in a nested dictionary object in JSON format
    :rtype: dict
    """
    try:
        if not util.ipv4(target):
            raise ValueError("target is not a valid IPv4 address")
        task = collections.namedtuple('Target', ['host', 'port'])
        stub = '.'.join(target.split('.')[:-1]) + '.%d'
        util.debug('Scanning for online hosts in subnet {} - {}'.format(stub % 1, stub % 255))
        if subnet:
            for x in range(1,255):
                if _ping(stub % x):
                    globals()['targets'].append(stub % x)
                    for port in ports:
                        globals()['tasks'].put_nowait((_scan, task(stub % x, port)))
        else:
            globals()['targets'].append(target)
            if _ping(target):
                for port in ports:
                    globals()['tasks'].put_nowait((_scan, task(target, port)))
        if globals()['tasks'].qsize():
            for i in range(1, int((globals()['tasks'].qsize() / 100) if globals()['tasks'].qsize() >= 100 else 1)):
                threads['portscan-%d' % i] = _threader(globals()['tasks'])
            if __results and len(__results):
                return dict({k: __results[k] for k in sorted(__results.keys()) if k in globals()['targets']})
            else:
                return "Target(s) offline"
    except Exception as e:
        util.debug("{} error: {}".format(_scan.func_name, str(e)))
Пример #3
0
def run(target='192.168.1.1', ports=[21,22,23,25,80,110,111,135,139,443,445,554,993,995,1433,1434,3306,3389,8000,8008,8080,8888]):
    """
    Run a portscan against a target hostname/IP address

    `Optional`
    :param str target: Valid IPv4 address
    :param list ports: Port numbers to scan on target host
    :returns: Results in a nested dictionary object in JSON format

    Returns onlne targets & open ports as key-value pairs in dictionary (JSON) object

    """
    global tasks
    global threads
    global results
    if not util.ipv4(target):
        raise ValueError("target is not a valid IPv4 address")
    if _ping(target):
        for port in ports:
            tasks.put_nowait((_scan, (target, port)))
        for i in range(1, tasks.qsize()):
            threads['portscan-%d' % i] = _threader()
        for t in threads:
            threads[t].join()
        return json.dumps(results[target])
    else:
        return "Target offline"
Пример #4
0
def run(target='192.168.1.1',
        subnet=False,
        ports=[
            21, 22, 23, 25, 80, 110, 111, 135, 139, 443, 445, 993, 995, 1433,
            1434, 3306, 3389, 8000, 8008, 8080, 8888
        ]):
    """ 
    Run a portscan against a target hostname/IP address

    `Optional`
    :param str target: Valid IPv4 address
    :param list ports: Port numbers to scan on target host
    :returns: Results in a nested dictionary object in JSON format

    Returns onlne targets & open ports as key-value pairs in dictionary (JSON) object
    """
    #    try:
    if not util.ipv4(target):
        raise ValueError("target is not a valid IPv4 address")
    print 'Scanning {} for open ports'.format(target)
    globals()['targets'].append(target)
    if _ping(target):
        for port in ports:
            globals()['tasks'].put_nowait((_scan, (target, port)))
    if globals()['tasks'].qsize():
        for i in range(
                1,
                int((globals()['tasks'].qsize() /
                     100) if globals()['tasks'].qsize() >= 100 else 1)):
            threads['portscan-%d' % i] = _threader()
        if len(globals()['results']):
            return dict({
                k: globals()['results'][k]
                for k in sorted(globals()['results'].keys())
                if k in globals()['targets']
            })
        else:
            return "Target(s) offline"