Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

17 May 2016

Prevent hyperlink click behavior using jQuery


Often web devs (you and me), put an anchor tag and write a custom function for its onclick event. The href field will get assigned with a "#" and you are happy to see your function getting called on every click of the hyperlink. So far so good.

It will be a little later that you notice a jerk when you click on the hyperlink, which puts your page scrolled back to the top. This is a kind of an undesired behavior which you do not want to see.

Well, the solution is simple. Just add preventDefault() call at the start of the onclick handler.  The sample code below shows an example.

<a href="#" id="link">Click here</a>
.
.
.
$("#link").click(function(param){
param.preventDefault();
//do stuff
});

17 Mar 2016

Fork Bomb Detector

Fork bomb is a denial of service attack on the operating system wherein a process continually replicates itself to deplete available resources, causing resource starvation and slow down or system crash. The current Linux kernel sets a limit to the maximum process id in the limits.conf system file
to prevent from such attacks. This would lead to denial of fork calls even to legitimate processes. This kernel functionality moves a step forward to identify a fork bomb by calculating the time between two fork calls along with enforcing a threshold.

Solution

The solution approach involves developing a loadable kernel module(LKM) that hooks the fork system call in order to examine if the system call is from a fork bomb. This can be found out if the fork call is from a process with process id larger than a predefined system threshold or if the time elapsed after process creation of the child processes is less than a predetermined period. If the call is made by a potential fork bomb, the process is not allowed to execute the fork system call and notifying the user about the event.

The module once loaded is expected to intercept all fork calls and detect if there is a fork bomb spawning processes. If it detects unusual forking by any process, the process will not be allowed to complete the fork call. The action taken will be logged in syslog.

The project is hosted in GitHub.


Fork