Click to See Complete Forum and Search --> : Need Some C Code About Port Scan


Herro_tales
08-01-2005, 11:07 AM
i want to learning about port scanning.so need some c code of scanning to study such as TCP SYN (half open) scanning, TCP FIN (stealth) scanning, TCP ftp proxy (bounce attack) scanning, SYN/FIN scanning using IP fragments (bypasses packet filters), UDP recvfrom() scanning, UDP raw ICMP port unreachable scanning, ICMP scanning (ping-sweep), and Reverse-ident scanning.
actual,i should analyse the c code of nmap,but it's diffcult for me now.
i need some more basic code.
whoever can help me by send it to my email :Herro_tales@163.com
thank u!

janet loves bill
08-01-2005, 05:01 PM
here ya go.......it is a basic scanner, nothing fancy.....improve on it if you want...........


#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
main(int argc, char *argv[]) {
if(argc < 3) {
printf("Usage: %s <host/ip> <start_port>\n", argv[0]);
printf("Rootscan was written by pawns4unme@yahoo.com\n");
exit(-1);
}
int sock;
struct hostent *host;
struct sockaddr_in dest;
int count = 0;
int start_port = atoi(argv[2]);
if((host = gethostbyname(argv[1])) == NULL) {
printf("Couldn't resolve %s\n", argv[1]);
exit(-1);
}

for(count = start_port; count <= 65535; count++) {
if((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
printf("Couldn't make socket!\n");
exit(-1);
}

dest.sin_family = AF_INET;
dest.sin_port = htons(count);
dest.sin_addr = *((struct in_addr *)host->h_addr);
if(connect(sock, (struct sockaddr *)&dest, sizeof(struct sockaddr)) == -1) {
printf("Port %d \t Closed\n", count);
close(sock);
sleep(1);
}
else {
printf("Port %d \t Open\n", count);
close(sock);
sleep(1);
}
}
return(0);
}

bwkaz
08-01-2005, 08:41 PM
Well... you could just read a bit. Writing those various types of scans really isn't that difficult once you know what they are (and the basics of TCP in general).

And like you said -- nmap is freely available. You'll understand a lot more about it once you figure out what it's trying to do, packet-wise.

This does look a lot like something a script kiddie would post, though. (I want to be careful here -- I'm not saying you are one. Just that your question looks like something that would come from someone who never takes the time to learn anything, but just uses tools that others have written to make it easy for them to break into things. Which is the very definition of a script kiddie.)

I am going to close this thread -- if you have a legitimate reason for needing someone to give you this code (as opposed to taking a bit of time to learn how this stuff works on your own), PM me with that reason and I'll consider reopening it.

Thanks!