LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-29-2020, 05:09 PM   #1
patrik_
LQ Newbie
 
Registered: Jan 2020
Posts: 12

Rep: Reputation: Disabled
cannot see the echo sshpass output in my portal


Hello guys,

Thanks for allow me to be part of this community. I very new at Linux and I'm running my first project. So far I guess is working however when I want to display the output of a command in the html portal I dont see anything. Here is the bash:



#!/bin/bash
read -p "Mac given: " Add

if [ "$1" != "" ] ; then
Add=$1
fi

echo "Content-type: text/html"
echo $Add <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<this output is visible and i can confirm that what ever I receive from the PHP script is correct

echo ""
echo "<html><head><title>Bash as CGI"
echo "</title></head><body>"

echo "<center><h1>Find the information below</h1></center>"

echo $(sshpass -p XXXXX ssh XXXXXX@XXXXX show mac address-table address $Add) >>>>> Here is where it fails. If I run the batch I can see the output but if I go the portal I dont see anything.

echo ""
echo "<center>INITIAL TEST</center>"
echo "</body></html>"

Any help will be much appreciated !
 
Old 01-29-2020, 05:23 PM   #2
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Without commenting on the security considerations...but please read those in man sshpass

What does the web server -access and -error logs contain? If there's an error, it should be logged in the error_log.
 
Old 01-29-2020, 05:35 PM   #3
patrik_
LQ Newbie
 
Registered: Jan 2020
Posts: 12

Original Poster
Rep: Reputation: Disabled
I know, needs a lot work on that side but I want to make it work first. I have too few exposure on this world.
The command works, if I run it directly from the server I can see the correct out put.

let me check what the log says.

Thanks !!
 
Old 01-29-2020, 06:42 PM   #4
patrik_
LQ Newbie
 
Registered: Jan 2020
Posts: 12

Original Poster
Rep: Reputation: Disabled
ok, Permission denied...the last part I check the one that had the solution. Thanks for the advise again!
 
Old 01-29-2020, 10:32 PM   #5
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,312
Blog Entries: 3

Rep: Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722
Using shell for CGI is fine but the way you are going about the work flow here provides several glaring security holes. Security is part of the intial design process and cannot be bolted on afterwards. If you need an example of bad design, look at the 40+ years of M$ garbage. So please reconsider your work flow to include security from the beginning.

Any data coming in from the outside is filthy and cannot be safely used or passed on to other programs without first being sanitized or at least validated. For example, someone could pass a single line of instructions and get a full reverse shell to $1, instead of what you were expecting:

So what are the allowed ranges or values for the $Add variable? Write a routine for your shell script to make sure it is clean.

Then as for the SSH password, don't use one, use an SSH key instead. SSH keys can be locked to a single program. Then on the server side, lock down the key with command="..." in authorized_keys. Substitute your details for the ... there. If you need to pass information, then make use of the $SSH_ORIGINAL_COMMAND environment variable and mine that for what you need. Again, keep in mind that information from the variable must be sanitized before use.
 
Old 01-30-2020, 11:02 AM   #6
patrik_
LQ Newbie
 
Registered: Jan 2020
Posts: 12

Original Poster
Rep: Reputation: Disabled
Hello Turbocapitalist, those are very useful recommendation for me, honestly I didn't think on that before maybe coz my lack of experience. But I will review all of it before sharing the portal with any user for sure.

The variable comes from a HTML format that is send to PHP script then from there I run the bash, I wont take all the credit, I took that flow from here and there and just put them together according to what I needed and made it work. It was simple but for my took me around a week :S.

I can do certs for sure to connect to my equipment and I didn't know I could do that in regards of the command recommendation which I'm planning to do it that way.

Any other observation is more than welcome!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
echo 0:$(echo 8*35*37*47 | bc) | xxd -r && echo $(id -un) Linuxanity LinuxQuestions.org Member Intro 1 08-15-2012 06:30 PM
start stop portal 1 and portal 2 dnaqvi Programming 6 11-30-2010 12:15 PM
Kphone echo (echo echo) scabies Linux - Software 0 10-18-2004 02:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration