Skip to content

Instantly share code, notes, and snippets.

View tahaconfiant's full-sized avatar
🎯
Focusing

lordx64 tahaconfiant

🎯
Focusing
View GitHub Profile
@tahaconfiant
tahaconfiant / follow-fork-child-breakpoints.py
Created December 10, 2019 09:15
follow-fork-child-breakpoints
def custom_breakpoints(debugger, command, result, internal_dict):
target = debugger.GetSelectedTarget()
breakpoint = target.BreakpointCreateByName("fork")
breakpoint.SetScriptCallbackFunction('follow_fork_child.fork_callback')
breakpoint = target.BreakpointCreateByName("waitpid")
breakpoint.SetScriptCallbackFunction('follow_fork_child.waitpid_callback')
@tahaconfiant
tahaconfiant / get_child_pid.py
Created December 10, 2019 09:18
get_child_pid
def get_child_pid(process_name, parent_pid):
child_pid = 0
for pid in check_output(["pgrep", process_name]).split():
print ("found new pid: %i\n" % int(pid))
if parent_pid == int(pid):
continue
elif int(pid) > parent_pid:
child_pid = int(pid)
@tahaconfiant
tahaconfiant / follow_fork_child.py
Created December 10, 2019 09:19
follow_fork_child
# by [email protected]
# LLDB custom command follow-fork-child, equivalent to GDB "follow-fork-mode child"
# tested on $lldb --version
# lldb-1100.0.30.6
# Apple Swift version 5.1.2 (swiftlang-1100.0.278 clang-1100.0.33.9)
# (lldb) script
# Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.
# >>> import sys
# >>> print(sys.version)
@tahaconfiant
tahaconfiant / waitpid_callback_part1.py
Created December 10, 2019 09:33
waitpid_callback_part1
def waitpid_callback(frame, bp_loc, dict):
global backup_bytes
global patch_address
print ("waitpid() detected!")
# let's attach to the child process:
# Get the current debugged process pid
curr_target = frame.thread.process.GetTarget()
@tahaconfiant
tahaconfiant / waitpid_callback_part2.py
Created December 10, 2019 09:33
waitpid_callback_part2
# Let's attempt to attach to the child process
listener = lldb.SBListener('listener')
error = lldb.SBError()
child = curr_target.AttachToProcessWithID(listener, child_pid, error)
if not error.Success():
print ("error %s\n" % error.GetCString())
raise Exception('Failed to attach to the process.')
assert child.IsValid()
else:
print ("sucessfully attached to child, with pid : %s\n" % str(child.GetProcessID()))
@tahaconfiant
tahaconfiant / waitpid_callback_part3.py
Created December 10, 2019 09:34
waitpid_callback_part3
# we are attached to the child, we running on the child context:
# lets recover our backup_bytes
print('backup_bytes recovered : 0x%x' % backup_bytes)
# let's write the original backup_byte
new_value = struct.pack('h', backup_bytes)
error = lldb.SBError()
result = child.WriteMemory(patch_address, new_value, error)
if not error.Success() or result != len(new_value):
print('SBProcess.WriteMemory() failed!')
@tahaconfiant
tahaconfiant / follow_fork_child.py
Created December 10, 2019 09:36
follow_fork_child
# by [email protected]
# LLDB custom command follow-fork-child, equivalent to GDB "follow-fork-mode child"
# tested on $lldb --version
# lldb-1100.0.30.6
# Apple Swift version 5.1.2 (swiftlang-1100.0.278 clang-1100.0.33.9)
# (lldb) script
# Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.
# >>> import sys
# >>> print(sys.version)
@tahaconfiant
tahaconfiant / waitpid_callback_kill_child.py
Created December 10, 2019 09:38
waitpid_callback_kill_child
def waitpid_callback(frame, bp_loc, dict):
print ("waitpid() detected!")
# let's attach to the child process:
# get the current process id
curr_target = frame.thread.process.GetTarget()
pid = frame.thread.process.GetProcessID()
print ("current pid is %s\n" % str(pid))
# let get the current filename of the current target
@tahaconfiant
tahaconfiant / unicorn_import.py
Created December 10, 2019 09:39
unicorn_import
from unicorn import *
from unicorn.x86_const import *
@tahaconfiant
tahaconfiant / uc_init.py
Created December 10, 2019 09:41
uc_init
mu = Uc (UC_ARCH_X86, UC_MODE_64)