开发者

How to decrypt wpa 2 psk with openssl, programming in c

开发者 https://www.devze.com 2023-03-29 09:19 出处:网络
I need to decrypt wpa 2 psk programming in c. Assuming that i alredy have the TK (need to decrypt only unicast) I\'m trying to decrypt packets whit the following code (with no luck actually):

I need to decrypt wpa 2 psk programming in c. Assuming that i alredy have the TK (need to decrypt only unicast) I'm trying to decrypt packets whit the following code (with no luck actually):

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#inc开发者_JAVA技巧lude <openssl/pem.h>
#include <openssl/bn.h>
#include <openssl/aes.h>


    struct ctr_state { 
unsigned char ivec[128];   
unsigned int num; 
unsigned char ecount[128]; 
}; 

 void init_ctr(struct ctr_state *state, const unsigned char iv[16]){     //
    state->num = 0; 
    memset(state->ecount, 0, 128);
    memset(state->ivec, 0, 128); 
    memcpy(state->ivec, iv, 16);
} 

char * extochar(char * in, int inLen){
    int i,k;
    int resInt[inLen/2];
    char * resChar=malloc(inLen/2);

    k=0;
    for(i=0; i<inLen/2; i=i++){
            resInt[k]=chartoint(in[i*2])<<4;
            resInt[k]+=chartoint(in[(i*2)+1]);
            k++;
    }

    for(k=0; k<inLen/2;k++){
            resChar[k]=(char)resInt[k];
    }
    return resChar;
}

int chartoint(char car){
    int intero = 0;
    intero = car - '0';
    if(intero < 10 && intero > -1)
            return intero;
    else
            return car - 'a' + 10; 
}

void main(){        

    unsigned char * po = extochar("00",2);
    unsigned char * a2 = extochar("0012f0be7301",12);
    unsigned char * pn = extochar("000000000052",12);
    unsigned char * nonce= malloc(13);
    char * hextk= "15b1657878b1d12c93b4e073e42b629a";
    unsigned char * tk= extochar(hexstr, strlen(hextk));
    init_ctr(&status, nonce);

    nonce[0]=po[0];        
    nonce[1]=a2[0];
    nonce[2]=a2[1];
    nonce[3]=a2[2];
    nonce[4]=a2[3];
    nonce[5]=a2[4];
    nonce[6]=a2[5];
    nonce[7]=pn[0];
    nonce[8]=pn[1];
    nonce[9]=pn[2];
    nonce[10]=pn[3];
    nonce[11]=pn[4];
    nonce[12]=pn[5];

    AES_KEY aes_key;
    if(AES_set_encrypt_key(tk, 128, &aes_key))
            exit(-1);
    //encrypted payload
    char * ext_crypt = "146a056e3b20ece434594373a0e4fcbc83114c9a1bc158ecc4ca6bb449d6ec8468c8e08af3f4f33ce961f7b42c7651e22042e0bf39bd864a1b5f1035af5a54986183ee79446e3fb80a6f9bbb7a0177f557ce192c5515bd3a671b73464b9cf0fb817fd614987b65c0e20d753dedab8bf1934294e112cb865effb14724a2c66fcc7956f8fcfb0f7f2e539fbbf4e30c08fc18d10eb143510eae8b88e911c1cee773b73cdaf6d45151ad01fb2e2f5aa014510a";
    int msg_len= strlen(ext_crypt)/2 - 12;
    unsigned char * crypt =  extochar(ext_crypt, strlen(ext_crypt));
    AES_ctr128_encrypt(crypt, cleartxt, msg_len, &aes_key, status.ivec, status.ecount, &status.num);

}

The output should be something like that: -SEARCH * HTTP/1.1 HOST: 239.255.255.250:1900 MAN: "ssdp:discover" MX: 2 ST: urn:schemas-upnp-org:service:WANPPPConnection:1

I pasted the source of the encrypted packet here: http://pastebin.com/RvkfSt54 are there any problems in the code or in the data, and how can I solve them? thanks a lot!


Aside from the code being uncommented and somewhat poorly formatted... your question whether there are "any problems in the code" can be answered by your compiler, if you enable warnings (which you should always do):

test.c: In function ‘extochar’:
test.c:28:26: warning: operation on ‘i’ may be undefined
test.c:29:13: warning: implicit declaration of function ‘chartoint’
test.c: At top level:
test.c:40:5: error: conflicting types for ‘chartoint’
test.c:40:1: note: an argument type that has a default promotion can’t match an empty parameter name list declaration
test.c:29:23: note: previous implicit declaration of ‘chartoint’ was here
test.c:49:6: warning: return type of ‘main’ is not ‘int’
test.c: In function ‘main’:
test.c:51:26: warning: pointer targets in initialization differ in signedness
test.c:52:26: warning: pointer targets in initialization differ in signedness
test.c:53:26: warning: pointer targets in initialization differ in signedness
test.c:56:34: error: ‘hexstr’ undeclared (first use in this function)
test.c:56:34: note: each undeclared identifier is reported only once for each function it appears in
test.c:57:15: error: ‘status’ undeclared (first use in this function)
test.c:79:30: warning: pointer targets in initialization differ in signedness
test.c:80:31: error: ‘cleartxt’ undeclared (first use in this function)
0

精彩评论

暂无评论...
验证码 换一张
取 消