How is stdout piped in to a file located in a different directory?
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I want to pipe the stdout of my python file exploit1.py
to be accepted as a command line argument of a C executable lab2C.c
. My intention is to overflow the char buffer in lab2C.c
so that the memory leaks in to int set_me
. This will cause conditional statement located in main() to call the shell() function even though I did not enter either of the correct passwords.
The problem is that exploit1.py
and lab2C.c
are located in two different directories that do not belong to the same local path. exploit1.py
is located in /tmp
. lab2C
and lab2C.c
are located in /levels/lab02
. How do I pipe the stdout of exploit1.py
to be accepted as a main function parameter of lab2C
?
Here are the two files for reference:
exploit1.py:
def main():
print("aaabbbcccdddeeexefxbexadxde")
main()
lab2C.c:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
void shell()
printf("You did it.n");
system("/bin/sh");
int main(int argc, char** argv)
if(argc != 2)
printf("usage:n%s stringn", argv[0]);
return EXIT_FAILURE;
int set_me = 0;
char buf[15];
strcpy(buf, argv[1]);
if(set_me == 0xdeadbeef)
shell();
else
printf("Not authenticated.nset_me was %dn", set_me);
return EXIT_SUCCESS;
directory pipe
add a comment |Â
up vote
0
down vote
favorite
I want to pipe the stdout of my python file exploit1.py
to be accepted as a command line argument of a C executable lab2C.c
. My intention is to overflow the char buffer in lab2C.c
so that the memory leaks in to int set_me
. This will cause conditional statement located in main() to call the shell() function even though I did not enter either of the correct passwords.
The problem is that exploit1.py
and lab2C.c
are located in two different directories that do not belong to the same local path. exploit1.py
is located in /tmp
. lab2C
and lab2C.c
are located in /levels/lab02
. How do I pipe the stdout of exploit1.py
to be accepted as a main function parameter of lab2C
?
Here are the two files for reference:
exploit1.py:
def main():
print("aaabbbcccdddeeexefxbexadxde")
main()
lab2C.c:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
void shell()
printf("You did it.n");
system("/bin/sh");
int main(int argc, char** argv)
if(argc != 2)
printf("usage:n%s stringn", argv[0]);
return EXIT_FAILURE;
int set_me = 0;
char buf[15];
strcpy(buf, argv[1]);
if(set_me == 0xdeadbeef)
shell();
else
printf("Not authenticated.nset_me was %dn", set_me);
return EXIT_SUCCESS;
directory pipe
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to pipe the stdout of my python file exploit1.py
to be accepted as a command line argument of a C executable lab2C.c
. My intention is to overflow the char buffer in lab2C.c
so that the memory leaks in to int set_me
. This will cause conditional statement located in main() to call the shell() function even though I did not enter either of the correct passwords.
The problem is that exploit1.py
and lab2C.c
are located in two different directories that do not belong to the same local path. exploit1.py
is located in /tmp
. lab2C
and lab2C.c
are located in /levels/lab02
. How do I pipe the stdout of exploit1.py
to be accepted as a main function parameter of lab2C
?
Here are the two files for reference:
exploit1.py:
def main():
print("aaabbbcccdddeeexefxbexadxde")
main()
lab2C.c:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
void shell()
printf("You did it.n");
system("/bin/sh");
int main(int argc, char** argv)
if(argc != 2)
printf("usage:n%s stringn", argv[0]);
return EXIT_FAILURE;
int set_me = 0;
char buf[15];
strcpy(buf, argv[1]);
if(set_me == 0xdeadbeef)
shell();
else
printf("Not authenticated.nset_me was %dn", set_me);
return EXIT_SUCCESS;
directory pipe
I want to pipe the stdout of my python file exploit1.py
to be accepted as a command line argument of a C executable lab2C.c
. My intention is to overflow the char buffer in lab2C.c
so that the memory leaks in to int set_me
. This will cause conditional statement located in main() to call the shell() function even though I did not enter either of the correct passwords.
The problem is that exploit1.py
and lab2C.c
are located in two different directories that do not belong to the same local path. exploit1.py
is located in /tmp
. lab2C
and lab2C.c
are located in /levels/lab02
. How do I pipe the stdout of exploit1.py
to be accepted as a main function parameter of lab2C
?
Here are the two files for reference:
exploit1.py:
def main():
print("aaabbbcccdddeeexefxbexadxde")
main()
lab2C.c:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
void shell()
printf("You did it.n");
system("/bin/sh");
int main(int argc, char** argv)
if(argc != 2)
printf("usage:n%s stringn", argv[0]);
return EXIT_FAILURE;
int set_me = 0;
char buf[15];
strcpy(buf, argv[1]);
if(set_me == 0xdeadbeef)
shell();
else
printf("Not authenticated.nset_me was %dn", set_me);
return EXIT_SUCCESS;
directory pipe
edited May 3 at 7:36
asked May 3 at 6:40
Darien Springer
33
33
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
3
down vote
accepted
Your C program does not read from standard input, so nothing can be piped to it. It expects command line arguments though, so you'd have to invoke it as
/levels/lab02/lab2C.exe "$(python /tmp/exploit1.py)"
If you are currently located in /levels/lab02
, then this may be shortened to
./lab2C.exe "$(python /tmp/exploit1.py)"
Note that it's uncommon to give executable files the .exe
suffix on Unix. You also have errors in your code (a buffer overrun, and missing headers), and the string in the Python code does not do what you think it does (the slashes should probably be backslashes).
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
Your C program does not read from standard input, so nothing can be piped to it. It expects command line arguments though, so you'd have to invoke it as
/levels/lab02/lab2C.exe "$(python /tmp/exploit1.py)"
If you are currently located in /levels/lab02
, then this may be shortened to
./lab2C.exe "$(python /tmp/exploit1.py)"
Note that it's uncommon to give executable files the .exe
suffix on Unix. You also have errors in your code (a buffer overrun, and missing headers), and the string in the Python code does not do what you think it does (the slashes should probably be backslashes).
add a comment |Â
up vote
3
down vote
accepted
Your C program does not read from standard input, so nothing can be piped to it. It expects command line arguments though, so you'd have to invoke it as
/levels/lab02/lab2C.exe "$(python /tmp/exploit1.py)"
If you are currently located in /levels/lab02
, then this may be shortened to
./lab2C.exe "$(python /tmp/exploit1.py)"
Note that it's uncommon to give executable files the .exe
suffix on Unix. You also have errors in your code (a buffer overrun, and missing headers), and the string in the Python code does not do what you think it does (the slashes should probably be backslashes).
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
Your C program does not read from standard input, so nothing can be piped to it. It expects command line arguments though, so you'd have to invoke it as
/levels/lab02/lab2C.exe "$(python /tmp/exploit1.py)"
If you are currently located in /levels/lab02
, then this may be shortened to
./lab2C.exe "$(python /tmp/exploit1.py)"
Note that it's uncommon to give executable files the .exe
suffix on Unix. You also have errors in your code (a buffer overrun, and missing headers), and the string in the Python code does not do what you think it does (the slashes should probably be backslashes).
Your C program does not read from standard input, so nothing can be piped to it. It expects command line arguments though, so you'd have to invoke it as
/levels/lab02/lab2C.exe "$(python /tmp/exploit1.py)"
If you are currently located in /levels/lab02
, then this may be shortened to
./lab2C.exe "$(python /tmp/exploit1.py)"
Note that it's uncommon to give executable files the .exe
suffix on Unix. You also have errors in your code (a buffer overrun, and missing headers), and the string in the Python code does not do what you think it does (the slashes should probably be backslashes).
edited May 3 at 6:49
answered May 3 at 6:47
Kusalananda
102k13199316
102k13199316
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f441466%2fhow-is-stdout-piped-in-to-a-file-located-in-a-different-directory%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password