chiark / gitweb /
Allow user control over autobinding. Also try ports at random to start
[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
82environment, or, failing that, looking up the
83.I real
a6d9626b 84(not effective) user id in the password database. However, if the
85environment variable
86.B NOIP_CONFIG
87is set, then the file it names is read instead (assuming it exists; if
88it doesn't, no configuration is read).
e4976bb0 89.PP
90The configuration file has a simple line-based format. A line is
91ignored if it consists only of whitespace, or if its first whitespace
92character is
93.RB ` # '.
94Otherwise, the first whitespace-delimited word is a keyword and the
95remainder of the line is a value. The following keywords are
96recognized.
97.TP
98.BR "debug " [\fInumber\fR]
99If
100.I number
101is nonzero, turn debugging on; if it is zero, turn debugging off. The
102default, if no
103.I number
104is given, is to turn debugging on. Debugging is written to standard
105error. Some debugging is produced before the configuration file is
106read; the environment variable
107.B NOIP_DEBUG
108can be used to control this.
109.TP
110.BI "socketdir " directory
111Store the Unix-domain sockets in
112.IR directory
a6d9626b 113rather than the default. The environment variable
114.B NOIP_SOCKETDIR
115can also be used to control which directory is used for sockets.
e4976bb0 116.TP
f6049fdd 117.BI "autoports " min "\-" max
118Select which ports are used for implicit binding. Allocating ports can
119be a bit slow, since checking whether a Unix domain socket is in use is
120difficult. A wide range makes things easier, because
121.B noip
122starts by trying ports at random from the given range. The environment
123variable
124.B NOIP_AUTOPORTS
125can also be used to control which ports are assigned automatically.
126.TP
e4976bb0 127.BI "realbind " acl-entry
128Add an entry to the
129.B realbind
130access control list (ACL). When a program attempts to
131.BR bind (2)
132a socket to an address, the
133.B realbind
134ACL is consulted. If the address is matched, then the program is
135allowed to bind a real Internet socket to that address; otherwise, the
a6d9626b 136socket is bound to a Unix-domain socket. Three environment variables
137are consulted too:
138.BR NOIP_REALBIND_BEFORE ,
139.BR NOIP_REALBIND ,
140and
141.BR NOIP_REALBIND_AFTER .
142The
143.B _BEFORE
144rules are inserted at the front of the list; the
145.B _AFTER
146rules are appended on the end. Currently, the rules in
147.B NOIP_REALBIND
148are also put at the end (before the
149.B _AFTER
150rules), though this may change later.
e4976bb0 151.TP
a6d9626b 152.BI "realconnect " acl-entry
e4976bb0 153Add an entry to the
154.B realconnect
155access control list (ACL). When a program attempts to
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.
e4976bb0 180.PP
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.)
188.PP
189An
190.I acl-entry
a6d9626b 191is a comma-separated list of entries of the form:
e4976bb0 192.IP
193.BR + | \-
194.IR address \c
195.RB [ \- \c
196.IR address | \c
197.BR / \c
198.IR mask ]| \c
199.BR local | any
200.RB [ : \c
201.IR port [ \c
202.BI \- \c
203.IR port ]]
204.PP
205(The spaces in the above are optional.)
206.PP
207The leading sign says whether
208matching addresses should be
209.I accepted
210.RB (` + ')
211or
212.I denied
213.RB (` \- ').
214.PP
215The IP-address portion may be any of the following
216.TP
217.B any
218Matches all addresses.
219.TP
220.B local
221Matches the address of one of the machine's network interfaces.
222.TP
223.I address
224Matches just the given address
225.TP
226.IB address \- address
227Matches any address which falls in the given range. Addresses are
228compared lexicographically, with octets to the left given precedence
229over octets to the right.
230.TP
231.IB address / mask
232Matches an address in the given network. The
233.I mask
234may be a netmask in dotted-quad form, or a one-bit-count.
235.PP
236The port portion may be omitted (which means `match any port'), or may
237be a single
238.I port
239or a range
240.IB port \- port
241to match.
242.PP
243Range comparisons are always inclusive of both endpoints.
244.PP
245ACL entries are processed in the order they appear in the configuration
246file. The default action of an ACL, used if none of its entries match,
247is the opposite of the last actual entry in the list: if the last entry
248says `accept', then the default is to deny, and vice-versa. If the ACL
249is empty, the default is to deny all addresses.
250.PP
251For example, it may be useful to allow access at least to a DNS server.
252This can be accomplished by adding a line
253.VS
254realconnect +1.2.3.4:52
255.VE
256to the configuration file, where 1.2.3.4 is the IP address of one of
257your DNS server.
258.SS Example applications
259SLIME is an Emacs extension for doing interactive programming with Lisp
260systems. It communicates with the Lisp system using TCP sockets, since
261Unix-domain sockets are unavailable on Windows, and besides, they are
262less well supported by Lisp implementations. Unfortunately, when the
263author wrote this program, SLIME applied no authentication on its TCP
264port, allowing any local user to take over the running Lisp. Worse,
265some Lisps are unable to bind a listening socket to a particular
266address, leaving the socket potentially available to anyone on the
267network. By running Emacs under
268.BR noip ,
269the security hole is closed completely and no messing with
270authentication secrets is needed.
271.PP
272SSH is an excellent tool for secure communications over hostile
273networks. In particular, its ability to forward TCP connections to a
274port on one side of an SSH tunnel to the other side is very useful.
275However, such a forwarded port is available to all users on the source
276side of the tunnel. Using
277.B noip
278and a suitable configuration, a user can restrict access to a forwarded
279port to himself or a small group.
280.SH BUGS
281.B noip
282is implemented as an
283.B LD_PRELOAD
284hack. It won't work on setuid programs. Also, perhaps more
285importantly, it can't do anything a
286.I malicious
287program use of networking: a program could theoretically issue sockets
288system calls directly instead of using the C library calls that
289.B noip
290intercepts. It is intended only as a tool for enhancing the security of
291software written by well-meaning programmers who don't understand the
292security aspects of writing networking code.
293.PP
294It's very hard to tell exactly what state a Unix-domain socket is in.
295If the filesystem object isn't there, it's not active, but if it
296.I is
297then the socket might be in use or it might be stale.
298.B noip
299consults
300.B /proc/net/unix
301to decide whether a socket is in use, but this can fail in two ways.
302Firstly, if the socket is created and renamed, the kernel doesn't
303notice, and
304.B noip
305will think that the new name is stale. Secondly, if the socket is
306created, used, unlinked while it's still in use, and recreated, then
307.B noip
308will think that it's in use when in fact it's gone stale. Don't mess
309with
310.BR noip 's
311sockets unless you know what you're doing.
312.PP
313The procedure to replace a Unix-domain socket by an Internet one is
314fairly thorough, but there are some missing cases. In particular, if
315the socket being bound or connected is a duplicate (using
316.BR dup (2))
317then only one of the copies will be fixed. Similarly, copies owned by
318child processes will be unaffected.
319.PP
320This manual is surprisingly long and complicated for such a simple hack.
321.SH AUTHOR
322Mark Wooding, <mdw@nsict.org>