It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
AFAIK, a buffer overflow is achieved by overwriting memory adjacent to a C variable's buffer. This overwriting is used to spawn a shell which executes commands.
But what if the user that is running the program vulnerable to a buffer overflow has the shell disabled ?
/etc/passwd:
user1:x:1000:1000:user1,,,,:/home/user1:/bin/false
sudo -u user1 /usr/bin/programname
"Shell disabled" only matters if you're actually logging in. If you're exploiting an already running program then you don't need to log in.
Exploits do not use a shell which is configured for a user — they normally include a binary code, shellcode, which are functionally equivalent to a primitive shell, meaning that it will start any chosen executable — for example a real shell program. Exploited program is then tricked to execute this code.
There are many different shellcodes available on the net, for example which do not include a byte '\0', so they will be passed unharmed as a C string, or which only include printable characters, valid unicode strings etc.
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
How does GCC ensure that The Stack doesn't overflow?
Shouldn't it check the Size is less than the MAX it can retain and prompt user accordingly,esp when it is implicitly defined?WIll this not be a great programming paradigm?
It doesn't. If you recurse deep enough, you will overflow, and there's nothing the compiler can do about it.
edit: I should point out that at the time I answered this question, the question simply read:
"How does GCC ensure that The Stack doesn't overflow?"
Linux uses a "guard area". It puts one or more access-protect pages at the end of the stack for each thread.
If the program accesses the guard area, the OS handles the fault. If the thread is already using its max permitted stack then it terminates something (the thread or the whole process, I don't remember which). Otherwise it tries to map memory to the addresses occupied by the guard area for use as stack, and protects a new area beyond the end of the newly-enlarged stack.
Prompting the user isn't really suitable for an OS like Linux, in which many processes are not monitored by a user, and for that matter there may not be any logged-in user at the time the problem arises. So your process just fails. Since it's an all-purpose compiler, gcc doesn't attempt runtime user interaction either.
Other OSes and platforms may or may not have stack guard pages (Windows does). About all gcc really needs to do is to ensure that if the stack is going to be exceeded, it doesn't "miss" the guard page by jumping a long way forward.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I was solving a practice problem on a site which states that
The purpose of this problem is to verify whether the method you are
using to read input data is sufficiently fast to handle problems
branded with the enormous Input/Output warning. You are expected to be
able to process at least 2.5MB of input data per second at runtime.
Also how do I optimize input/output routines other than printf and scanf?
It is operating system specific (because the C standard only knows about <stdio.h>). With Linux consider using low-level syscalls for efficiency, like open(2), mmap(2), read(2), pread(2), write(2). You might also want to use readahead(2). Don't forget to make I/O in rather large blocks (e.g. 128Kbytes), page aligned if possible. Read the Advanced Linux Programming book.
If restricted to standard C99 functions, use fread(3) on rather big chunks. Consider also increasing the internal buffer with setvbuf(3)
And 2.5Mbyte/sec is not very impressive. Probably, the bottleneck is the hardware, but you should be able to get perhaps 20 or 50Mbytes/sec on a standard desktop hardware. Using SSD would help a big lot.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I'm trying to get the size of a file from the commandline in C using argv. I'm not too familiar with file i/o in C, so any pointers would be greatly appreciated. Thanks.
You've not stated the platform, but your C program is given an argument list when it is started, and the file names are strings. The POSIX function you'd probably use is stat(); it takes a pointer to a struct stat and will put the file's size into the st_size member of the structure.
The answer may be different on Windows; the POSIX subsystem will provide a stat() workalike (probably named _stat()), but there'll also be a native interface.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 12 years ago.
is it possible to write a C program that reads another program line by line and make it(2nd program) execute? please help
Yes.
But the details are complicated and depend on many things that you don't specify in your question.
What language is the second program written in?
Why you want to do this will affect how it should be done
Are you looking to control the 2nd program in some advanced way?
etc.
yes, with exec on unix and ShellExecute on windows
It's called an interpreter. Google for "C interpreter".
Read in the program, put it into a file, compile, link and execute it?
C isn't Perl if that is what you are looking for.
Frank
Yes. It is not only possible, but done all the time. UNIBASIC & UNIBASIC DL4 are two of the languages that I've used that are written in C.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 12 years ago.
I am writing a C program that reads a text file and parses the data in it into various fields. The text file I am reading from is very large though (31MB) and when I run the program on a text file that has 41880 lines of input everything works fine. I will ultimately need to read from text files that are much much larger than that though. So when I increase the lines to 41881 though I get a segmentation fault. Any ideas?
You are trashing memory somewhere along the way and it's finally hitting you at line 41881.
If your platform is supported, try running under Valgrind.