regsecurity.py 1021 B

1234567891011121314151617181920
  1. import win32api, win32con, win32security, ntsecuritycon
  2. new_privs = ((win32security.LookupPrivilegeValue('',ntsecuritycon.SE_SECURITY_NAME),win32con.SE_PRIVILEGE_ENABLED),
  3. (win32security.LookupPrivilegeValue('',ntsecuritycon.SE_TCB_NAME),win32con.SE_PRIVILEGE_ENABLED)
  4. )
  5. ph = win32api.GetCurrentProcess()
  6. th = win32security.OpenProcessToken(ph,win32security.TOKEN_ALL_ACCESS|win32con.TOKEN_ADJUST_PRIVILEGES)
  7. win32security.AdjustTokenPrivileges(th,0,new_privs)
  8. hkey=win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE,None,0,win32con.KEY_ALL_ACCESS)
  9. win32api.RegCreateKey(hkey,'SYSTEM\\NOTMP')
  10. notmpkey=win32api.RegOpenKey(hkey,'SYSTEM\\notmp',0,win32con.ACCESS_SYSTEM_SECURITY)
  11. tmp_sid = win32security.LookupAccountName('','tmp')[0]
  12. sacl=win32security.ACL()
  13. sacl.AddAuditAccessAce(win32security.ACL_REVISION,win32con.GENERIC_ALL,tmp_sid,1,1)
  14. sd=win32security.SECURITY_DESCRIPTOR()
  15. sd.SetSecurityDescriptorSacl(1,sacl,1)
  16. win32api.RegSetKeySecurity(notmpkey,win32con.SACL_SECURITY_INFORMATION,sd)