A Tool to Drop TCP Sessions for the Solaris OS: tcpdropCeri Davies, February 2007
AbstractThere are occasions during an administrator's work when it is necessary to forcibly disconnect an established TCP session. However, no easy way exists for an administrator to drop an established TCP session without doing something heavy-handed, such as null routing all traffic from the client, adding anipfilter rule (which, again, likely blocks more traffic than is strictly necessary), or taking the last resort of killing the associated server-side process.
I ported IntroductionImagine that, for whatever reason, you wish to kick a remote client off your Solaris OS host. Perhaps you believe that the connection is causing a resource issue, or you might be debugging an application's reaction to sudden disconnects. If a user is logged in over Secure Shell (SSH), then it's relatively simple to identify
and kill the user's shell and the associated Identifying the VictimAn established TCP socket can be uniquely identified by the following quadruple:
{local IP address, local port, remote IP address, remote port}
You can, therefore, use a tool such as # netstat -n -Ptcp | egrep 172.20.3.75.\*192.168.4.25 172.20.3.75.80 192.168.4.25.33062 49640 0 49640 0 ESTABLISHED The output shows an established TCP connection to port 80 on IP address
Null RoutesOne popular method of dropping IP traffic is to null route, or black
hole, the remote machine. With the remote machine from the previous example,
# route add -host 192.168.4.25 127.0.0.1 -blackhole Now, replies generated by the host cannot reach the client, and the TCP session eventually times out. Note, however, that some packets from the client might still be processed by the application. One downside to this approach is that it has black holed all traffic from the remote IP address. The black hole has very likely caused some collateral damage if the remote machine is one of these:
FirewallingThe IP Filter packet filter distributed with the Solaris 10 OS allows a finer grain of selectivity when discarding traffic. You can build a rule that drops a particular connection using the following template. (This should all be on one line.) block return-rst in quick proto tcp from /remote_addr/ port = \ /remote_port/ to /local_addr/ port = /local_port/ Assuming you have the same previously established connection, plugging in the values yields the following: block return-rst in quick proto tcp from 192.168.4.25 port = 33062 to 172.20.3.75 port = 80 This method has the advantage of blocking only the connection that you wish to
block. However, this rule must now be prepended to the head of
svcadm restart ipfilter If there is enough traffic between the hosts, then the quadruple
eventually gets recycled. So when the connection times out, you
need to remove the line from The tcpdrop UtilityWhile working on a security fix for a TCP packet ordering problem,
Markus Friedl of the OpenBSD project found that he was having to go to
some lengths in order to drop TCP connections. Although there are, of
course, methods other than the ones covered previously, Markus decided that
his life would be easier if he wrote a tool that would take a quadruple
and have the OpenBSD kernel drop the connection. That tool, An example of using # tcpdrop 172.20.3.75 80 192.168.4.25 33062 172.20.3.75 80 192.168.4.25 33062: dropped The connection is instantly dropped, and there is no ill effect on new connections or on already established connections from the same host. Solaris administrators have had to make do without this tool. In a
recent discussion on the Usenet group Note: Since the kernel interface is undocumented, this tool is liable to stop working or to break in future versions of the Solaris OS. About the AuthorCeri Davies (ceri [at] submonkey.net) is a UNIX systems administrator for a Welsh university and a FreeBSD developer. Unless otherwise licensed, code in all technical manuals herein (including articles, FAQs, samples) is provided under this License. |
| |||