def Main(): cgiEnv = lib_common.CgiEnv() hostname = cgiEnv.GetId() nodeHost = lib_common.gUriGen.HostnameUri(hostname) grph = cgiEnv.GetGraph() # Return the name of the computer, name of the user, and active and idle times for the session. # No special group membership is required for level 0 or level 10 calls. level = 10 try: # hostname = "Titi" for example lib_win32.WNetAddConnect(hostname) sessionList = win32net.NetSessionEnum(level, hostname) except Exception: lib_common.ErrorMessageHtml("Hostname=" + hostname + ". Exception:" + str(sys.exc_info())) for eltLst in sessionList: for keyLst in eltLst: valLst = eltLst[keyLst] grph.add((nodeHost, lib_common.MakeProp(keyLst), lib_common.NodeLiteral(valLst))) cgiEnv.OutCgiRdf()
def Main(): cgiEnv = lib_common.ScriptEnvironment() hostname = cgiEnv.GetId() node_host = lib_uris.gUriGen.HostnameUri(hostname) grph = cgiEnv.GetGraph() # Return the name of the computer, name of the user, and active and idle times for the session. # No special group membership is required for level 0 or level 10 calls. level = 10 try: lib_win32.WNetAddConnect(hostname) session_list = win32net.NetSessionEnum(level, hostname) except Exception as exc: lib_common.ErrorMessageHtml("Hostname=" + hostname + ". Exception:" + str(exc)) for elt_lst in session_list: for key_lst in elt_lst: val_lst = elt_lst[key_lst] grph.add((node_host, lib_common.MakeProp(key_lst), lib_util.NodeLiteral(val_lst))) cgiEnv.OutCgiRdf()
def Main(): cgiEnv = lib_common.ScriptEnvironment() hostname = cgiEnv.GetId() node_host = lib_uris.gUriGen.HostnameUri(hostname) grph = cgiEnv.GetGraph() try: lib_win32.WNetAddConnect(hostname) except Exception as exc: lib_common.ErrorMessageHtml("NetUserEnum:" + str(exc)) # This could be a parameter. Hard-coded value for the moment. if lib_util.is_local_address(hostname): level = 2 # 1,2 else: level = 2 # 1,2 logging.debug("hostname=%s level=%d", hostname, level) resume_handle = 0 while True: try: # Connects a computer to or disconnects a computer from a shared resource, or displays information about computer connections. # The command also controls persistent net connections. Used without parameters, net use retrieves a list of network connections. # net use [{DeviceName | *}] [\\ComputerName\ShareName[\volume]] [{Password | *}]] [/user:[DomainName\]UserName] # [/user:[DottedDomainName\]UserName] [/user: [UserName@DottedDomainName] [/savecred] [/smartcard] [{/delete | /persistent:{yes | no}}] # https://mail.python.org/pipermail/python-win32/2003-April/000961.html lst_users, total, resume_handle = win32net.NetUserEnum( hostname, level, win32netcon.FILTER_NORMAL_ACCOUNT, resume_handle) except Exception as exc: lib_common.ErrorMessageHtml("NetUserEnum:" + str(exc)) for usr_elt in lst_users: # {'comment': u'Built-in account for administering the computer/domain', 'workstations': u'', 'country_code': 0L, 'last_logon': 1426 # 729970L, 'full_name': u'', 'parms': u'', 'code_page': 0L, 'priv': 2L, 'auth_flags': 0L, 'logon_server': u'\\\\*', 'home_dir': u'', ' # usr_comment': u'', 'acct_expires': 4294967295L, 'bad_pw_count': 0L, 'logon_hours': '\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff # \xff\xff\xff\xff\xff\xff\xff\xff\xff', 'password': None, 'units_per_week': 168L, 'last_logoff': 0L, 'name': u'Administrator', 'max_s # torage': 4294967295L, 'num_logons': 11L, 'password_age': 191184801L, 'flags': 66083L, 'script_path': u''}, user_name = usr_elt['name'] node_user = survol_Win32_UserAccount.MakeUri(user_name, hostname) grph.add((node_host, pc.property_user, node_user)) try: txt_comment = usr_elt['comment'] grph.add((node_user, pc.property_information, lib_util.NodeLiteral(txt_comment))) except KeyError: pass if resume_handle == 0: break cgiEnv.OutCgiRdf()
def Main(): cgiEnv = lib_common.CgiEnv(can_process_remote=True) try: # Exception if local machine. hostName = cgiEnv.m_entity_id_dict["Domain"] except KeyError: hostName = None if not hostName or lib_util.IsLocalAddress(hostName): serverBox = lib_common.gUriGen serverNode = lib_common.nodeMachine servName_or_None = None else: serverBox = lib_common.RemoteBox(hostName) serverNode = lib_common.gUriGen.HostnameUri(hostName) servName_or_None = hostName # hostname = "Titi" for example try: lib_win32.WNetAddConnect(hostName) except: lib_common.ErrorMessageHtml("Error WNetAddConnect %s:%s" % (hostName, str(sys.exc_info()))) userName = cgiEnv.m_entity_id_dict["Name"] DEBUG("hostName=%s userName=%s", hostName, userName) grph = cgiEnv.GetGraph() nodeUser = survol_Win32_UserAccount.MakeUri(userName, hostName) # TODO: Quid de NetUserGetGroups ?? # [(groupName, attribute), ...] = NetUserGetGroups(serverName, userName ) try: resuList = win32net.NetUserGetLocalGroups(servName_or_None, userName) except: lib_common.ErrorMessageHtml("Error:userName="******":servName_or_None=" + str(servName_or_None) + ":" + str(sys.exc_info())) for groupName in resuList: nodeGroup = survol_Win32_Group.MakeUri(groupName, hostName) grph.add((nodeUser, pc.property_group, nodeGroup)) if hostName: nodeGroupRemote = serverBox.UriMakeFromDict( "Win32_Group", { "Name": groupName, "Domain": hostName }) # TODO: Instead, both object must have the same universal alias grph.add((nodeGroup, pc.property_alias, nodeGroupRemote)) cgiEnv.OutCgiRdf()
def Main(): cgiEnv = lib_common.ScriptEnvironment(can_process_remote=True) try: # Exception if local machine. host_name = cgiEnv.m_entity_id_dict["Domain"] except KeyError: host_name = None if lib_util.is_local_address(host_name): server_box = lib_uris.gUriGen serv_name_or_none = None else: server_box = lib_common.RemoteBox(host_name) serv_name_or_none = host_name try: lib_win32.WNetAddConnect(host_name) except Exception as exc: lib_common.ErrorMessageHtml("Error WNetAddConnect %s:%s" % (host_name, str(exc))) user_name = cgiEnv.m_entity_id_dict["Name"] logging.debug("host_name=%s user_name=%s", host_name, user_name) grph = cgiEnv.GetGraph() node_user = survol_Win32_UserAccount.MakeUri(user_name, host_name) # TODO: And NetUserGetGroups ?? # [(group_name, attribute), ...] = NetUserGetGroups(serverName, user_name ) try: resu_list = win32net.NetUserGetLocalGroups(serv_name_or_none, user_name) except Exception as exc: lib_common.ErrorMessageHtml("Error:user_name=" + user_name + ":serv_name_or_none=" + str(serv_name_or_none) + ":" + str(exc)) for group_name in resu_list: node_group = survol_Win32_Group.MakeUri(group_name, host_name) grph.add((node_user, pc.property_group, node_group)) if host_name: node_group_remote = server_box.node_from_dict( "Win32_Group", { "Name": group_name, "Domain": host_name }) # TODO: Instead, both object must have the same universal alias grph.add((node_group, pc.property_alias, node_group_remote)) cgiEnv.OutCgiRdf()
def Main(): cgiEnv = lib_common.CgiEnv(can_process_remote=True) server = cgiEnv.m_entity_id_dict["Domain"] groupName = cgiEnv.m_entity_id_dict["Name"] grph = cgiEnv.GetGraph() # http://www.math.uiuc.edu/~gfrancis/illimath/windows/aszgard_mini/movpy-2.0.0-py2.4.4/movpy/lib/win32/Demos/win32netdemo.py # hostname = "Titi" for example try: lib_win32.WNetAddConnect(server) except: exc = sys.exc_info()[1] lib_common.ErrorMessageHtml("Server=%s Caught:%s" % (server, str(exc))) if not server or lib_util.IsLocalAddress(server): servName_or_None = None # So it is compatible with WMI. servNameNotNone = lib_uris.TruncateHostname(lib_util.currentHostname) # .home serverNode = lib_common.nodeMachine serverBox = lib_common.gUriGen else: servName_or_None = server servNameNotNone = server serverNode = lib_common.gUriGen.HostnameUri(server) serverBox = lib_common.RemoteBox(server) # nodeGroup = serverBox.GroupUri( groupName ) # nodeGroup = survol_Win32_Group.MakeUri( groupName, servName_or_None ) nodeGroup = survol_Win32_Group.MakeUri(groupName, servNameNotNone) try: memberresume = 0 while True: memberData, total, memberResume = win32net.NetLocalGroupGetMembers( servName_or_None, groupName, 2, memberresume) for member in memberData: sidUsage = member['sidusage'] # Converts Sid to username try: memberName, domain, type = win32security.LookupAccountSid( server, member['sid']) except Exception: exc = sys.exc_info()[1] ERROR("Server=%s Caught:%s", server, str(exc)) continue DEBUG("Member: %s:", str(member)) DEBUG("Lookup: %s: %s", memberName, member['domainandname']) # nodeUser = serverBox.UserUri( userName ) DEBUG("servNameNotNone=%s", servNameNotNone) memberNode = MemberNameToNode(sidUsage, memberName, servNameNotNone) grph.add((memberNode, pc.property_group, nodeGroup)) grph.add((memberNode, lib_common.MakeProp("SID Usage"), lib_common.NodeLiteral(SidUsageToString(sidUsage)))) grph.add( (memberNode, lib_common.MakeProp("Security Identifier"), lib_common.NodeLiteral(member['sid']))) if servName_or_None: nodeMemberRemote = MemberNameToNodeRemote( sidUsage, memberName, servName_or_None, serverBox) # TODO: Instead, both object must have the same universal alias grph.add((memberNode, pc.property_alias, nodeMemberRemote)) if memberResume == 0: break except Exception: exc = sys.exc_info()[1] lib_common.ErrorMessageHtml("win32 local groups:" + str(exc)) cgiEnv.OutCgiRdf("LAYOUT_SPLINE")
def Main(): cgiEnv = lib_common.ScriptEnvironment(can_process_remote=True) server = cgiEnv.GetId() grph = cgiEnv.GetGraph() if lib_util.is_local_address(server): serv_name_or_none = None server_node = lib_common.nodeMachine else: serv_name_or_none = server server_node = lib_uris.gUriGen.HostnameUri(server) try: lib_win32.WNetAddConnect(serv_name_or_none) except Exception as exc: # Maybe the machine is not online. lib_common.ErrorMessageHtml(str(exc)) resume = 0 num_members = 0 try: while True: data, total, resume = win32net.NetLocalGroupEnum( serv_name_or_none, 1, resume) for group in data: logging.debug("Group %(name)s:%(comment)s", group) # TODO: Not sure about the groupname syntax. group_name = group['name'] logging.debug("group_name=%s", group_name) node_group = survol_Win32_Group.MakeUri(group_name, server) grph.add((node_group, pc.property_host, server_node)) group_comment = group['comment'] logging.debug("group_comment=%s", group_comment) if group_comment != "": group_comment_max_width = max(80, len(group_name)) if len(group_comment) > group_comment_max_width: group_comment = group_comment[: group_comment_max_width] + "..." grph.add((node_group, pc.property_information, lib_util.NodeLiteral(group_comment))) memberresume = 0 while True: member_data, total, member_resume = win32net.NetLocalGroupGetMembers( serv_name_or_none, group_name, 2, memberresume) for member in member_data: # Converts Sid to username num_members = num_members + 1 try: user_name, domain, the_type = win32security.LookupAccountSid( server, member['sid']) except Exception as exc: logging.warning( "Server=%s LookupAccountSid Caught:%s", server, str(exc)) continue logging.debug("Member: %s: %s server=%s", user_name, member['domainandname'], server) # node_user = serverBox.UserUri( user_name ) node_user = survol_Win32_UserAccount.MakeUri( user_name, server) # TODO: Not sure about the property. # TODO: Not sure about the username syntax. grph.add((node_user, pc.property_group, node_group)) if memberresume == 0: break if not resume: break except Exception as exc: lib_common.ErrorMessageHtml("win32 local groups:" + str(exc)) cgiEnv.OutCgiRdf("LAYOUT_SPLINE")
def Main(): cgiEnv = lib_common.CgiEnv() hostname = cgiEnv.GetId() nodeHost = lib_common.gUriGen.HostnameUri(hostname) grph = cgiEnv.GetGraph() try: # hostname = "Titi" for example lib_win32.WNetAddConnect(hostname) except: exc = sys.exc_info()[1] lib_common.ErrorMessageHtml("NetUserEnum:" + str(exc)) if lib_util.IsLocalAddress(hostname): level = 2 # 1,2 else: level = 2 # 1,2 sys.stderr.write("hostname=%s level=%d\n" % (hostname, level)) resumeHandle = 0 while True: try: # Maintenant, comme tous les autres appels remote a Windows, ca retourne "access denied" vers Titi. # Comme s'il y avait avant une connection implicite. # Ou bien un Impersonate() ? On en a vire un qui ne marchait quand machine locale. # Peut-etre que le process du serveur en beneficiait tout le temps ? # Et meme WMI fonctionnait sans meme entrer le mot de passe. # # Connects a computer to or disconnects a computer from a shared resource, or displays information about computer connections. # The command also controls persistent net connections. Used without parameters, net use retrieves a list of network connections. # net use [{DeviceName | *}] [\\ComputerName\ShareName[\volume]] [{Password | *}]] [/user:[DomainName\]UserName] # [/user:[DottedDomainName\]UserName] [/user: [UserName@DottedDomainName] [/savecred] [/smartcard] [{/delete | /persistent:{yes | no}}] # Ca marche si on fait ca avant: # net use \\Titi tXXXXXXa /user:Titi\[email protected] # https://mail.python.org/pipermail/python-win32/2003-April/000961.html lstUsers, total, resumeHandle = win32net.NetUserEnum( hostname, level, win32netcon.FILTER_NORMAL_ACCOUNT, resumeHandle) except: exc = sys.exc_info()[1] lib_common.ErrorMessageHtml("NetUserEnum:" + str(exc)) for usrElt in lstUsers: # {'comment': u'Built-in account for administering the computer/domain', 'workstations': u'', 'country_code': 0L, 'last_logon': 1426 # 729970L, 'full_name': u'', 'parms': u'', 'code_page': 0L, 'priv': 2L, 'auth_flags': 0L, 'logon_server': u'\\\\*', 'home_dir': u'', ' # usr_comment': u'', 'acct_expires': 4294967295L, 'bad_pw_count': 0L, 'logon_hours': '\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff # \xff\xff\xff\xff\xff\xff\xff\xff\xff', 'password': None, 'units_per_week': 168L, 'last_logoff': 0L, 'name': u'Administrator', 'max_s # torage': 4294967295L, 'num_logons': 11L, 'password_age': 191184801L, 'flags': 66083L, 'script_path': u''}, userName = usrElt['name'] nodeUser = survol_Win32_UserAccount.MakeUri(userName, hostname) grph.add((nodeHost, pc.property_user, nodeUser)) try: txtComment = usrElt['comment'] grph.add((nodeUser, pc.property_information, lib_common.NodeLiteral(txtComment))) except KeyError: pass if resumeHandle == 0: break cgiEnv.OutCgiRdf()
def Main(): cgiEnv = lib_common.CgiEnv(can_process_remote=True) server = cgiEnv.GetId() grph = cgiEnv.GetGraph() if lib_util.IsLocalAddress(server): servName_or_None = None serverNode = lib_common.nodeMachine else: servName_or_None = server serverNode = lib_common.gUriGen.HostnameUri(server) # http://www.math.uiuc.edu/~gfrancis/illimath/windows/aszgard_mini/movpy-2.0.0-py2.4.4/movpy/lib/win32/Demos/win32netdemo.py # servName_or_None, imper = lib_win32.MakeImpersonate(server) # hostname = "Titi" for example try: lib_win32.WNetAddConnect(servName_or_None) except: # Maybe the machine is not online. exc = sys.exc_info()[1] lib_common.ErrorMessageHtml(str(exc)) resume = 0 numMembers = 0 try: while True: # data, total, resume = win32net.NetLocalGroupEnum(server, 1, resume) data, total, resume = win32net.NetLocalGroupEnum( servName_or_None, 1, resume) for group in data: DEBUG("Group %(name)s:%(comment)s", group) # TODO: Not sure about the groupname syntax. groupName = group['name'] DEBUG("groupName=%s", groupName) # nodeGroup = serverBox.GroupUri( groupName ) nodeGroup = survol_Win32_Group.MakeUri(groupName, server) grph.add((nodeGroup, pc.property_host, serverNode)) groupComment = group['comment'] DEBUG("groupComment=%s", groupComment) if groupComment != "": groupCommentMaxWidth = max(80, len(groupName)) if len(groupComment) > groupCommentMaxWidth: groupComment = groupComment[:groupCommentMaxWidth] + "..." grph.add((nodeGroup, pc.property_information, lib_common.NodeLiteral(groupComment))) memberresume = 0 while True: # memberData, total, memberResume = win32net.NetLocalGroupGetMembers(server, group['name'], 2, resume) memberData, total, memberResume = win32net.NetLocalGroupGetMembers( servName_or_None, groupName, 2, memberresume) for member in memberData: # Converts Sid to username numMembers = numMembers + 1 try: userName, domain, type = win32security.LookupAccountSid( server, member['sid']) except Exception: exc = sys.exc_info()[1] WARNING("Server=%s Caught:%s", server, str(exc)) continue DEBUG("Member: %s: %s server=%s", userName, member['domainandname'], server) # nodeUser = serverBox.UserUri( userName ) nodeUser = survol_Win32_UserAccount.MakeUri( userName, server) # TODO: Not sure about the property. # TODO: Not sure about the username syntax. grph.add((nodeUser, pc.property_group, nodeGroup)) if memberResume == 0: break if not resume: break except Exception: exc = sys.exc_info()[1] lib_common.ErrorMessageHtml("win32 local groups:" + str(exc)) cgiEnv.OutCgiRdf("LAYOUT_SPLINE")
def Main(): cgiEnv = lib_common.ScriptEnvironment(can_process_remote = True) server = cgiEnv.m_entity_id_dict["Domain"] group_name = cgiEnv.m_entity_id_dict["Name"] grph = cgiEnv.GetGraph() try: lib_win32.WNetAddConnect(server) except Exception as exc: lib_common.ErrorMessageHtml("Server=%s Caught:%s" % (server, str(exc))) if lib_util.is_local_address(server): serv_name_or_none = None # So it is compatible with WMI: ".home" removal. serv_name_not_none = lib_uris.TruncateHostname(lib_util.currentHostname) else: serv_name_or_none = server serv_name_not_none = server server_box = lib_uris.MachineBox(server) node_group = survol_Win32_Group.MakeUri(group_name, serv_name_not_none) try: memberresume = 0 while True: member_data, total, member_resume = win32net.NetLocalGroupGetMembers( serv_name_or_none, group_name, 2, memberresume) prop_sid_usage = lib_common.MakeProp("SID Usage") prop_security_identifier = lib_common.MakeProp("Security Identifier") for member in member_data: sid_usage = member['sidusage'] # Converts Sid to username try: member_name, domain, type = win32security.LookupAccountSid(server, member['sid']) except Exception as exc: logging.error("Server=%s Caught:%s", server, str(exc)) continue logging.debug("Member: %s:", str(member)) logging.debug("Lookup: %s: %s", member_name, member['domainandname']) member_node = _member_name_to_node(sid_usage, member_name, serv_name_not_none) grph.add((member_node, pc.property_group, node_group)) grph.add((member_node, prop_sid_usage, lib_util.NodeLiteral(_sid_usage_to_string(sid_usage)))) grph.add((member_node, prop_security_identifier, lib_util.NodeLiteral(member['sid']))) if serv_name_or_none: node_member_remote = serv_name_or_none(sid_usage, member_name, serv_name_or_none, server_box) # TODO: Instead, both object must have the same universal alias grph.add((member_node, pc.property_alias, node_member_remote)) if member_resume == 0: break except Exception as exc: lib_common.ErrorMessageHtml("win32 local groups:" + str(exc)) cgiEnv.OutCgiRdf("LAYOUT_SPLINE")