如何找出网站的代码所在?

事实:

  • 有一个网站
  • 本网站可通过www.example.org访问
  • 有一个很可能保持网站的EC2实例
  • 服务器是Apache
  • 服务器操作系统是Ubuntu
  • 我有完整的访问权限(和sudo权限)
  • 服务器是一个巨大的混乱

问题是我不知道在哪里 – 简单地说 – find加载的index.html / index.php。

我如何找出在哪里可以find网站的PHP和HTML代码? 有没有一个系统的方法来解决这个问题?

首先,您应该检查服务器上托pipe的网站

 # apachectl -t -D DUMP_VHOSTS 

然后,当您将find一个站点时,请检查DocumentRoot选项的相应configuration文件。 例如

 # apachectl -t -D DUMP_VHOSTS VirtualHost configuration: wildcard NameVirtualHosts and _default_ servers: *:80 is a NameVirtualHost default server 192.168.88.87 (/etc/httpd/conf.d/192.168.88.87.conf:1) port 80 namevhost 192.168.88.87 (/etc/httpd/conf.d/192.168.88.87.conf:1) port 80 namevhost gl-hooks.example.net (/etc/httpd/conf.d/hooks.conf:1) alias example.net alias www.example.net 

你想知道哪里是一个网站example.net

 # grep DocumentRoot /etc/httpd/conf.d/hooks.conf DocumentRoot /vhosts/gl-hooks.example.net/ # cd /vhosts/gl-hooks.example.net/ # ls -la total 4484 drwxr-xr-x 6 apache apache 4096 Feb 10 11:59 . drwxr-xr-x 14 root root 4096 Feb 23 08:54 .. -rw-r--r-- 1 root root 1078 Dec 19 09:31 favicon.ico -rw-r--r-- 1 apache apache 195 Dec 25 14:51 .htaccess -rw-r--r-- 1 apache apache 98 Dec 7 10:52 index.html 

还应该寻找别名和redirect/重写

你也应该注意任何别名指令。 例如使用以下设置

 <VirtualHost *:80> ServerName example.net ServerAlias www.example.net ... DocumentRoot /vhosts/default/public_html/ Alias /api/ /vhosts/default/public_api/ ... </VirtualHost> 

当您访问http://example.net/some.file.html&#x65F6; ,apache将会在/ vhosts / default / public_html /中查找文件,同时使用http://example.net/api/some.file .html文件将被看作/ vhosts / default / public_api /。

如何重写/redirect,特别是编程(当redirect是由一些PHP代码触发的),我认为没有简单的方法来find这种情况。

尝试使用查找

 find / -type f \( -iname "*index.html*" -o -iname "*index.php*" \) 2> /dev/null 

否则,假设已经从Ubuntu存储库安装了Apache,请查看/etc/apache2/sites-available ,即

 grep -niR "thedomainname" /etc/apache2/sites-available 

如果网站有一个定义的apache VHOST,可能会findconfiguration文件,然后在该文件中查找"documentroot"这应该告诉你的源代码的位置

另一种可用于debugging网站(或任何其他进程)的方法是使用lsof (可能不在path上,通常在/sbin/lsof

lsof -s [PID]会列出给定进程所处理的所有文件,并且可以准确地查看正在使用的内容(包括您的html / php文件,以及该站点所需的日志文件和库)

我不知道在哪里…find加载的index.html / index.php。

寻找页面源文件

一种方法是浏览网站,find一个更独特的页面 – 让我们说newcontactform.php – 理想情况下,不太可能出现在同一台服务器托pipe的其他网站。

你可以试试

 locate newcontactform.php 

如果失败,请按照

 find / -name newcontactform.php 

这应该产生一个可观的小候选人名单。

然后,您可以检查这些文件,进行差异化处理,如有必要,可以尝试进行小的更改(例如插入HTML注释)以确认文件确实生成了页面。

findconfiguration

有时configuration文件在ps命令的输出中很明显。 最坏的情况是ps -ef | grep -e 'apache|httpd' ps -ef | grep -e 'apache|httpd'但更多的ps选项的创造性使用可能值得探索。

您可以在Ubuntu的典型位置和Apache httpd项目(可能有所不同)中查找httpd.conf ,或者使用locatefind

有时主configuration文件是指vhost的其他configuration文件。 你可以通过识别主configuration文件来解决这个问题。

慢性病例

有时,旧的服务器运行各种web服务器守护进程。 在这种情况下,可能需要一段时间才能find所有的configuration文件。 上述技术的组合应该最终成功。

你可以使用netstat -lntpfind正在监听80端口的程序。 通常,查找二进制文件是一个有用的指向包含configuration文件的目录树的指针。

您可以在Web服务器的(apache)configuration文件 – httpd.conf (很可能位于/ etc /中)中检查Vhost是否正在寻找的域。只需打开文件并滚动直到findVirtulaHost指令你的域名,你将看到DocumentRoot指令 – 这是你的网站的文档根目录,你可以在这里find应用程序的文件。

请去

cd / etc / apache2 / site-avaliable /

在这里你可以find你的configuration文件(即:000-default.conf)

请打开此文件/使用打开您的configuration文件

vi 000-default.conf

在那里你会findDocumentRoot.That是你的网站的代码

这是默认的conf文件,同样你也会有一些conf的细节,请检查一下。