為伺服器程式增加清理殭屍程序機制

2021-06-22 10:52:06 字數 2925 閱讀 8517

/*server.c*/

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#define port 1234

#define max_que 5

#define buf_size 1024

void sig_child();

pid_t pid;

int main()

printf("socket id = %d\n",socketfd);

local_sockaddr.sin_family = af_inet;

local_sockaddr.sin_port    = htons(port);

local_sockaddr.sin_addr.s_addr = htonl(inaddr_any);

printf("server ip =%s\n",inet_ntoa(local_sockaddr.sin_addr));//輸出伺服器ip位址

memset(local_sockaddr.sin_zero,0,8);

int i;

setsockopt(socketfd,sol_socket,so_reuseaddr,&i,sizeof(i));//允許重複使用本地的位址與套接字進行繫結

if(bind(socketfd,(struct sockaddr *)&local_sockaddr,sizeof(struct sockaddr))<0)//繫結函式bind()

printf("bind success!\n");

if(listen(socketfd,max_que)<0)//利用listen()設定被動監聽

printf("listening>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");

for( ; ; )

if((pid = fork()) == 0)

printf("receive messages from ip:%s\tport:%d\t:%s\n",client_ip,ntohs(client.sin_port),buf);

if(strcmp(buf,"exit")==0)

memset(buf,0,sizeof(buf));//清空沖區

snprintf(buf,sizeof(buf),"%s","server reply:");

strcat(buf,ctime(&nowtime));

if((sendbytes=send(clientfd,buf,strlen(buf),0))<0)

printf("send reply to client ip :%s port:%d success\n",client_ip,ntohs(client.sin_port));

}close(clientfd);

exit(0);

}close(clientfd);}}

void sig_child(int signo)

/*client.c*/

#include

#include

#include

#include

#include

#include

#include

#include

#include

#define port 1234

#define buf_size 1024

int main(int argc,char *argv)

if((socketfd=socket(af_inet,sock_stream,0))<0)//建立socket連線

printf("socket id = %d\n",socketfd);

serv_addr.sin_family = af_inet;

serv_addr.sin_port = htons(port);

inet_aton(argv[1], &serv_addr.sin_addr);  

memset(serv_addr.sin_zero,0,8);

if(connect(socketfd, (struct sockaddr*)&serv_addr, sizeof(struct sockaddr))< 0) //呼叫connect()函式連線伺服器

else

printf("connect to %s success!\n",argv[1]);

struct sockaddr_in serv, clie;

socklen_t serv_len = sizeof(serv);

socklen_t clie_len = sizeof(clie);

getpeername(socketfd, (struct sockaddr*)&serv, &serv_len);

inet_ntop(af_inet, &serv.sin_addr, serv_ip, sizeof(serv_ip));

printf("server ip:%s\tport:%d\n", serv_ip, ntohs(serv.sin_port));

memset(buf,0,sizeof(buf));

while(1)

if(strcmp(buf,"exit")==0)

memset(buf,0,sizeof(buf));

if((recvbytes = recv(socketfd,buf,buf_size,0))<0)

printf("receive reply from server %s:%s\n",serv_ip,buf);

}close(socketfd);//關閉socket連線

return 0;

}

為 WSUS 伺服器定期執行清理嚮導

在 wsus 的管理介面的 options 裡面,可以找到 server cleanup wizard 然後執行。後來想了一下,為什麼不把它弄成定期執行呢!找了一下,從 windows server 2012 開始,這個嚮導可以通過 powershell 執行,具體命令是 invoke wsusse...

伺服器被礦機程式攻擊

執行top命令 image.png google搜尋第一條顯示這是乙個礦機程式。image.png 那就是說明雲伺服器被礦機程式破解了。image.png 有兩個可執行程式ddgs.3013和qw3xt.2 image.png 1,刪掉 tmp下的ddgs.3013和qw3xt.2 2.刪掉cron...

Linux 判定伺服器為物理機還是虛擬機器

使用 dmidecode 進行查詢 dmidecode t system返回資訊為 root hcdb2 dmidecode t system dmidecode 2.12 smbios 2.4 present.handle 0x0100,dmi type 1,27 bytes system inf...