[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnumed-devel] remote help
From: |
Ian Haywood |
Subject: |
[Gnumed-devel] remote help |
Date: |
Sun, 04 Dec 2005 21:50:54 +1100 |
User-agent: |
Debian Thunderbird 1.0.7 (X11/20051017) |
This is a little script to help people who for various reasons are unwilling or
unable
to open ports and hand out root passwords on their boxes but still need help in
setting things up or fixing problems.
It connects to the helper's machine (who must open the SSH port and have an
ordinary user account available.)
The helper can then access a shell via this incoming connection (so it's the
reverse of a
normal SSH connection)
The session is replayed live on the local console, so the helpee can see what
is going on
(and check the helper isn't doing anything untoward)
The helper must have 'netcat' installed, and listen for connections using
stty raw -echo; nc -l -p 8883; stty sane
the port number 8883 is of course arbitrary.
Ian
import select, pty, popen2, os, signal, sys
if len (sys.argv) != 3:
print """
remote_help.py user host
host is a remote host where someone who can help you is logged in.
user is the name of a low-priviledge account on that system.
ssh is used to connect to that system, then the connection is
run 'backwards': the remote host has access to a shell on the local
machine, as the current user.
Obviusly a certain amount of trust in the remote user is required,
but not that much: the session is replayed live on the terminal, so you
can see what they are doing in real-time.
The remote user needs to run
stty raw -echo; nc -l -p 8883; stty sane
in a terminal and wait for the shell prompt to appear.
"""
sys.exit (0)
ssh = popen2.Popen4 ("/usr/bin/ssh -l %s %s nc 127.0.0.1 8883" % (sys.argv[1],
sys.argv[2]))
ssh_stdout = ssh.fromchild.fileno ()
ssh_stdin = ssh.tochild.fileno ()
bash_pid, bash = pty.fork ()
bashbuf = ''
sshbuf = ''
if bash_pid == 0:
os.execl ('/bin/bash', '-l')
else:
try:
while 1:
wfds = []
if sshbuf:
wfds.append (bash)
if bashbuf:
wfds.append (ssh_stdin)
rfds, wfds, efds = select.select ([bash, ssh_stdout], wfds, [bash,
ssh_stdout, ssh_stdin])
if bash in rfds:
bashbuf += os.read (bash, 1024)
if ssh_stdout in rfds:
sshbuf += os.read (ssh_stdout, 1024)
if bash in wfds:
n = os.write (bash, sshbuf)
sshbuf = sshbuf[n:]
if ssh_stdin in wfds:
n = os.write (ssh_stdin, bashbuf)
os.write (1, bashbuf[:n])
bashbuf = bashbuf[n:]
except OSError, e:
os.kill (bash_pid, signal.SIGKILL)
os.kill (ssh.pid, signal.SIGKILL)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnumed-devel] remote help,
Ian Haywood <=