Today I got an itch to grab banners from services. I didn’t immediately find any code to do exactly what I wanted. I did find code to do something more than I wanted. Here is that code: http://packetstormsecurity.org/UNIX/scanners/banner.c. It is much more full featured than I wanted as it is will scan multiple IPs and ports grabbing the banners and doing some simple logic to determine if they might be vulnerable. So spent a little while this afternoon and hacked it up to just grab a single IP and port combination banner. Not being very creative I named my derivative work banner2.c .Here’s the code:
/* Name: banner2.c v0.9
* hacked up by: pjohnson@bosconet.org
* original code by Author: Cyber_Bob
* Made: Code Crusader 2.1.4 (very l33t scr1pt maker, y0 
* Compiled: linux 2.2.16 i686 (slackware 7.1)
* gcc version egcs-2.91.66
* gcc banner2.c -o banner2
*
* ------------------------------------------------------------------------------
* Release Notes:
*
* This version is a big improvement over the last version. Some added features
* are the ability to scan a range of hosts and it will look for keywords in
* banners to check for a possible entry point for breakin. I've also been told
* it works good for reporting Wingates which prove ever useful on IRC. Also, it
* has the ability to recognize certain ports daemons by name (RFC Standards).
* If a possible vulnerable daemon is found you must strike enter before the scan
* will continue. Look for logging options in the next version. As of right now
* I am only testing idea's. There is also a delay in microseconds between
* connections to each port, this options is #define'd at 500000 (half a second)
* by default so you can watch the output scroll by without much effort. For a
* simple method of logging I added a "< !>” event at the beginning of lines that
* signal a possible risk (I like to call it the attention mark) for easy parsing
* of a command like:
*
* pjohnson hack:
*
* I wanted a simpler tool to just grab the banner on a given tcp port
* the first one I found was Cyber_Bob’s banner.c . It works great but is MUCH more
* full featured than I wanted. So I took his fine work and stripped it down to what
* I wanted. This is the result…..to run:
*
* ./banner2 127.0.0.1 22
*
* ——————————————————————————
* [Shoutz] #NuKeZ , #OutLaw , #Assassins , and #twlc cr3w’z
*
* [Shoutz/People] ^Paladin^, Sleep, L^WaRrioR, DePhAzEr, Dark, skalore,
* Jackery, firebird1, trunck, Cyber_Egg (stupid ass bot),
* h1kari, Sleep, soulFate, CommPort5, RizzDog, ScuzleBut,
* sgxxxxxxxxxxxxxxxxxxxxx (lots of leet x’s ;P), n0th,
* t03tag, USSR Labs (just cuz they dissed marc of eEye ;),
* VIRILATOR, evilgh0st, Phear, anybody else I forgot and
* deserves to be in here..
* ——————————————————————————
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define VERSION “1.0 beta”
#define DELAY 500000
char data[1000];
int sock,p1, p2,i=1,ctr2;
unsigned long start, end, ctr;
struct sockaddr_in sa;
int main (int argc, char *argv[]) {
if(argc!=3) {
printf(”\nUsage: %s
\n”,argv[0]);
exit(1);
}
else {
start=inet_addr(argv[1]);
p1=atoi(argv[2]);
}
ctr = ntohl(start);
if((ctr & 0xff) == 0) ctr++;
if((ctr & 0xff) ==255) ctr++;
sa.sin_family=AF_INET;
sa.sin_port=htons(p1);
sa.sin_addr.s_addr=htonl(ctr);
sock=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
connect(sock,(struct sockaddr *)&sa,sizeof(sa));
fflush(stdin);
memset(data,0,sizeof(data));
read(sock,&data,1000);
printf(”host: %s port: %d banner: %s\n”, argv[1], p1, data);
usleep(DELAY);
return 0;
}