分享

"SSH Connect" in Dashboard context menu...

 昵称7585456 2011-09-07
1. Get Shellinabox AJAX web ssh/telnet shell.

2. Compile and install it, but don't start it as a service.

3. Edit the following telnet.sh and ssh.sh and put them into the cgi-bin directory of your web server that is hosting Zabbix frontend.

PHP Code:
#!/bin/bash

# ssh.sh
# This is a CGI script that uses shellinabox in CGI mode.

function connect {
    
shellinaboxd --cgi -/var/lib/shellinabox -/:SSH:$parms
    
if [ $? -ne 0 ]; then
    
echo "$res" > /tmp/1.log
    cannot_connect
    fi
}

function default {
     
# First time that the CGI script was called. Show initial HTML page.
     
printf 'Content-Type: text/html\r\n\r\n'
     
cat <<EOF
     
<html>
       <
head>
         <
title>SSH Shell</title>
       </
head>
       <
body>
         <
h1>SSH Shell</h1>

         <
p>Enter address to connect to:
         <
form method="POST">
           <
input type="text" name="cmd" style="width: 40em" value="127.0.0.1" />
         </
form>
         </
p>
       </
body>
EOF
}

function 
cannot_connect {
     
printf 'Content-Type: text/html\r\n\r\n'
     
cat <<EOF
     
<html>
       <
head>
         <
title>SSH Shell</title>
       </
head>
       <
body>
         <
h1>SSH Shell</h1>

         <
p>Unable to establish connection with $parms</p>
       </
body>
EOF
}

case 
"${REQUEST_METHOD}" in
  GET
)
     
# Retrieve CGI parameter, then start shellinabox with this address
     
parms=`echo $QUERY_STRING`
     if [ 
"$parms" != "" ]; then
        connect $parms
     
else
        default
     
fi
     
;;

  
POST)
     
# Retrieve CGI parameter, then start shellinabox with this address
     
read parms
     parms
="$(printf "$(echo "${parms}"|sed -'s/%\(..\)/\\x\1/g;s/%/%%/g')")" #"
     
parms="${parms#cmd=}"
     
if [ "$parms" != "" ]; then
        connect $parms
     else
        default
     fi
     ;;

  *)
     default
     ;;
esac  
END__VBULLETIN__CODE__SNIPPET 
?>
PHP Code:
#!/bin/bash

# telnet.sh
# This is a CGI script that uses shellinabox in CGI mode.

function connect {
    
shellinaboxd --cgi -/var/lib/shellinabox -"/:$(id -u):$(id -g):HOME:telnet ${parms}"
    
if [ $? -ne 0 ]; then
    cannot_connect
    fi
}

function default {
     
# First time that the CGI script was called. Show initial HTML page.
     
printf 'Content-Type: text/html\r\n\r\n'
     
cat <<EOF
     
<html>
       <
head>
         <
title>Telnet Shell</title>
       </
head>
       <
body>
         <
h1>Telnet Shell</h1>

         <
p>Enter address to connect to:
         <
form method="POST">
           <
input type="text" name="cmd" style="width: 40em" value="127.0.0.1" />
         </
form>
         </
p>
       </
body>
EOF
}

function 
cannot_connect {
     
printf 'Content-Type: text/html\r\n\r\n'
     
cat <<EOF
     
<html>
       <
head>
         <
title>Telnet Shell</title>
       </
head>
       <
body>
         <
h1>Telnet Shell</h1>

         <
p>Unable to establish connection with $parms</p>
       </
body>
EOF
}

case 
"${REQUEST_METHOD}" in
  GET
)
     
# Retrieve CGI parameter, then start shellinabox with this address
     
parms=`echo $QUERY_STRING`
     if [ 
"$parms" != "" ]; then
        connect $parms
     
else
        default
     
fi
     
;;

  
POST)
     
# Retrieve CGI parameter, then start shellinabox with this address
     
read parms
     parms
="$(printf "$(echo "${parms}"|sed -'s/%\(..\)/\\x\1/g;s/%/%%/g')")" #"
     
parms="${parms#cmd=}"
     
if [ "$parms" != "" ]; then
        connect $parms
     else
        default
     fi
     ;;

  *)
     default
     ;;
esac  
END__VBULLETIN__CODE__SNIPPET 
?>
4. Ensure that your cgi-bin directory is enabled in your web server config and cgi-scripts are accessible from a web browser.

5. Create /var/lib/shellinabox directory and make it rwx-accessible by your web server process, i.e. apache, nobody, whatever it is. Or just chmod it to 777, which is a security hole.

6. Open Zabbix network map editor, chose a host to edit and type in the URL field: http://<Your Zabbix Web Server Address>/cgi-bin/telnet.sh?<IP Address Of A Network Host>

7. Save the map, open it in the map viewer, point at the edited icon and click the URL link. A telnet window will replace your current browser tab.

If you have firewalling on your Zabbix server enabled your browser will likely fail to connect to Shellinabox. In this case temporary enable all incoming connections to check it's working and tune your firewall.

There are other web shells such as Ajaxterm, js_terminal, nixs, webshell, webtty, and probably others, but I didn't try them because Shellinabox just worked.

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多