diff --git a/README.md b/README.md index 4f59739..d529af9 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,16 @@ ssh防止暴力破解,适用Debian 8、9、11 Centos 7 支持钉钉告警和邮件告警 支持第三方QQ邮箱告警 支持一次运行检测、后台运行检测 + +``` Debian系统请安装libcurl库和libiptc库 -Centos 7系统请安装libcurl库和iptables-devel库,yum install iptables-devel libcurl-devel + apt install libip4tc-dev libcurl4-openssl-dev (或者libcurl4-gnutls-dev) +``` + +``` +Centos 7系统请安装libcurl库和iptables-devel库 + yum install iptables-devel libcurl-devel +``` ``` diff --git a/denyhosts.sh b/denyhosts.sh index ed34431..32b7998 100644 --- a/denyhosts.sh +++ b/denyhosts.sh @@ -9,7 +9,7 @@ source /etc/profile function init() { - SEND_MAIL=0 + SEND_MAIL=1 PWD_PATH="/root"; TIME=`date +"%Y%m%d%H%M"`; LOG_FILE="${PWD_PATH}/${TIME}.log"; diff --git a/rhost.c b/rhost.c index 42060fd..c59b472 100644 --- a/rhost.c +++ b/rhost.c @@ -97,7 +97,8 @@ int dingding_warning(char *illegal_ip, char *public_ip, conf *conf) strcpy(temp, public_ip); temp[strlen(public_ip)-1] = '\0'; - if ((fp = fopen("libcurl_ding.log", "wt+")) == NULL){ + if ((fp = fopen("libcurl_ding.log", "wt+")) == NULL) + { return 1; } @@ -106,7 +107,8 @@ int dingding_warning(char *illegal_ip, char *public_ip, conf *conf) curl_global_init(CURL_GLOBAL_ALL); curl = curl_easy_init(); - if (curl == NULL) { + if (curl == NULL) + { return 1; } @@ -148,7 +150,7 @@ int dingding_warning(char *illegal_ip, char *public_ip, conf *conf) } // 邮件告警 -int mail_warning(char *illegal_ip, char *public_ip) +int mail_warning(char *illegal_ip, char *public_ip, conf *conf) { FILE *fp = NULL; char buff[BUFFER]; @@ -162,15 +164,15 @@ int mail_warning(char *illegal_ip, char *public_ip) strcpy(temp, public_ip); temp[strlen(public_ip)-1] = '\0'; + sprintf(text, "echo \"主机:%s, 禁止%s访问\" | mail -s \"System ban IP\" %s", temp, illegal_ip, conf->RECV_MAIL); - sprintf(text, "主机:%s, 禁止%s访问", temp, illegal_ip); - strcat(text, " mail -s \"System ban IP\" 1605227279@qq.com"); - - if (NULL == (fp = popen(text, "r"))) { + if (NULL == (fp = popen(text, "r"))) + { perror("popen text"); } - while (fgets(buff, BUFFER, fp) != NULL) { + while (fgets(buff, BUFFER, fp) != NULL) + { buff[strlen(buff) - 1] = '\0'; } @@ -196,12 +198,10 @@ int QQ_mail_warning(char *illegal_ip, char *public_ip, conf *conf) temp[strlen(public_ip)-1] = '\0'; sprintf(text, "主机:%s, 禁止%s访问", temp, illegal_ip); - sprintf(string, QQMAIL, conf->RECV_MAIL, text); - printf("%s\n", string); - system(string); + - return 0; + return system(string); } // 封禁非法IP @@ -298,7 +298,7 @@ int rule(conf *conf) if (conf->IS_MAIL == 1) // 邮件告警 { - mail_warning(buffer, public_ip); + mail_warning(buffer, public_ip, conf); sleep(3); }