# Need for emergency help



## akbarakbari (May 1, 2014)

Hello,

I am a newbie in FreeBSD and I have an assignment to write a kernel module for PC-BSD. *T*his module should count the number of BSD sbrk function calls. I found dtrace but I can use it in PC-BSD 10. Can anyone help me? *P*lease! My assignment deadline is two days later. *P*lease, please.

Regards.


----------



## fonz (May 1, 2014)

Obligatory disclaimer: PC-BSD DesktopBSD FreeNAS NAS4Free m0N0WALL pfSense ArchBSD

You'll want to hook the system call. Here's an outline of what to do:

When messing around with the kernel, you may want to do so in a virtual machine for safety reasons.
If you have access to a library, see if you can obtain the book _"Designing BSD Rootkits"_ by Joseph Kong. Section 2.1 should be enough to get you going, but just in case, read the following.
Write a hook function that increments a counter and then calls the original system call.
Complete the kernel module by writing the load() function (which replaces the original system call with your hook and vice versa upon unloading) and some other obligatory filler code.


----------



## akbarakbari (May 1, 2014)

Thanks for your very useful hints. I have a problem while doing `make module`. I have seen this message after make.

```
make: "/usr/share/mk/bsd.kmod.mk" line 12: Unable to locate the kernel source tree. Set SYSDIR to override.
```
I think the reason is that I run PC-BSD on VMware. Would you give me another useful hint?


----------



## fonz (May 1, 2014)

akbarakbari said:
			
		

> ```
> make: "/usr/share/mk/bsd.kmod.mk" line 12: Unable to locate the kernel source tree. Set SYSDIR to override.
> ```


It looks like you either don't have the kernel source code installed, or have it installed in an unusual place. On a FreeBSD system the source is typically in /usr/src/sys/, but I don't know exactly how PC-BSD handles FreeBSD source code. They might have an installable package for it, they may (or may not) install it into a different location, etc. This sounds like a question for someone who knows more about PC-BSD and the differences between it and FreeBSD.


----------



## akbarakbari (May 1, 2014)

Thanks. I think it's better I ask this question on the PC-BSD forum.


----------

