📄 single.c
字号:
#include <sys/types.h>#include <sys/socket.h>#include <sys/un.h>#include <stdio.h>#include <dirent.h>#include <unistd.h>#include <wait.h>#include <string.h>/* This program reads a file (line-by-line) that contains list of files which should be scanned by Trophie. It does only one request at a time For example, create a file by doing (will take a while ;): # find / -type f > FILELIST Then use fsock with: # ./fsock <trophie_socket> FILELIST */char sockname[256];int check(char *path);int main(int argc, char *argv[]){ char buf[256]; char filelist[256]; FILE *fp; if (argc != 3) { printf("Usage: %s <socket> <filename_with_filelist>\n", argv[0]); exit(1); } sockname[0] = '\0'; filelist[0] = '\0'; strncpy(sockname, argv[1], sizeof(sockname)-1); strncpy(filelist, argv[2], sizeof(filelist)-1); if ((fp = fopen(filelist, "r")) == NULL) { perror("fopen"); exit(1); } while(fgets(buf, sizeof(buf), fp)) { if (strchr(buf, '\n')) *strchr(buf, '\n') = '\0'; check(buf); } exit(0);}int check(char *path){ int sock; struct sockaddr_un server; char buf[256]; int bread; /* Create socket */ sock = socket(AF_UNIX, SOCK_STREAM, 0); if (sock < 0) { perror("socket"); exit(1); } /* Connect socket using name specified by command line. */ server.sun_family = AF_UNIX; strcpy(server.sun_path, sockname); if (connect(sock, &server, sizeof(struct sockaddr_un)) < 0) { close(sock); perror("connect"); exit(1); } if (write(sock, path, strlen(path)) < 0) perror("write"); memset(buf, 0, sizeof(buf)); if ((bread = read(sock, buf, sizeof(buf))) > 0) { if (strchr(buf, '\n')) *strchr(buf, '\n') = '\0'; if (buf[0] == '1') printf("FILE INFECTED : [%s]\n", path); else if (!strncmp(buf, "-1", 2)) printf("UNKNOWN STATUS: [%s]\n", path); else printf("FILE OKAY : [%s]\n", path); } else { printf("*** Argh - failed to read response from Trophie\n"); } close(sock); return(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -