Skip to content

Commit

Permalink
+ print_debug
Browse files Browse the repository at this point in the history
+ print_error
  • Loading branch information
matricali committed Dec 30, 2017
1 parent fad74dd commit eacb64b
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions honeypot-detector.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down

0 comments on commit eacb64b

Please sign in to comment.