From 9fdc6d3d282b01b6d0ed303aacb2e5d9d724092b Mon Sep 17 00:00:00 2001 From: Ralph Ronnquist Date: Sun, 21 Feb 2021 09:23:55 +1100 Subject: [PATCH] added --- socket-sniff.lsp | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 socket-sniff.lsp diff --git a/socket-sniff.lsp b/socket-sniff.lsp new file mode 100755 index 0000000..95639e9 --- /dev/null +++ b/socket-sniff.lsp @@ -0,0 +1,60 @@ +#!/usr/bin/newlisp +# +# Open a raw socket to sniff an interface; output to stdout + +(signal 2 (fn (x) (exit 0))) + +(context 'LIBC6) +(constant 'library "/lib/x86_64-linux-gnu/libc.so.6") +(import library "ioctl" "int" "int" "long" "void*" ) +(import library "perror" "void" "char*" ) +(import library "fdopen" "void*" "int" "char*" ) +(import library "setbuf" "void" "void*" "void*" ) +(import library "ntohs" "int" "int" ) +(import library "htons" "int" "int" ) +(import library "inet_addr" "void*" "void*") +(import library "socket" "int" "int" "int" "int") +(import library "setsockopt" "int" "int" "int" "int" "void*" "int") +(import library "perror" "void" "char*") +(setf bind-socket (import library "bind" "int" "int" "void*" "int")) + +(define (die) + (perror (join (map string (args)) " ")) + (exit 1)) + +(letex ((AF_INET 2) + (SOCK_RAW 10) + (IPPROTO_RAW (htons 0x0800)) + (SOL_SOCKET 1) + (SO_BINDTODEVICE 25) + (SO_BROADCAST 6) + (SIZEOF_struct_sockaddr 16) + ) + (define (raw-socket) + (socket AF_INET SOCK_RAW IPPROTO_RAW)) + + (define (bind-to-device FD IFACE) + (when (!= (setsockopt FD SOL_SOCKET SO_BINDTODEVICE IFACE (length IFACE))) + (die "setsockopt bind")) + (when (!= (setsockopt FD SOL_SOCKET SO_BROADCAST (pack "lu" 1) 4)) + (die "setsockopt broadcast")) + 0) + + ) ; end letex + +(context MAIN) + +(setf IFACE (main-args -1) FD (LIBC6:raw-socket) ) + +(when (< FD) + (LIBC6:die "socket")) + +(when (!= (LIBC6:bind-to-device FD IFACE)) + (LIBC6:die "bind-to-device")) + +(LIBC6:setbuf (LIBC6:fdopen 1 "w") 0) + +(while (> (setf N (read FD BUFFER 2048)) 0) + (write 1 BUFFER)) + +(exit 0) -- 2.39.2