{"id":258,"date":"2007-06-29T03:12:00","date_gmt":"2007-06-29T03:12:00","guid":{"rendered":"https:\/\/defragged.org\/ossec\/?p=258"},"modified":"2020-07-03T03:13:17","modified_gmt":"2020-07-03T03:13:17","slug":"hidden-ports-on-linux","status":"publish","type":"post","link":"https:\/\/defragged.org\/ossec\/2007\/06\/hidden-ports-on-linux\/","title":{"rendered":"Hidden ports on Linux"},"content":{"rendered":"\n<p>If you ever had trouble with hidden ports on Linux (2.4 and 2.6), I may have figured out one of the possible causes today (and no, it is not a rootkit). To keep the story short: if you&nbsp;<em>bind<\/em>&nbsp;any TCP port, but do not&nbsp;<em>listen<\/em>&nbsp;on it, netstat will not show it at all (the same does not happen with UDP ports).<\/p>\n\n\n\n<p>Here is the idea. If you get this&nbsp;<a href=\"http:\/\/www.ossec.net\/files\/other\/bind_ports.c\">simple C program<\/a>, it will attempt to bind every TCP port from 1025 to 1050, but it will not listen on them. After it is done, if you do a netstat (or fuser or lsof) nothing will be shown. However, if you try to use the port, you will get an error saying that it is already in use.<\/p>\n\n\n\n<p>To reproduce, download the&nbsp;<a href=\"http:\/\/www.ossec.net\/files\/other\/bind_ports.c\">bind_ports.c<\/a>&nbsp;program, compile and execute it:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>dcid@copacabana:~$&nbsp;<strong>wget http:\/\/www.ossec.net\/files\/other\/bind_ports.c<\/strong><br>..<br>14:56:32 (309.92 KB\/s) \u2013 `bind_ports.c\u2019 saved [1371\/1371]<\/p><p>dcid@copacabana:~$&nbsp;<strong>gcc -o bind_ports bind_ports.c<\/strong><br>dcid@copacabana:~$&nbsp;<strong>.\/bind_ports &amp;<\/strong><br>[1] 11332<\/p><p>Ports from 1025 to 1050 were bind..<\/p><\/blockquote>\n\n\n\n<p>After that, run netstat (or lsof or fuser) to see if the port is listed (it will not be):<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>dcid@copacabana:~$&nbsp;<strong>netstat -tan<\/strong><br>Active Internet connections (servers and established)<br>Proto Recv-Q Send-Q Local Address Foreign Address State<br>tcp 0 0 127.0.0.1:80 0.0.0.0:* LISTEN<br>tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN<br>\u2026<\/p><\/blockquote>\n\n\n\n<p>However, if you try to use the port, you will receive the \u201calready in use\u201d error (if using nc, it takes up to 10 seconds to fail).<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>dcid@copacabana:~$&nbsp;<strong>nc -l -p 1025<\/strong><br>Can\u2019t grab 0.0.0.0:1025 with bind<br>dcid@copacabana:~$&nbsp;<strong>nc -l -p 1026<\/strong><br>Can\u2019t grab 0.0.0.0:1026 with bind<br>dcid@copacabana:~$&nbsp;<strong>nc -p 1026 127.0.0.1 80<\/strong><br>Can\u2019t grab 0.0.0.0:1026 with bind<\/p><\/blockquote>\n\n\n\n<p>Anyone has ideas why this happens? If I try the same thing on OpenBSD, netstat lists all the ports correctly.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you ever had trouble with hidden ports on Linux (2.4 and 2.6), I may have figured out one of the possible causes today (and no, it is not a rootkit). To keep the story short: if you&nbsp;bind&nbsp;any TCP port, but do not&nbsp;listen&nbsp;on it, netstat will not show it at all (the same does not [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/defragged.org\/ossec\/wp-json\/wp\/v2\/posts\/258"}],"collection":[{"href":"https:\/\/defragged.org\/ossec\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/defragged.org\/ossec\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/defragged.org\/ossec\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/defragged.org\/ossec\/wp-json\/wp\/v2\/comments?post=258"}],"version-history":[{"count":1,"href":"https:\/\/defragged.org\/ossec\/wp-json\/wp\/v2\/posts\/258\/revisions"}],"predecessor-version":[{"id":259,"href":"https:\/\/defragged.org\/ossec\/wp-json\/wp\/v2\/posts\/258\/revisions\/259"}],"wp:attachment":[{"href":"https:\/\/defragged.org\/ossec\/wp-json\/wp\/v2\/media?parent=258"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/defragged.org\/ossec\/wp-json\/wp\/v2\/categories?post=258"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/defragged.org\/ossec\/wp-json\/wp\/v2\/tags?post=258"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}