| 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <string.h> |
| 4 | #include <unistd.h> |
| 5 | #include <arpa/inet.h> |
| 6 | #include <sys/types.h> |
| 7 | #include <sys/socket.h> |
| 8 | #include <netdb.h> |
| 9 | #include <netinet/in.h> |
| 10 | #include <dirent.h> |
| 11 | |
| 12 | #include "vulnpass.h" |
| 13 | #include "showpass.h" |
| 14 | #include "common.h" |
| 15 | |
| 16 | List vulnFullpaths; |
| 17 | List vulnDispaths; |
| 18 | |
| 19 | void vulnpass(const char *dpath) { |
| 20 | char *lang = getlang(); |
| 21 | |
| 22 | |
| 23 | int sock; |
| 24 | struct sockaddr_in srv; |
| 25 | struct addrinfo hints, *addr; |
| 26 | |
| 27 | memset(&hints, 0, sizeof(hints)); |
| 28 | hints.ai_family = AF_INET; |
| 29 | hints.ai_socktype = SOCK_STREAM; |
| 30 | |
| 31 | int status = getaddrinfo("076.moe", NULL, &hints, &addr); |
| 32 | if (status != 0) { |
| 33 | fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(status)); |
| 34 | return; |
| 35 | } |
| 36 | |
| 37 | sock = socket(AF_INET, SOCK_STREAM, 0); |
| 38 | if (sock == -1) { |
| 39 | const char *ero = strncmp(lang, "en", 2) == 0 ? |
| 40 | "Failed to create socket" : "ソケットを作成に失敗"; |
| 41 | perror(ero); |
| 42 | return; |
| 43 | } |
| 44 | |
| 45 | srv.sin_addr = ((struct sockaddr_in *)(addr->ai_addr))->sin_addr; |
| 46 | srv.sin_family = AF_INET; |
| 47 | srv.sin_port = htons(9951); |
| 48 | |
| 49 | freeaddrinfo(addr); |
| 50 | |
| 51 | if (connect(sock, (struct sockaddr *)&srv, sizeof(srv)) < 0) { |
| 52 | const char *ero = strncmp(lang, "en", 2) == 0 ? "Failed to connect" : "接続に失敗"; |
| 53 | perror(ero); |
| 54 | close(sock); |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | |
| 59 | List fpaths; |
| 60 | initList(&fpaths); |
| 61 | initList(&vulnFullpaths); |
| 62 | initList(&vulnDispaths); |
| 63 | scanDir(dpath, dpath, &fpaths, &vulnFullpaths, &vulnDispaths); |
| 64 | int vulncount = 0; |
| 65 | |
| 66 | puts(strncmp(lang, "en", 2) == 0 ? |
| 67 | "Checking, please wait for a while..." : "確認中。暫くお待ち下さい・・・"); |
| 68 | |
| 69 | for (size_t i = 0; i < vulnDispaths.size; i++) { |
| 70 | const char *pass = showpass(getElement(&vulnDispaths, i)); |
| 71 | if (!pass) continue; |
| 72 | char res[256]; |
| 73 | int reslen = 0; |
| 74 | |
| 75 | if (send(sock, pass, strlen(pass), 0) < 0) { |
| 76 | const char *ero = strncmp(lang, "en", 2) == 0 ? |
| 77 | "Failed to send" : "送信に失敗"; |
| 78 | perror(ero); |
| 79 | close(sock); |
| 80 | freeList(&fpaths); |
| 81 | return; |
| 82 | } |
| 83 | |
| 84 | reslen = recv(sock, res, sizeof(res) -1, 0); |
| 85 | if (reslen < 0) { |
| 86 | const char *ero = strncmp(lang, "en", 2) == 0 ? |
| 87 | "Failed to retreive" : "受取に失敗"; |
| 88 | perror(ero); |
| 89 | close(sock); |
| 90 | freeList(&fpaths); |
| 91 | return; |
| 92 | } |
| 93 | |
| 94 | res[reslen] = '\0'; |
| 95 | |
| 96 | if (strncmp(res, "0", 1) != 0) { |
| 97 | printf("【!】"); |
| 98 | if (strncmp(lang, "en", 2) == 0) { |
| 99 | printf("The password \"%s\" has been breached %d times.\n", |
| 100 | getElement(&vulnDispaths, i), atoi(res)); |
| 101 | } else { |
| 102 | printf("パスワード「%s」は%d回に漏洩されました。\n", |
| 103 | getElement(&vulnDispaths, i), atoi(res)); |
| 104 | } |
| 105 | |
| 106 | vulncount++; |
| 107 | } |
| 108 | |
| 109 | close(sock); |
| 110 | |
| 111 | |
| 112 | sock = socket(AF_INET, SOCK_STREAM, 0); |
| 113 | if (sock == -1) { |
| 114 | const char *ero = strncmp(lang, "en", 2) == 0 ? |
| 115 | "Failed to create socket" : "ソケットを作成に失敗"; |
| 116 | perror(ero); |
| 117 | return; |
| 118 | } |
| 119 | |
| 120 | if (connect(sock, (struct sockaddr *)&srv, sizeof(srv)) < 0) { |
| 121 | const char *ero = strncmp(lang, "en", 2) == 0 ? |
| 122 | "Failed to reconnect" : "再接続に失敗"; |
| 123 | perror(ero); |
| 124 | close(sock); |
| 125 | return; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | if (strncmp(lang, "en", 2) == 0) { |
| 130 | printf("\nTotal breached: %d\n", vulncount); |
| 131 | if (vulncount > 0) |
| 132 | printf("It's advised to change any of the breached " |
| 133 | "passwords as soon as possible!\n"); |
| 134 | } else { |
| 135 | printf("\n漏洩したパスワードの合計: %d\n", vulncount); |
| 136 | if (vulncount > 0) |
| 137 | printf("漏洩したパスワードは出来るだけ早く変更する事をお勧めします!\n"); |
| 138 | } |
| 139 | |
| 140 | freeList(&fpaths); |
| 141 | } |