#include #include #include #include #include #include #include #include #include char *hash = "hqDTK7b8K2rvw"; #define GCHQ 0x71686367 static int contact(const char *host, const uint32_t *u) { int sk; struct hostent *h; ssize_t n; struct sockaddr_in sin; char buf[256]; if (!(h = gethostbyname(host))) { printf("error: gethostbyname() failed\n"); return (-1); } sin.sin_family = h->h_addrtype; memcpy(&sin.sin_addr, h->h_addr, h->h_length); sin.sin_port = htons(80); sk = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if (connect(sk, (struct sockaddr *)&sin, sizeof(sin))) { printf("error: connect(\"%s\") failed\n", host); return (-1); } sprintf(buf, "GET /%s/%x/%x/%x/key.txt HTTP/1.0\r\n\r\n", hash, u[0], u[1], u[2]); printf("request:\n\n%s", buf); if (send(sk, buf, strlen(buf), 0) <= 0) { printf("error: send() failed\n"); return (-1); } printf("response\n\n"); for (;;) { memset(buf, 0, sizeof(buf)); if ((n = recv(sk, buf, sizeof(buf) - 1, 0)) <= 0) break; printf("%s", buf); } printf("\n"); return (n); } int main(int argc, char *argv[]) { FILE *fp; uint32_t u[3]; union { char c[44]; uint32_t u[6]; } buf; int validp = 0; printf("\nkeygen.exe\n\n"); if (argc != 2) { printf("usage: keygen.exe hostname\n"); return (-1); } if (!(fp = fopen("license.txt", "r"))) { printf("error: license.txt not found\n"); return (-1); } memset(buf.u, 0, sizeof(buf.u)); fscanf(fp, "%s", buf.c); fclose(fp); if (buf.u[0] == GCHQ) { if (strcmp(crypt(buf.c + 4, hash), hash) == 0) validp = 1; printf("loading stage1 license key(s)\n"); u[0] = buf.u[3]; printf("loading stage2 license key(s)\n"); u[1] = buf.u[4]; u[2] = buf.u[5]; } if (!validp) { printf("error: license.txt invalid\n"); return (-1); } return (contact(argv[1], u)); }