what you don't know can hurt you
Home Files News &[SERVICES_TAB]About Contact Add New

obsd_nospoof.c

obsd_nospoof.c
Posted May 23, 2000
Authored by s0ftpj, Pigpen | Site s0ftpj.org

Anti-spoofing lkm for OpenBSD via setsockopt() - detects and logs IP header manipulation.

tags | spoof
systems | openbsd
SHA-256 | fca4eaa52977935a2efb9a116a709ae0a74a82aa8047fb6d7c04baf8fddfd9e4

obsd_nospoof.c

Change Mirror Download
/*
* Name: NoSpoof v1beta
* Date: May 23 04:06:37 2000
* Author: pIGpEN [ pigpen@s0ftpj.org, deadhead@sikurezza.org ]
*
* SoftProject Digital Security for Y2K
* Sikurezza.org Italian Security Mailing List
*
* COFFEE-WARE LICENSE - This source code is like "THE BEER-WARE LICENSE" by
* Poul-Henning Kamp <phk@FreeBSD.ORG> but you can give me in return a coffee.
*
* Tested on: OpenBSD 2.6 kern#0 i386
*/

#define DONT_PERMIT

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/syscall.h>
#include <sys/mount.h>
#include <sys/conf.h>
#include <sys/syscallargs.h>
#include <sys/exec.h>
#include <sys/lkm.h>
#include <sys/file.h>
#include <sys/filedesc.h>
#include <sys/errno.h>

#include <sys/proc.h>
#include <sys/syslog.h>

#include <sys/mbuf.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <netinet/in.h>



int my_setsockopt __P((struct proc *, void *, register_t *));


MOD_MISC("NoSpoof");

static int
NoSpoof_load(struct lkm_table *lkmtp, int cmd)
{
if(cmd == LKM_E_LOAD) {
printf("EXtern Sp00fiNG Pr0tection\n");
printf("(c) Coffeeware - SoftProject Y2k\n");
printf("pIGpEN / s0ftpj\n");
sysent[SYS_setsockopt].sy_call = my_setsockopt;
}

return 0;
}


static int
NoSpoof_unload(struct lkm_table *lkmtp, int cmd)
{
if(cmd == LKM_E_UNLOAD) {
printf("NoSp00f unloaded\n");
sysent[SYS_setsockopt].sy_call = sys_setsockopt;
}

return 0;
}


NoSpoof( lkmtp, cmd, ver)
struct lkm_table *lkmtp;
int cmd;
int ver;
{
DISPATCH(lkmtp, cmd, ver, NoSpoof_load, NoSpoof_unload, lkm_nofunc);
}


int
my_setsockopt(p, v, retval)
struct proc *p;
void *v;
register_t *retval;
{
register struct sys_setsockopt_args *uap = v;
struct file *fp;
struct mbuf *m = NULL;
int error;

if(SCARG(uap, level) == IPPROTO_IP &&
SCARG(uap, name) == IP_HDRINCL) {
log(LOG_INFO, "detect IP_HDRINCL invoked by %s\n", p->p_comm);
#ifdef DONT_PERMIT
log(LOG_INFO, "ip header manipulation denied!\n");
return EPERM;
#endif
}

if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0)
return (error);
if (SCARG(uap, valsize) > MLEN)
return (EINVAL);
if (SCARG(uap, val)) {
m = m_get(M_WAIT, MT_SOOPTS);
if (m == NULL)
return (ENOBUFS);
error = copyin(SCARG(uap, val), mtod(m, caddr_t),
SCARG(uap, valsize));
if (error) {
(void) m_free(m);
return (error);
}
m->m_len = SCARG(uap, valsize);
}
return (sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
SCARG(uap, name), m));
}

/*

SRCS=obsd_nospoof.c
OBJS=$(SRCS:.c=.o)

MODOBJ=NoSpoof.o

KMOD=NoSpoof
CFLAGS+= -D_KERNEL -I/sys

all: $(MODOBJ)

clean:
rm -f $(OBJS) $(KOBJS) $(MODOBJ) $(KMOD)

load:
modload -o $(KMOD) -e$(KMOD) $(MODOBJ)

unload:
modunload -n $(KMOD)

$(MODOBJ): $(OBJS) $(KOBJS)
$(LD) -r -o $(MODOBJ) $(OBJS) $(KOBJS)
*/
Login or Register to add favorites

File Archive:

July 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Jul 1st
    27 Files
  • 2
    Jul 2nd
    10 Files
  • 3
    Jul 3rd
    35 Files
  • 4
    Jul 4th
    27 Files
  • 5
    Jul 5th
    18 Files
  • 6
    Jul 6th
    0 Files
  • 7
    Jul 7th
    0 Files
  • 8
    Jul 8th
    28 Files
  • 9
    Jul 9th
    44 Files
  • 10
    Jul 10th
    24 Files
  • 11
    Jul 11th
    25 Files
  • 12
    Jul 12th
    11 Files
  • 13
    Jul 13th
    0 Files
  • 14
    Jul 14th
    0 Files
  • 15
    Jul 15th
    0 Files
  • 16
    Jul 16th
    0 Files
  • 17
    Jul 17th
    0 Files
  • 18
    Jul 18th
    0 Files
  • 19
    Jul 19th
    0 Files
  • 20
    Jul 20th
    0 Files
  • 21
    Jul 21st
    0 Files
  • 22
    Jul 22nd
    0 Files
  • 23
    Jul 23rd
    0 Files
  • 24
    Jul 24th
    0 Files
  • 25
    Jul 25th
    0 Files
  • 26
    Jul 26th
    0 Files
  • 27
    Jul 27th
    0 Files
  • 28
    Jul 28th
    0 Files
  • 29
    Jul 29th
    0 Files
  • 30
    Jul 30th
    0 Files
  • 31
    Jul 31st
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close