I am crashing my head against the wall with this one...
I run nmap from my desktop for a specific server I have, to check some opened ports which could be security issues. It returns ports which shouldn't be opened :
nmap -T5 WWW.XXX.YYY.ZZZ
Starting Nmap 7.12 ( https://nmap.org ) at 2016-08-09 21:21 CEST
Nmap scan report for mydomain.com (WWW.XXX.YYY.ZZZ)
Host is up (0.0034s latency).
Not shown: 992 filtered ports
PORT STATE SERVICE
80/tcp open http
110/tcp open pop3
143/tcp open imap
443/tcp open https
993/tcp open imaps
995/tcp open pop3s
Nmap done: 1 IP address (1 host up) scanned in 3.33 seconds
http and https have to be opened. But not the other ones... I run this test from 5 different IP addresses.
Ok maybe it's false positives due to how nmap select open/filtered/closed ports. So I tried to telnet those ports and... I do have a connexion :
[meandmyself@MacBook ~]$ telnet WWW.XXX.YYY.ZZZ 110
Trying WWW.XXX.YYY.ZZZ...
Connected to mydomain.com.
Escape character is '^]'.
On the target host, I double checked my netstat and iptables to see if I missed something :
[21:55] ovh-user@mydomain:~ $ sudo netstat -tanlp | grep LISTEN
[sudo] password for ovh-user:
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1016/master
tcp 0 0 WWW.XXX.YYY.ZZZ:4444 0.0.0.0:* LISTEN 353/sshd
tcp 0 0 0.0.0.0:5665 0.0.0.0:* LISTEN 2485/icinga2
tcp 0 0 127.0.0.1:8999 0.0.0.0:* LISTEN 826/php-fpm.conf)
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 25433/mysqld
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 346/rpcbind
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 828/nginx -g daemon
tcp6 0 0 :::9000 :::* LISTEN 25477/java
tcp6 0 0 :::111 :::* LISTEN 346/rpcbind
Except for rpcbind, i know all these services, only nginx is reachable from outside. Ther is nothing on ports 110, 143, 993 and 995...
Then I double checked my iptables :
[21:33] ovh-user@mydomain:~ $ sudo iptables -v -L INPUT
Chain INPUT (policy DROP 8 packets, 352 bytes)
pkts bytes target prot opt in out source destination
2602 749K ACCEPT all -- any any anywhere anywhere state RELATED,ESTABLISHED
76 5472 ACCEPT all -- lo any anywhere anywhere
272 8912 ACCEPT icmp -- any any anywhere anywhere
1 64 ACCEPT tcp -- any any anywhere anywhere tcp dpt:4444
27 1604 ACCEPT tcp -- any any anywhere anywhere tcp dpt:http
1 44 ACCEPT tcp -- any any anywhere anywhere tcp dpt:https
0 0 ACCEPT tcp -- any any anywhere anywhere tcp spt:ftp state ESTABLISHED
0 0 ACCEPT tcp -- any any anywhere anywhere tcp spt:ftp-data state RELATED,ESTABLISHED
0 0 ACCEPT tcp -- any any anywhere anywhere tcp spts:1024:65535 dpts:1024:65535 state ESTABLISHED
[21:34] ovh-user@mydomain:~ $ sudo iptables -v -L FORWARD
Chain FORWARD (policy DROP 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
[21:55] ovh-user@mydomain:~ $ sudo iptables -t nat -nvL PREROUTING
Chain PREROUTING (policy ACCEPT 1342 packets, 49898 bytes)
pkts bytes target prot opt in out source destination
There is nothing opened on pop or imap ports...
From my basic understanding of unix services and firewalling I don't get it. Why does telnet gives me "Connected to mydomain.com" for a port with no process listening on it ? Is there a way to trace how telnet reaches something ?
netstat -tanlp | grep LISTEN
instead of grepping for individual ports?