├── LICENSE ├── README.md ├── gNAS.py ├── gSECURITY.py ├── images ├── ... ├── 5g_aka_authentication.png ├── NWu_Emulator.png ├── eap_aka_prime_authentication.png ├── free5gc_setup.png └── non3gpp_untrusted_authentication.png └── nwu_emulator.py /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NWu-Non3GPP-5GC client 2 | NWu IKEv2/IPSec Client Dialer for 5GC-N3IWF 3 | 4 | This is a NWu and SWu client emulator done in python3 that establishes an IKEv2/IPSec tunnel(s) with N3IWF or ePDG. 5 | This application implements not only the control plane of NWu and SWu (IKEv2 and first SA child (for NWu)) but also the user plane (IPSec). 6 | 7 | To interact with a real N3IWF or ePDG you need to get credentials from the USIM to derive the keys needed for 5G-AKA, EAP-AKA' or EAP-AKA, so once again you need to have a modem that supports the AT command AT+CSIM, or a SmartCard reader, or even through an https server (see https://github.com/fasferraz/USIM-https-server). 8 | 9 | Note: If no Modem/SmartCard Reader/HTTPS Server then a default CK, IK and RES will be used (check corresponding variables inside the code) 10 | 11 | For authentication the application also accepts Ki and OP/OPC for Milenage operation (usefull for testing with developments like open5gs or free5gc, where the USIM parameters are defined in the HSS/UDR). 12 | 13 | 14 | NWu is the interface between UE and the N3IWF as defined by the 3GPP, and is an IKEv2 based protocol with some minor modifications that can be found in 3GPP 33.501, 24.501 and 24.502. The IKEv2 control plane is used to help perform authentication, establish SA Child, either the signalling SA Child or the User Plane SA Child. 15 | 16 | This application can use any network type (Wifi, Fixed, Mobile) to establish an IKEv2 Tunnel towards the N3IWF or ePDG and can be used in a more broader way than just the VoWifi scenario, since any DDN/APN can be requested. 17 | The applications outputs every single KEY and parameter used in the IKEv2 and IPSec processes, which allow us to decode the corresponding traces in wireshark if needed. 18 | 19 | 20 | 21 | This applications supports currently the following RFCs and options: 22 | - IKEv2 RFC 5996 / RFC 7296 23 | - EAP-AKA Authentication RFC 4187 24 | - EAP-AKA' Authentication RFC 5448 25 | - IKEv2 Encryption: AES-CBC-128 and AES-CBC-256 and NULL 26 | - IKEv2 Pseudo Random Function: PRF-HMAC-MD5, PRF-HMAC-SHA1, PRF-HMAC-SHA2-256, PRF-HMAC-SHA2-384 and PRF-HMAC-SHA2-512 27 | - IKEv2 Integrity: HMAC-MD5-96, HMAC-SHA1-96, HMAC-SHA2-256-128, HMAC-SHA2-384-192 and HMAC-SHA2-512-256 28 | - Diffie-Hellman Group: 1, 2, 5, 14, 15, 16, 17 and 18 29 | - IPSec Encryption: AES-CBC-128, AES-CBC-256, AES-GCM-8, AES-CGM-12, AES-GCM-16 and NULL 30 | - No Certificates 31 | - NAT-T Detection 32 | - IKEv2 over UDP port 500 or 4500 33 | - IPSec over ESP or UDP port 4500 34 | - Fast-Reauthentication (currently only supported for SWu) 35 | - IKE and IPSec Rekeying (currently ony supported for SWu) 36 | - 5G-AKA or EAP-AKA' authentication methods with N3IWF for 5G 37 | 38 | https://www.iana.org/assignments/ikev2-parameters/ikev2-parameters.xhtml#ikev2-parameters-6 39 | 40 | The next picture shows the authentication flow for non-3GPP access in 5G: 41 | 42 |

43 | 44 | 45 | There are two methods for authentication: 46 | 47 | - EAP-AKA': 48 | 49 |

50 | 51 | 52 | or 53 | - 5G-AKA: 54 | 55 |

56 | 57 | 58 | 59 | ---- 60 | 61 | The application has 4 distinct processes: 62 | - Main process that handles the IKEv2 flow states 63 | - After establishing the initial SA Child for IPSec (signalling SA Child for NWu or user plane SA child for SWu) three additional processes are created to handle the IPSec Encryption/Decryption: 64 | - IPSec Encoder: 65 | - Gets user data from tunnel interface, encrypts and sends it to N3IWF/ePDG 66 | - Receives info from main process to create/update/delete SA Child 67 | - IPSec Decoder: 68 | - Gets encrypted data from N3IWF/ePDG, decrypts it and sends it to the tunnel interface 69 | - Sends decrypted IKEv2 message to main process (with NAT Traversal since IKEv2 messages are also received in UDP port 4500) 70 | - TCP process: 71 | - Send and receive NAS messages to/from N3IWF, transfered through the signalling SA child 72 | - Send and receive NAS messages to/from Main process 73 | 74 | 75 | The next picture shows an high-level description of this: 76 | 77 |

78 | 79 | 80 | 81 | These are the required modules needed for python3 in order to be able to run the application: 82 | 83 | ``` 84 | import serial 85 | import struct 86 | import socket 87 | import random 88 | import time 89 | import select 90 | import sys 91 | import os 92 | import fcntl 93 | import subprocess 94 | import multiprocessing 95 | import requests 96 | 97 | from optparse import OptionParser 98 | from binascii import hexlify, unhexlify 99 | 100 | from cryptography.hazmat.backends import default_backend 101 | from cryptography.hazmat.primitives.asymmetric import dh 102 | from cryptography.hazmat.primitives import hashes, hmac 103 | from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes 104 | 105 | from Crypto.Cipher import AES 106 | from cryptography.hazmat.primitives.ciphers.aead import AESGCM 107 | 108 | from smartcard.System import readers 109 | from smartcard.util import toHexString,toBytes 110 | 111 | from card.USIM import * 112 | 113 | from CryptoMobile.Milenage import Milenage 114 | 115 | from gNAS import * 116 | from gSECURITY import * 117 | ``` 118 | Note: I added the card.USIM module (https://github.com/mitshell/card) because it handles much better blank USIM cards bought in eBay or AliExprees, than my old USIM interaction functions. 119 | 120 | Installation: 121 | 122 | ``` 123 | sudo apt insatll libpcsclite-dev 124 | 125 | pip3 install serial wheel pycrypto pyscard swig requests cryptography 126 | 127 | git clone https://github.com/mitshell/card.git 128 | cd card 129 | python3 setup.py install 130 | cd .. 131 | 132 | git clone https://github.com/mitshell/CryptoMobile.git 133 | cd CryptoMobile/ 134 | python3 setup.py install 135 | cd .. 136 | ``` 137 | 138 | 139 | These are the options currently available when starting the app: 140 | 141 | ``` 142 | root@ubuntu# python3 nwu_emulator.py -h 143 | Usage: nwu_emulator.py [options] 144 | 145 | Options: 146 | -h, --help show this help message and exit 147 | -m MODEM, --modem=MODEM 148 | modem port (i.e. COMX, or /dev/ttyUSBX), smartcard 149 | reader index (0, 1, 2, ...), or server for https 150 | -s SOURCE_ADDR, --source=SOURCE_ADDR 151 | IP address of source interface used for IKE/IPSEC 152 | -d DESTINATION_ADDR, --dest=DESTINATION_ADDR 153 | ip address or fqdn of ePDG 154 | -a APN, --apn=APN APN to use 155 | -g GATEWAY_IP_ADDRESS, --gateway_ip_address=GATEWAY_IP_ADDRESS 156 | gateway IP address 157 | -I IMSI, --imsi=IMSI IMSI 158 | -E IMEI, --imei=IMEI IMEI 159 | -M MCC, --mcc=MCC MCC of ePDG (3 digits) 160 | -N MNC, --mnc=MNC MNC of ePDG (3 digits) 161 | -K KI, --ki=KI ki for Milenage (if not using option -m) 162 | -P OP, --op=OP op for Milenage (if not using option -m) 163 | -C OPC, --opc=OPC opc for Milenage (if not using option -m) 164 | -T INTERFACE_TYPE, --type=INTERFACE_TYPE 165 | SWU or NWU interface. (By default is NWU) 166 | -F, --free5gc-core if using non compliant R16 free5gc N3IWF 167 | -u FREE5GC_USERPLANE_IP_ADDRESS, --userplane-ip-address=FREE5GC_USERPLANE_IP_ADDRESS 168 | userplane IP address (for non compliant free5gc N3IWF) 169 | 170 | ``` 171 | 172 | 173 | The option -F is used when using this application with Free5GC 5G Core. 174 | There are some bugs in free5GC, and I needed to adapt to those bugs to make my application work. 175 | This was needed, since this was the only open 5G Core I know with N3IWF implementation. 176 | 177 | Nevertheless, I implemented the app to comply with R16 standards, althoug I never test it against a N3IWF fully compliant. 178 | 179 | 180 | Please check the Wiki (https://github.com/fasferraz/NWu-Non3GPP-5GC/wiki/Setup-Example) to see a setup example with free5GC. 181 | 182 | 183 | Some free5GC issues: 184 | ------------------- 185 | 186 | - Does not send the PDU Session Establishment Accept to the UE through signaling SA child. Only creates the userplane SA child. That means that we must figure out what will be the session IP. Usingo free5gc defaults, that address is 60.60.0.1. But i added option -u so that we can set the session IP in order to create the tunnel for user plane sesion correctly. 187 | - The GRE implementation does not comply with 3GPP requirements (4 bytes instead of 8 bytes with RQI) 188 | - The NAS messages should be prefixed with 2 bytes with NAS lengh information, but in free5GC NAS messages are carried directly in the TCP connection 189 | - AN parameter "requested NSSAI" is not correctly formated 190 | - EAP-AKA' authentication not complete (in AMF), and several erronous checks (in AUSF when comparing RES with XRES, wrong padding in RES processing, KSEAF calculated based on empty KAUSF key) 191 | - EAP-AKA' packets do not have the subtype byte (e.g. AKA-Challenge, etc...) and the following 2 reserved bytes (3 bytes in total) 192 | - Integrity and Ciphering functions in AMF are using Bearer ID for 3GPP access, instead of non-3GPP access as stated in 33.501 193 | 194 | Update 2021/10/28: 195 | ----------------- 196 | 197 | In free5gc version 3.0.6 some of these issues were solved. The current version of my app was updated to work with this new free5gc release. 198 | 199 | 200 | Update 2022/03/15: 201 | ----------------- 202 | 203 | The current version of my app was updated to work with Free5gc N3IWF Fix issues #7, that solved some previous bugs (ex: IPSec SPIs, Create Child SA, forwarding of pduSessionEstablishmentAccept to the UE, etc...) and some non standard implementation (ex. lack of NAS envelop, etc...). 204 | This version also corrects some bugs that I had in the code. 205 | 206 | ------------ 207 | 208 | Example with EAP-AKA' Authentication (I needed to change several files in free5GC to make it work...): 209 | 210 | ``` 211 | root@ubuntu:/home/fabricio# python3 nwu_emulator.py -a internet -d 172.16.62.131 -M 208 -N 93 -I 208930000000003 -K 8baf473f2f8fd09487cccbd7097c6862 -P 8e27b6af0e692e750f32667a3b14605d -s 172.16.62.130 -F 212 | INTERFACE_TYPE 1 213 | 214 | STATE 1: 215 | ------- 216 | NAT SOURCE 854046b0c728ce20cc492ef5c1bf8072cb56d7df 217 | NAT DESTINATION e45afe1d291c4cf5c5a9ae263e08f62400dbeeed 218 | sending IKE_SA_INIT 219 | 220 | Received IKE message decoded: 221 | [[33, [1, 1, b'', b'\x00\x00\x00,\x01\x01\x00\x04\x03\x00\x00\x0c\x01\x00\x00\x0c\x80\x0e\x00\x80\x03\x00\x00\x08\x02\x00\x00\x02\x03\x00\x00\x08\x03\x00\x00\x02\x00\x00\x00\x08\x04\x00\x00\x0e']], [34, [14, b'\xb1QQq5\x81\x97pr\x088[\xaf\x12\'\xf0T\xf8\xb20)\xa1Oh#HE\xa2A\xebg\xf4\x19\xbc\xd7\xe88\xb9~g\xca\x81\\\xdcU \xecQE*x\xa1I\xc4\xc1\xcd\x89@F\x8a\x8e#\x9b\xdb\xa2\xba"N\xd2\x17WZ\xc10)\xf1 \xf3S\x17\x83\xf3\xeb\xffJ\xadT\xcb\x15\r\xdcMBU\xd2\xe8b\x7f\x9b\xa6\xe8G+\xda\x90\x19&\\h\xc8\xee\x96~n\xf9\x00i\x08]\xfenytK\x8bhu9\xf9\xe3\xdb]\'4\'\xdf\x19\xdf\xa16\x95A1m\x84\xb6E\xc8}\xd4\x8bB\x95\xf4% \x87\xfd\xda*\x8e\x81+@\xcc\xdc_\xeej\xf5\x11\xe1\x13n\xc6\xb2i\xe5\xd2\xbf6\xc5"q%E\xb9|\xb4z\xbd\x0e\xa8E\xc8\xab\xdb\xab\xf2\x8ccl\x1c\x06\xed\xe1\x80\x8a\xce\x19\x12K\xcc3z|@\x93?N\xea\xdb>\x05\x13\xb6\xe2KkK\x05\x07\x8b?\x06m?,a\r\xd28,\x05\xbb\x9d\xe9g\x93\xf6|F\xf1\xf4\x92D']], [40, [b'\xb8\xef&E\xda{_a\x94\xabKj\xfd\xd0\xd9\x80\x86\xc5c\xfc5mK|mLJ\xae\x0cuO\xa3\x07m\x7f\x82h}C\xee\xbc\xef\xfb\xe9\x8f\xc1S\xa1\xcfC\xdcGw\x9c\xb3\x93\x0f\xda\xfcv\xa2\x04\xca[\x112v\x9a\xcc4~x\xbc\xa1z\xeb\xb9P\xec\xd7o\xed`&\x08<\t\xd3O\xf5\xf5J\xf0\xf9\xaf\x14Q\xc0\xc3\x98\x92\xf2L+yM^\xe2\xd6r\xd30\xed\x1bb\x9a\xea&A\x89\x88<\x84\x1c5\x8ac\xf9\xf8f\xbf(\x07\x0c\x828\xdcX\xc6[\xea\xa9\xdd&z_\x17\x06>\xc3|q\xd0\xeb\xc7G\x9c\xea\x17W?`\x08\xa9\xb4\x94\xa3\xf5\x8c\xc31\xe7\xb1\xc4\x9b\xa9\xa1\x9e\xa4\xde\xaann\x7f\x08\x8bV\x05\xc7\xbfz\xb7HP\xe8\xa4?\xd6\xc6\xd9\x01\xe2DW\x97\xa3\x01\x0e\x13~\xcc\xda1B\xe6\x91\xe9y\xb4\xeaa\xaa\x9aZ\xb1\x9c \xbd\xe3\xa1Mm\xf2<&\x16\x84\xc9\x07\xaa\xaaZ']], [41, [0, 16388, b'', b'\xca\x18\xf0c\xcd\xf2\x94\xbb\xe4\xf3E\xac\x85\xa6~\x05\xac\x10>\x83\x01\xf4']], [41, [0, 16389, b'', b'\xca\x18\xf0c\xcd\xf2\x94\xbb\xe4\xf3E\xac\x85\xa6~\x05\xac\x10>\x82\x01\xf4']]] 222 | received IKE_SA_INIT 223 | DIFFIE-HELLMAN KEY 522ccd9e8c83c95c6dba80fb857f9c49a460930462bba4aa7664169b117e65bd520788a9db3a43cfe045f75d996d75ca3d010ea2c475156744ac815941a5745067b64736a9ea12583fd3c460bdf5a58c7a3025eecfda07389560c265dec6bf1ec6b16257e4ca2d763e7f6bd31c5d38afa1d0284a1acaade6b21048d444ee2ec1fdae179d939ee43d291b31fc08da2fb1fa9d5e1c568ec98c689b8032be90abbcd6a213c35dcac7a363680bf94ab160f36c93f8f895688a00a9af5aa6fc90e5c176dba6469eaa8d638560238c7bad6c8a1cbc30a79aba34622528737ceec148d8fd627254ca61e97a6cfcc04dbe6dcfa4773c7f894be3917be146b231c019b339 224 | NAT SOURCE RECEIVED ca18f063cdf294bbe4f345ac85a67e05ac103e8301f4 225 | NAT SOURCE CALCULATED b4039caa7997221a839cdfa79b80ca205ccccfe8 226 | NAT DESTINATION RECEIVED ca18f063cdf294bbe4f345ac85a67e05ac103e8201f4 227 | NAT DESTINATION CALCULATED e5769b1d0ff2d36ebf7a2ebdf422306652ce29eb 228 | SKEYSEED ea148f52ae1ec3913200ff383ca476cbc9c9a5b4 229 | STREAM 4a4c049e1d63537123b5a7f8e999ec87b8ef2645da7b5f6194ab4b6afdd0d98086c563fc356d4b7c6d4c4aae0c754fa3076d7f82687d43eebceffbe98fc153a1cf43dc47779cb3930fdafc76a204ca5b1132769acc347e78bca17aebb950ecd76fed6026083c09d34ff5f54af0f9af1451c0c39892f24c2b794d5ee2d672d330ed1b629aea264189883c841c358a63f9f866bf28070c8238dc58c65beaa9dd267a5f17063ec37c71d0ebc7479cea17573f6008a9b494a3f58cc331e7b1c49ba9a19ea4de3c4b51e44848c338af265ef4ff3eaa6e6e7f088b5605c7bf7ab74850e8a43fd6c6d901e2445797a3010e137eccda3142e691e979b4ea61aa9a5ab19c20bde3a14d6df23c261684c907aaaa5aca18f063cdf294bbe4f345ac85a67e05 230 | SK_D b9f68333219ff0ed4a6ac382b9b5ecc4eb6bb738 231 | SK_AI 52f6bdb5c29422c101760e5638f2aa4ab480a5f0 232 | SK_AR 43f6469d239ea17f745c159248558bea067a2cb5 233 | SK_EI fcd5263e5890bb19d7fbea47e9571ccc 234 | SK_ER c3cb8e406ac4acb331c8e55d1197c226 235 | SK_PI ce7c55e3f2049d0b790ef01ba6eeef1d4cc1ed56 236 | SK_PR fae19eb5ffe2d2f4cfc462603802407b0c425ce6 237 | IKE SPI INITIATOR ca18f063cdf294bb 238 | IKE SPI RESPONDER e4f345ac85a67e05 239 | 240 | STATE 2: 241 | ------- 242 | sending IKE_AUTH (1) 243 | EAP 01bf000efe0028af000000030100 244 | 245 | Received IKE message decoded: 246 | [[46, [[36, [2, b'n3iwf.free5gc.org']], [37, [4, b'0\x82\x03\xf90\x82\x02\xe1\xa0\x03\x02\x01\x02\x02\x14\x0b\xabB\xd3f\xbd\xbb\xc3\xd4\x80\xeb\xb5\xb1"\xf5\x11\xf4\xba\xe4\x050\r\x06\t*\x86H\x86\xf7\r\x01\x01\x0b\x05\x000\x81\x9c1\x0b0\t\x06\x03U\x04\x06\x13\x02TW1\x0f0\r\x06\x03U\x04\x08\x0c\x06Taiwan1\x0f0\r\x06\x03U\x04\x07\x0c\x06Taipei1\x100\x0e\x06\x03U\x04\n\x0c\x07WireLab1\x110\x0f\x06\x03U\x04\x0b\x0c\x08Wireless1*0(\x06\t*\x86H\x86\xf7\r\x01\t\x01\x16\x1bwirelab@wire.cs.nctu.edu.tw1\x1a0\x18\x06\x03U\x04\x03\x0c\x11n3iwf.free5gc.org0\x1e\x17\r200329114305Z\x17\r300327114305Z0\x81\x9c1\x0b0\t\x06\x03U\x04\x06\x13\x02TW1\x0f0\r\x06\x03U\x04\x08\x0c\x06Taiwan1\x0f0\r\x06\x03U\x04\x07\x0c\x06Taipei1\x100\x0e\x06\x03U\x04\n\x0c\x07WireLab1\x110\x0f\x06\x03U\x04\x0b\x0c\x08Wireless1*0(\x06\t*\x86H\x86\xf7\r\x01\t\x01\x16\x1bwirelab@wire.cs.nctu.edu.tw1\x1a0\x18\x06\x03U\x04\x03\x0c\x11n3iwf.free5gc.org0\x82\x01"0\r\x06\t*\x86H\x86\xf7\r\x01\x01\x01\x05\x00\x03\x82\x01\x0f\x000\x82\x01\n\x02\x82\x01\x01\x00\xc3\x90\x81\x13\xdf[\x97o<\xf7\xf2\xde\xb9\x0b\x92\xc7o\xdc%\x17\xc2UY\xd8\xdb\xfd\x84\x13\xdc]k\x9a\xfe\x16xs\x03\x1d\xad\xde\xc8\x8f\x8a\xef2c\x9cA"a\x0b\xa6\xbe\xfaOF\xf7o\xca\t\xd9\x82\xdf1 `Er\x9fq\x85|\xfa\xf5\xfd1\x8f\xa1t\xd3\xf8\x00\x8an\xb2\xbd\x8a\xf9\x92\xa5Hot\x8fM\xe6A\xd4\x18\x08\xd7/\xc5m\x80V;\xd6N)\xccU\x8c*\xee#\x97\xf4\'\xc5\xd5\'\x01a\x02\xa2\x0f\x1d8\xc7\x88\xf7\xd7.^\xa99\xeb#A\xd5\x94"\x00\x99\x00\xca}8\xf27+\x91pT&\xbf\xd2\xbd\xd4\xb2\'\xef\x12\xad\xfc25\x8cF\x83p`\x96Y\x1f\\i\x0b\x1a\xa1\xafX\xdb2\xc6c\x04\r\x82A\xf6\x8f\x7f\r\x86\xb2C\x17\x1a\x8c\xdf1\xaczV\x14\x1c\xcc\x15RX\x9c\xbd\xee\x8e\x8c\xc3\xda\x1a/W$4v\x9c\\\xfbN4=\x85+\xac\x18:\xd5\x0c\xb5|\xc0\x1b\xa6HN\xd2\x1e\xf0\xad\x80f&\xb8\x88\x04\t\x02\x03\x01\x00\x01\xa310/0\x1c\x06\x03U\x1d\x11\x04\x150\x13\x82\x11n3iwf.free5gc.org0\x0f\x06\x03U\x1d\x13\x04\x080\x06\x01\x01\xff\x02\x01\x000\r\x06\t*\x86H\x86\xf7\r\x01\x01\x0b\x05\x00\x03\x82\x01\x01\x00Q\xa2\xdd\x04\r\x02\xcdK\xb2W\xcd\xb6\x8e\x83d\x01M\xcd\x14\xda2|\x15\x94#\xf8\xfb\xa1f\xf4Z\xcb\x02`\x0b\x06jqf2\xaa\x90#<\xa8\xa8\xa8\xd3\xea\x08\xefb\x04\x87\xa9]5[\x8e\xaag\xdb\xbf\xf6\xa7\x9e\xa8T\xb7\xc2\xf0\x1a^\xbdj\xed\x16\xfc\xcc\xa9\xdaFa\xf3u\xd4\xa3\xe0\xc9\xba\xc1\xf6\xf5\xf8\xcf%\x8e\x13\x11\x0b-\xc4k\xc2\x1d\x1bql\xb0\xff\x95\xe8\x01\xd6j$\x89G\x0bIY&\x11\x8aJC.\xba\xdc\x06\x8a\xcdt\x18\xbf1\xad~\xb0\xa6\x1c\\\xd4.\x83\xd3\xb9\xd9\xd0p\x1fs@\xacD\xc4\x13\xe9\x95x\x8e\x83yO\xbc\xd7fO"\x177\xecb\x12\x92\x9b=\xe8A\xaf/R\xfd}\x85\xf3\xc7\x9b\xb4\x89\x0c\xa9X\xca=\x15C1\xa7\x8e\xb9\xf0m\xca\n\x93h\x1d\x90\x9f)\xde\xa3Z\xd7+\xb2n\xc7\xcf\xae\xf7\xd2.Y\x80\x8b\x95\x80\x83?\x05\x85\x12\xe6\xb7\x90q`=\x1b\x95\x81y\xe7au\xbbv\xad\xaf\xa23JqV']], [39, [1, b'(\x90\x13@I\x15\xf2\xc3\xd16\x1f\xc5s\x8a\x1a+\x96l9]\xdd\x92\xac\xf2\x7f\x83\x8c\xdc{\xe5\xa2\\T$\xe3o\x18\xdaw<;\xc6\xce\xaa\x05O\x10\xee\x0c\x0f\x1d\xcf\x85l\xc2\xe4q\x83\xd75\xb8]qK\xc0\x8fQ\xec\x80\xc9}\xb3k\xdf\x0c\x91\xe8\xb1\x0c\xd6\x11#l#\r\xe9\x8f\xea9\x87\x90\x93\xad\xf8\xdb.\xa1h\xfe\x07\xab0&\xdc\x08X\x17\x99\xdb\x1c\x06\xbe\xe4\xe0\xf2Q\x03\xdc}H\xae[A\x05\xed\xa5I\x9e\xbfGb#\x89\xd4\x83\xa1\xa0\xf2\x08\xe8\x0e\xa2 \xfd\xfew0\xc2\xe0(\xf2\xbakM\x10\x99\xc3\xecT\xe0v\xc6\xb4s\xa3@\x90>\xda\xf9\xc85j\x1d\x91\x9aH-,n\xbfi\xff\xdb\x82\x08H)\x1e)\xcc1.lU\xac\x8a{`\xdb\x86\xadip\x89\x94{\x9dBU\x83\r.\xd9\x99\xea\x1a)+\xf3\xf7\x85\xdf\xb5\xa2N\xee\xaa`\xb0\x13\xa7\x99\n\xd7V\xf6\x93\xe1\x08 tB\xa6\x15\xa4\xddL$\x1f\x050\xd5\xe2\x98~']], [48, [1, 191, 254, b'\xfe\x00(\xaf\x00\x00\x00\x03', [10415, 3, 1]]]]]] 247 | received IKE_AUTH (1) 248 | 249 | STATE 3: 250 | ------- 251 | sending IKE_SA_AUTH (2) 252 | EAP 01420083fe0028af00000003020000737e005600020000780069014400693201050000b8e57928494f1719ca64d522d0a7f6f70205000052a5ee94be8d80000b523f708f0900cd0b0500006d12c5341346c1f1ba4463f6b7de0c50180100011709002035473a6d6e633039332e6d63633230382e336770706e6574776f726b2e6f7267 253 | 254 | Received IKE message decoded: 255 | [[46, [[48, [1, 66, 254, b'\xfe\x00(\xaf\x00\x00\x00\x03', [10415, 3, 2, None, b'~\x00V\x00\x02\x00\x00x\x00i\x01D\x00i2\x01\x05\x00\x00\xb8\xe5y(IO\x17\x19\xcad\xd5"\xd0\xa7\xf6\xf7\x02\x05\x00\x00R\xa5\xee\x94\xbe\x8d\x80\x00\x0bR?p\x8f\t\x00\xcd\x0b\x05\x00\x00m\x12\xc54\x13F\xc1\xf1\xbaDc\xf6\xb7\xde\x0cP\x18\x01\x00\x01\x17\t\x00 5G:mnc093.mcc208.3gppnetwork.org']]]]]] 256 | received IKE_AUTH (2) 257 | NAS_DECODED [(1, 126), (2, 0), (3, 86), (111, 0), (112, b'\x00\x00'), (115, b'\x01D\x00i2\x01\x05\x00\x00\xb8\xe5y(IO\x17\x19\xcad\xd5"\xd0\xa7\xf6\xf7\x02\x05\x00\x00R\xa5\xee\x94\xbe\x8d\x80\x00\x0bR?p\x8f\t\x00\xcd\x0b\x05\x00\x00m\x12\xc54\x13F\xc1\xf1\xbaDc\xf6\xb7\xde\x0cP\x18\x01\x00\x01\x17\t\x00 5G:mnc093.mcc208.3gppnetwork.org')] 258 | ABBA 0000 259 | EAP 014400693201050000b8e57928494f1719ca64d522d0a7f6f70205000052a5ee94be8d80000b523f708f0900cd0b0500006d12c5341346c1f1ba4463f6b7de0c50180100011709002035473a6d6e633039332e6d63633230382e336770706e6574776f726b2e6f7267 260 | NAS EAP MESSAGE [1, 68, 50, 1, [(1, b'\xb8\xe5y(IO\x17\x19\xcad\xd5"\xd0\xa7\xf6\xf7'), (2, b'R\xa5\xee\x94\xbe\x8d\x80\x00\x0bR?p\x8f\t\x00\xcd'), (11, b'm\x12\xc54\x13F\xc1\xf1\xbaDc\xf6\xb7\xde\x0cP'), (24, 1), (23, b'5G:mnc093.mcc208.3gppnetwork.org')]] 261 | RAND b8e57928494f1719ca64d522d0a7f6f7 262 | AUTN 52a5ee94be8d80000b523f708f0900cd 263 | MAC 6d12c5341346c1f1ba4463f6b7de0c50 264 | KDF 1 265 | KDF_INPUT b'5G:mnc093.mcc208.3gppnetwork.org' 266 | RES b59a7b2dde74fe2a 267 | CK 911211660fefb6e1d9e7036dfdcbef31 268 | IK 4aca874a02b849ad3c199e3b71e11357 269 | CK' 95e8952135ebe2a6eadb13fa54f0fbf7 270 | IK' 1f03c4bee093c54467094e722858fae3 271 | MK d5f45eb45fd24acaee12aa9f900d23a651f718d9c1d5d260aeaddf6a918e6721e1f70d20b0d997cd0b60c30e79af3d9bfdbf89cb251cf097ba1b08fbd9ba952baabadf438cd50d83bcbd087299c30c13e7299ac4bf1b408b18f925d2a80d8f51691fb60a2532cf88a2792fcf8c461d21de90b261a7d4b4a6d5784b205a6b80983492e1851bf7954212da4fa856451cd11eeeff8d50bf682a543b8df6493cd9ce14a172137d65b5c79701f7ad30a8b9c1df9df4e3bd31b972381654f4e5b5eabc9802c7896a0f0fd70cd3ab80ce9e3c17 272 | KENCR d5f45eb45fd24acaee12aa9f900d23a6 273 | KAUT 51f718d9c1d5d260aeaddf6a918e6721e1f70d20b0d997cd0b60c30e79af3d9b 274 | KRE fdbf89cb251cf097ba1b08fbd9ba952baabadf438cd50d83bcbd087299c30c13 275 | MSK e7299ac4bf1b408b18f925d2a80d8f51691fb60a2532cf88a2792fcf8c461d21de90b261a7d4b4a6d5784b205a6b80983492e1851bf7954212da4fa856451cd1 276 | EMSK 1eeeff8d50bf682a543b8df6493cd9ce14a172137d65b5c79701f7ad30a8b9c1df9df4e3bd31b972381654f4e5b5eabc9802c7896a0f0fd70cd3ab80ce9e3c17 277 | KAUSF 1eeeff8d50bf682a543b8df6493cd9ce14a172137d65b5c79701f7ad30a8b9c1 278 | KSEAF 3d072e2fb889b7a873d1b78aed8790097011afe365749039aafe9667ed793947 279 | KAMF 3d3b8a8c50c56e61758d173755084b1ec01159616080fa55b507f5f8d0c686cb 280 | EEA1-KEY 870ddda904eeebeee06761003612d0a0 281 | EEA2-KEY f65286c2f2a0bc6a33fb3dedc67f7434 282 | EEA3-KEY 17ee3cb10e96031f596cc9d3415d7ff5 283 | EIA1-KEY 586a613ded2620c8beea70758c26d3a2 284 | EIA2-KEY cab73183c834c2dbdb035f3ba165a07d 285 | EIA3-KEY c9ac0ef0cca754776ec173991ea1b899 286 | 287 | STATE 4: 288 | ------- 289 | sending IKE_SA_AUTH (3) 290 | EAP 011e002efe0028af000000030200001e7e03355e3a59007e005d0200028020e13601007800040344000438020000 291 | 292 | Received IKE message decoded: 293 | [[46, [[48, [1, 30, 254, b'\xfe\x00(\xaf\x00\x00\x00\x03', [10415, 3, 2, None, b'~\x035^:Y\x00~\x00]\x02\x00\x02\x80 \xe16\x01\x00x\x00\x04\x03D\x00\x048\x02\x00\x00']]]]]] 294 | received IKE_AUTH (3) 295 | NAS DECODED [(1, 126), (2, 3), (4, b'5^:Y'), (5, 0), (6, b'~\x00]\x02\x00\x02\x80 \xe16\x01\x00x\x00\x04\x03D\x00\x048\x02\x00\x00')] 296 | NAS DECODED [(1, 126), (2, 0), (3, 93), (120, 2), (111, 0), (121, b'\x80 '), (117, 1), (118, b'\x00'), (115, b'\x03D\x00\x04'), (112, b'\x00\x00')] 297 | MAC Received 355e3a59 298 | MAC Calculated 355e3a59 299 | KN3IWF f97f3ab0ee8c7523da9d5b3d0a071154150ff0f42987f1880c3d50324e38e1de 300 | 021e0028fe0028af000000030200000000167e043e2d44c5007e005e7700095534129078563412f0 301 | 302 | STATE 5: 303 | ------- 304 | sending IKE_SA_AUTH (4) 305 | EAP 038e0004 306 | 307 | Received IKE message decoded: 308 | [[46, [[48, [3, 142]]]]] 309 | received IKE_AUTH (4) 310 | 311 | STATE 6: 312 | ------- 313 | sending IKE_SA_AUTH (5) 314 | 315 | Received IKE message decoded: 316 | [[46, [[39, [2, b'\x06eGT\x1f(\x9c\n\x03\xfc*\xcb\x82"\xebq\x0fQ@\xa9']], [47, [2, [(1, '0.0.0.0', '0.0.0.0', '0.0.255.255', '10.0.0.157'), (2, '255.255.255.0')]]], [33, [1, 3, b'\xf5x\xe05', b'\x00\x00\x00 \x01\x03\x04\x02\xf5x\xe05\x03\x00\x00\x0c\x01\x00\x00\x0c\x80\x0e\x01\x00\x00\x00\x00\x08\x05\x00\x00\x00']], [44, [1, [(7, 0, 0, 65535, '10.0.0.157', '10.0.0.157')]]], [45, [1, [(7, 0, 0, 65535, '10.0.0.1', '10.0.0.1')]]], [41, [0, 55502, b'', b'\n\x00\x00\x01']], [41, [0, 55506, b'', b'N ']]]]] 317 | received IKE_AUTH (5) 318 | IPV4 ADDRESS ['0.0.0.0', '0.0.0.0', '0.0.255.255', '10.0.0.157'] 319 | TUNNEL IP FOR TCP 10.0.0.157 320 | IPSEC RESP SPI f578e035 321 | IPSEC INIT SPI f578e035 322 | IPSEC PROPOSAL 1 323 | NAS IP ADDRESS 10.0.0.1 324 | NAS TCP PORT 20000 325 | SK_IPSEC_AI 326 | SK_IPSEC_AR 327 | SK_IPSEC_EI 846520ca10350649fed55f4b0e5fa5be296dd6b5a3b2d6d0063671831843a8f2 328 | SK_IPSEC_ER 794170d83d83d0dae1b314593fe6da1bd4ddfcb26207d7c9dcaa117e275ecb16 329 | 330 | Signaling SA CHILD created. Establishing TCP session towards NAS... 331 | 332 | 333 | STATE 7: 334 | ------- 335 | NAS DECODED [(1, 126), (2, 2), (4, b'\xf8\xbd\x00\x01'), (5, 1), (6, b'~\x00B\x01\x02w\x00\x0b\xf2\x02\xf89\xca\xfe\x00\x00\x00\x00\x01T\x07\x00\x02\xf89\x00\x00\x01\x15\n\x04\x01\x01\x02\x03\x04\x01\x11"3]\x01I\x16\x01,')] 336 | NAS DECODED [(1, 126), (2, 0), (3, 66), (100, b'\x02'), (101, b'\xf2\x02\xf89\xca\xfe\x00\x00\x00\x00\x01'), (103, b'\x00\x02\xf89\x00\x00\x01'), (104, b'\x04\x01\x01\x02\x03\x04\x01\x11"3'), (109, b'I'), (110, b',')] 337 | REGISTRATION ACCEPT message received: 338 | 5G-GUTI [(40000, 2), (40001, 20893), (40002, 202), (40003, 1016), (40004, 0), (40005, b'\x00\x00\x00\x01')] 339 | Preparing REGISTRATION COMPLETE to send... 340 | Preparing UL NAS TRANSPORT message with container PDU SESSION ESTABLISHMENT REQUEST to send... 341 | 342 | Received IKE message decoded: 343 | [[46, [[33, [1, 3, b'\x13Z?\x19', b'\x00\x00\x00 \x01\x03\x04\x02\x13Z?\x19\x03\x00\x00\x0c\x01\x00\x00\x0c\x80\x0e\x01\x00\x00\x00\x00\x08\x05\x00\x00\x00']], [40, [b'\x12\xe6\xfc\xa2\xf0k\x0e \xefI\x85\xf9\xac\xca\xad\x1c\xcdX\x0e\xff&9\xa1.\xf7\x99\x16w\xbc{x\xbc\x1et<\x17\xfe\xd7\xad~\x02-\x08|\xea)\xaa\xc9M_/\xff\x9a\x85$]\xee\r\xe1\x1f\xd4\x98\x8ert-\x80V2\xae\xdd\xbd\x0b#\x81g\x0bE\x01\xe9\x91\xbdm\xe4UJ\x18r\x8b\x8cJW\x8e\xcb\xb4\x98\nKS)$\xdei\xafa5\xa3\xae\x9cT\x15\x7f}BBC\xe6,\x87\xc2{)\xafR\xf2\xa9\x8d\x10\r\x8d\xdb\x17*\x0e\x98\xcbS\xd5\x1c\x01\x14\xb5\x07l_a\xc1A\x0c^\xc4R6\xcd2\x14\x04_\xcc\x01\x95\x98\x01c\xad}\xc5\xcd\xbf\xf7\xd1S\xf4D\xbb`\xdf\xd5j\t\xad\xd1C(\xe6\xee\xb0/\xb9ui\x1eT\xe3\xa4iZ\xd35\x0c/P\x88\xf2\xdd\x96\xc6\xe1\x0f\xdf\xe8D\xbd9^V\xa1~\xd9\xc0\xc4\xab\xd9\x9a\x9e3\xd1\xc3\xd0\xb4\xa3`\x8fY\xe4\x03.\xa8\xbe\x16\x16\xca\xc7Gs\x0b\xc6\x82.7\xf0\x814\xa0\xfc\xf8']], [44, [1, [(7, 0, 0, 65535, '10.0.0.1', '10.0.0.1')]]], [45, [1, [(7, 0, 0, 65535, '10.0.0.157', '10.0.0.157')]]], [41, [0, 55501, b'', b'\x05\x05\x01\t\x02']], [41, [0, 55504, b'', b'\n\x00\x00\x01']]]]] 344 | 345 | STATE N3IWF SENT A CREATE CHILD SA: 346 | ---------------------------------- 347 | 5G QOS INFO 0505010902 348 | UP IPV4 ADDRESS 10.0.0.1 349 | received CREATE_CHILD_SA request IPSEC 350 | USERPLANE CHILD SPI INITIATOR 135a3f19 351 | USERPLANE CHILD SPI RESPONDER 135a3f19 352 | SK_IPSEC_AI 353 | SK_IPSEC_AR 354 | SK_IPSEC_EI fa4f95d17473bce3074cff9aecb37c73814420ea2c0f3656e7f8005440fb42c7 355 | SK_IPSEC_ER ac4ba5cb1756628cd8210a60dc336079dfed2ab3b979d8a301acfca9ce83ed03 356 | sending CREATE_CHILD_SA response IPSEC 357 | q 358 | Exiting TCP process. Process terminated. 359 | sending INFORMATIONAL (delete IKE) 360 | 361 | ``` 362 | 363 | Example with 5G-AKA Authentication: 364 | 365 | ``` 366 | root@ubuntu:/home/fabricio# python3 nwu_emulator.py -a internet -d 172.16.62.131 -M 208 -N 93 -I 2089300007487 -K 5122250214c33e723a5dd523fc145fc0 -P c9e8763286b5b9ffbdf56e1297d0887b -s 172.16.62.130 -F 367 | INTERFACE_TYPE 1 368 | 369 | STATE 1: 370 | ------- 371 | NAT SOURCE 954715cd38c93802b8bb33df4a2858c72d2274bf 372 | NAT DESTINATION 6306ead29e8bd997983784e1b4c3f17310ec9fec 373 | sending IKE_SA_INIT 374 | 375 | Received IKE message decoded: 376 | [[33, [1, 1, b'', b'\x00\x00\x00,\x01\x01\x00\x04\x03\x00\x00\x0c\x01\x00\x00\x0c\x80\x0e\x00\x80\x03\x00\x00\x08\x02\x00\x00\x02\x03\x00\x00\x08\x03\x00\x00\x02\x00\x00\x00\x08\x04\x00\x00\x0e']], [34, [14, b'\xae)oZ<`\x8b\xa5v\xa6\xcab\xcb\xb2^q%\xc0\xffjhm[\xec\x92\xc0\xa7\x81\x82\x80Z\xce\x03\xb3\x85Di\xd8\x18\xf1\xd4\xadc\xa5\xff\x1fS \xe6\xc0l\xa6\x17\xe1\xc3\xb3*\xba>\xa1[\xeb0\xd0&\xe2\x9bd\xc1\x88/>\x9e\x83\xc4s\xc8\x8c\xac(\x85\x98\xa9\xf4\x14\x96\x0efA\x8ef\x879\x04.$J\x02g\xbc\xda(<\x01\x0c\x99\xb4\x0f\xaf\xceti0lJ\r\xc43\xea=\xd5\x92\xd4\xa2\xd6c\x97\x8b6\x14Yc<\t\xb9DO\xee\xf9^%\xbaS\x91\xf4\x9f\x04\xae\xd9\xba\x18F\x9dq\\\xa2\xd8\x817"\x08\x80\xc4R\x1ef\xef\x1d\xe1zd(\xac\xf2\xb3\xdc^\xfe<\xdf\xee\xb3r\x8d:\xd9~\xda\x05\xce\xf9\xdfP\x82\xdd\xc0\xa0+\xf8\x06\xad\x11}\xd3\x8e\xaf?`y\xc0\xe6C\xfco!\xef\xe6\x0e6\xc5>9\xca(\xfb2e\td\xeex\x07\x96\x03\x022\x85\x18\x05\x8e\x18\x19\xa5\x187\x11\xa8XD\x04\x9a\xd5\x03\xf7\xb1\x8d']], [40, [b'\xdb0Z\xed(\x83\x97|g\xce.\x11MMR\xb3\x9c\xa8\xb8\xd7kmyb\xc9\xb8r\x9afB\xeb\xaa\x88\xbb\xcb`\x1avN\x843\xd5\xb2\xfe\xd2\xdd\xdf=\x8c J.3\x98\xd0\xb6\xd6\x93\xe78\xc6\xf6\xc1\xeb\xa1H\xc8\xedg\xadM\x08\xe1\x13\x91\xd5W\x844\xdet\xe4 E\t\x04\xc7t\\\x8c \x13\x92\xb8\x84>(\n\x88\xe7J\x16* \xe4-N\xf8\xf4\xee\xe5\x8d\xcb\xe3\xd8\xda\xd4\xb9\xb8\xa5\x152\x18\xf5G[LDh\x1f\xa2\xdce~\x0e(Mw\x16J\xccx\xc9ae\x8e\xb7i\x19\x95\xd1*\x88\xda\xa0\xa8\xc2\xc8\x10\xa6Y$X!P?\xce\xb4\x81\xad\xd1|\x1b\xe5{D\n?\x8e\xe7\xe6\x8a\xb8\x8b\x13~\xffw\xe0\xf1\xb95\x0b\xaceK_\r\xce\xc2\xb6\x9c\x8d\xbd\xa7E$`ocWJN\xfa9\xb4\x95:\xa5]1\x15g\x8a\x82UXu\xe3\x95!\xafG5#\xbe\xdf\xd7\xf1\x9e\xfdFYA\xe9V?@4-\x8e\xc4R\x00;\xb3']], [41, [0, 16388, b'', b'\xcf\xee\xe6\n3\x84k\x9dD/\xebA\xc0\xfe\xfd\xae\xac\x10>\x83\x01\xf4']], [41, [0, 16389, b'', b'\xcf\xee\xe6\n3\x84k\x9dD/\xebA\xc0\xfe\xfd\xae\xac\x10>\x82\x01\xf4']]] 377 | received IKE_SA_INIT 378 | DIFFIE-HELLMAN KEY a071f10d9e4ac5534263e7618b5c509320df6742625bb94c634a3abe8760ebd08ae1088111c9a168d20fb44258caf2da993b080242e1ea783e6ff6077cad96a9f0e80bdede5c5557757e5601d974f42e130e8466ae709e2578eeb685e520ea4037cffe2af3dc43c618941771f32266f4828442996388c19dabec475643f4cd6e97cdea857aa86da6e09d333869a5065f14ba52eb7e5b3956ea9c2c5134440c5bd6b55ebfca715195282c60ae6d4684d71f994b18ec5ba3fbe43e9d51a381b86c9ea4b2197ba39e85e82c703ce9a221c35c802a15691267cedc27df75cc3d589716136e89bf518da375ac3c9cc51676d99120d163826b1e7b3ed8a9d9341b3464 379 | NAT SOURCE RECEIVED cfeee60a33846b9d442feb41c0fefdaeac103e8301f4 380 | NAT SOURCE CALCULATED 5b61cac2b422bc653807794d8bdbfaa2cc30b1fd 381 | NAT DESTINATION RECEIVED cfeee60a33846b9d442feb41c0fefdaeac103e8201f4 382 | NAT DESTINATION CALCULATED 04496b07c4e3d9ff253f34ebf6c5a85904c3d87c 383 | SKEYSEED 62507d00d5c7ae95fa3515da6c69a01e0b7211bc 384 | STREAM bf1868601f3b9529ae11e96a797c400fdb305aed2883977c67ce2e114d4d52b39ca8b8d76b6d7962c9b8729a6642ebaa88bbcb601a764e8433d5b2fed2dddf3d8c204a2e3398d0b6d693e738c6f6c1eba148c8ed67ad4d08e11391d5578434de74e420450904c7745c8c201392b8843e280a88e74a162a20e42d4ef8f4eee58dcbe3d8dad4b9b8a5153218f5475b4c44681fa2dc657e0e284d77164acc78c961658eb7691995d12a88daa0a8c2c810a659245821503fceb481add17c1be57b440a3f8ee7e68ab88b137eff77e0f1b9350bac654b5f0dcec2b69c8dbda74524606f63574a4efa39b4953aa55d3115678a82555875e39521af473523bedfd7f19efd465941e9563f40342d8ec452003bb3cfeee60a33846b9d442feb41c0fefdae 385 | SK_D 50307f77952da0697ade354997a77d9a1c61fbb6 386 | SK_AI 507b976c0d0ea8473aefa0d53799b8e3f232baed 387 | SK_AR ace52cfd4a67d79e1fc170a3b958b3ddb7b0b9c1 388 | SK_EI 092205ebd7bdb3e4f62596fd2d0d55fd 389 | SK_ER 42a1ff90f3d32e075cb7ac6c0ebce8b1 390 | SK_PI 46ab91967bf36cd9aba173718637aa64144958fa 391 | SK_PR a67681e66b6273e29b5689a99a309fcde5929e02 392 | IKE SPI INITIATOR cfeee60a33846b9d 393 | IKE SPI RESPONDER 442feb41c0fefdae 394 | 395 | STATE 2: 396 | ------- 397 | sending IKE_AUTH (1) 398 | EAP 01a4000efe0028af000000030100 399 | 400 | Received IKE message decoded: 401 | [[46, [[36, [2, b'n3iwf.free5gc.org']], [37, [4, b'0\x82\x03\xf90\x82\x02\xe1\xa0\x03\x02\x01\x02\x02\x14\x0b\xabB\xd3f\xbd\xbb\xc3\xd4\x80\xeb\xb5\xb1"\xf5\x11\xf4\xba\xe4\x050\r\x06\t*\x86H\x86\xf7\r\x01\x01\x0b\x05\x000\x81\x9c1\x0b0\t\x06\x03U\x04\x06\x13\x02TW1\x0f0\r\x06\x03U\x04\x08\x0c\x06Taiwan1\x0f0\r\x06\x03U\x04\x07\x0c\x06Taipei1\x100\x0e\x06\x03U\x04\n\x0c\x07WireLab1\x110\x0f\x06\x03U\x04\x0b\x0c\x08Wireless1*0(\x06\t*\x86H\x86\xf7\r\x01\t\x01\x16\x1bwirelab@wire.cs.nctu.edu.tw1\x1a0\x18\x06\x03U\x04\x03\x0c\x11n3iwf.free5gc.org0\x1e\x17\r200329114305Z\x17\r300327114305Z0\x81\x9c1\x0b0\t\x06\x03U\x04\x06\x13\x02TW1\x0f0\r\x06\x03U\x04\x08\x0c\x06Taiwan1\x0f0\r\x06\x03U\x04\x07\x0c\x06Taipei1\x100\x0e\x06\x03U\x04\n\x0c\x07WireLab1\x110\x0f\x06\x03U\x04\x0b\x0c\x08Wireless1*0(\x06\t*\x86H\x86\xf7\r\x01\t\x01\x16\x1bwirelab@wire.cs.nctu.edu.tw1\x1a0\x18\x06\x03U\x04\x03\x0c\x11n3iwf.free5gc.org0\x82\x01"0\r\x06\t*\x86H\x86\xf7\r\x01\x01\x01\x05\x00\x03\x82\x01\x0f\x000\x82\x01\n\x02\x82\x01\x01\x00\xc3\x90\x81\x13\xdf[\x97o<\xf7\xf2\xde\xb9\x0b\x92\xc7o\xdc%\x17\xc2UY\xd8\xdb\xfd\x84\x13\xdc]k\x9a\xfe\x16xs\x03\x1d\xad\xde\xc8\x8f\x8a\xef2c\x9cA"a\x0b\xa6\xbe\xfaOF\xf7o\xca\t\xd9\x82\xdf1 `Er\x9fq\x85|\xfa\xf5\xfd1\x8f\xa1t\xd3\xf8\x00\x8an\xb2\xbd\x8a\xf9\x92\xa5Hot\x8fM\xe6A\xd4\x18\x08\xd7/\xc5m\x80V;\xd6N)\xccU\x8c*\xee#\x97\xf4\'\xc5\xd5\'\x01a\x02\xa2\x0f\x1d8\xc7\x88\xf7\xd7.^\xa99\xeb#A\xd5\x94"\x00\x99\x00\xca}8\xf27+\x91pT&\xbf\xd2\xbd\xd4\xb2\'\xef\x12\xad\xfc25\x8cF\x83p`\x96Y\x1f\\i\x0b\x1a\xa1\xafX\xdb2\xc6c\x04\r\x82A\xf6\x8f\x7f\r\x86\xb2C\x17\x1a\x8c\xdf1\xaczV\x14\x1c\xcc\x15RX\x9c\xbd\xee\x8e\x8c\xc3\xda\x1a/W$4v\x9c\\\xfbN4=\x85+\xac\x18:\xd5\x0c\xb5|\xc0\x1b\xa6HN\xd2\x1e\xf0\xad\x80f&\xb8\x88\x04\t\x02\x03\x01\x00\x01\xa310/0\x1c\x06\x03U\x1d\x11\x04\x150\x13\x82\x11n3iwf.free5gc.org0\x0f\x06\x03U\x1d\x13\x04\x080\x06\x01\x01\xff\x02\x01\x000\r\x06\t*\x86H\x86\xf7\r\x01\x01\x0b\x05\x00\x03\x82\x01\x01\x00Q\xa2\xdd\x04\r\x02\xcdK\xb2W\xcd\xb6\x8e\x83d\x01M\xcd\x14\xda2|\x15\x94#\xf8\xfb\xa1f\xf4Z\xcb\x02`\x0b\x06jqf2\xaa\x90#<\xa8\xa8\xa8\xd3\xea\x08\xefb\x04\x87\xa9]5[\x8e\xaag\xdb\xbf\xf6\xa7\x9e\xa8T\xb7\xc2\xf0\x1a^\xbdj\xed\x16\xfc\xcc\xa9\xdaFa\xf3u\xd4\xa3\xe0\xc9\xba\xc1\xf6\xf5\xf8\xcf%\x8e\x13\x11\x0b-\xc4k\xc2\x1d\x1bql\xb0\xff\x95\xe8\x01\xd6j$\x89G\x0bIY&\x11\x8aJC.\xba\xdc\x06\x8a\xcdt\x18\xbf1\xad~\xb0\xa6\x1c\\\xd4.\x83\xd3\xb9\xd9\xd0p\x1fs@\xacD\xc4\x13\xe9\x95x\x8e\x83yO\xbc\xd7fO"\x177\xecb\x12\x92\x9b=\xe8A\xaf/R\xfd}\x85\xf3\xc7\x9b\xb4\x89\x0c\xa9X\xca=\x15C1\xa7\x8e\xb9\xf0m\xca\n\x93h\x1d\x90\x9f)\xde\xa3Z\xd7+\xb2n\xc7\xcf\xae\xf7\xd2.Y\x80\x8b\x95\x80\x83?\x05\x85\x12\xe6\xb7\x90q`=\x1b\x95\x81y\xe7au\xbbv\xad\xaf\xa23JqV']], [39, [1, b'8\xdc\xa1\xff\xb1\x98\xb8]\x8f\x84F\xfa+j\x11\x83\xd8\xfb\x1a]\x16\xdc\x83\xdaTVz\x05\xd3nys\x9bZ\xbc\x8f\x89\xad\xdfE\x97\xccu\xb4\xa2\x82De-\xbe\xff,\x91\xd45\x12\xd0\x04\x99\xaey\xdd\xf3\x02\xa8\xed%\xdf\xe1<\x88\xeb\x13\x81az\x16A\x0f\x02)\xdaK9\xa1\xbd3\ta\xab3\xe2>l*\xdc\xe4\xd0Y\x91]|\xa4\xd4\xa8\xf0\xb8\x13\x91\xb4;\xd3\xb1\x02%\x93|\x8ef\xb0K\x9c\x1a\x83F\x9b\x86R\x83x\xe4d\xf2\x1a\x08\xd87\xcb\xfb\x93X(\xb9\x14H\xceI\xbaz\xdd\xe0S\xdci\xad\x85\xd0<\x1bn\xd0\xc5V\xe5\x1e\x8fH\xf5y\x80\xac\xd10\x13\x12\xe78\xbfGs|\x16\xc4\x01A\x1eW\x02\xad}Zd\xa0\xca\x04\x94\xea\xdf\xd9\x07oA?\x96\x85\xe3\x88\x8a\xc2O\xe0\x13\xae\xe45\xa4\xec\x1f\xc7r\xa3\xf8`\xcf\x9e\xa2\x9a[\xd4\x93\xa0d\x85N\x95\x05e\x90%]\xd3\xd5\xa2|\x1f\xc7\xfb\x1f@h\xe6\xcaFd\tQ']], [48, [1, 164, 254, b'\xfe\x00(\xaf\x00\x00\x00\x03', [10415, 3, 1]]]]]] 402 | received IKE_AUTH (1) 403 | 404 | STATE 3: 405 | ------- 406 | sending IKE_SA_AUTH (2) 407 | EAP 0142003afe0028af000000030200002a7e00560002000021ad2913a001213ae32cfea97815418de220106b7d8ebdcef680008a90b8454ddbd7cf 408 | 409 | Received IKE message decoded: 410 | [[46, [[48, [1, 66, 254, b'\xfe\x00(\xaf\x00\x00\x00\x03', [10415, 3, 2, None, b'~\x00V\x00\x02\x00\x00!\xad)\x13\xa0\x01!:\xe3,\xfe\xa9x\x15A\x8d\xe2 \x10k}\x8e\xbd\xce\xf6\x80\x00\x8a\x90\xb8EM\xdb\xd7\xcf']]]]]] 411 | received IKE_AUTH (2) 412 | NAS_DECODED [(1, 126), (2, 0), (3, 86), (111, 0), (112, b'\x00\x00'), (113, b'\xad)\x13\xa0\x01!:\xe3,\xfe\xa9x\x15A\x8d\xe2'), (114, b'k}\x8e\xbd\xce\xf6\x80\x00\x8a\x90\xb8EM\xdb\xd7\xcf')] 413 | ABBA 0000 414 | RAND ad2913a001213ae32cfea97815418de2 415 | AUTN 6b7d8ebdcef680008a90b8454ddbd7cf 416 | RES cd4dc86ed5408828 417 | CK b251627c33abc793fa9df1f7a531c0f2 418 | IK 13c779322d4f763bbc5c2180413381f9 419 | b'5G:mnc093.mcc208.3gppnetwork.org' 420 | RES* 624822b1fdd4243b63d8acd6238b6b01 421 | HRES* 88d07928ff94c4c3801fcdb85e58183c 422 | KAUSF 5310410b6c686d57871209a34d4ba398dfc60fe40070bdd692629e8e5061d066 423 | KSEAF 71b6d0643668df5ace9dbc5211aed5ac1d80630c9fe1624aa6b91bce6d820a04 424 | KAMF f44cecdc982ead73aabe8882cb5050ac693feb29fb2fd113bb049ad3138e7344 425 | EEA1-KEY 764cf350bfa6ae449e96b060c4d7376f 426 | EEA2-KEY 1905da7cfca260585e9122734aa92937 427 | EEA3-KEY 54670e959a87507c6ab6bb5d7d5326cb 428 | EIA1-KEY 5a2706241a11a2aefd4c24e7d54f9373 429 | EIA2-KEY f13464a319c2234620cc66d54f92d09d 430 | EIA3-KEY 48908fae1e8c324526d666be5f52e064 431 | 02420027fe0028af000000030200000000157e00572d10624822b1fdd4243b63d8acd6238b6b01 432 | 433 | STATE 4: 434 | ------- 435 | sending IKE_SA_AUTH (3) 436 | EAP 011e0023fe0028af00000003020000137e03049d304d007e005d0200028020e1360100 437 | 438 | Received IKE message decoded: 439 | [[46, [[48, [1, 30, 254, b'\xfe\x00(\xaf\x00\x00\x00\x03', [10415, 3, 2, None, b'~\x03\x04\x9d0M\x00~\x00]\x02\x00\x02\x80 \xe16\x01\x00']]]]]] 440 | received IKE_AUTH (3) 441 | NAS DECODED [(1, 126), (2, 3), (4, b'\x04\x9d0M'), (5, 0), (6, b'~\x00]\x02\x00\x02\x80 \xe16\x01\x00')] 442 | NAS DECODED [(1, 126), (2, 0), (3, 93), (120, 2), (111, 0), (121, b'\x80 '), (117, 1), (118, b'\x00')] 443 | MAC Received 049d304d 444 | MAC Calculated 049d304d 445 | KN3IWF 37aa91bf898993eb1f7c09d5f4f8bfab4951b0e61b3ad53121d8826f00ecb221 446 | 021e0028fe0028af000000030200000000167e0400486f4c007e005e7700095534129078563412f0 447 | 448 | STATE 5: 449 | ------- 450 | sending IKE_SA_AUTH (4) 451 | EAP 038e0004 452 | 453 | Received IKE message decoded: 454 | [[46, [[48, [3, 142]]]]] 455 | received IKE_AUTH (4) 456 | 457 | STATE 6: 458 | ------- 459 | sending IKE_SA_AUTH (5) 460 | 461 | Received IKE message decoded: 462 | [[46, [[39, [2, b'l\xe4J\xe0\xe8hl\xe7U\xee\xc3\xa4\xff\xeeHkVml\xb5']], [47, [2, [(1, '0.0.0.0', '0.0.0.0', '0.0.255.255', '10.0.0.13'), (2, '255.255.255.0')]]], [33, [1, 3, b'\x1eS5\xa3', b'\x00\x00\x00 \x01\x03\x04\x02\x1eS5\xa3\x03\x00\x00\x0c\x01\x00\x00\x0c\x80\x0e\x01\x00\x00\x00\x00\x08\x05\x00\x00\x00']], [44, [1, [(7, 0, 0, 65535, '10.0.0.13', '10.0.0.13')]]], [45, [1, [(7, 0, 0, 65535, '10.0.0.1', '10.0.0.1')]]], [41, [0, 55502, b'', b'\n\x00\x00\x01']], [41, [0, 55506, b'', b'N ']]]]] 463 | received IKE_AUTH (5) 464 | IPV4 ADDRESS ['0.0.0.0', '0.0.0.0', '0.0.255.255', '10.0.0.13'] 465 | TUNNEL IP FOR TCP 10.0.0.13 466 | IPSEC RESP SPI 1e5335a3 467 | IPSEC INIT SPI 1e5335a3 468 | IPSEC PROPOSAL 1 469 | NAS IP ADDRESS 10.0.0.1 470 | NAS TCP PORT 20000 471 | SK_IPSEC_AI 472 | SK_IPSEC_AR 473 | SK_IPSEC_EI 9c53fc27953f17c00ef4d52e9de8b4d1266782b4ff971ce5d3fd4906abd30293 474 | SK_IPSEC_ER 38826cb8a5c4c5c18ee9f06201b75363680a78ea02a64385819233b3972bb423 475 | 476 | Signaling SA CHILD created. Establishing TCP session towards NAS... 477 | 478 | 479 | STATE 7: 480 | ------- 481 | NAS DECODED [(1, 126), (2, 2), (4, b'\x93\n\x12\xd0'), (5, 1), (6, b'~\x00B\x01\x02w\x00\x0b\xf2\x02\xf89\xca\xfe\x00\x00\x00\x00\x01T\x07\x00\x02\xf89\x00\x00\x01\x15\n\x04\x01\x01\x02\x03\x04\x01\x11"3]\x01I\x16\x01,')] 482 | NAS DECODED [(1, 126), (2, 0), (3, 66), (100, b'\x02'), (101, b'\xf2\x02\xf89\xca\xfe\x00\x00\x00\x00\x01'), (103, b'\x00\x02\xf89\x00\x00\x01'), (104, b'\x04\x01\x01\x02\x03\x04\x01\x11"3'), (109, b'I'), (110, b',')] 483 | REGISTRATION ACCEPT message received: 484 | 5G-GUTI [(40000, 2), (40001, 20893), (40002, 202), (40003, 1016), (40004, 0), (40005, b'\x00\x00\x00\x01')] 485 | Preparing REGISTRATION COMPLETE to send... 486 | Preparing UL NAS TRANSPORT message with container PDU SESSION ESTABLISHMENT REQUEST to send... 487 | 488 | Received IKE message decoded: 489 | [[46, [[33, [1, 3, b'\x07\xfdI\xb7', b'\x00\x00\x00 \x01\x03\x04\x02\x07\xfdI\xb7\x03\x00\x00\x0c\x01\x00\x00\x0c\x80\x0e\x01\x00\x00\x00\x00\x08\x05\x00\x00\x00']], [40, [b'\x0b\xa7\xd6\xe1-\xf5\xcb\xcfq\xb9\x93\xf8\xa1\xf3\xe1y\xff\xd9\x19\xb6\xb3\xaaw\xc9\xb5)3)\x91\xf3\xd5\xd8M\xb9\xb7\xaeI\x82\xf3\xfeu;d\x8dn\'-\xdf\x82\xc8\xb4)\x9dA\xb4\xe4\xce]\xb4>v\x81\xb2\xe7=\xc8\xce@%#\xe1\x9bv\xe3D\xb2\x9a="\xd3>\x82\x0e\x92\xf3\x16\x152\xbc\xcflN.56\x15\xdb\x07!\xbc\xc1\xe1\xe6J\x7fp\xb4\x10\xbd\xe4\x9d\xfb\x86\x9b\xde\x80\x8f\x9a\x91\xb3>F%\x02\x81\x04\x7fH\xf2\xb6\xf6\xc3\x8c\xe5\xd3F\xbd\xab{m\xc0\xce}5\x15\xab*\x86\r}!"\x1a\xf7\xf5\x87D[\x98bUG\x99\x03\x89\x8cY\xa4\t\x1b :\x1d\x8c\xad\xd3\x187v_\x99\xfa\xbf\xa1\x8a\x99\xdb+\x95\xda1\xde\xab\x98z*\xea\xa16\xdd\xaaT\xaf\xce\x9fS\xa3\xba;-\x88e\x0fN\xe3\x0ekHAX\xc4\xa7R\xeeZ\xd2\xbdW#\x0e\x92*\x15\xd2P7{\x92\x89\x87\\V\x90\xcchH\t6\xa0\x9f\x8f\x80R\xb7tQ']], [44, [1, [(7, 0, 0, 65535, '10.0.0.1', '10.0.0.1')]]], [45, [1, [(7, 0, 0, 65535, '10.0.0.13', '10.0.0.13')]]], [41, [0, 55501, b'', b'\x05\x05\x01\t\x02']], [41, [0, 55504, b'', b'\n\x00\x00\x01']]]]] 490 | 491 | STATE N3IWF SENT A CREATE CHILD SA: 492 | ---------------------------------- 493 | 5G QOS INFO 0505010902 494 | UP IPV4 ADDRESS 10.0.0.1 495 | received CREATE_CHILD_SA request IPSEC 496 | USERPLANE CHILD SPI INITIATOR 07fd49b7 497 | USERPLANE CHILD SPI RESPONDER 07fd49b7 498 | SK_IPSEC_AI 499 | SK_IPSEC_AR 500 | SK_IPSEC_EI 7c5c848cadbb1fe3364ec333affbff0127c32debed1907eea20d9395cd8d8150 501 | SK_IPSEC_ER e9ba5b67dc97ef5e7f8961380b035926c36293276ba9952c3de77c050f06c416 502 | sending CREATE_CHILD_SA response IPSEC 503 | q 504 | Exiting TCP process. Process terminated. 505 | sending INFORMATIONAL (delete IKE) 506 | root@ubuntu:/home/fabricio# 507 | 508 | 509 | 510 | 511 | ``` 512 | 513 | 514 | Example of routing table after session establishment: 515 | 516 | -> N3IWF NAS IP address: 10.0.0.1 517 | -> UE source IP address to communicate with NAS: 10.0.0.218 (IP address of tun2 - Signaling SA CHILD) 518 | 519 | -> Session IP address: 60.60.0.8 (IP address of tun3 - Userplane SA Child, Default Route) 520 | 521 | ``` 522 | root@ubuntu:/etc# route -n 523 | Kernel IP routing table 524 | Destination Gateway Genmask Flags Metric Ref Use Iface 525 | 0.0.0.0 60.60.0.8 128.0.0.0 UG 0 0 0 tun3 <- Userplane SA Child 526 | 0.0.0.0 172.16.62.2 0.0.0.0 UG 20100 0 0 ens33 527 | 10.0.0.1 10.0.0.218 255.255.255.255 UGH 0 0 0 tun2 <- Signalling SA Child 528 | 128.0.0.0 60.60.0.8 128.0.0.0 UG 0 0 0 tun3 <- Userplane SA Child 529 | 169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 ens33 530 | 172.16.62.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33 531 | root@ubuntu:/etc# 532 | ``` 533 | 534 | 535 | # Updated Version: 536 | 537 | - Support for Network Namespaces for User Plane Traffic (option -n) for SWU or NWU mode; 538 | - TCP Process moved to a specific signalling network namespace to avoid possible IP overlapping between NAS_IP_ADDRESS or INTERNAL_IP4_ADDRESS and any local interface; 539 | - Synch Failure in EAP-AKA' authentication (was already supported for 5G-AKA); 540 | 541 | Example of 5G-AKA with namespace option: 542 | 543 | ``` 544 | root@ubuntu:/home/fabricio# python3 nwu_emulator.py -a internet -d 172.16.62.131 -M 208 -N 93 -m 0 -F -s 172.16.62.130 -g 172.16.62.131 -n baba 545 | 208930000000003 546 | INTERFACE_TYPE 1 547 | 548 | STATE 1: 549 | ------- 550 | NAT SOURCE 46931f1f97cedc0e37e845354cfe391e59327436 551 | NAT DESTINATION 560dfed5de6f96d1007774e9547af0e4ecd8d307 552 | sending IKE_SA_INIT 553 | 554 | Received IKE message decoded: 555 | [[41, [0, 17, b'', b'\x00\x0e']]] 556 | received IKE_SA_INIT 557 | REPEAT_STATE : INVALID_KE_PAYLOAD 558 | 559 | STATE 1 (retry 1): 560 | ------- ------- 561 | NAT SOURCE 46931f1f97cedc0e37e845354cfe391e59327436 562 | NAT DESTINATION 560dfed5de6f96d1007774e9547af0e4ecd8d307 563 | sending IKE_SA_INIT 564 | 565 | Received IKE message decoded: 566 | [[33, [1, 1, b'', b'\x00\x00\x00,\x01\x01\x00\x04\x03\x00\x00\x0c\x01\x00\x00\x0c\x80\x0e\x00\x80\x03\x00\x00\x08\x02\x00\x00\x02\x03\x00\x00\x08\x03\x00\x00\x02\x00\x00\x00\x08\x04\x00\x00\x0e']], [34, [14, b'\x9b#\xaal\xf4\x81\xb36T\xf9\xbd\xfe\xa2\xec\xd4\xf3\x1a8A\xe9@\x1e\x1e\xb7\xc9EM\xac\x80wHi#\xd1\xb0cs1m\xb7\x04\x02\xa1\x82\xfcIWb\xc8Rbu\xcfE%\x8a\x95\x06\x9a\x94\xf0\xb8-n\xb7\xa2\x94^8\x0fs\xf8dF\xa6y\xd5\xba\xfa\xf3I\x96\x17\xdb0\xcczN-\xd1\r\xff\xdcNa\x1c\xb2\xd9\xc5-\xc0i\xfe5\x0c\x95\xd2\x8a\nj\xc2\x0ct\x8c\xef\x14M\x98O\xe8\x90\xd2`:\x8c\x10DK\xb6S\xd5\x8e \xfe\xebd\xbc\xdc]\xefP\xda\xf3\xb6?x\x96\xe7\xad\xaa\x0e\x12\x95\x84\xb8\xd5\x18\xd5\xc4\xfc\xb5j\xe9\x86\xec\xe5\xa2\xb4D\xcd\x8f\xf2B\xfc\x87\x86\x97\xfatc\x0e<\x8d\x17\x84\xe3\x07wv?\xef\x7f\x99\xf9;\x8f\xafP\xfb\xe5x #\x9b\xfb%2\xca\xe5\xb9\x17\x90\x99\nm\x00\x8a\xb0\x9fT\xa7u\x035\x8b6\x83=\xdd\xa9\x84x0\xa5`\xb0?9\xd3\x0c\xa0&\xfb1\x10PCK\x80-1\xdd\x02\xcd\x93\x8b']], [40, [b'\x97\xbe\xf7\x1d\x94\xaa:\xdeT\x14\xba,\x12\xeb\x87\r\xed\xb2\xeb\xd4b\x98M\xe6\xe5~z\x9b\xdb\x8d\xaa\xd0x\x08\xc2\x0f\x05\xef\x9c\x9c\xb2\xa2\xd7~\xec^\xb3\xef\x18cr\xb9\xfc\xc6J=gs\xff\xe7\t\xcb\x899\xd8w\x0et\xd4\xccR^\xff\xb0`\xcb\x9b\xe8\xe5\xd5{u\x0b\xe0\xa0$\xbe\xa5\xdb-7>\x9e\xc9\x81,D\x0c\xd6p\xfa0\xce~"-\x94\x8c\xf4L\xdaA\x82\x11\x88hv\xd3\xa8\xb6\xc9\xae\x91H^\xd5\x1e;\x88\x8f\xb4\x9eN>\xe9\xa7V:{\xcd\x9d\xa5\x1e\xd2`\xd9\xfb%7\xd1\x06\xa4z\x8b\xb6aa\x9d2/]T]\xe7\xa5\xd3c%\x81~\xdap9\x8d{\xa9\xb6`\xea1)\xfd\xfa\x1cB\x9a\xceY@G\xb3\rp{\xc3x\xbd\x9b\xb3\xe7\x83\xe1\'\xc3\xf3$\xf6\t&\x17\xfd\xef\\\x80\xf749>_\xeah\x9e\xdc\x90,Z\x08\xd1#7&\x95\xea\x01C\xb8R\xa8{\xd0\xf7h\xef\x98[\xaacx7\xc2\xf3\x81~\xb8\xaa\xad']], [41, [0, 16388, b'', b'i\xb5A\xb6\x8e\x0e\xa5#\x8e\x05:\x12\xb4"\xeb\xa8\xac\x10>\x83\x01\xf4']], [41, [0, 16389, b'', b'i\xb5A\xb6\x8e\x0e\xa5#\x8e\x05:\x12\xb4"\xeb\xa8\xac\x10>\x82\x01\xf4']]] 567 | received IKE_SA_INIT 568 | DIFFIE-HELLMAN KEY 4ae0c3316f08139247a486139855d679b7df62e34493afe1d5d125f470d027d36ce70ba8d27c79cbc8f58da81b868355feef514d8b8825bcbb50c1c4b17753257b8a874be3ea7c8c15bc669cd297fd5a0c5920f8ddb83041522c69b992e598a1696c9e77c3cc845ed461e07dd371ebb57309cd9df8b9f5669a640eb316fb9ad1451a08bcab58bbd3cc9ae62610c10553f8f762618593fceebb0e990a925c7e50419f7ac1ff52e31fb0fe10f526c5cc519cea63e4c8ded02e6fe360350ada927e5175600c80d7564147f54d9f8aae9fa66e6a81e6c8fc7b490a6ec90d896747ccc9d5011199b4a69e455b268b5986b3114a027e882466c3685cd26cf0d27ea8fa 569 | NAT SOURCE RECEIVED 69b541b68e0ea5238e053a12b422eba8ac103e8301f4 570 | NAT SOURCE CALCULATED 1f84559feff40bd6475e6a7e22b9dcccebdf00f9 571 | NAT DESTINATION RECEIVED 69b541b68e0ea5238e053a12b422eba8ac103e8201f4 572 | NAT DESTINATION CALCULATED ddba1b86ba37b2943ace54719ca56299950d2ea2 573 | SKEYSEED fd4c85ec14014047f47207d1a6790eef2f33d307 574 | STREAM 1518527e5174dc1f2c68b1de346b25d597bef71d94aa3ade5414ba2c12eb870dedb2ebd462984de6e57e7a9bdb8daad07808c20f05ef9c9cb2a2d77eec5eb3ef186372b9fcc64a3d6773ffe709cb8939d8770e74d4cc525effb060cb9be8e5d57b750be0a024bea5db2d373e9ec9812c440cd670fa30ce7e222d948cf44cda418211886876d3a8b6c9ae91485ed51e3b888fb49e4e3ee9a7563a7bcd9da51ed260d9fb2537d106a47a8bb661619d322f5d545de7a5d36325817eda70398d7ba9b660ea3129fdfa1c429ace594047b30d707bc378bd9bb3e783e127c3f324f6092617fdef5c80f734393e5fea689edc902c5a08d123372695ea0143b852a87bd0f768ef985baa637837c2f3817eb8aaad69b541b68e0ea5238e053a12b422eba8 575 | SK_D 579ecb351d3dffa7f954ce1ae2d925f852101309 576 | SK_AI d1a573ffdc9b6dfef0b1f93682fd271fc10cc0d7 577 | SK_AR a8be721548dc83c7248e2732f986228c7d711ced 578 | SK_EI be6f513b22dfc08f1ec08771f65b245c 579 | SK_ER a6a8ac9ed8c6704f52a3ad1b7e4e5dea 580 | SK_PI e25acef0fc925dd1c7d4a2bbf2f67f0625e1bb30 581 | SK_PR 8f18458133afa71fcd12989bbaf419c95d8d71fd 582 | IKE SPI INITIATOR 69b541b68e0ea523 583 | IKE SPI RESPONDER 8e053a12b422eba8 584 | 585 | STATE 2: 586 | ------- 587 | sending IKE_AUTH (1) 588 | EAP 0113000efe0028af000000030100 589 | 590 | Received IKE message decoded: 591 | [[46, [[36, [2, b'n3iwf.free5gc.org']], [37, [4, b'0\x82\x03\xf90\x82\x02\xe1\xa0\x03\x02\x01\x02\x02\x14\x0b\xabB\xd3f\xbd\xbb\xc3\xd4\x80\xeb\xb5\xb1"\xf5\x11\xf4\xba\xe4\x050\r\x06\t*\x86H\x86\xf7\r\x01\x01\x0b\x05\x000\x81\x9c1\x0b0\t\x06\x03U\x04\x06\x13\x02TW1\x0f0\r\x06\x03U\x04\x08\x0c\x06Taiwan1\x0f0\r\x06\x03U\x04\x07\x0c\x06Taipei1\x100\x0e\x06\x03U\x04\n\x0c\x07WireLab1\x110\x0f\x06\x03U\x04\x0b\x0c\x08Wireless1*0(\x06\t*\x86H\x86\xf7\r\x01\t\x01\x16\x1bwirelab@wire.cs.nctu.edu.tw1\x1a0\x18\x06\x03U\x04\x03\x0c\x11n3iwf.free5gc.org0\x1e\x17\r200329114305Z\x17\r300327114305Z0\x81\x9c1\x0b0\t\x06\x03U\x04\x06\x13\x02TW1\x0f0\r\x06\x03U\x04\x08\x0c\x06Taiwan1\x0f0\r\x06\x03U\x04\x07\x0c\x06Taipei1\x100\x0e\x06\x03U\x04\n\x0c\x07WireLab1\x110\x0f\x06\x03U\x04\x0b\x0c\x08Wireless1*0(\x06\t*\x86H\x86\xf7\r\x01\t\x01\x16\x1bwirelab@wire.cs.nctu.edu.tw1\x1a0\x18\x06\x03U\x04\x03\x0c\x11n3iwf.free5gc.org0\x82\x01"0\r\x06\t*\x86H\x86\xf7\r\x01\x01\x01\x05\x00\x03\x82\x01\x0f\x000\x82\x01\n\x02\x82\x01\x01\x00\xc3\x90\x81\x13\xdf[\x97o<\xf7\xf2\xde\xb9\x0b\x92\xc7o\xdc%\x17\xc2UY\xd8\xdb\xfd\x84\x13\xdc]k\x9a\xfe\x16xs\x03\x1d\xad\xde\xc8\x8f\x8a\xef2c\x9cA"a\x0b\xa6\xbe\xfaOF\xf7o\xca\t\xd9\x82\xdf1 `Er\x9fq\x85|\xfa\xf5\xfd1\x8f\xa1t\xd3\xf8\x00\x8an\xb2\xbd\x8a\xf9\x92\xa5Hot\x8fM\xe6A\xd4\x18\x08\xd7/\xc5m\x80V;\xd6N)\xccU\x8c*\xee#\x97\xf4\'\xc5\xd5\'\x01a\x02\xa2\x0f\x1d8\xc7\x88\xf7\xd7.^\xa99\xeb#A\xd5\x94"\x00\x99\x00\xca}8\xf27+\x91pT&\xbf\xd2\xbd\xd4\xb2\'\xef\x12\xad\xfc25\x8cF\x83p`\x96Y\x1f\\i\x0b\x1a\xa1\xafX\xdb2\xc6c\x04\r\x82A\xf6\x8f\x7f\r\x86\xb2C\x17\x1a\x8c\xdf1\xaczV\x14\x1c\xcc\x15RX\x9c\xbd\xee\x8e\x8c\xc3\xda\x1a/W$4v\x9c\\\xfbN4=\x85+\xac\x18:\xd5\x0c\xb5|\xc0\x1b\xa6HN\xd2\x1e\xf0\xad\x80f&\xb8\x88\x04\t\x02\x03\x01\x00\x01\xa310/0\x1c\x06\x03U\x1d\x11\x04\x150\x13\x82\x11n3iwf.free5gc.org0\x0f\x06\x03U\x1d\x13\x04\x080\x06\x01\x01\xff\x02\x01\x000\r\x06\t*\x86H\x86\xf7\r\x01\x01\x0b\x05\x00\x03\x82\x01\x01\x00Q\xa2\xdd\x04\r\x02\xcdK\xb2W\xcd\xb6\x8e\x83d\x01M\xcd\x14\xda2|\x15\x94#\xf8\xfb\xa1f\xf4Z\xcb\x02`\x0b\x06jqf2\xaa\x90#<\xa8\xa8\xa8\xd3\xea\x08\xefb\x04\x87\xa9]5[\x8e\xaag\xdb\xbf\xf6\xa7\x9e\xa8T\xb7\xc2\xf0\x1a^\xbdj\xed\x16\xfc\xcc\xa9\xdaFa\xf3u\xd4\xa3\xe0\xc9\xba\xc1\xf6\xf5\xf8\xcf%\x8e\x13\x11\x0b-\xc4k\xc2\x1d\x1bql\xb0\xff\x95\xe8\x01\xd6j$\x89G\x0bIY&\x11\x8aJC.\xba\xdc\x06\x8a\xcdt\x18\xbf1\xad~\xb0\xa6\x1c\\\xd4.\x83\xd3\xb9\xd9\xd0p\x1fs@\xacD\xc4\x13\xe9\x95x\x8e\x83yO\xbc\xd7fO"\x177\xecb\x12\x92\x9b=\xe8A\xaf/R\xfd}\x85\xf3\xc7\x9b\xb4\x89\x0c\xa9X\xca=\x15C1\xa7\x8e\xb9\xf0m\xca\n\x93h\x1d\x90\x9f)\xde\xa3Z\xd7+\xb2n\xc7\xcf\xae\xf7\xd2.Y\x80\x8b\x95\x80\x83?\x05\x85\x12\xe6\xb7\x90q`=\x1b\x95\x81y\xe7au\xbbv\xad\xaf\xa23JqV']], [39, [1, b'\xa5#m\xdb\xbf\xec0\xcf~\xd4\x03\xd0\xd8\xd7\x87\xd4\xdb\x04%\x95\xe4\xe0\x03\'\xa3\xa0\xe2.]\x03w\xab\x94\xb0\xeak\xa7\rGb\xed\xe7\x95\x14dDxgh9N\x1a,\x1c\xb2\x1b!\xd0 k\xfb\x02\xf0,\x81\xf7\xda\xfa\x80\x19\x08\xaa\xdd\x1dEK4\xc7\xf2\xde\x1d\xb2Q\xda\xc8\xcf\x8a\xb0}+\xfb\x7f}\x91[}\xe2\xc0\x98!\x8f"\xf9\x06\xe5\x98:\xb2\x80\xc7\x9c!Sf\\uE\xde\x8e\x9f0\x05\xfe\x91#B\x05\x1d\x90\x00F|\xccMo\x84\xeb\xf7B\x8f:I#\x84\x90W\xd6\xfc\x85c\x97\xa3\x9a\x0e\x83\x7f\xbby \x9c~\xd9\xe0\xde\x0ePC\x98\x05z\xe3\x92\xe5\xc4\x02\x89\xdb\xac\xd8\xff\x04\'f\xb4\x14\x7f:\xf4x\xbf\x9fK\tY\xe6\xec2(g\r\xa2\xcf[\x86\x89"+\xcd\x02\xc5 PAYLOAD CONTAINER: PDU SESSION ESTABLISHMENT ACCEPT message received 689 | USERPLANE SESSION IPV4 ADDRESS 60.60.0.4 690 | cmd: ip netns exec baba ip link set dev tun3 up 691 | cmd: ip netns exec baba ip addr add 60.60.0.4/32 dev tun3 692 | cmd: ip netns exec baba route add -net 0.0.0.0/1 gw 60.60.0.4 693 | cmd: ip netns exec baba route add -net 128.0.0.0/1 gw 60.60.0.4 694 | 695 | Received IKE message decoded: 696 | [[46, [[33, [1, 3, b'\x98\x11\xee\x8b', b'\x00\x00\x00 \x01\x03\x04\x02\x98\x11\xee\x8b\x03\x00\x00\x0c\x01\x00\x00\x0c\x80\x0e\x01\x00\x00\x00\x00\x08\x05\x00\x00\x00']], [40, [b'\xf1\x1a\x00jk\x99\x17N)(\xac\x17\xc2\x93\xf3\x1d \xa0\x82\xe9\xe7\xb7Q\xbd\xe1\xbd\x10\xe7\t\x99\xc0\x8a\xd6\t\xedL0vt\xda\xae\x9dE\x04\xa1\xc7\xc7~\x07\xfby\xdf\nr\xcf\xe4\xa8Z\xa9\xdfYX\x96\x97\x1a\x0c;\x87 \xe7\xa8\xe6\x9e\xe1\xc2\xd3\xd4\x11l\xad\x10\x0f\xf0\xfc\xe0=af[\xade\xbdr\xee(\xbf\xcf\xaej\xd4\xad\xb4\x16\x19A\x93\x1b\x99\xf8\x84\x93aI\xa0/\xb0\x1bs\x85\x9f\xa5\xca\x91R\x1e\xd2x\xecrPF\xa3$\xceNZ\x0cL\x1aDW\x88H\x0b:\x7fo\xeeX0\x8d\xc5\x11\x12#\x91[sPv\xb0\xccdulb\xcd\xd69\xe8t3hM\xd5t\x95%\x96%\xf7\xc9H\xc1<\x16\x1f\n+\xe6\xfbw\x7f\xec\x8bzI^,{\x0f\xd7\xc6\xe5T5.\x8c\xe1\x9fFq\x81\xbfh\xd8-s\xa1\xd6\xb7\xb0\xdc]\x13\n----<5G-TMSI> 747 | ``` 748 | 749 | by Fabricio - 2022 750 | -------------------------------------------------------------------------------- /gNAS.py: -------------------------------------------------------------------------------- 1 | import struct 2 | import socket 3 | from binascii import hexlify, unhexlify 4 | 5 | 6 | _5GS_MM = 126 7 | _5GS_SM = 46 8 | 9 | #5GS MM Messages: 10 | 11 | REGISTRATION_REQUEST = 65 12 | REGISTRATION_ACCEPT = 66 13 | REGISTRATION_COMPLETE = 67 14 | REGISTRATION_REJECT = 68 15 | DEREGISTRATION_REQUEST_UE_ORIGINATING = 69 16 | DEREGISTRATION_ACCEPT_UE_ORIGINATING = 70 17 | DEREGISTRATION_REQUEST_UE_TERMINATED = 71 18 | DEREGISTRATION_ACCEPT_UE_TERMINATED = 72 19 | 20 | SERVICE_REQUEST = 76 21 | SERVICE_REJECT = 77 22 | SERVICE_ACCEPT = 78 23 | CONTROL_PLANE_SERVICE_REQUEST = 79 24 | 25 | NETWORK_SLICE_SPECIFIC_AUTHENTICATION_COMMAND = 80 26 | NETWORK_SLICE_SPECIFIC_AUTHENTICATION_COMPLETE = 81 27 | NETWORK_SLICE_SPECIFIC_AUTHENTICATION_RESULT = 82 28 | CONFIGURATION_UPDATE_COMMAND = 84 29 | CONFIGURATION_UPDATE_COMPLETE = 85 30 | AUTHENTICATION_REQUEST = 86 31 | AUTHENTICATION_RESPONSE = 87 32 | AUTHENTICATION_REJECT = 88 33 | AUTHENTICATION_FAILURE = 89 34 | AUTHENTICATION_RESULT = 90 35 | IDENTITY_REQUEST = 91 36 | IDENTITY_RESPONSE = 92 37 | SECURITY_MODE_COMMAND = 93 38 | SECURITY_MODE_COMPLETE = 94 39 | SECURITY_MODE_REJECT = 95 40 | 41 | _5GMM_STATUS = 100 42 | NOTIFICATION = 101 43 | NOTIFICATION_RESPONSE = 102 44 | UL_NAS_TRANSPORT = 103 45 | DL_NAS_TRANSPORT = 104 46 | 47 | #5GS SM Messages: 48 | 49 | PDU_SESSION_ESTABLISHMENT_REQUEST = 193 50 | PDU_SESSION_ESTABLISHMENT_ACCEPT = 194 51 | PDU_SESSION_ESTABLISHMENT_REJECT = 195 52 | PDU_SESSION_AUTHENTICATION_COMMAND = 197 53 | PDU_SESSION_AUTHENTICATION_COMPLETE = 198 54 | PDU_SESSION_AUTHENTICATION_RESULT = 199 55 | PDU_SESSION_MODIFICATION_REQUEST = 201 56 | PDU_SESSION_MODIFICATION_REJECT = 202 57 | PDU_SESSION_MODIFICATION_COMMAND = 203 58 | PDU_SESSION_MODIFICATION_COMPLETE = 204 59 | PDU_SESSION_MODIFICATION_COMMAND_REJECT = 205 60 | PDU_SESSION_RELEASE_REQUEST = 209 61 | PDU_SESSION_RELEASE_REJECT = 210 62 | PDU_SESSION_RELEASE_COMMAND = 211 63 | PDU_SESSION_RELEASE_COMPLETE = 212 64 | _5GSM_STATUS = 214 65 | 66 | 67 | # Security header 68 | PLAIN_5GS_NAS_MESSAGE = 0 69 | INTEGRITY_PROTECTED = 1 70 | INTEGRITY_PROTECTED_AND_CIPHERED = 2 71 | INTEGRITY_PROTECTED_WITH_NEW_5GS_MAS_SECURITY_CONTEXT = 3 72 | INTEGRITY_PROTECTED_AND_CIPHERED_WITH_NEW_5GS_MAS_SECURITY_CONTEXT = 4 73 | 74 | #5GS mobile_identity 75 | _5GS_MOBILE_IDENTITY_IE_TYPE_OF_IDENTITY__NO_IDENTITY = 0 76 | _5GS_MOBILE_IDENTITY_IE_TYPE_OF_IDENTITY__SUCI = 1 77 | _5GS_MOBILE_IDENTITY_IE_TYPE_OF_IDENTITY__5G_GUTI = 2 78 | _5GS_MOBILE_IDENTITY_IE_TYPE_OF_IDENTITY__IMEI = 3 79 | _5GS_MOBILE_IDENTITY_IE_TYPE_OF_IDENTITY__5G_S_TMSI = 4 80 | _5GS_MOBILE_IDENTITY_IE_TYPE_OF_IDENTITY__IMEISV = 5 81 | _5GS_MOBILE_IDENTITY_IE_TYPE_OF_IDENTITY__MAC_ADDRESS = 6 82 | _5GS_MOBILE_IDENTITY_IE_TYPE_OF_IDENTITY__EUI_64 = 7 83 | 84 | 85 | _5GS_MOBILE_IDENTITY_IE_SUPI_FORMAT__IMSI = 0 86 | _5GS_MOBILE_IDENTITY_IE_SUPI_FORMAT__NETWORK_SPECIFIC_FORMAT = 1 87 | _5GS_MOBILE_IDENTITY_IE_SUPI_FORMAT__GCI = 2 88 | _5GS_MOBILE_IDENTITY_IE_SUPI_FORMAT__GLI = 3 89 | 90 | _5GS_MOBILE_IDENTITY_IE_PROTECTION_SCHEME__NULL = 0 91 | _5GS_MOBILE_IDENTITY_IE_PROTECTION_SCHEME__ECIES_PROFILE_A = 1 92 | _5GS_MOBILE_IDENTITY_IE_PROTECTION_SCHEME__ECIES_PROFILE_B = 2 93 | 94 | 95 | KAMF_DERIVATION_IS_NOT_REQUIRED = 0 96 | KAMF_DERIVATION_IS_REQUIRED = 1 97 | 98 | RETRANSMISSION_OF_INITIAL_NAS_NOT_REQUESTED = 0 99 | RETRANSMISSION_OF_INITIAL_NAS_REQUESTED = 1 100 | 101 | IMEISV_NOT_REQUESTED = 0 102 | IMEISV_REQUESTED = 1 103 | 104 | 105 | PAYLOAD_CONTAINER_TYPE__N1_SM_INFORMATION = 1 106 | PAYLOAD_CONTAINER_TYPE__SMS = 2 107 | PAYLOAD_CONTAINER_TYPE__LTE_POSITIONING_PROTOCOL = 3 108 | PAYLOAD_CONTAINER_TYPE__SOR_TRANSPARENT_CONTAINER = 4 109 | PAYLOAD_CONTAINER_TYPE__UE_POLICY_CONTAINER = 5 110 | PAYLOAD_CONTAINER_TYPE__UE_PARAMETERS_UPDATE_TRANSPARENT_CONTAINER = 6 111 | PAYLOAD_CONTAINER_TYPE__LOCATION_SERVICES_MESSAGE_CONTAINER = 7 112 | PAYLOAD_CONTAINER_TYPE__CIOT_USER_DATA_CONTAINER = 8 113 | PAYLOAD_CONTAINER_TYPE__MULTIPLE_PAYLOADS = 9 114 | 115 | S_NSSAI_SST__EMBB = 1 116 | S_NSSAI_SST__URLLC = 2 117 | S_NSSAI_SST__MIOT = 3 118 | S_NSSAI_SST__V2X = 4 119 | 120 | IE_INTEGRITY_PROTECTION_MAXIMUM_DATA_RATE__64_KBPS = b'\x00\x00' 121 | IE_INTEGRITY_PROTECTION_MAXIMUM_DATA_RATE__NULL = b'\x01\x01' 122 | IE_INTEGRITY_PROTECTION_MAXIMUM_DATA_RATE__FULL_DATA_RATE = b'\xff\xff' 123 | 124 | 125 | IE_PDU_SESSION_TYPE__IPV4 = 1 126 | IE_PDU_SESSION_TYPE__IPV6 = 2 127 | IE_PDU_SESSION_TYPE__IPV4V6 = 3 128 | IE_PDU_SESSION_TYPE__UNSTRUCTURED = 4 129 | IE_PDU_SESSION_TYPE__ETHERNET = 5 130 | IE_PDU_SESSION_TYPE__RESERVED = 7 131 | 132 | 133 | IE_REQUEST_TYPE__INITIAL_REQUEST = 1 134 | IE_REQUEST_TYPE__EXISTING_PDU_SESSION = 2 135 | IE_REQUEST_TYPE__INITIAL_EMERGENCY_PDU_SESSION = 3 136 | IE_REQUEST_TYPE__EXISTING_EMERGENCY_PDU_SESSION = 4 137 | IE_REQUEST_TYPE__MODIFICATION_REQUEST = 5 138 | IE_REQUEST_TYPE__MA_PDU_REQUEST = 6 139 | IE_REQUEST_TYPE__RESERVED = 7 140 | 141 | IE_5GS_REGISTRATION_TYPE__INITIAL_REGISTRATION = 1 142 | IE_5GS_REGISTRATION_TYPE__MOBILITY_REGISTRATION_UPDATING = 2 143 | IE_5GS_REGISTRATION_TYPE__PERIODIC_REGISTRATION_UPDATING = 3 144 | IE_5GS_REGISTRATION_TYPE__EMERGENCY_REGISTRATION = 4 145 | IE_5GS_REGISTRATION_TYPE__RESERVED = 7 146 | 147 | IE_5GS_REGISTRATION_TYPE__FOR__NO_FOLLOW_ON_REQUEST_PENDING = 0 148 | IE_5GS_REGISTRATION_TYPE__FOR__FOLLOW_ON_REQUEST_PENDING = 1 149 | 150 | 151 | IE_5GMM_CAUSE__SYNCH_FAILURE = 21 152 | 153 | IE_5GSM_CAUSE__REGULAR_DEACTIVATION = 36 154 | 155 | 156 | IE_PCO_PROTOCOL_IDENTIFIER__LCP = 0xC021 157 | IE_PCO_PROTOCOL_IDENTIFIER__PAP = 0xC023 158 | IE_PCO_PROTOCOL_IDENTIFIER__CHAP = 0xC223 159 | IE_PCO_PROTOCOL_IDENTIFIER__IPCP = 0x8021 160 | IE_PCO_PROTOCOL_IDENTIFIER__P_CSCF_IPV6_ADDRESS = 0x1 161 | IE_PCO_PROTOCOL_IDENTIFIER__IM_CN_SUBSYSTEM_SIGNALING_FLAG = 0x2 162 | IE_PCO_PROTOCOL_IDENTIFIER__DNS_SERVER_IPV6_ADDRESS = 0x3 163 | IE_PCO_PROTOCOL_IDENTIFIER__POLICY_CONTROL_REJECTION_CODE = 0x4 164 | IE_PCO_PROTOCOL_IDENTIFIER__MS_SUPPORT_OF_NETWORK_REQUESTED_BEARER_CONTROL = 0x5 165 | IE_PCO_PROTOCOL_IDENTIFIER__DSMIPV6_HOME_AGENT_ADDRESS = 0x7 166 | IE_PCO_PROTOCOL_IDENTIFIER__DSMIPV6_HOME_AGENT_PREFIX = 0x8 167 | IE_PCO_PROTOCOL_IDENTIFIER__DSMIPV6_IPV4_HOME_AGENT_ADDRESS = 0x9 168 | IE_PCO_PROTOCOL_IDENTIFIER__IP_ADDRESS_ALLOCATION_VIA_NAS_SIGNALLING = 0xA 169 | IE_PCO_PROTOCOL_IDENTIFIER__IPV4_ALLOCATION_VIA_DHCPV4 = 0xB 170 | IE_PCO_PROTOCOL_IDENTIFIER__P_CSCF_IPV4_ADDRESS = 0xC 171 | IE_PCO_PROTOCOL_IDENTIFIER__DNS_SERVER_IPV4_ADDRESS = 0xD 172 | IE_PCO_PROTOCOL_IDENTIFIER__MSISDN = 0xE 173 | IE_PCO_PROTOCOL_IDENTIFIER__IFOM_SUPPORT = 0xF 174 | IE_PCO_PROTOCOL_IDENTIFIER__IPV4_LINK_MTU = 0x10 175 | IE_PCO_PROTOCOL_IDENTIFIER__MS_SUPPORT_OF_LOCAL_ADDRESS_IN_TFT_INDICATOR = 0x11 176 | IE_PCO_PROTOCOL_IDENTIFIER__P_CSCF_RE_SELECTION_SUPPORT = 0x12 177 | IE_PCO_PROTOCOL_IDENTIFIER__NBIFOM_REQUEST_INDICATOR = 0x13 178 | IE_PCO_PROTOCOL_IDENTIFIER__NBIFOM_MODE = 0x14 179 | IE_PCO_PROTOCOL_IDENTIFIER__NON_IP_LINK_MTU = 0x15 180 | IE_PCO_PROTOCOL_IDENTIFIER__APN_RATE_CONTROL_SUPPORT = 0x16 181 | IE_PCO_PROTOCOL_IDENTIFIER__3GPP_PS_DATA_OFF_UE_STATUS = 0x17 182 | IE_PCO_PROTOCOL_IDENTIFIER__RELIABLE_DATA_SERVICE = 0x18 183 | IE_PCO_PROTOCOL_IDENTIFIER__ADDITIONAL_APN_RATE_CONTROL_FOR_EXCEPTION_DATA_SUPPORT_INDICATOR = 0x19 184 | 185 | 186 | ############################################################# INTERNAL USE ######################################################### 187 | 188 | #IE NAMES FOR SEARCH PURPOSES 189 | IE_EXTENDED_PROTOCOL_DISCRIMINATOR = 1 190 | IE_SECURITY_HEADER = 2 191 | IE_MESSAGE_TYPE = 3 192 | IE_MESSAGE_AUTHENTICATION_CODE = 4 193 | IE_SEQUENCE_NUMBER = 5 194 | IE_NAS_MESSAGE_ENCRYPTED = 6 195 | IE_PDU_SESSION_IDENTITY = 7 196 | IE_PROCEDURE_TRANSACTION_IDENTITY = 8 197 | 198 | 199 | 200 | IE_5GS_REGISTRATION_RESULT = 100 201 | IE_5G_GUTI = 101 202 | IE_EQUIVALENT_PLMNS = 102 203 | IE_TAI_LIST = 103 204 | IE_ALLOWED_NSSAI = 104 205 | IE_REJECTED_NSSAI = 105 206 | IE_CONFIGURED_NSSAI = 106 207 | IE_5GS_NETWORK_FEATURE_SUPPORT = 107 208 | IE_T3512_VALUE = 108 209 | IE_NON_3GPP_DEREGISTRATION_TIMER_VALUE = 109 210 | IE_T3502_VALUE = 110 211 | 212 | IE_NAS_KEY_SET_IDENTIFIER = 111 213 | IE_ABBA = 112 214 | IE_RAND = 113 215 | IE_AUTN = 114 216 | IE_EAP_MESSAGE = 115 217 | IE_EPS_NAS_SECURITY_ALGORITHMS = 116 218 | IE_IMEISV_REQUEST = 117 219 | IE_ADDITIONAL_5G_SECURITY_INFORMATION = 118 220 | IE_S1_UE_SECURITY_CAPABILITIES = 119 221 | IE_NAS_SECURITY_ALGORITHMS = 120 222 | IE_UE_SECURITY_CAPABILITY = 121 223 | IE_PDU_SESSION_STATUS = 122 224 | IE_PDU_SESSION_REACTIVATION_RESULT = 123 225 | IE_PDU_SESSION_REACTIVATION_RESULT_ERROR = 124 226 | IE_LADN_INFORMATION = 125 227 | IE_MICO_INDICATION = 126 228 | IE_NETWORK_SLICING_INDICATION = 127 229 | IE_SERVICE_AREA_LIST = 128 230 | IE_EMERGENCY_NUMBER_LIST = 129 231 | IE_EXTENDED_EMERGENCY_NUMBER_LIST = 130 232 | IE_SOR_TRANSPARENT_CONTAINER = 131 233 | IE_NSSAI_INCLUSION_MODE = 132 234 | IE_OPERATOR_DEFINED_ACCESS_CATEGORY_DEFINITIONS = 133 235 | IE_5GS_DRX_PARAMETERS = 134 236 | IE_NON_3GPP_NW_PROVIDED_POLICIES = 135 237 | IE_EPS_BEARER_CONTEXT_STATUS = 136 238 | IE_EXTENDED_DRX_PARAMETERS = 137 239 | IE_T3447_VALUE = 138 240 | IE_T3448_VALUE = 139 241 | IE_T3324_VALUE = 140 242 | IE_UE_RADIO_CAPABILITY_ID = 141 243 | IE_UE_RADIO_CAPABILITY_ID_DELETION = 142 244 | IE_PENDING_NSSAI = 143 245 | IE_CIPHERING_KEY_DATA = 144 246 | IE_CAG_INFORMATION_LIST = 145 247 | IE_TRUNCATED_5G_S_TMSI_CONFIGURATION = 146 248 | IE_WUS_ASSISTANCE_INFORMATION = 147 249 | IE_NB_N1_MODE_DRX_PARAMETERS = 148 250 | IE_DDN = 149 251 | IE_PDU_SESSION_TYPE = 150 252 | IE_SSC_MODE = 151 253 | IE_QOS_RULES = 152 254 | IE_SESSION_AMBR = 153 255 | IE_5GSM_CAUSE = 154 256 | IE_PDU_ADDRESS = 155 257 | IE_RQ_TIMER_VALUE = 156 258 | IE_S_NSSAI = 157 259 | IE_ALWAYS_ON_PDU_SESSION_INDICATION = 158 260 | IE_MAPPED_EPS_BEARER_CONTEXTS = 159 261 | IE_QOS_FLOW_DESCRIPTIONS = 160 262 | IE_EXTENDED_PROTOCOL_CONFIGURATIONS_OPTIONS = 161 263 | IE_5GSM_NETWORK_FEATURE_SUPPORT = 162 264 | IE_SERVING_PLMN_RATE_CONTROL = 163 265 | IE_ATSSS_CONTAINER = 164 266 | IE_CONTROL_PLANE_ONLY_INDICATION = 165 267 | IE_IP_HEADER_COMPRESSION_CONFIGURATION = 166 268 | IE_ETHERNET_HEADER_COMPRESSION_CONFIGURATION = 167 269 | IE_BACK_OFF_TIMER_VALUE = 168 270 | IE_ALLOWED_SCC_MODE = 169 271 | IE_RE_ATTEMPT_INDICATOR = 170 272 | IE_5GSM_CONGESTION_RE_ATTEMPT_INDICATOR = 171 273 | IE_PAYLOAD_CONTAINER_TYPE = 172 274 | IE_PAYLOAD_CONTAINER = 173 275 | IE_ADDITIONAL_INFORMATION = 174 276 | IE_5GMM_CAUSE = 175 277 | IE_IDENTITY_TYPE = 176 278 | 279 | IE_DDN__DDN = 14801 280 | 281 | 282 | 283 | IE_ADDITIONAL_5G_SECURITY_INFORMATION__HDP = 11801 284 | IE_ADDITIONAL_5G_SECURITY_INFORMATION__RETRANSMISSION_OF_INITIAL_NAS = 11802 285 | 286 | 287 | IE_DECODER_5GS_TYPE_OF_IDENTITY = 40000 288 | IE_DECODER_5GS_MCC_MNC = 40001 289 | IE_DECODER_5GS_AMF_REGION_ID = 40002 290 | IE_DECODER_5GS_AMF_SET_ID = 40003 291 | IE_DECODER_5GS_AMF_POINTER = 40004 292 | IE_DECODER_5GS_5G_TMSI = 40005 293 | 294 | 295 | ###################################################################################################################### 296 | # D E C O D E F U N C T I O N S # 297 | ###################################################################################################################### 298 | 299 | 300 | #BASE FUNCTION to be called from external modules 301 | 302 | #only used for downlink messages 303 | #input: nas message 304 | 305 | 306 | def nas_decode(nas): #DONE 307 | nas_list = [] 308 | if nas == None: 309 | return nas_list 310 | 311 | extended_protocol_discriminator = nas[0] 312 | nas_list.append((IE_EXTENDED_PROTOCOL_DISCRIMINATOR, extended_protocol_discriminator)) 313 | if extended_protocol_discriminator == _5GS_MM: # 5GS_MM 314 | 315 | security_header = nas[1] 316 | nas_list.append((IE_SECURITY_HEADER, security_header)) 317 | if security_header == 0: # plain nas 318 | nas_list.append((IE_MESSAGE_TYPE, nas[2])) 319 | if len(nas)>3: 320 | emm_list = nas_decode_5gs_mm(nas[2], nas[3:]) 321 | nas_list += emm_list 322 | 323 | else: 324 | nas_list.append((IE_MESSAGE_AUTHENTICATION_CODE,nas[2:6])) 325 | nas_list.append((IE_SEQUENCE_NUMBER,nas[6])) 326 | nas_list.append((IE_NAS_MESSAGE_ENCRYPTED, nas[7:])) 327 | 328 | elif extended_protocol_discriminator == _5GS_SM: # 5GS_SM 329 | pdu_session_identity = nas[1] 330 | nas_list.append((IE_PDU_SESSION_IDENTITY, pdu_session_identity)) 331 | nas_list.append((IE_PROCEDURE_TRANSACTION_IDENTITY, nas[2])) 332 | nas_list.append((IE_MESSAGE_TYPE, nas[3])) 333 | if len(nas)>3: 334 | esm_list = nas_decode_5gs_sm(nas[3], nas[4:]) 335 | nas_list += esm_list 336 | #esm# 337 | 338 | return nas_list 339 | 340 | 341 | 342 | def return_ie_list_and_pointer(packet, iei_list, pointer, iei_type, name, size=0): #size is needed for V or TV tag type. 343 | # TV size=0 means tag and value in one byte 344 | # TV size= 1 means tag and 1 byte for value. return value as integer 345 | # TV size >1 means tag and n bytes for value. return bytes in range 346 | 347 | #V size = 1 means value in one byte return value as integer 348 | #V size > 1 means value in n bytes. return bytes in range 349 | 350 | if iei_type == 'V': 351 | if size == 1: 352 | iei_list.append((name, packet[pointer])) 353 | pointer += 1 354 | else: 355 | iei_list.append((name, packet[pointer:pointer+size])) 356 | pointer += size 357 | elif iei_type == 'LV': 358 | iei_list.append((name, packet[pointer+1:pointer+1+packet[pointer]])) 359 | pointer += 1+packet[pointer] 360 | elif iei_type == 'LV-E': 361 | iei_list.append((name, packet[pointer+2:pointer+2+packet[pointer]*256+packet[pointer+1]])) 362 | pointer += 2+packet[pointer]*256+packet[pointer+1] 363 | elif iei_type == 'TV': 364 | if size == 0: 365 | iei_list.append((name, packet[pointer] % 16)) 366 | pointer += 1 367 | elif size == 1: 368 | iei_list.append((name, packet[pointer+1])) 369 | pointer += 2 370 | else: 371 | iei_list.append((name, packet[pointer+1:pointer+1+size])) 372 | pointer += 1+size 373 | elif iei_type == 'TLV': 374 | iei_list.append((name, packet[pointer+2:pointer+2+packet[pointer+1]])) 375 | pointer += 2+packet[pointer+1] 376 | elif iei_type == 'TLV-E': 377 | iei_list.append((name, packet[pointer+3:pointer+3+packet[pointer+1]*256+packet[pointer+2]])) 378 | pointer += 3+packet[pointer+1]*256+packet[pointer+2] 379 | 380 | return iei_list, pointer 381 | 382 | 383 | #-------------------------------------# 384 | # # 385 | # 5 G S M M - P r o c e d u r e s # 386 | # # 387 | #-------------------------------------# 388 | 389 | #input: message_type and next bytes of nas with ies 390 | def nas_decode_5gs_mm(message_type, ies): #DONE 391 | ies_list = [] 392 | if message_type == REGISTRATION_ACCEPT: 393 | ies_list = nas_decode_5gs_mm_registration_accept(ies) 394 | elif message_type == REGISTRATION_REJECT: 395 | ies_list = nas_decode_5gs_mm_registration_reject(ies) 396 | elif message_type == DEREGISTRATION_REQUEST_UE_TERMINATED: 397 | ies_list = nas_decode_5gs_mm_deregistration_request(ies) 398 | elif message_type == DEREGISTRATION_ACCEPT_UE_ORIGINATING: 399 | ies_list = nas_decode_5gs_mm_deregistration_accept(ies) 400 | elif message_type == AUTHENTICATION_REQUEST: 401 | ies_list = nas_decode_5gs_mm_authentication_request(ies) 402 | elif message_type == AUTHENTICATION_REJECT: 403 | ies_list = nas_decode_5gs_mm_authentication_reject(ies) 404 | elif message_type == IDENTITY_REQUEST: 405 | ies_list = nas_decode_5gs_mm_identity_request(ies) 406 | elif message_type == SECURITY_MODE_COMMAND: 407 | ies_list = nas_decode_5gs_mm_security_mode_command(ies) 408 | elif message_type == DL_NAS_TRANSPORT: 409 | ies_list = nas_decode_5gs_mm_dl_nas_transport(ies) 410 | 411 | return ies_list 412 | 413 | 414 | def nas_decode_5gs_mm_dl_nas_transport(ies): 415 | ies_list, ies_size = [] , len(ies) 416 | ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,0,"V",IE_PAYLOAD_CONTAINER_TYPE,1) 417 | ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"LV-E",IE_PAYLOAD_CONTAINER) 418 | if pointer < ies_size and ies[pointer] == 0x12: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TV",IE_PDU_SESSION_IDENTITY,1) 419 | if pointer < ies_size and ies[pointer] == 0x24: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_ADDITIONAL_INFORMATION) 420 | if pointer < ies_size and ies[pointer] == 0x12: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TV",IE_5GMM_CAUSE,1) 421 | if pointer < ies_size and ies[pointer] == 0x37: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_BACK_OFF_TIMER_VALUE) 422 | return ies_list 423 | 424 | def nas_decode_5gs_mm_registration_accept(ies): #DONE 425 | ies_list, ies_size = [] , len(ies) 426 | ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,0,"LV",IE_5GS_REGISTRATION_RESULT) 427 | if pointer < ies_size and ies[pointer] == 0x77: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV-E",IE_5G_GUTI) 428 | if pointer < ies_size and ies[pointer] == 0x4A: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_EQUIVALENT_PLMNS) 429 | if pointer < ies_size and ies[pointer] == 0x54: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_TAI_LIST) 430 | if pointer < ies_size and ies[pointer] == 0x15: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_ALLOWED_NSSAI) 431 | if pointer < ies_size and ies[pointer] == 0x11: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_REJECTED_NSSAI) 432 | if pointer < ies_size and ies[pointer] == 0x31: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_CONFIGURED_NSSAI) 433 | if pointer < ies_size and ies[pointer] == 0x21: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_5GS_NETWORK_FEATURE_SUPPORT) 434 | if pointer < ies_size and ies[pointer] == 0x50: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_PDU_SESSION_STATUS) 435 | if pointer < ies_size and ies[pointer] == 0x26: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_PDU_SESSION_REACTIVATION_RESULT) 436 | if pointer < ies_size and ies[pointer] == 0x72: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV-E",IE_PDU_SESSION_REACTIVATION_RESULT_ERROR) 437 | if pointer < ies_size and ies[pointer] == 0x79: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV-E",IE_LADN_INFORMATION) 438 | if pointer < ies_size and ies[pointer] // 16 == 0xB: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TV",IE_MICO_INDICATION,0) 439 | if pointer < ies_size and ies[pointer] // 16 == 0x9: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TV",IE_NETWORK_SLICING_INDICATION,0) 440 | if pointer < ies_size and ies[pointer] == 0x27: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_SERVICE_AREA_LIST) 441 | if pointer < ies_size and ies[pointer] == 0x5e: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_T3512_VALUE) 442 | if pointer < ies_size and ies[pointer] == 0x5d: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_NON_3GPP_DEREGISTRATION_TIMER_VALUE) 443 | if pointer < ies_size and ies[pointer] == 0x16: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_T3502_VALUE) 444 | if pointer < ies_size and ies[pointer] == 0x34: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_EMERGENCY_NUMBER_LIST) 445 | if pointer < ies_size and ies[pointer] == 0x7a: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV-E",IE_EXTENDED_EMERGENCY_NUMBER_LIST) 446 | if pointer < ies_size and ies[pointer] == 0x73: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV-E",IE_SOR_TRANSPARENT_CONTAINER) 447 | if pointer < ies_size and ies[pointer] == 0x78: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV-E",IE_EAP_MESSAGE) 448 | if pointer < ies_size and ies[pointer] // 16 == 0xA: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TV",IE_NSSAI_INCLUSION_MODE,0) 449 | if pointer < ies_size and ies[pointer] == 0x76: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV-E",IE_OPERATOR_DEFINED_ACCESS_CATEGORY_DEFINITIONS) 450 | if pointer < ies_size and ies[pointer] == 0x51: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_5GS_DRX_PARAMETERS) 451 | if pointer < ies_size and ies[pointer] // 16 == 0xD: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TV",IE_NON_3GPP_NW_PROVIDED_POLICIES,0) 452 | if pointer < ies_size and ies[pointer] == 0x60: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_EPS_BEARER_CONTEXT_STATUS) 453 | 454 | if pointer < ies_size and ies[pointer] == 0x6e: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_EXTENDED_DRX_PARAMETERS) 455 | if pointer < ies_size and ies[pointer] == 0x6c: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_T3447_VALUE) 456 | if pointer < ies_size and ies[pointer] == 0x6b: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_T3448_VALUE) 457 | if pointer < ies_size and ies[pointer] == 0x6a: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_T3324_VALUE) 458 | if pointer < ies_size and ies[pointer] == 0x67: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_UE_RADIO_CAPABILITY_ID) 459 | if pointer < ies_size and ies[pointer] // 16 == 0xc: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TV",IE_UE_RADIO_CAPABILITY_ID_DELETION,0) 460 | if pointer < ies_size and ies[pointer] == 0x39: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_PENDING_NSSAI) 461 | if pointer < ies_size and ies[pointer] == 0x74: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV-E",IE_CIPHERING_KEY_DATA) 462 | if pointer < ies_size and ies[pointer] == 0x75: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV-E",IE_CAG_INFORMATION_LIST) 463 | if pointer < ies_size and ies[pointer] == 0x1b: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_TRUNCATED_5G_S_TMSI_CONFIGURATION) 464 | if pointer < ies_size and ies[pointer] == 0x1c: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_WUS_ASSISTANCE_INFORMATION) 465 | if pointer < ies_size and ies[pointer] == 0x29: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_NB_N1_MODE_DRX_PARAMETERS) 466 | 467 | 468 | return ies_list 469 | 470 | def nas_decode_5gs_mm_registration_reject(ies): 471 | ies_list, ies_size = [] , len(ies) 472 | 473 | return ies_list 474 | 475 | def nas_decode_5gs_mm_deregistration_request(ies): 476 | ies_list, ies_size = [] , len(ies) 477 | 478 | 479 | return ies_list 480 | 481 | def nas_decode_5gs_mm_deregistration_accept(ies): 482 | pass #done no IEI 483 | 484 | 485 | def nas_decode_5gs_mm_authentication_request(ies): #DONE 486 | ies_list, ies_size = [] , len(ies) 487 | ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,0,"V",IE_NAS_KEY_SET_IDENTIFIER,1) 488 | ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"LV",IE_ABBA,1) 489 | if pointer < ies_size and ies[pointer] == 0x21: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TV",IE_RAND,16) 490 | if pointer < ies_size and ies[pointer] == 0x20: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_AUTN) 491 | if pointer < ies_size and ies[pointer] == 0x78: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV-E",IE_EAP_MESSAGE) 492 | 493 | return ies_list 494 | 495 | 496 | 497 | def nas_decode_5gs_mm_authentication_reject(ies): #DONE 498 | ies_list = [] 499 | if ies[pointer] == 0x78: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,0,"TLV-E",IE_EAP_MESSAGE) 500 | 501 | return ies_list 502 | 503 | def nas_decode_5gs_mm_identity_request(ies): 504 | ies_list = [] 505 | ies_list.append((IE_IDENTITY_TYPE, ies[0] % 16)) 506 | 507 | return ies_list 508 | 509 | def nas_decode_5gs_mm_security_mode_command(ies): #DONE 510 | ies_list, ies_size = [] , len(ies) 511 | ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,0,"V",IE_NAS_SECURITY_ALGORITHMS,1) 512 | ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"V",IE_NAS_KEY_SET_IDENTIFIER,1) 513 | ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"LV",IE_UE_SECURITY_CAPABILITY) 514 | if pointer < ies_size and ies[pointer] // 16 == 0xE: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TV",IE_IMEISV_REQUEST,0) 515 | if pointer < ies_size and ies[pointer] == 0x57: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TV",IE_EPS_NAS_SECURITY_ALGORITHMS,1) 516 | if pointer < ies_size and ies[pointer] == 0x36: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_ADDITIONAL_5G_SECURITY_INFORMATION) 517 | if pointer < ies_size and ies[pointer] == 0x78: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV-E",IE_EAP_MESSAGE) 518 | if pointer < ies_size and ies[pointer] == 0x38: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_ABBA) 519 | if pointer < ies_size and ies[pointer] == 0x19: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_S1_UE_SECURITY_CAPABILITIES) 520 | 521 | return ies_list 522 | 523 | 524 | 525 | #-------------------------------------# 526 | # # 527 | # 5 G S S M - P r o c e d u r e s # 528 | # # 529 | #-------------------------------------# 530 | 531 | #inputs: message_type and next bytes of nas with ies 532 | def nas_decode_5gs_sm(message_type, ies): 533 | ies_list = [] 534 | if message_type == PDU_SESSION_ESTABLISHMENT_ACCEPT: 535 | ies_list = nas_decode_5gs_sm_pdu_session_establishment_accept(ies) 536 | elif message_type == PDU_SESSION_ESTABLISHMENT_REJECT: 537 | ies_list = nas_decode_5gs_sm_pdu_session_establishment_reject(ies) 538 | 539 | return ies_list 540 | 541 | 542 | def nas_decode_5gs_sm_pdu_session_establishment_accept(ies): 543 | ies_list, ies_size = [] , len(ies) 544 | ies_list.append((IE_PDU_SESSION_TYPE, ies[0]%16)) 545 | ies_list.append((IE_SSC_MODE, ies[0]//16)) 546 | ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,1,"LV-E",IE_QOS_RULES) 547 | ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"LV",IE_SESSION_AMBR) 548 | if pointer < ies_size and ies[pointer] == 0x59: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TV",IE_5GSM_CAUSE,1) 549 | if pointer < ies_size and ies[pointer] == 0x29: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_PDU_ADDRESS) 550 | if pointer < ies_size and ies[pointer] == 0x56: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TV",IE_RQ_TIMER_VALUE,1) 551 | if pointer < ies_size and ies[pointer] == 0x22: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_S_NSSAI) 552 | if pointer < ies_size and ies[pointer] // 16 == 0x8: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TV",IE_ALWAYS_ON_PDU_SESSION_INDICATION,0) 553 | if pointer < ies_size and ies[pointer] == 0x75: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV-E",IE_MAPPED_EPS_BEARER_CONTEXTS) 554 | if pointer < ies_size and ies[pointer] == 0x78: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV-E",IE_EAP_MESSAGE) 555 | if pointer < ies_size and ies[pointer] == 0x79: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV-E",IE_QOS_FLOW_DESCRIPTIONS) 556 | if pointer < ies_size and ies[pointer] == 0x7B: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV-E",IE_EXTENDED_PROTOCOL_CONFIGURATIONS_OPTIONS) 557 | if pointer < ies_size and ies[pointer] == 0x25: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_DDN) 558 | if pointer < ies_size and ies[pointer] == 0x17: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_5GSM_NETWORK_FEATURE_SUPPORT) 559 | if pointer < ies_size and ies[pointer] == 0x18: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_SERVING_PLMN_RATE_CONTROL) 560 | if pointer < ies_size and ies[pointer] == 0x77: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV-E",IE_ATSSS_CONTAINER) 561 | if pointer < ies_size and ies[pointer] // 16 == 0xC: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TV",IE_CONTROL_PLANE_ONLY_INDICATION,0) 562 | if pointer < ies_size and ies[pointer] == 0x66: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_IP_HEADER_COMPRESSION_CONFIGURATION) 563 | if pointer < ies_size and ies[pointer] == 0x1F: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_ETHERNET_HEADER_COMPRESSION_CONFIGURATION) 564 | return ies_list 565 | 566 | 567 | def nas_decode_5gs_sm_pdu_session_establishment_reject(ies): 568 | ies_list, ies_size = [] , len(ies) 569 | ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,0,"V",IE_5GSM_CAUSE,1) 570 | if pointer < ies_size and ies[pointer] == 0x37: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_BACK_OFF_TIMER_VALUE) 571 | if pointer < ies_size and ies[pointer] // 16 == 0xF: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TV",IE_ALLOWED_SCC_MODE,0) 572 | if pointer < ies_size and ies[pointer] == 0x78: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV-E",IE_EAP_MESSAGE) 573 | if pointer < ies_size and ies[pointer] == 0x7B: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV-E",IE_EXTENDED_PROTOCOL_CONFIGURATIONS_OPTIONS) 574 | if pointer < ies_size and ies[pointer] == 0x1D: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_RE_ATTEMPT_INDICATOR) 575 | if pointer < ies_size and ies[pointer] == 0x61: ies_list, pointer = return_ie_list_and_pointer(ies,ies_list,pointer,"TLV",IE_5GSM_CONGESTION_RE_ATTEMPT_INDICATOR) 576 | return ies_list 577 | 578 | 579 | ###################################################################################################################### 580 | # E N C O D E F U N C T I O N S # 581 | ###################################################################################################################### 582 | 583 | #[(protocol_discriminator, security_header), (iei1, format, value), (iei2, format, value), etc...] 584 | # iei = 0 if mandatory. i[2] in bytes format 585 | # other values as 0x19. i[2] in bytes format 586 | # if half byte it should be like 0xF. the other part i[2] is in decimal 587 | # 588 | #input nas_list with sequencial 589 | def nas_encode(nas_list): 590 | nas = b'' 591 | extended_protocol_discriminator = nas_list[0][0] 592 | security_header = nas_list[0][1] 593 | nas += bytes([extended_protocol_discriminator]) 594 | nas += bytes([security_header]) 595 | for i in range(1,len(nas_list)): 596 | if nas_list[i][0] == 0: 597 | if nas_list[i][1] == 'V': 598 | nas += nas_list[i][2] 599 | elif nas_list[i][1] == 'LV': 600 | nas += bytes([len(nas_list[i][2])]) + nas_list[i][2] 601 | elif nas_list[i][1] == 'LV-E': 602 | nas += bytes([len(nas_list[i][2])//256]) + bytes([len(nas_list[i][2])%256]) + nas_list[i][2] 603 | else: 604 | if nas_list[i][1] == "TV": 605 | if nas_list[i][0] < 16: #one hex symbol is just one byte len. always TV. Value in decimal 606 | nas += bytes([(nas_list[i][0]<<4) + nas_list[i][2]]) 607 | else: 608 | nas += bytes([nas_list[i][0]]) + nas_list[i][2] 609 | if nas_list[i][1] == "TLV": 610 | nas += bytes([nas_list[i][0]]) + bytes([len(nas_list[i][2])]) + nas_list[i][2] 611 | if nas_list[i][1] == "TLV-E": 612 | nas += bytes([nas_list[i][0]]) + bytes([len(nas_list[i][2])//256]) + bytes([len(nas_list[i][2])%256]) + nas_list[i][2] 613 | 614 | return nas 615 | 616 | 617 | ## Messages: ## MM 618 | 619 | def nas_security_protected_nas_message(security_header,message_authentication_code, count, nas_message): 620 | emm_list = [] 621 | emm_list.append((_5GS_MM,security_header)) # protocol discriminator / 622 | emm_list.append((0,'V',message_authentication_code)) # message type: authentication response 623 | emm_list.append((0,'V',bytes([count%256]))) 624 | emm_list.append((0,'V',nas_message)) 625 | return nas_encode(emm_list) 626 | 627 | def nas_5gs_mm_registration_request(mcc_mnc, imsi, _5gs_registration_type,nas_key_set_identifier): 628 | emm_list = [] 629 | emm_list.append((_5GS_MM,PLAIN_5GS_NAS_MESSAGE)) 630 | emm_list.append((0,'V',bytes([REGISTRATION_REQUEST]))) 631 | emm_list.append((0,'V',bytes([(nas_key_set_identifier<<4) + _5gs_registration_type]))) 632 | emm_list.append((0,'LV-E',encode_suci_null_scheme(mcc_mnc,imsi))) 633 | emm_list.append((0x10,'TLV',b'\x06')) 634 | emm_list.append((0x2E,'TLV',b'\x80\x20')) 635 | return nas_encode(emm_list) 636 | 637 | def nas_5gs_mm_registration_request_guti(mcc_mnc, amf_region_id, amf_set_id, amf_pointer, _5g_tmsi, _5gs_registration_type,nas_key_set_identifier): 638 | emm_list = [] 639 | emm_list.append((_5GS_MM,PLAIN_5GS_NAS_MESSAGE)) 640 | emm_list.append((0,'V',bytes([REGISTRATION_REQUEST]))) 641 | emm_list.append((0,'V',bytes([(nas_key_set_identifier<<4) + _5gs_registration_type]))) 642 | emm_list.append((0,'LV-E',encode_5g_guti(mcc_mnc, amf_region_id, amf_set_id, amf_pointer, _5g_tmsi))) 643 | emm_list.append((0x10,'TLV',b'\x06')) 644 | emm_list.append((0x2E,'TLV',b'\x80\x20')) 645 | return nas_encode(emm_list) 646 | 647 | def nas_5gs_mm_authentication_response(res= None, eap=None): 648 | emm_list = [] 649 | emm_list.append((_5GS_MM,PLAIN_5GS_NAS_MESSAGE)) 650 | emm_list.append((0,'V',bytes([AUTHENTICATION_RESPONSE]))) 651 | if res is not None: emm_list.append((0x2D,'TLV',res)) 652 | if eap is not None: emm_list.append((0x78,'TLV-E',eap)) 653 | return nas_encode(emm_list) 654 | 655 | 656 | def nas_5gs_mm_authentication_failure(cause, auts): 657 | emm_list = [] 658 | emm_list.append((_5GS_MM,PLAIN_5GS_NAS_MESSAGE)) 659 | emm_list.append((0,'V',bytes([AUTHENTICATION_FAILURE]))) 660 | emm_list.append((0,'V',bytes([cause]))) 661 | emm_list.append((0x30,'TLV',auts)) 662 | return nas_encode(emm_list) 663 | 664 | def nas_5gs_mm_security_mode_complete(imeisv, nas): 665 | emm_list = [] 666 | emm_list.append((_5GS_MM,PLAIN_5GS_NAS_MESSAGE)) 667 | emm_list.append((0,'V',bytes([SECURITY_MODE_COMPLETE]))) 668 | if imeisv is not None: emm_list.append((0x77,'TLV-E',encode_imei_imeisv(_5GS_MOBILE_IDENTITY_IE_TYPE_OF_IDENTITY__IMEISV,imeisv))) 669 | if nas is not None: emm_list.append((0x71, 'TLV-E', nas)) 670 | return nas_encode(emm_list) 671 | 672 | def nas_5gs_mm_registration_complete(): 673 | emm_list = [] 674 | emm_list.append((_5GS_MM,PLAIN_5GS_NAS_MESSAGE)) 675 | emm_list.append((0,'V',bytes([REGISTRATION_COMPLETE]))) 676 | return nas_encode(emm_list) 677 | 678 | 679 | def nas_5gs_mm_ul_nas_transport(payload_type, payload, pdu_session_id, request_type, s_nssai, ddn): 680 | emm_list = [] 681 | emm_list.append((_5GS_MM,PLAIN_5GS_NAS_MESSAGE)) 682 | emm_list.append((0,'V',bytes([UL_NAS_TRANSPORT]))) 683 | emm_list.append((0,'V',bytes([payload_type]))) 684 | emm_list.append((0,'LV-E',payload)) 685 | if pdu_session_id is not None: emm_list.append((0x12,'TV',bytes([pdu_session_id]))) 686 | if request_type is not None: emm_list.append((0x8,'TV',request_type)) 687 | if s_nssai is not None: emm_list.append((0x22,'TLV',s_nssai)) 688 | if ddn is not None: emm_list.append((0x25,'TLV',ddn)) 689 | return nas_encode(emm_list) 690 | 691 | def nas_5gs_mm_identity_response_suci(mcc_mnc,imsi): 692 | emm_list = [] 693 | emm_list.append((_5GS_MM,PLAIN_5GS_NAS_MESSAGE)) 694 | emm_list.append((0,'V',bytes([IDENTITY_RESPONSE]))) 695 | emm_list.append((0,'LV-E',encode_suci_null_scheme(mcc_mnc,imsi))) 696 | return nas_encode(emm_list) 697 | 698 | 699 | 700 | ## Messages: ## SM 701 | 702 | 703 | def nas_5gs_sm_pdu_session_establishment_request(pdu_session_id,pti,integrity_protection,pdu_session_type,always_on,extended_protocol_configurations): 704 | emm_list = [] 705 | emm_list.append((_5GS_SM,pdu_session_id)) 706 | emm_list.append((0,'V',bytes([pti]))) 707 | emm_list.append((0,'V',bytes([PDU_SESSION_ESTABLISHMENT_REQUEST]))) 708 | emm_list.append((0,'V',integrity_protection)) #2 bytes 709 | 710 | if pdu_session_type is not None: emm_list.append((0x9,'TV',pdu_session_type)) 711 | if always_on is not None: emm_list.append((0xB,'TV',always_on)) 712 | if extended_protocol_configurations is not None: emm_list.append((0x7B,'TLV-E',extended_protocol_configurations)) 713 | return nas_encode(emm_list) 714 | 715 | 716 | def nas_5gs_sm_pdu_session_release_request(pdu_session_id,pti,_5gsm_cause,extended_protocol_configurations): 717 | emm_list = [] 718 | emm_list.append((_5GS_SM,pdu_session_id)) 719 | emm_list.append((0,'V',bytes([pti]))) 720 | emm_list.append((0,'V',bytes([PDU_SESSION_RELEASE_REQUEST]))) 721 | 722 | if _5gsm_cause is not None: emm_list.append((0x59,'TV',bytes([_5gsm_cause]))) 723 | if extended_protocol_configurations is not None: emm_list.append((0x7B,'TLV-E',extended_protocol_configurations)) 724 | return nas_encode(emm_list) 725 | 726 | 727 | 728 | 729 | 730 | ###################################################################################################################### 731 | ###################################################################################################################### 732 | ###################################################################################################################### 733 | ###################################################################################################################### 734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 | 742 | ###################################################################################################################### 743 | ###################################################################################################################### 744 | ###################################################################################################################### 745 | # 746 | # specific Fucntions to decode some NAS IEI 747 | # 748 | # 749 | 750 | def decode_additional_5g_security_information(iei): #DONE 751 | iei_list = [] 752 | retrans_initial_nas = iei[0] % 4 // 2 753 | hdp = iei[0] % 2 754 | iei_list.append((IE_ADDITIONAL_5G_SECURITY_INFORMATION__HDP, hdp)) 755 | iei_list.append((IE_ADDITIONAL_5G_SECURITY_INFORMATION__RETRANSMISSION_OF_INITIAL_NAS, retrans_initial_nas)) 756 | return iei_list 757 | 758 | 759 | def decode_5gs_mobile_identity(iei): #DONE FOR 5G-GUTI 760 | iei_list = [] 761 | type_of_identity = iei[0] % 8 762 | iei_list.append((IE_DECODER_5GS_TYPE_OF_IDENTITY, type_of_identity)) 763 | if type_of_identity == _5GS_MOBILE_IDENTITY_IE_TYPE_OF_IDENTITY__5G_GUTI: #5g guti 764 | mcc = str(iei[1]%16) + str(iei[1]//16) + str(iei[2]%16) 765 | if iei[2] // 16 == 15: #1111 766 | mnc = str(iei[3]%16) + str(iei[3]//16) 767 | else: 768 | mnc = str(iei[3]%16) + str(iei[3]//16) + str(iei[2]//16) 769 | iei_list.append((IE_DECODER_5GS_MCC_MNC,int(mcc + mnc))) 770 | iei_list.append((IE_DECODER_5GS_AMF_REGION_ID, iei[4])) 771 | amf_region_id = (iei[5]<<2) + (iei[6]>>6) 772 | iei_list.append((IE_DECODER_5GS_AMF_SET_ID, amf_region_id)) 773 | iei_list.append((IE_DECODER_5GS_AMF_POINTER, iei[6]%64)) 774 | iei_list.append((IE_DECODER_5GS_5G_TMSI, iei[7:11])) 775 | return iei_list 776 | 777 | 778 | def decode_pdu_address(iei): #DONE 779 | iei_list = [] 780 | pdu_type_value = iei[0] % 8 781 | iei_list.append((IE_PDU_SESSION_TYPE, pdu_type_value)) 782 | if pdu_type_value == IE_PDU_SESSION_TYPE__IPV4: # ipv4 783 | iei_list.append((IE_PDU_SESSION_TYPE__IPV4,socket.inet_ntop(socket.AF_INET, iei[1:1+4]))) 784 | elif pdu_type_value == IE_PDU_SESSION_TYPE__IPV6: # ipv6 785 | iei_list.append((IE_PDU_SESSION_TYPE__IPV6, socket.inet_ntop(socket.AF_INET6, iei[1:1+8] + 8*b'\x00'))) 786 | elif pdu_type_value == IE_PDU_SESSION_TYPE__IPV4V6: # ipv4v6 787 | iei_list.append((IE_PDU_SESSION_TYPE__IPV6, socket.inet_ntop(socket.AF_INET6, iei[1:1+8] + 8*b'\x00'))) 788 | iei_list.append((IE_PDU_SESSION_TYPE__IPV4,socket.inet_ntop(socket.AF_INET, iei[9:9+4]))) 789 | return iei_list 790 | 791 | def decode_ddn(byteArray): #DONE 792 | a = [] 793 | pos = 0 794 | while pos < len(byteArray): 795 | i = int(byteArray[pos]) 796 | for x in range(pos+1, pos+1+i): 797 | a.append(chr(byteArray[x])) 798 | 799 | a.append(".") 800 | pos = pos+1+i 801 | 802 | return [(IE_DDN__DDN, ''.join(a)[:-1])] 803 | 804 | 805 | 806 | def decode_pco(iei): 807 | iei_list = [] 808 | position = 1 809 | while position < len(iei): 810 | protocol_id = struct.unpack("!H", iei[position:position+2])[0] 811 | length = iei[position+2] 812 | iei_list.append((protocol_id, iei[position+3:position+3+length])) 813 | position += 3 + length 814 | 815 | return iei_list 816 | 817 | ###################################################################################################################### 818 | ###################################################################################################################### 819 | ###################################################################################################################### 820 | # 821 | # specific Fucntions to encode some NAS IEI 822 | # 823 | # 824 | 825 | #related to 5GS Mobile Identity: 826 | 827 | def encode_pco(session_type): 828 | iei_list = [] 829 | if session_type == IE_PDU_SESSION_TYPE__IPV4: 830 | iei_list.append((IE_PCO_PROTOCOL_IDENTIFIER__DNS_SERVER_IPV4_ADDRESS,None)) 831 | elif session_type == IE_PDU_SESSION_TYPE__IPV6: 832 | iei_list.append((IE_PCO_PROTOCOL_IDENTIFIER__DNS_SERVER_IPV6_ADDRESS,None)) 833 | elif session_type == IE_PDU_SESSION_TYPE__IPV4V6: 834 | iei_list.append((IE_PCO_PROTOCOL_IDENTIFIER__DNS_SERVER_IPV4_ADDRESS,None)) 835 | iei_list.append((IE_PCO_PROTOCOL_IDENTIFIER__DNS_SERVER_IPV6_ADDRESS,None)) 836 | return encode_pco_generic(iei_list) 837 | 838 | def encode_pco_generic(iei_list): #return pco payload in bytes 839 | pco = b'\x80' 840 | for i in iei_list: 841 | pco += struct.pack("!H", i[0]) 842 | if i[1] is None: 843 | pco += b'\x00' 844 | else: 845 | pco += bytes([len(i[1])]) + i[1] 846 | return pco 847 | 848 | def encode_ddn(ddn): 849 | ddn_bytes = bytes() 850 | ddn_l = ddn.split(".") 851 | for word in ddn_l: 852 | ddn_bytes += struct.pack("!B", len(word)) + word.encode() 853 | return ddn_bytes 854 | 855 | 856 | def encode_5g_guti(mcc_mnc, amf_region_id, amf_set_id, amf_pointer, _5g_tmsi): 857 | guti = struct.pack("!B", (15<<4) + _5GS_MOBILE_IDENTITY_IE_TYPE_OF_IDENTITY__5G_GUTI) 858 | 859 | if len(mcc_mnc) == 5: mcc_mnc += 'f' 860 | guti += unhexlify(mcc_mnc[1] + mcc_mnc[0] + mcc_mnc[5] +mcc_mnc[2]+ mcc_mnc[4]+ mcc_mnc[3]) 861 | guti += struct.pack("!B", amf_region_id) 862 | guti += struct.pack("!H", (amf_set_id<<6) + amf_pointer) 863 | guti += struct.pack("!L", _5g_tmsi) 864 | return guti 865 | 866 | def encode_msin(msin): #DONE 867 | if len(msin) % 2 == 1: msin += 'f' 868 | aux = b'' 869 | for i in range(0,len(msin),2): 870 | aux += unhexlify(msin[i+1] + msin[i]) 871 | return aux 872 | 873 | def encode_suci_supi(mcc_mnc, type_identity, supi_format, ri1, ri2, ri3, ri4, protection_scheme, hnp_key_identifier, output): # DONE #output could by schemme output or msin in case of null scheme 874 | suci_supi = b'' 875 | suci_supi += struct.pack("!B", (supi_format<<4) + type_identity) 876 | if len(mcc_mnc) == 5: mcc_mnc += 'f' 877 | suci_supi += unhexlify(mcc_mnc[1] + mcc_mnc[0] + mcc_mnc[5] +mcc_mnc[2]+ mcc_mnc[4]+ mcc_mnc[3]) 878 | suci_supi += struct.pack("!B", (ri2<<4) + ri1) 879 | suci_supi += struct.pack("!B", (ri4<<4) + ri3) 880 | suci_supi += struct.pack("!B", protection_scheme) 881 | suci_supi += struct.pack("!B", hnp_key_identifier) 882 | suci_supi += output 883 | return suci_supi 884 | 885 | def encode_suci_null_scheme(mcc_mnc, imsi): #DONE 886 | return encode_suci_supi(mcc_mnc, _5GS_MOBILE_IDENTITY_IE_TYPE_OF_IDENTITY__SUCI, 887 | _5GS_MOBILE_IDENTITY_IE_SUPI_FORMAT__IMSI,0, 0xF, 0xF, 0xF, 888 | _5GS_MOBILE_IDENTITY_IE_PROTECTION_SCHEME__NULL,0,encode_msin(imsi[len(mcc_mnc):])) 889 | 890 | def encode_imei_imeisv(type_identity,imei): #DONE 891 | if len(imei) % 2 ==1: 892 | type_identity += 8 893 | else: 894 | imei += 'f' 895 | imei_imeisv = struct.pack("!B", (int(imei[0])<<4) +type_identity) 896 | for i in range(1,len(imei),2): 897 | imei_imeisv += unhexlify(imei[i+1] + imei[i]) 898 | return imei_imeisv 899 | 900 | 901 | def encode_s_nssai(sst,ssd=None, mapped_hplmn_sst = None, mapped_hplmn_ssd=None): 902 | s_nssai = bytes([sst]) 903 | if ssd is not None: s_nssai += struct.pack("!I",ssd)[1:] 904 | if mapped_hplmn_sst is not None: s_nssai += bytes([mapped_hplmn_sst]) 905 | if mapped_hplmn_ssd is not None: s_nssai += struct.pack("!I",mapped_hplmn_ssd)[1:] 906 | return s_nssai 907 | 908 | 909 | 910 | def encode_5gs_registration_type(_for, _5gs_registration_type_value): 911 | return 8*_for + _5gs_registration_type_value 912 | 913 | ############################################################ 914 | ############################################################ 915 | 916 | def get_nas_ie_by_name(nas_list, name): 917 | for i in nas_list: 918 | if i[0] == name: 919 | return i[1] 920 | return None 921 | 922 | def get_pco_element_by_name(pco_list, name): 923 | pco_return_list = [] 924 | for i in pco_list: 925 | if i[0] == name: 926 | pco_return_list.append(i[1]) 927 | return pco_return_list 928 | 929 | def get_ip_str_from_ip_bytes(ip_list): 930 | return_list = [] 931 | for i in ip_list: 932 | if len(i) == 4: 933 | return_list.append(socket.inet_ntop(socket.AF_INET,i)) 934 | elif len(i) == 16: 935 | return_list.append(socket.inet_ntop(socket.AF_INET6,i)) 936 | return return_list 937 | 938 | -------------------------------------------------------------------------------- /gSECURITY.py: -------------------------------------------------------------------------------- 1 | from Crypto.Hash import HMAC 2 | from Crypto.Hash import SHA256 3 | from CryptoMobile.CM import * 4 | from binascii import hexlify, unhexlify 5 | import struct 6 | from datetime import datetime 7 | 8 | DIRECTION_DOWN = 1 9 | DIRECTION_UP = 0 10 | 11 | 12 | BEARER_ID_NAS_CONNECTION_IDENTIFIER_3GPP = 0x1 13 | BEARER_ID_NAS_CONNECTION_IDENTIFIER_NON_3GPP = 0x2 14 | 15 | # print with timestamp information. comment next 4 lines if you don't want timestamp information. 16 | old_print = print 17 | def timestamped_print(*args, **kwargs): 18 | old_print(bcolors.OKBLUE + '[',datetime.now(),']'+bcolors.ENDC, *args, **kwargs) 19 | print = timestamped_print 20 | 21 | class bcolors: 22 | HEADER = '\033[95m' 23 | OKBLUE = '\033[94m' 24 | OKGREEN = '\033[92m' 25 | WARNING = '\033[93m' 26 | FAIL = '\033[91m' 27 | ENDC = '\033[0m' 28 | BOLD = '\033[1m' 29 | UNDERLINE = '\033[4m' 30 | 31 | def bcd_bytes(chars): 32 | bcd_string = "" 33 | for i in range(len(chars) // 2): 34 | bcd_string += chars[1+2*i] + chars[2*i] 35 | return bytes(bytearray.fromhex(bcd_string)) 36 | 37 | def return_plmn(mccmnc): 38 | mccmnc = str(mccmnc) 39 | if len(mccmnc)==5: 40 | return bcd_bytes(mccmnc[0] + mccmnc[1] + mccmnc[2] + 'f' + mccmnc[3] + mccmnc[4]) 41 | elif len(mccmnc)==6: 42 | return bcd_bytes(mccmnc[0] + mccmnc[1] + mccmnc[2] + mccmnc[5] + mccmnc[3] + mccmnc[4]) 43 | else: 44 | return b'' 45 | 46 | def return_5g_plmn(mccmnc): 47 | mcc = mccmnc[0:3] 48 | if len(mccmnc)==5: 49 | mnc = '0' + mccmnc[3:5] 50 | else: 51 | mnc = mccmnc[3:6] 52 | 53 | return b'5G:mnc' + mnc.encode('utf-8') + b'.mcc' + mcc.encode('utf-8') + b'.3gppnetwork.org' 54 | 55 | 56 | #33.501# 57 | #A.2 58 | def return_kausf(plmn, autn, ck, ik): 59 | key = unhexlify(ck + ik) 60 | sqn_xor_ak = autn[0:12] 61 | plmn = return_5g_plmn(plmn) 62 | message = unhexlify('6a') + plmn + unhexlify('00') + bytes([len(plmn)]) + unhexlify(sqn_xor_ak + '0006') 63 | h = HMAC.new(key, msg=message, digestmod=SHA256) 64 | return h.digest()[-32:] 65 | 66 | #A.4 67 | def return_res_star(plmn, rand, res, ck, ik): 68 | key = unhexlify(ck + ik) 69 | plmn = return_5g_plmn(plmn) 70 | print(plmn) 71 | message = unhexlify('6b') + plmn + unhexlify('00') + bytes([len(plmn)]) + unhexlify(rand + '0010' + res + '0008') 72 | h = HMAC.new(key, msg=message, digestmod=SHA256) 73 | return h.digest()[-16:] 74 | 75 | #A.5 76 | def return_hres_star( rand, xres): 77 | s = unhexlify(rand) + xres 78 | h = SHA256.new(s) 79 | return h.digest()[-16:] 80 | 81 | 82 | #A.6 83 | def return_kseaf(plmn, kausf): 84 | key = kausf 85 | plmn = return_5g_plmn(plmn) 86 | message = unhexlify('6c') + plmn + unhexlify('00') + bytes([len(plmn)]) 87 | h = HMAC.new(key, msg=message, digestmod=SHA256) 88 | return h.digest()[-32:] 89 | 90 | def return_kseaf_eap_aka_prime(access_network_identity, kausf): 91 | key = kausf 92 | message = unhexlify('6c') + access_network_identity + unhexlify('00') + bytes([len(access_network_identity)]) 93 | h = HMAC.new(key, msg=message, digestmod=SHA256) 94 | return h.digest()[-32:] 95 | 96 | 97 | #A.7 98 | def return_kamf(supi, abba, kseaf): 99 | key = kseaf 100 | message = unhexlify('6d') + supi.encode('utf-8') + unhexlify('00') + bytes([len(supi)]) + abba + unhexlify('00') + bytes([len(abba)]) 101 | h = HMAC.new(key, msg=message, digestmod=SHA256) 102 | return h.digest()[-32:] 103 | 104 | 105 | #A.8 106 | def algorithm_key_derivation_function(algo_type,algo_identity, kamf): 107 | key = kamf 108 | message = unhexlify('69') + bytes([algo_type]) + unhexlify('0001') + bytes([algo_identity]) + unhexlify('0001') 109 | h = HMAC.new(key, msg=message, digestmod=SHA256) 110 | return h.digest()[-16:] 111 | 112 | 113 | 114 | def return_all_possible_keys(plmn, autn, ck, ik, abba, supi, print_keys = False): 115 | kausf = return_kausf(plmn, autn, ck, ik) 116 | kseaf = return_kseaf(plmn, kausf) 117 | kamf = return_kamf(supi, abba, kseaf) 118 | nas_enc_alg1 = algorithm_key_derivation_function(1,1,kamf) 119 | nas_enc_alg2 = algorithm_key_derivation_function(1,2,kamf) 120 | nas_enc_alg3 = algorithm_key_derivation_function(1,3,kamf) 121 | nas_int_alg1 = algorithm_key_derivation_function(2,1,kamf) 122 | nas_int_alg2 = algorithm_key_derivation_function(2,2,kamf) 123 | nas_int_alg3 = algorithm_key_derivation_function(2,3,kamf) 124 | if print_keys == True: 125 | print('KAUSF', hexlify(kausf).decode('utf-8')) 126 | print('KSEAF', hexlify(kseaf).decode('utf-8')) 127 | print('KAMF', hexlify(kamf).decode('utf-8')) 128 | print('EEA1-KEY', hexlify(nas_enc_alg1).decode('utf-8')) 129 | print('EEA2-KEY', hexlify(nas_enc_alg2).decode('utf-8')) 130 | print('EEA3-KEY', hexlify(nas_enc_alg3).decode('utf-8')) 131 | print('EIA1-KEY', hexlify(nas_int_alg1).decode('utf-8')) 132 | print('EIA2-KEY', hexlify(nas_int_alg2).decode('utf-8')) 133 | print('EIA3-KEY', hexlify(nas_int_alg3).decode('utf-8')) 134 | 135 | return kausf, kseaf, kamf, nas_enc_alg1, nas_enc_alg2, nas_enc_alg3, nas_int_alg1, nas_int_alg2, nas_int_alg3 136 | 137 | 138 | def return_all_possible_keys_eap_aka_prime(access_network_identity, kausf, abba, supi, print_keys = False): 139 | kseaf = return_kseaf_eap_aka_prime(access_network_identity, kausf) 140 | kamf = return_kamf(supi, abba, kseaf) 141 | nas_enc_alg1 = algorithm_key_derivation_function(1,1,kamf) 142 | nas_enc_alg2 = algorithm_key_derivation_function(1,2,kamf) 143 | nas_enc_alg3 = algorithm_key_derivation_function(1,3,kamf) 144 | nas_int_alg1 = algorithm_key_derivation_function(2,1,kamf) 145 | nas_int_alg2 = algorithm_key_derivation_function(2,2,kamf) 146 | nas_int_alg3 = algorithm_key_derivation_function(2,3,kamf) 147 | if print_keys == True: 148 | print('KSEAF', hexlify(kseaf).decode('utf-8')) 149 | print('KAMF', hexlify(kamf).decode('utf-8')) 150 | print('EEA1-KEY', hexlify(nas_enc_alg1).decode('utf-8')) 151 | print('EEA2-KEY', hexlify(nas_enc_alg2).decode('utf-8')) 152 | print('EEA3-KEY', hexlify(nas_enc_alg3).decode('utf-8')) 153 | print('EIA1-KEY', hexlify(nas_int_alg1).decode('utf-8')) 154 | print('EIA2-KEY', hexlify(nas_int_alg2).decode('utf-8')) 155 | print('EIA3-KEY', hexlify(nas_int_alg3).decode('utf-8')) 156 | 157 | return kseaf, kamf, nas_enc_alg1, nas_enc_alg2, nas_enc_alg3, nas_int_alg1, nas_int_alg2, nas_int_alg3 158 | 159 | 160 | #A.9 161 | def return_kgnb_kn3iwf(kamf, uplink_count, access_type): 162 | key = kamf 163 | message = unhexlify('6e') + struct.pack('!I',uplink_count) + unhexlify('0004') + bytes([access_type]) + unhexlify('0001') 164 | h = HMAC.new(key, msg=message, digestmod=SHA256) 165 | return h.digest()[-32:] 166 | 167 | 168 | 169 | 170 | # Annex B 171 | 172 | def nas_hash_func(nas, count, dir, key, algo, bearer_id): 173 | sqn=bytes([count%256]) #last byte 174 | if algo == 1: 175 | return EIA1(key, count, bearer_id, dir, sqn+nas) 176 | elif algo ==2: 177 | return EIA2(key, count, bearer_id, dir, sqn+nas) 178 | elif algo ==3: 179 | return EIA3(key, count, bearer_id, dir, sqn+nas) 180 | else: 181 | return b'\x00\x00\x00\x00' 182 | 183 | def nas_encrypt_func(nas, count, dir, key, algo, bearer_id): 184 | if algo == 1: 185 | return EEA1(key, count, bearer_id, dir, nas) 186 | elif algo ==2: 187 | return EEA2(key, count, bearer_id, dir, nas) 188 | elif algo ==3: 189 | return EEA3(key, count, bearer_id, dir, nas) 190 | else: 191 | return nas 192 | 193 | 194 | #33.402 A.2 195 | def return_ck_prime_ik_prime(access_network, autn, ck, ik): #autn ck and ik in hex string 196 | key = unhexlify(ck + ik) 197 | sqn_xor_ak = autn[0:12] 198 | message = unhexlify('20') +access_network + unhexlify('00') + bytes([len(access_network)]) + unhexlify(sqn_xor_ak + '0006') 199 | h = HMAC.new(key, msg=message, digestmod=SHA256) 200 | ck_prime_ik_prime= h.digest() 201 | return ck_prime_ik_prime[:16], ck_prime_ik_prime[-16:] -------------------------------------------------------------------------------- /images/...: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /images/5g_aka_authentication.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fasferraz/NWu-Non3GPP-5GC/9d98653fd7965afdcb57f4e52c0ce50962eb4be1/images/5g_aka_authentication.png -------------------------------------------------------------------------------- /images/NWu_Emulator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fasferraz/NWu-Non3GPP-5GC/9d98653fd7965afdcb57f4e52c0ce50962eb4be1/images/NWu_Emulator.png -------------------------------------------------------------------------------- /images/eap_aka_prime_authentication.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fasferraz/NWu-Non3GPP-5GC/9d98653fd7965afdcb57f4e52c0ce50962eb4be1/images/eap_aka_prime_authentication.png -------------------------------------------------------------------------------- /images/free5gc_setup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fasferraz/NWu-Non3GPP-5GC/9d98653fd7965afdcb57f4e52c0ce50962eb4be1/images/free5gc_setup.png -------------------------------------------------------------------------------- /images/non3gpp_untrusted_authentication.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fasferraz/NWu-Non3GPP-5GC/9d98653fd7965afdcb57f4e52c0ce50962eb4be1/images/non3gpp_untrusted_authentication.png --------------------------------------------------------------------------------