5

Tomcat安全配置 | WooYun知识库

 6 years ago
source link:
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Tomcat安全配置

tomcat是一个开源Web服务器,基于TomcatWeb运行效率高,可以在一般的硬件平台上流畅运行,因此,颇受Web站长的青睐。不过,在默认配置下其存在一定的安全隐患,可被恶意攻击。

0x00 测试环境


Win2003

Tomcat6.0.18 安装版

0x01 安全验证


一.登陆后台

首先在win2003上部署Tomcat,一切保持默认。

Tomcat的默认后台地址为:http://域名:端口/manager/html.进入之后弹出登陆对话框,Tomcat默认的用户名admin,密码为空。

Tomcat的一些弱口令:

tomcat tomcat 
admin 空 
admin admin 
admin 123456

enter image description here

然后来看一下Tomcat安装版默认的tomacat-users.xml配置文件

enter image description here

注:Linux平台及Windows平台免安装版本不受该漏洞影响。

二.获取Webshell

Tomcat的后台有个WAR file to deploy模块,通过其可以上传WAR文件。Tomcat可以解析WAR文件,能够将其解压并生成web文件。

enter image description here

我们将一个jsp格式的webshellWinRar打包然后将其后缀改名为WAR(本例为no.war),这样;一个WAR包就生成了。最后将其上传到服务器,可以看到在Tomcat的后台中多了一个名为/no的目录。

enter image description here

点击该目录打开该目录jsp木马就运行了,这样就获得了一个Webshell

enter image description here

三.获取服务器权限

Tomcat服务默认是以system权限运行的,因此该jsp木马就继承了其权限,几乎可以对Web服务器进行所有的操作。

enter image description here

然后创建用户: net user Boom shellcode /add

添加到管理员用户组: net localgroup administrators Boom /add

enter image description here

然后可以干什么事我就不说了

0x02 安全配置


一.修改tomacat-users.xml或删除Tomcat后台

修改\conf\tomacat-users.xml

enter image description here

删除Tomcat后台 \webapps全部删除就好。

二.禁止列目录

IIS中如果设置不当,就会列出Web当前目录中的所有文件,然而在Tomcat也不例外。如果浏览者可以在客户端浏览Web目录,那将会存在较大的安全隐患,因此我们要确认Tomcat的设置中禁止列目录。\conf\web.xml

<init-param>
<param-name>listings</param-name>
<param-value>false</param-value>
</init-param>  

确认是false而不是true

enter image description here

三.服务降权

默认安装时Tomcat是以系统服务权限运行的,因此缺省情况下几乎所有的Web服务器的管理员都具有Administrator权限,存在极大的安全隐患,所以我们的安全设置首先从Tomcat服务降权开始。

首先创建一个普通用户,为其设置密码,将其密码策略设置为“密码永不过期”,比如我们创建的用户为tomcat。然后修改tomcat安装文件夹的访问权限,为tomcat赋予Tomcat文件夹的读、写、执行的访问权限,赋予TomcatWebApps文件夹的只读访问权限,如果某些Web应用程序需要写访问权限,单独为其授予对那个文件夹的写访问权限。

enter image description here

“开始→运行”,输入services.msc打开服务管理器,找到Apache Tomcat服务,双击打开该服务的属性,在其实属性窗口中点击“登录”选项卡,在登录身份下选中“以此帐户”,然后在文本框中输入tomcat和密码,最后“确定”并重启服务器。这样tomcat就以tomcat这个普通用户的权限运行。

enter image description here

然后重启服务,就生效了。这样普通用户tomcat运行的Tomcat其权限就大大地降低了,就算是攻击者获得了Webshell也不能进一步深入,从而威胁web服务器的安全。

四.关闭war自动部署

关闭war自动部署 unpackWARs="false" autoDeploy="false"。防止被植入木马等恶意程序

应用程序部署与tomcat启动,不能使用同一个用户。

enter image description here


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK