chiark / gitweb /
noip.c (do_implicit_bind): Handle `SAME' impbind entries properly.
[preload-hacks] / noip.1
CommitLineData
e4976bb0 1.de VS
2.sp 1
3.RS
4.nf
5.ft B
6..
7.de VE
8.ft R
9.fi
10.RE
11.sp 1
12..
13.TH noip 1 "5 May 2005" "Straylight/Edgeware" "Preload hacks"
14.SH NAME
15noip \- run programs without the ability to use IP sockets
16.SH SYNOPSIS
17.B noip
18.RI [ command
19.RI [ args ...]]
20.SH DESCRIPTION
21The
22.B noip
23program runs
24.I command
25(by default, the user's shell, as determined by the
26.B SHELL
27environment variable) in an environment where attempts to use TCP/IP
28networking are (mostly) transparently translated into the use of
29Unix-domain sockets in a private directory.
30.PP
31There are many programs which use TCP/IP for their own internal
32communications needs, largely unnecessarily. This can present security
33problems: even if a program binds its listening sockets to
34.BR localhost ,
35other users on the same system can still connect, and many such programs
36don't seem to have authentication systems.
37.PP
38.B noip
39addresses this problem by intercepting a program's networking calls and
40making it use Unix-domain sockets in a private directory instead of
41TCP/IP. Now its communications are truly private to the running user.
42.SS The socket directory
43The
44.B noip
45program keeps its sockets in a directory whose name can be configured,
46but by default is
47.BI noip- \c
48.IR username ,
49where
50.I username
51is determined by the
52.B USER
53or
54.B LOGNAME
55environment variables, or is
56.BI uid- \c
57.IR realuid
58in the temporary directory, which in turn is determined by the
59.B TMPDIR
60or
61.B TMP
62environment variables, or is
63.BR /tmp .
64The sockets in this directory are simply named
65.IB dottedquad : port
66after the Internet sockets they represent.
67.PP
68If the socket directory does not exist when a program running under
69.B noip
70starts up, it is created and made readable and writable only by the
71current user. Also, it is scanned and any apparently stale sockets are
72removed.
73.SS Configuration
74The operation of
75.B noip
76is controlled by a configuration file. By default,
77.B noip
78reads configuration from
79.B .noip
80in the calling user's home directory, as determined by the
81.B HOME
5b49f527 82environment, or, failing that, looking up the effective user id in the
83password database. However, if the environment variable
a6d9626b 84.B NOIP_CONFIG
85is set, then the file it names is read instead (assuming it exists; if
86it doesn't, no configuration is read).
e4976bb0 87.PP
88The configuration file has a simple line-based format. A line is
673935dd
MW
89ignored if it consists only of whitespace, or if its first
90non-whitespace character is
e4976bb0 91.RB ` # '.
92Otherwise, the first whitespace-delimited word is a keyword and the
93remainder of the line is a value. The following keywords are
94recognized.
95.TP
96.BR "debug " [\fInumber\fR]
97If
98.I number
99is nonzero, turn debugging on; if it is zero, turn debugging off. The
100default, if no
101.I number
102is given, is to turn debugging on. Debugging is written to standard
103error. Some debugging is produced before the configuration file is
104read; the environment variable
105.B NOIP_DEBUG
106can be used to control this.
107.TP
108.BI "socketdir " directory
109Store the Unix-domain sockets in
110.IR directory
a6d9626b 111rather than the default. The environment variable
112.B NOIP_SOCKETDIR
113can also be used to control which directory is used for sockets.
e4976bb0 114.TP
f6049fdd 115.BI "autoports " min "\-" max
116Select which ports are used for implicit binding. Allocating ports can
117be a bit slow, since checking whether a Unix domain socket is in use is
118difficult. A wide range makes things easier, because
119.B noip
120starts by trying ports at random from the given range. The environment
121variable
122.B NOIP_AUTOPORTS
123can also be used to control which ports are assigned automatically.
124.TP
e4976bb0 125.BI "realbind " acl-entry
7071520e 126Add a comma-separated list of entries to the
e4976bb0 127.B realbind
7071520e
MW
128access control list (ACL). (See below for the format of an ACL entry.)
129When a program attempts to
e4976bb0 130.BR bind (2)
131a socket to an address, the
132.B realbind
133ACL is consulted. If the address is matched, then the program is
134allowed to bind a real Internet socket to that address; otherwise, the
a6d9626b 135socket is bound to a Unix-domain socket. Three environment variables
136are consulted too:
137.BR NOIP_REALBIND_BEFORE ,
138.BR NOIP_REALBIND ,
139and
140.BR NOIP_REALBIND_AFTER .
141The
142.B _BEFORE
143rules are inserted at the front of the list; the
144.B _AFTER
145rules are appended on the end. Currently, the rules in
146.B NOIP_REALBIND
147are also put at the end (before the
148.B _AFTER
149rules), though this may change later.
e4976bb0 150.TP
a6d9626b 151.BI "realconnect " acl-entry
7071520e 152Add a comma-separated list of entries to the
e4976bb0 153.B realconnect
7071520e
MW
154access control list (ACL). (See below for the format of an ACL entry.)
155When a program attempts to
e4976bb0 156.BR connect (2)
157a socket to an address, or to contact another socket using
158.BR sendto (2)
159or
160.BR sendmsg (2),
161the
162.B realconnect
163ACL is consulted. If the destination address is matched, then the
164program is allowed to contact the real Internet socket; otherwise, the
a6d9626b 165attempt is made to contact a Unix-domain socket. Three environment variables
166are consulted too:
167.BR NOIP_REALCONNET_BEFORE ,
168.BR NOIP_REALCONNECT ,
169and
170.BR NOIP_REALCONNECT_AFTER .
171The
172.B _BEFORE
173rules are inserted at the front of the list; the
174.B _AFTER
175rules are appended on the end. Currently, the rules in
176.B NOIP_REALCONNECT
177are also put at the end (before the
178.B _AFTER
179rules), though this may change later.
2f2b91d9
MW
180.IP
181(Aside: An attempt to connect to a remote host may not be a hopeless failure,
182even if a real IP socket is denied:
183.B noip
184deliberately makes no attempt to check that addresses being bound to
185sockets correspond to locally available addresses; and besides, sockets
186can be introduced into the directory by other programs simulating remote
187servers.)
7be80f86
MW
188.TP
189.BI "impbind " bind-rule
7071520e
MW
190Add a comma-separated list of entries to the implicit-bind rule list.
191When a program attempts to transmit from a socket \(en e.g., with
192.BR connect (2),
193.BR sendto (2), or
194.BR sendmsg (2)
195\(en without binding its local address first,
7be80f86
MW
196.B noip
197consults this list to decide on the correct local address to assign.
198Each entry in the list has the form
199.RS
200.IP
201.I address-range
202.IR address | \c
203.B same
204.PP
205The rules are tried in order: if the remote address matches (in the same
206way as in an ACL entry) the address range on the left side of the rule,
207then the socket is bound to the address from the right side; if the
208address on the right is
209.B same
210then the remote address is used.
211.PP
212Three environment variables
213are consulted too:
214.BR NOIP_IMPBIND_BEFORE ,
215.BR NOIP_IMPBIND ,
216and
217.BR NOIP_IMPBIND_AFTER .
218The
219.B _BEFORE
220rules are inserted at the front of the list; the
221.B _AFTER
222rules are appended on the end. Currently, the rules in
223.B NOIP_IMPBIND
224are also put at the end (before the
225.B _AFTER
226rules), though this may change later.
227.RE
e4976bb0 228.PP
e4976bb0 229An
230.I acl-entry
a6d9626b 231is a comma-separated list of entries of the form:
e4976bb0 232.IP
233.BR + | \-
0a6ab6a1 234.I address-range
e4976bb0 235.RB [ : \c
0a6ab6a1 236.IR port-range ]
e4976bb0 237.PP
238(The spaces in the above are optional.)
239.PP
99222954 240The leading sign says whether matching addresses should be
e4976bb0 241.I accepted
242.RB (` + ')
243or
244.I denied
245.RB (` \- ').
246.PP
0a6ab6a1
MW
247The
248.I address-range
249portion may be any of the following.
e4976bb0 250.TP
251.B any
252Matches all addresses.
253.TP
254.B local
255Matches the address of one of the machine's network interfaces.
256.TP
257.I address
2a06ea0b 258Matches just the given IPv4 or IPv6 address. An
9314b85a 259.I address
2a06ea0b
MW
260may be enclosed in square brackets; IPv6 addresses must be so enclosed,
261because colons are significant in the rest of the ACL syntax.
e4976bb0 262.TP
263.IB address \- address
264Matches any address which falls in the given range. Addresses are
265compared lexicographically, with octets to the left given precedence
266over octets to the right.
267.TP
9314b85a
MW
268.IB address / prefix-length
269Matches an address in the given network.
e4976bb0 270.PP
0a6ab6a1
MW
271The
272.I port-range
273may be omitted (which means `match any port'), or may be a single
e4976bb0 274.I port
275or a range
276.IB port \- port
277to match.
278.PP
279Range comparisons are always inclusive of both endpoints.
280.PP
281ACL entries are processed in the order they appear in the configuration
282file. The default action of an ACL, used if none of its entries match,
283is the opposite of the last actual entry in the list: if the last entry
284says `accept', then the default is to deny, and vice-versa. If the ACL
285is empty, the default is to deny all addresses.
286.PP
287For example, it may be useful to allow access at least to a DNS server.
288This can be accomplished by adding a line
289.VS
a8be0591 290realconnect +1.2.3.4:53
e4976bb0 291.VE
292to the configuration file, where 1.2.3.4 is the IP address of one of
293your DNS server.
294.SS Example applications
295SLIME is an Emacs extension for doing interactive programming with Lisp
296systems. It communicates with the Lisp system using TCP sockets, since
297Unix-domain sockets are unavailable on Windows, and besides, they are
298less well supported by Lisp implementations. Unfortunately, when the
299author wrote this program, SLIME applied no authentication on its TCP
300port, allowing any local user to take over the running Lisp. Worse,
301some Lisps are unable to bind a listening socket to a particular
302address, leaving the socket potentially available to anyone on the
303network. By running Emacs under
304.BR noip ,
305the security hole is closed completely and no messing with
306authentication secrets is needed.
307.PP
308SSH is an excellent tool for secure communications over hostile
309networks. In particular, its ability to forward TCP connections to a
310port on one side of an SSH tunnel to the other side is very useful.
311However, such a forwarded port is available to all users on the source
312side of the tunnel. Using
313.B noip
314and a suitable configuration, a user can restrict access to a forwarded
315port to himself or a small group.
316.SH BUGS
317.B noip
318is implemented as an
319.B LD_PRELOAD
320hack. It won't work on setuid programs. Also, perhaps more
a8be0591 321importantly, it can't do anything to prevent a
e4976bb0 322.I malicious
a8be0591 323program's use of networking: a program could theoretically issue sockets
e4976bb0 324system calls directly instead of using the C library calls that
325.B noip
326intercepts. It is intended only as a tool for enhancing the security of
327software written by well-meaning programmers who don't understand the
328security aspects of writing networking code.
329.PP
330It's very hard to tell exactly what state a Unix-domain socket is in.
331If the filesystem object isn't there, it's not active, but if it
332.I is
333then the socket might be in use or it might be stale.
334.B noip
335consults
336.B /proc/net/unix
337to decide whether a socket is in use, but this can fail in two ways.
338Firstly, if the socket is created and renamed, the kernel doesn't
339notice, and
340.B noip
341will think that the new name is stale. Secondly, if the socket is
342created, used, unlinked while it's still in use, and recreated, then
343.B noip
344will think that it's in use when in fact it's gone stale. Don't mess
345with
346.BR noip 's
347sockets unless you know what you're doing.
348.PP
349The procedure to replace a Unix-domain socket by an Internet one is
350fairly thorough, but there are some missing cases. In particular, if
351the socket being bound or connected is a duplicate (using
352.BR dup (2))
353then only one of the copies will be fixed. Similarly, copies owned by
354child processes will be unaffected.
355.PP
356This manual is surprisingly long and complicated for such a simple hack.
357.SH AUTHOR
a8be0591 358Mark Wooding, <mdw@distorted.org.uk>