def dump_Payload(avps): for avp in avps: (name, value) = decodeAVP(avp) if name == 'EAP-Payload': print 'Response:', name, '=', value.encode('hex') E = eap.decode_EAP(value.encode('hex')) for eavp in E.avps: (code, data) = eavp print code, '=', data else: print 'Response:', name, '=', value
def dump_Payload(avps): for avp in avps: (name, value) = decodeAVP(avp) if name == 'EAP-Payload': print(f'Response: {name}={codecs.decode(value, encoding="hex")})') E = eap.decode_EAP(value.encode('hex')) for eavp in E.avps: (code, data) = eavp print(code, '=', data) else: print(f'Response: {name}=^{value}')
def dump_Payload(avps): for avp in avps: (name,value)=decodeAVP(avp) if name=='EAP-Message': print 'Response:',name,'=',value.encode('hex') E=eap.decode_EAP(value.encode('hex')) for eavp in E.avps: (code,data)=eavp print code,'=',data else: print 'Response:',name,'=',value.encode("hex")
def dump_Payload(avps): for avp in avps: (name, value) = decodeAVP(avp) if name == "EAP-Payload": print "Response:", name, "=", value.encode("hex") E = eap.decode_EAP(value.encode("hex")) for eavp in E.avps: (code, data) = eavp print code, "=", data else: print "Response:", name, "=", value
# Set command code # Remember - Requests normally starts from AAA-> UE, so # even when skipped, identity is actually an response EAP.cmd = eap.EAP_CODE_RESPONSE # Set id EAP.id = 1 # Set type EAP.type = eap.EAP_TYPE_AKA # Set sub-type EAP.stype = eap.dictEAPSUBname2type("AKA-Identity") I = "0031303231313131323334353631303540776c616e2e6d6e633032332e6d63633236322e336770706e6574776f726b2e6f7267" print len(I), len(I) / 4, len(I) / 8 IDENTITY = I.decode("hex") EAP.avps.append(("AT_IDENTITY", IDENTITY.encode("hex"))) Payload = eap.encode_EAP(EAP) print "S Payload", Payload # Payload now contains EAP-Payload AVP E = eap.decode_EAP(Payload) print "=" * 30 print eap.getEAPCodeName(E.code) (et, er) = eap.getEAPTypeName(E.type) if er == 0: print "Type:", et if E.stype != 0: x = eap.dictEAPSUBtype2name(E.stype) print "Subtype:", x for avp in E.avps: (code, data) = avp print code, "=", data print "-" * 30
# Create Identity Payload msg = create_Identity_Request() # msg now contains EAP Request+Identity Payload as hex string logging.debug("+" * 30) # send data Conn.send(msg.decode("hex")) # Receive response received = Conn.recv(MSG_SIZE) # Process response EAPAnyId = HDRItem() stripHdr(EAPAnyId, received.encode("hex")) Identity_avps = splitMsgAVPs(EAPAnyId.msg) Identity_Payload = findAVP("EAP-Payload", Identity_avps) # Display response for better undestanding dump_Payload(Identity_avps) E = eap.decode_EAP(Identity_Payload.encode('hex')) ########################################################### # If Identity round is not skipped, we need to send AT_IDENTITY # Create Identity Payload #msg=create_Identity_Response(E.id,ETYPE) # msg now contains EAP Request+Identity Payload as hex string #logging.debug("+"*30) # send data #Conn.send(msg.decode("hex")) # Receive response #received = Conn.recv(MSG_SIZE) ########################################################### # Process Challenge # split header and AVPs EAPChallenge = HDRItem() stripHdr(EAPChallenge, received.encode("hex"))
msg = create_Identity_Request() # msg now contains EAP Request+Identity Payload as hex string logging.debug("+" * 30) # send data Conn.send(codecs.decode(msg, encoding="hex")) # Receive response received = Conn.recv(MSG_SIZE) # Process response EAPAnyId = HDRItem() stripHdr(EAPAnyId, codecs.encode(received, encoding="hex")) Identity_avps = splitMsgAVPs(EAPAnyId.msg) Identity_Payload = findAVP("EAP-Payl" "oad", Identity_avps) # Display response for better undestanding dump_Payload(Identity_avps) E = eap.decode_EAP(codecs.encode(Identity_Payload, encoding="hex")) ########################################################### # If Identity round is not skipped, we need to send AT_IDENTITY # Create Identity Payload # msg=create_Identity_Response(E.id,ETYPE) # msg now contains EAP Request+Identity Payload as hex string # logging.debug("+"*30) # send data # Conn.send(msg.decode("hex")) # Receive response # received = Conn.recv(MSG_SIZE) ########################################################### # Process Challenge # split header and AVPs EAPChallenge = HDRItem() stripHdr(EAPChallenge, codecs.encode(received, encoding="hex"))
# msg now contains EAP Request+Identity Payload as hex string logging.debug("+"*30) # send data Conn.sendto(msg.decode("hex"),(HOST,PORT)) # Receive response received = Conn.recv(MSG_SIZE) # Process response EAPAnyId=HDRItem() stripHdr(EAPAnyId,received.encode("hex")) RID=EAPAnyId.Identifier+1 Identity_avps=splitMsgAVPs(EAPAnyId.msg) Identity_Payload=findAVP("EAP-Message",Identity_avps) STATE=findAVP("State",Identity_avps) # Display response for better undestanding dump_Payload(Identity_avps) E=eap.decode_EAP(Identity_Payload.encode('hex')) ########################################################### # If Identity round is not skipped, we need to send AT_IDENTITY msg=create_Identity_Response(RID,E.id,ETYPE) # msg now contains EAP Request+Identity Payload as hex string logging.debug("+"*30) # send data Conn.sendto(msg.decode("hex"),(HOST,PORT)) # Receive response received = Conn.recv(MSG_SIZE) ########################################################### # Process Challenge # split header and AVPs EAPChallenge=HDRItem() stripHdr(EAPChallenge,received.encode("hex")) RID=EAPChallenge.Identifier+1
# This software is distributed under the terms of BSD license. ################################################################## # decoding EAP-Payload value into AVPs from libDiameter import * import eap import sys if __name__ == "__main__": # level for decoding are: DEBUG, INFO, WARNING, ERROR, CRITICAL logging.basicConfig(level=logging.DEBUG) LoadDictionary("dictDiameter.xml") eap.LoadEAPDictionary("dictEAP.xml") msg = sys.argv[1] #msg="01020014120A00000F020002000100000D010000" print msg E = eap.decode_EAP(msg) print "=" * 30 print eap.getEAPCodeName(E.code) (et, er) = eap.getEAPTypeName(E.type) if er == 0: print "Type:", et if E.stype != 0: x = eap.dictEAPSUBtype2name(E.stype) print "Subtype:", x for avp in E.avps: (code, data) = avp print code, "=", data print "-" * 30
# This software is distributed under the terms of BSD license. ################################################################## # decoding EAP-Payload value into AVPs import eap import sys import logging if __name__ == "__main__": # level for decoding are: DEBUG, INFO, WARNING, ERROR, CRITICAL logging.basicConfig(level=logging.DEBUG) eap.LoadEAPDictionary("dictEAP.xml") msg=sys.argv[1] #msg="01020014120A00000F020002000100000D010000" print msg E=eap.decode_EAP(msg) print "="*30 print eap.getEAPCodeName(E.code) (et,er)=eap.getEAPTypeName(E.type) if er==0: print "Type:",et if E.stype!=0: x=eap.dictEAPSUBtype2name(E.stype) print "Subtype:",x for avp in E.avps: (code,data)=avp print code,"=",data print "-"*30
# Set command code # Remember - Requests normally starts from AAA-> UE, so # even when skipped, identity is actually an response EAP.cmd=eap.EAP_CODE_RESPONSE # Set id EAP.id=1 # Set type EAP.type=eap.EAP_TYPE_AKA # Set sub-type EAP.stype=eap.dictEAPSUBname2type("AKA-Identity") I="0031303231313131323334353631303540776c616e2e6d6e633032332e6d63633236322e336770706e6574776f726b2e6f7267" print len(I),len(I)/4, len(I)/8 IDENTITY=I.decode("hex") EAP.avps.append(("AT_IDENTITY",IDENTITY.encode("hex"))) Payload=eap.encode_EAP(EAP) print "S Payload",Payload # Payload now contains EAP-Payload AVP E=eap.decode_EAP(Payload) print "="*30 print eap.getEAPCodeName(E.code) (et,er)=eap.getEAPTypeName(E.type) if er==0: print "Type:",et if E.stype!=0: x=eap.dictEAPSUBtype2name(E.stype) print "Subtype:",x for avp in E.avps: (code,data)=avp print code,"=",data print "-"*30