Ejemplo n.º 1
0
def ServerEnum():
    "Enumerates all servers on the network"
    resume = 0
    while 1:
        data, total, resume = win32net.NetServerEnum("", 100,
                                                     win32netcon.SV_TYPE_ALL,
                                                     None, resume)
        # data, total, resume = win32net.NetServerEnum("\\\\RCHATEAU-HP", 100, win32netcon.SV_TYPE_ALL, None, resume)
        print(str(total))
        print(str(resume))
        for s in data:
            verbose("Server %s" % s['name'])
            # Now loop over the shares.
            shareresume = 0
            while 1:
                sharedata, total, shareresume = win32net.NetShareEnum(
                    GlobalServer, 2, shareresume)
                for share in sharedata:
                    verbose(
                        "    %(netname)s (%(path)s):%(remark)s - in use by %(current_uses)d users"
                        % share)
                if not shareresume:
                    break
        if not resume:
            break
Ejemplo n.º 2
0
def Main():
    cgiEnv = lib_common.CgiEnv()
    hostname = cgiEnv.GetId()

    nodeHost = lib_common.gUriGen.HostnameUri(hostname)

    grph = cgiEnv.GetGraph()

    # Loop over the shares.
    shareresume = 0
    while 1:
        try:
            # If running on the local machine, pass the host as None otherwise authorization is checked
            # just like a remote machine, which means User Account Control (UAC) disabling,
            # and maybe setting LocalAccountTokenFilterPolicy=1
            if lib_util.IsLocalAddress(hostname):
                hostname_or_None = None
                level = 2  # 1,2
            else:
                hostname_or_None = hostname
                level = 1  # 1,2

            sharedata, total, shareresume = win32net.NetShareEnum(
                hostname_or_None, level, shareresume)

        except Exception:
            # "Access is denied."
            exc = sys.exc_info()[1]
            lib_common.ErrorMessageHtml("Hostname=" + hostname +
                                        ". Exception:" + str(exc))

        for share in sharedata:
            sys.stderr.write("share=%s\n" % (str(share)))
            # share={'remark': 'Remote Admin', 'passwd': None, 'current_uses': 0, 'netname': 'ADMIN$', 'max_uses': 4294967295, 'path': 'C:\\\\Windows', 'type': 2147483648, 'permissions': 0}
            share_netname = share['netname']
            try:
                share_path = share['path']
                share_remark = share['remark']
            except:
                share_path = ""
                share_remark = ""

            shareNode = lib_common.gUriGen.SmbShareUri("//" + hostname + "/" +
                                                       share_netname)
            grph.add((nodeHost, pc.property_smbshare, shareNode))

            if share_path:
                # TODO: Horrible display. Strange because this is encoded in the function.
                # mountNode = lib_common.gUriGen.FileUri( share_path.replace('\\','/') )
                mountNode = lib_common.gUriGen.FileUri(share_path)
                grph.add((shareNode, pc.property_smbmount, mountNode))

            if share_remark:
                grph.add((shareNode, pc.property_information,
                          lib_common.NodeLiteral(share_remark)))

        if not shareresume:
            break

    cgiEnv.OutCgiRdf()
Ejemplo n.º 3
0
    def get_shares(self):
        """
        Get the Windows shares.

        :return:
        """

        win32net.NetShareEnum(self._ip)
Ejemplo n.º 4
0
def Main():
    cgiEnv = lib_common.ScriptEnvironment()
    hostname = cgiEnv.GetId()

    nodeHost = lib_uris.gUriGen.HostnameUri(hostname)

    grph = cgiEnv.GetGraph()

    # Loop over the shares.
    shareresume = 0
    while 1:
        try:
            # If running on the local machine, pass the host as None otherwise authorization is checked
            # just like a remote machine, which means User Account Control (UAC) disabling,
            # and maybe setting LocalAccountTokenFilterPolicy=1
            if lib_util.is_local_address(hostname):
                hostname_or_None = None
                level = 2  # 1,2
            else:
                hostname_or_None = hostname
                level = 1  # 1,2

            sharedata, total, shareresume = win32net.NetShareEnum(
                hostname_or_None, level, shareresume)

        except Exception as exc:
            # "Access is denied."
            lib_common.ErrorMessageHtml("Hostname=" + hostname +
                                        ". Exception:" + str(exc))

        for share in sharedata:
            logging.debug("share=%s", str(share))
            # share={'remark': 'Remote Admin', 'passwd': None, 'current_uses': 0, 'netname': 'ADMIN$', 'max_uses': 4294967295, 'path': 'C:\\\\Windows', 'type': 2147483648, 'permissions': 0}
            share_netname = share['netname']
            try:
                share_path = share['path']
                share_remark = share['remark']
            except:
                share_path = ""
                share_remark = ""

            shareNode = lib_uris.MachineBox(hostname).SmbShareUri(
                share_netname)
            grph.add((nodeHost, pc.property_smbshare, shareNode))

            if share_path:
                mountNode = lib_uris.gUriGen.FileUri(share_path)
                grph.add((shareNode, pc.property_smbmount, mountNode))

            if share_remark:
                grph.add((shareNode, pc.property_information,
                          lib_util.NodeLiteral(share_remark)))

        if not shareresume:
            break

    cgiEnv.OutCgiRdf()
Ejemplo n.º 5
0
def cidrScan(target):
    print('Scanning for %s') % target
    for ip in IPNetwork(target):
        try:
            shares, _, _ = win32net.NetShareEnum(ip, 0)
            print('list of shares for %s') % ip
            for share in shares:
                print(share)
        except:
            pass
    print('/FIN')
    sys.exit(2)
Ejemplo n.º 6
0
def singleScan(target):
    print('Scanning for %s') % target
    try:
        shares, _, _ = win32net.NetShareEnum(target, 0)
        print(sharess)
        print('list of shares for %s') % ip
        for share in shares:
            print(share)
    except:
        pass

    print('/FIN')
    sys.exit(2)
Ejemplo n.º 7
0
def ServerEnum():
    "Enumerates all servers on the network"
    resume = 0
    while 1:
        data, total, resume = win32net.NetServerEnum(server, 100, win32netcon.SV_TYPE_ALL, None, resume)
        for s in data:
            verbose("Found server %s" % s['name'])
            # Now loop over the shares.
            shareresume=0
            while 1:
                sharedata, total, shareresume = win32net.NetShareEnum(server, 2, shareresume)
                for share in sharedata:
                    verbose(" %(netname)s (%(path)s):%(remark)s - in use by %(current_uses)d users" % share)
                if not shareresume:
                    break
        if not resume:
            break
    print "Enumerated all the servers on the network"
Ejemplo n.º 8
0
    def get_all(self):
        if self.shares == []:
            resume = 1
            while resume:
                resume = 0
                sharelist = None
                try:
                    (sharelist, total,
                     resume) = win32net.NetShareEnum(wpc.conf.remote_server, 0,
                                                     resume, 9999)
                except:
                    print "[E] Can't check shares - not enough privs?"

                if sharelist:
                    for shareitem in sharelist:
                        s = share(shareitem['netname'])
                        self.shares.append(s)

        return self.shares
Ejemplo n.º 9
0
outfile = ""
optlist, args = getopt.getopt(sys.argv[1:], 'o:', ['output='])
for opt, a in optlist:
    if opt in ('-o', '--output'):
        outfile = a
COMPUTER_NAME = args[0]  # look at this machine
INFO_LEVEL = 2

if outfile:
    fp = open(outfile, "a+")

resume = 0
while 1:
    (shares, total, resume) = \
      win32net.NetShareEnum (
        COMPUTER_NAME,
        INFO_LEVEL,
        resume,
        win32netcon.MAX_PREFERRED_LENGTH
      )

    for share in shares:
        if not outfile:
            print(COMPUTER_NAME + ":" + share['netname'])
        else:
            fp.write(COMPUTER_NAME + ":" + share['netname'] + "\n")
    if not resume:
        break
if outfile:
    fp.close()
Ejemplo n.º 10
0
 def get_shares(self):
     win32net.NetShareEnum(self._ip)
Ejemplo n.º 11
0
import win32net

f = open("test.txt","r")
enumList = []

domain = #domain\\

for line in f:
    try:
        shares,_,_ = win32net.NetShareEnum(f'{domain}{line}',0)
        enumList.append(line)
        print(shares)
    except Exception as e:
        if "denied" in str(e):
            print(f"Found {line}")
            enumList.append(line)

f.close()

print(enumList)
print "USERS"
print "=========="
for user in users[0]:
    print user['name']
print ""

#print groups
groups = win32net.NetGroupEnum('localhost', 0)
print "GROUPS"
print "=========="
for group in groups[0]:
    print group['name']
print ""

#print shares
shares = win32net.NetShareEnum('localhost', 0)
print "SHARES"
print "=========="
for share in shares[0]:
    print share['netname']
print ""

#print servers
servers = win32net.NetServerEnum(None, 100)
print "SERVERS"
print "=========="
for server in servers[0]:
    print server['name']
print ""