Execute shell script from wlan

Post new topic   Reply to topic    DD-WRT Forum Forum Index -> General Questions
Author Message
feichter
DD-WRT Novice


Joined: 31 Aug 2012
Posts: 10

PostPosted: Sat Nov 20, 2021 19:57    Post subject: Execute shell script from wlan Reply with quote
Hi

Hope someone can help. This should not be so difficult.
I am trying to execute a .sh script from the outside world.
I have jffs enable and have a test script in the /nocat folder (/jffs/nocat).

The script (test.sh) is very simple:
#!/bin/sh

echo "Hello world"

I have two routers. Main router and the second router which I have open ported (on 5280) to the main router.

Now, being used to raspberry pi, I should be able to execute this script by typing http://xxx.xxx.x.xx:5280/test.sh where the x's are the external ip address.

Where am I going wrong?

Many thanks.
Sponsor
kernel-panic69
DD-WRT Guru


Joined: 08 May 2018
Posts: 12619
Location: Texas, USA

PostPosted: Sat Nov 20, 2021 20:46    Post subject: Reply with quote
https://ostechnix.com/execute-shell-commands-via-http-server/

https://itsfoss.com/run-shell-script-linux/

https://easycodeshare.com/trigger-remote-shell-script-on-linux-via-http-browser/

https://www.baeldung.com/linux/execute-bash-script-from-url

https://www.thegeekstuff.com/2010/07/execute-shell-script/

https://stackoverflow.com/questions/5735666/execute-bash-script-from-url

https://github.com/msoap/shell2http

_________________
Official Forum Rules, Guidelines & Helpful InformationFirmware FAQInstallation WikiWhere Do I Download Firmware‽
DON'T use Chromium-based browsersRTFM/STFW TL;DR is NOT an excuse. • Why Should I Care What Color the Bikeshed Is‽
Please DO NOT PM me with questions; Ask in the forum. ---------------------- Linux User #377467 counter.li.org / linuxcounter.net
feichter
DD-WRT Novice


Joined: 31 Aug 2012
Posts: 10

PostPosted: Sun Nov 21, 2021 14:51    Post subject: Reply with quote
kernel-panic69 wrote:
https://ostechnix.com/execute-shell-commands-via-http-server/

https://itsfoss.com/run-shell-script-linux/

https://easycodeshare.com/trigger-remote-shell-script-on-linux-via-http-browser/

https://www.baeldung.com/linux/execute-bash-script-from-url

https://www.thegeekstuff.com/2010/07/execute-shell-script/

https://stackoverflow.com/questions/5735666/execute-bash-script-from-url

https://github.com/msoap/shell2http


Thanks for these links, however none actually answer my question.

My question is:
How can I execute a shell script on the router from the outside world?

On a raspberry pi I can execute a script that is in the /var/www/html directory on (for example) http://100.100.10.10:9999/test.sh

Many thanks
kernel-panic69
DD-WRT Guru


Joined: 08 May 2018
Posts: 12619
Location: Texas, USA

PostPosted: Sun Nov 21, 2021 20:20    Post subject: Reply with quote
Your Raspberry Pi probably already includes the implementation of the information in those links... whereas DD-WRT probably does not, save and except for the webUI commands page...
_________________
Official Forum Rules, Guidelines & Helpful InformationFirmware FAQInstallation WikiWhere Do I Download Firmware‽
DON'T use Chromium-based browsersRTFM/STFW TL;DR is NOT an excuse. • Why Should I Care What Color the Bikeshed Is‽
Please DO NOT PM me with questions; Ask in the forum. ---------------------- Linux User #377467 counter.li.org / linuxcounter.net
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 9775
Location: Netherlands

PostPosted: Tue Nov 23, 2021 10:23    Post subject: Reply with quote
You might use SSH to run a script remote e.g.:

https://www.cyberciti.biz/faq/unix-linux-execute-command-using-ssh/

_________________
Routers:Netgear R7800, R6400v1, R6400v2, Linksys EA8500, EA6900 (XvortexCFE), E2000 (converted WRT320N), WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
the-joker
DD-WRT Developer/Maintainer


Joined: 31 Jul 2021
Posts: 1224
Location: All over YOUR webs

PostPosted: Tue Nov 23, 2021 13:02    Post subject: Reply with quote
What egc said exactly.

DD-WRT is a router FW, a Rpi or any other machine just running a web server, may allow anything and their mothers by default.

I can say for sure without examining all the firewall rules or security mechanisms in place in the FW, that prevent httpd from doing this by default, I have a sneaking suspicion that's the cause for the failure as you noted.

I wouldn't expect my router accessible to the outside world, with default configs to allow execution of scripts somewhere in its directories, and if the router just allowed this by default, I would consider it insecure and security issue ripe for abuse.

Via SSH you are essentially the root user, and its up to you to understand the implications of opening yourself up to what that entails.

You also have a built in light http server in the FW, you can also enable that allow it outside access and perhaps the webinterface restrictions wont apply there (again idk what restrictions are in place of the top of my head) and you maybe able to reproduce your Rpi scenario that way too.

have a nice day.

_________________
Saving your retinas from the burn!🔥
DD-WRT Inspired themes for routers
DD-WRT Inspired themes for the phpBB Forum
DD-WRT Inspired themes for the SVN Trac & FTP site
Join in for a chat @ #style_it_themes_public:matrix.org or #style_it_themes:discord

DD-WRT UI Themes Bug Reporting and Discussion thread

Router: ANus RT-AC68U E1 (recognized as C1)
SurprisedItWorks
DD-WRT Guru


Joined: 04 Aug 2018
Posts: 1336
Location: Appalachian mountains, USA

PostPosted: Tue Nov 23, 2021 18:25    Post subject: Reply with quote
Yeah, what they said.

Set up ssh with key authorization (NOT user/pass), get everything working first from inside your network, and only then try doing things from the WAN. If you are coming from a linux box you'll want to use ssh-agent to streamline access.

Anyway, the key here is that the ssh client on that friendly linux box (at least on my old Fedora system) can take an argument that is a command to be run on the ssh server's system. This can be a many-line command in quotes or a short command to run what you have in /opt. You can write a few short scripts or bash functions on that linux box to streamline things.

_________________
4 Linksys WRT1900ACSv2 routers on 49081, 2 on 48141: VLANs, VAPs, NAS, client mode, OpenVPN client (AirVPN), DDNS, wireguard servers and clients (AzireVPN), three DNSCrypt DNS providers (incl Quad9) via VPN clients.
feichter
DD-WRT Novice


Joined: 31 Aug 2012
Posts: 10

PostPosted: Wed Nov 24, 2021 11:22    Post subject: Reply with quote
Thanks all for your replies.

I understand the security implications, however I think if I can work out how to execute a script remotely via a specific port, then I should also be able to work out how to add some username/password authentication to said port/directory to prevent unauthorised access.

I would like to use php on my server to execute a script on the router (just in case my question was not clear in the first instance - if anyone else has done something like that).

ps: All my scripts work from the command line.

Again, many thanks.
feichter
DD-WRT Novice


Joined: 31 Aug 2012
Posts: 10

PostPosted: Sat Nov 27, 2021 12:50    Post subject: Reply with quote
Well, still searching for an answer...

I found this:

https://wiki.dd-wrt.com/wiki/index.php/Script_Execution#Execute_Scripts_with_a_Different_Extension_or_in_a_Different_Folder

and made a startup script in /jffs/etc/config as described.
This startup script is called 'sh-execute.sh' and has the following content:
Code:

#!/bin/sh

for I in `/bin/ls /jffs/scripts/*.sh`;do
  sh $I &
done


Then I wrote a shell script in /jffs/scripts called 'test.sh'.
This shell script writes the current date/time to a text file (test.txt).

Now if I execute http://192.168.3.1:5280/jffs/scripts/test.sh then I would expect the date/time to be in test.txt.

But it's not working. Any ideas?

Many thanks
the-joker
DD-WRT Developer/Maintainer


Joined: 31 Jul 2021
Posts: 1224
Location: All over YOUR webs

PostPosted: Sat Nov 27, 2021 14:29    Post subject: Reply with quote
Script is made executable right?
_________________
Saving your retinas from the burn!🔥
DD-WRT Inspired themes for routers
DD-WRT Inspired themes for the phpBB Forum
DD-WRT Inspired themes for the SVN Trac & FTP site
Join in for a chat @ #style_it_themes_public:matrix.org or #style_it_themes:discord

DD-WRT UI Themes Bug Reporting and Discussion thread

Router: ANus RT-AC68U E1 (recognized as C1)
feichter
DD-WRT Novice


Joined: 31 Aug 2012
Posts: 10

PostPosted: Sat Nov 27, 2021 15:49    Post subject: Reply with quote
the-joker wrote:
Script is made executable right?


Yes, it is.
mwchang
DD-WRT Guru


Joined: 26 Mar 2013
Posts: 1001
Location: Hung Hom, Hong Kong

PostPosted: Mon Nov 29, 2021 8:29    Post subject: Re: Execute shell script from wlan Reply with quote
feichter wrote:
I am trying to execute a .sh script from the outside world.
I have jffs enable and have a test script in the /nocat folder (/jffs/nocat).

The script (test.sh) is very simple:
#!/bin/sh

echo "Hello world"

I have two routers. Main router and the second router which I have open ported (on 5280) to the main router.

Now, being used to raspberry pi, I should be able to execute this script by typing http://xxx.xxx.x.xx:5280/test.sh where the x's are the external ip address.


So I looked up "raspberry pi port 5280" in Google, and got this result:

Networked Pipes with Netcat | RasPipe: A Raspberry Pi Pipeline Viewer, Part 2 | Adafruit Learning System
https://learn.adafruit.com/raspipe-a-raspberry-pi-pipeline-viewer-part-2/networked-pipes-with-netcat

https://www.google.com/search?q=netcat+server+client

I believe you need to setup NetCat in DD-WRT that listens to port 5280, then execute a script accordingly. For that, you need to install Entware. Also, you have to consider security and firewall issues.

DropBear SSH of DD-WRT supports remote command execution! Look it up via Google. It's installed by default. I believe Raspberry Pi's Linux distribution has OpenSSH as well. Smile

Lastly, the following query had some interesting results:

https://www.google.com/search?q=dd-wrt+remote+execute+script


_________________
Router: Asus RT-N18U (rev. A1)

May the Force and farces be with you! Live long and prosper!

Facebook: https://www.facebook.com/changmanwai
Website: https://sites.google.com/site/changmw
SETI@Home profile: http://setiathome.berkeley.edu/view_profile.php?userid=211832
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Forum Index -> General Questions All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum