Port scanner with a nice interface. Prompts for banner.
8bd800104043b93ad61675985333a24b5e4beecff4a27488c42726047481d2a1
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <fcntl.h>
#include <sys/file.h>
void checkport(char *host);
#define MAXPORT 1024
#define STARTPORT 1
#define COLOR "\E[32m"
#define WHITE "\E[m"
#define COLORS "\E[33m"
#define RED "\E[31m"
main(int argc, char *argv[])
{
int sockfd, port;
struct sockaddr_in sin;
struct hostent *h;
struct servent *s;
int x, y;
int secport;
char b[100];
char buffer[100];
struct sockaddr_in sins;
int socks;
if(argc < 2) {
fprintf(stderr, COLORS " [pHelon's Internet Port Scanner]\n");
fprintf(stderr, WHITE " phelon@antionline.org \n\n");
fprintf(stderr, "usage: %s [-help] <hostname> [start-port] [max-port]\n", argv[0]);
exit(1);
}
if(strcmp(argv[1], "-help") == 0) {
printf(COLOR "\n ____________-=HELP SCREEN=-_____________\n\n");
printf(RED "Argument Description\n");
printf(WHITE "-----------------------------------------------\n");
printf("Hostname The hostname is the address of\n");
printf(" the computer that you want to \n");
printf(" scan the ports on. It can be a\n");
printf(" numerical address (IP) in the \n");
printf(" form of 127.0.0.1. Or it can be\n");
printf(" in the form of a hostname, such \n");
printf(" as samba.berkeley.edu. Port scanning\n");
printf(" is not illegal but you could get\n");
printf(" kicked off of your ISP.\n");
printf("\n");
printf("Start/End Port Computers have things called ports.\n");
printf(" These ports could have possible vulnerabilites\n");
printf(" that can possibly be exploited. So, try to\n");
printf(" scan as high as you can, I think its 650000 or\n");
printf(" something. By default, the ports are 1 to 1024\n");
printf("\n");
printf("Help This help screen\n");
printf("\n");
exit(0);
}
if((h = gethostbyname(argv[1])) == NULL) {
herror(argv[1]);
exit(1);
}
if(argc > 2)
x = atoi(argv[2]);
else
x = STARTPORT;
if(argc > 3)
y = atoi(argv[3]);
else
y = MAXPORT;
printf(COLOR "Open Ports for %s:\n\n", argv[1]);
printf(WHITE "Scanning...\n");
sin.sin_family = AF_INET;
sin.sin_addr = *((struct in_addr *)h->h_addr);
printf(COLORS "Port Protocol Service\n");
printf(WHITE "------------------------------------------------------------\n");
for(port = x; port <= y; port++) {
sockfd = socket(AF_INET, SOCK_STREAM, 0);
sin.sin_port = htons(port);
s = getservbyport(htons(port), "tcp");
if(connect(sockfd, (struct sockaddr *)&sin, sizeof(sin)) == 0)
printf("%i %s %s\n", port, (s == NULL) ? "NULL" : s->s_proto, (s == NULL) ? "UNKNOWN" : s->s_name);
if(port == 7000 || port == 31337 || port == 30464 || port == 12345) {
printf(COLOR "\t*** Port: %d is most likeley a Trojan Horse ***", port);
printf(WHITE ".\n");
}
close(sockfd);
}
close(sockfd);
printf("-------------------------------------------------------------\n");
checkport(argv[1]);
close(sockfd);
return 0;
}
void checkport(char *host) {
char buffers[100];
char bufsalot[100];
int portsalot;
int sock;
struct sockaddr_in newsin;
struct hostent *hostent;
if((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
perror("socket failed");
exit(1);
}
if((hostent = gethostbyname(host)) == NULL) {
herror(host);
exit(1);
}
printf("Would you like further information? ");
scanf("%s", &buffers);
if(strstr(buffers, "y")) {
printf("Which port? ");
scanf("%d", &portsalot);
newsin.sin_family = AF_INET;
newsin.sin_addr = *((struct in_addr *)hostent->h_addr);
newsin.sin_port = htons(portsalot);
if(connect(sock, (struct sockaddr *)&newsin, sizeof(newsin)) == 0) {
while(read(sock, bufsalot, sizeof(bufsalot)) > 0) {
printf(COLOR "%s\n", bufsalot);
printf(WHITE "[Check bugtraq to see if daemon is vulnerable at http://www.securityfocus.com]\n");
exit(0);
}
exit(0);
} else {
printf("Connection Failed\n");
exit(0);
}
}
}