How is stdout piped in to a file located in a different directory?

The name of the pictureThe name of the pictureThe name of the pictureClash 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;







share|improve this question

























    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;







    share|improve this question























      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;







      share|improve this question













      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;









      share|improve this question












      share|improve this question




      share|improve this question








      edited May 3 at 7:36
























      asked May 3 at 6:40









      Darien Springer

      33




      33




















          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).






          share|improve this answer























            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );








             

            draft saved


            draft discarded


















            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






























            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).






            share|improve this answer



























              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).






              share|improve this answer

























                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).






                share|improve this answer















                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).







                share|improve this answer















                share|improve this answer



                share|improve this answer








                edited May 3 at 6:49


























                answered May 3 at 6:47









                Kusalananda

                102k13199316




                102k13199316






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    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













































































                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Displaying single band from multi-band raster using QGIS

                    How many registers does an x86_64 CPU actually have?