def GetHexFromFile(inputfile: str): ''' Return the full Hex of a file. -return: string ''' LibDebug.CheckFile(inputfile) with open(inputfile, mode='rb') as f: return f.read().hex()
def menu(): # inputfile = "test.out" # outputfile = "ELFx64_EDITED_printf.out" # LibObjCopy.test() # HexContent = LibByteEditor.GetHexFromFile(inputfile) # ElfInput = LibElfAnnalyzer.Extract(HexContent) # ElfInput.Programheadertable.headertable[3].filesz = "0000000000003500" # ElfInput.Programheadertable.headertable[3].memsz = "0000000000003500" # # ElfInput.Programheadertable.headertable[5].offset = "000000000000304d" # # ElfInput.Programheadertable.headertable[5].vaddr = "000000000000304d" # # ElfInput.Programheadertable.headertable[5].paddr = "000000000000304d" # print(ElfInput.Elfheader.entrypoint) # ElfInput.Elfheader.entrypoint = ElfInput.Sectionheadertable.sectiontable[27].offset # print(ElfInput.Elfheader.entrypoint) # ElfInput.Sectionheadertable.sectiontable[27].flags = "0000000000000006" # ElfInput.PrintProgramHeaderTable() # LibByteEditor.CreateBinFromClass(outputfile,ElfInput) # HexContent2 = LibByteEditor.GetHexFromFile(outputfile) # if HexContent != HexContent2: # print("shit") # exit() outputfile = LibObfuscator.RandomizedString(7) + ".exe" print("Welcome to Hypnos Hephaistos Version") print( "Do you want to specify an executable to edit or did you want me to generate one ? [edit/generate] or [e/g] : ", end="") value = input() case = ["generate", "edit", "e", "g"] if value in case: if value == "generate" or value == "g": LibDebug.Log("WORK", "Generating executable..") try: ObfuscatedC = LibObfuscator.ObfuscateC( LibObfuscator.GenerateC(50), 25) inputfile = LibObfuscator.Compile(ObfuscatedC) os.system("rm *.c") LibDebug.Log("SUCCESS", inputfile + " generated..") except: LibDebug.Log("ERROR", "Generation failed..") elif value == "edit" or value == "e": LibDebug.Log("WORK", "Generating executable..") print("There is the sample list :") for (dirpath, _, filenames) in os.walk("EXECUTABLE"): for file in filenames: print(dirpath + "/" + file) value = input("Enter the file you want to exploit : ") LibDebug.CheckFile(value) inputfile = value else: LibDebug.Log("ERROR", "Bad entry. Exiting.") exit() HexContent = LibByteEditor.GetHexFromFile(inputfile) PeInput = LibPeAnnalyzer.Extract(HexContent) if PeInput.Optionalpeheader.signature == "020b": print("!! Your file is a X64 beware to pick a X64 shellcode !!") elif PeInput.Optionalpeheader.signature == "010b": print("!! Your file is a X32 beware to pick a X32 shellcode !!") print("It's time to generate a shellcode .\nHere's a list of options :") shellcodes = [] for (dirpath, _, filenames) in os.walk("SHELLCODES"): for file in filenames: shellcodes.append( (dirpath + "/" + file).replace("\\", "/").replace( "ASM/ShellCodes/", "").split(".")[0]) case = [] for i in range(0, len(shellcodes)): case += str(i) print(" " + str(i) + " - " + shellcodes[i].replace("SHELLCODES/", ""))