TCPSPY.RULES(5)
π TCPSPY.RULES(5) π
okay bestie, sit down, hydrate, because today we're talking about tcpspy.rules β the config file that tells tcpspy which connections to log. no cap, it's giving "tiny file, huge power". π
β¨ NAME β¨
tcpspy.rules β the configuration file for tcpspy πΈ
π¦ DESCRIPTION π¦
so this file β by default it lives at /etc/tcpspy.rules β gets read by the /etc/init.d/tcpspy script at init time, and its whole job is to configure the tcpspy logger filtering rules (peep tcpspy(8) for the main character himself π
).
it might look like this:
# /etc/tcpspt.rules example
user "joedoe" and rport 22 and raddr 192.168.1.10
user 1003
lport 22 or lport 21
(lport 23 and user "joedoe") or raddr 192.168.1.20
this rules file is saying that tcpspy logs tcp connections according to 4 rules (line 1 to line 4 β one per each line), using the boolean logic (more on that below π) to evaluate each rule.
this particular example logs connections:
- line 1 β for user
"joedoe"connecting to192.168.1.10:22(remote) - line 2 β for user whose UID is
1003 - line 3 β to
*:22or*:21(both locally) - line 4 β for user
"joedoe"to*:23(local) or to192.168.1.20(remote)
and here's the lil quality-of-life thing: everything from an # signal to the end of the line will not be evaluated. so comment away, queen π
π Rule Syntax β just extracted from tcpspy(8) π
a rule may be specified with the following comparison operators:
useruid β true if the local user initiating or accepting the connection has the effective user id uid.user "username"β same as above, but using a username instead of a user id. πipβ true if the connection is IPv4.ip6β true if the connection is IPv6.lportport β true if the local end of the connection has port number port.lport [low] - [high]β true if the local end of the connection has a port number greater than or equal to low and less than or equal to high. if the formlow-is used, high is assumed to be65535. if the form-highis used, low is assumed to be0. it is an error to omit both low and high π.lport "service"β same as above, but using a service name from/etc/servicesinstead of a port number.rportβ same aslportbut compares the port number of the remote end of the connection.laddr n.n.n.n[/m.m.m.m]laddr n.n.n.n/mladdr ip6-addr[/m]β interpreted as a"net/mask"expression; true if"net"is equal to the bitwise AND of the local address of the connection and"mask". if no mask is specified, a default mask with all bits set (255.255.255.255) is used. the CIDR type netmask is also possible. with IPv6 only a prefix length netmask is allowed, and the length defaults to128. depending on the address family, these rules contain an implicit match condition"ip"or"ip6", respectively.raddrβ same asladdrbut compares the remote address.exe "pattern"β true if the full filename (including directory) of the executable that created/accepted the connection matches pattern, aglob(7)-style wildcard pattern.- the pattern
""(an empty string) matches connections created/accepted by processes whose executable filename is unknown. - if the
-poption is not specified, a warning message will be printed, and the result of this comparison will always be true. (yes bestie, always. π)
- the pattern
expressions (including the comparisons listed above) may be joined together with the following logical operations:
expr1 or expr2β true if either of expr1 or expr2 are true (logical OR).expr1 and expr2β true if both expr1 and expr2 are true (logical AND).not exprβ true if expr is false (logical NOT).
rules are evaluated from left to right. whitespace (space, tab and newline) characters are ignored between "words". rules consisting of only whitespace match no connections, but do not cause an error. parentheses, '(' and ')', may be placed around expressions to affect the order of evaluation. π«Ά
π Examples π
these are some sample rules which further demonstrate how they are constructed:
user "joe" and rport "ssh"β log connections made by user"joe"for the service"ssh".not raddr 10.0.0.0/255.0.0.0 and rport 25 and (user "bob" or user "joe")β log connections made by users"bob"and"joe"to remote port25on machines not on a fictional "intranet".
π AUTHOR π
Tim J. Robbins (tcpspy), Pablo Lorenzzoni (this manpage) and Mats Erik Andersson (changes for IPv6) π
π₯ SEE ALSO π₯
glob(7), proc(5), services(5), signal(7), syslog(3), tcpspy(8)
and that's the whole page, bestie β no crumbs left, you ate it all. this iconic lil manual came from Spectra, dated April 2001 (yes, she's an elder but she still serves π ). now go write some rules and stay logged, periodt. β¨π¦π
π¦ where this page comes from
- debian bookworm: tcpspy 1.7d-15 Β· BSD-3-Clause
- debian trixie: tcpspy 1.7d-16 Β· BSD-3-Clause
- ubuntu jammy: tcpspy 1.7d-15 Β· BSD-3-Clause
- ubuntu noble: tcpspy 1.7d-15 Β· BSD-3-Clause
- ubuntu questing: tcpspy 1.7d-16
- ubuntu resolute: tcpspy 1.7d-17 Β· BSD-3-Clause
- ubuntu stonking: tcpspy 1.7d-17 Β· BSD-3-Clause
- Copyright (c) 2001 Pablo Lorenzzoni
- Copyright (c) 2011 Mats Erik Andersson
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms