C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 11-03-2009, 04:06 AM   #1
Registered User
 
Join Date: Nov 2009
Posts: 1
C bufferoverflow question. can anyone solve it?

Consider the following C program:
Code:
void func(char * str)
{
char buff[16];
strcpy(buff,str);
}
void main(int argc, char * argv[])
{
int check = 1;
func(argv);
if(check == 1)
{
printf(“check should be 1 (%d)\n”,check);
} else
{
Printf(“check should not be 1 (%d)\n”,check);
}
}
Q1. Mount buffer overflow attack on the given program and corrupt the variable “check” with the value 25.

After the buffer overflow attack the output of the program should be the following:

check should not be 1 (25)

Q2. Mount buffer overflow attack on the given program and bypass the “if” condition.

After the buffer overflow attack the output of the program should be the following:
check should not be 1 (1)

Q3. Increase the size of the buffer “buff” to as much as you want. Mount a buffer overflow attack and make the program execute a shell (“/bin/bash”).
asdfgh is offline   Reply With Quote
Old 11-03-2009, 04:42 AM   #2
Guest
 
Sebastiani's Avatar
 
Join Date: Aug 2001
Posts: 4,923
Hint: why wouldn't this be vulnerable to a buffer overflow?

Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define CONSTANT 2

int main( int argc, char** argv )
{
	int unused = CONSTANT;
	char buffer[ CONSTANT ];
	if( argc != 2 )
	{
		printf( "Overflow This!\n" );
		printf( "Usage: %s <text>\n", *argv );
		return EXIT_FAILURE;
	}
	strncpy( buffer, argv[ 1 ], sizeof( buffer ) );
	buffer[ sizeof( buffer ) - 1 ] = 0; 
	printf( "Unused = %d, Buffer: '%s'\n", unused, buffer );	
	return EXIT_SUCCESS;
}
If you can answer that, then you can answer the original questions, I think.
Sebastiani is offline   Reply With Quote
Old 11-03-2009, 01:40 PM   #3
Registered User
 
Join Date: Nov 2008
Posts: 75
Quote:
Originally Posted by asdfgh View Post
Consider the following C program:
Code:
void func(char * str)
{
char buff[16];
strcpy(buff,str);
}
void main(int argc, char * argv[])
{
int check = 1;
func(argv);
if(check == 1)
{
printf(“check should be 1 (%d)\n”,check);
} else
{
Printf(“check should not be 1 (%d)\n”,check);
}
}
Q1. Mount buffer overflow attack on the given program and corrupt the variable “check” with the value 25.

After the buffer overflow attack the output of the program should be the following:

check should not be 1 (25)

Q2. Mount buffer overflow attack on the given program and bypass the “if” condition.

After the buffer overflow attack the output of the program should be the following:
check should not be 1 (1)

Q3. Increase the size of the buffer “buff” to as much as you want. Mount a buffer overflow attack and make the program execute a shell (“/bin/bash”).
Are you sure that your code isn't like this instead: func(argv[1]); ?
MisterIO is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
another do while question kbpsu C++ Programming 3 03-23-2009 12:14 PM
Design layer question mdoland C# Programming 0 10-19-2007 04:22 AM
A question on Pointers & Structs FJ8II C++ Programming 4 05-28-2007 10:56 PM
Question type program for beginners Kirdra C++ Programming 7 09-15-2002 05:10 AM
what does this warningmean??? kreyes C Programming 5 03-04-2002 07:53 AM


All times are GMT -6. The time now is 12:01 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22