linux - dropbear如何禁止登录三次被拒绝的用户IP

标签 linux

请问,我想修改dropbear添加一个

功能。我已经下载了 dropbear-0.52 的源代码并且我已经

读了很长时间但我不知道我应该修改哪个c.file..

我想添加这样的功能,如果用户登录被拒绝3次,

禁止其IP 30分钟

我尝试修改cli.auth,但不起作用

/*
if(ses.authstate.failcount >= 3){
        if (cli_ses.auth_interact_failed) {
            finished = 0;
        } else {
            cli_auth_interactive();
            cli_ses.lastauthtype = AUTH_TYPE_INTERACT;
            finished = 1;
    }
*/

希望有人能帮我解决这个问题,非常感谢

最佳答案

dropbear 中的

svr-auth.c 文件检查密码并重试查看 send_msg_userauth_failure() 函数,因为您有 ses.authstate.failcount 跟踪连续登录失败的变量,如果达到 3,您可以在 svr-main.c 文件中阻止来自该 ip 的连接 30 分钟

svr-auth.c

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);
            }

关于linux - dropbear如何禁止登录三次被拒绝的用户IP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28341083/

相关文章:

c++ - C++ 程序中的内存使用情况,由 Gnome 资源监视器 : confusion 报告

linux - 如何根据文件B中的行号替换文件A中的某些行

linux - 反对 Windows 注册表的主要原因是什么?

Android 模拟器导致 linux 崩溃并出现错误?

linux - 将目录更改为参数(如果给定) - Bash 脚本

c++ - 自己的lib,另一台电脑: cannot open shared object file: No such file or directory

linux - sed 任何整个单词搜索和替换

linux - Linux 依赖项的 Mac Firebreath 插件端口

linux - 如何使用 bash 脚本从文本文件中选择特定范围的行

linux - ffmpeg 错误 : "Missing ' )' or too many args in ' if(gt(a, 1),650,-1 )'"