Text   |  XML   |  ReML   |   Visible Warnings:

Buffer Overrun  at airpdcap.c:1322

No properties have been set. | edit properties
Jump to warning location ↓ warning details...
Show Events | Options

AirPDcapRsna4WHandshake

(/home/sate/Testcases/c/cve/wireshark-1.2.0/epan/crypt/airpdcap.c)expand/collapse
Show more  
 1171  AirPDcapRsna4WHandshake(
 1172      PAIRPDCAP_CONTEXT ctx,
 1173      const UCHAR *data,
 1174      AIRPDCAP_SEC_ASSOCIATION *sa,
 1175      PAIRPDCAP_KEY_ITEM key,
 1176      INT offset)
 1177  {
 1178      AIRPDCAP_KEY_ITEM *tmp_key, pkt_key;
 1179      AIRPDCAP_SEC_ASSOCIATION *tmp_sa;
 1180      INT key_index;
 1181      INT ret_value=1;
 1182      UCHAR useCache=FALSE;
 1183      UCHAR eapol[AIRPDCAP_EAPOL_MAX_LEN];
 1184      USHORT eapol_len;
 1185   
 1186      if (sa->key!=NULL)
 1187          useCache=TRUE;
 1188   
 1189      /* a 4-way handshake packet use a Pairwise key type (IEEE 802.11i-2004, pg. 79)     */
 1190      if (AIRPDCAP_EAP_KEY(data[offset+1])!=1) {
 1191          AIRPDCAP_DEBUG_PRINT_LINE("AirPDcapRsna4WHandshake", "Group/STAKey message (not used)", AIRPDCAP_DEBUG_LEVEL_5);
 1192          return AIRPDCAP_RET_NO_VALID_HANDSHAKE;
 1193      }
 1194   
 1195      /* TODO timeouts? */
 1196       
 1197      /* This saves the sa since we are reauthenticating which will overwrite our current sa GCS*/
 1198      if(sa->handshake == 4) {
 1199          tmp_sa=se_alloc(sizeof(AIRPDCAP_SEC_ASSOCIATION));
 1200          memcpy(tmp_sa, sa, sizeof(AIRPDCAP_SEC_ASSOCIATION));
 1201          sa->next=tmp_sa;
 1202      }
 1203   
 1204      /* TODO consider key-index  */
 1205   
 1206      /* TODO considera Deauthentications */
 1207   
 1208      AIRPDCAP_DEBUG_PRINT_LINE("AirPDcapRsna4WHandshake", "4-way handshake...", AIRPDCAP_DEBUG_LEVEL_5);
 1209   
 1210      /* manage 4-way handshake packets; this step completes the 802.1X authentication process (IEEE 802.11i-2004, pag. 85)       */
 1211   
 1212      /* message 1: Authenticator->Supplicant (Sec=0, Mic=0, Ack=1, Inst=0, Key=1(pairwise), KeyRSC=0, Nonce=ANonce, MIC=0)       */
 1213      if (AIRPDCAP_EAP_INST(data[offset+1])==0 &&
 1214          AIRPDCAP_EAP_ACK(data[offset+1])==1 &&
 1215          AIRPDCAP_EAP_MIC(data[offset])==0)
 1216      {
 1217          AIRPDCAP_DEBUG_PRINT_LINE("AirPDcapRsna4WHandshake", "4-way handshake message 1", AIRPDCAP_DEBUG_LEVEL_3);
 1218   
 1219          /* On reception of Message 1, the Supplicant determines whether the Key Replay Counter field value has been                     */
 1220          /* used before with the current PMKSA. If the Key Replay Counter field value is less than or equal to the current       */
 1221          /* local value, the Supplicant discards the message.                                                                                                                                                                    */
 1222          /* -> not checked, the Authenticator will be send another Message 1 (hopefully!)                                                                                                */
 1223   
 1224          /* save ANonce (from authenticator)     to derive the PTK with the SNonce (from the 2 message)  */
 1225          memcpy(sa->wpa.nonce, data+offset+12, 32);
 1226   
 1227          /* get the Key Descriptor Version (to select algorithm used in decryption -CCMP or TKIP-)       */
 1228          sa->wpa.key_ver=AIRPDCAP_EAP_KEY_DESCR_VER(data[offset+1]);
 1229   
 1230          sa->handshake=1;
 1231   
 1232          return AIRPDCAP_RET_SUCCESS_HANDSHAKE;
 1233      }
 1234   
 1235      /* message 2|4: Supplicant->Authenticator (Sec=0|1, Mic=1, Ack=0, Inst=0, Key=1(pairwise), KeyRSC=0, Nonce=SNonce|0, MIC=MIC(KCK,EAPOL))    */
 1236      if (AIRPDCAP_EAP_INST(data[offset+1])==0 &&
 1237          AIRPDCAP_EAP_ACK(data[offset+1])==0 &&
 1238          AIRPDCAP_EAP_MIC(data[offset])==1)
 1239      {
 1240          if (AIRPDCAP_EAP_SEC(data[offset])==0) {
 1241   
 1242              /* PATCH:   some implementations set secure bit to 0 also in the 4th message                */
 1243              /*          to recognize which message is this check if wep_key data length is 0            */
 1244              /*          in the 4th message                                                              */
 1245              if (data[offset+92]!=0 || data[offset+93]!=0) {
 1246                  /* message 2    */
 1247                  AIRPDCAP_DEBUG_PRINT_LINE("AirPDcapRsna4WHandshake", "4-way handshake message 2", AIRPDCAP_DEBUG_LEVEL_3);
 1248   
 1249                  /* On reception of Message 2, the Authenticator checks that the key replay counter corresponds to the   */
 1250                  /* outstanding Message 1. If not, it silently discards the message.                                                                                             */
 1251                  /* If the calculated MIC does not match the MIC that the Supplicant included in the EAPOL-Key frame,    */
 1252                  /* the Authenticator silently discards Message 2.                                                                                                                                               */
 1253                  /* -> not checked; the Supplicant will send another message 2 (hopefully!)                                                                              */
 1254   
 1255                  /* now you can derive the PTK   */
 1256                  for (key_index=0; key_index<(INT)ctx->keys_nr || useCache; key_index++) {
 1257                      /* use the cached one, or try all keys      */
 1258                      if (!useCache) {
 1259                          AIRPDCAP_DEBUG_PRINT_LINE("AirPDcapRsna4WHandshake", "Try WPA key...", AIRPDCAP_DEBUG_LEVEL_3);
 1260                          tmp_key=&ctx->keys[key_index];
 1261                      } else {
 1262                          /* there is a cached key in the security association, if it's a WPA key try it...       */
 1263                          if (sa->key!=NULL &&
 1264                              (sa->key->KeyType==AIRPDCAP_KEY_TYPE_WPA_PWD ||
 1265                               sa->key->KeyType==AIRPDCAP_KEY_TYPE_WPA_PSK ||
 1266                               sa->key->KeyType==AIRPDCAP_KEY_TYPE_WPA_PMK)) {
 1267                                  AIRPDCAP_DEBUG_PRINT_LINE("AirPDcapRsna4WHandshake", "Try cached WPA key...", AIRPDCAP_DEBUG_LEVEL_3);
 1268                                  tmp_key=sa->key;
 1269                          } else {
 1270                              AIRPDCAP_DEBUG_PRINT_LINE("AirPDcapRsna4WHandshake", "Cached key is of a wrong type, try WPA key...", AIRPDCAP_DEBUG_LEVEL_3);
 1271                              tmp_key=&ctx->keys[key_index];
 1272                          }
 1273                      }
 1274   
 1275                      /* obviously, try only WPA keys...  */
 1276                      if (tmp_key->KeyType==AIRPDCAP_KEY_TYPE_WPA_PWD ||
 1277                          tmp_key->KeyType==AIRPDCAP_KEY_TYPE_WPA_PSK ||
 1278                          tmp_key->KeyType==AIRPDCAP_KEY_TYPE_WPA_PMK)
 1279                      {
 1280                          if (tmp_key->KeyType == AIRPDCAP_KEY_TYPE_WPA_PWD && tmp_key->UserPwd.SsidLen == 0 && ctx->pkt_ssid_len > 0 && ctx->pkt_ssid_len <= AIRPDCAP_WPA_SSID_MAX_LEN) {
 1281                              /* We have a "wildcard" SSID.  Use the one from the packet. */
 1282                              memcpy(&pkt_key, tmp_key, sizeof(pkt_key));
 1283                              memcpy(&pkt_key.UserPwd.Ssid, ctx->pkt_ssid, ctx->pkt_ssid_len);
 1284                               pkt_key.UserPwd.SsidLen = ctx->pkt_ssid_len;
 1285                              AirPDcapRsnaPwd2Psk(pkt_key.UserPwd.Passphrase, pkt_key.UserPwd.Ssid,
 1286                                  pkt_key.UserPwd.SsidLen, pkt_key.KeyData.Wpa.Psk);
 1287                              tmp_key = &pkt_key;
 1288                          }
 1289   
 1290                          /* derive the PTK from the BSSID, STA MAC, PMK, SNonce, ANonce  */
 1291                          AirPDcapRsnaPrfX(sa,                    /* authenticator nonce, bssid, station mac      */
 1292                              tmp_key->KeyData.Wpa.Pmk,   /* PMK  */
 1293                              data+offset+12,             /* supplicant nonce     */
 1294                              512,
 1295                              sa->wpa.ptk);
 1296   
 1297                          /* verify the MIC (compare the MIC in the packet included in this message with a MIC calculated with the PTK)   */
 1298                          eapol_len=pntohs(data+offset-3)+4;
 1299                          memcpy(eapol, &data[offset-5], (eapol_len<AIRPDCAP_EAPOL_MAX_LEN?eapol_len:AIRPDCAP_EAPOL_MAX_LEN));
 1300                          ret_value=AirPDcapRsnaMicCheck(eapol,                                           /*      eapol frame (header also)               */
 1301                              eapol_len,                                                                                                  /*      eapol frame length                              */
 1302                              sa->wpa.ptk,                                                                                                /*      Key Confirmation Key                            */
 1303[+]                             AIRPDCAP_EAP_KEY_DESCR_VER(data[offset+1]));                /*      EAPOL-Key description version   */
 1304   
 1305                          /* If the MIC is valid, the Authenticator checks that the RSN information element bit-wise matches              */
 1306                          /* that from the (Re)Association Request message.                                                                                                                                               */
 1307                          /*              i) TODO If these are not exactly the same, the Authenticator uses MLME-DEAUTHENTICATE.request   */
 1308                          /* primitive to terminate the association.                                                                                                                                                              */
 1309                          /*              ii) If they do match bit-wise, the Authenticator constructs Message 3.                                                                  */
 1310                      }
 1311   
 1312                      if (!ret_value &&
 1313                          (tmp_key->KeyType==AIRPDCAP_KEY_TYPE_WPA_PWD ||
 1314                          tmp_key->KeyType==AIRPDCAP_KEY_TYPE_WPA_PSK ||
 1315                          tmp_key->KeyType==AIRPDCAP_KEY_TYPE_WPA_PMK))
 1316                      {
 1317                          /* the temporary key is the correct one, cached in the Security Association     */
 1318   
 1319                          sa->key=tmp_key;
 1320   
 1321                          if (key!=NULL) {
 1322                              memcpy(key, &tmp_key, sizeof(AIRPDCAP_KEY_ITEM));
 1323                              if (AIRPDCAP_EAP_KEY_DESCR_VER(data[offset+1])==AIRPDCAP_WPA_KEY_VER_NOT_CCMP)
 1324                                  key->KeyType=AIRPDCAP_KEY_TYPE_TKIP;
 1325                              else if (AIRPDCAP_EAP_KEY_DESCR_VER(data[offset+1])==AIRPDCAP_WPA_KEY_VER_AES_CCMP)
 1326                                  key->KeyType=AIRPDCAP_KEY_TYPE_CCMP;
 1327                          }
 1328   
 1329                          break;
 1330                      } else {
 1331                          /* the cached key was not valid, try other keys */
 1332   
 1333                          if (useCache==TRUE) {
 1334                              useCache=FALSE;
 1335                              key_index--;
Show more  




Change Warning 1101.30500 : Buffer Overrun

Priority:
State:
Finding:
Owner:
Note: