Home Command line utilities How To Execute Shell Commands Via HTTP Server

How To Execute Shell Commands Via HTTP Server

By sk
Published: Last Updated on 10.1K views

Today, we are going to discuss about an interesting and useful utility called "shell2http" that can be used to execute shell commands via http server. You can run any commands on your Linux box, and send the output to your colleague or friend on the local network to review them. S/He can view the output on a web browser. This tool might be useful if you don't want to give the SSH access to your friend. Just ask him what command's output he would like to see, and run that command in your local system and allow him to view it on his web browser from anywhere on the local network. Your friend doesn't need an SSH access to view the results of any output.

shell2http - Execute Shell Commands Via HTTP Server

shell2http can be downloaded from the following link depending upon the distribution you use. It will support GNU/Linux, Windows, and Mac OS X.

Or, run the following commands to download it from the Terminal:

Make sure you have installed the command line downloader wget and compression tool unzip.

On RPM based systems, run the following command as root user to install them.

$ yum install wget unzip

On DEB based systems, run:

$ sudo apt-get install wget unzip

To download 64 bit shell2http:

$ wget https://github.com/msoap/shell2http/releases/download/1.7/shell2http-1.7.linux.amd64.zip

To download 32-bit shellhttp:

$ wget https://github.com/msoap/shell2http/releases/download/1.7/shell2http-1.7.linux.386.zip

Extract the compressed file in any location of your choice.

$ unzip shell2http-1.7.linux.xxx.zip

Go to the extracted folder, and start using shell2http.

Let us say your friend wants to view the installed Linux Kernel version of your system.

To do so, run:

$ shell2http -host -port 8080 /kernel "uname -r"

Here, is your local system's IP address. 8080 is the port number. /kernel - is the path to view the command's output. And "uname -r" is the command to display your system's Kernel version.

Sample output:

2017/02/03 14:57:21 register: /kernel (uname -r)
2017/02/03 14:57:21 listen

You probably need to open the port "8080" in your firewall or router. On systems that use firewalld (E.g RHEL, CentOS), run the following command as root user to open port 8080:

# firewall-cmd --add-port=8080/tcp --permanent

Restart firewalld service using command:

# firewall-cmd --reload

On Debian and Ubuntu systems, run:

$ sudo ufw allow 8080

Just make sure the port 8080 hasn't been used by any other applications. If it is, mention different port in the command and allow that port via firewall too.

Now, tell your friend to open his web browser and point it to "http://IP-address:8080/kernel" or "http://hostname:8080/kernel". It's simple as that.

Sample output:

If your friend wants to analyze the disk usage, just run the following command on your local system.

$ shell2http -host -port 8080 /diskusage "du -h"

And, ask him to open the path - http://IP-address:8080/diskusage in his web browser.

To exit the command, press CTRL+C.

Quite handy, isn't? Of course, it is!

You can also combine two commands and send the outputs to your friend like below.

In the below example, I am going to run du and ps commands and send the output to http server.

$ shell2http /diskspace "df -h" /ps "ps aux"2017/02/03 15:09:34 register: /diskspace (df -h)

Sample output:

2017/02/03 15:09:34 register: /ps (ps aux)
2017/02/03 15:09:34 listen http://:8080/

Did you notice the above command? I didn't mention the IP address of my system. shell2http will work without mentioning the IP address or hostname too.

Now, your friend can view the output of diskspace from the URL - http://IP-address:8080/diskspace, and view the output of "ps" command using URL - http://IP-address:8080/ps.

Diskspace output:

PS command output:

Disclaimer: Use shell2http tool with caution inside your trusted network only. Your server can easily be compromised if you didn't take the necessary precautions.


You May Also Like

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More