├── README.md ├── bin ├── karma └── monitor-mode.sh ├── etc ├── karma-lan.xml ├── karma-scan.xml └── karma.xml └── usr ├── sbin ├── hostapd └── hostapd_cli └── src ├── hostapd-1.0-karma.patch ├── hostapd-1.0.tar.gz └── karma-20060124.tar.gz /README.md: -------------------------------------------------------------------------------- 1 | Pineapple-Pi 2 | ============ 3 | 4 | Porting the Pineapple to the Raspberry Pi 5 | 6 | Changelog 7 | ---------- 8 | * 27-06-2013 - Added Karma 0.4 package 9 | * 25-06-2013 - Added Patched Karma Hostapd binaries 10 | -------------------------------------------------------------------------------- /bin/karma: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # 3 | # 4 | # 5 | 6 | require 'rexml/document' 7 | require File::dirname(__FILE__) + "/../modules/loader" 8 | 9 | ### 10 | # Main 11 | ### 12 | 13 | if (ARGV.length < 1) 14 | puts "usage: #{$0} " 15 | exit -1 16 | end 17 | 18 | # 19 | # Splash 20 | # 21 | puts "Starting KARMA..." 22 | 23 | Thread.abort_on_exception = true 24 | 25 | # Scan module directories for XML descriptor files when loaded 26 | Karma::ScanModules() 27 | 28 | # 29 | # Load configuration file 30 | # 31 | 32 | puts "Loading config file #{ARGV[0]}" 33 | 34 | config = REXML::Document.new(File.new(ARGV[0])) 35 | 36 | # Parse options first 37 | config.elements.each('karma/option') { |element| 38 | module_id = element.attributes['module'] 39 | option_name = element.attributes['name'] 40 | option_value = element.attributes['value'] 41 | 42 | Karma::MODULES[module_id].options[option_name] = option_value 43 | } 44 | 45 | # Run modules now 46 | config.elements.each('karma/run') { |element| 47 | module_id = element.attributes['module'] 48 | 49 | Karma::MODULES[module_id].run() 50 | } 51 | 52 | puts "Delivering judicious KARMA, hit Control-C to quit." 53 | 54 | # Wait for all threads to terminate or SIGINT 55 | trap ("SIGINT") { 56 | Karma::MODULES.each_value() {|m| 57 | m.stop() 58 | } 59 | 60 | exit(0) 61 | } 62 | sleep() # Sleep forever 63 | -------------------------------------------------------------------------------- /bin/monitor-mode.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | INTERFACE=$1 4 | 5 | if [ $# -lt 1 ]; then 6 | echo "usage: $0 " 7 | exit 1 8 | fi 9 | 10 | if [ "$OSTYPE" = "FreeBSD" ]; then 11 | ifconfig $INTERFACE down 12 | ifconfig $INTERFACE channel 1 mediaopt monitor up 13 | else 14 | # Assuming MadWiFi because the other drivers suck 15 | /sbin/ifconfig $INTERFACE down 16 | /usr/sbin/iwconfig $INTERFACE channel 1 mode monitor essid any 17 | /sbin/ifconfig $INTERFACE up 18 | fi 19 | -------------------------------------------------------------------------------- /etc/karma-lan.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 11 | 12 | 23 | -------------------------------------------------------------------------------- /etc/karma-scan.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | 11 | 12 | 20 | -------------------------------------------------------------------------------- /etc/karma.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 11 | 12 | 13 | 14 | 15 | 27 | -------------------------------------------------------------------------------- /usr/sbin/hostapd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InteliSecureLabs/Pineapple-Pi/e88002edc3d8619c031ef32e1a708790d50c00b0/usr/sbin/hostapd -------------------------------------------------------------------------------- /usr/sbin/hostapd_cli: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InteliSecureLabs/Pineapple-Pi/e88002edc3d8619c031ef32e1a708790d50c00b0/usr/sbin/hostapd_cli -------------------------------------------------------------------------------- /usr/src/hostapd-1.0-karma.patch: -------------------------------------------------------------------------------- 1 | diff -Nur hostapd-1.0/hostapd/.config hostapd-1.0-karma/hostapd/.config 2 | --- hostapd-1.0/hostapd/.config 1970-01-01 01:00:00.000000000 +0100 3 | +++ hostapd-1.0-karma/hostapd/.config 2012-08-06 16:55:02.000000000 +0100 4 | @@ -0,0 +1,246 @@ 5 | +# Example hostapd build time configuration 6 | +# 7 | +# This file lists the configuration options that are used when building the 8 | +# hostapd binary. All lines starting with # are ignored. Configuration option 9 | +# lines must be commented out complete, if they are not to be included, i.e., 10 | +# just setting VARIABLE=n is not disabling that variable. 11 | +# 12 | +# This file is included in Makefile, so variables like CFLAGS and LIBS can also 13 | +# be modified from here. In most cass, these lines should use += in order not 14 | +# to override previous values of the variables. 15 | + 16 | +# Driver interface for Host AP driver 17 | +CONFIG_DRIVER_HOSTAP=y 18 | + 19 | +# Driver interface for wired authenticator 20 | +#CONFIG_DRIVER_WIRED=y 21 | + 22 | +# Driver interface for madwifi driver 23 | +#CONFIG_DRIVER_MADWIFI=y 24 | +#CFLAGS += -I../../madwifi # change to the madwifi source directory 25 | + 26 | +# Driver interface for drivers using the nl80211 kernel interface 27 | +CONFIG_DRIVER_NL80211=y 28 | + 29 | +# Driver interface for FreeBSD net80211 layer (e.g., Atheros driver) 30 | +#CONFIG_DRIVER_BSD=y 31 | +#CFLAGS += -I/usr/local/include 32 | +#LIBS += -L/usr/local/lib 33 | +#LIBS_p += -L/usr/local/lib 34 | +#LIBS_c += -L/usr/local/lib 35 | + 36 | +# Driver interface for no driver (e.g., RADIUS server only) 37 | +#CONFIG_DRIVER_NONE=y 38 | + 39 | +# IEEE 802.11F/IAPP 40 | +CONFIG_IAPP=y 41 | + 42 | +# WPA2/IEEE 802.11i RSN pre-authentication 43 | +CONFIG_RSN_PREAUTH=y 44 | + 45 | +# PeerKey handshake for Station to Station Link (IEEE 802.11e DLS) 46 | +CONFIG_PEERKEY=y 47 | + 48 | +# IEEE 802.11w (management frame protection) 49 | +# This version is an experimental implementation based on IEEE 802.11w/D1.0 50 | +# draft and is subject to change since the standard has not yet been finalized. 51 | +# Driver support is also needed for IEEE 802.11w. 52 | +#CONFIG_IEEE80211W=y 53 | + 54 | +# Integrated EAP server 55 | +CONFIG_EAP=y 56 | + 57 | +# EAP-MD5 for the integrated EAP server 58 | +CONFIG_EAP_MD5=y 59 | + 60 | +# EAP-TLS for the integrated EAP server 61 | +CONFIG_EAP_TLS=y 62 | + 63 | +# EAP-MSCHAPv2 for the integrated EAP server 64 | +CONFIG_EAP_MSCHAPV2=y 65 | + 66 | +# EAP-PEAP for the integrated EAP server 67 | +CONFIG_EAP_PEAP=y 68 | + 69 | +# EAP-GTC for the integrated EAP server 70 | +CONFIG_EAP_GTC=y 71 | + 72 | +# EAP-TTLS for the integrated EAP server 73 | +CONFIG_EAP_TTLS=y 74 | + 75 | +# EAP-SIM for the integrated EAP server 76 | +#CONFIG_EAP_SIM=y 77 | + 78 | +# EAP-AKA for the integrated EAP server 79 | +#CONFIG_EAP_AKA=y 80 | + 81 | +# EAP-AKA' for the integrated EAP server 82 | +# This requires CONFIG_EAP_AKA to be enabled, too. 83 | +#CONFIG_EAP_AKA_PRIME=y 84 | + 85 | +# EAP-PAX for the integrated EAP server 86 | +#CONFIG_EAP_PAX=y 87 | + 88 | +# EAP-PSK for the integrated EAP server (this is _not_ needed for WPA-PSK) 89 | +#CONFIG_EAP_PSK=y 90 | + 91 | +# EAP-pwd for the integrated EAP server (secure authentication with a password) 92 | +#CONFIG_EAP_PWD=y 93 | + 94 | +# EAP-SAKE for the integrated EAP server 95 | +#CONFIG_EAP_SAKE=y 96 | + 97 | +# EAP-GPSK for the integrated EAP server 98 | +#CONFIG_EAP_GPSK=y 99 | +# Include support for optional SHA256 cipher suite in EAP-GPSK 100 | +#CONFIG_EAP_GPSK_SHA256=y 101 | + 102 | +# EAP-FAST for the integrated EAP server 103 | +# Note: Default OpenSSL package does not include support for all the 104 | +# functionality needed for EAP-FAST. If EAP-FAST is enabled with OpenSSL, 105 | +# the OpenSSL library must be patched (openssl-0.9.9-session-ticket.patch) 106 | +# to add the needed functions. 107 | +#CONFIG_EAP_FAST=y 108 | + 109 | +# Wi-Fi Protected Setup (WPS) 110 | +#CONFIG_WPS=y 111 | +# Enable WSC 2.0 support 112 | +#CONFIG_WPS2=y 113 | +# Enable UPnP support for external WPS Registrars 114 | +#CONFIG_WPS_UPNP=y 115 | + 116 | +# EAP-IKEv2 117 | +#CONFIG_EAP_IKEV2=y 118 | + 119 | +# Trusted Network Connect (EAP-TNC) 120 | +#CONFIG_EAP_TNC=y 121 | + 122 | +# PKCS#12 (PFX) support (used to read private key and certificate file from 123 | +# a file that usually has extension .p12 or .pfx) 124 | +CONFIG_PKCS12=y 125 | + 126 | +# RADIUS authentication server. This provides access to the integrated EAP 127 | +# server from external hosts using RADIUS. 128 | +#CONFIG_RADIUS_SERVER=y 129 | + 130 | +# Build IPv6 support for RADIUS operations 131 | +CONFIG_IPV6=y 132 | + 133 | +# IEEE Std 802.11r-2008 (Fast BSS Transition) 134 | +#CONFIG_IEEE80211R=y 135 | + 136 | +# Use the hostapd's IEEE 802.11 authentication (ACL), but without 137 | +# the IEEE 802.11 Management capability (e.g., madwifi or FreeBSD/net80211) 138 | +#CONFIG_DRIVER_RADIUS_ACL=y 139 | + 140 | +# IEEE 802.11n (High Throughput) support 141 | +#CONFIG_IEEE80211N=y 142 | + 143 | +# Remove debugging code that is printing out debug messages to stdout. 144 | +# This can be used to reduce the size of the hostapd considerably if debugging 145 | +# code is not needed. 146 | +#CONFIG_NO_STDOUT_DEBUG=y 147 | + 148 | +# Add support for writing debug log to a file: -f /tmp/hostapd.log 149 | +# Disabled by default. 150 | +CONFIG_DEBUG_FILE=y 151 | + 152 | +# Remove support for RADIUS accounting 153 | +#CONFIG_NO_ACCOUNTING=y 154 | + 155 | +# Remove support for RADIUS 156 | +#CONFIG_NO_RADIUS=y 157 | + 158 | +# Remove support for VLANs 159 | +#CONFIG_NO_VLAN=y 160 | + 161 | +# Enable support for fully dynamic VLANs. This enables hostapd to 162 | +# automatically create bridge and VLAN interfaces if necessary. 163 | +#CONFIG_FULL_DYNAMIC_VLAN=y 164 | + 165 | +# Remove support for dumping state into a file on SIGUSR1 signal 166 | +# This can be used to reduce binary size at the cost of disabling a debugging 167 | +# option. 168 | +#CONFIG_NO_DUMP_STATE=y 169 | + 170 | +# Enable tracing code for developer debugging 171 | +# This tracks use of memory allocations and other registrations and reports 172 | +# incorrect use with a backtrace of call (or allocation) location. 173 | +#CONFIG_WPA_TRACE=y 174 | +# For BSD, comment out these. 175 | +#LIBS += -lexecinfo 176 | +#LIBS_p += -lexecinfo 177 | +#LIBS_c += -lexecinfo 178 | + 179 | +# Use libbfd to get more details for developer debugging 180 | +# This enables use of libbfd to get more detailed symbols for the backtraces 181 | +# generated by CONFIG_WPA_TRACE=y. 182 | +#CONFIG_WPA_TRACE_BFD=y 183 | +# For BSD, comment out these. 184 | +#LIBS += -lbfd -liberty -lz 185 | +#LIBS_p += -lbfd -liberty -lz 186 | +#LIBS_c += -lbfd -liberty -lz 187 | + 188 | +# hostapd depends on strong random number generation being available from the 189 | +# operating system. os_get_random() function is used to fetch random data when 190 | +# needed, e.g., for key generation. On Linux and BSD systems, this works by 191 | +# reading /dev/urandom. It should be noted that the OS entropy pool needs to be 192 | +# properly initialized before hostapd is started. This is important especially 193 | +# on embedded devices that do not have a hardware random number generator and 194 | +# may by default start up with minimal entropy available for random number 195 | +# generation. 196 | +# 197 | +# As a safety net, hostapd is by default trying to internally collect 198 | +# additional entropy for generating random data to mix in with the data 199 | +# fetched from the OS. This by itself is not considered to be very strong, but 200 | +# it may help in cases where the system pool is not initialized properly. 201 | +# However, it is very strongly recommended that the system pool is initialized 202 | +# with enough entropy either by using hardware assisted random number 203 | +# generator or by storing state over device reboots. 204 | +# 205 | +# hostapd can be configured to maintain its own entropy store over restarts to 206 | +# enhance random number generation. This is not perfect, but it is much more 207 | +# secure than using the same sequence of random numbers after every reboot. 208 | +# This can be enabled with -e command line option. The specified 209 | +# file needs to be readable and writable by hostapd. 210 | +# 211 | +# If the os_get_random() is known to provide strong random data (e.g., on 212 | +# Linux/BSD, the board in question is known to have reliable source of random 213 | +# data from /dev/urandom), the internal hostapd random pool can be disabled. 214 | +# This will save some in binary size and CPU use. However, this should only be 215 | +# considered for builds that are known to be used on devices that meet the 216 | +# requirements described above. 217 | +#CONFIG_NO_RANDOM_POOL=y 218 | + 219 | +# Select TLS implementation 220 | +# openssl = OpenSSL (default) 221 | +# gnutls = GnuTLS 222 | +# internal = Internal TLSv1 implementation (experimental) 223 | +# none = Empty template 224 | +#CONFIG_TLS=openssl 225 | + 226 | +# TLS-based EAP methods require at least TLS v1.0. Newer version of TLS (v1.1) 227 | +# can be enabled to get a stronger construction of messages when block ciphers 228 | +# are used. 229 | +#CONFIG_TLSV11=y 230 | + 231 | +# If CONFIG_TLS=internal is used, additional library and include paths are 232 | +# needed for LibTomMath. Alternatively, an integrated, minimal version of 233 | +# LibTomMath can be used. See beginning of libtommath.c for details on benefits 234 | +# and drawbacks of this option. 235 | +#CONFIG_INTERNAL_LIBTOMMATH=y 236 | +#ifndef CONFIG_INTERNAL_LIBTOMMATH 237 | +#LTM_PATH=/usr/src/libtommath-0.39 238 | +#CFLAGS += -I$(LTM_PATH) 239 | +#LIBS += -L$(LTM_PATH) 240 | +#LIBS_p += -L$(LTM_PATH) 241 | +#endif 242 | +# At the cost of about 4 kB of additional binary size, the internal LibTomMath 243 | +# can be configured to include faster routines for exptmod, sqr, and div to 244 | +# speed up DH and RSA calculation considerably 245 | +#CONFIG_INTERNAL_LIBTOMMATH_FAST=y 246 | + 247 | +# Interworking (IEEE 802.11u) 248 | +# This can be used to enable functionality to improve interworking with 249 | +# external networks. 250 | +#CONFIG_INTERWORKING=y 251 | diff -Nur hostapd-1.0/hostapd/config_file.c hostapd-1.0-karma/hostapd/config_file.c 252 | --- hostapd-1.0/hostapd/config_file.c 2012-05-09 22:56:09.000000000 +0100 253 | +++ hostapd-1.0-karma/hostapd/config_file.c 2012-08-06 12:20:55.000000000 +0100 254 | @@ -122,6 +122,63 @@ 255 | } 256 | 257 | 258 | +// KARMA 259 | +static int hostapd_config_read_karma_ssid(const char *fname, struct hostapd_config *conf) { 260 | + FILE *f; 261 | + char buf[33], *pos; 262 | + int line = 0; 263 | + karma_ssid_t *karma_ssid; 264 | + 265 | + if (!fname) 266 | + return 0; 267 | + 268 | + f = fopen(fname, "r"); 269 | + if (!f) { 270 | + wpa_printf(MSG_ERROR, "MAC list file '%s' not found.", fname); 271 | + return -1; 272 | + } 273 | + 274 | + while (fgets(buf, sizeof(buf), f)) { 275 | + line++; 276 | + 277 | + if (buf[0] == '#') 278 | + continue; 279 | + pos = buf; 280 | + while (*pos != '\0') { 281 | + if (*pos == '\n') { 282 | + *pos = '\0'; 283 | + break; 284 | + } 285 | + pos++; 286 | + } 287 | + if (buf[0] == '\0') 288 | + continue; 289 | + 290 | + wpa_printf(MSG_DEBUG, "Found ssid in file: %s", buf); 291 | + 292 | + if (strlen (buf) > HOSTAPD_MAX_SSID_LEN) { 293 | + wpa_printf(MSG_ERROR, "ESSID too long '%s' at " 294 | + "line %d in '%s'", buf, line, fname); 295 | + fclose(f); 296 | + return -1; 297 | + } 298 | + 299 | + karma_ssid = os_malloc (sizeof (karma_ssid_t)); 300 | + karma_ssid->length = strlen(buf); 301 | + karma_ssid->ssid = os_malloc (karma_ssid->length + 1); 302 | + os_memcpy(karma_ssid->ssid, buf, strlen(buf) + 1); 303 | + karma_ssid->next = conf->karma_list; 304 | + conf->karma_list = karma_ssid; 305 | + wpa_printf(MSG_DEBUG, "CTRL_IFACE KARMA ADDED SUCCESSFULLY"); 306 | + } 307 | + 308 | + fclose(f); 309 | + 310 | + return 0; 311 | +} 312 | + 313 | +// END KARMA 314 | + 315 | static int hostapd_config_read_maclist(const char *fname, 316 | struct mac_acl_entry **acl, int *num) 317 | { 318 | @@ -1216,6 +1273,17 @@ 319 | 320 | bss = conf->last_bss = conf->bss; 321 | 322 | + // KARMA 323 | + // default Karma to off 324 | + conf->enable_karma = 0; 325 | + 326 | + // default to black list so everything is accepted 327 | + conf->karma_black_white = 1; 328 | + 329 | + // Nothing in the black/white list to start with 330 | + conf->karma_list = NULL; 331 | + // KARMA END 332 | + 333 | while (fgets(buf, sizeof(buf), f)) { 334 | bss = conf->last_bss; 335 | line++; 336 | @@ -1279,6 +1347,30 @@ 337 | bss->logger_syslog = atoi(pos); 338 | } else if (os_strcmp(buf, "logger_stdout") == 0) { 339 | bss->logger_stdout = atoi(pos); 340 | + // KARMA START 341 | + } else if (os_strcmp(buf, "karma_ssid_file") == 0) { 342 | + if (hostapd_config_read_karma_ssid (pos, conf)) 343 | + { 344 | + wpa_printf(MSG_ERROR, "Line %d: Failed to " 345 | + "read karma_ssid_file '%s'", 346 | + line, pos); 347 | + errors++; 348 | + } 349 | + } else if (os_strcmp(buf, "karma_black_white") == 0) { 350 | + int val = atoi(pos); 351 | + conf->karma_black_white = (val != 0); 352 | + if (conf->karma_black_white == 0) { 353 | + wpa_printf(MSG_DEBUG, "KARMA: White list mode"); 354 | + } else { 355 | + wpa_printf(MSG_DEBUG, "KARMA: Black list mode"); 356 | + } 357 | + } else if (os_strcmp(buf, "enable_karma") == 0) { 358 | + int val = atoi(pos); 359 | + conf->enable_karma = (val != 0); 360 | + if (conf->enable_karma) { 361 | + wpa_printf(MSG_DEBUG, "KARMA: Enabled"); 362 | + } 363 | + // KARMA END 364 | } else if (os_strcmp(buf, "dump_file") == 0) { 365 | bss->dump_log_name = os_strdup(pos); 366 | } else if (os_strcmp(buf, "ssid") == 0) { 367 | diff -Nur hostapd-1.0/hostapd/ctrl_iface.c hostapd-1.0-karma/hostapd/ctrl_iface.c 368 | --- hostapd-1.0/hostapd/ctrl_iface.c 2012-05-09 22:56:09.000000000 +0100 369 | +++ hostapd-1.0-karma/hostapd/ctrl_iface.c 2012-08-06 14:38:25.000000000 +0100 370 | @@ -39,6 +39,7 @@ 371 | #include "wps/wps_defs.h" 372 | #include "wps/wps.h" 373 | #include "ctrl_iface.h" 374 | +#include "ap/beacon.h" 375 | 376 | 377 | struct wpa_ctrl_dst { 378 | @@ -267,6 +268,170 @@ 379 | return 0; 380 | } 381 | 382 | +// KARMA START 383 | + 384 | +static int hostapd_ctrl_iface_karma_get_black_white (struct hostapd_data *hapd) 385 | +{ 386 | + wpa_printf(MSG_DEBUG, "KARMA CTRL_IFACE BLACK/WHITE QUERY (%i) x", hapd->iconf->karma_black_white); 387 | + return hapd->iconf->karma_black_white; 388 | +} 389 | +static int hostapd_ctrl_iface_karma_get_state (struct hostapd_data *hapd) 390 | +{ 391 | + wpa_printf(MSG_DEBUG, "KARMA CTRL_IFACE STATUS QUERY"); 392 | + return hapd->iconf->enable_karma; 393 | +} 394 | +static int hostapd_ctrl_iface_karma_del_ssid (struct hostapd_data *hapd, 395 | + const char *ssid) { 396 | + wpa_printf(MSG_DEBUG, "KARMA CTRL_IFACE DEL SSID %s", ssid); 397 | + 398 | + karma_ssid_t *karma_ssid; 399 | + karma_ssid_t *previous_ssid; 400 | + 401 | + if (strlen(ssid) > HOSTAPD_MAX_SSID_LEN || strlen(ssid) == 0) { 402 | + return -1; 403 | + } 404 | + 405 | + karma_ssid = hapd->iconf->karma_list; 406 | + previous_ssid = NULL; 407 | + 408 | + while (karma_ssid != NULL) { 409 | +// wpa_printf(MSG_DEBUG, "KARMA CTRL_IFACE Checking ssid %s against %s", karma_ssid->ssid, ssid); 410 | + 411 | + if (strncmp(karma_ssid->ssid, ssid, karma_ssid->length) == 0) { 412 | + wpa_printf(MSG_DEBUG, "KARMA CTRL_IFACE Match found, deleting and returning early"); 413 | + if (previous_ssid == NULL) { 414 | + hapd->iconf->karma_list = karma_ssid->next; 415 | + } else { 416 | + previous_ssid->next = karma_ssid->next; 417 | + } 418 | + os_free (karma_ssid); 419 | + return 0; 420 | + } 421 | + previous_ssid = karma_ssid; 422 | + karma_ssid = karma_ssid->next; 423 | + } 424 | + wpa_printf(MSG_DEBUG, "KARMA SCTRL_IFACE No match found"); 425 | + return 0; 426 | +} 427 | +// Used in the hostapd_ctrl_iface_karma_add_mac function to sort the MAC ACL list 428 | +static int hostapd_acl_comp(const void *a, const void *b) 429 | +{ 430 | + const struct mac_acl_entry *aa = a; 431 | + const struct mac_acl_entry *bb = b; 432 | + return os_memcmp(aa->addr, bb->addr, sizeof(macaddr)); 433 | +} 434 | + 435 | +static int hostapd_ctrl_iface_karma_add_mac (struct hostapd_data *hapd, 436 | + const char *mac, int black) { 437 | + 438 | + u8 addr[ETH_ALEN]; 439 | + struct mac_acl_entry *newacl; 440 | + struct hostapd_bss_config *bss; 441 | + char buf[128]; 442 | + struct mac_acl_entry **acl; 443 | + int *num; 444 | + // for now we don't care about VLANs so just hardcoding 0 445 | + int vlan_id = 0; 446 | + 447 | + if (hwaddr_aton(mac, addr)) { 448 | + wpa_printf(MSG_ERROR, "Invalid MAC address '%s'", buf); 449 | + return -1; 450 | + } 451 | + 452 | + bss = hapd->iconf->last_bss; 453 | + if (black) { 454 | + hostapd_ctrl_iface_deauthenticate(hapd, buf); 455 | + num = &bss->num_deny_mac; 456 | + acl = &bss->deny_mac; 457 | + } else { 458 | + num = &bss->num_accept_mac; 459 | + acl = &bss->accept_mac; 460 | + } 461 | + 462 | + newacl = os_realloc(*acl, (*num + 1) * sizeof(**acl)); 463 | + if (newacl == NULL) { 464 | + wpa_printf(MSG_ERROR, "MAC list reallocation failed"); 465 | + return -1; 466 | + } 467 | + 468 | + *acl = newacl; 469 | + os_memcpy((*acl)[*num].addr, addr, ETH_ALEN); 470 | + (*acl)[*num].vlan_id = vlan_id; 471 | + (*num)++; 472 | + 473 | + qsort(*acl, *num, sizeof(**acl), hostapd_acl_comp); 474 | + 475 | + //num = &bss->num_deny_mac; 476 | + wpa_printf(MSG_DEBUG, "There are now %i MAC addresses in the list", *num); 477 | + 478 | + return 0; 479 | +} 480 | + 481 | +static int hostapd_ctrl_iface_karma_add_ssid (struct hostapd_data *hapd, 482 | + const char *ssid) { 483 | + wpa_printf(MSG_DEBUG, "KARMA CTRL_IFACE ADD SSID %s", ssid); 484 | + 485 | + karma_ssid_t *karma_ssid; 486 | + 487 | + if (strlen(ssid) > HOSTAPD_MAX_SSID_LEN || strlen(ssid) == 0) { 488 | + return -1; 489 | + } 490 | + 491 | + karma_ssid = os_malloc (sizeof (karma_ssid_t)); 492 | + karma_ssid->length = strlen(ssid); 493 | + karma_ssid->ssid = os_malloc (karma_ssid->length + 1); 494 | + os_memcpy(karma_ssid->ssid, ssid, strlen(ssid) + 1); 495 | + karma_ssid->next = hapd->iconf->karma_list; 496 | + hapd->iconf->karma_list = karma_ssid; 497 | + wpa_printf(MSG_DEBUG, "CTRL_IFACE KARMA ADDED SUCCESSFULLY"); 498 | + return 0; 499 | +} 500 | + 501 | +static int hostapd_ctrl_iface_karma_change_ssid (struct hostapd_data *hapd, 502 | + const char *ssid) { 503 | + wpa_printf(MSG_DEBUG, "KARMA CTRL_IFACE CHANGE SSID %s", ssid); 504 | + 505 | + if (strlen(ssid) > HOSTAPD_MAX_SSID_LEN || strlen(ssid) == 0) { 506 | + return -1; 507 | + } 508 | + 509 | + hapd->conf->ssid.ssid_len = strlen(ssid); 510 | + // Not sure if the +1 is needed here or not 511 | + os_memcpy(hapd->conf->ssid.ssid, ssid, strlen(ssid) + 1); 512 | + ieee802_11_set_beacon(hapd); 513 | + wpa_printf(MSG_DEBUG, "CTRL_IFACE KARMA Default SSID Changed"); 514 | + return 0; 515 | +} 516 | + 517 | +static int hostapd_ctrl_iface_karma_black_white (struct hostapd_data *hapd, 518 | + int status) 519 | +{ 520 | + // 0 = white 521 | + if (status == 0) { 522 | + wpa_printf(MSG_DEBUG, "KARMA CTRL_IFACE White List"); 523 | + } else { 524 | + wpa_printf(MSG_DEBUG, "KARMA CTRL_IFACE Black List"); 525 | + } 526 | + hapd->iconf->karma_black_white = status; 527 | + wpa_printf(MSG_DEBUG, "KARMA CTRL_IFACE list passed in %i value %i", status, hapd->iconf->karma_black_white ); 528 | + 529 | + return 0; 530 | +} 531 | + 532 | +static int hostapd_ctrl_iface_karma_enable_disable (struct hostapd_data *hapd, 533 | + int status) 534 | +{ 535 | + if (status) { 536 | + wpa_printf(MSG_DEBUG, "KARMA CTRL_IFACE ENABLED"); 537 | + } else { 538 | + wpa_printf(MSG_DEBUG, "KARMA CTRL_IFACE DISABLED"); 539 | + } 540 | + hapd->iconf->enable_karma = status; 541 | + 542 | + return 0; 543 | +} 544 | + 545 | +// KARMA END 546 | 547 | static int hostapd_ctrl_iface_disassociate(struct hostapd_data *hapd, 548 | const char *txtaddr) 549 | @@ -942,6 +1107,80 @@ 550 | } else if (os_strncmp(buf, "GET ", 4) == 0) { 551 | reply_len = hostapd_ctrl_iface_get(hapd, buf + 4, reply, 552 | reply_size); 553 | +// KARMA 554 | + } else if (os_strcmp(buf, "KARMA_BLACK_WHITE") == 0) { 555 | + if (hostapd_ctrl_iface_karma_get_black_white(hapd)) { 556 | + os_memcpy(reply, "BLACK\n", 6); 557 | + reply_len = 6; 558 | + } else { 559 | + os_memcpy(reply, "WHITE\n", 6); 560 | + reply_len = 6; 561 | + } 562 | + } else if (os_strcmp(buf, "KARMA_STATE") == 0) { 563 | + if (hostapd_ctrl_iface_karma_get_state(hapd)) { 564 | + os_memcpy(reply, "ENABLED\n", 8); 565 | + reply_len = 8; 566 | + } else { 567 | + os_memcpy(reply, "DISABLED\n", 9); 568 | + reply_len = 9; 569 | + } 570 | + } else if (os_strncmp(buf, "KARMA_DEL_SSID ", 15) == 0) { 571 | + if (hostapd_ctrl_iface_karma_del_ssid (hapd, buf + 15)) { 572 | + reply_len = -1; 573 | + } else { 574 | + os_memcpy(reply, "DELETED\n", 8); 575 | + reply_len = 8; 576 | + } 577 | + } else if (os_strncmp(buf, "KARMA_ADD_SSID ", 15) == 0) { 578 | + if (hostapd_ctrl_iface_karma_add_ssid (hapd, buf + 15)) { 579 | + reply_len = -1; 580 | + } else { 581 | + os_memcpy(reply, "ADDED\n", 6); 582 | + reply_len = 6; 583 | + } 584 | + } else if (os_strncmp(buf, "KARMA_ADD_WHITE_MAC ", 20) == 0) { 585 | + if (hostapd_ctrl_iface_karma_add_mac (hapd, buf + 20, 0)) { 586 | + reply_len = -1; 587 | + } else { 588 | + os_memcpy(reply, "ADDED\n", 6); 589 | + reply_len = 6; 590 | + } 591 | + } else if (os_strncmp(buf, "KARMA_ADD_BLACK_MAC ", 20) == 0) { 592 | + if (hostapd_ctrl_iface_karma_add_mac (hapd, buf + 20, 1)) { 593 | + reply_len = -1; 594 | + } else { 595 | + os_memcpy(reply, "ADDED\n", 6); 596 | + reply_len = 6; 597 | + } 598 | + } else if (os_strcmp(buf, "KARMA_GET_SSID") == 0) { 599 | + wpa_printf(MSG_DEBUG, "KARMA CTRL_IFACE GET SSID"); 600 | + size_t len; 601 | + 602 | + // +2 for the new line and the null byte terminator 603 | + len = hapd->conf->ssid.ssid_len + 2; 604 | + os_snprintf(reply, len, "%s\n", hapd->conf->ssid.ssid); 605 | + reply_len = len; 606 | + 607 | + } else if (os_strncmp(buf, "KARMA_CHANGE_SSID ", 18) == 0) { 608 | + if (hostapd_ctrl_iface_karma_change_ssid (hapd, buf + 18)) { 609 | + reply_len = -1; 610 | + } else { 611 | + os_memcpy(reply, "CHANGED\n", 8); 612 | + reply_len = 8; 613 | + } 614 | + } else if (os_strcmp(buf, "KARMA_WHITE") == 0) { 615 | + if (hostapd_ctrl_iface_karma_black_white(hapd, 0)) 616 | + reply_len = -1; 617 | + } else if (os_strcmp(buf, "KARMA_BLACK") == 0) { 618 | + if (hostapd_ctrl_iface_karma_black_white(hapd, 1)) 619 | + reply_len = -1; 620 | + } else if (os_strcmp(buf, "KARMA_DISABLE") == 0) { 621 | + if (hostapd_ctrl_iface_karma_enable_disable(hapd, 0)) 622 | + reply_len = -1; 623 | + } else if (os_strcmp(buf, "KARMA_ENABLE") == 0) { 624 | + if (hostapd_ctrl_iface_karma_enable_disable(hapd, 1)) 625 | + reply_len = -1; 626 | +// END KARMA 627 | } else { 628 | os_memcpy(reply, "UNKNOWN COMMAND\n", 16); 629 | reply_len = 16; 630 | diff -Nur hostapd-1.0/hostapd/hostapd_cli.c hostapd-1.0-karma/hostapd/hostapd_cli.c 631 | --- hostapd-1.0/hostapd/hostapd_cli.c 2012-05-09 22:56:09.000000000 +0100 632 | +++ hostapd-1.0-karma/hostapd/hostapd_cli.c 2012-08-06 14:34:58.000000000 +0100 633 | @@ -21,6 +21,9 @@ 634 | #include "utils/edit.h" 635 | #include "common/version.h" 636 | 637 | +// Added this here as it is in an include file that isn't normally included 638 | +// by the cli 639 | +#define HOSTAPD_MAX_SSID_LEN 32 640 | 641 | static const char *hostapd_cli_version = 642 | "hostapd_cli v" VERSION_STR "\n" 643 | @@ -81,31 +84,44 @@ 644 | 645 | static const char *commands_help = 646 | "Commands:\n" 647 | -" mib get MIB variables (dot1x, dot11, radius)\n" 648 | -" sta get MIB variables for one station\n" 649 | -" all_sta get MIB variables for all stations\n" 650 | -" new_sta add a new station\n" 651 | +" mib get MIB variables (dot1x, dot11, radius)\n" 652 | +" sta get MIB variables for one station\n" 653 | +" all_sta get MIB variables for all stations\n" 654 | +" new_sta add a new station\n" 655 | " deauthenticate deauthenticate a station\n" 656 | -" disassociate disassociate a station\n" 657 | +" disassociate disassociate a station\n" 658 | #ifdef CONFIG_IEEE80211W 659 | -" sa_query send SA Query to a station\n" 660 | +" sa_query send SA Query to a station\n" 661 | #endif /* CONFIG_IEEE80211W */ 662 | #ifdef CONFIG_WPS 663 | " wps_pin [timeout] [addr] add WPS Enrollee PIN\n" 664 | -" wps_check_pin verify PIN checksum\n" 665 | -" wps_pbc indicate button pushed to initiate PBC\n" 666 | +" wps_check_pin verify PIN checksum\n" 667 | +" wps_pbc indicate button pushed to initiate PBC\n" 668 | #ifdef CONFIG_WPS_OOB 669 | " wps_oob use WPS with out-of-band (UFD)\n" 670 | #endif /* CONFIG_WPS_OOB */ 671 | " wps_ap_pin [params..] enable/disable AP PIN\n" 672 | " wps_config configure AP\n" 673 | #endif /* CONFIG_WPS */ 674 | -" get_config show current configuration\n" 675 | -" help show this usage help\n" 676 | -" interface [ifname] show interfaces/select interface\n" 677 | -" level change debug level\n" 678 | -" license show full hostapd_cli license\n" 679 | -" quit exit hostapd_cli\n"; 680 | +" get_config show current configuration\n" 681 | +" help show this usage help\n" 682 | +" interface [ifname] show interfaces/select interface\n" 683 | +" level change debug level\n" 684 | +" license show full hostapd_cli license\n" 685 | +" ping send a ping, get a pong\n" 686 | +" karma_change_ssid change the default SSID for when Karma is off\n" 687 | +" karma_get_ssid get the default SSID for when Karma is off\n" 688 | +" karma_enable enable Karma\n" 689 | +" karma_disable disable Karma\n" 690 | +" karma_black blacklist Karma\n" 691 | +" karma_white whitelist Karma\n" 692 | +" karma_get_black_white get the black/whitelist state of Karma\n" 693 | +" karma_add_ssid add an SSID to the black/white list\n" 694 | +" karma_del_ssid delete an SSID from the black/white list\n" 695 | +" karma_get_state get the state of Karma\n" 696 | +" karma_add_black_mac add a MAC to the black list\n" 697 | +" karma_add_white_mac add a MAC to the white list\n" 698 | +" quit exit hostapd_cli\n"; 699 | 700 | static struct wpa_ctrl *ctrl_conn; 701 | static int hostapd_cli_quit = 0; 702 | @@ -343,6 +359,129 @@ 703 | return wpa_ctrl_command(ctrl, buf); 704 | } 705 | 706 | +// KARMA 707 | + 708 | +static int hostapd_cli_cmd_karma_del_ssid(struct wpa_ctrl *ctrl, int argc, 709 | + char *argv[]) 710 | +{ 711 | + char buf[50]; 712 | + if (argc < 1) { 713 | + printf("Invalid 'delete Karma SSID' command - exactly one " 714 | + "argument, SSID, is required.\n"); 715 | + return -1; 716 | + } 717 | + os_snprintf(buf, sizeof(buf), "KARMA_DEL_SSID %s", argv[0]); 718 | + return wpa_ctrl_command(ctrl, buf); 719 | +} 720 | + 721 | +static int hostapd_cli_cmd_karma_change_ssid(struct wpa_ctrl *ctrl, int argc, 722 | + char *argv[]) 723 | +{ 724 | + // Max length of SSID is 32 chars + the command and the null byte 725 | + char buf[50]; 726 | + if (argc < 1) { 727 | + printf("Invalid 'change Karma SSID' command - exactly one " 728 | + "argument, SSID, is required.\n"); 729 | + return -1; 730 | + } 731 | + if (strlen(argv[0]) > HOSTAPD_MAX_SSID_LEN) { 732 | + printf("The max length of an SSID is %i\n", HOSTAPD_MAX_SSID_LEN); 733 | + return -1; 734 | + } 735 | + os_snprintf(buf, sizeof(buf), "KARMA_CHANGE_SSID %s", argv[0]); 736 | + return wpa_ctrl_command(ctrl, buf); 737 | +} 738 | +static int hostapd_cli_cmd_karma_get_ssid(struct wpa_ctrl *ctrl, int argc, 739 | + char *argv[]) 740 | +{ 741 | + return wpa_ctrl_command(ctrl, "KARMA_GET_SSID"); 742 | +} 743 | +static int hostapd_cli_cmd_karma_add_white_mac(struct wpa_ctrl *ctrl, int argc, 744 | + char *argv[]) 745 | +{ 746 | + // Max length of MAC is 17 chars + the command and the null byte 747 | + char buf[50]; 748 | + if (argc < 1) { 749 | + printf("Invalid 'add white MAC' command - exactly one " 750 | + "argument, MAC, is required.\n"); 751 | + return -1; 752 | + } 753 | + // Can't find a define for the length of a MAC address as a string 754 | + // ETH_ALEN is the number of individual bytes 755 | + if (strlen(argv[0]) != 17) { 756 | + printf("The MAC should be in the format 00:11:22:33:44:55\n"); 757 | + return -1; 758 | + } 759 | + os_snprintf(buf, sizeof(buf), "KARMA_ADD_WHITE_MAC %s", argv[0]); 760 | + return wpa_ctrl_command(ctrl, buf); 761 | +} 762 | + 763 | +static int hostapd_cli_cmd_karma_add_black_mac(struct wpa_ctrl *ctrl, int argc, 764 | + char *argv[]) 765 | +{ 766 | + // Max length of MAC is 17 chars + the command and the null byte 767 | + char buf[50]; 768 | + if (argc < 1) { 769 | + printf("Invalid 'add black MAC' command - exactly one " 770 | + "argument, MAC, is required.\n"); 771 | + return -1; 772 | + } 773 | + // Can't find a define for the length of a MAC address as a string 774 | + // ETH_ALEN is the number of individual bytes 775 | + if (strlen(argv[0]) != 17) { 776 | + printf("The MAC should be in the format 00:11:22:33:44:55\n"); 777 | + return -1; 778 | + } 779 | + os_snprintf(buf, sizeof(buf), "KARMA_ADD_BLACK_MAC %s", argv[0]); 780 | + return wpa_ctrl_command(ctrl, buf); 781 | +} 782 | + 783 | +static int hostapd_cli_cmd_karma_add_ssid(struct wpa_ctrl *ctrl, int argc, 784 | + char *argv[]) 785 | +{ 786 | + // Max length of SSID is 32 chars + the command and the null byte 787 | + char buf[50]; 788 | + if (argc < 1) { 789 | + printf("Invalid 'added Karma SSID' command - exactly one " 790 | + "argument, SSID, is required.\n"); 791 | + return -1; 792 | + } 793 | + if (strlen(argv[0]) > HOSTAPD_MAX_SSID_LEN) { 794 | + printf("The max length of an SSID is %i\n", HOSTAPD_MAX_SSID_LEN); 795 | + return -1; 796 | + } 797 | + os_snprintf(buf, sizeof(buf), "KARMA_ADD_SSID %s", argv[0]); 798 | + return wpa_ctrl_command(ctrl, buf); 799 | +} 800 | + 801 | +// These should be one function with a parameter 802 | + 803 | +static int hostapd_cli_cmd_karma_disable(struct wpa_ctrl *ctrl, int argc, char *argv[]) 804 | +{ 805 | + return wpa_ctrl_command(ctrl, "KARMA_DISABLE"); 806 | +} 807 | +static int hostapd_cli_cmd_karma_black(struct wpa_ctrl *ctrl, int argc, char *argv[]) 808 | +{ 809 | + return wpa_ctrl_command(ctrl, "KARMA_BLACK"); 810 | +} 811 | +static int hostapd_cli_cmd_karma_white(struct wpa_ctrl *ctrl, int argc, char *argv[]) 812 | +{ 813 | + return wpa_ctrl_command(ctrl, "KARMA_WHITE"); 814 | +} 815 | +static int hostapd_cli_cmd_karma_get_black_white(struct wpa_ctrl *ctrl, int argc, char *argv[]) 816 | +{ 817 | + return wpa_ctrl_command(ctrl, "KARMA_BLACK_WHITE"); 818 | +} 819 | +static int hostapd_cli_cmd_karma_enable(struct wpa_ctrl *ctrl, int argc, char *argv[]) 820 | +{ 821 | + return wpa_ctrl_command(ctrl, "KARMA_ENABLE"); 822 | +} 823 | +static int hostapd_cli_cmd_karma_get_state(struct wpa_ctrl *ctrl, int argc, char *argv[]) 824 | +{ 825 | + return wpa_ctrl_command(ctrl, "KARMA_STATE"); 826 | +} 827 | +// END KARMA 828 | + 829 | 830 | #ifdef CONFIG_IEEE80211W 831 | static int hostapd_cli_cmd_sa_query(struct wpa_ctrl *ctrl, int argc, 832 | @@ -757,6 +896,22 @@ 833 | { "quit", hostapd_cli_cmd_quit }, 834 | { "set", hostapd_cli_cmd_set }, 835 | { "get", hostapd_cli_cmd_get }, 836 | +// KARMA 837 | +// Because I always type ? first 838 | + { "?", hostapd_cli_cmd_help }, 839 | + { "karma_del_ssid", hostapd_cli_cmd_karma_del_ssid}, 840 | + { "karma_add_ssid", hostapd_cli_cmd_karma_add_ssid}, 841 | + { "karma_add_black_mac", hostapd_cli_cmd_karma_add_black_mac}, 842 | + { "karma_add_white_mac", hostapd_cli_cmd_karma_add_white_mac}, 843 | + { "karma_change_ssid", hostapd_cli_cmd_karma_change_ssid}, 844 | + { "karma_get_ssid", hostapd_cli_cmd_karma_get_ssid}, 845 | + { "karma_get_state", hostapd_cli_cmd_karma_get_state}, 846 | + { "karma_disable", hostapd_cli_cmd_karma_disable}, 847 | + { "karma_enable", hostapd_cli_cmd_karma_enable}, 848 | + { "karma_white", hostapd_cli_cmd_karma_white}, 849 | + { "karma_black", hostapd_cli_cmd_karma_black}, 850 | + { "karma_get_black_white", hostapd_cli_cmd_karma_get_black_white}, 851 | +// END KARMA 852 | { NULL, NULL } 853 | }; 854 | 855 | diff -Nur hostapd-1.0/hostapd/hostapd.conf hostapd-1.0-karma/hostapd/hostapd.conf 856 | --- hostapd-1.0/hostapd/hostapd.conf 2012-05-09 22:56:09.000000000 +0100 857 | +++ hostapd-1.0-karma/hostapd/hostapd.conf 2012-08-06 17:06:46.000000000 +0100 858 | @@ -1,3 +1,12 @@ 859 | +# 0 = disabled 860 | +# 1 = enabled 861 | +enable_karma=1 862 | + 863 | +# 0 = white 864 | +# 1 = black 865 | +karma_black_white=1 866 | +#karma_ssid_file=/etc/hostapd_karma_ssid 867 | + 868 | ##### hostapd configuration file ############################################## 869 | # Empty lines and lines starting with # are ignored 870 | 871 | @@ -47,9 +56,9 @@ 872 | # 4 = warning 873 | # 874 | logger_syslog=-1 875 | -logger_syslog_level=2 876 | +logger_syslog_level=0 877 | logger_stdout=-1 878 | -logger_stdout_level=2 879 | +logger_stdout_level=0 880 | 881 | # Dump file for state information (on SIGUSR1) 882 | dump_file=/tmp/hostapd.dump 883 | @@ -939,13 +948,9 @@ 884 | # in the AP). 885 | #pbc_in_m1=1 886 | 887 | -# Static access point PIN for initial configuration and adding Registrars 888 | +# Access point PIN for initial configuration and adding Registrars 889 | # If not set, hostapd will not allow external WPS Registrars to control the 890 | -# access point. The AP PIN can also be set at runtime with hostapd_cli 891 | -# wps_ap_pin command. Use of temporary (enabled by user action) and random 892 | -# AP PIN is much more secure than configuring a static AP PIN here. As such, 893 | -# use of the ap_pin parameter is not recommended if the AP device has means for 894 | -# displaying a random PIN. 895 | +# access point. 896 | #ap_pin=12345670 897 | 898 | # Skip building of automatic WPS credential 899 | @@ -1117,8 +1122,13 @@ 900 | # as the defaults for the following BSSes. However, it is recommended that all 901 | # BSSes include explicit configuration of all relevant configuration items. 902 | # 903 | -#bss=wlan0_0 904 | +#bss=wlan10 905 | #ssid=test2 906 | +#bssid=02:21:91:01:11:31 907 | +# 908 | +#bss=wlan11 909 | +#ssid=test3 910 | +#bssid=02:21:91:01:11:32 911 | # most of the above items can be used here (apart from radio interface specific 912 | # items, like channel) 913 | 914 | diff -Nur hostapd-1.0/hostapd/main.c hostapd-1.0-karma/hostapd/main.c 915 | --- hostapd-1.0/hostapd/main.c 2012-05-09 22:56:09.000000000 +0100 916 | +++ hostapd-1.0-karma/hostapd/main.c 2012-08-06 16:53:56.000000000 +0100 917 | @@ -512,7 +512,8 @@ 918 | "User space daemon for IEEE 802.11 AP management,\n" 919 | "IEEE 802.1X/WPA/WPA2/EAP/RADIUS Authenticator\n" 920 | "Copyright (c) 2002-2012, Jouni Malinen " 921 | - "and contributors\n"); 922 | + "and contributors\n" 923 | + "Karma patches by Robin Wood - robin@digininja.org\n"); 924 | } 925 | 926 | 927 | diff -Nur hostapd-1.0/src/ap/ap_config.h hostapd-1.0-karma/src/ap/ap_config.h 928 | --- hostapd-1.0/src/ap/ap_config.h 2012-05-09 22:56:09.000000000 +0100 929 | +++ hostapd-1.0-karma/src/ap/ap_config.h 2012-08-06 12:20:55.000000000 +0100 930 | @@ -364,6 +364,19 @@ 931 | }; 932 | 933 | 934 | +/* 935 | +* KARMA STUFF 936 | +* 937 | +* A structure to hold the black/white list 938 | +* 939 | +*/ 940 | +typedef struct karma_ssid{ 941 | + int length; 942 | + char *ssid; 943 | + struct karma_ssid *next; 944 | +} karma_ssid_t; 945 | +// END KARMA 946 | + 947 | /** 948 | * struct hostapd_config - Per-radio interface configuration 949 | */ 950 | @@ -371,6 +384,14 @@ 951 | struct hostapd_bss_config *bss, *last_bss; 952 | size_t num_bss; 953 | 954 | + // KARMA 955 | + int enable_karma; 956 | + // 0 = white 957 | + int karma_black_white; /* KARMA black or white list*/ 958 | + karma_ssid_t *karma_list; 959 | + 960 | + // KARMA END 961 | + 962 | u16 beacon_int; 963 | int rts_threshold; 964 | int fragm_threshold; 965 | diff -Nur hostapd-1.0/src/ap/beacon.c hostapd-1.0-karma/src/ap/beacon.c 966 | --- hostapd-1.0/src/ap/beacon.c 2012-05-09 22:56:09.000000000 +0100 967 | +++ hostapd-1.0-karma/src/ap/beacon.c 2012-08-06 17:01:34.000000000 +0100 968 | @@ -198,6 +198,11 @@ 969 | struct sta_info *sta = NULL; 970 | size_t buflen; 971 | size_t i; 972 | + // KARMA 973 | + karma_ssid_t *karma_ssid; 974 | + int found; 975 | + int free_ssid = 0; 976 | + // END KARMA 977 | 978 | ie = mgmt->u.probe_req.variable; 979 | if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req)) 980 | @@ -274,34 +279,93 @@ 981 | } 982 | #endif /* CONFIG_P2P */ 983 | 984 | - if (elems.ssid_len == 0 || 985 | - (elems.ssid_len == hapd->conf->ssid.ssid_len && 986 | - os_memcmp(elems.ssid, hapd->conf->ssid.ssid, elems.ssid_len) == 987 | - 0)) { 988 | - ssid = hapd->conf->ssid.ssid; 989 | - ssid_len = hapd->conf->ssid.ssid_len; 990 | - if (sta) 991 | - sta->ssid_probe = &hapd->conf->ssid; 992 | - } 993 | 994 | - if (!ssid) { 995 | - if (!(mgmt->da[0] & 0x01)) { 996 | + // KARMA 997 | + if (hapd->iconf->enable_karma) { 998 | + wpa_printf(MSG_MSGDUMP, "KARMA CTRL_IFACE Karam is enabled for handling probe request\n"); 999 | + // Max length for SSID is 32 chars 1000 | + if (elems.ssid_len > 0 && elems.ssid_len <= 32) { 1001 | + 1002 | + char myssid_txt[33]; 1003 | + ieee802_11_print_ssid(myssid_txt, elems.ssid, elems.ssid_len); 1004 | + 1005 | + wpa_printf(MSG_DEBUG, "KARMA CTRL_IFACE Requested ESSID is %s", myssid_txt); 1006 | + 1007 | + karma_ssid = hapd->iconf->karma_list; 1008 | + 1009 | + found = 0; 1010 | + 1011 | + while (karma_ssid != NULL) { 1012 | + wpa_printf(MSG_DEBUG, "KARMA CTRL_IFACE Checking ESSID %s against %s", karma_ssid->ssid, myssid_txt); 1013 | + 1014 | + if (strlen(myssid_txt) == karma_ssid->length && strncmp(karma_ssid->ssid, myssid_txt, karma_ssid->length) == 0) { 1015 | + wpa_printf(MSG_DEBUG, "KARMA CTRL_IFACE Match found, leaving loop"); 1016 | + found = 1; 1017 | + break; 1018 | + } 1019 | + karma_ssid = karma_ssid->next; 1020 | + } 1021 | + 1022 | + 1023 | + if (hapd->iconf->karma_black_white == 0 && found == 0) { 1024 | + // white list 1025 | + wpa_printf(MSG_MSGDUMP, "KARMA: ESSID not found in white list mode so not accepting probe"); 1026 | + return; 1027 | + } 1028 | + if (hapd->iconf->karma_black_white == 1 && found == 1) { 1029 | + // black list 1030 | + wpa_printf(MSG_MSGDUMP, "KARMA: ESSID found in black list mode so not accepting the probe"); 1031 | + return; 1032 | + } 1033 | + 1034 | + ssid = os_malloc(elems.ssid_len + 1); 1035 | + free_ssid = 1; 1036 | + 1037 | + memcpy (ssid, elems.ssid, elems.ssid_len + 1); 1038 | + ssid_len = elems.ssid_len; 1039 | + if (sta) 1040 | + sta->ssid_probe = &hapd->conf->ssid; 1041 | + } 1042 | + 1043 | + if (elems.ssid_len != 0) { 1044 | char ssid_txt[33]; 1045 | ieee802_11_print_ssid(ssid_txt, elems.ssid, 1046 | - elems.ssid_len); 1047 | - wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR 1048 | - " for foreign SSID '%s' (DA " MACSTR ")", 1049 | - MAC2STR(mgmt->sa), ssid_txt, 1050 | - MAC2STR(mgmt->da)); 1051 | + elems.ssid_len); 1052 | + wpa_printf(MSG_MSGDUMP, "KARMA: Probe Request from " MACSTR 1053 | + " for SSID '%s'", 1054 | + MAC2STR(mgmt->sa), ssid_txt); 1055 | + } 1056 | + } else { 1057 | + wpa_printf(MSG_MSGDUMP, "KARMA is disabled when handling probe request\n"); 1058 | + if (elems.ssid_len == 0 || 1059 | + (elems.ssid_len == hapd->conf->ssid.ssid_len && 1060 | + os_memcmp(elems.ssid, hapd->conf->ssid.ssid, elems.ssid_len) == 1061 | + 0)) { 1062 | + ssid = hapd->conf->ssid.ssid; 1063 | + ssid_len = hapd->conf->ssid.ssid_len; 1064 | + if (sta) 1065 | + sta->ssid_probe = &hapd->conf->ssid; 1066 | + } 1067 | + 1068 | + if (!ssid) { 1069 | + if (!(mgmt->da[0] & 0x01)) { 1070 | + char ssid_txt[33]; 1071 | + ieee802_11_print_ssid(ssid_txt, elems.ssid, 1072 | + elems.ssid_len); 1073 | + wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR 1074 | + " for foreign SSID '%s'", 1075 | + MAC2STR(mgmt->sa), ssid_txt); 1076 | + } 1077 | + return; 1078 | } 1079 | - return; 1080 | } 1081 | + // KARMA END 1082 | 1083 | #ifdef CONFIG_INTERWORKING 1084 | if (elems.interworking && elems.interworking_len >= 1) { 1085 | u8 ant = elems.interworking[0] & 0x0f; 1086 | if (ant != INTERWORKING_ANT_WILDCARD && 1087 | - ant != hapd->conf->access_network_type) { 1088 | + ant != hapd->conf->access_network_type) { 1089 | wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR 1090 | " for mismatching ANT %u ignored", 1091 | MAC2STR(mgmt->sa), ant); 1092 | @@ -310,14 +374,14 @@ 1093 | } 1094 | 1095 | if (elems.interworking && 1096 | - (elems.interworking_len == 7 || elems.interworking_len == 9)) { 1097 | + (elems.interworking_len == 7 || elems.interworking_len == 9)) { 1098 | const u8 *hessid; 1099 | if (elems.interworking_len == 7) 1100 | hessid = elems.interworking + 1; 1101 | else 1102 | hessid = elems.interworking + 1 + 2; 1103 | if (!is_broadcast_ether_addr(hessid) && 1104 | - os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) { 1105 | + os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) { 1106 | wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR 1107 | " for mismatching HESSID " MACSTR 1108 | " ignored", 1109 | @@ -427,6 +491,13 @@ 1110 | wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s " 1111 | "SSID", MAC2STR(mgmt->sa), 1112 | elems.ssid_len == 0 ? "broadcast" : "our"); 1113 | + 1114 | + // KARMA 1115 | + if (free_ssid) { 1116 | +// wpa_printf(MSG_MSGDUMP, "KARMA ssid malloc'd so free it\n"); 1117 | + os_free (ssid); 1118 | + } 1119 | + // END KARMA 1120 | } 1121 | 1122 | #endif /* NEED_AP_MLME */ 1123 | diff -Nur hostapd-1.0/src/ap/ieee802_11.c hostapd-1.0-karma/src/ap/ieee802_11.c 1124 | --- hostapd-1.0/src/ap/ieee802_11.c 2012-05-09 22:56:09.000000000 +0100 1125 | +++ hostapd-1.0-karma/src/ap/ieee802_11.c 2012-08-06 12:24:27.000000000 +0100 1126 | @@ -520,18 +520,28 @@ 1127 | if (ssid_ie == NULL) 1128 | return WLAN_STATUS_UNSPECIFIED_FAILURE; 1129 | 1130 | - if (ssid_ie_len != hapd->conf->ssid.ssid_len || 1131 | - os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) { 1132 | + // KARMA 1133 | + if (hapd->iconf->enable_karma) { 1134 | char ssid_txt[33]; 1135 | ieee802_11_print_ssid(ssid_txt, ssid_ie, ssid_ie_len); 1136 | - hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, 1137 | - HOSTAPD_LEVEL_INFO, 1138 | - "Station tried to associate with unknown SSID " 1139 | - "'%s'", ssid_txt); 1140 | - return WLAN_STATUS_UNSPECIFIED_FAILURE; 1141 | - } 1142 | + wpa_printf(MSG_MSGDUMP, "KARMA: Checking SSID for start of association, pass through %s", ssid_txt); 1143 | 1144 | - return WLAN_STATUS_SUCCESS; 1145 | + return WLAN_STATUS_SUCCESS; 1146 | + } else { 1147 | + if (ssid_ie_len != hapd->conf->ssid.ssid_len || 1148 | + os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) { 1149 | + char ssid_txt[33]; 1150 | + ieee802_11_print_ssid(ssid_txt, ssid_ie, ssid_ie_len); 1151 | + hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, 1152 | + HOSTAPD_LEVEL_INFO, 1153 | + "Station tried to associate with unknown SSID " 1154 | + "'%s'", ssid_txt); 1155 | + return WLAN_STATUS_UNSPECIFIED_FAILURE; 1156 | + } 1157 | + 1158 | + return WLAN_STATUS_SUCCESS; 1159 | + } 1160 | + // KARMA END 1161 | } 1162 | 1163 | 1164 | @@ -1523,6 +1533,21 @@ 1165 | * step. 1166 | */ 1167 | ap_sta_set_authorized(hapd, sta, 1); 1168 | + 1169 | + // KARMA 1170 | + // Print that it has associated and give the MAC and AP 1171 | + // Doesn't currently work though as can't find ESSID 1172 | + if (hapd->iconf->enable_karma) { 1173 | + // This gives the ESSID of the AP and not the one from the probe. 1174 | + //struct hostapd_ssid *ssid = sta->ssid; 1175 | + 1176 | + // printf("KARMA: Successful association of " MACSTR " to ESSID '%s'\n", 1177 | + // MAC2STR(mgmt->da), ssid->ssid); 1178 | + printf("KARMA: Successful association of " MACSTR "\n", 1179 | + MAC2STR(mgmt->da)); 1180 | + } 1181 | + 1182 | + // KARMA END 1183 | } 1184 | 1185 | if (reassoc) 1186 | diff -Nur hostapd-1.0/src/crypto/random.c hostapd-1.0-karma/src/crypto/random.c 1187 | --- hostapd-1.0/src/crypto/random.c 2012-05-09 22:56:09.000000000 +0100 1188 | +++ hostapd-1.0-karma/src/crypto/random.c 2012-08-06 12:20:55.000000000 +0100 1189 | @@ -134,8 +134,8 @@ 1190 | static unsigned int count = 0; 1191 | 1192 | count++; 1193 | - wpa_printf(MSG_MSGDUMP, "Add randomness: count=%u entropy=%u", 1194 | - count, entropy); 1195 | + //wpa_printf(MSG_MSGDUMP, "Add randomness: count=%u entropy=%u", 1196 | + // count, entropy); 1197 | if (entropy > MIN_COLLECT_ENTROPY && (count & 0x3ff) != 0) { 1198 | /* 1199 | * No need to add more entropy at this point, so save CPU and 1200 | -------------------------------------------------------------------------------- /usr/src/hostapd-1.0.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InteliSecureLabs/Pineapple-Pi/e88002edc3d8619c031ef32e1a708790d50c00b0/usr/src/hostapd-1.0.tar.gz -------------------------------------------------------------------------------- /usr/src/karma-20060124.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InteliSecureLabs/Pineapple-Pi/e88002edc3d8619c031ef32e1a708790d50c00b0/usr/src/karma-20060124.tar.gz --------------------------------------------------------------------------------