-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
i suspect there is something wrong about the mac footer calculated #256
Comments
What hardware are you using? |
i had try apimote and cc2531 on raspbain with python3.7 and python 3.6 it's 0:33 local time now,i will back to my lab after 9 hours |
the apimote should be letting the radio auto generate the crc if you use the inject() function killerbee/killerbee/dev_apimote.py Line 182 in c413761
self.handle.RF_autocrc(1) #let radio add the CRC the RF_txpacket is sending a command to the apimote firmware - you can see the code to handle it here: the CCSPIAPP tells it to use this app - 0x81 is the "verb" to use the ccspi_tx function - then has the packet bytes+length to send |
i guess enc_data is aps_payload in packet with pkcs7padding, what is the args zigbee_data. |
can find implementation for decrypt_ccm here: The parameters for this function are: the zigbee_data is used as auth-data, so it will need to match the same value used during encryption. The decrypted data should be unaffected, the MIC validation will be false if this value doesn't match. |
python3 test.py my code ` data = b'a\x88\xec!8\xb8o\x00\x00\x08\x00\xb8o\x00\x00\x1e~!\xc40\t\xa0\x05\x00\x94J\x84\xfe\xff\xbd\x1b\xec\xdd\xae/>\xde\x19Ff\xb5\xdeHuH\xec\x98B] \x12\xfa\xb4]8>Y\xc87\xa9y0\xc6p\xce\x16\xefM\xdf.\xb97\xeb' ` i try the function in kbdecrypt,some error happen |
hmm failing here: killerbee/killerbee/scapy_extensions.py Line 474 in 3bbf7eb
from your code I see
so it's failing because your packet isn't using an ext_src. I'll keep looking to see how to fix. edit: |
i had try decrypt_ccm. the aes-ccm* result is wrong the packet is(copy from ubiqua) (encrypted packet data) (decrypted packet data) from Crypto.Cipher import AES
from Crypto.Util import Counter
import binascii
from zigbee_crypt import *
from killerbee.scapy_extensions import *
#capture on the air
data = b'a\x88\xec!8\xb8o\x00\x00\x08\x00\xb8o\x00\x00\x1e~!\xc40\t\xa0\x05\x00\x94J\x84\xfe\xff\xbd\x1b\xec\xdd\xae/>\xde\x19Ff\xb5\xdeHuH\xec\x98B] \x12\xfa\xb4]8>Y\xc87\xa9y0\xc6p\xce\x16\xefM\xdf.\xb97\xeb'
def zigbee_aps_decrypt(data):
#select mac payload
#nwk header 8 bytes | nwk payload
mac_payload = data[9 : -2]
nwk_header = mac_payload[:8]
#select nwk payload
#aps header (2 bytes) | aps aux header (13 bytes) | aps payload
#nwk_payload = data[17: -2]
nwk_payload = mac_payload[8:]
aps_header = nwk_payload[:2]
aps_aux_header = nwk_payload[2:15]
# content in APS AUX Header
# APS Security Control (1 bytes) | APS Frame Counter (4 bytes) | Source Address (8 bytes)
#print(aps_aux_header)
aps_security_control = aps_aux_header[0]
aps_frame_counter = aps_aux_header[1:5]
#print(aps_frame_counter)
source_address = aps_aux_header[5:]
#print(source_address)
aps_payload = nwk_payload[15:-4]
print(len(aps_payload))
aps_mic = nwk_payload[-4:]
#print(aps_payload)
#add_auth_data
auth_data = nwk_header + aps_aux_header
add_auth_data = len(auth_data).to_bytes(2, byteorder = 'big') + auth_data
add_auth_data = pkcs7padding(add_auth_data)
#nonce
nonce = source_address + aps_frame_counter + bytes([aps_security_control])
#print(nonce)
enc_data = aps_payload
enc_data1 = pkcs7padding(aps_payload)
zigbee_data = b'a\x88\xec!8\xb8o\x00\x00\x08\x00\xb8o\x00\x00\x1e~!\xc40\t\xa0\x05\x00\x94J\x84\xfe\xff\xbd\x1b\xec'
key = bytes([0x5A, 0x69, 0x67, 0x42, 0x65, 0x65, 0x41, 0x6C, 0x6C,0x69,0x61,0x6E,0x63, 0x65, 0x30, 0x39])
(pt_data, mic_check) = decrypt_ccm(key, nonce, aps_mic, enc_data, zigbee_data)
(pt_data1, mic_check1) = decrypt_ccm(key, nonce, aps_mic, enc_data1, zigbee_data)
print(pt_data)
print(pt_data1)
print(mic_check)
# scapy_packet = Dot15d4(data)
# result = kbdecrypt(scapy_packet, key)
# print(result)
zigbee_aps_decrypt(data) #result
python test.py
35
b"\xd0\xa5`\x14l\x9f\xaa\xf6\xd4\xc6\x86\xf1)\xd1\xc3\x85 W\xf4j\xc1i\xe7\xee\xe8+\xfbV'$ZO\xf4\xf1N"
b"\xd0\xa5`\x14l\x9f\xaa\xf6\xd4\xc6\x86\xf1)\xd1\xc3\x85 W\xf4j\xc1i\xe7\xee\xe8+\xfbV'$ZO\xf4\xf1N\x7f\xf3,\xc1\xfb\xe0\xaa\xd3\xbe\xb9J\x13K"
0 i think i should read the aes-ccm* document andthend read the source code
if i got the true counter, i can use aes_ctr to decrypt it |
I saved the packet you provided as a pcap to view in wireshark. It also noted an issue with the source address and did not seem to be able to parse or decrypt the packet
you can save to pcap by
|
i captue it from ubiqua,the transport key packet with seqnum 0xec,the data in python code is capture from pyCCsniffer. |
Thanks I'll take a look! |
ok,thank you,i work for many days for this thing,i will keep on this weekend. |
i read the zigbee's document about the encryption and decryption
edit: |
Were you able to figure this out? I've tried using
but didn't have success - I am able to see that wireshark decrypts the packet from your pcap with the key ZigBeeAlliance09 |
actually, I think I got this working with the hashed key.
I need to put in a PR to fix the issue with missing ext_src to pull source addr from the ZigbeeSecurityHeader field |
i just have one question can't solved,the first question of this issue. why the association request i send by killerbee is be reject by the zigbee gateway the autocrc(1) result and the makeFCS() result is different in my test. but i don't know how to solve this in the firmware i wirte some function for me to send the zigbee packet function def kb_inject_packet(payload):
global kb_kb
try:
kb_kb.inject(payload)
except Exception as e:
sys.stderr.write("ERROR: Unable to inject packet: {0}".format(e))
sys.exit(-1)
kb_kb.sniffer_off()
def create_beacon_request_packet(seqnum):
#beacon request format
beacon = b"\x03\x08\x00\xff\xff\xff\xff\x07"
beaconp1 = beacon[0:2]
beaconp2 = beacon[3:]
packet = b''.join([beaconp1, b"%c" % seqnum, beaconp2])
return packet
def create_asso_packet(frame_control, seqnum, destination_pan_id, destination_address, source_address, mac_payload):
packet = b''.join([frame_control, b"%c" % seqnum, destination_pan_id, destination_address,
#soure pan id
b'\xff\xff', source_address, mac_payload ])
return packet
def create_data_req_packet(frame_control, seqnum, destination_pan_id, destination_address, source_address, mac_payload):
packet = b''.join([frame_control, b"%c" % seqnum, destination_pan_id, destination_address, source_address, mac_payload ])
return packet
def create_acknowledge_packet(seqnum):
packet = b''.join([b"\x12\x00", b"%c" % seqnum])
return packet
kb_kb = KillerBee("/dev/ttyUSB0") i send packet with these function,and capture packets show in my first question |
What is mac_payload? can you show an example of what payload is that you send to kb_kb.inject(payload) ? |
i had use killerbee to write a tool for zigbee network connect.
i just use the kb.inject to send zigbee packet,with a threading capture process to sniffer the pack by another project from github. i can't capture the beacon back by kb.pnext ,because the gateway response the beacon too fast.
until i solve so many troubles about this tool, i found something that make me feel so weird.
i imitate as a normal zigbee device to send association request, but the zigbee gateway response with a Pan access denied
i capture packets on my windows at the sametime as fllows.
i found the association request packet send by killerbee, and call the crc check function makeFCS, indeed this packet will also be invalidcrc
i can just flow the inject() to RF_txpacket(), i can't find the send packet crc where to calculate. i don't understand the logic of writecmd()
The text was updated successfully, but these errors were encountered: