dropbear加入安全機制 - Linux

Table of Contents

各位版上前輩好,

我想用dropbear加入以下功能,

連續三次登入未能成功則阻擋該IP 30分鐘,

目前已下載dropbear souce code更改,

更改svr-auth.c與svr-main.c

svr-auth更改如下

if (ses.authstate.failcount >= MAX_AUTH_TRIES) {
char * userstr;
/* XXX - send disconnect ? */
TRACE(("Max auth tries reached, exiting"))

if (ses.authstate.pw_name == NULL) {
userstr = "is invalid";
} else {
userstr = ses.authstate.pw_name;
}
dropbear_exit("Max auth tries reached - user '%s' from %s",
userstr, svr_ses.addrstring);
}


svr-main.c更改如下

/* child */
#ifdef DEBUG_FORKGPROF
extern void _start(void), etext(void);
monstartup((u_long)&_start, (u_long)&etext);
#endif /* DEBUG_FORKGPROF */

getaddrstring(&remoteaddr, NULL, &remote_port, 0);
dropbear_log(LOG_INFO, "Child connection from %s:%s",
remote_host, remote_port);

///Ignore connection here for 30 mins if you found 3 times login failure

m_free(remote_host);
m_free(remote_port);

#ifndef DEBUG_NOFORK
if (setsid() < 0) {
dropbear_exit("setsid: %s", strerror(errno));
}
#endif

/* make sure we close sockets */
for (i = 0; i < listensockcount; i++) {
m_close(listensocks[i]);
}

m_close(childpipe[0]);

/* start the session */
svr_session(childsock, childpipe[1]);
/* don't return */
dropbear_assert(0);
}

以上compile過後都未能新增這功能,

stack overflow則是有建議安裝fail2ban,

但我在openwrt底下這套軟體太過肥大暫不考慮

想請教版上前輩是否能指點我哪裡更改錯誤呢? 請多多指教 謝謝


--

All Comments

Olga avatarOlga2015-02-08
你沒把ip存起來當然不行
Emily avatarEmily2015-02-13
建list存ip和時間,每次檢查才行,很麻煩
Dora avatarDora2015-02-15
dropbear可以連結fail2ban
眼殘抱歉..