summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulian Daube2018-02-12 15:39:30 +0100
committerJulian Daube2018-02-12 15:39:30 +0100
commit0482ce891c56a8631d6f48af5467fbdb40dcaa83 (patch)
tree92b88a571679c7c308c9e4e1830f6cda4e6e4893
downloadaur-0482ce891c56a8631d6f48af5467fbdb40dcaa83.tar.gz
initial commit (v1.0.1)
-rw-r--r--.SRCINFO13
-rw-r--r--Makefile7
-rw-r--r--PKGBUILD25
-rw-r--r--ioctl_preload.64b.c90
4 files changed, 135 insertions, 0 deletions
diff --git a/.SRCINFO b/.SRCINFO
new file mode 100644
index 000000000000..c8e997f6e220
--- /dev/null
+++ b/.SRCINFO
@@ -0,0 +1,13 @@
+# Generated by mksrcinfo v8
+# Mon Feb 12 14:32:54 UTC 2018
+pkgbase = libmacspoof
+ pkgver = 1.0.1
+ pkgrel = 1
+ arch = any
+ source = ioctl_preload.64b.c
+ source = Makefile
+ md5sums = SKIP
+ md5sums = SKIP
+
+pkgname = libmacspoof
+
diff --git a/Makefile b/Makefile
new file mode 100644
index 000000000000..de080a597672
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,7 @@
+
+all:
+ @#gcc -fPIC -rdynamic -g -c -Wall ioctl_preload.c
+ gcc -shared -fPIC -Wl,-soname,libmacspoof.so.1 -o libmacspoof.so.1.0.1 ioctl_preload.64b.c -lc -ldl
+
+clean:
+ rm -f libmacspoof.so.1.0.1
diff --git a/PKGBUILD b/PKGBUILD
new file mode 100644
index 000000000000..96f35cc83148
--- /dev/null
+++ b/PKGBUILD
@@ -0,0 +1,25 @@
+# : Julian Daube <joposter at gmail.com>
+# Maintainer : Julian Daube <joposter at gmail.com>
+
+pkgname=libmacspoof
+pkgver=1.0.1
+pkgrel=1
+pkgdesc=A simple library to preload for spoofing the mac address
+
+source=("ioctl_preload.64b.c"
+ "Makefile")
+md5sums=('23341bdb5ca2d928d67ba8cf1e3c9ada'
+ '5cf8006342e32d40e86217a4fc444832')
+arch=("any")
+makedeps=("make")
+depends=()
+url="http://fringe.davesource.com/Fringe/Hacking/Hacks/MAC_Spoofing/"
+
+function build() {
+ make
+}
+
+function package() {
+ mkdir -p "$pkgdir/usr/lib/"
+ install libmacspoof.so.1.0.1 -m664 "$pkgdir/usr/lib/libmacspoof.so.1.0.1"
+}
diff --git a/ioctl_preload.64b.c b/ioctl_preload.64b.c
new file mode 100644
index 000000000000..68f1c76d6348
--- /dev/null
+++ b/ioctl_preload.64b.c
@@ -0,0 +1,90 @@
+/*
+ * Spoof a MAC address with LD_PRELOAD
+ *
+ * If environment variable $MAC_ADDRESS is set in the form "01:02:03:04:05:06"
+ * then use that value, otherwise pass through unchanged.
+ *
+ * Bugs: This currently spoofs MAC addresses for *all* interfaces.
+ * It would be better to watch calls to socket() for the interfaces
+ * you want and then only spoof ioctl calls to that file descriptor.
+ *
+ * Updated by Ed Avis for:
+ * + 64-bit (needs -fPIC for compilation)
+ * + Passes actual MAC address if env var unset (instead of hardcoded)
+ * + More validation and sanity checking on env var
+ *
+ * (Untested by MarginalHacks.com)
+ */
+#include <dlfcn.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#ifndef RTLD_NEXT
+#define RTLD_NEXT ((void *) -1l)
+#endif
+
+#define SIOCGIFHWADDR 0x8927
+
+const char *ENV_VAR = "MAC_ADDRESS";
+const size_t EXPECTED_LEN = 17;
+
+int
+ioctl(int d, int request, unsigned char *argp)
+{
+ static void *handle = NULL;
+ static int (*orig_ioctl)(int, int, char*);
+ int ret;
+ char *p;
+
+ // If this var isn't set, leave alone.
+ p=getenv(ENV_VAR);
+
+ if (handle == NULL) {
+ char *error;
+ orig_ioctl = dlsym(RTLD_NEXT, "ioctl");
+ if ((error = dlerror()) != NULL) {
+ fprintf(stderr, "%s\n", error);
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ ret = orig_ioctl(d, request, argp);
+
+ if (p && strlen(p) && strlen(p) != EXPECTED_LEN) {
+ fprintf(stderr, "malformed %s environment variable, expected length %d, got length %d from '%s'\n",
+ ENV_VAR, EXPECTED_LEN, strlen(p), p);
+ exit(EXIT_FAILURE);
+ }
+
+ if (p && strlen(p) && request == SIOCGIFHWADDR) {
+ unsigned char *ptr = argp + 18;
+ int i;
+ for (i=0; i < 6; i++) {
+ int val = 0;
+ if (p[0]>='0' && p[0]<='9') val |= (p[0]-'0')<<4;
+ else if (p[0]>='a' && p[0]<='f') val |= (p[0]-'a'+10)<<4;
+ else if (p[0]>='A' && p[0]<='F') val |= (p[0]-'A'+10)<<4;
+ else {
+ fprintf(stderr, "bad character '%c' in %s environment variable - expected hex digit\n", p[0], ENV_VAR);
+ exit(EXIT_FAILURE);
+ }
+ if (p[1]>='0' && p[1]<='9') val |= p[1]-'0';
+ else if (p[1]>='a' && p[1]<='f') val |= p[1]-'a'+10;
+ else if (p[1]>='A' && p[1]<='F') val |= p[1]-'A'+10;
+ else {
+ fprintf(stderr, "bad character '%c' in %s environment variable - expected hex digit\n", p[1], ENV_VAR);
+ exit(EXIT_FAILURE);
+ }
+ if (p[2]!=':' && p[2]!='\0') {
+ fprintf(stderr, "bad character '%c' in %s environment variable - expected : or end of string\n", p[2], ENV_VAR);
+ exit(EXIT_FAILURE);
+ }
+ ptr[i] = val;
+ p+=3;
+ }
+ }
+ return ret;
+}
+
+