├── LICENSE ├── MobileOperators.txt ├── README.md ├── dh ├── decorators.py ├── diffiehellman.py ├── exceptions.py └── primes.py ├── epdg_utils.py ├── ikev2_class.py └── vowifi_scanner.py /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 Spinlogic S.L., Albacete, Spain 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /MobileOperators.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Spinlogic/epdg_discoverer/c7697fdc6aa44e7506533bbb6929be2aa919421c/MobileOperators.txt -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ePDG discoverer 2 | Resolves the IP addresses of ePDGs from most mobile operators in the world and checks if each ePDG responds to ICMP and whether it accepts IKEv2 connection 3 | 4 | ## Introduction 5 | 3GPP specification TS23.402 defines the network architecture for non-3GPP accesses. The most important of such access technologies is IEEE 802.11 (i.e. WiFi). 6 | There are basically two architectural variants, one for "trusted" WiFi access and one for "untrusted" WiFi access. The "untrusted" access variant is currently the most commonly used by cellular network operators around the world. 7 | 8 | In the "untrusted" case, the clients (mobile phones) establish a secure connection to a node called ePDG (evolved Packet Data Gateway). 9 | 10 | Untrusted WLAN access is used to provide VoWiFi (Voice over WiFi) service. 11 | 12 | ## ePDG address resolution 13 | For any mobile network operator, the URI of their ePDG's is defined in 3GPP TS23.003 as follows: 14 | 15 | >epdg.epc.mcc<_mcc_>.mnc<_mnc_>.pub.3gppnetwork.org 16 | 17 | where <_mcc_> is the three digits mobile country code of the country of the operator and <_mnc_> is the mobile network code of the operator in this country, with three digits length (add zeros on the left of the mnc if it has with less than three digits). 18 | 19 | For example, Spain has mcc = 214 and Movistar (Telefónica) has mnc = 07 in Spain. Therefore the URI for Movistar ePDG's is: 20 | 21 | >epdg.epc.mcc214.mnc007.pub.3gppnetwork.org 22 | 23 | The script does both, IPv4 and IPv6, resolutions. If the ePDG resolves to multiple addresses, then each IP address is in one line in the output file. 24 | 25 | ## Usage 26 | >vowifi_scanner <_operatorsfilename_> <_outputfilename_> 27 | 28 | where: 29 | 30 | * **operatorfilename** is a file with the list of operators to check. It is a tap separated values file in which the first column is the mcc, the second is the mnc, the third is the operator name and the fourth is the country name. 31 | * **outputfilename** is the output file. It is also a tab separated values file for which the first four columns are the same as for the operatorfilename, the fifth column is the IP address of the ePDG, the sixth column shows whether the ePDG responds to ICMP echo, and the seventh column shows the packet length to IKEv2_SA_INIT request. This file can easily be imported by all major spreadsheets. 32 | 33 | ## Dependencies 34 | This script uses [scapy3k](https://github.com/phaethon/scapy). As of February 2018, this code does not work with the official distribution of [scapy](https://github.com/secdev/scapy) 35 | The Diffie-Hellman key exchange is derived from [diffiehellman](https://github.com/chrisvoncsefalvay/diffiehellman) , but it has been modified to include DH Group 2 and 128 bit keys. -------------------------------------------------------------------------------- /dh/decorators.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | # borrowed from https://github.com/chrisvoncsefalvay/diffiehellman 4 | 5 | # 6 | # The MIT License (MIT) 7 | # 8 | # Copyright (c) 2016 Chris von Csefalvay 9 | # 10 | # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 11 | # associated documentation files (the "Software"), to deal in the Software without restriction, 12 | # including without limitation the rights to use, copy, modify, merge, publish, distribute 13 | # sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 14 | # furnished to do so, subject to the following conditions: 15 | # 16 | # The above copyright notice and this permission notice shall be included in all copies or 17 | # substantial portions of the Software. 18 | # 19 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 20 | # NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 22 | # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | # 25 | 26 | 27 | """ 28 | decorators declares some decorators that ensure the object has the 29 | correct keys declared when need be. 30 | """ 31 | 32 | 33 | def requires_private_key(func): 34 | """ 35 | Decorator for functions that require the private key to be defined. 36 | """ 37 | 38 | def func_wrapper(self, *args, **kwargs): 39 | if hasattr(self, "_DiffieHellman__private_key"): 40 | func(self, *args, **kwargs) 41 | else: 42 | self.generate_private_key() 43 | func(self, *args, **kwargs) 44 | 45 | return func_wrapper 46 | 47 | 48 | def requires_public_key(func): 49 | """ 50 | Decorator for functions that require the public key to be defined. By definition, this includes the private key, as such, it's enough to use this to effect definition of both public and private key. 51 | """ 52 | 53 | def func_wrapper(self, *args, **kwargs): 54 | if hasattr(self, "public_key"): 55 | func(self, *args, **kwargs) 56 | else: 57 | self.generate_public_key() 58 | func(self, *args, **kwargs) 59 | 60 | return func_wrapper 61 | -------------------------------------------------------------------------------- /dh/diffiehellman.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | # base code borrowed from https://github.com/chrisvoncsefalvay/diffiehellman 4 | # modified to support DH group 2 and short keys (128 bits) 5 | 6 | # 7 | # The MIT License (MIT) 8 | # 9 | # Copyright (c) 2016 Chris von Csefalvay 10 | # 11 | # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 12 | # associated documentation files (the "Software"), to deal in the Software without restriction, 13 | # including without limitation the rights to use, copy, modify, merge, publish, distribute 14 | # sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 15 | # furnished to do so, subject to the following conditions: 16 | # 17 | # The above copyright notice and this permission notice shall be included in all copies or 18 | # substantial portions of the Software. 19 | # 20 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 21 | # NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 23 | # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | # 26 | 27 | 28 | 29 | 30 | """ 31 | diffiehellmann declares the main key exchange class. 32 | """ 33 | 34 | __version__ = '0.13.4' 35 | 36 | from hashlib import sha256 37 | 38 | from dh.decorators import requires_private_key 39 | from dh.exceptions import MalformedPublicKey, RNGError 40 | from dh.primes import PRIMES 41 | 42 | try: 43 | from ssl import RAND_bytes 44 | rng = RAND_bytes 45 | except(AttributeError, ImportError): 46 | raise RNGError 47 | 48 | 49 | class DiffieHellman: 50 | """ 51 | Implements the Diffie-Hellman key exchange protocol. 52 | 53 | """ 54 | 55 | def __init__(self, 56 | group=2, 57 | key_length=128): 58 | 59 | self.key_length = max(100, key_length) 60 | self.generator = PRIMES[group]["generator"] 61 | self.prime = PRIMES[group]["prime"] 62 | 63 | def generate_private_key(self): 64 | """ 65 | Generates a private key of key_length bits and attaches it to the object as the __private_key variable. 66 | 67 | :return: void 68 | :rtype: void 69 | """ 70 | key_length = self.key_length // 8 + 8 71 | key = 0 72 | 73 | try: 74 | key = int.from_bytes(rng(key_length), byteorder='big') 75 | except: 76 | key = int(hex(rng(key_length)), base=16) 77 | 78 | self.__private_key = key 79 | 80 | def verify_public_key(self, other_public_key): 81 | return self.prime - 1 > other_public_key > 2 and pow(other_public_key, (self.prime - 1) // 2, self.prime) == 1 82 | 83 | @requires_private_key 84 | def generate_public_key(self): 85 | """ 86 | Generates public key. 87 | 88 | :return: void 89 | :rtype: void 90 | """ 91 | self.public_key = pow(self.generator, 92 | self.__private_key, 93 | self.prime) 94 | 95 | @requires_private_key 96 | def generate_shared_secret(self, other_public_key, echo_return_key=False): 97 | """ 98 | Generates shared secret from the other party's public key. 99 | 100 | :param other_public_key: Other party's public key 101 | :type other_public_key: int 102 | :param echo_return_key: Echo return shared key 103 | :type bool 104 | :return: void 105 | :rtype: void 106 | """ 107 | if self.verify_public_key(other_public_key) is False: 108 | raise MalformedPublicKey 109 | 110 | self.shared_secret = pow(other_public_key, 111 | self.__private_key, 112 | self.prime) 113 | 114 | shared_secret_as_bytes = self.shared_secret.to_bytes(self.shared_secret.bit_length() // 8 + 1, byteorder='big') 115 | 116 | _h = sha256() 117 | _h.update(bytes(shared_secret_as_bytes)) 118 | 119 | self.shared_key = _h.hexdigest() 120 | #self.shared_key = shared_secret_as_bytes 121 | 122 | if echo_return_key is True: 123 | return self.shared_key -------------------------------------------------------------------------------- /dh/exceptions.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | # borrowed from https://github.com/chrisvoncsefalvay/diffiehellman 4 | 5 | # 6 | # (c) Chris von Csefalvay, 2015. 7 | 8 | """ 9 | exceptions is responsible for exception handling etc. 10 | """ 11 | 12 | 13 | class MalformedPublicKey(BaseException): 14 | """ 15 | The public key is malformed as it does not meet the Legendre symbol criterion. The key might have been tampered with or might have been damaged in transit. 16 | """ 17 | 18 | def __str__(self): 19 | return "Public key malformed: fails Legendre symbol verification." 20 | 21 | 22 | class RNGError(BaseException): 23 | """ 24 | Thrown when RNG could not be obtained. 25 | """ 26 | 27 | def __str__(self): 28 | return "RNG could not be obtained. This module currently only works with Python 3." -------------------------------------------------------------------------------- /dh/primes.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | # base code borrowed from https://github.com/chrisvoncsefalvay/diffiehellman 4 | 5 | # 6 | # The MIT License (MIT) 7 | # 8 | # Copyright (c) 2016 Chris von Csefalvay 9 | # 10 | # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 11 | # associated documentation files (the "Software"), to deal in the Software without restriction, 12 | # including without limitation the rights to use, copy, modify, merge, publish, distribute 13 | # sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 14 | # furnished to do so, subject to the following conditions: 15 | # 16 | # The above copyright notice and this permission notice shall be included in all copies or 17 | # substantial portions of the Software. 18 | # 19 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 20 | # NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 22 | # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | # 25 | # The primes presented here are (c) The Internet Society, 2003. 26 | # Extracted from: Kivinen, T. and Kojo, M. (2003), _More Modular Exponential (MODP) Diffie-Hellman 27 | # groups for Internet Key Exchange (IKE)_. 28 | # 29 | 30 | """ 31 | primes holds the RFC 3526 MODP primes and their generators. 32 | DH group 2 taken from RFC 7296 (IKEv2) 33 | """ 34 | 35 | PRIMES = { 36 | 2: { 37 | "prime": 0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF, 38 | "generator": 2 39 | }, 40 | 5: { 41 | "prime": 0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA237327FFFFFFFFFFFFFFFF, 42 | "generator": 2 43 | }, 44 | 14: { 45 | "prime": 0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AACAA68FFFFFFFFFFFFFFFF, 46 | "generator": 2 47 | }, 48 | 15: { 49 | "prime": 0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF, 50 | "generator": 2 51 | }, 52 | 16: { 53 | "prime": 0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D788719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA993B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934063199FFFFFFFFFFFFFFFF, 54 | "generator": 2 55 | }, 56 | 17: { 57 | "prime": 0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D788719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA993B4EA988D8FDDC186FFB7DC90A6C08F4DF435C93402849236C3FAB4D27C7026C1D4DCB2602646DEC9751E763DBA37BDF8FF9406AD9E530EE5DB382F413001AEB06A53ED9027D831179727B0865A8918DA3EDBEBCF9B14ED44CE6CBACED4BB1BDB7F1447E6CC254B332051512BD7AF426FB8F401378CD2BF5983CA01C64B92ECF032EA15D1721D03F482D7CE6E74FEF6D55E702F46980C82B5A84031900B1C9E59E7C97FBEC7E8F323A97A7E36CC88BE0F1D45B7FF585AC54BD407B22B4154AACC8F6D7EBF48E1D814CC5ED20F8037E0A79715EEF29BE32806A1D58BB7C5DA76F550AA3D8A1FBFF0EB19CCB1A313D55CDA56C9EC2EF29632387FE8D76E3C0468043E8F663F4860EE12BF2D5B0B7474D6E694F91E6DCC4024FFFFFFFFFFFFFFFF, 58 | "generator": 2 59 | }, 60 | 18: { 61 | "prime": 0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D788719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA993B4EA988D8FDDC186FFB7DC90A6C08F4DF435C93402849236C3FAB4D27C7026C1D4DCB2602646DEC9751E763DBA37BDF8FF9406AD9E530EE5DB382F413001AEB06A53ED9027D831179727B0865A8918DA3EDBEBCF9B14ED44CE6CBACED4BB1BDB7F1447E6CC254B332051512BD7AF426FB8F401378CD2BF5983CA01C64B92ECF032EA15D1721D03F482D7CE6E74FEF6D55E702F46980C82B5A84031900B1C9E59E7C97FBEC7E8F323A97A7E36CC88BE0F1D45B7FF585AC54BD407B22B4154AACC8F6D7EBF48E1D814CC5ED20F8037E0A79715EEF29BE32806A1D58BB7C5DA76F550AA3D8A1FBFF0EB19CCB1A313D55CDA56C9EC2EF29632387FE8D76E3C0468043E8F663F4860EE12BF2D5B0B7474D6E694F91E6DBE115974A3926F12FEE5E438777CB6A932DF8CD8BEC4D073B931BA3BC832B68D9DD300741FA7BF8AFC47ED2576F6936BA424663AAB639C5AE4F5683423B4742BF1C978238F16CBE39D652DE3FDB8BEFC848AD922222E04A4037C0713EB57A81A23F0C73473FC646CEA306B4BCBC8862F8385DDFA9D4B7FA2C087E879683303ED5BDD3A062B3CF5B3A278A66D2A13F83F44F82DDF310EE074AB6A364597E899A0255DC164F31CC50846851DF9AB48195DED7EA1B1D510BD7EE74D73FAF36BC31ECFA268359046F4EB879F924009438B481C6CD7889A002ED5EE382BC9190DA6FC026E479558E4475677E9AA9E3050E2765694DFC81F56E880B96E7160C980DD98EDD3DFFFFFFFFFFFFFFFFF, 62 | "generator": 2 63 | }, 64 | } 65 | -------------------------------------------------------------------------------- /epdg_utils.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Set of helper functions. 4 | """ 5 | 6 | import random, socket 7 | 8 | def RandHexString(length = 16): 9 | '''Generates a random hex string of any legth (16 characters by default)''' 10 | valid_letters='0123456789abcdef' 11 | return ''.join((random.choice(valid_letters) for i in range(length))) 12 | 13 | 14 | 15 | def GetIp(): 16 | '''Gets the IP address of the interface for default route.''' 17 | # Code borrowed from https://stackoverflow.com/questions/166506/finding-local-ip-addresses-using-pythons-stdlib 18 | s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 19 | try: 20 | # doesn't even have to be reachable 21 | s.connect(('10.255.255.255', 1)) 22 | IP = s.getsockname()[0] 23 | except: 24 | IP = '127.0.0.1' 25 | finally: 26 | s.close() 27 | return IP -------------------------------------------------------------------------------- /ikev2_class.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | This class handles IKEv2 state machine for interactions with ePDGs. 4 | Only IPv4 at this time. 5 | """ 6 | 7 | import binascii, hashlib, socket 8 | import logging 9 | from dh.diffiehellman import DiffieHellman 10 | import epdg_utils as eutils 11 | logging.getLogger("scapy3k.runtime").setLevel(logging.ERROR) 12 | from scapy3k.all import * 13 | load_contrib('ikev2') 14 | 15 | 16 | class epdg_ikev2(object): 17 | 18 | def __init__(self, ip_dst, sport, dport): 19 | self.i_spi = binascii.unhexlify(eutils.RandHexString(16)) 20 | self.r_spi = binascii.unhexlify('0' * 16) 21 | self.dst_addr = ip_dst 22 | self.dst_port = dport 23 | self.src_addr = eutils.GetIp() 24 | self.src_port = sport 25 | self.transform_set = {'encrypt': 12, 'prf': 2, 'integr': 2, 'group': 2} 26 | self.dh = DiffieHellman(group = 2, key_length = 128) 27 | self.dh.generate_public_key() 28 | self.i_n = binascii.unhexlify(eutils.RandHexString(32)) 29 | 30 | 31 | def sa_init(self, analyse_response = False): 32 | '''Attempts to set up SA to peer. 33 | 34 | :param analyse_response: Analyse the response from server 35 | :type bool 36 | :return: length of the response from peer 37 | :rtype: int''' 38 | ## calculate nat_detection_source_ip and nat_detection_destination_ip 39 | ip_src = socket.inet_aton(self.src_addr) 40 | ip_dst = socket.inet_aton(self.dst_addr) 41 | src_port = binascii.unhexlify(format(self.src_port, '04x')) 42 | dst_port = binascii.unhexlify(format(self.dst_port, '04x')) 43 | nat_det_src = binascii.unhexlify(hashlib.sha1(self.i_spi + self.r_spi + ip_src + src_port).hexdigest()) 44 | nat_det_dst = binascii.unhexlify(hashlib.sha1(self.i_spi + self.r_spi + ip_dst + dst_port).hexdigest()) 45 | transform_1 = IKEv2_payload_Transform(next_payload = 'Transform', transform_type = 'Encryption', transform_id = 12, length = 12, key_length = 128) 46 | transform_2 = IKEv2_payload_Transform(next_payload = 'Transform', transform_type = 'PRF', transform_id = 2) 47 | transform_3 = IKEv2_payload_Transform(next_payload = 'Transform', transform_type = 'Integrity', transform_id = 2) 48 | transform_4 = IKEv2_payload_Transform(next_payload = 'last', transform_type = 'GroupDesc', transform_id = 2) 49 | packet = IP(dst = self.dst_addr, proto = 'udp') /\ 50 | UDP(sport = self.src_port, dport = self.dst_port) /\ 51 | IKEv2(init_SPI = self.i_spi, next_payload = 'SA', exch_type = 'IKE_SA_INIT', flags='Initiator') /\ 52 | IKEv2_payload_SA(next_payload = 'KE', prop = IKEv2_payload_Proposal(trans_nb = 4, trans = transform_1 / transform_2 / transform_3 / transform_4, )) /\ 53 | IKEv2_payload_KE(next_payload = 'Nonce', group = '1024MODPgr', load = binascii.unhexlify(format(self.dh.public_key, '0256x'))) /\ 54 | IKEv2_payload_Nonce(next_payload = 'Notify', load = self.i_n) /\ 55 | IKEv2_payload_Notify(next_payload = 'Notify', type = 16388, load = nat_det_src) /\ 56 | IKEv2_payload_Notify(next_payload = 'None', type = 16389, load = nat_det_dst) 57 | ans = sr1(packet, timeout = 3, verbose = 0) 58 | if ans == None: 59 | return 0 60 | else: 61 | if(analyse_response): 62 | self.__analyseSAInitResponse(IKEv2(ans[UDP].load)) 63 | return len(ans) 64 | 65 | 66 | def __analyseSAInitResponse(self, ans): 67 | assert ans.init_SPI == self.i_spi 68 | self.r_spi = ans.resp_SPI 69 | try: 70 | self.r_ke = int.from_bytes(ans[IKEv2_payload_KE].load, byteorder='big') 71 | self.r_n = ans[IKEv2_payload_Nonce].load 72 | print('received nonce: {}'.format(self.r_n)) 73 | print('received ke: {}'.format(self.r_ke)) 74 | self.__generateKeys() 75 | except: 76 | print('Proposal not supported by peer.') 77 | 78 | def __generateKeys(self): 79 | # TODO 80 | return None 81 | 82 | -------------------------------------------------------------------------------- /vowifi_scanner.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # The MIT License (MIT) 4 | 5 | # Copyright (c) 2018 Spinlogic S.L., Albacete, Spain 6 | 7 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | # this software and associated documentation files (the "Software"), to deal in 9 | # the Software without restriction, including without limitation the rights to 10 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 11 | # of the Software, and to permit persons to whom the Software is furnished to do 12 | # so, subject to the following conditions: 13 | 14 | # The above copyright notice and this permission notice shall be included in all 15 | # copies or substantial portions of the Software. 16 | 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | # SOFTWARE. 24 | 25 | 26 | ################################################################# 27 | # 28 | # Module : vowifi_scanner.py 29 | # Author : Juan Noguera 30 | # Purpose: This script goes through the list of operators in 31 | # file declared as parameter and finds whether there 32 | # is a DNS entry for the ePDG of each operator. 33 | # 34 | # Input: file generated from http://www.imei.info/operator-codes/ 35 | # 36 | # Output: csv file with the following columns: 37 | # 38 | # Country Operator_Name FQDN_for_ePDG Resolved_IP_Address Responds to ping? length of response to IKEv2_SA_INIT 39 | # 40 | # One entry per IP Address resolved. I.e. if the FQDN of an 41 | # operator resolves to multiple IP Addresses, then this 42 | # operator has multiple consecutive entries. 43 | # 44 | ################################################################# 45 | 46 | """Usage: vowifi_scanner """ 47 | 48 | __version__ = '0.2.0' 49 | 50 | import argparse, binascii, random, dns.resolver 51 | import ikev2_class as ikev2 52 | import logging 53 | import epdg_utils as eutils 54 | logging.getLogger("scapy3k.runtime").setLevel(logging.ERROR) 55 | from scapy3k.all import * 56 | 57 | # --------------------------// Globals /___________________________ 58 | csv_separator = "\t" 59 | 60 | # def nslookupv4(operator_url): 61 | # """performs a dns query for the data contained in operator""" 62 | # try: 63 | # dns_query_result = socket.gethostbyname(operator_url) 64 | # except: 65 | # dns_query_result = "none" 66 | # return dns_query_result 67 | 68 | def nslookup(operator_url): 69 | """"Performs DNS lookup for A (IPv4) and AAAA (IPv6) records""" 70 | dnsres = dns.resolver.Resolver() # create a new instance named 'myResolver' 71 | records = [] 72 | try: 73 | ansv4 = dnsres.query(operator_url, "A") 74 | for record in ansv4: 75 | records.append(record.address) 76 | ansv6 = dnsres.query(operator_url, "AAAA") 77 | for record in ansv6: 78 | records.append(record.address) 79 | except: 80 | pass 81 | return records 82 | 83 | 84 | def respondsToPing(address): 85 | '''Checks if the machine at "address" responds to ICMP Echo requests''' 86 | responds_to_ping = 'No' 87 | if(':' in address): 88 | icmp_sender = sr1(IPv6(dst = address) / ICMPv6EchoRequest(data="HELLO"), timeout = 5, verbose = 0) 89 | else: 90 | icmp_sender = sr1(IP(dst = address)/ ICMP() / "HELLO", timeout = 5, verbose = 0) 91 | if icmp_sender != None: 92 | responds_to_ping = 'Yes' 93 | else: 94 | if icmp_sender != None: 95 | print(icmp_sender.summary()) 96 | return responds_to_ping 97 | 98 | 99 | def iterateoperatorsfile(fn_mobileoperators, fn_output): 100 | """Iterate the operators file checking for ePDG DNS records. If records are found, then check whether the 101 | entry responds to ICMP ECHO requests. 102 | The result for each operator is output as lines in fn_output with format: 103 | MNC \t MCC \t country name \t Operator name \t IPv4v6 address \t Yes/No to question 'responds to ping?' 104 | fn_output is a csv file with tabs as 'separator'""" 105 | global csv_separator 106 | num_lines = 0 107 | op_file = open(fn_mobileoperators, "r") 108 | out_file = open(fn_output, "w") 109 | for line in op_file: 110 | num_lines +=1 111 | csv_line = "" 112 | operator = line.split(csv_separator) 113 | if len(operator) == 3: 114 | mcc = operator[0][:3] 115 | mnc = operator[0][3:].strip() 116 | operator[2] = operator[2].strip("\n") 117 | if(len(mnc) < 3): 118 | if(len(mnc) < 2): 119 | mnc = "00" + mnc 120 | else: 121 | mnc = "0" + mnc 122 | operator_url = "epdg.epc.mnc" + mnc + ".mcc" + mcc + ".pub.3gppnetwork.org" 123 | dns_query_result = nslookup(operator_url) 124 | if len(dns_query_result) > 0 : 125 | for record in dns_query_result: 126 | responds_to_ping = respondsToPing(record) 127 | if(':' in record): # ikev2 class does not support IPv6 128 | sa_resp_length = 0 129 | else: 130 | ikev2_pack = ikev2.epdg_ikev2(record, random.randrange(50000, 55000), 500) 131 | sa_resp_length = ikev2_pack.sa_init() 132 | csv_line = mnc + csv_separator + mcc + csv_separator + operator[2] + csv_separator + operator[1] + csv_separator + record + csv_separator + responds_to_ping + csv_separator + str(sa_resp_length) 133 | out_file.write(csv_line + "\n") 134 | print(csv_line) 135 | else: 136 | csv_line = mnc + csv_separator + mcc + csv_separator + operator[2] + csv_separator + operator[1] + csv_separator + 'none' + csv_separator + 'No' + csv_separator + '0' 137 | out_file.write(csv_line + "\n") 138 | print(csv_line) 139 | # if(num_lines > 10): break 140 | last_line = "Number of operators checked = %d" % num_lines 141 | out_file.write(last_line) 142 | op_file.close() 143 | out_file.close() 144 | 145 | 146 | def main(operators_file, out_file): 147 | iterateoperatorsfile(operators_file, out_file) 148 | 149 | 150 | if __name__ == '__main__': 151 | parser = argparse.ArgumentParser() 152 | parser.add_argument('operators_file', type = str, help = 'File with list of operators and their data') 153 | parser.add_argument('out_file', type = str, help = 'output file (CVS)') 154 | args = parser.parse_args() 155 | main(args.operators_file, args.out_file) --------------------------------------------------------------------------------