execve

execve with path search?

无人久伴 提交于 2019-12-12 09:42:40
问题 I want to execute a program from my code, and supply it with environment variables and arguments. AFAICT, execve is the right choice. But, execve receives a path argument, not a filename , meaning it expects the first argument to be a path to the executable. I know I can parse $PATH myself to find the path, but really, is there no other choice? Has no one else implemented it somewhere for me to use? 回答1: Some systems may provide execvpe() . A Google search for 'execvpe' shows a variety of

How do I make this simple shellcode c program compile from terminal?

坚强是说给别人听的谎言 提交于 2019-12-11 04:09:24
问题 I am trying to compile this using the terminal on ubuntu 12: #include <stdio.h> #include <stdlib.h> main() { /*declare argument array*/ char *args[2]; args[0] = “/bin/bash”; args[1] = NULL; execve(args[0], args, NULL); exit(0); } I found this example on http://www.securitytube.net/video/235 which also happened to be the one Aleph One used in 'Smashing the Stack for Fun and Profit'. I am aware that much has changed since then. In more simple examples I have used: gcc -ggdb -mpreferred-stack

Call Unix external commands with arguments

限于喜欢 提交于 2019-12-11 03:16:57
问题 I've found a way to call unix external commands without arguments(ex. "ls", "pwd"). It goes like that: //Child process char cwd[1024]; getcwd(cwd, sizeof(cwd)); char *argv[] = {*args, NULL}//(ex.) {"ls", NULL} char *env[] = {cwd, NULL}; //concat():method that connects 2 strings char *command_source = concat("/bin/", *args); execve(command_source, argv, env); return 0; I'm trying to convert this code in order to accept external commands with arguments like "ls -l" 回答1: Assuming that you know

execve with path search?

瘦欲@ 提交于 2019-12-10 08:53:36
问题 I want to execute a program from my code, and supply it with environment variables and arguments. AFAICT, execve is the right choice. But, execve receives a path argument, not a filename , meaning it expects the first argument to be a path to the executable. I know I can parse $PATH myself to find the path, but really, is there no other choice? Has no one else implemented it somewhere for me to use? 回答1: Some systems may provide execvpe() . A Google search for 'execvpe' shows a variety of

C - Passing A Pipe thru execve

孤人 提交于 2019-12-09 23:55:52
问题 I am working on a project for school and I am not sure if the way I am trying to solve it is even possible. The project involves making a program, forking off 2 children which then have to replace their pid's with other programs, and having the 2 children talk thru a pipe by use of read() and write(). The question I have is with using execve and passing the pipe thru to that child. What I have right now is this: Parent Program - forking and having the child call execve: #include <unistd.h>

Are the arguments of a C program guaranteed to be '\0'-terminated?

。_饼干妹妹 提交于 2019-12-07 15:14:17
问题 About the arguments of main() , the 2011 C standard says (5.1.2.2.1:2): If the value of argc is greater than zero, the array members argv[0] through argv[argc-1] inclusive shall contain pointers to strings, which are given implementation-defined values by the host environment prior to program startup. Should the word “string” in this context be interpreted as “0-terminated string”, that is, a sequence of non-0 characters followed by a final '\0', or do/may some implementations pass arguments

execve with path search?

你说的曾经没有我的故事 提交于 2019-12-05 16:10:32
I want to execute a program from my code, and supply it with environment variables and arguments. AFAICT, execve is the right choice. But, execve receives a path argument, not a filename , meaning it expects the first argument to be a path to the executable. I know I can parse $PATH myself to find the path, but really, is there no other choice? Has no one else implemented it somewhere for me to use? Some systems may provide execvpe() . A Google search for 'execvpe' shows a variety of options, including at least one implementation (considerably more complex than what follows, but it includes

C - Passing A Pipe thru execve

天涯浪子 提交于 2019-12-04 20:17:39
I am working on a project for school and I am not sure if the way I am trying to solve it is even possible. The project involves making a program, forking off 2 children which then have to replace their pid's with other programs, and having the 2 children talk thru a pipe by use of read() and write(). The question I have is with using execve and passing the pipe thru to that child. What I have right now is this: Parent Program - forking and having the child call execve: #include <unistd.h> #include <stdio.h> #include <errno.h> #include <stdlib.h> #include <sys/stat.h> #include <fcntl.h>

understanding requirements for execve and setting environment vars

好久不见. 提交于 2019-12-03 12:55:08
问题 We are having a lot of trouble interpreting our teacher. We asked for clarification and got the following back from him For execve, send it a environment you setup with your exported variables and create a builtin command to spawn a subshell of /bin/bash, that way you can see your exported variables using env. (He is talking about creating our own environment vars here.) Yes create your own. You can start by copying environ when your shell starts and add only exported variables This is

execve(“/bin/sh”, 0, 0); in a pipe

爷,独闯天下 提交于 2019-12-03 11:53:23
I have the following example program: #include <stdio.h> int main(int argc, char ** argv){ char buf[100]; printf("Please enter your name: "); fflush(stdout); gets(buf); printf("Hello \"%s\"\n", buf); execve("/bin/sh", 0, 0); } I and when I run without any pipe it works as it should and returns a sh promt: bash$ ./a.out Please enter your name: warning: this program uses gets() which is unsafe. testName Hello "testName" $ exit bash$ But this does not work in a pipe, i think I know why that is, but I cannot figure out a solution. Example run bellow. bash$ echo -e "testName\npwd" | ./a.out Please