T 136 | 000003E0: 68 69 73 20 64 6F 6D 61 69 6E 20 69 73 20 65 73 his domain is es 137 | 000003F0: 74 61 62 6C 69 73 68 65 64 20 74 6F 20 62 65 20 tablished to be 138 | 139 | SSL Session: 1820201001719DF42ECCA1D289C3D32E0AA0454B50E8AF00E8A65B0108F209A8 140 | [SSL_read] 93.184.216.34:443 --> 100.97.20.44:45836 141 | 00000000: 75 73 65 64 20 66 6F 72 20 69 6C 6C 75 73 74 72 used for illustr 142 | 00000010: 61 74 69 76 65 20 65 78 61 6D 70 6C 65 73 20 69 ative examples i 143 | 00000020: 6E 20 64 6F 63 75 6D 65 6E 74 73 2E 20 59 6F 75 n documents. You 144 | 00000030: 20 6D 61 79 20 75 73 65 20 74 68 69 73 0A 20 20 may use this. 145 | 00000040: 20 20 64 6F 6D 61 69 6E 20 69 6E 20 65 78 61 6D domain in exam 146 | 00000050: 70 6C 65 73 20 77 69 74 68 6F 75 74 20 70 72 69 ples without pri 147 | 00000060: 6F 72 20 63 6F 6F 72 64 69 6E 61 74 69 6F 6E 20 or coordination 148 | 00000070: 6F 72 20 61 73 6B 69 6E 67 20 66 6F 72 20 70 65 or asking for pe 149 | 00000080: 72 6D 69 73 73 69 6F 6E 2E 3C 2F 70 3E 0A 20 20 rmission.
. 150 | 00000090: 20 20 3C 70 3E 3C 61 20 68 72 65 66 3D 22 68 74More informat 154 | 000000D0: 69 6F 6E 2E 2E 2E 3C 2F 61 3E 3C 2F 70 3E 0A 3C ion...
.< 155 | 000000E0: 2F 64 69 76 3E 0A 3C 2F 62 6F 64 79 3E 0A 3C 2F /div>.. 156 | 000000F0: 68 74 6D 6C 3E 0A html>. 157 | ``` 158 | 159 | ## Dependencies 160 | This program uses the [frida](https://www.frida.re/) framework to perform code injection. 161 | 162 | Frida can be installed as follows: `sudo pip install frida` 163 | 164 | ## TODO 165 | 166 | - Add support for processes that communicate via SSL without using [libssl](https://wiki.openssl.org/index.php/Libssl_API). 167 | - Allow user to run *ssl_logger* before starting the process to be logged. 168 | 169 | 170 | ## Disclaimer 171 | 172 | This is not an official Google product. -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. -------------------------------------------------------------------------------- /ssl_logger.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Google Inc. All Rights Reserved. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """Decrypts and logs a process's SSL traffic. 16 | 17 | Hooks the functions SSL_read() and SSL_write() in a given process and logs the 18 | decrypted data to the console and/or to a pcap file. 19 | 20 | Typical usage example: 21 | 22 | ssl_log("wget", "log.pcap", True) 23 | 24 | Dependencies: 25 | frida (https://www.frida.re/): 26 | sudo pip install frida 27 | hexdump (https://bitbucket.org/techtonik/hexdump/) if using verbose output: 28 | sudo pip install hexdump 29 | """ 30 | 31 | __author__ = "geffner@google.com (Jason Geffner)" 32 | __version__ = "1.0" 33 | 34 | 35 | import argparse 36 | import os 37 | import platform 38 | import pprint 39 | import random 40 | import signal 41 | import socket 42 | import struct 43 | import time 44 | 45 | import frida 46 | 47 | try: 48 | import hexdump # pylint: disable=g-import-not-at-top 49 | except ImportError: 50 | pass 51 | 52 | 53 | _FRIDA_SCRIPT = """ 54 | /** 55 | * Initializes 'addresses' dictionary and NativeFunctions. 56 | */ 57 | function initializeGlobals() 58 | { 59 | global.addresses = {}; 60 | 61 | var resolver = new ApiResolver("module"); 62 | 63 | var exps = [ 64 | ["*libssl*", 65 | ["SSL_read", "SSL_write", "SSL_get_fd", "SSL_get_session", 66 | "SSL_SESSION_get_id"]], 67 | [Process.platform == "darwin" ? "*libsystem*" : "*libc*", 68 | ["getpeername", "getsockname"]] 69 | ]; 70 | for (var i = 0; i < exps.length; i++) 71 | { 72 | var lib = exps[i][0]; 73 | var names = exps[i][1]; 74 | 75 | for (var j = 0; j < names.length; j++) 76 | { 77 | var name = names[j]; 78 | var matches = resolver.enumerateMatchesSync("exports:" + lib + "!" + 79 | name); 80 | if (matches.length == 0) 81 | { 82 | throw "Could not find " + lib + "!" + name; 83 | } 84 | else if (matches.length != 1) 85 | { 86 | // Sometimes Frida returns duplicates. 87 | var address = 0; 88 | var s = ""; 89 | var duplicates_only = true; 90 | for (var k = 0; k < matches.length; k++) 91 | { 92 | if (s.length != 0) 93 | { 94 | s += ", "; 95 | } 96 | s += matches[k].name + "@" + matches[k].address; 97 | if (address == 0) 98 | { 99 | address = matches[k].address; 100 | } 101 | else if (!address.equals(matches[k].address)) 102 | { 103 | duplicates_only = false; 104 | } 105 | } 106 | if (!duplicates_only) 107 | { 108 | throw "More than one match found for " + lib + "!" + name + ": " + 109 | s; 110 | } 111 | } 112 | addresses[name] = matches[0].address; 113 | } 114 | } 115 | 116 | global.SSL_get_fd = new NativeFunction(addresses["SSL_get_fd"], "int", 117 | ["pointer"]); 118 | global.SSL_get_session = new NativeFunction(addresses["SSL_get_session"], 119 | "pointer", ["pointer"]); 120 | global.SSL_SESSION_get_id = new NativeFunction(addresses["SSL_SESSION_get_id"], 121 | "pointer", ["pointer", "pointer"]); 122 | global.getpeername = new NativeFunction(addresses["getpeername"], "int", ["int", 123 | "pointer", "pointer"]); 124 | global.getsockname = new NativeFunction(addresses["getsockname"], "int", ["int", 125 | "pointer", "pointer"]); 126 | } 127 | initializeGlobals(); 128 | 129 | /** 130 | * Returns a dictionary of a sockfd's "src_addr", "src_port", "dst_addr", and 131 | * "dst_port". 132 | * @param {int} sockfd The file descriptor of the socket to inspect. 133 | * @param {boolean} isRead If true, the context is an SSL_read call. If 134 | * false, the context is an SSL_write call. 135 | * @return {dict} Dictionary of sockfd's "src_addr", "src_port", "dst_addr", 136 | * and "dst_port". 137 | */ 138 | function getPortsAndAddresses(sockfd, isRead) 139 | { 140 | var message = {}; 141 | 142 | var addrlen = Memory.alloc(4); 143 | var addr = Memory.alloc(16); 144 | 145 | var src_dst = ["src", "dst"]; 146 | for (var i = 0; i < src_dst.length; i++) 147 | { 148 | Memory.writeU32(addrlen, 16); 149 | if ((src_dst[i] == "src") ^ isRead) 150 | { 151 | getsockname(sockfd, addr, addrlen); 152 | } 153 | else 154 | { 155 | getpeername(sockfd, addr, addrlen); 156 | } 157 | message[src_dst[i] + "_port"] = Memory.readU16(addr.add(2)); 158 | message[src_dst[i] + "_addr"] = Memory.readU32(addr.add(4)); 159 | } 160 | 161 | return message; 162 | } 163 | 164 | /** 165 | * Get the session_id of SSL object and return it as a hex string. 166 | * @param {!NativePointer} ssl A pointer to an SSL object. 167 | * @return {dict} A string representing the session_id of the SSL object's 168 | * SSL_SESSION. For example, 169 | * "59FD71B7B90202F359D89E66AE4E61247954E28431F6C6AC46625D472FF76336". 170 | */ 171 | function getSslSessionId(ssl) 172 | { 173 | var session = SSL_get_session(ssl); 174 | if (session == 0) 175 | { 176 | return 0; 177 | } 178 | var len = Memory.alloc(4); 179 | var p = SSL_SESSION_get_id(session, len); 180 | len = Memory.readU32(len); 181 | 182 | var session_id = ""; 183 | for (var i = 0; i < len; i++) 184 | { 185 | // Read a byte, convert it to a hex string (0xAB ==> "AB"), and append 186 | // it to session_id. 187 | session_id += 188 | ("0" + Memory.readU8(p.add(i)).toString(16).toUpperCase()).substr(-2); 189 | } 190 | 191 | return session_id; 192 | } 193 | 194 | Interceptor.attach(addresses["SSL_read"], 195 | { 196 | onEnter: function (args) 197 | { 198 | var message = getPortsAndAddresses(SSL_get_fd(args[0]), true); 199 | message["ssl_session_id"] = getSslSessionId(args[0]); 200 | message["function"] = "SSL_read"; 201 | this.message = message; 202 | this.buf = args[1]; 203 | }, 204 | onLeave: function (retval) 205 | { 206 | retval |= 0; // Cast retval to 32-bit integer. 207 | if (retval <= 0) 208 | { 209 | return; 210 | } 211 | send(this.message, Memory.readByteArray(this.buf, retval)); 212 | } 213 | }); 214 | 215 | Interceptor.attach(addresses["SSL_write"], 216 | { 217 | onEnter: function (args) 218 | { 219 | var message = getPortsAndAddresses(SSL_get_fd(args[0]), false); 220 | message["ssl_session_id"] = getSslSessionId(args[0]); 221 | message["function"] = "SSL_write"; 222 | send(message, Memory.readByteArray(args[1], parseInt(args[2]))); 223 | }, 224 | 225 | onLeave: function (retval) 226 | { 227 | } 228 | }); 229 | """ 230 | 231 | 232 | # ssl_session[