Friday 15 November 2019

linux - Find file running on python port hosting


I have a localhost:5000 port that is hosted by python3 server in ubuntu. How to i know which file it serves without knowing anything extra?


I am using lsof -i :5000 and i only know that it is hosted by python 3. I am trying to locate the file/folder hosted by that that without any extra knowledge given. The thing i know that yes, there is some file being hosted at port 5000 using python3. But i dunno what is the name of the file hosted and which directory it is located.


Also tried fuser 5000/tcp -v but id dones not show the file hosted.


Is that possible and what command do i need to get all file/folder hosted by it?



Answer



lsof should have told you the PID of the process. Let's call it $pid. Investigate what is inside /proc/$pid/. Some of the following commands may require root access (i.e. you may want to sudo su - beforehand).


cd /proc/$pid
readlink exe # the executable
readlink cwd # current working directory
xxd cmdline # command line (xxd useful because items are null-separated)

cd /proc/$pid/fd
ls -l # file descriptors in use

Additionally interact with the server (e.g. download the file) while using strace to see what it does. See this answer: how to investigate what a process is doing?


Or you can download the file and try to find a duplicate by comparing the content. Preliminary comparison by size may speed things up greatly.


file="/path/to/the/downloaded/file"
size=`<"$file" wc -c`

# now you will probably want to use sudo
find / -type f ! -path "/proc/*" ! -path "/sys/*" ! -path "/dev/*" -size ${size}c -exec cmp -s "$file" {} \; -print

unset -v file size # just to clean

Note I excluded /proc/, /sys/ and /dev/. You may also get familiar with -xdev (see man 1 find) and use it maybe.


No comments:

Post a Comment

How can I VLOOKUP in multiple Excel documents?

I am trying to VLOOKUP reference data with around 400 seperate Excel files. Is it possible to do this in a quick way rather than doing it m...