blob: 37d73af3378854619ec831b44457edbe24d86763 [file] [log] [blame]
Austin Schuh8d0a2852019-12-28 22:54:28 -08001/* Wrap socket() to force the protocol to SCTP for STREAM connections.
2 *
3 * Thanks to Midgard Security Services for
4 * http://www.securiteam.com/tools/3D5PTR5QAE.html
5 * from whence I cribbed the code to find the old socket().
6 *
7 * gcc sctp_socket.c -o sctp_socket.so -ldl -shared -O2 -s
8 * export LD_PRELOAD=./sctp_socket.so
9 *
10 * Copyright 2003 La Monte HP Yarroll <piggy@acm.org>
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 *
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials provided with
21 * the distribution.
22 * 3. The name of the author may not be used to endorse or promote
23 * products derived from this software without specific prior written
24 * permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
27 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
30 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
32 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
34 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
35 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
36 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 */
38#include <string.h> /* for strncmp() */
39#include <stdio.h>
40#include "sctp_socket.h"
41
42/* IPPROTO_SCTP SHOULD be defined in
43 * /usr/include/linux/in.h but probably isn't.
44 * It is an enum element, not a #define, so we can't easily check.
45 */
46#define SHOULD_IPPROTO_SCTP 132
47
48int
49socket(int domain, int type, int protocol)
50{
51 _sctp_load_libs();
52
53 if (((PF_INET == domain) || (PF_INET6 == domain))
54 && (SOCK_STREAM == type)) {
55 protocol = SHOULD_IPPROTO_SCTP;
56 }
57
58 return (real_socket)(domain, type, protocol);
59}