A simple script to verify the MESSAGE-INTEGRITY field of a STUN message. Also as a sample to calculate the MESSAGE-INTEGRITY field.
To use it, you need to select the STUN message part in Wireshark, copy the whole STUN message (no IP/UDP headers included) as Bytes (Hex Stream), then calls: ./msgintegirty.py passwd hexstream
Here is an example:
$ ./msg_integirty.py xa/ykWBKUukRHCxH8O1hkQbo 000100542112a442e4e8b0fd9c2294326 5a6f9fd0006000c617957763a653343660000000024000478ffffff802900080000000030333233 8054000431000000807000040000000200080014eb7db09217a9a9cdded592c200f3c372dd1c741 7802800048abb842c
The Integrity calculated is: eb7db09217a9a9cdded592c200f3c372dd1c7417 Integrity MATCH!
#!/usr/bin/env python import hmac import hashlib import sys def align_to_64(data): length = len(data) i = 64 while i < length: i += 64 return data + '\x00'*(i-length) def cal_integ(passwd, stun_msg): msg_to_check = stun_msg[:-(24+8)] # strip the MESSAGE-INTEGRITY and FINGERPRINT part dummy_msg = align_to_64(msg_to_check) integ = hmac.new(passwd, dummy_msg, hashlib.sha1) return integ def match_stun_integrity(passwd, stun_msg): integ_in_msg = stun_msg[-28:-8] integ = cal_integ(passwd, stun_msg) print "The Integrity calculated is:", integ.hexdigest() if integ_in_msg == integ.digest(): print "Integrity MATCH!" else: print "Integrity DOES NOT MATH!!" def hex_to_string(hex_stream): i = 0 charlist = [] while i < len(hex_stream): charlist.append(chr(eval('0x' + hex_stream[i:i+2]))) i+=2 return ''.join(charlist) def main(passwd, stun_hex_stream): stun_msg = hex_to_string(stun_hex_stream) match_stun_integrity(passwd, stun_msg) if __name__ == '__main__': if len(sys.argv) < 3: print "Usage: msg_integrity passwd stun_hex_stram" else: main(sys.argv[1], sys.argv[2])
You need to login to post a comment.
