Charred_Phoenix
07-10-2003, 01:13 AM
In C, how would you go about making your output another program's input (like when you pipe two commands)?
|
Click to See Complete Forum and Search --> : Writing to program Charred_Phoenix 07-10-2003, 01:13 AM In C, how would you go about making your output another program's input (like when you pipe two commands)? Citadel 07-10-2003, 01:25 AM You could save the first programs data in a text file with a specific name, than you would still use a shell script. Otherwise if everything were done inside of one program than you would have to use threads. delryn 07-10-2003, 01:31 AM Originally posted by Charred_Phoenix In C, how would you go about making your output another program's input (like when you pipe two commands)? IT's been a while since I've done even basic programming (read 6-8 years). But I would assume you would declare a system wide variable to memory, and have the second program read that variable. Or as Citadel recommended save the output as a string to a text file and have the second program read that file. That would work better if there is a system shutdown between creation and execution, and probably free up more memory for slower systems - though I am not 100% on that. Again I am rusty. Charred_Phoenix 07-10-2003, 02:36 AM Well, I now see my post wasn't very clear, pehaps if I explain exactly what I am trying to do it will clear up some of the ambiguity. I'm simply wondering how one would go about exploiting a buffer overflow in a program that copies input from stdin rather than the command line. So I want to be able to run a program, have it run the second one with the exploits output going to the progams input. Citadel 07-10-2003, 08:52 AM Have you tried to use threads? Stuka 07-10-2003, 09:48 AM Here's the trick: use pipe(2) to create the 2 file descriptors (the write end for your code, the read end for the code you're going to send data too). Then, fork, and in the child process, close stdin. Now, call dup(2) - because it creates the new fd in the lowest available spot, this automatically becomes stdin for the child process. Next, exec() the program you want to send data to. Now it's stdin is the output from your write end of the pipe. NOTE: I do NOT encourage or condone cracking. However, this is a valid, useful C technique in Unix, and a determined searcher will find it (I learned it from W. Richard Stevens' 'Unix Network Programming v. 2'). stoe 07-10-2003, 09:51 AM edit: beat to the punch by Stuka! i assume you're not doing this for malicious purposes, otherwise you probably wouldn't have posted on a public message board looking for help. your gonna need the following functions: fork(), pipe(), and dup2(). i would recommend looking through the glibc manual for these functions. here is a link to a page within the manual describing an example of exactly what you want to do. http://www.gnu.org/manual/glibc-2.2.5/html_node/Creating-a-Pipe.html#Creating%20a%20Pipe Strogian 07-10-2003, 10:24 AM What's wrong with using a normal pipe, on the command-line? bwkaz 07-10-2003, 06:49 PM Sorry guys, but this isn't a "teach me how to use exploits" board... Stuka's answer is correct (and has been illustrated by him before, in at least this (http://www.justlinux.com/forum/showthread.php?s=&postid=301819#post301819) thread), but the owners of the JL boards cannot be responsible for people misusing information they find here. justlinux.com
Copyright Internet.com Inc. All Rights Reserved. |