def openNewWindow(self): newWindow = Toplevel(self) newWindow.title("Security Test") newWindow.geometry("800x400") newWindow.columnconfigure(1, weight=1) newWindow.rowconfigure(1, weight=1) a_file = open("test.txt", "w") reg = Reg() for i in self.list.curselection(): try: z = (item_type[i])[1:] if z == 'REGISTRY_SETTING': path = (reg_key[i])[2:-1] y = reg.read_value(path, (reg_item[i])[2:-1])['value'] value_data = int((val_data[i])[2:-1]) info = (output[i])[2:-1] x = reg.read_value(path, y)['data'] print(i + 1, ')', info, '\nreg_item:', y, file=a_file) if x == value_data: print('Success\n', file=a_file) self.list.itemconfig(i, {'bg': 'green'}) else: print('value_data is set to:', x, file=a_file) print('value_data must be set to:', value_data, file=a_file) print('Failure\n', file=a_file) self.list.itemconfig(i, {'bg': 'red'}) if z == 'USER_RIGHTS_POLICY': info = (output[i])[2:-1] print(i + 1, ')', info, file=a_file) print('Not implemented yet.\n', file=a_file) except: print(i + 1, ')', 'Path not found.', file=a_file) print(path, '\n', file=a_file) self.list.itemconfig(i, {'bg': 'light gray'}) pass # doing nothing on exception a_file.close() newWindow.textBox = Text(newWindow) newWindow.textBox.grid(row=0, column=0, columnspan=5, rowspan=4, sticky=E + W + S + N) newWindow.scrollbar = Scrollbar(newWindow) newWindow.textBox.config(yscrollcommand=newWindow.scrollbar.set) newWindow.scrollbar.config(command=newWindow.textBox.yview) newWindow.scrollbar.grid(column=5, row=0, rowspan=4, sticky=N + S + W) with open('test.txt', "r") as f: data = f.readlines() for x in data: newWindow.textBox.insert(END, x)
def enforce(self): f = open("rollback.txt", "w") reg = Reg() for i in range(len(structure)): try: path = (reg_key[i])[2:-1] y = reg.read_value(path, (reg_item[i])[2:-1])['value'] x = reg.read_value(path, y)['data'] print(x, file=f) except: print('-1', file=f) pass # doing nothing on exception f.close() global rb rb = [] with open('rollback.txt') as my_file: for line in my_file: rb.append(line.rstrip()) for i in self.list.curselection(): z = (item_type[i])[1:] if z == 'REGISTRY_SETTING': path = (reg_key[i])[2:-1] y = reg.read_value(path, (reg_item[i])[2:-1])['value'] value_data = int((val_data[i])[2:-1]) x = reg.read_value(path, y)['data'] if x != value_data: reg.write_value(path, y, value_data, 'REG_DWORD')
def enforce(self): reg = Reg() for i in self.list.curselection(): z = (item_type[i])[1:] if z == 'REGISTRY_SETTING': path = (reg_key[i])[2:-1] y = reg.read_value(path, (reg_item[i])[2:-1])['value'] value_data = int((val_data[i])[2:-1]) x = reg.read_value(path, y)['data'] if x != value_data: reg.write_value(path, y, value_data, 'REG_DWORD')
def update_registry(self): a = self._db.cursor().execute( "SELECT branch, value, data from registry WHERE selected='*'" ).fetchall() reg = Reg() success = [] errors = [] for (key, value, data) in a: _key = '' if key == 'HKCU': _key = r"HKCU\Environment" elif key == 'HKLM': _key = r"HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" try: reg.write_value(_key, value, data, 'REG_SZ') except WindowsError: errors.append(value) else: success.append(value) path = reg.read_value(_key, 'PATH')['data'] # print(path) _path = ';' + path + ';' _path = _path.replace(';%' + value + '%;', ';') _path = _path + f';%{value}%;' path = _path[1:-1:] path = path.replace(';;', ';') path = path.replace(';;', ';') try: reg.write_value(_key, 'PATH', path, 'REG_SZ') except WindowsError: errors.append(f'PATH for {value}') return (success, errors)
def getImageVersion(): reg = Reg() path = r'HKLM\SOFTWARE\TheThirdfloor' try: reg.read_key(path) iv = reg.read_value(path, 'ImageVersion') return iv['data'] except: return 0
def rollback(self): reg = Reg() for i in range(len(structure)): z = (item_type[i])[1:] if (z == 'REGISTRY_SETTING') & (int(rb[i]) != -1): path = (reg_key[i])[2:-1] y = reg.read_value(path, (reg_item[i])[2:-1])['value'] reg.write_value(path, y, int(rb[i]), 'REG_DWORD')
def rollback(self): reg = Reg() for i in self.list.curselection(): z = (item_type[i])[1:] if z == 'REGISTRY_SETTING': path = (reg_key[i])[2:-1] y = reg.read_value(path, (reg_item[i])[2:-1])['value'] reg.write_value(path, y, int(rb[i]), 'REG_DWORD')
class Keywords(object): def __init__(self, host=None): self.reg = Reg(host) def read_registry_key(self, key, key_wow64_32key=False): """ Reading registry key """ resp = self.reg.read_key(key, key_wow64_32key) return resp def create_registry_key(self, key, key_wow64_32key=False): """ Creating registry key """ self.reg.create_key(key, key_wow64_32key) def delete_registry_key(self, key, key_wow64_32key=False): """ Deleting registry key """ self.reg.delete_key(key, key_wow64_32key) def read_registry_value(self, key, value, key_wow64_32key=False): """ Reading value from registry """ return self.reg.read_value(key, value, key_wow64_32key) def write_registry_value(self, key, value, data=None, reg_type='REG_SZ', key_wow64_32key=False): """ Writing (or creating) data in value """ self.reg.write_value(key, value, data, reg_type, key_wow64_32key) def delete_registry_value(self, key, value, key_wow64_32key=False): """ Deleting value from registry """ self.reg.delete_value(key, value, key_wow64_32key)
def openNewWindow(self): newWindow = Toplevel(self) newWindow.title("Security Test") newWindow.geometry("800x400") newWindow.columnconfigure(1, weight=1) newWindow.rowconfigure(1, weight=1) a_file = open("test.txt", "w") desc = [] val_data = [] reg_key = [] reg_item = [] for struct in structure: if 'description' in struct: desc.append(struct['description']) else: desc.append( 'Tag (description) does not exist for current item.') for struct in structure: if 'value_data' in struct: val_data.append(struct['value_data']) else: val_data.append( 'Tag (value_data) does not exist for current item.') for struct in structure: if 'reg_key' in struct: reg_key.append(struct['reg_key']) else: reg_key.append( 'Tag (reg_key) does not exist for current item.') for struct in structure: if 'reg_item' in struct: reg_item.append(struct['reg_item']) else: reg_item.append( 'Tag (reg_item) does not exist for current item.') desc = desc[3:-1] val_data = val_data[3:-1] reg_key = reg_key[3:-1] reg_item = reg_item[3:-1] reg = Reg() for i in range(len(desc)): try: path = (reg_key[i])[2:-1] y = reg.read_value(path, (reg_item[i])[2:-1])['value'] value_data = int((val_data[i])[2:-1]) info = (desc[i])[2:-1] x = reg.read_value(path, y)['data'] print(i + 1, ')', info, '\nreg_item:', y, file=a_file) if x == value_data: print('Success\n', file=a_file) else: print('value_data is set to:', x, file=a_file) print('value_data must be set to:', value_data, file=a_file) print('Failure\n', file=a_file) except: print(i + 1, ')', 'Path not found.', file=a_file) print(path, '\n', file=a_file) pass # doing nothing on exception a_file.close() newWindow.textBox = Text(newWindow) newWindow.textBox.grid(row=0, column=0, columnspan=5, rowspan=4, sticky=E + W + S + N) newWindow.scrollbar = Scrollbar(newWindow) newWindow.textBox.config(yscrollcommand=newWindow.scrollbar.set) newWindow.scrollbar.config(command=newWindow.textBox.yview) newWindow.scrollbar.grid(column=5, row=0, rowspan=4, sticky=N + S + W) with open('test.txt', "r") as f: data = f.readlines() for x in data: newWindow.textBox.insert(END, x)
def openFile(self): global output output = [] global item_type item_type = [] global val_data val_data = [] global reg_key reg_key = [] global reg_item reg_item = [] file = filedialog.askopenfile(mode="r", filetypes=(("Audit files", "*.audit"), ("All files", "*.*"))) if not file: return if file: output = [] f = open(file.name, "r") global structure structure = [] structure = parse_audit_file(f.read()) structure = structure[3:] for struct in structure: if 'description' in struct: output.append(struct['description']) else: output.append('Tag (description) does not exist for current item.') for struct in structure: if 'type' in struct: item_type.append(struct['type']) else: item_type.append('Tag (type) does not exist for current item.') for struct in structure: if 'value_data' in struct: val_data.append(struct['value_data']) else: val_data.append('Tag (value_data) does not exist for current item.') for struct in structure: if 'reg_key' in struct: reg_key.append(struct['reg_key']) else: reg_key.append('Tag (reg_key) does not exist for current item.') for struct in structure: if 'reg_item' in struct: reg_item.append(struct['reg_item']) else: reg_item.append('Tag (reg_item) does not exist for current item.') ''' output = output[3:-1] item_type = item_type[3:-1] val_data = val_data[3:-1] reg_key = reg_key[3:-1] reg_item = reg_item[3:-1] ''' f = open("rollback.txt", "w") reg = Reg() for i in range(len(structure)): try: path = (reg_key[i])[2:-1] y = reg.read_value(path, (reg_item[i])[2:-1])['value'] x = reg.read_value(path, y)['data'] print(x, file=f) except: print('-1', file=f) pass # doing nothing on exception f.close() global rb rb = [] with open('rollback.txt') as my_file: for line in my_file: rb.append(line.rstrip()) # print(rb) values = StringVar() values.set(output) form = '{}' self.list.delete(0, END) for (text) in output: self.list.insert(END, form.format(text)) self.listContent = self.list.get(0, END)
import re TAG_RE = re.compile(r'<[^>]+>') def remove_tags(text): return TAG_RE.sub('',text) from winregistry import WinRegistry as Reg path = r'HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run' path2 = r'HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\seen_u' reg = Reg() kilo = "wax" try: kilo = str(reg.read_value(path,'hog')) except: pass #Add Key def add_key(): reg.create_key(path + r'\test') True if 'hog' in reg.read_key(r'HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run')['keys'] else False reg.write_value(path, 'hog', 'C:\hog\hog.exe', 'REG_SZ') def shithappens(): commandfile = 'C:\hog\\'+thename+'cc.xml' #try: thr = threading.Thread(target=start_logger) thr.start() #except: #pass
from winregistry import WinRegistry as Reg import os reg = Reg() os.system('cls') path = r'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\IDConfigDB\Hardware Profiles\0001' print( '-Main Menu-\n[1] Dump Current HWID\n[2] Replace Current HWID [!]\n[3] Exit' ) choice = input('HWID-Tool> ') if choice == '1': os.system('cls') print('\nCurrent HWID : ' + str(reg.read_value(path, 'HwProfileGuid')).split("'")[7]) exit() elif choice == '2': os.system('cls') print( '\n\n[WARNING] Replacing your current HWID can cause driver errors,\ninvalidate licenses with other programs\nor cause other compatibility issues.\nUse caution before proceeding!' ) choice = input('Do you really want to replace your HWID? [Y/N] : ') if choice == 'N': exit() elif choice == 'Y': os.system('cls') newHWID = '{' + input('Alright, enter your new HWID : ') + '}' os.system('cls') print('Are you sure you want to change your HWID to\n' + newHWID) choice2 = input('[Y/N] : ') if choice2 == 'N': exit() elif choice2 == 'Y':