I hereby claim:
- I am tomac on github.
- I am lostinsecurity (https://keybase.io/lostinsecurity) on keybase.
- I have a public key whose fingerprint is 07CD 38E4 15D9 A3F3 4033 563E A076 8098 3DE2 51FB
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <unistd.h> | |
| #include <netinet/in.h> | |
| #include <linux/types.h> | |
| #include <linux/netfilter.h> /* for NF_ACCEPT */ | |
| #include <libnetfilter_queue/libnetfilter_queue.h> | |
| #include "latch.h" |
| import nfqueue | |
| import socket | |
| import latch | |
| q = None | |
| def cb(dummy, payload): | |
| response = api.status("ACCOUNT_ID_HERE").get_data() | |
| if response["operations"][appId]["status"] == 'on' | |
| payload.set_verdict(nfqueue.NF_DROP) |
| var options = { | |
| 'hostname': config.API_HOST.hostname, | |
| 'port': config.API_HOST.port, | |
| 'path': queryString, | |
| 'method': HTTPMethod, | |
| 'headers': headers, | |
| 'protocol': config.API_HOST.protocol | |
| }; | |
| var latchResponse = ''; |
| var authorizationHeader = config.AUTHORIZATION_METHOD + config.AUTHORIZATION_HEADER_FIELD_SEPARATOR + | |
| config.appId + config.AUTHORIZATION_HEADER_FIELD_SEPARATOR + signData(stringToSign); | |
| var headers = {}; | |
| headers[config.AUTHORIZATION_HEADER_NAME] = authorizationHeader; | |
| headers[config.DATE_HEADER_NAME] = utc; |
| notificationPort = IONotificationPortCreate(kIOMasterPortDefault); | |
| CFRunLoopAddSource(CFRunLoopGetCurrent(), IONotificationPortGetRunLoopSource(notificationPort), kCFRunLoopDefaultMode); |
| /* Para poder intentar suspender un dispositivo USB, tenemos que hacer varias cosas siendo lo primero crear un diccionario con el vendorId y productId concreto al que queremos mandar la orden de suspender, y después de usar IOServiceGetMatchingServices para encontrarlo, entonces ya podemos abrir el dispositivo y lanzar la orden */ | |
| err = IOCreatePlugInInterfaceForService(usbService, kIOUSBDeviceUserClientTypeID, kIOCFPlugInInterfaceID, | |
| &pluginInterface, &score); | |
| CHECKRETURN(err, "No se he podido crear el plugin"); | |
| if(!pluginInterface) { | |
| fprintf(stderr, "No hay interfaz de plugin\n"); | |
| return -1; | |
| } | |
| /* Busquemos ahora a ver si encontramos el interfaz USB que necesitamos */ |
| bsdName = (CFStringRef) IORegistryEntrySearchCFProperty(device | |
| , kIOServicePlane | |
| , CFSTR( kIOBSDNameKey ) | |
| , NULL | |
| , kIORegistryIterateRecursively); | |
| /* Ahora ya podemos ver si está latch activado o no para desmontar el disco */ | |
| char* bsdNameChar = malloc(CFStringGetLength(bsdName) * sizeof(char)); | |
| if (bsdNameChar) { | |
| if (CFStringGetCString(bsdName, bsdNameChar, CFStringGetLength(bsdName) +1, kCFStringEncodingASCII)) { |
| /* Obtenemos el nombre del dispositivo. Este es el nombre que suele poner el fabricante y en el caso de los discos duros | |
| * existe de todo: Flash Disk, DISK, Mass Storage, etc. OJO! No es el mismo nombre que el nombre del volumen que es el | |
| * nombre que aparece cuando montamos la unidad en el sistema operativo | |
| */ | |
| if (IORegistryEntryGetName(device, devicename) != KERN_SUCCESS) { | |
| fprintf(stderr, "%s unknown device (unable to get device name)\n", newdev ? "Added " : " Removed"); | |
| return -1; | |
| } | |
| /* Obtenemos el EntryPath, que indica dónde está en el sistema operativo |
| io_service_t usbDevice; | |
| int action = 0; | |
| while ((usbDevice = IOIteratorNext(iterator))) { | |
| get_usb_device_info(usbDevice, newdev); | |
| IOObjectRelease(usbDevice); | |
| } |