pax_global_header00006660000000000000000000000064140504445330014514gustar00rootroot0000000000000052 comment=cda590b1e9aac6c148e031324ad623e1914e7995 hcxkeys-6.2.0/000077500000000000000000000000001405044453300131775ustar00rootroot00000000000000hcxkeys-6.2.0/.gitignore000066400000000000000000000000401405044453300151610ustar00rootroot00000000000000wlangenpmk wlangenpmkocl pwhash hcxkeys-6.2.0/Makefile000077500000000000000000000025231405044453300146440ustar00rootroot00000000000000PRODUCTION := 1 PRODUCTION_VERSION := 6.2.0 PRODUCTION_YEAR := 2021 ifeq ($(PRODUCTION),1) VERSION_TAG := $(PRODUCTION_VERSION) else VERSION_TAG := $(shell git describe --tags || echo $(PRODUCTION_VERSION)) endif VERSION_YEAR := $(shell echo $(PRODUCTION_YEAR)) PREFIX ?=/usr/local INSTALLDIR = $(DESTDIR)$(PREFIX)/bin HOSTOS := $(shell uname -s) CC = gcc CFLAGS ?= -O3 -Wall -Wextra CFLAGS += -std=gnu99 DEFS = -DVERSION_TAG=\"$(VERSION_TAG)\" -DVERSION_YEAR=\"$(VERSION_YEAR)\" INSTFLAGS = -m 0755 ifeq ($(HOSTOS), Linux) INSTFLAGS += -D endif ifeq ($(HOSTOS), Darwin) CFLAGS += -L/usr/local/opt/openssl/lib -I/usr/local/opt/openssl/include endif all: build build: $(CC) $(CFLAGS) $(CPPFLAGS) $(DEFS) -o wlangenpmk wlangenpmk.c -lcrypto $(LDFLAGS) ifeq ($(HOSTOS), Darwin) $(CC) $(CFLAGS) $(CPPFLAGS) $(DEFS) -o wlangenpmkocl wlangenpmkocl.c -lcrypto -Wl,-framework,OpenCL -lm $(LDFLAGS) else $(CC) $(CFLAGS) $(CPPFLAGS) $(DEFS) -o wlangenpmkocl wlangenpmkocl.c -lcrypto -lOpenCL $(LDFLAGS) endif install: build install $(INSTFLAGS) wlangenpmk $(INSTALLDIR)/wlangenpmk install $(INSTFLAGS) wlangenpmkocl $(INSTALLDIR)/wlangenpmkocl rm -f wlangenpmk rm -f wlangenpmkocl rm -f pwhash rm -f *.o *~ clean: rm -f wlangenpmk rm -f wlangenpmkocl rm -f *.o *~ uninstall: rm -f $(INSTALLDIR)/wlangenpmk rm -f $(INSTALLDIR)/wlangenpmkocl hcxkeys-6.2.0/README.md000066400000000000000000000030461405044453300144610ustar00rootroot00000000000000hcxkeys ============== Small set of tools to generate plainmasterkeys (rainbowtables) and hashes for the use with latest hashcat and latest John the Ripper. Brief description -------------- Multiple stand-alone binaries. All of these utils are designed to execute only one specific function. Read this post: hcxtools - solution for capturing wlan traffic and conversion to hashcat formats (https://hashcat.net/forum/thread-6661.html) Detailed description -------------- | Tool | Description | | -------------- | ---------------------------------------------------------------------------------------------------- | | wlangenpmk | Generates plainmasterkeys (CPU) from essid and password for use with hashcat hash-mode 2501 | | wlangenpmkocl | Generates plainmasterkeys (GPU) from essid and password for use with hashcat hash-mode 2501 | | pwhash | Generate hash of a word by using a given charset | Compile -------------- Simply run: ``` make make install (as super user) ``` Requirements -------------- * Linux (recommended Arch, but other distros should work, too) * gcc 10 recommended (deprecated versions are not supported: https://gcc.gnu.org/) * OpenCL and OpenCL Headers installed * libopenssl and openssl-dev installed * librt and librt-dev installed (should be installed by default) Notice -------------- Most output files will be appended to existing files. hcxkeys-6.2.0/changelog000066400000000000000000000002731405044453300150530ustar00rootroot0000000000000017.05.2021 ========== release v6.2.0 get ready for gcc 11.1.0 11.02.2021 ========== removed pwhash because all functions are provided by openssl 01.05.2020 ========== added changelog hcxkeys-6.2.0/include/000077500000000000000000000000001405044453300146225ustar00rootroot00000000000000hcxkeys-6.2.0/include/common.c000066400000000000000000000132431405044453300162610ustar00rootroot00000000000000#define _GNU_SOURCE #include #include #include #define PW_MAX 64 /*===========================================================================*/ uint32_t rotl32(uint32_t a, uint32_t n) { return((a << n) | (a >> (32 - n))); } /*===========================================================================*/ uint64_t rotl64(uint64_t a, uint64_t n) { return ((a << n) | (a >> (64 - n))); } /*===========================================================================*/ uint32_t rotr32(uint32_t a, uint32_t n) { return ((a >> n) | (a << (32 - n))); } /*===========================================================================*/ uint64_t rotr64(uint64_t a, uint64_t n) { return ((a >> n) | (a << (64 - n))); } /*===========================================================================*/ uint16_t byte_swap_16 (uint16_t n) { return (n & 0xff00) >> 8 | (n & 0x00ff) << 8; } /*===========================================================================*/ uint32_t byte_swap_32(int32_t n) { #if defined (__clang__) || defined (__GNUC__) return __builtin_bswap32 (n); #else return(n & 0xff000000) >> 24 | (n & 0x00ff0000) >> 8 | (n & 0x0000ff00) << 8 | (n & 0x000000ff) << 24; #endif } /*===========================================================================*/ uint64_t byte_swap_64(uint64_t n) { #if defined (__clang__) || defined (__GNUC__) return __builtin_bswap64 (n); #else return (n & 0xff00000000000000ULL) >> 56 | (n & 0x00ff000000000000ULL) >> 40 | (n & 0x0000ff0000000000ULL) >> 24 | (n & 0x000000ff00000000ULL) >> 8 | (n & 0x00000000ff000000ULL) << 8 | (n & 0x0000000000ff0000ULL) << 24 | (n & 0x000000000000ff00ULL) << 40 | (n & 0x00000000000000ffULL) << 56; #endif } /*===========================================================================*/ /*===========================================================================*/ void uint8t2hex_lower(uint8_t v, uint8_t hex[2]) { const uint8_t tbl[0x10] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; hex[1] = tbl[(v >> 0) &0xf]; hex[0] = tbl[(v >> 4) &0xf]; return; } /*===========================================================================*/ void do_hexify (uint8_t *buf, int len, uint8_t *out) { int max_len = (len >= PW_MAX) ? PW_MAX : len; for(int i = max_len - 1, j = i * 2; i >= 0; i -= 1, j -= 2) { uint8t2hex_lower(buf[i], out + j); } out[max_len *2] = 0; return; } /*===========================================================================*/ void do_full_hexify (uint8_t *buf, int len, uint8_t *out) { int max_len = (len >= PW_MAX) ? PW_MAX : len; out[0] = '$'; out[1] = 'H'; out[2] = 'E'; out[3] = 'X'; out[4] = '['; out += 5; for (int i = max_len - 1, j = i * 2; i >= 0; i -= 1, j -= 2) { uint8t2hex_lower(buf[i], out + j); } out[max_len *2] = ']'; out[max_len *2 +1] = 0; return; } /*===========================================================================*/ uint8_t hex_convert(uint8_t c) { return (c & 0xf) + (c >> 6) * 9; } /*===========================================================================*/ uint8_t hex2uint8t(uint8_t hex[2]) { uint8_t v = 0; v |= ((uint8_t)hex_convert(hex[1]) << 0); v |= ((uint8_t)hex_convert(hex[0]) << 4); return (v); } /*===========================================================================*/ bool is_valid_hex_char(uint8_t c) { if((c >= '0') && (c <= '9')) return true; if((c >= 'A') && (c <= 'F')) return true; if((c >= 'a') && (c <= 'f')) return true; return false; } /*===========================================================================*/ bool is_valid_hex_string(uint8_t *s, int len) { if((len %2) != 0) return false; for(int i = 0; i < len; i++) if (is_valid_hex_char(s[i]) == false) return false; return true; } /*===========================================================================*/ int do_unhexify(uint8_t *in_buf, int in_len, uint8_t *out_buf, int out_size) { int i, j; uint8_t c; for(i = 0, j = 5; j < in_len -1; i += 1, j += 2) { c = hex2uint8t(&in_buf[j]); out_buf[i] = c; } memset(out_buf + i, 0, out_size -i); return (i); } /*===========================================================================*/ bool is_hexify(uint8_t *in_buf, int len) { if(len < 6) return false; // $HEX[] = 6 if(in_buf[0] != '$') return false; if(in_buf[1] != 'H') return false; if(in_buf[2] != 'E') return false; if(in_buf[3] != 'X') return false; if(in_buf[4] != '[') return false; if(in_buf[len - 1] != ']') return false; if(is_valid_hex_string(in_buf +5, len -6) == false) return false; return true; } /*===========================================================================*/ bool is_printable_ascii (uint8_t *in_buf, int len) { for(int i = 0; i < len; i++) { if(in_buf[i] < 0x20) return false; if(in_buf[i] > 0x7e) return false; } return true; } /*===========================================================================*/ bool need_hexify(uint8_t *in_buf, int len) { if(is_printable_ascii(in_buf, len) == false) return true; return false; } /*===========================================================================*/ int mystrlen(uint8_t *in_buf) { int c = 0; while(in_buf[c] != 0) c++; return c; } /*===========================================================================*/ int countdelimiter(uint8_t *in_buf, char delimiter) { int c = 0; int d = 0; while(in_buf[c] != 0) { if(in_buf[c] == delimiter) d++; c++; } return d; } /*===========================================================================*/ int getdelimiterpos(uint8_t *in_buf, char delimiter) { int c = 0; while(in_buf[c] != 0) { if(in_buf[c] == delimiter) return c; c++; } return c; } /*===========================================================================*/ hcxkeys-6.2.0/include/common.h000066400000000000000000000341031405044453300162640ustar00rootroot00000000000000#if !defined(FALSE) #define FALSE 0 #endif #if !defined(TRUE) #define TRUE 1 #endif #define NEWENTY -1 #define HCCAPX_SIGNATURE 0x58504348 #define HCCAPX_VERSION 4 #define MAC_SIZE_ACK (10) #define MAC_SIZE_RTS (16) #define MAC_SIZE_NORM (24) #define MAC_SIZE_QOS (26) #define MAC_SIZE_LONG (30) #define MAC_TYPE_MGMT 0x0 #define MAC_TYPE_CTRL 0x1 #define MAC_TYPE_DATA 0x2 #define MAC_TYPE_RSVD 0x3 // management subtypes #define MAC_ST_ASSOC_REQ 0x0 #define MAC_ST_ASSOC_RESP 0x1 #define MAC_ST_REASSOC_REQ 0x2 #define MAC_ST_REASSOC_RESP 0x3 #define MAC_ST_PROBE_REQ 0x4 #define MAC_ST_PROBE_RESP 0x5 #define MAC_ST_BEACON 0x8 #define MAC_ST_DISASSOC 0xA #define MAC_ST_AUTH 0xB #define MAC_ST_DEAUTH 0xC #define MAC_ST_ACTION 0xD // data subtypes #define MAC_ST_DATA 0x0 #define MAC_ST_NULL 0x4 #define MAC_ST_QOSNULL 0xC #define MAC_ST_QOSDATA 0x8 // control subtypes #define MAC_ST_BACK_REQ 0x8 #define MAC_ST_BACK 0x9 #define MAC_ST_RTS 0xB #define MAC_ST_CTS 0xC #define MAC_ST_ACK 0xD /* Reason codes (IEEE 802.11-2007, 7.3.1.7, Table 7-22) */ #define WLAN_REASON_UNSPECIFIED 1 #define WLAN_REASON_PREV_AUTH_NOT_VALID 2 #define WLAN_REASON_DEAUTH_LEAVING 3 #define WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY 4 #define WLAN_REASON_DISASSOC_AP_BUSY 5 #define WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA 6 #define WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA 7 #define WLAN_REASON_DISASSOC_STA_HAS_LEFT 8 #define WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH 9 /* IEEE 802.11h */ #define WLAN_REASON_PWR_CAPABILITY_NOT_VALID 10 #define WLAN_REASON_SUPPORTED_CHANNEL_NOT_VALID 11 /* IEEE 802.11i */ #define WLAN_REASON_INVALID_IE 13 #define WLAN_REASON_MICHAEL_MIC_FAILURE 14 #define WLAN_REASON_4WAY_HANDSHAKE_TIMEOUT 15 #define WLAN_REASON_GROUP_KEY_UPDATE_TIMEOUT 16 #define WLAN_REASON_IE_IN_4WAY_DIFFERS 17 #define WLAN_REASON_GROUP_CIPHER_NOT_VALID 18 #define WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID 19 #define WLAN_REASON_AKMP_NOT_VALID 20 #define WLAN_REASON_UNSUPPORTED_RSN_IE_VERSION 21 #define WLAN_REASON_INVALID_RSN_IE_CAPAB 22 #define WLAN_REASON_IEEE_802_1X_AUTH_FAILED 23 #define WLAN_REASON_CIPHER_SUITE_REJECTED 24 #define IEEE80211_SEQ_SEQ_MASK 0xfff0 #define IEEE80211_SEQ_SEQ_SHIFT 4 #define WBIT(n) (1 << (n)) #define WPA_KEY_INFO_TYPE_MASK (WBIT(0) | WBIT(1) | WBIT(2)) #define WPA_KEY_INFO_TYPE_HMAC_MD5_RC4 WBIT(0) #define WPA_KEY_INFO_TYPE_HMAC_SHA1_AES WBIT(1) #define WPA_KEY_INFO_KEY_TYPE WBIT(3) /* 1 = Pairwise, 0 = Group key */ #define WPA_KEY_INFO_KEY_INDEX_MASK (WBIT(4) | WBIT(5)) #define WPA_KEY_INFO_KEY_INDEX_SHIFT 4 #define WPA_KEY_INFO_INSTALL WBIT(6) /* pairwise */ #define WPA_KEY_INFO_TXRX WBIT(6) /* group */ #define WPA_KEY_INFO_ACK WBIT(7) #define WPA_KEY_INFO_MIC WBIT(8) #define WPA_KEY_INFO_SECURE WBIT(9) #define WPA_KEY_INFO_ERROR WBIT(10) #define WPA_KEY_INFO_REQUEST WBIT(11) #define WPA_KEY_INFO_ENCR_KEY_DATA WBIT(12) /* IEEE 802.11i/RSN only */ struct radiotap_header { uint8_t it_version; uint8_t it_pad; uint16_t it_len; uint32_t it_present; }; typedef struct radiotap_header rth_t; #define RTH_SIZE (sizeof(rth_t)) struct ppi_packet_header { uint8_t pph_version; uint8_t pph_flags; uint16_t pph_len; uint32_t pph_dlt; } __attribute__((packed)); typedef struct ppi_packet_header ppi_packet_header_t; struct adr_frame { uint8_t addr[6]; }; typedef struct adr_frame adr_t; #define ADR_SIZE (sizeof(adr_t)) struct loopb_header { uint32_t family; } __attribute__((packed)); typedef struct loopb_header loopb_header_t; #define LOOPB_SIZE (sizeof(loopb_header_t)) struct ether_header { adr_t addr1; adr_t addr2; uint16_t ether_type; } __attribute__((packed)); typedef struct ether_header ether_header_t; #define ETHER_SIZE (sizeof(ether_header_t)) struct qos_frame { uint8_t control; uint8_t flags; }; typedef struct qos_frame qos_t; #define QOS_SIZE (sizeof(qos_t)) struct mac_frame { #if __BYTE_ORDER == __BIG_ENDIAN unsigned subtype : 4; unsigned type : 2; unsigned version : 2; unsigned ordered : 1; unsigned protected : 1; unsigned more_data : 1; unsigned power : 1; unsigned retry : 1; unsigned more_frag : 1; unsigned from_ds : 1; unsigned to_ds : 1; #else unsigned version : 2; unsigned type : 2; unsigned subtype : 4; unsigned to_ds : 1; unsigned from_ds : 1; unsigned more_frag : 1; unsigned retry : 1; unsigned power : 1; unsigned more_data : 1; unsigned protected : 1; unsigned ordered : 1; #endif uint16_t duration; adr_t addr1; adr_t addr2; adr_t addr3; uint16_t sequence; adr_t addr4; qos_t qos; }; typedef struct mac_frame mac_t; struct llc_frame { uint8_t dsap; uint8_t ssap; uint8_t control; uint8_t org[3]; uint16_t type; #define LLC_TYPE_AUTH 0x888e #define LLC_TYPE_IPV4 0x0800 #define LLC_TYPE_IPV6 0x86dd #define LLC_TYPE_PREAUT 0x88c7 #define LLC_TYPE_FRRR 0x890d }; typedef struct llc_frame llc_t; #define LLC_SIZE (sizeof(llc_t)) #define LLC_SNAP 0xaa struct ieee_tag { uint8_t id; #define TAG_SSID 0 #define TAG_RATE 1 #define TAG_CHAN 3 #define TAG_XRAT 0x32 uint8_t len; uint8_t data[]; } __attribute__((__packed__)); typedef struct ieee_tag tag_t; #define TAGINFO_SIZE (sizeof(tag_t)) struct beaconinfo { uint64_t beacon_timestamp; uint16_t beacon_interval; uint16_t beacon_capabilities; } __attribute__((__packed__)); typedef struct beaconinfo beacon_t; #define BEACONINFO_SIZE (sizeof(beacon_t)) struct essidinfo { uint8_t info_essid; uint8_t info_essid_len; uint8_t* essid[0]; } __attribute__((__packed__)); typedef struct essidinfo essid_t; #define ESSIDINFO_SIZE (sizeof(essid_t)) struct authenticationf { uint16_t authentication_algho; uint16_t authentication_seq; } __attribute__((__packed__)); typedef struct authenticationf authf_t; #define AUTHF_SIZE (sizeof(authf_t)) struct associationreqf { uint16_t client_capabilities; uint16_t client_listeninterval; } __attribute__((__packed__)); typedef struct associationreqf assocreq_t; #define ASSOCIATIONREQF_SIZE (sizeof(assocreq_t)) struct associationresf { uint16_t ap_capabilities; uint16_t ap_status; uint16_t ap_associd; } __attribute__((__packed__)); typedef struct associationresf assocres_t; #define ASSOCIATIONRESF_SIZE (sizeof(assocres_t)) struct reassociationreqf { uint16_t client_capabilities; uint16_t client_listeninterval; adr_t addr3; } __attribute__((__packed__)); typedef struct reassociationreqf reassocreq_t; #define REASSOCIATIONREQF_SIZE (sizeof(reassocreq_t)) struct mpdu_frame { uint8_t pn[3]; uint8_t keyid; uint8_t exitiv[4]; }; typedef struct mpdu_frame mpdu_frame_t; #define MPDUF_SIZE (sizeof(mpdu_frame_t)) struct eap_frame { uint8_t version; uint8_t type; uint16_t len; uint8_t keytype; uint16_t keyinfo; uint16_t keylen; uint64_t replaycount; uint8_t nonce[32]; uint8_t keyiv[16]; uint8_t keyrsc[8]; uint8_t keyid[8]; uint8_t keymic[16]; uint16_t wpadatalen; uint8_t wpadata[10]; } __attribute__((__packed__)); typedef struct eap_frame eap_t; #define EAP_SIZE (sizeof(eap_t)) struct vendor_id { uint8_t vid[3]; }; typedef struct vendor_id vid_t; #define VID_SIZE (sizeof(vidt_t)) struct eapext_frame { uint8_t version; uint8_t type; uint16_t len; uint8_t eapcode; #define EAP_CODE_REQ 1 #define EAP_CODE_RESP 2 #define EAP_CODE_SUCCESS 3 #define EAP_CODE_FAILURE 4 #define EAP_CODE_INITIATE 5 #define EAP_CODE_FINISH 6 uint8_t eapid; uint16_t eaplen; uint8_t eaptype; #define EAP_TYPE_EAP 0 #define EAP_TYPE_ID 1 #define EAP_TYPE_NOTIFY 2 #define EAP_TYPE_NAK 3 #define EAP_TYPE_MD5 4 #define EAP_TYPE_OTP 5 #define EAP_TYPE_GTC 6 #define EAP_TYPE_RSA 9 #define EAP_TYPE_DSS 10 #define EAP_TYPE_KEA 11 #define EAP_TYPE_KEA_VALIDATE 12 #define EAP_TYPE_TLS 13 #define EAP_TYPE_AXENT 14 #define EAP_TYPE_RSA_SSID 15 #define EAP_TYPE_RSA_ARCOT 16 #define EAP_TYPE_LEAP 17 #define EAP_TYPE_SIM 18 #define EAP_TYPE_SRP_SHA1 19 #define EAP_TYPE_TTLS 21 #define EAP_TYPE_RAS 22 #define EAP_TYPE_AKA 23 #define EAP_TYPE_3COMEAP 24 #define EAP_TYPE_PEAP 25 #define EAP_TYPE_MSEAP 26 #define EAP_TYPE_MAKE 27 #define EAP_TYPE_CRYPTOCARD 28 #define EAP_TYPE_MSCHAPV2 29 #define EAP_TYPE_DYNAMICID 30 #define EAP_TYPE_ROB 31 #define EAP_TYPE_POTP 32 #define EAP_TYPE_MSTLV 33 #define EAP_TYPE_SENTRI 34 #define EAP_TYPE_AW 35 #define EAP_TYPE_CSBA 36 #define EAP_TYPE_AIRFORT 37 #define EAP_TYPE_HTTPD 38 #define EAP_TYPE_SS 39 #define EAP_TYPE_DC 40 #define EAP_TYPE_SPEKE 41 #define EAP_TYPE_MOBAC 42 #define EAP_TYPE_FAST 43 #define EAP_TYPE_ZLXEAP 44 #define EAP_TYPE_LINK 45 #define EAP_TYPE_PAX 46 #define EAP_TYPE_PSK 47 #define EAP_TYPE_SAKE 48 #define EAP_TYPE_IKEV2 49 #define EAP_TYPE_AKA1 50 #define EAP_TYPE_GPSK 51 #define EAP_TYPE_PWD 52 #define EAP_TYPE_EKE1 53 #define EAP_TYPE_PTEAP 54 #define EAP_TYPE_TEAP 55 #define EAP_TYPE_EXPAND 254 #define EAP_TYPE_EXPERIMENTAL 255 } __attribute__((__packed__)); typedef struct eapext_frame eapext_t; #define EAPEXT_SIZE (sizeof(eapext_t)) struct eapri_frame { uint8_t version; uint8_t type; uint16_t len; uint8_t eapcode; uint8_t eapid; uint16_t eaplen; uint8_t eaptype; uint8_t identity[]; } __attribute__((__packed__)); typedef struct eapri_frame eapri_t; #define EAPRI_SIZE (sizeof(eapri_t)) struct eapleap_frame { uint8_t version; uint8_t type; uint16_t len; uint8_t eapcode; uint8_t eapid; uint16_t eaplen; uint8_t eaptype; uint8_t leapversion; uint8_t leapreserved; uint8_t leapcount; uint8_t leapdata[]; } __attribute__((__packed__)); typedef struct eapleap_frame eapleap_t; #define EAPLEAP_SIZE (sizeof(eapleap_t)) struct eapmd5_frame { uint8_t version; uint8_t type; uint16_t len; uint8_t eapcode; uint8_t eapid; uint16_t eaplen; uint8_t eaptype; uint8_t eapvaluesize; uint8_t md5data[]; } __attribute__((__packed__)); typedef struct eapmd5_frame eapmd5_t; #define EAPMD5_SIZE (sizeof(eapmd5_t)) struct ipv4_frame { uint8_t ver_hlen; uint8_t tos; uint16_t len; uint16_t ipid; uint16_t flags_offset; uint8_t ttl; uint8_t nextprotocol; uint16_t checksum; uint8_t srcaddr[4]; uint8_t dstaddr[4]; } __attribute__ ((packed)); typedef struct ipv4_frame ipv4_frame_t; #define IPV4_SIZE (sizeof(ipv4_frame_t)) #define IPV4_SIZE_MIN 20 #define IPV4_SIZE_MAX 64 struct ipv6_frame { uint32_t ver_class; uint16_t len; uint8_t nextprotocol; uint8_t hoplimint; uint8_t srcaddr[16]; uint8_t dstaddr[16]; } __attribute__ ((packed)); typedef struct ipv6_frame ipv6_frame_t; #define IPV6_SIZE (sizeof(ipv6_frame_t)) #define NEXTHDR_HOP 0 /* Hop-by-hop option header. */ #define NEXTHDR_TCP 6 /* TCP segment. */ #define NEXTHDR_UDP 17 /* UDP message. */ #define NEXTHDR_IPV6 41 /* IPv6 in IPv6 */ #define NEXTHDR_ROUTING 43 /* Routing header. */ #define NEXTHDR_FRAGMENT 44 /* Fragmentation/reassembly header. */ #define NEXTHDR_GRE 47 /* GRE header. */ #define NEXTHDR_ESP 50 /* Encapsulating security payload. */ #define NEXTHDR_AUTH 51 /* Authentication header. */ #define NEXTHDR_ICMP 58 /* ICMP for IPv6. */ #define NEXTHDR_NONE 59 /* No next header */ #define NEXTHDR_DEST 60 /* Destination options header. */ #define NEXTHDR_SCTP 132 /* SCTP message. */ #define NEXTHDR_MOBILITY 135 /* Mobility header. */ #define NEXTHDR_MAX 255 struct gre_frame { uint16_t flags; uint16_t type; uint16_t length; uint16_t callid; uint16_t seq; /* optional based on flags */ uint16_t ack; /* optional based on flags */ } __attribute__ ((packed)); typedef struct gre_frame gre_frame_t; #define GRE_SIZE (sizeof(gre_frame_t)) #define GRE_MIN_SIZE (sizeof(gre_frame_t) - 4) #define GREPROTO_PPP 0x880b #define GRE_FLAG_SYNSET 0x0010 #define GRE_FLAG_ACKSET 0x8000 struct ppp_frame { uint16_t proto; } __attribute__ ((packed)); typedef struct ppp_frame ppp_frame_t; #define PPP_SIZE sizeof(ppp_frame_t) #define PPPPROTO_CHAP 0xc223 struct pppchap_frame { uint8_t code; uint8_t identifier; uint16_t length; union { struct { uint8_t datalen; uint8_t serverchallenge[16]; uint8_t names; } challenge; struct { uint8_t datalen; uint8_t clientchallenge[16]; uint8_t unknown[8]; /* all zero's */ uint8_t authresponse[24]; uint8_t status; uint8_t namec; } response; } u; } __attribute__ ((packed)); typedef struct pppchap_frame pppchap_frame_t; #define PPPCHAPHDR_SIZE 4 #define PPPCHAPHDR_MIN_CHAL_SIZE 21 #define PPPCHAPHDR_MIN_RESP_SIZE 55 #define PPPCHAP_CHALLENGE 1 #define PPPCHAP_RESPONSE 2 #define PPPCHAP_SUCCESS 3 #define PPPCHAP_FAILURE 4 struct netdb { long int tv_sec; long int tv_usec; adr_t mac_ap; adr_t mac_sta; uint8_t essid_len; uint8_t essid[32]; }; typedef struct netdb netdb_t; #define NETDB_SIZE (sizeof(netdb_t)) struct eapdb { long int tv_sec; time_t tv_usec; adr_t mac_ap; adr_t mac_sta; uint16_t eapol_len; uint8_t eapol[256]; }; typedef struct eapdb eapdb_t; #define EAPDB_SIZE (sizeof(eapdb_t)) #define MYREPLAYCOUNT 63232 #define MESSAGE_PAIR_M12E2 0 #define MESSAGE_PAIR_M14E4 1 #define MESSAGE_PAIR_M32E2 2 #define MESSAGE_PAIR_M32E3 3 #define MESSAGE_PAIR_M34E3 4 #define MESSAGE_PAIR_M34E4 5 #define MESSAGE_PAIR_M12E2NR 128 #define MESSAGE_PAIR_M14E4NR 129 #define MESSAGE_PAIR_M32E2NR 130 #define MESSAGE_PAIR_M32E3NR 131 #define MESSAGE_PAIR_M34E3NR 132 #define MESSAGE_PAIR_M34E4NR 133 struct hcx { uint32_t signature; uint32_t version; uint8_t message_pair; uint8_t essid_len; uint8_t essid[32]; uint8_t keyver; uint8_t keymic[16]; adr_t mac_ap; uint8_t nonce_ap[32]; adr_t mac_sta; uint8_t nonce_sta[32]; uint16_t eapol_len; uint8_t eapol[256]; } __attribute__((packed)); typedef struct hcx hcx_t; #define HCX_SIZE (sizeof(hcx_t)) /*===========================================================================*/ /* globale Konstante */ const uint8_t channellist[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ,14, 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165 }; #define CHANNELLIST_SIZE sizeof(channellist) const uint8_t mynonce[] = { 0x68, 0x20, 0x09, 0xe2, 0x1f, 0x0e, 0xbc, 0xe5, 0x62, 0xb9, 0x06, 0x5b, 0x54, 0x89, 0x79, 0x09, 0x9a, 0x65, 0x52, 0x86, 0xc0, 0x77, 0xea, 0x28, 0x2f, 0x6a, 0xaf, 0x13, 0x8e, 0x50, 0xcd, 0xb9 }; #define ANONCE_SIZE sizeof(anonce) /*===========================================================================*/ hcxkeys-6.2.0/license.txt000066400000000000000000000020711405044453300153620ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2000-2021 ZeroBeat Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. hcxkeys-6.2.0/wlangenpmk.c000066400000000000000000000226621405044453300155160ustar00rootroot00000000000000#define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #ifdef __APPLE__ #define strdupa strdup #include #else #include #endif #include #include "include/common.h" #define COWPATTY_SIGNATURE 0x43575041L struct cow_head { uint32_t magic; uint8_t reserved1[3]; uint8_t essidlen; uint8_t essid[32]; }; typedef struct cow_head cow_head_t; #define COWHEAD_SIZE (sizeof(cow_head_t)) /*===========================================================================*/ /* globale Variablen */ uint8_t progende = FALSE; /*===========================================================================*/ void programmende(int signum) { if((signum == SIGINT) || (signum == SIGTERM) || (signum == SIGKILL)) { progende = TRUE; } return; } /*===========================================================================*/ size_t chop(char *buffer, size_t len) { char *ptr = buffer +len -1; while(len) { if (*ptr != '\n') break; *ptr-- = 0; len--; } while(len) { if (*ptr != '\r') break; *ptr-- = 0; len--; } return len; } /*---------------------------------------------------------------------------*/ int fgetline(FILE *inputstream, size_t size, char *buffer) { if(feof(inputstream)) return -1; char *buffptr = fgets (buffer, size, inputstream); if(buffptr == NULL) return -1; size_t len = strlen(buffptr); len = chop(buffptr, len); return len; } /*===========================================================================*/ void filecombiout(FILE *fhcombi, FILE *fhascii, FILE *fhasciipw, FILE *fhcow) { int c; char *ptr1 = NULL; char *ptr2 = NULL; int combilen; int saltlen; int pwlen; int cr; cow_head_t cow; uint8_t cowreclen = 0; long int pmkcount = 0; long int skippedcount = 0; char combiline[256]; unsigned char salt[34]; char password[64]; unsigned char pmk[64]; signal(SIGINT, programmende); if(fhcow != NULL) { memset(&cow, 0, COWHEAD_SIZE); cow.magic = COWPATTY_SIGNATURE; memset(&cow.essid, 0, 32); cow.essidlen = 0; cow.reserved1[2] = 1; cr = fwrite(&cow, COWHEAD_SIZE, 1, fhcow); if(cr != 1) { fprintf(stderr, "error writing cowpatty file\n"); exit(EXIT_FAILURE); } } while((progende != TRUE) && ((combilen = fgetline(fhcombi, 256, combiline)) != -1)) { if(combilen < 10) { skippedcount++; continue; } ptr1 = combiline; ptr2 = strchr(ptr1, ':') +1; pwlen = strlen(ptr2); if((pwlen < 8) || (pwlen > 63)) { skippedcount++; continue; } memset(&password, 0, 64); memcpy(&password, ptr2, pwlen); saltlen = strlen(ptr1); if(saltlen < 3) { skippedcount++; continue; } saltlen -= pwlen +1; if((saltlen < 1) || (saltlen > 32)) { skippedcount++; continue; } memset(&salt, 0, 34); memcpy(&salt, ptr1, saltlen); if( PKCS5_PBKDF2_HMAC_SHA1(password, pwlen, salt, saltlen, 4096, 32, pmk) != 0 ) { if(fhcow != NULL) { cowreclen = sizeof(cowreclen) + pwlen + 32; cr = fwrite(&cowreclen, sizeof(cowreclen), 1, fhcow); if(cr != 1) { fprintf(stderr, "error writing cowpatty file\n"); exit(EXIT_FAILURE); } fprintf(fhcow, "%s", password); cr = fwrite(&pmk, sizeof(uint8_t), 32, fhcow); if(cr != 32) { fprintf(stderr, "error writing cowpatty file\n"); exit(EXIT_FAILURE); } } for(c = 0; c< 32; c++) { if(fhascii != NULL) fprintf(fhascii, "%02x", pmk[c]); if(fhasciipw != NULL) fprintf(fhasciipw, "%02x", pmk[c]); } if(fhascii != NULL) fprintf(fhascii, "\n"); if(fhasciipw != NULL) fprintf(fhasciipw, ":%s\n", password); pmkcount++; if((pmkcount %1000) == 0) printf("\r%ld", pmkcount); } } printf("\r%ld plainmasterkeys generated, %ld password(s) skipped\n", pmkcount, skippedcount); return; } /*===========================================================================*/ void filepmkout(FILE *pwlist, FILE *fhascii, FILE *fhasciipw, FILE *fhcow, char *essidname, uint8_t essidlen) { int pwlen; int c; int cr; cow_head_t cow; uint8_t cowreclen = 0; long int pmkcount = 0; long int skippedcount = 0; unsigned char essid[32]; char password[64]; unsigned char pmk[64]; signal(SIGINT, programmende); memcpy(&essid, essidname, essidlen); if((fhcow != NULL) && (essidname != NULL)) { memset(&cow, 0, COWHEAD_SIZE); cow.magic = COWPATTY_SIGNATURE; memcpy(cow.essid, essidname, essidlen); cow.essidlen = essidlen; cr = fwrite(&cow, COWHEAD_SIZE, 1, fhcow); if(cr != 1) { fprintf(stderr, "error writing cowpatty file\n"); exit(EXIT_FAILURE); } } while((progende != TRUE) && ((pwlen = fgetline(pwlist, 64, password)) != -1)) { if((pwlen < 8) || pwlen > 63) { skippedcount++; continue; } if(PKCS5_PBKDF2_HMAC(password, pwlen, essid, essidlen, 4096, EVP_sha1(), 32, pmk) != 0) { if(fhcow != NULL) { cowreclen = sizeof(cowreclen) + pwlen + 32; cr = fwrite(&cowreclen, sizeof(cowreclen), 1, fhcow); if(cr != 1) { fprintf(stderr, "error writing cowpatty file\n"); exit(EXIT_FAILURE); } fprintf(fhcow, "%s", password); cr = fwrite(&pmk, sizeof(uint8_t), 32, fhcow); if(cr != 32) { fprintf(stderr, "error writing cowpatty file\n"); exit(EXIT_FAILURE); } } for(c = 0; c< 32; c++) { if(fhascii != NULL) fprintf(fhascii, "%02x", pmk[c]); if(fhasciipw != NULL) fprintf(fhasciipw, "%02x", pmk[c]); } if(fhascii != NULL) fprintf(fhascii, "\n"); if(fhasciipw != NULL) fprintf(fhasciipw, ":%s\n", password); pmkcount++; if((pmkcount %1000) == 0) printf("\r%ld", pmkcount); } } printf("\r%ld plainmasterkeys generated, %ld password(s) skipped\n", pmkcount, skippedcount); return; } /*===========================================================================*/ void singlepmkout(char *pwname, int pwlen, char *essidname, int essidlen) { int c; unsigned char essid[32]; unsigned char pmk1[64]; unsigned char pmk256[64]; memset(&essid, 0, 32); memcpy(&essid, essidname, essidlen); fprintf(stdout, "\n" "essid (networkname)....: %s\n" "password...............: %s\n" , essidname, pwname); if(PKCS5_PBKDF2_HMAC(pwname, pwlen, essid, essidlen, 4096, EVP_sha1(), 32, pmk1) != 0) { printf("plainmasterkey (SHA1)..: "); for(c = 0; c< 32; c++) { printf("%02x", pmk1[c]); } printf("\n"); } if(PKCS5_PBKDF2_HMAC(pwname, pwlen, essid, essidlen, 4096, EVP_sha256(), 32, pmk256) != 0) { printf("plainmasterkey (SHA256): "); for(c = 0; c< 32; c++) { printf("%02x", pmk256[c]); } printf("\n\n"); } return; } /*===========================================================================*/ static void usage(char *eigenname) { printf("%s %s (C) %s ZeroBeat\n" "usage: %s \n" "\n" "options:\n" "-e : input single essid (networkname: 1 .. 32 characters) requires -p or -i\n" "-p : input single password (8 .. 63 characters) requires -e\n" "-i : input passwordlist\n" "-I : input combilist (essid:password)\n" "-a : output plainmasterkeys as ASCII file (hash mode 2200x, 1680x, 250x)\n" "-A : output plainmasterkeys:password as ASCII file\n" "-c : output cowpatty hashfile (existing file will be replaced)\n" "-h : this help\n" "\n", eigenname, VERSION_TAG, VERSION_YEAR, eigenname); exit(EXIT_FAILURE); } /*===========================================================================*/ int main(int argc, char *argv[]) { FILE *fhpwlist = NULL; FILE *fhascii = NULL; FILE *fhasciipw = NULL; FILE *fhcow = NULL; FILE *fhcombi = NULL; int auswahl; int pwlen = 0; uint8_t essidlen = 0; char *eigenname = NULL; char *eigenpfadname = NULL; char *pwname = NULL; char *essidname = NULL; eigenpfadname = strdupa(argv[0]); eigenname = basename(eigenpfadname); setbuf(stdout, NULL); while ((auswahl = getopt(argc, argv, "p:e:i:I:a:A:c:h")) != -1) { switch (auswahl) { case 'e': essidname = optarg; essidlen = strlen(essidname); if((essidlen < 1) || (essidlen > 32)) { fprintf(stderr, "error wrong essid len\n"); exit(EXIT_FAILURE); } break; case 'p': pwname = optarg; pwlen = strlen(pwname); if((pwlen < 1) || (pwlen > 63)) { fprintf(stderr, "error wrong password len\n"); exit(EXIT_FAILURE); } break; case 'i': if((fhpwlist = fopen(optarg, "r")) == NULL) { fprintf(stderr, "error opening %s\n", optarg); exit(EXIT_FAILURE); } break; case 'I': if((fhcombi = fopen(optarg, "r")) == NULL) { fprintf(stderr, "error opening %s\n", optarg); exit(EXIT_FAILURE); } break; case 'a': if((fhascii = fopen(optarg, "a")) == NULL) { fprintf(stderr, "error opening %s\n", optarg); exit(EXIT_FAILURE); } break; case 'A': if((fhasciipw = fopen(optarg, "a")) == NULL) { fprintf(stderr, "error opening %s\n", optarg); exit(EXIT_FAILURE); } break; case 'c': if((fhcow = fopen(optarg, "w")) == NULL) { fprintf(stderr, "error opening %s\n", optarg); exit(EXIT_FAILURE); } break; case 'h': usage(eigenname); break; default: usage(eigenname); break; } } if((essidname != NULL) && (pwname != NULL)) singlepmkout(pwname, pwlen, essidname, essidlen); else if((essidname != NULL) && (fhpwlist != NULL)) filepmkout(fhpwlist, fhascii, fhasciipw, fhcow, essidname, essidlen); else if(fhcombi != NULL) filecombiout(fhcombi, fhascii, fhasciipw, fhcow); if(fhcombi != NULL) fclose(fhcombi); if(fhpwlist != NULL) fclose(fhpwlist); if(fhascii != NULL) fclose(fhascii); return EXIT_SUCCESS; } hcxkeys-6.2.0/wlangenpmkocl.c000066400000000000000000000750011405044453300162070ustar00rootroot00000000000000#define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #ifdef __APPLE__ #define strdupa strdup #include #else #include #endif #include #include #include #define CL_USE_DEPRECATED_OPENCL_1_2_APIS #define CL_TARGET_OPENCL_VERSION 120 #ifdef __APPLE__ #include #else #include #endif #include "include/common.h" #include "include/common.c" #define MAX_SOURCE_SIZE (0x1000000) typedef struct { uint32_t h0,h1,h2,h3,h4; } SHA_DEV_CTX; typedef struct { SHA_DEV_CTX ctx_ipad; SHA_DEV_CTX ctx_opad; SHA_DEV_CTX e1; SHA_DEV_CTX e2; } gpu_inbuffer; typedef struct { SHA_DEV_CTX pmk1; SHA_DEV_CTX pmk2; } gpu_outbuffer; #define COWPATTY_SIGNATURE 0x43575041L struct cow_head { uint32_t magic; uint8_t reserved1[3]; uint8_t essidlen; uint8_t essid[32]; }; typedef struct cow_head cow_head_t; #define COWHEAD_SIZE (sizeof(cow_head_t)) #define MAX_WORKSIZE (1024*1024) /* Max. figure */ static size_t gws = 16; /* Start figure; will auto-tune */ static cl_ulong max_gpu_alloc; /* Memory limit */ /*===========================================================================*/ /* globale Variablen */ bool pipeflag = false; cl_uint platformCount; cl_platform_id *platforms = NULL; cl_uint deviceCount; cl_device_id *devices = NULL; cl_int ret; cl_context context; cl_command_queue command_queue; cl_kernel kernel; uint8_t progende = false; uint8_t essidlen = 0; char *essidname = NULL; FILE *fhascii = NULL; FILE *fhasciipw = NULL; FILE *fhcow = NULL; gpu_inbuffer inbuffer[MAX_WORKSIZE]; char password[MAX_WORKSIZE][64]; #define HANDLE_CLERROR(command) \ do { cl_int __err = (command); \ if (__err != CL_SUCCESS) { \ fprintf(stderr, "OpenCL %s error in %s:%d\n", \ getCLresultMsg(__err), __FILE__, __LINE__); \ } \ } while (0) static const char *kerneldata = "\n" \ "#ifndef uint32_t \n" \ "#define uint32_t unsigned int \n" \ "#endif \n" \ " \n" \ "typedef struct \n" \ "{ \n" \ " uint32_t h0,h1,h2,h3,h4; \n" \ "} SHA_DEV_CTX; \n" \ " \n" \ "#define CPY_DEVCTX(src, dst) { dst.h0 = src.h0; dst.h1 = src.h1; dst.h2 = src.h2; dst.h3 = src.h3; dst.h4 = src.h4; } \n" \ " \n" \ "typedef struct \n" \ "{ \n" \ " SHA_DEV_CTX ctx_ipad; \n" \ " SHA_DEV_CTX ctx_opad; \n" \ " SHA_DEV_CTX e1; \n" \ " SHA_DEV_CTX e2; \n" \ "} gpu_inbuffer; \n" \ " \n" \ "typedef struct \n" \ "{ \n" \ " SHA_DEV_CTX pmk1; \n" \ " SHA_DEV_CTX pmk2; \n" \ "} gpu_outbuffer; \n" \ " \n" \ " \n" \ " \n" \ "void sha1_process(__private const SHA_DEV_CTX ctx, __private SHA_DEV_CTX *data) \n" \ "{ \n" \ " uint32_t temp, W[16], A, B, C, D, E; \n" \ " \n" \ " W[ 0] = data->h0; W[ 1] = data->h1; \n" \ " W[ 2] = data->h2; W[ 3] = data->h3; \n" \ " W[ 4] = data->h4; W[ 5] = 0x80000000; \n" \ " W[ 6] = 0; W[ 7] = 0; \n" \ " W[ 8] = 0; W[ 9] = 0; \n" \ " W[10] = 0; W[11] = 0; \n" \ " W[12] = 0; W[13] = 0; \n" \ " W[14] = 0; W[15] = (64+20)*8; \n" \ " \n" \ " A = ctx.h0; \n" \ " B = ctx.h1; \n" \ " C = ctx.h2; \n" \ " D = ctx.h3; \n" \ " E = ctx.h4; \n" \ " \n" \ "#undef R \n" \ "#define R(t) (temp = W[(t - 3) & 0x0F] ^ W[(t - 8) & 0x0F] ^ W[(t - 14) & 0x0F] ^ W[t & 0x0F], ( W[t & 0x0F] = rotate((int)temp,1))) \n" \ " \n" \ "#undef P \n" \ "#define P(a,b,c,d,e,x) { e += rotate((int)a,5) + F(b,c,d) + K + x; b = rotate((int)b,30); } \n" \ " \n" \ "#define F(x,y,z) (z ^ (x & (y ^ z))) \n" \ "#define K 0x5A827999 \n" \ " \n" \ " P( A, B, C, D, E, W[0] ); \n" \ " P( E, A, B, C, D, W[1] ); \n" \ " P( D, E, A, B, C, W[2] ); \n" \ " P( C, D, E, A, B, W[3] ); \n" \ " P( B, C, D, E, A, W[4] ); \n" \ " P( A, B, C, D, E, W[5] ); \n" \ " P( E, A, B, C, D, W[6] ); \n" \ " P( D, E, A, B, C, W[7] ); \n" \ " P( C, D, E, A, B, W[8] ); \n" \ " P( B, C, D, E, A, W[9] ); \n" \ " P( A, B, C, D, E, W[10] ); \n" \ " P( E, A, B, C, D, W[11] ); \n" \ " P( D, E, A, B, C, W[12] ); \n" \ " P( C, D, E, A, B, W[13] ); \n" \ " P( B, C, D, E, A, W[14] ); \n" \ " P( A, B, C, D, E, W[15] ); \n" \ " P( E, A, B, C, D, R(16) ); \n" \ " P( D, E, A, B, C, R(17) ); \n" \ " P( C, D, E, A, B, R(18) ); \n" \ " P( B, C, D, E, A, R(19) ); \n" \ " \n" \ "#undef K \n" \ "#undef F \n" \ " \n" \ "#define F(x,y,z) (x ^ y ^ z) \n" \ "#define K 0x6ED9EBA1 \n" \ " \n" \ " P( A, B, C, D, E, R(20) ); \n" \ " P( E, A, B, C, D, R(21) ); \n" \ " P( D, E, A, B, C, R(22) ); \n" \ " P( C, D, E, A, B, R(23) ); \n" \ " P( B, C, D, E, A, R(24) ); \n" \ " P( A, B, C, D, E, R(25) ); \n" \ " P( E, A, B, C, D, R(26) ); \n" \ " P( D, E, A, B, C, R(27) ); \n" \ " P( C, D, E, A, B, R(28) ); \n" \ " P( B, C, D, E, A, R(29) ); \n" \ " P( A, B, C, D, E, R(30) ); \n" \ " P( E, A, B, C, D, R(31) ); \n" \ " P( D, E, A, B, C, R(32) ); \n" \ " P( C, D, E, A, B, R(33) ); \n" \ " P( B, C, D, E, A, R(34) ); \n" \ " P( A, B, C, D, E, R(35) ); \n" \ " P( E, A, B, C, D, R(36) ); \n" \ " P( D, E, A, B, C, R(37) ); \n" \ " P( C, D, E, A, B, R(38) ); \n" \ " P( B, C, D, E, A, R(39) ); \n" \ " \n" \ "#undef K \n" \ "#undef F \n" \ " \n" \ "#define F(x,y,z) ((x & y) | (z & (x | y))) \n" \ "#define K 0x8F1BBCDC \n" \ " \n" \ " P( A, B, C, D, E, R(40) ); \n" \ " P( E, A, B, C, D, R(41) ); \n" \ " P( D, E, A, B, C, R(42) ); \n" \ " P( C, D, E, A, B, R(43) ); \n" \ " P( B, C, D, E, A, R(44) ); \n" \ " P( A, B, C, D, E, R(45) ); \n" \ " P( E, A, B, C, D, R(46) ); \n" \ " P( D, E, A, B, C, R(47) ); \n" \ " P( C, D, E, A, B, R(48) ); \n" \ " P( B, C, D, E, A, R(49) ); \n" \ " P( A, B, C, D, E, R(50) ); \n" \ " P( E, A, B, C, D, R(51) ); \n" \ " P( D, E, A, B, C, R(52) ); \n" \ " P( C, D, E, A, B, R(53) ); \n" \ " P( B, C, D, E, A, R(54) ); \n" \ " P( A, B, C, D, E, R(55) ); \n" \ " P( E, A, B, C, D, R(56) ); \n" \ " P( D, E, A, B, C, R(57) ); \n" \ " P( C, D, E, A, B, R(58) ); \n" \ " P( B, C, D, E, A, R(59) ); \n" \ " \n" \ "#undef K \n" \ "#undef F \n" \ " \n" \ "#define F(x,y,z) (x ^ y ^ z) \n" \ "#define K 0xCA62C1D6 \n" \ " \n" \ " P( A, B, C, D, E, R(60) ); \n" \ " P( E, A, B, C, D, R(61) ); \n" \ " P( D, E, A, B, C, R(62) ); \n" \ " P( C, D, E, A, B, R(63) ); \n" \ " P( B, C, D, E, A, R(64) ); \n" \ " P( A, B, C, D, E, R(65) ); \n" \ " P( E, A, B, C, D, R(66) ); \n" \ " P( D, E, A, B, C, R(67) ); \n" \ " P( C, D, E, A, B, R(68) ); \n" \ " P( B, C, D, E, A, R(69) ); \n" \ " P( A, B, C, D, E, R(70) ); \n" \ " P( E, A, B, C, D, R(71) ); \n" \ " P( D, E, A, B, C, R(72) ); \n" \ " P( C, D, E, A, B, R(73) ); \n" \ " P( B, C, D, E, A, R(74) ); \n" \ " P( A, B, C, D, E, R(75) ); \n" \ " P( E, A, B, C, D, R(76) ); \n" \ " P( D, E, A, B, C, R(77) ); \n" \ " P( C, D, E, A, B, R(78) ); \n" \ " P( B, C, D, E, A, R(79) ); \n" \ " \n" \ "#undef K \n" \ "#undef F \n" \ " \n" \ " data->h0 = ctx.h0 + A; \n" \ " data->h1 = ctx.h1 + B; \n" \ " data->h2 = ctx.h2 + C; \n" \ " data->h3 = ctx.h3 + D; \n" \ " data->h4 = ctx.h4 + E; \n" \ " \n" \ "} \n" \ " \n" \ "__kernel \n" \ "void opencl_pmk_kernel(__global gpu_inbuffer *inbuffer, __global gpu_outbuffer *outbuffer) \n" \ "{ \n" \ " int i; \n" \ " const int idx = get_global_id(0); \n" \ " SHA_DEV_CTX temp_ctx; \n" \ " SHA_DEV_CTX pmk_ctx; \n" \ " SHA_DEV_CTX ipad; \n" \ " SHA_DEV_CTX opad; \n" \ " \n" \ " CPY_DEVCTX(inbuffer[idx].ctx_ipad, ipad); \n" \ " CPY_DEVCTX(inbuffer[idx].ctx_opad, opad); \n" \ " \n" \ " CPY_DEVCTX(inbuffer[idx].e1, temp_ctx); \n" \ " CPY_DEVCTX(temp_ctx, pmk_ctx); \n" \ " for( i = 0; i < 4096-1; i++ ) \n" \ " { \n" \ " sha1_process(ipad, &temp_ctx); \n" \ " sha1_process(opad, &temp_ctx); \n" \ " pmk_ctx.h0 ^= temp_ctx.h0; pmk_ctx.h1 ^= temp_ctx.h1; \n" \ " pmk_ctx.h2 ^= temp_ctx.h2; pmk_ctx.h3 ^= temp_ctx.h3; \n" \ " pmk_ctx.h4 ^= temp_ctx.h4; \n" \ " } \n" \ " CPY_DEVCTX(pmk_ctx, outbuffer[idx].pmk1); \n" \ " \n" \ " \n" \ " CPY_DEVCTX(inbuffer[idx].e2, temp_ctx); \n" \ " CPY_DEVCTX(temp_ctx, pmk_ctx); \n" \ " for( i = 0; i < 4096-1; i++ ) \n" \ " { \n" \ " sha1_process(ipad, &temp_ctx); \n" \ " sha1_process(opad, &temp_ctx); \n" \ " pmk_ctx.h0 ^= temp_ctx.h0; pmk_ctx.h1 ^= temp_ctx.h1; \n" \ " pmk_ctx.h2 ^= temp_ctx.h2; pmk_ctx.h3 ^= temp_ctx.h3; \n" \ " pmk_ctx.h4 ^= temp_ctx.h4; \n" \ " } \n" \ " CPY_DEVCTX(pmk_ctx, outbuffer[idx].pmk2); \n" \ "} \n"; /*===========================================================================*/ static char* getCLresultMsg(cl_int error) { switch (error) { case CL_SUCCESS: return "CL_SUCCESS"; case CL_DEVICE_NOT_FOUND: return "CL_DEVICE_NOT_FOUND"; case CL_DEVICE_NOT_AVAILABLE: return "CL_DEVICE_NOT_AVAILABLE"; case CL_COMPILER_NOT_AVAILABLE: return "CL_COMPILER_NOT_AVAILABLE"; case CL_MEM_OBJECT_ALLOCATION_FAILURE: return "CL_MEM_OBJECT_ALLOCATION_FAILURE"; case CL_OUT_OF_RESOURCES: return "CL_OUT_OF_RESOURCES"; case CL_OUT_OF_HOST_MEMORY: return "CL_OUT_OF_HOST_MEMORY"; case CL_PROFILING_INFO_NOT_AVAILABLE: return "CL_PROFILING_INFO_NOT_AVAILABLE"; case CL_MEM_COPY_OVERLAP: return "CL_MEM_COPY_OVERLAP"; case CL_IMAGE_FORMAT_MISMATCH: return "CL_IMAGE_FORMAT_MISMATCH"; case CL_IMAGE_FORMAT_NOT_SUPPORTED: return "CL_IMAGE_FORMAT_NOT_SUPPORTED"; case CL_BUILD_PROGRAM_FAILURE: return "CL_BUILD_PROGRAM_FAILURE"; case CL_MAP_FAILURE: return "CL_MAP_FAILURE"; case CL_INVALID_VALUE: return "CL_INVALID_VALUE"; case CL_INVALID_DEVICE_TYPE: return "CL_INVALID_DEVICE_TYPE"; case CL_INVALID_PLATFORM: return "CL_INVALID_PLATFORM"; case CL_INVALID_DEVICE: return "CL_INVALID_DEVICE"; case CL_INVALID_CONTEXT: return "CL_INVALID_CONTEXT"; case CL_INVALID_QUEUE_PROPERTIES: return "CL_INVALID_QUEUE_PROPERTIES"; case CL_INVALID_COMMAND_QUEUE: return "CL_INVALID_COMMAND_QUEUE"; case CL_INVALID_HOST_PTR: return "CL_INVALID_HOST_PTR"; case CL_INVALID_MEM_OBJECT: return "CL_INVALID_MEM_OBJECT"; case CL_INVALID_IMAGE_FORMAT_DESCRIPTOR: return "CL_INVALID_IMAGE_FORMAT_DESCRIPTOR"; case CL_INVALID_IMAGE_SIZE: return "CL_INVALID_IMAGE_SIZE"; case CL_INVALID_SAMPLER: return "CL_INVALID_SAMPLER"; case CL_INVALID_BINARY: return "CL_INVALID_BINARY"; case CL_INVALID_BUILD_OPTIONS: return "CL_INVALID_BUILD_OPTIONS"; case CL_INVALID_PROGRAM: return "CL_INVALID_PROGRAM"; case CL_INVALID_PROGRAM_EXECUTABLE: return "CL_INVALID_PROGRAM_EXECUTABLE"; case CL_INVALID_KERNEL_NAME: return "CL_INVALID_KERNEL_NAME"; case CL_INVALID_KERNEL_DEFINITION: return "CL_INVALID_KERNEL_DEFINITION"; case CL_INVALID_KERNEL: return "CL_INVALID_KERNEL"; case CL_INVALID_ARG_INDEX: return "CL_INVALID_ARG_INDEX"; case CL_INVALID_ARG_VALUE: return "CL_INVALID_ARG_VALUE"; case CL_INVALID_ARG_SIZE: return "CL_INVALID_ARG_SIZE"; case CL_INVALID_KERNEL_ARGS: return "CL_INVALID_KERNEL_ARGS"; case CL_INVALID_WORK_DIMENSION: return "CL_INVALID_WORK_DIMENSION"; case CL_INVALID_WORK_GROUP_SIZE: return "CL_INVALID_WORK_GROUP_SIZE"; case CL_INVALID_WORK_ITEM_SIZE: return "CL_INVALID_WORK_ITEM_SIZE"; case CL_INVALID_GLOBAL_OFFSET: return "CL_INVALID_GLOBAL_OFFSET"; case CL_INVALID_EVENT_WAIT_LIST: return "CL_INVALID_EVENT_WAIT_LIST"; case CL_INVALID_EVENT: return "CL_INVALID_EVENT"; case CL_INVALID_OPERATION: return "CL_INVALID_OPERATION"; case CL_INVALID_GL_OBJECT: return "CL_INVALID_GL_OBJECT"; case CL_INVALID_BUFFER_SIZE: return "CL_INVALID_BUFFER_SIZE"; case CL_INVALID_MIP_LEVEL: return "CL_INVALID_MIP_LEVEL"; default : return "Unknown CLresult"; } return "Unknown CLresult"; } /*===========================================================================*/ uint32_t finalcalc(size_t listsize) { size_t c; int cr; cl_mem g_inbuffer, g_outbuffer; gpu_outbuffer *outbuffer; gpu_outbuffer zeigerout; g_inbuffer = NULL; g_outbuffer = NULL; cl_event clEvents[3]; uint8_t cowreclen; cl_ulong start_ts, end_ts; uint32_t ms_dur; uint32_t cowpmk[8]; outbuffer = malloc(listsize *sizeof(gpu_outbuffer)); g_inbuffer = clCreateBuffer(context, CL_MEM_READ_ONLY, listsize *sizeof(gpu_inbuffer), NULL, &ret); HANDLE_CLERROR(clEnqueueWriteBuffer(command_queue, g_inbuffer, CL_FALSE, 0, listsize *sizeof(gpu_inbuffer), &inbuffer, 0, NULL, &clEvents[0])); g_outbuffer = clCreateBuffer(context, CL_MEM_WRITE_ONLY, listsize *sizeof(gpu_outbuffer), NULL, &ret); HANDLE_CLERROR(clSetKernelArg(kernel, 0, sizeof(cl_mem), &g_inbuffer)); HANDLE_CLERROR(clSetKernelArg(kernel, 1, sizeof(cl_mem), &g_outbuffer)); HANDLE_CLERROR(clEnqueueNDRangeKernel(command_queue, kernel, 1, NULL, &listsize, NULL, 1, clEvents, &clEvents[1])); HANDLE_CLERROR(clEnqueueReadBuffer(command_queue, g_outbuffer, CL_FALSE, 0, listsize *sizeof(gpu_outbuffer), outbuffer, 2, clEvents, &clEvents[2])); HANDLE_CLERROR(clFinish(command_queue)); HANDLE_CLERROR(clWaitForEvents(3, clEvents)); HANDLE_CLERROR(clGetEventProfilingInfo(clEvents[1], CL_PROFILING_COMMAND_START, sizeof(cl_ulong), &start_ts, NULL)); HANDLE_CLERROR(clGetEventProfilingInfo(clEvents[2], CL_PROFILING_COMMAND_END, sizeof(cl_ulong), &end_ts, NULL)); ms_dur = (uint32_t)((end_ts - start_ts) / 1000000); //fprintf(stderr, "GWS %zu Time: %u ms\n", gws, ms_dur); if (ms_dur <= 100 && 2 * gws < MAX_WORKSIZE && 2 * gws * sizeof(gpu_inbuffer) < max_gpu_alloc) { gws *= 2; } for(c = 0; c < listsize; c++) { zeigerout = outbuffer[c]; if(fhascii != NULL) fprintf(fhascii, "%08x%08x%08x%08x%08x%08x%08x%08x\n",zeigerout.pmk1.h0, zeigerout.pmk1.h1, zeigerout.pmk1.h2, zeigerout.pmk1.h3, zeigerout.pmk1.h4, zeigerout.pmk2.h0, zeigerout.pmk2.h1, zeigerout.pmk2.h2); if(fhasciipw != NULL) fprintf(fhasciipw, "%08x%08x%08x%08x%08x%08x%08x%08x:%s\n",zeigerout.pmk1.h0, zeigerout.pmk1.h1, zeigerout.pmk1.h2, zeigerout.pmk1.h3, zeigerout.pmk1.h4, zeigerout.pmk2.h0, zeigerout.pmk2.h1, zeigerout.pmk2.h2, &password[c][0]); if(fhcow != NULL) { cowreclen = sizeof(cowreclen) + strlen(&password[c][0]) + 32; cr = fwrite(&cowreclen, sizeof(cowreclen), 1, fhcow); if(cr != 1) { fprintf(stderr, "error writing cowpatty file\n"); exit(EXIT_FAILURE); } fprintf(fhcow, "%s", &password[c][0]); cowpmk[0] = byte_swap_32(zeigerout.pmk1.h0); cowpmk[1] = byte_swap_32(zeigerout.pmk1.h1); cowpmk[2] = byte_swap_32(zeigerout.pmk1.h2); cowpmk[3] = byte_swap_32(zeigerout.pmk1.h3); cowpmk[4] = byte_swap_32(zeigerout.pmk1.h4); cowpmk[5] = byte_swap_32(zeigerout.pmk2.h0); cowpmk[6] = byte_swap_32(zeigerout.pmk2.h1); cowpmk[7] = byte_swap_32(zeigerout.pmk2.h2); cr = fwrite(&cowpmk[0], sizeof(uint32_t), 8, fhcow); if(cr != 8) { fprintf(stderr, "error writing cowpatty file\n"); exit(EXIT_FAILURE); } } } for (c = 0; c < 3; c++) { if(clEvents[c] != 0) clReleaseEvent(clEvents[c]); } if (g_inbuffer != NULL) clReleaseMemObject(g_inbuffer); if (g_outbuffer != NULL) clReleaseMemObject(g_outbuffer); free(outbuffer); return listsize * 1000 / ms_dur; } /*===========================================================================*/ void precalc(gpu_inbuffer *zeigerinbuffer, uint8_t passwdlen, char *password) { int i; SHA_CTX ctx_pad; unsigned char essid[32 +4]; unsigned char pad[64]; unsigned char hmacout[32]; memcpy(essid, essidname, essidlen); memset(essid + essidlen, 0, sizeof(essid) - essidlen); memcpy(pad, password, passwdlen); memset(pad + passwdlen, 0, sizeof(pad) - passwdlen); for (i = 0; i < 16; i++) ((unsigned int*)pad)[i] ^= 0x36363636; SHA1_Init(&ctx_pad); SHA1_Update(&ctx_pad, pad, sizeof(pad)); zeigerinbuffer->ctx_ipad.h0 = ctx_pad.h0; zeigerinbuffer->ctx_ipad.h1 = ctx_pad.h1; zeigerinbuffer->ctx_ipad.h2 = ctx_pad.h2; zeigerinbuffer->ctx_ipad.h3 = ctx_pad.h3; zeigerinbuffer->ctx_ipad.h4 = ctx_pad.h4; for (i = 0; i < 16; i++) ((unsigned int*)pad)[i] ^= 0x6A6A6A6A; SHA1_Init(&ctx_pad); SHA1_Update(&ctx_pad, pad, sizeof(pad)); zeigerinbuffer->ctx_opad.h0 = ctx_pad.h0; zeigerinbuffer->ctx_opad.h1 = ctx_pad.h1; zeigerinbuffer->ctx_opad.h2 = ctx_pad.h2; zeigerinbuffer->ctx_opad.h3 = ctx_pad.h3; zeigerinbuffer->ctx_opad.h4 = ctx_pad.h4; essid[essidlen + 4 - 1] = '\1'; HMAC(EVP_sha1(), password, passwdlen, essid, essidlen + 4, hmacout, NULL); zeigerinbuffer->e1.h0 = (hmacout[0] << 24) | (hmacout[0 +1] << 16) | (hmacout[0 +2] << 8) | (hmacout[0 +3]); zeigerinbuffer->e1.h1 = (hmacout[4] << 24) | (hmacout[4 +1] << 16) | (hmacout[4 +2] << 8) | (hmacout[4 +3]); zeigerinbuffer->e1.h2 = (hmacout[8] << 24) | (hmacout[8 +1] << 16) | (hmacout[8 +2] << 8) | (hmacout[8 +3]); zeigerinbuffer->e1.h3 = (hmacout[12] << 24) | (hmacout[12 +1] << 16) | (hmacout[12 +2] << 8) | (hmacout[12 +3]); zeigerinbuffer->e1.h4 = (hmacout[16] << 24) | (hmacout[16 +1] << 16) | (hmacout[16 +2] << 8) | (hmacout[16 +3]); essid[essidlen + 4 - 1] = '\2'; HMAC(EVP_sha1(), password, passwdlen, essid, essidlen + 4, hmacout, NULL); zeigerinbuffer->e2.h0 = (hmacout[0] << 24) | (hmacout[0 +1] << 16) | (hmacout[0 +2] << 8) | (hmacout[0 +3]); zeigerinbuffer->e2.h1 = (hmacout[4] << 24) | (hmacout[4 +1] << 16) | (hmacout[4 +2] << 8) | (hmacout[4 +3]); zeigerinbuffer->e2.h2 = (hmacout[8] << 24) | (hmacout[8 +1] << 16) | (hmacout[8 +2] << 8) | (hmacout[8 +3]); zeigerinbuffer->e2.h3 = (hmacout[12] << 24) | (hmacout[12 +1] << 16) | (hmacout[12 +2] << 8) | (hmacout[12 +3]); zeigerinbuffer->e2.h4 = (hmacout[16] << 24) | (hmacout[16 +1] << 16) | (hmacout[16 +2] << 8) | (hmacout[16 +3]); return; } /*===========================================================================*/ void programmende(int signum) { if((signum == SIGINT) || (signum == SIGTERM) || (signum == SIGKILL)) { progende = true; } return; } /*===========================================================================*/ size_t chop(char *buffer, size_t len) { char *ptr = buffer +len -1; while(len) { if (*ptr != '\n') break; *ptr-- = 0; len--; } while(len) { if (*ptr != '\r') break; *ptr-- = 0; len--; } return len; } /*---------------------------------------------------------------------------*/ int fgetline(FILE *inputstream, size_t size, char *buffer) { if(feof(inputstream)) return -1; char *buffptr = fgets (buffer, size, inputstream); if(buffptr == NULL) return -1; size_t len = strlen(buffptr); len = chop(buffptr, len); return len; } /*===========================================================================*/ void filecombiout(FILE *fhcombi) { size_t c; char *ptr1 = NULL; int combilen; int pwlen; int cr; int hr; cow_head_t cow; long int pmkcount = 0; long int skippedcount = 0; uint32_t speed = 0; char combiline[256]; uint8_t buffhex[128]; signal(SIGINT, programmende); if(fhcow != NULL) { memset(&cow, 0, COWHEAD_SIZE); cow.magic = COWPATTY_SIGNATURE; memset(&cow.essid, 0,32); cow.essidlen = 0; cow.reserved1[2] = 1; cr = fwrite(&cow, COWHEAD_SIZE, 1, fhcow); if(cr != 1) { fprintf(stderr, "error writing cowpatty file\n"); exit(EXIT_FAILURE); } } c = 0; while((progende != true) && ((combilen = fgetline(fhcombi, 256, combiline)) != -1)) { if(combilen < 10) { skippedcount++; continue; } essidname = combiline; ptr1 = strchr(combiline, ':'); if(ptr1 == NULL) { skippedcount++; continue; } ptr1[0] = 0; ptr1++; essidlen = strlen(essidname); if(is_hexify((uint8_t*)essidname, essidlen)) { hr = do_unhexify((uint8_t*)essidname, essidlen, buffhex, 128); memcpy(essidname, buffhex, hr); essidlen = hr; } if((essidlen < 1) || (essidlen > 32)) { skippedcount++; continue; } pwlen = strlen(ptr1); if(is_hexify((uint8_t*)ptr1, pwlen)) { hr = do_unhexify((uint8_t*)ptr1, pwlen, buffhex, 128); memcpy(ptr1, buffhex, hr); pwlen = hr; } if((pwlen < 8) || (pwlen > 63)) { skippedcount++; continue; } memset(&password[c][0], 0, 64); memcpy(&password[c][0], ptr1, pwlen); precalc(&inbuffer[c], pwlen, &password[c][0]); c++; pmkcount++; if(c >= gws) { speed = finalcalc(c); c = 0; } if((pipeflag == false) && ((pmkcount % 1000) == 0)) { printf("\r%ld plainmasterkeys generated (%u/s)", pmkcount, speed); } } if(c != 0) speed = finalcalc(c); if(pipeflag == false) { printf("\r%ld plainmasterkeys generated, %ld password(s) skipped\n", pmkcount, skippedcount); } return; } /*===========================================================================*/ void processpasswords(FILE *fhpwlist) { int pwlen; size_t c; int cr; long int pmkcount = 0; long int skippedcount = 0; cow_head_t cow; uint32_t speed = 0; signal(SIGINT, programmende); if((fhcow != NULL) && (essidname != NULL)) { memset(&cow, 0, COWHEAD_SIZE); cow.magic = COWPATTY_SIGNATURE; memcpy(cow.essid, essidname, essidlen); cow.essidlen = essidlen; cr = fwrite(&cow, COWHEAD_SIZE, 1, fhcow); if(cr != 1) { fprintf(stderr, "error writing cowpatty file\n"); exit(EXIT_FAILURE); } } c = 0; while((progende != true) && ((pwlen = fgetline(fhpwlist, 64, &password[c][0])) != -1)) { if((pwlen < 8) || pwlen > 63) { skippedcount++; continue; } precalc(&inbuffer[c], pwlen, &password[c][0]); c++; pmkcount++; if(c >= gws) { speed = finalcalc(c); c = 0; } if((pipeflag == false) && ((pmkcount % 1000) == 0)) printf("\r%ld plainmasterkeys generated (%u/s)", pmkcount, speed); } if(c != 0) speed = finalcalc(c); if(pipeflag == false) { printf("\r%ld plainmasterkeys generated, %ld password(s) skipped\n", pmkcount, skippedcount); } return; } /*===========================================================================*/ bool initopencl(unsigned int gplfc, unsigned int gdevc) { cl_program program; char *devicename; size_t devicenamesize; HANDLE_CLERROR(clGetPlatformIDs(0, NULL, &platformCount)); platforms = (cl_platform_id*) malloc(sizeof(cl_platform_id) * platformCount); HANDLE_CLERROR(clGetPlatformIDs(platformCount, platforms, NULL)); if(gplfc >= platformCount) return false; HANDLE_CLERROR(clGetDeviceIDs(platforms[gplfc], CL_DEVICE_TYPE_ALL, 0, NULL, &deviceCount)); devices = (cl_device_id*) malloc(sizeof(cl_device_id) * deviceCount); HANDLE_CLERROR(clGetDeviceIDs(platforms[gplfc], CL_DEVICE_TYPE_ALL, deviceCount, devices, NULL)); if(gdevc >= deviceCount) return false; HANDLE_CLERROR(clGetDeviceInfo(devices[gdevc], CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof(max_gpu_alloc), &max_gpu_alloc, NULL)); HANDLE_CLERROR(clGetDeviceInfo(devices[gdevc], CL_DEVICE_NAME, 0, NULL, &devicenamesize)); devicename = (char*) malloc(devicenamesize); HANDLE_CLERROR(clGetDeviceInfo(devices[gdevc], CL_DEVICE_NAME, devicenamesize, devicename, NULL)); if(pipeflag == false) { printf("using: %s\n", devicename); } free(devicename); context = clCreateContext( NULL, 1, &devices[gdevc], NULL, NULL, &ret); command_queue = clCreateCommandQueue(context, devices[gdevc], CL_QUEUE_PROFILING_ENABLE, &ret); program = clCreateProgramWithSource(context, 1, (const char **) &kerneldata, NULL, &ret); ret = clBuildProgram(program, 1, &devices[gdevc], NULL, NULL, NULL); if (ret != CL_SUCCESS) { printf("OpenCL Error %s\n", getCLresultMsg(ret)); size_t len; char buffer[62048]; printf("Error: Failed to build program executable!\n"); clGetProgramBuildInfo(program, devices[gdevc], CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, &len); printf("%s\n", buffer); exit(1); return false; } kernel = clCreateKernel(program, "opencl_pmk_kernel", &ret); if (ret != CL_SUCCESS) { printf("OpenCL Error %s\n", getCLresultMsg(ret)); return false; } return true; } /*===========================================================================*/ bool listdevices() { unsigned int p, d; char* value1; char* value2; size_t valueSize; HANDLE_CLERROR(clGetPlatformIDs(0, NULL, &platformCount)); platforms = (cl_platform_id*) malloc(sizeof(cl_platform_id) * platformCount); HANDLE_CLERROR(clGetPlatformIDs(platformCount, platforms, NULL)); for (p = 0; p < platformCount; p++) { HANDLE_CLERROR(clGetDeviceIDs(platforms[p], CL_DEVICE_TYPE_ALL, 0, NULL, &deviceCount)); devices = (cl_device_id*) malloc(sizeof(cl_device_id) * deviceCount); HANDLE_CLERROR(clGetDeviceIDs(platforms[p], CL_DEVICE_TYPE_ALL, deviceCount, devices, NULL)); for (d = 0; d < deviceCount; d++) { clGetDeviceInfo(devices[d], CL_DEVICE_NAME, 0, NULL, &valueSize); value1 = (char*) malloc(valueSize); clGetDeviceInfo(devices[d], CL_DEVICE_NAME, valueSize, value1, NULL); clGetDeviceInfo(devices[d], CL_DEVICE_OPENCL_C_VERSION, 0, NULL, &valueSize); value2 = (char*) malloc(valueSize); clGetDeviceInfo(devices[d], CL_DEVICE_OPENCL_C_VERSION, valueSize, value2, NULL); printf("%s, %s for this device use options -P %d -D %d\n", value1, value2, p, d); free(value2); free(value1); } free(devices); } free(platforms); return true; } /*===========================================================================*/ void singlepmkout(char *pwname, int pwlen) { int c; unsigned char essid[32]; unsigned char pmk1[64]; unsigned char pmk256[64]; memset(&essid, 0, 32); memcpy(&essid, essidname, essidlen); fprintf(stdout, "\n" "essid (networkname)....: %s\n" "password...............: %s\n" , essidname, pwname); if(PKCS5_PBKDF2_HMAC(pwname, pwlen, essid, essidlen, 4096, EVP_sha1(), 32, pmk1) != 0) { printf("plainmasterkey (SHA1)..: "); for(c = 0; c< 32; c++) { printf("%02x", pmk1[c]); } printf("\n"); } if(PKCS5_PBKDF2_HMAC(pwname, pwlen, essid, essidlen, 4096, EVP_sha256(), 32, pmk256) != 0) { printf("plainmasterkey (SHA256): "); for(c = 0; c< 32; c++) { printf("%02x", pmk256[c]); } printf("\n\n"); } return; } /*===========================================================================*/ static void usage(char *eigenname) { printf("%s %s (C) %s ZeroBeat\n" "usage: %s \n" "\n" "options:\n" "-e : input single essid (networkname: 1 .. 32 characters) requires -p\n" "-p : input single password (8 .. 63 characters) requires -e\n" "-i : input passwordlist\n" "-I : input combilist (essid:password)\n" "-a : output plainmasterkeys as ASCII file (hash mode 2200x, 1680x, 250x)\n" "-A : output plainmasterkeys:password as ASCII file\n" "-c : output cowpatty hashfile (existing file will be replaced)\n" "-P : input platform, default 0 (first platform)\n" "-D : input device, default 0 (first device)\n" "-l : list device info\n" "-h : this help\n" "\n" "examples of stdin/stdout usage:\n" "cat wordlist | %s -e | hashcat ...\n" "cat wordlist | %s -e > \n" "or use classic mode:\n" "%s -e -i -a \n" "or use mixed mode:\n" "%s -e -i > \n" "\n", eigenname, VERSION_TAG, VERSION_YEAR, eigenname, eigenname, eigenname, eigenname, eigenname); exit(EXIT_FAILURE); } /*===========================================================================*/ int main(int argc, char *argv[]) { FILE *fhpwlist = NULL; FILE *fhcombi = NULL; int auswahl; unsigned int gplfc = 0; unsigned int gdevc= 0; int pwlen = 0; int listdeviceinfo = false; char *eigenname = NULL; char *eigenpfadname = NULL; char *pwname = NULL; eigenpfadname = strdupa(argv[0]); eigenname = basename(eigenpfadname); setbuf(stdout, NULL); while ((auswahl = getopt(argc, argv, "p:e:i:I:a:A:c:P:D:lh")) != -1) { switch (auswahl) { case 'e': essidname = optarg; essidlen = strlen(essidname); if((essidlen < 1) || (essidlen > 32)) { fprintf(stderr, "error wrong essid len\n"); exit(EXIT_FAILURE); } break; case 'p': pwname = optarg; pwlen = strlen(pwname); if((pwlen < 8) || (pwlen > 63)) { fprintf(stderr, "error wrong password len\n"); exit(EXIT_FAILURE); } break; case 'i': if((fhpwlist = fopen(optarg, "r")) == NULL) { fprintf(stderr, "error opening %s\n", optarg); exit(EXIT_FAILURE); } break; case 'I': if((fhcombi = fopen(optarg, "r")) == NULL) { fprintf(stderr, "error opening %s\n", optarg); exit(EXIT_FAILURE); } break; case 'a': if((fhascii = fopen(optarg, "a")) == NULL) { fprintf(stderr, "error opening %s\n", optarg); exit(EXIT_FAILURE); } break; case 'A': if((fhasciipw = fopen(optarg, "a")) == NULL) { fprintf(stderr, "error opening %s\n", optarg); exit(EXIT_FAILURE); } break; case 'c': if((fhcow = fopen(optarg, "w")) == NULL) { fprintf(stderr, "error opening %s\n", optarg); exit(EXIT_FAILURE); } break; case 'P': gplfc = atoi(optarg); break; case 'D': gdevc = atoi(optarg); break; case 'l': listdeviceinfo = true; break; case 'h': usage(eigenname); break; default: usage(eigenname); break; } } if((essidname != NULL) && (fhpwlist == NULL) && (fhascii == NULL) && (pwname == NULL) && (fhcombi == NULL) && (fhasciipw == NULL)) { printf("running in stdin/stdout mode\n"); pipeflag = true; fhascii = stdout; fhpwlist = stdin; } else if((essidname != NULL) && (fhpwlist != NULL) && (fhascii == NULL) && (pwname == NULL) && (fhcombi == NULL) && (fhasciipw == NULL)) { printf("running in stdout mode\n"); pipeflag = true; fhascii = stdout; } else if((essidname != NULL) && (fhpwlist == NULL) && (fhascii != NULL) && (pwname == NULL) && (fhcombi == NULL) && (fhasciipw == NULL)) { printf("running in stdin mode\n"); pipeflag = true; fhpwlist = stdin; } else if((essidname != NULL) && (fhpwlist == NULL) && (fhascii == NULL) && (pwname == NULL) && (fhcombi == NULL) && (fhasciipw != NULL)) { printf("running in stdin mode\n"); pipeflag = true; fhpwlist = stdin; } if(listdeviceinfo == true) { if(listdevices() != true) exit(EXIT_FAILURE); return EXIT_SUCCESS; } if(initopencl(gplfc, gdevc) != true) { fprintf(stderr, "couldn't initialize devices\n"); exit(EXIT_FAILURE); } if((essidname != NULL) && (pwname != NULL)) { singlepmkout(pwname, pwlen); return EXIT_SUCCESS; } else if((essidname != NULL) && (fhpwlist != NULL)) { processpasswords(fhpwlist); } else if(fhcombi != NULL) { filecombiout(fhcombi); } if(devices != NULL) free(devices); if(platforms != NULL) free(platforms); if(fhcombi != NULL) fclose(fhcombi); if(fhpwlist != NULL) fclose(fhpwlist); if(fhascii != NULL) fclose(fhascii); return EXIT_SUCCESS; }