A PHP Error was encountered

Severity: 8192

Message: Function create_function() is deprecated

Filename: geshi/geshi.php

Line Number: 4698

Backtrace:

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 4698
Function: _error_handler

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 4621
Function: _optimize_regexp_list_tokens_to_string

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 1655
Function: optimize_regexp_list

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 2029
Function: optimize_keyword_group

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 2168
Function: build_parse_cache

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/Process.php
Line: 45
Function: parse_code

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/models/Pastes.php
Line: 517
Function: syntax

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/controllers/Main.php
Line: 693
Function: getPaste

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/index.php
Line: 315
Function: require_once

Strobe port scanner. - Stikked
From John, 10 Years ago, written in C.
Embed
  1. /*
  2.  * Strobe (c) 1995 Julian Assange (proff@suburbia.net),
  3.  * All rights reserved.
  4.  *
  5.  * $ cc strobe.c -o strobe
  6.  */
  7.  
  8. #define VERSION "1.03"
  9.  
  10. #include <stdio.h>
  11. #include <unistd.h>
  12. #include <stdlib.h>
  13. #include <sys/types.h>
  14. #include <sys/time.h>
  15. #include <ctype.h>
  16. #include <fcntl.h>
  17. #include <sys/stat.h>
  18. #include <sys/socket.h>
  19. #ifdef _AIX
  20. #include <sys/select.h>
  21. #endif
  22. #include <netinet/in.h>
  23. #include <arpa/inet.h>
  24. #include <netdb.h>
  25. #include <string.h>
  26. #include <errno.h>
  27.  
  28. #if defined(solaris) || defined(linux) || defined(__FreeBSD__) || \
  29. defined(__NetBSD__) || defined(__GCC__)
  30. #define fvoid void
  31. #else
  32. #define fvoid
  33. extern int optind;
  34. extern char *optarg;
  35. #endif
  36. #define bool char
  37.  
  38. #ifndef INADDR_NONE
  39. #define INADDR_NONE ((unsigned long)-1)
  40. #endif
  41.  
  42. #define port_t (unsigned short)
  43.  
  44. /*
  45.  * the below should be set via the Makefile, but if not...
  46.  */
  47.  
  48. #ifndef ETC_SERVICES
  49. #define ETC_SERVICES "/etc/services"
  50. #endif
  51. #ifndef STROBE_SERVICES
  52. #define STROBE_SERVICES "strobe.services"
  53. #endif
  54. #ifndef LIB_STROBE_SERVICES
  55. #define LIB_STROBE_SERVICES "/usr/local/lib/strobe.services"
  56. #endif
  57.  
  58. int a_timeout = 20;
  59. char *a_output = NULL;
  60. char *a_services = "strobe.services";
  61. char *a_input = NULL;
  62. /* char *a_prescan = NULL; */
  63. int a_start = 1;
  64. int a_end = 65535;
  65. int a_sock_max = 64;
  66. int a_abort = 0;
  67. int a_bindport = 0;
  68. char *a_bindaddr = NULL;
  69. struct in_addr bindaddr;
  70. bool f_linear = 0;
  71. bool f_verbose = 0;
  72. bool f_verbose_stats = 0;
  73. bool f_fast = 0;
  74. bool f_stats = 0;
  75. bool f_quiet = 0;
  76. bool f_delete_dupes = 0;
  77. bool f_minimise = 0;
  78. bool f_dontgetpeername = 0;
  79.  
  80. int connects = 0;
  81. int hosts_done = 0;
  82. int attempts_done = 0;
  83. int attempts_outstanding = 0;
  84. struct timeval time_start;
  85.  
  86. fd_set set_sel;
  87. fd_set set_sel_r;
  88. fd_set set_sel_w;
  89.  
  90. int host_n;
  91. int Argc;
  92. char **Argv;
  93.  
  94. FILE *fh_input;
  95.  
  96. #define HO_ACTIVE 1
  97. #define HO_ABORT 2
  98. #define HO_COMPLETING 4
  99.  
  100. struct hosts_s {
  101.         char *name;
  102.         struct in_addr in_addr;
  103.         int port;
  104.         int portlist_ent;
  105.         struct timeval time_used;
  106.         struct timeval time_start;
  107.         int attempts;
  108.         int attempts_done;
  109.         int attempts_highest_done;
  110.         int connects;
  111.         time_t notice_abort;
  112.         int status;
  113. };
  114. struct hosts_s ho_initial;
  115. struct hosts_s *hosts;
  116.  
  117. #define HT_SOCKET 1
  118. #define HT_CONNECTING 2
  119.  
  120. struct htuple_s {
  121.         char *name;
  122.         struct in_addr in_addr;
  123.         int port;
  124.         int sfd;
  125.         int status;
  126.         struct timeval sock_start;
  127.         int timeout;
  128.         struct hosts_s *host;
  129. };
  130.  
  131. struct htuple_s ht_initial;
  132. struct htuple_s *attempt;
  133.  
  134. struct port_desc_s {
  135.         int port;
  136.         char *name;
  137.         char *portname;
  138.         struct port_desc_s *next;
  139.         struct port_desc_s *next_port;
  140. };
  141.  
  142. struct port_desc_s **port_descs;
  143.  
  144. int *portlist = NULL;
  145. int portlist_n = 0;
  146.  
  147. char *Srealloc(ptr, len)
  148. char *ptr;
  149. int len;
  150. {
  151.         char *p;
  152.         int retries = 10;
  153.         while (!(p = ptr ? realloc(ptr, len) : malloc(len))) {
  154.                 if (!--retries) {
  155.                         perror("malloc");
  156.                         exit(1);
  157.                 }
  158.                 if (!f_quiet)
  159.                         fprintf(stderr,
  160.                                 "Smalloc: couldn't allocate %d bytes...\
  161.                                 sleeping\n",
  162.                                 len);
  163.                 sleep(2);
  164.         }
  165.         return p;
  166. }
  167.  
  168. char *Smalloc(len)
  169. int len;
  170. {
  171.         return Srealloc(NULL, len);
  172. }
  173.  
  174. fvoid sock_block(sfd)
  175. int sfd;
  176. {
  177.         int flags;
  178.         flags = (~O_NONBLOCK) & fcntl(sfd, F_GETFL);
  179.         fcntl(sfd, F_SETFL, flags);
  180. }
  181.  
  182. fvoid sock_unblock(sfd)
  183. int sfd;
  184. {
  185.         int flags;
  186.         flags = O_NONBLOCK | fcntl(sfd, F_GETFL);
  187.         fcntl(sfd, F_SETFL, flags);
  188. }
  189.  
  190. int timeval_subtract(result, x, y)      /* from gnu c-lib info.texi */
  191. struct timeval *result, *x, *y;
  192. {
  193. /* Perform the carry for the later subtraction by updating y. */
  194.         if (x->tv_usec < y->tv_usec) {
  195.                 int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
  196.                 y->tv_usec -= 1000000 * nsec;
  197.                 y->tv_sec += nsec;
  198.         }
  199.         if (x->tv_usec - y->tv_usec > 1000000) {
  200.                 int nsec = (y->tv_usec - x->tv_usec) / 1000000;
  201.                 y->tv_usec += 1000000 * nsec;
  202.                 y->tv_sec -= nsec;
  203.         }
  204.  
  205. /* Compute the time remaining to wait.
  206.   `tv_usec' is certainly positive. */
  207.         result->tv_sec = x->tv_sec - y->tv_sec;
  208.         result->tv_usec = x->tv_usec - y->tv_usec;
  209.  
  210. /* Return 1 if result is negative. */
  211.         return x->tv_sec < y->tv_sec;
  212. }
  213.  
  214. fvoid attempt_clear(h)
  215. struct htuple_s *h;
  216. {
  217.         if (h->status & HT_SOCKET) {
  218.                 struct timeval tv1, tv2;
  219.                 gettimeofday(&tv1, NULL);
  220.                 timeval_subtract(&tv2, &tv1, &(h->sock_start));
  221.                 h->host->time_used.tv_sec += tv2.tv_sec;
  222.                 if ((h->host->time_used.tv_usec += tv2.tv_usec) >= 1000000) {
  223.                         h->host->time_used.tv_usec -= 1000000;
  224.                         h->host->time_used.tv_sec++;
  225.                 }
  226.                 attempts_done++;
  227.                 h->host->attempts_done++;
  228.                 if (h->port > h->host->attempts_highest_done)
  229.                         h->host->attempts_highest_done = h->port;
  230.                 sock_unblock(h->sfd);
  231. /*      shutdown (h->sfd, 2); */
  232.                 close(h->sfd);
  233.                 if (FD_ISSET(h->sfd, &set_sel)) {
  234.                         FD_CLR(h->sfd, &set_sel);
  235.                         attempts_outstanding--;
  236.                 }
  237.         }
  238.         *h = ht_initial;
  239. }
  240.  
  241. fvoid clear_all()
  242. {
  243.         int n;
  244.         for (n = 0; n < a_sock_max; n++)
  245.                 attempt_clear(&attempt[n]);
  246. }
  247.  
  248. fvoid attempt_init()
  249. {
  250.         int n;
  251.         for (n = 0; n < a_sock_max; n++)
  252.                 attempt[n] = ht_initial;
  253. }
  254.  
  255. fvoid hosts_init()
  256. {
  257.         int n;
  258.         for (n = 0; n < a_sock_max; n++)
  259.                 hosts[n] = ho_initial;
  260. }
  261.  
  262. fvoid fdsets_init()
  263. {
  264.         FD_ZERO(&set_sel_r);    /* yes, we have to do this, despite the later */
  265.         FD_ZERO(&set_sel_w);    /* assisgnments */
  266.         FD_ZERO(&set_sel);
  267. }
  268.  
  269. int sc_connect(h)
  270. struct htuple_s *h;
  271. {
  272.         struct sockaddr_in sa_in;
  273.         int sopts1 = 1;
  274.         struct linger slinger;
  275.         if ((h->sfd = socket(PF_INET, SOCK_STREAM, 0)) == -1)
  276.                 return 0;
  277.         memset(&sa_in, 0, sizeof(sa_in));
  278.         h->status |= HT_SOCKET;
  279.         gettimeofday(&(h->sock_start), NULL);
  280.         sock_unblock(h->sfd);
  281.         setsockopt(h->sfd, SOL_SOCKET, SO_REUSEADDR, (char *)&sopts1,
  282.                    sizeof(sopts1));
  283.         setsockopt(h->sfd, SOL_SOCKET, SO_OOBINLINE, (char *)&sopts1,
  284.                    sizeof(sopts1));
  285.         slinger.l_onoff = 0;    /* off */
  286.         setsockopt(h->sfd, SOL_SOCKET, SO_LINGER, (char *)&slinger,
  287.                    sizeof(slinger));
  288.         sa_in.sin_family = AF_INET;
  289.         if (a_bindport)
  290.                 sa_in.sin_port = a_bindport;
  291.         if (a_bindaddr)
  292.                 sa_in.sin_addr = bindaddr;
  293.         if (a_bindaddr || a_bindport)
  294.                 if (bind(h->sfd, (struct sockaddr *)&sa_in, sizeof(sa_in)) ==
  295.                     -1) {
  296.                         fprintf(stderr, "couldn't bind %s : %d  ",
  297.                                 a_bindaddr ? a_bindaddr : "0.0.0.0",
  298.                                 ntohs(a_bindport));
  299.                         perror("");
  300.                         if (errno == EACCES)
  301.                                 exit(1);
  302.                         return 0;
  303.                 }
  304.         sa_in.sin_addr = h->in_addr;
  305.         sa_in.sin_port = htons(h->port);
  306.  
  307.         if (connect(h->sfd, (struct sockaddr *)&sa_in, sizeof(sa_in)) == -1) {
  308.                 switch (errno) {
  309.                 case EINPROGRESS:
  310.                 case EWOULDBLOCK:
  311.                         break;
  312.                 case ETIMEDOUT:
  313.                 case ECONNREFUSED:
  314.                 case EADDRNOTAVAIL:
  315.                         if (f_verbose) {
  316.                                 fprintf(stderr, "%s:%d ", h->name, h->port);
  317.                                 perror("");
  318.                         }
  319.                         h->host->attempts++;
  320.                         attempt_clear(h);
  321.                         return 1;
  322.                 default:
  323.                         if (!f_quiet) {
  324.                                 fprintf(stderr, "%s:%d ", h->name, h->port);
  325.                                 perror("");
  326.                         }
  327.                         attempt_clear(h);
  328.                         return 0;
  329.                 }
  330.         }
  331.         h->host->attempts++;
  332.         h->status |= HT_CONNECTING;
  333.         sock_block(h->sfd);
  334.         FD_SET(h->sfd, &set_sel);
  335.         attempts_outstanding++;
  336.         return 1;
  337. }
  338.  
  339. int gatherer_tcp(h)
  340. struct htuple_s *h;
  341. {
  342.         struct port_desc_s *pd;
  343.         if (f_minimise)
  344.                 printf("%s\t%d\n", h->name, h->port);
  345.         else {
  346.                 if ((pd = port_descs[h->port])) {
  347.                         printf("%-30s %-16s %5d/tcp %s\n", h->name,
  348.                                pd->portname, h->port, pd->name);
  349.                         while (!f_delete_dupes && !f_minimise
  350.                                && (pd = pd->next))
  351.                                 printf("#%-29s %-16s %5d/tcp %s\n", h->name,
  352.                                        pd->portname, h->port, pd->name);
  353.                 } else
  354.                         printf("%-30s %-16s %5d/tcp unassigned\n", h->name,
  355.                                "unknown", h->port);
  356.         }
  357.         h->host->connects++;
  358.         connects++;
  359.         attempt_clear(h);
  360.         return 1;
  361. }
  362.  
  363. bool gather()
  364. {
  365.         struct timeval timeout;
  366.         struct htuple_s *h;
  367.         int n;
  368.         int selected;
  369.         time_t tim;
  370.  
  371.         if (!attempts_outstanding)
  372.                 return 1;
  373.         set_sel_r = set_sel_w = set_sel;
  374.         timeout.tv_sec = 0;
  375.         timeout.tv_usec = 250000;       /* 1/4 of a second */
  376.  
  377.         selected = select(FD_SETSIZE, &set_sel_r, &set_sel_w, 0, &timeout);
  378.         /* Look for timeouts */
  379.  
  380.         tim = time(NULL);
  381.         for (n = 0; n < a_sock_max; n++) {
  382.                 h = &attempt[n];
  383.                 if ((h->status & HT_SOCKET) &&
  384.                     ((h->sock_start.tv_sec + h->timeout) < tim))
  385.                         attempt_clear(h);
  386.         }
  387.  
  388.         switch (selected) {
  389.         case -1:
  390.                 perror("select");
  391.                 return 0;
  392.         case 0:
  393.                 return 1;
  394.         }
  395.         for (n = 0; selected && (n < a_sock_max); n++) {
  396.                 h = &attempt[n];
  397.                 if (h->status & HT_CONNECTING) {
  398.                         if (FD_ISSET(h->sfd, &set_sel_r)
  399.                             || FD_ISSET(h->sfd, &set_sel_w)) {
  400.                                 struct sockaddr_in in;
  401.                                 int len = sizeof(in);
  402.                                 selected--;
  403.                                 /* select() lies occasionaly
  404.                                  */
  405.                                 if (!f_dontgetpeername) {
  406.                                 /* but solaris2.3 crashes occasionally ;-| */
  407.                                         if (getpeername
  408.                                             (h->sfd, (struct sockaddr *)&in,
  409.                                              &len) == 0)
  410.                                                 gatherer_tcp(h);
  411.                                         else
  412.                                                 attempt_clear(h);
  413.                                 } else
  414.                                         gatherer_tcp(h);
  415.                         }
  416.                 }
  417.         }
  418.         return 1;
  419. }
  420.  
  421. bool add_attempt(add)
  422. struct htuple_s *add;
  423. {
  424.         struct htuple_s *h;
  425.         static time_t oldtime;
  426.         static int n;
  427.         for (;;) {
  428.                 for (; n < a_sock_max; n++) {
  429.                         h = &attempt[n];
  430.                         if (!h->status)
  431.                                 goto foundfree;
  432.                 }
  433.                 n = 0;
  434.                 gather();
  435.                 continue;
  436. foundfree:
  437.                 *h = *add;
  438.                 if (!sc_connect(h)) {
  439.                         gather();
  440.                         continue;
  441.                 }
  442.                 if ((oldtime + 1) < time(NULL)) {
  443.                         oldtime = time(NULL);
  444.                         gather();
  445.                 }
  446.                 break;
  447.         }
  448.         return 1;
  449. }
  450.  
  451. int scatter(host, timeout)
  452. struct hosts_s *host;
  453. int timeout;
  454. {
  455.         static struct htuple_s add;
  456.         add = ht_initial;
  457.         add.host = host;
  458.         add.name = host->name;
  459.         add.in_addr = host->in_addr;
  460.         add.port = host->port;
  461.         add.timeout = timeout;
  462.         if (f_verbose)
  463.                 fprintf(stderr, "attempting port=%d host=%s\n", add.port,
  464.                         add.name);
  465.         add_attempt(&add);
  466.         return 1;
  467. }
  468.  
  469. fvoid wait_end(t)
  470. int t;
  471. {
  472.         time_t st;
  473.         st = time(NULL);
  474.         while ((st + t) > time(NULL)) {
  475.                 gather();
  476.                 if (attempts_outstanding < 1)
  477.                         break;
  478.         }
  479. }
  480.  
  481. struct in_addr resolve(name)
  482. char *name;
  483. {
  484.         static struct in_addr in;
  485.         unsigned long l;
  486.         struct hostent *ent;
  487.         if ((l = inet_addr(name)) != INADDR_NONE) {
  488.                 in.s_addr = l;
  489.                 return in;
  490.         }
  491.         if (!(ent = gethostbyname(name))) {
  492.                 perror(name);
  493.                 in.s_addr = INADDR_NONE;
  494.                 return in;
  495.         }
  496.         return *(struct in_addr *)ent->h_addr;
  497. }
  498.  
  499. char *next_host()
  500. {
  501.         static char lbuf[512];
  502.         hosts_done++;
  503.         if (a_input) {
  504.                 int n;
  505. reread:
  506.                 if (!fgets(lbuf, sizeof(lbuf), fh_input)) {
  507.                         fclose(fh_input);
  508.                         a_input = NULL;
  509.                         return next_host();
  510.                 }
  511.                 if (strchr("# \t\n\r", lbuf[0]))
  512.                         goto reread;
  513.                 n = strcspn(lbuf, " \t\n\r");
  514.                 if (n)
  515.                         lbuf[n] = '\0';
  516.                 return lbuf;
  517.         }
  518.         if (host_n >= Argc)
  519.                 return NULL;
  520.  
  521.         return Argv[host_n++];
  522. }
  523.  
  524. bool host_init(h, name, nocheck)
  525. struct hosts_s *h;
  526. char *name;
  527. bool nocheck;
  528. {
  529.         int n;
  530.         *h = ho_initial;
  531.         h->in_addr = resolve(name);
  532.         if (h->in_addr.s_addr == INADDR_NONE)
  533.                 return 0;
  534.         if (!nocheck)
  535.                 for (n = 0; n < a_sock_max; n++) {
  536.                         if (hosts[n].name
  537.                             && hosts[n].in_addr.s_addr == h->in_addr.s_addr) {
  538.                                 if (!f_quiet)
  539.                                         fprintf(stderr,
  540.                                                 "ip duplication: %s == %s (\
  541.                                                 last host ignored)\n",
  542.                                                 hosts[n].name, name);
  543.                                 return 0;
  544.                         }
  545.                 }
  546.         h->name = (char *)Smalloc(strlen(name) + 1);
  547.         strcpy(h->name, name);
  548.         h->port = a_start;
  549.         h->status = HO_ACTIVE;
  550.         gettimeofday(&(h->time_start), NULL);
  551.         return 1;
  552. }
  553.  
  554. fvoid host_clear(h)
  555. struct hosts_s *h;
  556. {
  557.         if (h->name) {
  558.                 free(h->name);
  559.         }
  560.         *h = ho_initial;
  561. }
  562.  
  563. fvoid host_stats(h)
  564. struct hosts_s *h;
  565. {
  566.         struct timeval tv, tv2;
  567.         float t, st;
  568.         gettimeofday(&tv, NULL);
  569.         timeval_subtract(&tv2, &tv, &(h->time_start));
  570.         t = tv2.tv_sec + (float)tv2.tv_usec / 1000000.0;
  571.         st = h->time_used.tv_sec + (float)h->time_used.tv_usec / 1000000.0;
  572.         fprintf(stderr,
  573.                 "stats: host = %s trys = %d cons = %d time = %.2fs trys/s\
  574.                  = %.2f trys/ss = %.2f\n",
  575.                 h->name, h->attempts_done, h->connects, t, h->attempts_done / t,
  576.                 h->attempts_done / st);
  577. }
  578.  
  579. fvoid final_stats()
  580. {
  581.         struct timeval tv, tv2;
  582.         float t;
  583.         gettimeofday(&tv, NULL);
  584.         timeval_subtract(&tv2, &tv, &(time_start));
  585.         t = tv2.tv_sec + (float)tv2.tv_usec / 1000000.0;
  586.         fprintf(stderr,
  587.                 "stats: hosts = %d trys = %d cons = %d time = %.2fs trys/s = %.2f\n",
  588.                 hosts_done, attempts_done, connects, t, attempts_done / t);
  589. }
  590.  
  591. bool skip_host(h)
  592. struct hosts_s *h;
  593. {
  594.         if (a_abort && !h->connects && (h->attempts_highest_done >= a_abort)) {
  595.         /* async pain */
  596.                 if (h->status & HO_ABORT) {
  597.                         if ((time(NULL) - h->notice_abort) > a_timeout) {
  598.                                 if (f_verbose)
  599.                                         fprintf(stderr,
  600.                                                 "skipping: %s (no connects \
  601.                                                 in %d attempts)\n",
  602.                                                 h->name, h->attempts_done);
  603.                                 return 1;
  604.                         }
  605.                 } else {
  606.                         h->notice_abort = time(NULL);
  607.                         h->status |= HO_ABORT;
  608.                 }
  609.         }
  610.         return 0;
  611. }
  612.  
  613. int next_port(h)
  614. struct hosts_s *h;
  615. {
  616.         int n;
  617.         for (n = h->port; ++n <= a_end;) {
  618.                 if (!f_fast)
  619.                         return n;
  620.                 if (++h->portlist_ent > portlist_n)
  621.                         return -1;
  622.                 return (portlist[h->portlist_ent - 1]);
  623.         }
  624.         return -1;
  625. }
  626.  
  627. fvoid scan_ports_linear()
  628. {
  629.         struct hosts_s host;
  630.         char *name;
  631.         while ((name = next_host())) {
  632.                 if (!host_init(&host, name, 1))
  633.                         continue;
  634.                 for (;;) {
  635.                         scatter(&host, a_timeout);
  636.                         if (skip_host(&host))
  637.                                 break;
  638.                         if ((host.port = next_port(&host)) == -1)
  639.                                 break;
  640.                 }
  641.                 wait_end(a_timeout);
  642.                 if (f_verbose_stats)
  643.                         host_stats(&host);
  644.                 clear_all();
  645.                 host_clear(&host);
  646.         }
  647. }
  648.  
  649. /* Huristics:
  650.  *  o  fast connections have priority == maximise bandwidth i.e
  651.  *     a port in the hand is worth two in the bush
  652.  *
  653.  *  o  newer hosts have priority == lower ports checked more quickly
  654.  *
  655.  *  o  all hosts eventually get equal "socket time" == despite
  656.  *     priorities let no one host hog the sockets permanently
  657.  *
  658.  *  o  when host usage times are equal (typically on or shortly after
  659.  *     initial startup) distribute hosts<->sockets evenly rather than
  660.  *     play a game of chaotic bifurcatic ping-pong
  661.  */
  662.  
  663. fvoid scan_ports_paralell()
  664. {
  665.         int n;
  666.         struct timeval smallest_val;
  667.         int smallest_cnt;
  668.         char *name;
  669.         struct hosts_s *h, *smallest = &hosts[0];
  670.         while (smallest) {
  671.                 smallest_val.tv_sec = 0xfffffff;
  672.                 smallest_val.tv_usec = 0;
  673.                 for (n = 0, smallest_cnt = 0xfffffff, smallest = NULL;
  674.                      n < a_sock_max; n++) {
  675.                         h = &hosts[n];
  676.  
  677.                         if (((h->status & HO_COMPLETING) &&
  678.                              (h->attempts_done == h->attempts)) ||
  679.                             skip_host(h)) {
  680.                                 if (f_verbose_stats)
  681.                                         host_stats(h);
  682.                                 host_clear(h);
  683.                         }
  684.  
  685.                         if (!h->name && ((name = next_host())))
  686.                                 if (!host_init(h, name, 0)) {
  687.                                         host_clear(h);
  688.                                         continue;
  689.                                 }
  690.  
  691.                         if (h->name) {
  692.                                 if (((h->time_used.tv_sec < smallest_val.tv_sec)
  693.                                      ||
  694.                                      ((h->time_used.tv_sec ==
  695.                                        smallest_val.tv_sec)
  696.                                       && (h->time_used.tv_usec <=
  697.                                           smallest_val.tv_usec)))
  698.                                     &&
  699.                                     (((h->time_used.tv_sec !=
  700.                                        smallest_val.tv_sec)
  701.                                       && (h->time_used.tv_usec !=
  702.                                           smallest_val.tv_usec))
  703.                                      || (h->attempts < smallest_cnt))) {
  704.                                         smallest_cnt = h->attempts;
  705.                                         smallest_val = h->time_used;
  706.                                         smallest = h;
  707.                                 }
  708.                         }
  709.                 }
  710.  
  711.                 if (smallest) {
  712.                         if (!(smallest->status & HO_COMPLETING)) {
  713.                                 scatter(smallest, a_timeout);
  714.                                 if ((smallest->port =
  715.                                      next_port(smallest)) == -1)
  716.                                         smallest->status |= HO_COMPLETING;
  717.                         } else
  718.                                 gather();
  719.                 }
  720.         }
  721. }
  722.  
  723. fvoid loaddescs()
  724. {
  725.         FILE *fh;
  726.         char lbuf[1024];
  727.         char desc[256];
  728.         char portname[17];
  729.         unsigned int port;
  730.         char *fn;
  731.         char prot[4];
  732.         prot[3] = '\0';
  733.         if (!(fh = fopen((fn = a_services), "r")) &&
  734.             !(fh = fopen((fn = LIB_STROBE_SERVICES), "r")) &&
  735.             !(fh = fopen((fn = ETC_SERVICES), "r"))) {
  736.                 perror(fn);
  737.                 exit(1);
  738.         }
  739.         port_descs =
  740.             (struct port_desc_s **)Smalloc(sizeof(struct port_descs_s *) *
  741.                                            65536);
  742.         memset(port_descs, 0, 65536);
  743.         while (fgets(lbuf, sizeof(lbuf), fh)) {
  744.                 char *p;
  745.                 struct port_desc_s *pd, *pdp;
  746.                 if (strchr("*# \t\n", lbuf[0]))
  747.                         continue;
  748.                 if (!(p = strchr(lbuf, '/')))
  749.                         continue;
  750.                 *p = ' ';
  751.                 desc[0] = '\0';
  752.                 if (sscanf
  753.                     (lbuf, "%16s %u %3s %255[^\r\n]", portname, &port, prot,
  754.                      desc) < 3 || strcmp(prot, "tcp") || (port > 65535))
  755.                         continue;
  756.                 pd = port_descs[port];
  757.                 if (!pd) {
  758.                         portlist =
  759.                             (int *)Srealloc((char *)portlist,
  760.                                             ++portlist_n * sizeof(int));
  761.                         portlist[portlist_n - 1] = port;
  762.                 }
  763.                 if (!f_minimise) {
  764.                         pdp =
  765.                             (struct port_desc_s *)Smalloc(sizeof(*pd) +
  766.                                                           strlen(desc) + 1 +
  767.                                                           strlen(portname) + 1);
  768.                         if (pd) {
  769.                                 for (; pd->next; pd = pd->next) ;
  770.                                 pd->next = pdp;
  771.                                 pd = pd->next;
  772.                         } else {
  773.                                 pd = pdp;
  774.                                 port_descs[port] = pd;
  775.                         }
  776.                         pd->next = NULL;
  777.                         pd->name = (char *)(pd) + sizeof(*pd);
  778.                         pd->portname = pd->name + strlen(desc) + 1;
  779.                         strcpy(pd->name, desc);
  780.                         strcpy(pd->portname, portname);
  781.                 } else
  782.                         port_descs[port] = (struct port_desc_s *)-1;
  783.         }
  784.         if (f_minimise)
  785.                 free(port_descs);
  786. }
  787.  
  788. fvoid usage()
  789. {
  790.         fprintf(stderr, "\
  791. usage: %8s [options]\n\
  792. \t\t[-v(erbose)]\n\
  793. \t\t[-V(erbose_stats]\n\
  794. \t\t[-m(inimise)]\n\
  795. \t\t[-d(elete_dupes)]\n\
  796. \t\t[-g(etpeername_disable)]\n\
  797. \t\t[-s(tatistics)]\n\
  798. \t\t[-q(uiet)]\n\
  799. \t\t[-o output_file]\n\
  800. \t\t[-b begin_port_n]\n\
  801. \t\t[-e end_port_n]\n\
  802. \t\t[-p single_port_n]\n\
  803. \t\t[-P bind_port_n]\n\
  804. \t\t[-A bind_addr_n]\n\
  805. \t\t[-t timeout_n]\n\
  806. \t\t[-n num_sockets_n]\n\
  807. \t\t[-S services_file]\n\
  808. \t\t[-i hosts_input_file]\n\
  809. \t\t[-l(inear)]\n\
  810. \t\t[-f(ast)]\n\
  811. \t\t[-a abort_after_port_n]\n\
  812. \t\t[-M(ail_author)]\n\
  813. \t\t[host1 [...host_n]]\n", Argv[0]);
  814.         exit(1);
  815. }
  816.  
  817. int main(argc, argv)
  818. int argc;
  819. char **argv;
  820. {
  821.         int c;
  822.         Argc = argc;
  823.         Argv = argv;
  824.  
  825.         while ((c =
  826.                 getopt(argc, argv, "o:dvVmgb:e:p:P:a:A:t:n:S:i:lfsqM")) != -1)
  827.                 switch (c) {
  828.                 case 'o':
  829.                         a_output = optarg;
  830.                         break;
  831.                 case 'd':
  832.                         f_delete_dupes = 1;
  833.                         break;
  834.                 case 'v':
  835.                         f_verbose = 1;
  836.                         break;
  837.                 case 'V':
  838.                         f_verbose_stats = 1;
  839.                         break;
  840.                 case 'm':
  841.                         f_minimise = 1;
  842.                         break;
  843.                 case 'g':
  844.                         f_dontgetpeername = 1;
  845.                         break;
  846.                 case 'b':
  847.                         a_start = atoi(optarg);
  848.                         break;
  849.                 case 'e':
  850.                         a_end = atoi(optarg);
  851.                         break;
  852.                 case 'P':
  853.                         a_bindport = htons(atoi(optarg));
  854.                         break;
  855.                 case 'A':
  856.                         a_bindaddr = optarg;
  857.                         bindaddr = resolve(a_bindaddr);
  858.                         if (bindaddr.s_addr == INADDR_NONE) {
  859.                                 perror(a_bindaddr);
  860.                                 exit(1);
  861.                         }
  862.                         break;
  863.                 case 'p':
  864.                         a_start = a_end = atoi(optarg);
  865.                         break;
  866.                 case 'a':
  867.                         a_abort = atoi(optarg);
  868.                         break;
  869.                 case 't':
  870.                         a_timeout = atoi(optarg);
  871.                         break;
  872.                 case 'n':
  873.                         a_sock_max = atoi(optarg);
  874.                         break;
  875.                 case 'S':
  876.                         a_services = optarg;
  877.                         break;
  878.                 case 'i':
  879.                         a_input = optarg;
  880.                         break;
  881.                 case 'l':
  882.                         f_linear = 1;
  883.                         break;
  884.                 case 'f':
  885.                         f_fast = 1;
  886.                         break;
  887.                 case 's':
  888.                         f_stats = 1;
  889.                         break;
  890.                 case 'q':
  891.                         f_quiet = 1;
  892.                         break;
  893.                 case 'M':
  894.                         fprintf(stderr,
  895.                                 "Enter mail to author below. End with ^D or .\n");
  896.                         system("mail strobe@suburbia.net");
  897.                         break;
  898.                 case '?':
  899.                 default:
  900.                         fprintf(stderr, "unknown option %s\n",
  901.                                 argv[optind - 1]);
  902.                         usage();
  903.                         /* NOT_REACHED */
  904.                 }
  905.         host_n = optind;
  906.  
  907.         if (!f_quiet)
  908.                 fprintf(stderr,
  909.                         "strobe %s (c) 1995 Julian Assange (proff@suburbia.net).\n",
  910.                         VERSION);
  911.         if (a_input) {
  912.                 if (!strcmp("-", a_input)) {    /* Use stdin as input file */
  913.                         fh_input = stdin;
  914.                 } else {
  915.                         if (!(fh_input = fopen(a_input, "r"))) {
  916.                                 perror(a_input);
  917.                                 exit(1);
  918.                         }
  919.                 }
  920.         } else {
  921.                 switch (argc - host_n) {        /* Number of hosts found on command line */
  922.                 case 0:
  923.                         fh_input = stdin;
  924.                         a_input = "stdin";      /* Needed in "next_host()" */
  925.                         break;
  926.                 case 1:
  927.                         f_linear = 1;
  928.                         break;
  929.                 }
  930.         }
  931.  
  932.         if ((fh_input == stdin) && !f_quiet)
  933.                 fprintf(stderr, "Reading host names from stdin...\n");
  934.  
  935.         if (a_output) {
  936.                 int fd;
  937.                 if ((fd =
  938.                      open(a_output, O_WRONLY | O_CREAT | O_TRUNC,
  939.                           0666)) == -1) {
  940.                         perror(a_output);
  941.                         exit(1);
  942.                 }
  943.                 dup2(fd, 1);
  944.         }
  945.         attempt =
  946.             (struct htuple_s *)Smalloc(a_sock_max * sizeof(struct htuple_s));
  947.         attempt_init();
  948.         if (!f_linear) {
  949.                 hosts =
  950.                     (struct hosts_s *)Smalloc(a_sock_max *
  951.                                               sizeof(struct hosts_s));
  952.                 hosts_init();
  953.         }
  954.         if (!f_minimise || f_fast)
  955.                 loaddescs();
  956.         fdsets_init();
  957.         gettimeofday(&time_start, NULL);
  958.         f_linear ? scan_ports_linear() : scan_ports_paralell();
  959.         if (f_stats || f_verbose_stats)
  960.                 final_stats();
  961.         exit(0);
  962. }
  963.  

Replies to Strobe port scanner. rss

Title Name Language When
Re: Strobe port scanner. Tinct Crane c 7 Years ago.