Shell Script in netcat listener to talk with client
I have this script on my netcat server which asks for name and some other information:
*echo "Tell me your name"
read $ln
echo "I got '$ln'"
echo "Tell me something more"
while read ln; do
echo "I got '$ln'"
echo "Tell me something more"
done*
When a client connects to this server, I want the script to communicate with the client directly.
On server end I do : while true; do nc -l -p port-no | ./My-script-file ; done
The while loop is just so that the server continues listening even after one client has closed the connection and nothing else. But somehow, I cannot get the queries to appear on client side.
On client side I do: nc server-ip port-no
I want the lines "Tell me your name", "I got..." and "Tell me something else" to appear on client screen and the input from client end to be fed into the script.
I have also tried options like --exec
, -e
and --sh-exec
and the errors I am getting are something like
nc: invalid option -- '-'
usage: nc [-46CDdFhklNnrStUuvZz] [-I length] [-i interval] [-M ttl]
[-m minttl] [-O length] [-P proxy_username] [-p source_port]
[-q seconds] [-s source] [-T keyword] [-V rtable] [-W recvlimit] [-w timeout]
[-X proxy_protocol] [-x proxy_address[:port]] [destination] [port]
linux shell-script shell netcat nc
add a comment |
I have this script on my netcat server which asks for name and some other information:
*echo "Tell me your name"
read $ln
echo "I got '$ln'"
echo "Tell me something more"
while read ln; do
echo "I got '$ln'"
echo "Tell me something more"
done*
When a client connects to this server, I want the script to communicate with the client directly.
On server end I do : while true; do nc -l -p port-no | ./My-script-file ; done
The while loop is just so that the server continues listening even after one client has closed the connection and nothing else. But somehow, I cannot get the queries to appear on client side.
On client side I do: nc server-ip port-no
I want the lines "Tell me your name", "I got..." and "Tell me something else" to appear on client screen and the input from client end to be fed into the script.
I have also tried options like --exec
, -e
and --sh-exec
and the errors I am getting are something like
nc: invalid option -- '-'
usage: nc [-46CDdFhklNnrStUuvZz] [-I length] [-i interval] [-M ttl]
[-m minttl] [-O length] [-P proxy_username] [-p source_port]
[-q seconds] [-s source] [-T keyword] [-V rtable] [-W recvlimit] [-w timeout]
[-X proxy_protocol] [-x proxy_address[:port]] [destination] [port]
linux shell-script shell netcat nc
add a comment |
I have this script on my netcat server which asks for name and some other information:
*echo "Tell me your name"
read $ln
echo "I got '$ln'"
echo "Tell me something more"
while read ln; do
echo "I got '$ln'"
echo "Tell me something more"
done*
When a client connects to this server, I want the script to communicate with the client directly.
On server end I do : while true; do nc -l -p port-no | ./My-script-file ; done
The while loop is just so that the server continues listening even after one client has closed the connection and nothing else. But somehow, I cannot get the queries to appear on client side.
On client side I do: nc server-ip port-no
I want the lines "Tell me your name", "I got..." and "Tell me something else" to appear on client screen and the input from client end to be fed into the script.
I have also tried options like --exec
, -e
and --sh-exec
and the errors I am getting are something like
nc: invalid option -- '-'
usage: nc [-46CDdFhklNnrStUuvZz] [-I length] [-i interval] [-M ttl]
[-m minttl] [-O length] [-P proxy_username] [-p source_port]
[-q seconds] [-s source] [-T keyword] [-V rtable] [-W recvlimit] [-w timeout]
[-X proxy_protocol] [-x proxy_address[:port]] [destination] [port]
linux shell-script shell netcat nc
I have this script on my netcat server which asks for name and some other information:
*echo "Tell me your name"
read $ln
echo "I got '$ln'"
echo "Tell me something more"
while read ln; do
echo "I got '$ln'"
echo "Tell me something more"
done*
When a client connects to this server, I want the script to communicate with the client directly.
On server end I do : while true; do nc -l -p port-no | ./My-script-file ; done
The while loop is just so that the server continues listening even after one client has closed the connection and nothing else. But somehow, I cannot get the queries to appear on client side.
On client side I do: nc server-ip port-no
I want the lines "Tell me your name", "I got..." and "Tell me something else" to appear on client screen and the input from client end to be fed into the script.
I have also tried options like --exec
, -e
and --sh-exec
and the errors I am getting are something like
nc: invalid option -- '-'
usage: nc [-46CDdFhklNnrStUuvZz] [-I length] [-i interval] [-M ttl]
[-m minttl] [-O length] [-P proxy_username] [-p source_port]
[-q seconds] [-s source] [-T keyword] [-V rtable] [-W recvlimit] [-w timeout]
[-X proxy_protocol] [-x proxy_address[:port]] [destination] [port]
linux shell-script shell netcat nc
linux shell-script shell netcat nc
edited Dec 21 '18 at 19:43
GAD3R
25.5k1750107
25.5k1750107
asked Dec 21 '18 at 18:33
Shritama Sengupta
368
368
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
It seems Open-BSD netcat does not support -e
or --exec
commands which helps us to execute a file after a connection has been made. Since it is might cause the remote machine to run potentially harmful command to the connected machine, these commands are considered as dangerous.
As a work around I just uninstalled Open-BSD netcat and installed traditional-netcat server following the solution in the site https://stackoverflow.com/questions/10065993/how-to-switch-to-netcat-traditional-in-ubuntu. This gave me access to the -exec command.
The command that I run on server is : nc -l -p port-number -e File-Script-to-execute
add a comment |
Ok, so here I've set up a small example:
#!/bin/bash
while read -p 'Tell me your name: ' ln;
do
echo "I got $ln";
done
So you save the script make it executable and run it as follows:
On the server
nc -l -p 4444 -k --sh-exec ./yourscript
Here -k
does keep the connection open so no need for the loop you got there.
On the client
nc hostname 4444
foo bar
This should do the job.
I have tried using the --exec command before and it didn't work. I tried your command and this is what I got: root@kali:~/Desktop# nc -l -p 4444 -k --sh-exec ./Test-Script nc: invalid option -- '-' usage: nc [-46CDdFhklNnrStUuvZz] [-I length] [-i interval] [-M ttl] [-m minttl] [-O length] [-P proxy_username] [-p source_port] [-q seconds] [-s source] [-T keyword] [-V rtable] [-W recvlimit] [-w timeout] [-X proxy_protocol] [-x proxy_address[:port]] [destination] [port] root@kali:~/Desktop#
– Shritama Sengupta
Dec 21 '18 at 18:53
@ShritamaSengupta what version of netcat are you using? Doesnc --help
show you the option--sh-exec
?
– Valentin Bajrami
Dec 21 '18 at 18:56
I got this:nc -h OpenBSD netcat (Debian patchlevel 1.195-1)
– Shritama Sengupta
Dec 21 '18 at 19:00
@ShritamaSengupta yournc
doesn't support the exec flag the. There is this answer here but it usesnamed pipes
superuser.com/questions/691008/…
– Valentin Bajrami
Dec 21 '18 at 19:26
I just installed the traditional-netcat instead and accessed the -exec command. This seemed as the easier way to achieve my task. Thank you for your hint though.
– Shritama Sengupta
Dec 21 '18 at 19:29
|
show 1 more comment
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',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f490371%2fshell-script-in-netcat-listener-to-talk-with-client%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
It seems Open-BSD netcat does not support -e
or --exec
commands which helps us to execute a file after a connection has been made. Since it is might cause the remote machine to run potentially harmful command to the connected machine, these commands are considered as dangerous.
As a work around I just uninstalled Open-BSD netcat and installed traditional-netcat server following the solution in the site https://stackoverflow.com/questions/10065993/how-to-switch-to-netcat-traditional-in-ubuntu. This gave me access to the -exec command.
The command that I run on server is : nc -l -p port-number -e File-Script-to-execute
add a comment |
It seems Open-BSD netcat does not support -e
or --exec
commands which helps us to execute a file after a connection has been made. Since it is might cause the remote machine to run potentially harmful command to the connected machine, these commands are considered as dangerous.
As a work around I just uninstalled Open-BSD netcat and installed traditional-netcat server following the solution in the site https://stackoverflow.com/questions/10065993/how-to-switch-to-netcat-traditional-in-ubuntu. This gave me access to the -exec command.
The command that I run on server is : nc -l -p port-number -e File-Script-to-execute
add a comment |
It seems Open-BSD netcat does not support -e
or --exec
commands which helps us to execute a file after a connection has been made. Since it is might cause the remote machine to run potentially harmful command to the connected machine, these commands are considered as dangerous.
As a work around I just uninstalled Open-BSD netcat and installed traditional-netcat server following the solution in the site https://stackoverflow.com/questions/10065993/how-to-switch-to-netcat-traditional-in-ubuntu. This gave me access to the -exec command.
The command that I run on server is : nc -l -p port-number -e File-Script-to-execute
It seems Open-BSD netcat does not support -e
or --exec
commands which helps us to execute a file after a connection has been made. Since it is might cause the remote machine to run potentially harmful command to the connected machine, these commands are considered as dangerous.
As a work around I just uninstalled Open-BSD netcat and installed traditional-netcat server following the solution in the site https://stackoverflow.com/questions/10065993/how-to-switch-to-netcat-traditional-in-ubuntu. This gave me access to the -exec command.
The command that I run on server is : nc -l -p port-number -e File-Script-to-execute
edited Dec 22 '18 at 11:45
Rui F Ribeiro
39.1k1479130
39.1k1479130
answered Dec 21 '18 at 19:56
Shritama Sengupta
368
368
add a comment |
add a comment |
Ok, so here I've set up a small example:
#!/bin/bash
while read -p 'Tell me your name: ' ln;
do
echo "I got $ln";
done
So you save the script make it executable and run it as follows:
On the server
nc -l -p 4444 -k --sh-exec ./yourscript
Here -k
does keep the connection open so no need for the loop you got there.
On the client
nc hostname 4444
foo bar
This should do the job.
I have tried using the --exec command before and it didn't work. I tried your command and this is what I got: root@kali:~/Desktop# nc -l -p 4444 -k --sh-exec ./Test-Script nc: invalid option -- '-' usage: nc [-46CDdFhklNnrStUuvZz] [-I length] [-i interval] [-M ttl] [-m minttl] [-O length] [-P proxy_username] [-p source_port] [-q seconds] [-s source] [-T keyword] [-V rtable] [-W recvlimit] [-w timeout] [-X proxy_protocol] [-x proxy_address[:port]] [destination] [port] root@kali:~/Desktop#
– Shritama Sengupta
Dec 21 '18 at 18:53
@ShritamaSengupta what version of netcat are you using? Doesnc --help
show you the option--sh-exec
?
– Valentin Bajrami
Dec 21 '18 at 18:56
I got this:nc -h OpenBSD netcat (Debian patchlevel 1.195-1)
– Shritama Sengupta
Dec 21 '18 at 19:00
@ShritamaSengupta yournc
doesn't support the exec flag the. There is this answer here but it usesnamed pipes
superuser.com/questions/691008/…
– Valentin Bajrami
Dec 21 '18 at 19:26
I just installed the traditional-netcat instead and accessed the -exec command. This seemed as the easier way to achieve my task. Thank you for your hint though.
– Shritama Sengupta
Dec 21 '18 at 19:29
|
show 1 more comment
Ok, so here I've set up a small example:
#!/bin/bash
while read -p 'Tell me your name: ' ln;
do
echo "I got $ln";
done
So you save the script make it executable and run it as follows:
On the server
nc -l -p 4444 -k --sh-exec ./yourscript
Here -k
does keep the connection open so no need for the loop you got there.
On the client
nc hostname 4444
foo bar
This should do the job.
I have tried using the --exec command before and it didn't work. I tried your command and this is what I got: root@kali:~/Desktop# nc -l -p 4444 -k --sh-exec ./Test-Script nc: invalid option -- '-' usage: nc [-46CDdFhklNnrStUuvZz] [-I length] [-i interval] [-M ttl] [-m minttl] [-O length] [-P proxy_username] [-p source_port] [-q seconds] [-s source] [-T keyword] [-V rtable] [-W recvlimit] [-w timeout] [-X proxy_protocol] [-x proxy_address[:port]] [destination] [port] root@kali:~/Desktop#
– Shritama Sengupta
Dec 21 '18 at 18:53
@ShritamaSengupta what version of netcat are you using? Doesnc --help
show you the option--sh-exec
?
– Valentin Bajrami
Dec 21 '18 at 18:56
I got this:nc -h OpenBSD netcat (Debian patchlevel 1.195-1)
– Shritama Sengupta
Dec 21 '18 at 19:00
@ShritamaSengupta yournc
doesn't support the exec flag the. There is this answer here but it usesnamed pipes
superuser.com/questions/691008/…
– Valentin Bajrami
Dec 21 '18 at 19:26
I just installed the traditional-netcat instead and accessed the -exec command. This seemed as the easier way to achieve my task. Thank you for your hint though.
– Shritama Sengupta
Dec 21 '18 at 19:29
|
show 1 more comment
Ok, so here I've set up a small example:
#!/bin/bash
while read -p 'Tell me your name: ' ln;
do
echo "I got $ln";
done
So you save the script make it executable and run it as follows:
On the server
nc -l -p 4444 -k --sh-exec ./yourscript
Here -k
does keep the connection open so no need for the loop you got there.
On the client
nc hostname 4444
foo bar
This should do the job.
Ok, so here I've set up a small example:
#!/bin/bash
while read -p 'Tell me your name: ' ln;
do
echo "I got $ln";
done
So you save the script make it executable and run it as follows:
On the server
nc -l -p 4444 -k --sh-exec ./yourscript
Here -k
does keep the connection open so no need for the loop you got there.
On the client
nc hostname 4444
foo bar
This should do the job.
answered Dec 21 '18 at 18:49
Valentin Bajrami
5,90611627
5,90611627
I have tried using the --exec command before and it didn't work. I tried your command and this is what I got: root@kali:~/Desktop# nc -l -p 4444 -k --sh-exec ./Test-Script nc: invalid option -- '-' usage: nc [-46CDdFhklNnrStUuvZz] [-I length] [-i interval] [-M ttl] [-m minttl] [-O length] [-P proxy_username] [-p source_port] [-q seconds] [-s source] [-T keyword] [-V rtable] [-W recvlimit] [-w timeout] [-X proxy_protocol] [-x proxy_address[:port]] [destination] [port] root@kali:~/Desktop#
– Shritama Sengupta
Dec 21 '18 at 18:53
@ShritamaSengupta what version of netcat are you using? Doesnc --help
show you the option--sh-exec
?
– Valentin Bajrami
Dec 21 '18 at 18:56
I got this:nc -h OpenBSD netcat (Debian patchlevel 1.195-1)
– Shritama Sengupta
Dec 21 '18 at 19:00
@ShritamaSengupta yournc
doesn't support the exec flag the. There is this answer here but it usesnamed pipes
superuser.com/questions/691008/…
– Valentin Bajrami
Dec 21 '18 at 19:26
I just installed the traditional-netcat instead and accessed the -exec command. This seemed as the easier way to achieve my task. Thank you for your hint though.
– Shritama Sengupta
Dec 21 '18 at 19:29
|
show 1 more comment
I have tried using the --exec command before and it didn't work. I tried your command and this is what I got: root@kali:~/Desktop# nc -l -p 4444 -k --sh-exec ./Test-Script nc: invalid option -- '-' usage: nc [-46CDdFhklNnrStUuvZz] [-I length] [-i interval] [-M ttl] [-m minttl] [-O length] [-P proxy_username] [-p source_port] [-q seconds] [-s source] [-T keyword] [-V rtable] [-W recvlimit] [-w timeout] [-X proxy_protocol] [-x proxy_address[:port]] [destination] [port] root@kali:~/Desktop#
– Shritama Sengupta
Dec 21 '18 at 18:53
@ShritamaSengupta what version of netcat are you using? Doesnc --help
show you the option--sh-exec
?
– Valentin Bajrami
Dec 21 '18 at 18:56
I got this:nc -h OpenBSD netcat (Debian patchlevel 1.195-1)
– Shritama Sengupta
Dec 21 '18 at 19:00
@ShritamaSengupta yournc
doesn't support the exec flag the. There is this answer here but it usesnamed pipes
superuser.com/questions/691008/…
– Valentin Bajrami
Dec 21 '18 at 19:26
I just installed the traditional-netcat instead and accessed the -exec command. This seemed as the easier way to achieve my task. Thank you for your hint though.
– Shritama Sengupta
Dec 21 '18 at 19:29
I have tried using the --exec command before and it didn't work. I tried your command and this is what I got: root@kali:~/Desktop# nc -l -p 4444 -k --sh-exec ./Test-Script nc: invalid option -- '-' usage: nc [-46CDdFhklNnrStUuvZz] [-I length] [-i interval] [-M ttl] [-m minttl] [-O length] [-P proxy_username] [-p source_port] [-q seconds] [-s source] [-T keyword] [-V rtable] [-W recvlimit] [-w timeout] [-X proxy_protocol] [-x proxy_address[:port]] [destination] [port] root@kali:~/Desktop#
– Shritama Sengupta
Dec 21 '18 at 18:53
I have tried using the --exec command before and it didn't work. I tried your command and this is what I got: root@kali:~/Desktop# nc -l -p 4444 -k --sh-exec ./Test-Script nc: invalid option -- '-' usage: nc [-46CDdFhklNnrStUuvZz] [-I length] [-i interval] [-M ttl] [-m minttl] [-O length] [-P proxy_username] [-p source_port] [-q seconds] [-s source] [-T keyword] [-V rtable] [-W recvlimit] [-w timeout] [-X proxy_protocol] [-x proxy_address[:port]] [destination] [port] root@kali:~/Desktop#
– Shritama Sengupta
Dec 21 '18 at 18:53
@ShritamaSengupta what version of netcat are you using? Does
nc --help
show you the option --sh-exec
?– Valentin Bajrami
Dec 21 '18 at 18:56
@ShritamaSengupta what version of netcat are you using? Does
nc --help
show you the option --sh-exec
?– Valentin Bajrami
Dec 21 '18 at 18:56
I got this:nc -h OpenBSD netcat (Debian patchlevel 1.195-1)
– Shritama Sengupta
Dec 21 '18 at 19:00
I got this:nc -h OpenBSD netcat (Debian patchlevel 1.195-1)
– Shritama Sengupta
Dec 21 '18 at 19:00
@ShritamaSengupta your
nc
doesn't support the exec flag the. There is this answer here but it uses named pipes
superuser.com/questions/691008/…– Valentin Bajrami
Dec 21 '18 at 19:26
@ShritamaSengupta your
nc
doesn't support the exec flag the. There is this answer here but it uses named pipes
superuser.com/questions/691008/…– Valentin Bajrami
Dec 21 '18 at 19:26
I just installed the traditional-netcat instead and accessed the -exec command. This seemed as the easier way to achieve my task. Thank you for your hint though.
– Shritama Sengupta
Dec 21 '18 at 19:29
I just installed the traditional-netcat instead and accessed the -exec command. This seemed as the easier way to achieve my task. Thank you for your hint though.
– Shritama Sengupta
Dec 21 '18 at 19:29
|
show 1 more comment
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f490371%2fshell-script-in-netcat-listener-to-talk-with-client%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown