From 30300843e0c66ca3eefa97f5787f95b07c256d2f Mon Sep 17 00:00:00 2001 From: Epoch Qwert Date: Sun, 23 Nov 2014 14:25:42 -0600 Subject: fixed gitignore. >_> added a bunch of new piddly shit. --- .gitignore | 4 +- nocompile/bin/elapsedtime | 18 +++++++++ nocompile/bin/unescape | 7 ++++ nocompile/bin/what | 9 +++++ nocompile/libexec/gopherd.sh | 4 +- src/bin/filemon.c | 72 +++++++++++++++++++++++++++++++++++ src/bin/ipconvert.c | 8 ++++ src/bin/rrd.c | 91 ++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 209 insertions(+), 4 deletions(-) create mode 100755 nocompile/bin/elapsedtime create mode 100755 nocompile/bin/unescape create mode 100755 nocompile/bin/what create mode 100644 src/bin/filemon.c create mode 100644 src/bin/ipconvert.c create mode 100644 src/bin/rrd.c diff --git a/.gitignore b/.gitignore index 867ebf8..c1c61b8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -bin -libexec +./bin +./libexec diff --git a/nocompile/bin/elapsedtime b/nocompile/bin/elapsedtime new file mode 100755 index 0000000..3d26597 --- /dev/null +++ b/nocompile/bin/elapsedtime @@ -0,0 +1,18 @@ +#!/bin/sh +if [ "_$1" != "_" ];then + time=$1 +else + read time +fi + +partials=$(echo $time | cut -d. -f2) +wholes=$(echo $time | cut -d. -f1) +seconds=$(( wholes % 60 )) +minutes=$(( wholes/60 % 60 )) +hours=$(( wholes/60/60 % 24 )) +days=$(( wholes/60/60/24 % 7 )) +weeks=$(( wholes/60/60/24/7 )) +echo $weeks weeks $days days $hours:$minutes:$seconds.$partials +if read time;then + elapsedtime $time +fi diff --git a/nocompile/bin/unescape b/nocompile/bin/unescape new file mode 100755 index 0000000..c3cac84 --- /dev/null +++ b/nocompile/bin/unescape @@ -0,0 +1,7 @@ +#!/bin/sh +if [ "_$1" != "_" ];then + l="$1" +else + read l +fi +printf "$(echo "$l" | sed "s/%/\\\\x/g")" diff --git a/nocompile/bin/what b/nocompile/bin/what new file mode 100755 index 0000000..154dcc7 --- /dev/null +++ b/nocompile/bin/what @@ -0,0 +1,9 @@ +#!/bin/bash +cd /usr/local/share/answers/what +cd $1 +while shift 2>/dev/null;do + if [ "$1" ];then + echo $1 | sed "s/[^a-zA-Z0-9]//g" | xargs echo + fi +done +cat _ diff --git a/nocompile/libexec/gopherd.sh b/nocompile/libexec/gopherd.sh index e50b129..768d02b 100755 --- a/nocompile/libexec/gopherd.sh +++ b/nocompile/libexec/gopherd.sh @@ -1,5 +1,5 @@ #!/bin/bash -#I'm aware of the LFI. Have fun looking around my server. +#set these two variables if you have your server behind DMZ read -t 10 req base="$1" req=$(echo "$req" | tr -d '\r') @@ -10,7 +10,7 @@ if grep -v "^${base}" <<< "${realpath}" > /dev/null;then exit 1 fi myIP=$(/usr/local/bin/hop0 $(/usr/local/libexec/peerip)) -hostname=$(dig -x ${myIP} +short | rev | tail -c+2 | rev ) +hostname=$(dig -x ${myIP} +short | head -n1 | rev | tail -c+2 | rev ) if [ ! "${hostname}" ]; then hostname=${myIP} else diff --git a/src/bin/filemon.c b/src/bin/filemon.c new file mode 100644 index 0000000..6930673 --- /dev/null +++ b/src/bin/filemon.c @@ -0,0 +1,72 @@ +//ripped from the netbsd man page for kqueue +//and modified very slightly. +//I'll add some more stuff as I find a use for it. + #include + #include + #include + #include + #include + #include + #include + #include + + int + main(int argc, char *argv[]) + { + int fd, kq, nev; + struct kevent ev; + static const struct timespec tout = { 1, 0 }; + + if ((fd = open(argv[1], O_RDONLY)) == -1) + err(1, "Cannot open `%s'", argv[1]); + + if ((kq = kqueue()) == -1) + err(1, "Cannot create kqueue"); + + EV_SET(&ev, fd, EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_CLEAR, + NOTE_DELETE|NOTE_WRITE|NOTE_EXTEND|NOTE_ATTRIB|NOTE_LINK| + NOTE_RENAME|NOTE_REVOKE, 0, 0); + if (kevent(kq, &ev, 1, NULL, 0, &tout) == -1) + err(1, "kevent"); + for (;;) { + nev = kevent(kq, NULL, 0, &ev, 1, &tout); + if (nev == -1) + err(1, "kevent"); + if (nev == 0) + continue; + if (ev.fflags & (NOTE_DELETE|NOTE_WRITE|NOTE_EXTEND|NOTE_ATTRIB|NOTE_LINK|NOTE_RENAME|NOTE_REVOKE)) { + printf("%s: ",argv[1]); + } + if (ev.fflags & NOTE_DELETE) { + printf("deleted "); + ev.fflags &= ~NOTE_DELETE; + } + if (ev.fflags & NOTE_WRITE) { + printf("written "); + ev.fflags &= ~NOTE_WRITE; + } + if (ev.fflags & NOTE_EXTEND) { + printf("extended "); + ev.fflags &= ~NOTE_EXTEND; + } + if (ev.fflags & NOTE_ATTRIB) { + printf("chmod/chown/utimes "); + ev.fflags &= ~NOTE_ATTRIB; + } + if (ev.fflags & NOTE_LINK) { + printf("hardlinked "); + ev.fflags &= ~NOTE_LINK; + } + if (ev.fflags & NOTE_RENAME) { + printf("renamed "); + ev.fflags &= ~NOTE_RENAME; + } + if (ev.fflags & NOTE_REVOKE) { + printf("revoked "); + ev.fflags &= ~NOTE_REVOKE; + } + printf("\n"); + if (ev.fflags) + warnx("unknown event 0x%x\n", ev.fflags); + } + } diff --git a/src/bin/ipconvert.c b/src/bin/ipconvert.c new file mode 100644 index 0000000..5420e27 --- /dev/null +++ b/src/bin/ipconvert.c @@ -0,0 +1,8 @@ +#include + +int main(int argc,char *argv[]) { + int addr=inet_addr(argv[1]); + printf("%x\n",htonl(addr)); + printf("%u\n",htonl(addr)); + printf("%u.%u.%u.%u\n",addr&255,addr>>8&255,addr>>16&255,addr>>24&255); +} diff --git a/src/bin/rrd.c b/src/bin/rrd.c new file mode 100644 index 0000000..bbb907d --- /dev/null +++ b/src/bin/rrd.c @@ -0,0 +1,91 @@ +#include +#include +#include + +#include +#include + +/* +mostly ripped. just outputs routes from KRT on NetBSD. +used to look closer at a difference of output from route and netstat. +*/ + +get_rtaddrs(int addrs, struct sockaddr *sa, struct sockaddr **rti_info) +{ + int i; + + for (i = 0; i < RTAX_MAX; i++) { + if (addrs & (1 << i)) { + rti_info[i] = sa; + sa = (struct sockaddr *)((char *)(sa) + + RT_ROUNDUP(sa->sa_len)); + } else + rti_info[i] = NULL; + } +} + + +void print_sa6(struct sockaddr *sa) { + int i=0; + struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)sa; + struct in6_addr *in6 = &sa6->sin6_addr; + if(sa) { + for(i=0;i<16;i++) { + printf("%02x",(unsigned char)in6->s6_addr[i]); + i++; + printf("%02x",(unsigned char)in6->s6_addr[i]); + if(i != 15) printf(":"); + } + } else { + printf("none"); + } + printf("\n"); +} + +void p_rtentry(struct rt_msghdr *rtm) { + struct sockadrr *sa = (struct sockaddr *)(rtm+1); + struct sockaddr *rti_info[RTAX_MAX]; + struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)sa; + struct in6_addr *in6 = &sa6->sin6_addr; + get_rtaddrs(rtm->rtm_addrs, sa, rti_info); + + printf("addr: "); + print_sa6(rti_info[RTAX_DST]); + printf("mask: "); + print_sa6(rti_info[RTAX_NETMASK]); + printf("gate: "); + print_sa6(rti_info[RTAX_GATEWAY]); + printf("\n"); +} + +int main() { +// sysctl(const int *name, u_int namelen, void *oldp, size_t *oldlenp, +// const void *newp, size_t newlen); + int needed; + struct rt_msghdr *rtm; + struct sockaddr *sa; + char *buf,*next,*lim; + int mib[6]; + mib[0]=CTL_NET; + mib[1]=PF_ROUTE; + mib[2]=0; + mib[3]=AF_INET6; + mib[4]=NET_RT_DUMP; + mib[5]=0; + sysctl(mib,6,NULL,&needed,NULL,0); + buf=malloc(needed); + sysctl(mib,6,buf,&needed,NULL,0); + lim=buf+needed; + if (buf) { + for (next = buf; next < lim; next += rtm->rtm_msglen) { + rtm = (struct rt_msghdr *)next; + sa = (struct sockaddr *)(rtm + 1); + if (sa->sa_family != AF_INET6) + continue; + p_rtentry(rtm); + } + free(buf); + buf = NULL; + } + +} -- cgit v1.2.3