From eacb64b0a83f870aa435b24080377328231a00e5 Mon Sep 17 00:00:00 2001 From: Jorge Matricali Date: Sat, 30 Dec 2017 15:06:29 -0300 Subject: [PATCH] + print_debug + print_error --- honeypot-detector.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/honeypot-detector.c b/honeypot-detector.c index 948d1ab..b4583e2 100644 --- a/honeypot-detector.c +++ b/honeypot-detector.c @@ -39,14 +39,15 @@ int probe(char *serverAddr, unsigned int serverPort) struct sockaddr_in addr; int sockfd, ret; char buffer[BUF_SIZE]; + char *banner = NULL; sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd < 0) { - print_error("Error creating socket!\n"); + print_error("Error creating socket!"); sockfd = 0; return -1; } - print_debug("Socket created.\n"); + print_debug("Socket created."); struct timeval timeout; timeout.tv_sec = 10; @@ -61,76 +62,77 @@ int probe(char *serverAddr, unsigned int serverPort) addr.sin_addr.s_addr = inet_addr(serverAddr); addr.sin_port = htons(serverPort); - print_debug("\t[-] %s:%d Connecting...\n", serverAddr, serverPort); + print_debug("\t[-] %s:%d - Connecting...", serverAddr, serverPort); ret = connect(sockfd, (struct sockaddr *) &addr, sizeof(addr)); if (ret < 0) { - print_error("%s:%d - Error connecting to the server!\n", serverAddr, serverPort); + print_error("%s:%d - Error connecting to the server!", serverAddr, serverPort); close(sockfd); sockfd = 0; return -1; } - print_debug("\t[!] %s:%d Connected.\n", serverAddr, serverPort); + print_debug("\t[+] %s:%d - Connected.", serverAddr, serverPort); memset(buffer, 0, BUF_SIZE); // RECIBIR BANNER ret = recvfrom(sockfd, buffer, BUF_SIZE, 0, NULL, NULL); if (ret < 0) { - print_error("%s:%d - Error receiving banner!\n", serverAddr, serverPort); + print_error("%s:%d - Error receiving banner!", serverAddr, serverPort); close(sockfd); sockfd = 0; return -1; } - print_debug("\t[-] %s:%d - BANNER: %s\n", serverAddr, serverPort, buffer); + banner = malloc(sizeof(char) * 1024); + banner = strdup(strtok(buffer, "\n")); + print_debug("\t[?] %s:%d - %s", serverAddr, serverPort, banner); char *pkt1 = "SSH-2.0-OpenSSH_7.5"; char *pkt2 = "\n"; char *pkt3 = "asd\n "; char *search = "Protocol mismatch."; - print_debug("\t[<] %s:%d - Sending pkt1: %s\n", serverAddr, serverPort, pkt1); + print_debug("\t[<] %s:%d - Sending pkt1: %s", serverAddr, serverPort, strtok(pkt1, "\n")); ret = sendto(sockfd, pkt1, sizeof(pkt1), 0, (struct sockaddr *) &addr, sizeof(addr)); if (ret < 0) { - print_error("%s:%d - Error sending data pkt1!!\n", serverAddr, serverPort); + print_error("%s:%d - Error sending data pkt1!!", serverAddr, serverPort); close(sockfd); sockfd = 0; return -1; } - print_debug("\t[<] %s:%d - Sending pkt2: %s\n", serverAddr, serverPort, pkt2); + print_debug("\t[<] %s:%d - Sending pkt2: %s", serverAddr, serverPort, pkt2); ret = sendto(sockfd, pkt2, sizeof(pkt2), 0, (struct sockaddr *) &addr, sizeof(addr)); if (ret < 0) { - print_error("%s:%d - Error sending data pkt2!!\n", serverAddr, serverPort); + print_error("%s:%d - Error sending data pkt2!!", serverAddr, serverPort); close(sockfd); sockfd = 0; return -1; } - print_debug("\t[<] %s:%d - Sending pkt3: %s\n", serverAddr, serverPort, pkt3); + print_debug("\t[<] %s:%d - Sending pkt3: %s", serverAddr, serverPort, pkt3); ret = sendto(sockfd, pkt3, sizeof(pkt3), 0, (struct sockaddr *) &addr, sizeof(addr)); if (ret < 0) { - print_error("%s:%d - Error sending data pkt3!!\n", serverAddr, serverPort); + print_error("%s:%d - Error sending data pkt3!!", serverAddr, serverPort); close(sockfd); sockfd = 0; return -1; } - print_debug("\t[>] %s:%d - Receiving...\n", serverAddr, serverPort); + print_debug("\t[>] %s:%d - Receiving...", serverAddr, serverPort); ret = recvfrom(sockfd, buffer, BUF_SIZE, 0, NULL, NULL); if (ret < 0) { - print_error("%s:%d - Error receiving response!!\n", serverAddr, serverPort); + print_error("%s:%d - Error receiving response!!", serverAddr, serverPort); close(sockfd); sockfd = 0; return -1; } - print_debug("\t[+] %s:%d - Received: %s\n", serverAddr, serverPort, buffer); - + print_debug("\t[+] %s:%d - Received: %s", serverAddr, serverPort, buffer); if (strstr(buffer, search) != NULL) { - printf("\t[+] %s:%d - OK\n", serverAddr, serverPort); + printf("\t[+] %s:%d - %s\n", serverAddr, serverPort, banner); } else { printf("\t[!] %s:%d - POSSIBLE HONEYPOT!\n", serverAddr, serverPort); }