My Passion In Computer Science
This is blog used by me as a platform to spread the knowledge I have in Computer Science....., I hope it helps some people who have a great passion for Computer Science
Monday, July 21, 2014
Blog Moved
Thursday, July 17, 2014
Buffer OverFlow Attacks!!!!
Let's see what a buffer attack is and the bad programming practices that can result in this attack
Let's dive right in now
Let's be clear with the following basics:
Statistical memory allocation is done on stack which happens during compilation of a program where as dynamic memory allocation is done on a heap which happens during run time
Now let's come to the segmentation fault.., this is one of the most common type of error that most of the programmer run into.., Let's checkout the reason for this error.., Operating System allocates some memory called stack(during compile time) and some memory called heap(during run time this usually happens in dynamic memory allocation) when you are trying to access a memory unit outside the heap memory or stack memory during compile time this results in a segmentation fault which is an error thrown by the OS
Now Let's come to Buffer Overflow Attacks.., Suppose if you use functions like gets(var) and many other which doesn't check for the overflow Lets check the following example which can tell you about the intensity of the attacks of Buffer Overflow
Include stdio.h and string.h libraries
int main(void)
{
char buff[15];
int pass = 0;
printf("\n Enter the password : \n");
gets(buff);
if(strcmp(buff, "thegeekstuff"))
{
printf ("\n Wrong Password \n");
}
else
{
printf ("\n Correct Password \n");
pass = 1;
}
if(pass)
{
/* Now Give root or admin rights to user*/
printf ("\n Root privileges given to the user \n");
}
return 0;
}
Input 1
$ ./bfrovrflw
Enter the password :
thegeekstuff
Correct Password
Root privileges given to the user
Input 2
$ ./bfrovrflw
Enter the password :
hhhhhhhhhhhhhhhhhhhh
Wrong Password
Root privileges given to the user
By this time if you have gone through the above code carefully you should have got the intensity of Buffer Overflow attacks actually here in the second case though the statistical memory allocated on stack was only for 15 characters but you have overridden the next few characters in the heap with the string and these few locations happen to be the memory allocations of pass whose values are overridden hence though the password was incorrect pass has got a value which is non zero and the condition is passed and if this code actually grants users permissions then All Root Previleges must have gone to the malicious user
Thursday, July 10, 2014
Union Find Algorithm and improving It's efficiency
Union Find is the name of an algorithm used to solve the connectivity problem. This Union Find algorithms are applied as Percolations. These Percolation type situations are widely seen in many areas such as a solid may be conducting or not(percolating or not) also in Image processing and many other situations., I will write another post on how to apply this Union Find algorithm in Percolations.
In this post I discuss about how to improve the efficiency of an Union Find Algorithm..,Here is my github repo Have a look at it for source code
Sunday, July 6, 2014
Problem of nextInt and nextLine methods in Scanner class
Ever wondered why does nextInt() and nextLine() methods in java doesn't work properly when used simultaneously...Here you go..,
Let us say we have an object named input which is an instance of class Scanner.Now if you a code snipper lite the one below
var1=input.nextInt();
var2 = input.nextLine();
and if your input is say
1
hello
Now here var1 has the number 1 but the var2 doesn't have the string hello.this is because nextInt() method only takes input an Integer but it doesn't take the newline character "\n" so next thing in the input stream is new line character which will be saved into var2 when you now use a nextLine() method
How can we solve this Yah! the answer is below
method1:
You can insert a small snippet of code to remove that new line character from buffer i.e
var1=input.nextInt();
input.nextLine()
var2 = input.nextLine();
Method2:
Use two different objects of the class scanner call the method of first object when you use nextInt() method and use other second object for the nextLine() method..,this really works try it out!!!
Beginning...with A Game 2048
Most of you must be knowing the game 2048 If not try it out here.Though it eats some of your time try it out :)
Ya Now after playing it for sometime your intuition tells you "abhey yaar iska logic bahuth easy hai" Yes your intuition is correct but usually we get stuck up at how can we handle gui. By taking programming beginners into account I have made a github repo exclusively for the algorithmic thinking of the game 2048 where you the gui part is taken by some other people..,
So have fun in going through the code
Feel free to comment if you have any issues
First Post
This is my first post in this blog...In this blog I will be writing different concepts or programs related to computer science as I learn through them...My motto in creating this blog is to help many Learners who have a great passion in Computer Science like me..,
By the way thank you google for this platform as Blogger
By the way Blogger was bought by Google and it was not created by them but it was developed by Google
#nooffence:)