![]() |
| | #1 |
| Registered User Join Date: Dec 2009
Posts: 1
| Bufferoverflow in c iam new to this topic. but i has to learn the things for my academic project. Please anybody give me the sompe sample programs for bufferoverflow in c language. |
| dileep is offline | |
| | #2 |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 12,460
| What do you understand by "buffer overflow"? You should be able to construct a very simple example yourself given that understanding.
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way |
| laserlight is online now | |
| | #3 |
| Registered User Join Date: Sep 2006
Posts: 3,720
| gets() would be a great candidate for a good buffer overflow example. I don't have such an example, but you should be able to find several with a bit of googling. |
| Adak is offline | |
| | #4 | |
| Learning C. Join Date: Nov 2009
Posts: 59
| Quote:
Code: #include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]) {
int value = 5;
char buffer_one[8], buffer_two[8];
strcpy(buffer_one, "one"); /* Put "one" into buffer_one. */
strcpy(buffer_two, "two"); /* Put "two" into buffer_two. */
printf("[BEFORE] buffer_two is at %p and contains \'%s\'\n", buffer_two, buffer_two);
printf("[BEFORE] buffer_one is at %p and contains \'%s\'\n", buffer_one, buffer_one);
printf("[BEFORE] value is at %p and is %d (0x%08x)\n", &value, value, value);
printf("\n[STRCPY] copying %d bytes into buffer_two\n\n", strlen(argv[1]));
strcpy(buffer_two, argv[1]); /* Copy first argument into buffer_two. */
printf("[AFTER] buffer_two is at %p and contains \'%s\'\n", buffer_two, buffer_two);
printf("[AFTER] buffer_one is at %p and contains \'%s\'\n", buffer_one, buffer_one);
printf("[AFTER] value is at %p and is %d (0x%08x)\n", &value, value, value);
}
| |
| JOZZY& Wakko is offline | |
| | #5 |
| Registered User Join Date: Oct 2008
Posts: 943
| I've always been a fan of the following brain-dead example: Code: #include <stdio.h>
int main()
{
int *a[1];
int i;
printf("Main\n");
for(i = 0; i < 10; i++)
a[i] = main;
}
|
| EVOEx is offline | |
| | #6 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 16,078
| You think that should compile? It shouldn't. A better example should be: Code: int main()
{
int a[1];
for (int i = 0; i < 10; i++)
a[i] = 0;
}
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2010 Ultimate, C++0x "Thanks Elysia. You're a programming master! How the hell do you know every thing?" "Thanks for all your help. It's obvious yall really know what you're talking about when it comes to OOP/C++ stuff." Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #7 |
| Staff software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 6,014
| Your example removes all the coolness. The reason for using main as the value is so that the stack return address gets overwritten with the address of main, causing an infinite loop when the function tries to return. Yes, it might not compile as-is, but it would with an appropriate cast.
__________________ "Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot |
| brewbuck is offline | |
| | #8 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 16,078
| I'm fine with the example if it would compile. So if we would use a real function pointer, that would be cool. Code: typedef int (main_ptr)();
int main()
{
main_ptr* ptr[1];
for (int i = 0; i < 10; i++)
ptr[i] = &main;
}
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2010 Ultimate, C++0x "Thanks Elysia. You're a programming master! How the hell do you know every thing?" "Thanks for all your help. It's obvious yall really know what you're talking about when it comes to OOP/C++ stuff." Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #9 | |
| Staff software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 6,014
| Quote:
Would be a cool demo if it did work, and I'm sure it does, on some compilers.
__________________ "Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot | |
| brewbuck is offline | |
| | #10 |
| Registered User Join Date: Dec 2009 Location: Henderson, NV
Posts: 887
| Speaking of overflows....question for the Windows gurus out there.... back in the WinXP/Win2K era there was a way of blue-screening a Windows box with a printf() that went something like: Code: for(int x = 0; x < 5; x++)
printf("\t\t\b\b\b");
|
| jeffcobb is offline | |
| | #11 | ||
| Mysterious C++ User Join Date: Oct 2007
Posts: 16,078
| Quote:
![]() /boots up Visual Studio.
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2010 Ultimate, C++0x "Thanks Elysia. You're a programming master! How the hell do you know every thing?" "Thanks for all your help. It's obvious yall really know what you're talking about when it comes to OOP/C++ stuff." Quoted... at least once. Quote:
| ||
| Elysia is offline | |
| | #12 | |
| dat is, vast staat Join Date: Jul 2008 Location: SE Queens
Posts: 6,612
| Quote:
Just kidding.
__________________ C programming resources: GNU C Function and Macro Index -- glibc reference manual The C Book -- nice online learner guide Current ISO draft standard CCAN -- new CPAN like open source library repository GDB tutorial #1 -- gnu debugger tutorials -- GDB tutorial #2 cpwiki -- our wiki on sourceforge | |
| MK27 is offline | |
| | #13 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 16,078
| I got it working: Code: #include <stdlib.h>
typedef int (main_ptr)();
int main()
{
main_ptr* ptr[1];
printf("Main!\n");
for (int i = 0; i < 3; i++)
ptr[i] = &main;
__asm sub ebp, 4;
}
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2010 Ultimate, C++0x "Thanks Elysia. You're a programming master! How the hell do you know every thing?" "Thanks for all your help. It's obvious yall really know what you're talking about when it comes to OOP/C++ stuff." Quoted... at least once. Quote:
Last edited by Elysia; 12-18-2009 at 04:15 PM. | |
| Elysia is offline | |
| | #14 |
| and the Rod of Remorse Join Date: Apr 2006 Location: United States
Posts: 3,633
| |
| whiteflags is offline | |
| | #15 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 16,078
| Taking the address of a function without the &.
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2010 Ultimate, C++0x "Thanks Elysia. You're a programming master! How the hell do you know every thing?" "Thanks for all your help. It's obvious yall really know what you're talking about when it comes to OOP/C++ stuff." Quoted... at least once. Quote:
| |
| Elysia is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| C bufferoverflow question. can anyone solve it? | asdfgh | Linux Programming | 2 | 11-03-2009 01:40 PM |
| Constructive criticism, suggestions etc | BobS0327 | C Programming | 3 | 01-08-2006 09:35 AM |