-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possible to hook sys_kill(pid, signal)? #3
Comments
Hey, thank you for using KHOOK. As for hooking system calls you have to hook
Just use the right prototype for this |
Oh, whoops. My brain was not working correctly last night. Thanks for the help! However, the example did not work for me. When I run I tried changing the first parameter to a I'm pretty sure that |
It's weird. I've tried to By the way, my kernel is |
I'm working on |
OK, it makes sense then. From some point they changed syscalls notation and argument passing. So, now you have to look for
|
Oh, alright, cool! I'll try this out when I have a minute. |
Worked perfectly. Thanks for the help! |
Updated the README with this example. Thank you for the question. |
Can you explain where you found this new function signature? KHOOK_EXT(long, __x64_sys_kill, const struct pt_regs *);
static long khook___x64_sys_kill(const struct pt_regs *regs) I'm having trouble reproducing this with other syscalls. For example, I have this hook for KHOOK_EXT(long, __x64_ksys_msgctl, int, int, struct msqid_ds __user *);
static long khook___x64_ksys_msgctl(int msqid, int cmd, struct msqid_ds __user *buf) Here is a relevant LKML email: https://lore.kernel.org/lkml/[email protected]/ But I can't figure out where you found the prototype for the updated sys_kill function. As far as I can tell, it's not in the source code. But I also know that can't be right, so I'm a little stuck. Google has turned up nothing so far. Edit: I found this: https://github.com/torvalds/linux/blob/618d919cae2fcaadc752f27ddac8b939da8b441a/arch/x86/include/asm/syscall_wrapper.h#L125 and updated my code to: KHOOK_EXT(long, __x64_ksys_msgctl, const struct pt_regs *);
static long khook___x64_ksys_msgctl(const struct pt_regs * regs) {
// int msqid, int cmd, struct msqid_ds __user *buf
action_task* task;
// Read first two arguments
if (regs->di == -1 && regs->si == -1) {
if (condition) {
printk(KERN_EMERG "sys_msgctl -- preparing...\n");
...
return 0;
} else {
printk(KERN_EMERG "sys_msgctl\n");
task = (action_task*) regs->dx;
...
return 0;
}
} else {
return KHOOK_ORIGIN(__x64_ksys_msgctl, regs);
}
} However, this still does not hook |
TLDR: https://elixir.bootlin.com/linux/latest/source/ipc/msg.c#L614
You could ether hook |
It's still not being hooked properly. The syscall definition you pasted in was the reason I initially had
Should I change that ^ to I feel like I’m missing some core understanding of what I’m doing. Do you have any recommendations for topics I should read up on? |
YES (but I didn't test it) |
This works well for me:
$ dmesg |
What you posted did work for me. Funny enough, I actually posted that signature in a previous comment. I think my error was that the line below was never hit. I passed a
Anyways, the issue is now resolved. Thank you again for the help. |
hi, /proc/kallsyms shows __x64_sys_open, but not ksys_open. What are the right headers I need to include ? Along with sys_open, I need to hook sys_creat, sys_openat, sys_execve, sys_truncate, sys_ftruncate, sys_write, etc... Before kernel 4.17, I was able to find the symbol for sys_xyz, but from Kernel 4.17 onward, I am not sure if I need to hook __x64_sys_xyz or ksys_xyz or sys_xyz. In syscalls.h Some system call are declared with /__ARCH_WANT_SYSCALL_DEPRECATED/ Please help, |
@KTalinki Use the following code for every "modern" syscall handler (replace
|
Thank you milabs. If I were to use hook in a traditional way of finding a specific syscall table address and hook it, and what are the header files __x64_sys_creat or __x64_sys_openat are declared ? It will be great if someone can share a sample with what is needed to hook syscalls on kernels from 4.17 onward. thank you, |
Dear @KTalinki, you don't need to have headers to hook |
thank you @milabs , the way our existing code is structured, it uses the declaration of the syscalls from .../include/linux/syscalls.h The issue I am running in to is compilation errors for __x64_sys_open and __SYSCALL_64. Any help is appreciated, |
@KTalinki Again, you don't have to include ANY header to hook __x64_XXX, just use the
Which is the error with using this code? |
@milabs hello,I want to hook sys_exevce. I'm using the KHOOK_EXT macro,which work well on the 64-bit machines,for example Redhat6.8 x86_64 or CentOS8 x86_64.The code is as follows:
CentOS8 x86_64:
BUT,I have a problem on the 32-bit machine. I test it on Linux Redhat 6.8 2.6.32-642.el6.i686.The code is as follows:
I Found the sys_execve() symbols from the source code as follow: After I insmod, I execute "ls" or any other commands. ERROR as following: I suspect there is a problem with this code executing on a 32-bit machine.I hope you can take a look in your busy schedule. |
@wbt165 I'd recommend you to hook |
@milabs Thanks for your response!
After I insmod, I execute "ls" or any other commands. ERROR as following: Thanks for your help! |
@wbt165 Unfortunately, 32-bit stub is not implemented as I never had such requirement for myself (see https://github.com/milabs/khook/blob/master/khook/x86/stub.S#L24). It would be great if you'll try to implement missing part of the macro. |
If you could test that code on 32-bit system?
|
@milabs Unfortunately,this code has NO effect…… |
Made a branch for you to test: |
@milabs Thank you for creating a branch! I tested it on Linux Redhat6.8 2.6.32-642.el6.i686, but it didn't work. The code is as follow:
After I insmod, I execute "ls" or any other commands. ERROR as following: |
Just wanted to start out by saying this is an awesome project! Nice work!
I'm having a problem hooking
sys_kill
, and I was hoping you'd be able to help me out.sys_kill
is defined here inlinux/syscalls.h
.I have been trying to hook this function for a while and can not get anything to compile. I was able to hook
kill_pid
, however, that did not hook thekill
syscall.Is there a way to hook the actual kill syscall? Or can it not be done since the syscall table is no longer exported, post-Kernel 2.6?
The text was updated successfully, but these errors were encountered: