| 1 | #include "common.hh" |
| 2 | #include "vulnpass.hh" |
| 3 | #include "showpass.hh" |
| 4 | #include "../main.hh" |
| 5 | |
| 6 | #include <FL/Fl.H> |
| 7 | #include <FL/Fl_Window.H> |
| 8 | #include <FL/fl_ask.H> |
| 9 | #include <FL/Fl_Box.H> |
| 10 | #include <FL/Fl_Button.H> |
| 11 | #include <FL/Fl_Text_Display.H> |
| 12 | #include <FL/Fl_Text_Buffer.H> |
| 13 | #include <FL/Fl_Scrollbar.H> |
| 14 | |
| 15 | #include <vector> |
| 16 | #include <string> |
| 17 | #include <thread> |
| 18 | |
| 19 | #include <unistd.h> |
| 20 | #include <arpa/inet.h> |
| 21 | #include <sys/types.h> |
| 22 | #include <sys/socket.h> |
| 23 | #include <netdb.h> |
| 24 | #include <netinet/in.h> |
| 25 | |
| 26 | Vulnpass vuln; |
| 27 | int vulncount = 0; |
| 28 | std::vector<std::string> vulnpaths; |
| 29 | |
| 30 | bool Vulnpass::exec() { |
| 31 | std::string lang = Common::getlang(); |
| 32 | |
| 33 | |
| 34 | int sock; |
| 35 | struct sockaddr_in srv; |
| 36 | struct addrinfo hints, *addr; |
| 37 | |
| 38 | memset(&hints, 0, sizeof(hints)); |
| 39 | hints.ai_family = AF_INET; |
| 40 | hints.ai_socktype = SOCK_STREAM; |
| 41 | |
| 42 | int status = getaddrinfo("076.moe", nullptr, &hints, &addr); |
| 43 | if (status != 0) { |
| 44 | fl_alert("getaddrinfo: %s", gai_strerror(status)); |
| 45 | return false; |
| 46 | } |
| 47 | |
| 48 | sock = socket(AF_INET, SOCK_STREAM, 0); |
| 49 | if (sock == -1) { |
| 50 | fl_alert(lang.compare(0, 2, "en") == 0 ? |
| 51 | "Failed to create socket" : "ソケットを作成に失敗"); |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | srv.sin_addr = ((struct sockaddr_in *)(addr->ai_addr))->sin_addr; |
| 56 | srv.sin_family = AF_INET; |
| 57 | srv.sin_port = htons(9951); |
| 58 | |
| 59 | freeaddrinfo(addr); |
| 60 | |
| 61 | if (connect(sock, (struct sockaddr *)&srv, sizeof(srv)) < 0) { |
| 62 | fl_alert(lang.compare(0, 2, "en") == 0 ? |
| 63 | "Failed to connect" : "接続に失敗"); |
| 64 | close(sock); |
| 65 | return false; |
| 66 | } |
| 67 | |
| 68 | |
| 69 | Showpass show; |
| 70 | |
| 71 | for (const auto &dispath : dispaths) { |
| 72 | std::string fullpath = Common::getbasedir(true) + dispath + ".gpg"; |
| 73 | std::string pass = show.exec(fullpath.c_str(), true); |
| 74 | if (pass.empty()) continue; |
| 75 | |
| 76 | if (send(sock, pass.c_str(), pass.length(), 0) < 0) { |
| 77 | fl_alert(lang.compare(0, 2, "en") == 0 ? |
| 78 | "Failed to send" : "送信に失敗"); |
| 79 | close(sock); |
| 80 | return false; |
| 81 | } |
| 82 | |
| 83 | char res[256] = {0}; |
| 84 | int reslen = recv(sock, res, sizeof(res) - 1, 0); |
| 85 | if (reslen < 0) { |
| 86 | fl_alert(lang.compare(0, 2, "en") == 0 ? |
| 87 | "Failed to retrieve" : "受取に失敗"); |
| 88 | close(sock); |
| 89 | return false; |
| 90 | } |
| 91 | |
| 92 | res[reslen] = '\0'; |
| 93 | std::string response(res); |
| 94 | |
| 95 | if (response.compare(0, 1, "0") != 0) { |
| 96 | vulnpaths.push_back(dispath); |
| 97 | vulncount++; |
| 98 | } |
| 99 | |
| 100 | close(sock); |
| 101 | |
| 102 | |
| 103 | sock = socket(AF_INET, SOCK_STREAM, 0); |
| 104 | if (sock == -1) { |
| 105 | fl_alert(lang.compare(0, 2, "en") == 0 ? |
| 106 | "Failed to create socket" : "ソケットを作成に失敗"); |
| 107 | return false; |
| 108 | } |
| 109 | |
| 110 | if (connect(sock, (struct sockaddr *)&srv, sizeof(srv)) < 0) { |
| 111 | fl_alert(lang.compare(0, 2, "en") == 0 ? |
| 112 | "Failed to reconnect" : "再接続に失敗"); |
| 113 | close(sock); |
| 114 | return false; |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | close(sock); |
| 119 | |
| 120 | return true; |
| 121 | } |
| 122 | |
| 123 | void Vulnpass::showRes() { |
| 124 | std::string lang = Common::getlang(); |
| 125 | |
| 126 | std::string res; |
| 127 | if (lang.compare(0, 2, "en") == 0) { |
| 128 | res = "Breached passwords:\n"; |
| 129 | } else { |
| 130 | res = "漏洩したパスワード:\n"; |
| 131 | } |
| 132 | |
| 133 | for (const auto &path : vulnpaths) { |
| 134 | res += path + "\n"; |
| 135 | } |
| 136 | |
| 137 | if (lang.compare(0, 2, "en") == 0) { |
| 138 | res += "Total: " + std::to_string(vulnpaths.size()) + "\n"; |
| 139 | res += "It's advised to change any of the"; |
| 140 | res += "breached passwords as soon as possible!"; |
| 141 | } else { |
| 142 | res += "合計: " + std::to_string(vulnpaths.size()) + "\n"; |
| 143 | res += "漏洩したパスワードは出来るだけ早く変更する事をお勧めします!"; |
| 144 | } |
| 145 | |
| 146 | Fl_Window *win = new Fl_Window(500, 440, lang.compare(0, 2, "en") == 0 ? |
| 147 | "Results" : "結果"); |
| 148 | Fl_Text_Display *display = new Fl_Text_Display(10, 10, 480, 380); |
| 149 | Fl_Text_Buffer *textbuf = new Fl_Text_Buffer(); |
| 150 | |
| 151 | textbuf->text(res.c_str()); |
| 152 | display->buffer(textbuf); |
| 153 | display->scrollbar_width(15); |
| 154 | win->resizable(display); |
| 155 | |
| 156 | Fl_Button *okBtn = new Fl_Button(210, 400, 80, 30, "OK"); |
| 157 | okBtn->callback([](Fl_Widget *widget, void *win) { |
| 158 | (void)widget; |
| 159 | reinterpret_cast<Fl_Window*>(win)->hide(); |
| 160 | }, win); |
| 161 | |
| 162 | win->add(okBtn); |
| 163 | |
| 164 | win->end(); |
| 165 | win->show(); |
| 166 | } |
| 167 | |
| 168 | void Vulnpass::dialog_cb(Fl_Widget *w, void *) { |
| 169 | (void)w; |
| 170 | |
| 171 | std::string lang = Common::getlang(); |
| 172 | |
| 173 | Fl_Window *dialog = new Fl_Window(400, 50, |
| 174 | (lang.compare(0, 2, "en") == 0 ? |
| 175 | "Check for branched password" : "漏洩されたパスワードの確認")); |
| 176 | |
| 177 | Fl_Box *box = new Fl_Box(10, 10, 380, 20, |
| 178 | (lang.compare(0, 2, "en") == 0 ? |
| 179 | "Checking, please wait for a while..." : |
| 180 | "確認中。暫くお待ち下さい・・・")); |
| 181 | |
| 182 | dialog->add(box); |
| 183 | |
| 184 | dialog->end(); |
| 185 | dialog->set_modal(); |
| 186 | dialog->show(); |
| 187 | |
| 188 | std::thread checker([dialog]() { |
| 189 | vuln.exec(); |
| 190 | |
| 191 | Fl::lock(); |
| 192 | dialog->hide(); |
| 193 | vuln.showRes(); |
| 194 | Fl::unlock(); |
| 195 | }); |
| 196 | |
| 197 | checker.detach(); |
| 198 | } |