First, I will compile an ssh backdoor. The ssh backdoor will record all the logon passwords in tmpxxxxxx and start his root @ laptop: usrlocalopenssh2sbin # psaux | grepsshdroot136190.00.374321752? Ss23: 440: 00. sshd-p1234root137070.00.242921328pts3R + 23: 580
First, I will compile an ssh backdoor, which will record all logon passwords in/tmp/xxxxxx.
Start him
Root @ laptop:/usr/local/openssh2/sbin # ps aux |GrepSshd
Root 13619 0.0 0.3 7432 1752? Ss./sshd-p 1234
Root 13707 0.0 0.2 4292 1328 pts/3 R + grep sshd
Next we use sTrAce tracks pIdThe-ff parameter is very important, and the fork sub-process can be tracked.
Root @ laptop:/usr/local/openssh2/sbin # strace-o aa-ff-p 13619
Then we log on to ssh. After successfully logging on, we can check the current directory and generate the strace output.
Root @ laptop:/usr/local/openssh2/sbin #Ls
Aa aa.13636 aa.13638 aa.13640 aa.13569aa.13644 aa.13646 aa.13648 aa.13650 aa.13652 aa.13654 aa.13656 sshd
Aa.13635 aa.13637 aa.13639 aa.13641 aa.13643 aa.13645 aa.13647 aa.13649 aa.13651 aa.13653 aa.13655 aa.13657
We grep the open system call, and then filter out the error information and/dev/null information, and deniEdInformation, and find WR, is opened in read/write mode, because to write the recorded password to a file, it must be opened in write mode, take a rough look, it is easy to find the exception file/tmp/xxxxxx
Root @ laptop:/usr/local/openssh2/sbin # grep open aa * | grep-v-e No-e null-e denied | grep WR
Aa.13635: open ("/tmp/xxxxxx", O_WRONLY | O_APPEND | O_CREAT | O_LARGEFILE, 0666) = 3
Aa.13635: open ("/dev/ptmx", O_RDWR) = 3
Aa.13635: open ("/dev/pts/5", O_RDWR | O_NOCTTY) = 6
Aa.13635: open ("/var/run/utmp", O_RDWR) = 7
Aa.13635: open ("/var/log/wtmp", O_WRONLY) = 7
Aa.13635: open ("/var/log/lastlog", O_RDWR | O_CREAT | O_LARGEFILE, 02000) = 7
Aa.13635: open ("/var/run/utmp", O_RDWR) = 6
Aa.13635: open ("/var/log/wtmp", O_WRONLY) = 6
Aa.13638: open ("/dev/pts/5", O_RDWR | O_LARGEFILE) = 7
Aa.13638: open ("/dev/tty", O_WRONLY | O_LARGEFILE) = 8
Aa.13638: open ("/dev/tty", O_RDWR | O_NONBLOCK | O_LARGEFILE) = 3
Aa.13640: open ("/dev/tty", O_RDWR | O_NONBLOCK | O_LARGEFILE) = 3
Aa.13657: open ("/dev/tty", O_RDWR) = 3
Through the above method, we can roughly diagnose whether our sshd has been placed with a backdoor. But because of the various sshd backdoors, the sshd backdoors I mentioned above are excellent, he can set whether to record the password. If he does not set the password, we can use strace to estimate that he cannot be found, but there are still some ssh Backdoors that need to use special configuration files, reading special password files makes it easy to find them with strace.