[PATCH] mini port scanner for busybox - V2

Tito farmatito at tiscali.it
Thu Jun 14 14:12:20 UTC 2007


On Thursday 14 June 2007 10:37:54 Denis Vlasenko wrote:
> Hi Tito,
> 
> On Wednesday 13 June 2007 23:54, Tito wrote:
> > Hi,
> > this patch adds a very simple port scanner based on connect() to busybox.
> > I developed it for fun and to improve my skills.
> > Include it if you like it. Critics, hints and improvements are welcome.
> > It is turned off by default. Bloat-o-meter says:
> > 
> > scripts/bloat-o-meter busybox_old busybox_unstripped
> > function                                             old     new   delta
> > pscan_main                                             -     472    +472
> > .rodata                                           122515  122707    +192
> > packed_usage                                       22284   22334     +50
> > my_gettimeofday                                        -      35     +35
> > applets                                             3084    3096     +12
> > ------------------------------------------------------------------------------
> > (add/remove: 2/0 grow/shrink: 3/0 up/down: 761/0)             Total: 761 bytes
> > 
> > BTW: the increase in .rodata seems very big (maybe too big) to me, but i'm not a guru in this things....
> > 
> > Output looks like:
> > 
> > root at localhost:~/Desktop/busybox.orig# ./busybox pscan www.busybox.net
> > Scanning www.busybox.net ports 1 to 1024
> >  Port   Proto   State   Service
> >    22   tcp     open    ssh
> >    25   tcp     open    smtp
> >    53   tcp     open    domain
> >    80   tcp     open    www
> >   443   tcp     open    https
> >   873   tcp     open    rsync
> > 0 stealth, 1018 closed, 6 open ports
> 
> +               connect(s, &lsap->sa, lsap->len);
> +
> +               if (errno == ENETDOWN
> +               ||  errno == ENETUNREACH
> +               ||  errno == ENETRESET
> +               ||  errno == ECONNABORTED)
> +                       bb_perror_nomsg_and_die();
> +
> +               do {
> +                       if (errno == ECONNREFUSED) {
> +                               closed_ports++;
> +                               /* Attempt to calculate the rtt */
> +                               rtt = my_gettimeofday() - t1;
> +                               break;
> +                       }
> +                       retval = write(s, " ", 1);
> 
> Shouldn't you check connect return value, at least just before write?
> 
> +                       if (((rtt * 2) - (my_gettimeofday() - t1)) <= 0) {
> 
> You mean, if (rtt * 2 <= my_gettimeofday() - t1) ?
> 
> +                       /* Double rtt to try to avoid some false negative results */
> +                       /* on ports due to network performance decrease.          */
> 
> Where is the code which does this doubling? comment imply that rtt *= 2,
> but there is no such line.
> 
> It's good that you added these comments,
> but explanation is not clear enough (at least for me).
> 
> Care to improve?
> --
> vda
> 

Here a new version of the patch with improved comments. Enjoy! ;-D

PS: fixed also a stupid typo in my_gettimeofday
if (!gettimeofday(&now, NULL)) ==> if (gettimeofday(&now, NULL))

Ciao,
Tito

-------------- next part --------------
A non-text attachment was scrubbed...
Name: pscan02.patch
Type: text/x-diff
Size: 6251 bytes
Desc: not available
Url : http://lists.busybox.net/pipermail/busybox/attachments/20070614/76a62e5b/attachment-0002.bin 


More information about the busybox mailing list