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 -c /var/lib/shellinabox -s /: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 -e '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 -c /var/lib/shellinabox -s "/:$(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 -e '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.