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 to 192.168.1.10:22 (remote)
  • line 2 β€” for user whose UID is 1003
  • line 3 β€” to *:22 or *:21 (both locally)
  • line 4 β€” for user "joedoe" to *:23 (local) or to 192.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:

  • user uid β€” 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.
  • lport port β€” 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 form low- is used, high is assumed to be 65535. if the form -high is used, low is assumed to be 0. it is an error to omit both low and high πŸ™ˆ.
  • lport "service" β€” same as above, but using a service name from /etc/services instead of a port number.
  • rport β€” same as lport but 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/m
  • laddr 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 to 128. depending on the address family, these rules contain an implicit match condition "ip" or "ip6", respectively.
  • raddr β€” same as laddr but compares the remote address.
  • exe "pattern" β€” true if the full filename (including directory) of the executable that created/accepted the connection matches pattern, a glob(7)-style wildcard pattern.
    • the pattern "" (an empty string) matches connections created/accepted by processes whose executable filename is unknown.
    • if the -p option is not specified, a warning message will be printed, and the result of this comparison will always be true. (yes bestie, always. πŸ’€)

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 port 25 on 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