Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I ran nmap on my server and found a strange port open. I'm trying to figure out if there is a way to map that port to a specific process but have no idea if there is such a tool.

Any suggestions?

share|improve this question

6 Answers 6

up vote 41 down vote accepted

As well as Netstat, mentioned in other posts, the lsof command should be able to do this just fine. Just use this:

lsof -i :<port number>

and all of the processes should come up. I use it on OS X quite frequently.

Debian Administration article for lsof

share|improve this answer
    
interesting. I did not know about this. however, I am looking into this as the result of a hack attempt. machine is a friend's. you can telnet to the offending port BUT lsof AND netstat both do not reveal the port as being open. –  jnman Jun 14 '09 at 5:48
    
the port is 5631 which according to /etc/services is pcanywheredata so very suspicious. –  jnman Jun 14 '09 at 5:51
    
Now, that's nice, i didn't know that! Always used netstat. Thanks –  buster Jun 14 '09 at 12:07
4  
If neither netstat nor lsof show the port as being used, but the machine is responding to it, chances are there's been a root kit installed. I recommend moving any data off the machine somewhere else and then nuking it. –  Kamil Kisiel Jun 14 '09 at 17:23
6  
This is indeed a rootkit. I have seen this behavior before, and it is always a rootkit. Your system is compromised, and any tools you are using cannot be trusted. Boot into a Live CD (which has read-only trusted binaries) and use that to extract your data, settings, etc. Any programs you had, any scripts you had, abandon them. Do not bring them. Treat the system as if it has leprosy, because it /does/. Once you're done, nuke it from orbit. Do this as soon as possible. Oh, and unplug your network connection - deny your attacker access. –  Avery Payne Jun 14 '09 at 20:39

Warning: Your system is compromised.

The tool you need is lsof, which will list files (and sockets and ports). It is most likely installed, and it is most likely the attacker's version, which means it will lie to you.

This is indeed a rootkit. I have seen this behavior before, and it is always a rootkit. Your system is compromised, and any tools you are using that originate from the same machine cannot be trusted. Boot into a Live CD (which has read-only trusted binaries) and use that to extract your data, settings, etc. Any programs you had, any scripts you had, abandon them. Do not bring them. Treat them, and the system, as if they have leprosy, because they do.

Once you're done, nuke it from orbit.

Game over man, game over.

Do this as soon as possible. Oh, and unplug your network connection - deny your attacker access.

share|improve this answer
1  
This says it all really. Figure out what went wrong, flatten the server, restore from last known good backup. Life's too short to play games. –  RobM Jun 14 '09 at 20:49
1  
Just adding: be sure you know of the date of the break-in, as you may be restoring the same rootkit that you just removed. Otherwise, yeah, restore from /before/ that date. –  Avery Payne Jun 14 '09 at 20:54
    
That's a funny graphic. I know the system is compromised (thankfully it's not mine). The question I was more curious about was tracking down how he got in in the first place. I suspect via php/joomla but wanted to understand how/why this port was staying open when none of the root kit detection tools were showing that port. –  jnman Jun 14 '09 at 23:34
1  
lol @ "Oh, and unplug your network connection" –  theman_on_osx Jun 15 '09 at 11:40
    
+1 for that image –  ajduke Jul 30 '13 at 12:21
sudo netstat -lnp  

Lists ports that are listening for incoming connections and the associated process that has the port open.

share|improve this answer

netstat -anp

The "-p" tells it to list the process-ID that has the port open. The -an tells it to list listening ports and don't resolve names. On busy systems that can greatly speed up how fast it returns.

netstat -anp | grep "LIST"

That'll just give you the open ports.

share|improve this answer

If you can't see the port open with operating system tools and you suspect an intrussion it could be that a rootkit has been installed.

The rootkit could have changed systems tools to avoid certain processes and ports or changed kernel modules.

You can check for rootkit with several automated tools. 'apt-cache search rootkit' shows the following in Ubuntu:

chkrootkit - rootkit detector
rkhunter - rootkit, backdoor, sniffer and exploit scanner
unhide - Forensic tool to find hidden processes and ports

If you happen to have a rootkit you can revert the 'changed' to your system but I recommend that you find out how the intrussion was made and harden the system for it not to repeat.


They are not exclusive to Ubuntu, you can use them in CentOS too. Just look for the package or download it from their page.


By the output from that port it seems you're running pcanywhere indeed: "�Ы� <Enter>" is very similar to "Please press <Enter>" which is pcanywhere welcome message. I don't know why the process doesn't show up in the process list. Are you root?

You can try rebooting to see if it's a one time process running, as well.

share|improve this answer
    
any suggestions for centos? –  jnman Jun 14 '09 at 7:14
    
strangely, unhide-tcp does not show any suspicious ports. chkrootkit/rkhunter reported all clear (but mostly because i deleted the suspicious dirs prior to asking this question) –  jnman Jun 14 '09 at 8:37
    
FWIW, the rootkit had installed itself as apache in /var/tmp/... and /var/tmp/.ICE-Unix/* The second one was sneaky since I did not notice it the first time around and I was wondering how the heck a bash process kept spawning itself after being killed. –  jnman Jun 14 '09 at 23:36
    
Turns out the cracker installed a cron job. –  jnman Jun 14 '09 at 23:37

To expound on the answer by @bjtitus you can get some very detailed info, for example:

$ lsof -i :8000
COMMAND  PID  USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
squid3  1289 proxy   15u  IPv6 14810490      0t0  TCP *:8000 (LISTEN)

$ ps -fp 1289
UID        PID  PPID  C STIME TTY          TIME CMD
proxy     1289     1  0 09:48 ?        00:00:00 /usr/sbin/squid3 -N -f /etc/squid-deb-proxy/squid-deb-proxy.conf

I can see right there that squid is the process, but it is actualy my squid-deb-proxy that is taking up the port.

Another good example of a java app:

$ lsof -i :4242
COMMAND  PID USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
java    3075 root   86u  IPv4    12019      0t0  TCP *:4242 (LISTEN)

$ ps -fp 3075
UID        PID  PPID  C STIME TTY          TIME CMD
root      3075     1 15 May24 ?        3-16:07:25 /usr/local/crashplan/jre/bin/java -Dfile.encoding=UTF-8 -Dapp=CrashPlanService -DappBaseName=CrashPl

You can see in lsof (LiSt Open Files) that it is java, which is less than helpful. Running the ps command with the PID we can see right away that it is CrashPlan.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.