发信人: HPVC()
整理人: williamlong(1999-12-13 19:02:28), 站内信件
|
【 以下文字转载自 Solaris 讨论区 】 【 原文由 cpu 所发表 】 首先改inetd.conf,用自己的程序接管in.telnetd,该程序定名为 in.telnetd.firewall,比较长呵呵。 相应inetd.conf中telnet那一行变为: telnet stream tcp nowait root /usr/sbin/in.telnetd.firewall in.telnetd.firewall
然后写in.telnetd.firewall.c,原理:先初始化授权地址表(函数InitAuthIP), 然后检查对方地址(函数getpeername)是否与表中地址匹配(函数IPIsAuthed), 若不匹配记下时间和对方地址并警告对方,否则将处理移交(系统调用execl)给 真实服务进程,即/usr/bin/in.telnetd。
# include <stdio.h> # include <sys/types.h> # include <sys/socket.h> # include <netinet/in.h> # include <netdb.h> # include <unistd.h> # include <errno.h>
# define TRUE 0 # define FALSE -1
main( ) { struct sockaddr_in it; int itlen; itlen = sizeof(struct sockaddr_in);
InitAuthIP("/etc/telnet.allow"); /* read authorized IPs */
/* check the source ip */ if (getpeername(0, (struct sockaddr *)&it, &itlen) < 0) { perror("getpeername"); exit(-1); } if (IPIsAuthed(it.sin_addr.s_addr) == FALSE) { InitLog("/etc/telnet.log"); PrLog("%s", inet_ntoa(it.sin_addr)); EndLog( ); } if (IPIsAuthed(it.sin_addr.s_addr) == FALSE) { InitLog("/etc/telnet.log"); PrLog("%s", inet_ntoa(it.sin_addr)); printf("Not on console, u have been loged, xixi...;)\n"); close(0); exit(0); } execl("/usr/sbin/in.telnetd", "in.telnetd", (char *)0); }
-- ※ 来源:.广州网易 BBS bbs.nease.net.[FROM: 202.96.190.124]
|
|