在线
客服

在线客服
尊敬的客户,我们24小时竭诚为您服务 公司总机: 0755-83312037 (32条线)

客服
热线

0755-83312037 (32条线)
7*24小时客服服务热线

?

关注
微信

关注官方微信
TOP

返回
顶部

实例学习Apache服务器的安全防护知识

发布时间:2019-04-13浏览次数:964 <p> </p> <table style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0"><tbody><tr> <td style="WORD-WRAP: break-word" bgcolor="#fdfddf"> <font color="#ff0000">WebjxCom提示:</font><font color="#000000">开源 Apache 服务器安全防护技术精要及实战.</font> </td> </tr></tbody></table> <p style='font: 14px/26px "Segoe UI", Tahoma, Arial; margin: 1em 0px; padding: 0px; color: rgb(0, 0, 0); text-transform: none; text-indent: 2em; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; background-color: rgb(245, 250, 255); -webkit-text-size-adjust: none; -webkit-text-stroke-width: 0px;'>Apache 一直是世界上使用率排名前三的 Web 服务器软件。企业使用其构建 Web 应用,从很大程度上都需要对其安全性进行综合考虑,以保证能够应对拒绝服务攻击、流量窃听、数据泄漏等网络威胁,从而保证企业门户网站的安全。除了使用业界流行的防火墙、IDS/IPS(入侵检测系统 / 入侵防御系统)、WAF(Web 应用防火墙)、UTM(统一威胁管理)等外部安全设备对 Apache 服务进行安全防护外,作为一种优秀的开源服务器软件,Apache 本身就具有很多优秀的特性可以为服务器管理员提供安全配置,以防范各种网络攻击。因此,充分、高效地挖掘 Apache 服务器的自身安全能力也是企业安全工作者一个必备的技能。基于此,本文将通过大量的实例,从服务器安全设置、运行环境安全保障、安全模块保护、日志管理等 6 个方面详细剖析 Apache 服务器的安全防护要点。</p> <h2 id="major1" style='margin: 1em 0px; padding: 0px; color: rgb(0, 0, 0); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: "Segoe UI", Tahoma, Arial; font-size: 18px; font-style: normal; font-variant: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; background-color: rgb(245, 250, 255); -webkit-text-size-adjust: none; -webkit-text-stroke-width: 0px;'><strong>Apache 服务简介</strong></h2> <p style='font: 14px/26px "Segoe UI", Tahoma, Arial; margin: 1em 0px; padding: 0px; color: rgb(0, 0, 0); text-transform: none; text-indent: 2em; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; background-color: rgb(245, 250, 255); -webkit-text-size-adjust: none; -webkit-text-stroke-width: 0px;'>Web 服务器也称为 WWW 服务器或 HTTP 服务器 (HTTP Server),它是 Internet 上最常见也是使用最频繁的服务器之一,Web 服务器能够为用户提供网页浏览、论坛访问等等服务。</p> <p style='font: 14px/26px "Segoe UI", Tahoma, Arial; margin: 1em 0px; padding: 0px; color: rgb(0, 0, 0); text-transform: none; text-indent: 2em; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; background-color: rgb(245, 250, 255); -webkit-text-size-adjust: none; -webkit-text-stroke-width: 0px;'>由于用户在通过 Web 浏览器访问信息资源的过程中,无须再关心一些技术性的细节,而且界面非常友好,因而 Web 在 Internet 上一推出就得到了爆炸性的发展。现在 Web 服务器已经成为 Internet 上最大的计算机群,Web 文档之多、链接的网络之广,也令人难以想像。因此,Web 服务器软件的数量也开始增加,Web 服务器软件市场的竞争也越来越激烈。本文所讨论的就是一款最常用的 Web 服务器软件&#8212;&#8212; Apache。</p> <p style='font: 14px/26px "Segoe UI", Tahoma, Arial; margin: 1em 0px; padding: 0px; color: rgb(0, 0, 0); text-transform: none; text-indent: 2em; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; background-color: rgb(245, 250, 255); -webkit-text-size-adjust: none; -webkit-text-stroke-width: 0px;'>Apache 是一个免费的软件,用户可以免费从 Apache 的官方网站下载。任何人都可以参加其组成部分的开发。Apache 允许世界各地的人对其提供新特性。当新代码提交到 Apache Group 后,Apache Group 对其具体内容进行审查并测试和质量检查。如果他们满意,该代码就会被集成到 Apache 的主要发行版本中。</p> <p style='font: 14px/26px "Segoe UI", Tahoma, Arial; margin: 1em 0px; padding: 0px; color: rgb(0, 0, 0); text-transform: none; text-indent: 2em; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; background-color: rgb(245, 250, 255); -webkit-text-size-adjust: none; -webkit-text-stroke-width: 0px;'>Apache 的其他主要特征有:</p> <ul style='font: 14px/26px "Segoe UI", Tahoma, Arial; margin: 1em 0px; padding: 0px 0px 0px 30px; color: rgb(0, 0, 0); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; list-style-type: disc; white-space: normal; orphans: 2; widows: 2; background-color: rgb(245, 250, 255); -webkit-text-size-adjust: none; -webkit-text-stroke-width: 0px;'> <li style="list-style: inherit; margin: 0px 0px 5px; padding: 0px;">支持最新的 HTTP 协议:是最先支持 HTTP1.1 的 Web 服务器之一,其与新的 HTTP 协议完全兼容,同时与 HTTP1.0、HTTP1.1 向后兼容。Apache 还为支持新协议做好了准备。</li> <li style="list-style: inherit; margin: 0px 0px 5px; padding: 0px;">简单而强大的基于文件的配置:该服务器没有为管理员提供图形用户界面,提供了三个简单但是功能异常强大的配置文件。用户可以根据需要用这三个文件随心所欲地完成自己希望的 Apache 配置。</li> <li style="list-style: inherit; margin: 0px 0px 5px; padding: 0px;">支持通用网关接口(CGI):采用 mod_cgi 模块支持 CGI。Apache 支持 CGI/1.1 标准,并且提供了一些扩充。</li> <li style="list-style: inherit; margin: 0px 0px 5px; padding: 0px;">支持虚拟主机:是首批既支持 IP 虚拟主机又支持命名虚拟主机的 Web 服务器之一。</li> <li style="list-style: inherit; margin: 0px 0px 5px; padding: 0px;">支持 HTTP 认证:支持基于 Web 的基本认证。它还有望支持基于消息摘要的认证。</li> <li style="list-style: inherit; margin: 0px 0px 5px; padding: 0px;">内部集成 Perl:Perl 是 CGI 脚本编程的事实标准。Apache 对 Perl 提供了良好的支持,通过使用其 mod_perl 模块,还可以将 Perl 的脚本装入内存。</li> <li style="list-style: inherit; margin: 0px 0px 5px; padding: 0px;">集成代理服务器:用户还可以选择 Apache 作为代理服务器。</li> <li style="list-style: inherit; margin: 0px 0px 5px; padding: 0px;">支持 SSL:由于版本法和美国法律在进出口方面的限制,Apache 本身不支持 SSL。但是用户可以通过安装 Apache 的补丁程序集合(Apache-SSL)使得 Apache 支持 SSL。</li> <li style="list-style: inherit; margin: 0px 0px 5px; padding: 0px;">支持 HTTP Cookie:通过支持 Cookie,可以对用户浏览 Web 站点进行跟踪。</li> </ul> <div style='font: 14px/26px "Segoe UI", Tahoma, Arial; margin: 0px; padding: 0px; color: rgb(0, 0, 0); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; background-color: rgb(245, 250, 255); -webkit-text-size-adjust: none; -webkit-text-stroke-width: 0px;'> <h2 id="major2" style="margin: 1em 0px; padding: 0px; font-size: 18px;"><strong>Apache 服务面临的网络威胁</strong></h2> <p style="margin: 1em 0px; padding: 0px; text-indent: 2em;">一般说来,Apache 服务器主要面临如下几种网络威胁:</p> <ol type="1" style="margin: 1em 0px; padding: 0px 0px 0px 30px; list-style-type: decimal;"> <li style="list-style: inherit; margin: 0px 0px 5px; padding: 0px;">使用 HTTP 协议进行的拒绝服务攻击:攻击者会通过某些手段使服务器拒绝对 HTIP 应答。这样会使 Apache 对系统资源(CPU 时间和内存)需求巨增,造成 Apache 系统变慢甚至完全瘫痪,从而引起 HTTP 服务的中断或者合法用户的合法请求得不到及时地响应;</li> <li style="list-style: inherit; margin: 0px 0px 5px; padding: 0px;">缓冲区溢出攻击:由于 Apache 源代码完全开放,攻击者就可以利用程序编写的一些缺陷,使程序偏离正常流程。程序使用静态分配的内存保存请求数据,攻击者就可以发送一个超长请求使缓冲区溢出,从而导致缓冲区溢出攻击;</li> <li style="list-style: inherit; margin: 0px 0px 5px; padding: 0px;">被攻击者获得 root 权限,威胁系统安全:由于 Apache 服务器一般以 root 权限运行,攻击者通过它获得 root 权限,进而控制整个 Apache 系统;</li> <li style="list-style: inherit; margin: 0px 0px 5px; padding: 0px;">Apache 服务器与客户端通信安全:如果采用明文传输,则服务器与客户端的敏感通信信息将有可能被黑客或者不法用户获取;</li> <li style="list-style: inherit; margin: 0px 0px 5px; padding: 0px;">由于 Apache 配置文件设置不当引起的安全问题:恶意者可以随意下载或修改删除系统文件。这主要涉及到对访问者的内容和权限的限制。</li> </ol> <p style="margin: 1em 0px; padding: 0px; text-indent: 2em;">要应对上述这些安全威胁,要从 Apache 服务器端配置、运行环境、通信链路安全保障、安全模块使用、日志管理等各方面、全方位的进行保障,下面将进行分门别类的详细介绍。</p> <h2 id="major3" style="margin: 1em 0px; padding: 0px; font-size: 18px;"><strong>Apache 服务器端安全设置</strong></h2> <h3 id="minor3.1" style="margin: 1em 0px; padding: 0px; font-size: 18px;"><strong>限制 root 用户运行 Apache 服务器</strong></h3> <p style="margin: 1em 0px; padding: 0px; text-indent: 2em;">一般情况下,在 Linux 下启动 Apache 服务器的进程 httpd 需要 root 权限。由于 root 权限太大,存在许多潜在的对系统的安全威胁。一些管理员为了安全的原因,认为 httpd 服务器不可能没有安全漏洞,因而更愿意使用普通用户的权限来启动服务器。http.conf 主配置文件里面有如下 2 个配置是 Apache 的安全保证,Apache 在启动之后,就将其本身设置为这两个选项设置的用户和组权限进行运行,这样就降低了服务器的危险性。</p> <p style="margin: 1em 0px; padding: 0px; text-indent: 2em;">User apache</p> <p style="margin: 1em 0px; padding: 0px; text-indent: 2em;">Group apache</p> <p style="margin: 1em 0px; padding: 0px; text-indent: 2em;">需要特别指出的是:以上 2 个配置在主配置文件里面是默认选项,当采用 root 用户身份运行 httpd 进程后,系统将自动将该进程的用户组和权限改为 apache,这样,httpd 进程的权限就被限制在 apache 用户和组范围内,因而保证了安全。</p> <h3 id="minor3.2" style="margin: 1em 0px; padding: 0px; font-size: 18px;"><strong>向客户端隐藏 Apache 服务器的相关信息</strong></h3> <p style="margin: 1em 0px; padding: 0px; text-indent: 2em;">Apache 服务器的版本号可以作为黑客入侵的重要信息进行利用,他们通常在获得版本号后,通过网上搜索针对该版本服务器的漏洞,从而使用相应的技术和工具有针对性的入侵,这也是渗透测试的一个关键步骤。因此,为了避免一些不必要的麻烦和安全隐患,可以通过主配置文件 httpd.conf 下的如下两个选项进行:</p> <p style="margin: 1em 0px; padding: 0px; text-indent: 2em;">(1)ServerTokens:该选项用于控制服务器是否响应来自客户端的请求,向客户端输出服务器系统类型或者相应的内置模块等重要信息。Red Hat Enterprise Linux 5 操作系统在主配置文件中提供全局默认控制阈值为 OS,即 ServerTokens OS。它们将向客户端公开操作系统信息和相关敏感信息,所以保证安全情况下需要在该选项后使用“ProductOnly”,即 ServerTokens ProductOnly。</p> <p style="margin: 1em 0px; padding: 0px; text-indent: 2em;">(2)ServerSignature:该选项控制由系统生成的页面(错误信息等)。默认情况下为 off,即 ServerSignature off,该情况下不输出任何页面信息。另一情况为 on,即 ServerSignature on,该情况下输出一行关于版本号等相关信息。安全情况下应该将其状态设为 off。</p> <p style="margin: 1em 0px; padding: 0px; text-indent: 2em;">图 1 和图 2 为安全设定这两个选项前后正常情况下和错误情况下的输出页面(通过 Rhel5 中的 Mozilla Firefox 浏览器访问 Rhel5 中的 Apache 服务器)的详细对比。可以清楚看到,安全设定选项后,可以充分地向客户端用户隐藏 Linux 操作系统信息和 Apache 服务器版本信息。</p> <p style="margin: 1em 0px; padding: 0px; text-indent: 2em;">图 1. 错误情况下未设定安全选项前示意</p> <p style="margin: 1em 0px; padding: 0px; text-indent: 2em;"><a title="开源 Apache 服务器安全防护技术精要及实战" class="cboxElement" style="color: rgb(28, 61, 114); text-decoration: none;" href="http://upload.chinaz.com/2013/1017/1381977512685.jpg" rel="lightbox[49548]"><img title="" class="alignnone size-full wp-image-49549" style="border: 1px solid rgb(153, 153, 153); margin-right: auto; margin-left: auto; display: block;" alt="iimage001" src="http://www.webjx.com/files/allimg/131017/2050370.jpg" border="0"></a></p> <p style="margin: 1em 0px; padding: 0px; text-indent: 2em;">图 2. 操作情况下使用安全设定后的对比</p> <p style="margin: 1em 0px; padding: 0px; text-indent: 2em;"><a title="开源 Apache 服务器安全防护技术精要及实战" class="cboxElement" style="color: rgb(28, 61, 114); text-decoration: none;" href="http://upload.chinaz.com/2013/1017/1381977512386.jpg" rel="lightbox[49548]"><img title="" class="alignnone size-full wp-image-49550" style="border: 1px solid rgb(153, 153, 153); margin-right: auto; margin-left: auto; display: block;" alt="iimage002" src="http://www.webjx.com/files/allimg/131017/2050371.jpg" border="0"></a></p> <h3 id="minor3.3" style="margin: 1em 0px; padding: 0px; font-size: 18px;"><strong>设置虚拟目录和目录权限</strong></h3> <p style="margin: 1em 0px; padding: 0px; text-indent: 2em;">要从主目录以外的其他目录中进行发布,就必须创建虚拟目录。虚拟目录是一个位于 Apache 的主目录外的目录,它不包含在 Apache 的主目录中,但在访问 Web 站点的用户看来,它与位于主目录中的子目录是一样的。每个虚拟目录都有一个别名,用户 Web 浏览器中可以通过此别名来访问虚拟目录,如 http:// 服务器 IP 地址 / 别名 / 文件名,就可以访问虚拟目录下面的任何文件了。</p> <p style="margin: 1em 0px; padding: 0px; text-indent: 2em;">使用 Alias 选项可以创建虚拟目录。在主配置文件中,Apache 默认已经创建了两个虚拟目录。这两条语句分别建立了“/icons/”和“/manual”两个虚拟目录,它们对应的物理路径分别是“/var/www/icons/”和“/var/www/manual”。在主配置文件中,用户可以看到如下配置语句:</p> <div style="margin: 0px; padding: 0px;"> <div class="syntaxhighlighter notranslate shell ie" id="highlighter_889355" style="margin: 0px; padding: 0px;"> <table style="width: 641px; border-collapse: collapse; border-spacing: 0px; background-color: rgb(255, 255, 255);" border="0" cellspacing="0" cellpadding="0"><tbody><tr> <td class="gutter" style="margin: 0px; padding: 5px; border: 1px solid rgb(221, 221, 221);"> <div class="line number1 index0 alt2" style="margin: 0px 10px 10px; padding: 0px;">1</div> <div class="line number2 index1 alt1" style="margin: 0px 10px 10px; padding: 0px;">2</div> <div class="line number3 index2 alt2" style="margin: 0px 10px 10px; padding: 0px;">3</div> </td> <td class="code" style="margin: 0px; padding: 5px; border: 1px solid rgb(221, 221, 221);"> <div class="container" style="margin: auto; padding: 0px; width: 539.96px; overflow: hidden; background-color: rgb(255, 255, 255);"> <div class="line number1 index0 alt2" style="margin: 0px 10px 10px; padding: 0px;"> <code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>Alias<span class="Apple-converted-space">&#160;</span></code><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>/icons/</code><span class="Apple-converted-space">&#160;</span><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>“</code><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>/var/www/icons/</code><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>”</code> </div> <div class="line number2 index1 alt1" style="margin: 0px 10px 10px; padding: 0px;"> <code class="shell spaces" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>&#160;</code>&#160;</div> <div class="line number3 index2 alt2" style="margin: 0px 10px 10px; padding: 0px;"> <code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>Alias<span class="Apple-converted-space">&#160;</span></code><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>/manual</code><span class="Apple-converted-space">&#160;</span><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>“</code><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>/var/www/manual</code><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>”</code> </div> </div> </td> </tr></tbody></table> </div> </div> <p style="margin: 1em 0px; padding: 0px; text-indent: 2em;">在实际使用过程中,用户可以自己创建虚拟目录。比如,创建名为 /user 的虚拟目录,它所对应的路径为上面几个例子中常用的 /var/www/html/rhel5:</p> <div style="margin: 0px; padding: 0px;"> <div class="syntaxhighlighter notranslate shell ie" id="highlighter_604871" style="margin: 0px; padding: 0px;"> <table style="width: 641px; border-collapse: collapse; border-spacing: 0px; background-color: rgb(255, 255, 255);" border="0" cellspacing="0" cellpadding="0"><tbody><tr> <td class="gutter" style="margin: 0px; padding: 5px; border: 1px solid rgb(221, 221, 221);"> <div class="line number1 index0 alt2" style="margin: 0px 10px 10px; padding: 0px;">1</div> </td> <td class="code" style="margin: 0px; padding: 5px; border: 1px solid rgb(221, 221, 221);"> <div class="container" style="margin: auto; padding: 0px; width: 543.9px; overflow: hidden; background-color: rgb(255, 255, 255);"> <div class="line number1 index0 alt2" style="margin: 0px 10px 10px; padding: 0px;"> <code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>Alias<span class="Apple-converted-space">&#160;</span></code><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>/test</code><span class="Apple-converted-space">&#160;</span><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>“</code><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>/var/www/html/rhel5</code><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>″</code> </div> </div> </td> </tr></tbody></table> </div> </div> <p style="margin: 1em 0px; padding: 0px; text-indent: 2em;">如果需要对其进行权限设置,可以加入如下语句:</p> <div style="margin: 0px; padding: 0px;"> <div class="syntaxhighlighter notranslate xml ie" id="highlighter_881212" style="margin: 0px; padding: 0px;"> <table style="width: 641px; border-collapse: collapse; border-spacing: 0px; background-color: rgb(255, 255, 255);" border="0" cellspacing="0" cellpadding="0"><tbody><tr> <td class="gutter" style="margin: 0px; padding: 5px; border: 1px solid rgb(221, 221, 221);"> <div class="line number1 index0 alt2" style="margin: 0px 10px 10px; padding: 0px;">1</div> <div class="line number2 index1 alt1" style="margin: 0px 10px 10px; padding: 0px;">2</div> <div class="line number3 index2 alt2" style="margin: 0px 10px 10px; padding: 0px;">3</div> <div class="line number4 index3 alt1" style="margin: 0px 10px 10px; padding: 0px;">4</div> <div class="line number5 index4 alt2" style="margin: 0px 10px 10px; padding: 0px;">5</div> <div class="line number6 index5 alt1" style="margin: 0px 10px 10px; padding: 0px;">6</div> </td> <td class="code" style="margin: 0px; padding: 5px; border: 1px solid rgb(221, 221, 221);"> <div class="container" style="margin: auto; padding: 0px; width: 543.9px; overflow: hidden; background-color: rgb(255, 255, 255);"> <div class="line number1 index0 alt2" style="margin: 0px 10px 10px; padding: 0px;"> <code class="xml plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>&lt;</code><code class="xml keyword" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>Directory</code><span class="Apple-converted-space">&#160;</span><code class="xml plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>“/var/www/html/rhel5”&gt;</code> </div> <div class="line number2 index1 alt1" style="margin: 0px 10px 10px; padding: 0px;"> <code class="xml spaces" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>&#160;&#160;&#160;&#160;&#160;</code><code class="xml plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>AllowOverride None</code> </div> <div class="line number3 index2 alt2" style="margin: 0px 10px 10px; padding: 0px;"> <code class="xml spaces" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>&#160;&#160;&#160;&#160;&#160;</code><code class="xml plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>Options Indexes</code> </div> <div class="line number4 index3 alt1" style="margin: 0px 10px 10px; padding: 0px;"> <code class="xml spaces" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>&#160;&#160;&#160;&#160;&#160;</code><code class="xml plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>Order allow,deny</code> </div> <div class="line number5 index4 alt2" style="margin: 0px 10px 10px; padding: 0px;"> <code class="xml spaces" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>&#160;&#160;&#160;&#160;&#160;</code><code class="xml plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>Allow from all</code> </div> <div class="line number6 index5 alt1" style="margin: 0px 10px 10px; padding: 0px;"> <code class="xml spaces" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>&#160;</code><code class="xml plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'><code class="xml keyword" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>Directory</code><code class="xml plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>&gt;</code></code> </div> </div> </td> </tr></tbody></table> </div> </div> <p style="margin: 1em 0px; padding: 0px; text-indent: 2em;">设置该虚拟目录和目录权限后,可以使用客户端浏览器进行测试验证,采用别名对该目录中的文件进行访问,浏览结果如图 3 所示。</p> <h5 id="fig3" style="margin: 1em 0px; padding: 0px; font-size: 14px;">图 3. 使用虚拟目录的测试结果</h5> <p style="margin: 1em 0px; padding: 0px; text-indent: 2em;"><a title="开源 Apache 服务器安全防护技术精要及实战" class="cboxElement" style="color: rgb(28, 61, 114); text-decoration: none;" href="http://upload.chinaz.com/2013/1017/1381977512729.jpg" rel="lightbox[49548]"><img title="" class="alignnone size-full wp-image-49551" style="border: 1px solid rgb(153, 153, 153); margin-right: auto; margin-left: auto; display: block;" alt="iimage003" src="http://www.webjx.com/files/allimg/131017/2050372.jpg" border="0"></a></p> <p style="margin: 1em 0px; padding: 0px; text-indent: 2em;">&#160;</p> <h2 id="major4" style="margin: 1em 0px; padding: 0px; font-size: 18px;"><strong>限制 Apache 服务的运行环境</strong></h2> <p style="margin: 1em 0px; padding: 0px; text-indent: 2em;">Apache 服务器需要绑定到 80 端口上来监听请求,而 root 是唯一有这种权限的用户,随着攻击手段和强度的增加,这样会使服务器受到相当大的威胁,一但被利用缓冲区溢出漏洞,就可以控制整个系统。为了进一步提高系统安全性,Linux 内核引入 chroot 机制,chroot 是内核中的一个系统调用,软件可以通过调用函数库的 chroot 函数,来更改某个进程所能见到的根目录。</p> <p style="margin: 1em 0px; padding: 0px; text-indent: 2em;">chroot 机制即将某软件运行限制在指定目录中,保证该软件只能对该目录及其子目录的文件有所动作,从而保证整个服务器的安全。在这种情况下,即使出现黑客或者不法用户通过该软件破坏或被侵入系统,Linux 系统所受的损坏也仅限于该设定的根目录,而不会影响到整个系统的其他部分。</p> <p style="margin: 1em 0px; padding: 0px; text-indent: 2em;">将软件 chroot 化的一个问题是该软件运行时需要的所有程序、配置文件和库文件都必须事先安装到 chroot 目录中,通常称这个目录为 chroot“监牢”。如果在“监牢”中运行 httpd,那么用户根本看不到 Linux 文件系统中那个真正的目录,从而保证了 Linux 系统的安全。</p> <p style="margin: 1em 0px; padding: 0px; text-indent: 2em;">在使用该技术的时候,一般情况下需要事先创建目录,并将守护进程的可执行文件 httpd 复制到其中。同时,由于 httpd 需要几个库文件,所以需要把 httpd 程序依赖的几个 lib 文件同时也拷贝到同一个目录下,因此手工完成这一工作是非常麻烦的。幸运的是,用户可以通过使用开源的 jail 软件包来帮助简化 chroot“监牢”建立的过程,具体步骤如下所示:Jail 官方网站是:http://www.jmcresearch.com/projects/。</p> <p style="margin: 1em 0px; padding: 0px; text-indent: 2em;">首先将其下载,然后执行如下命令进行源代码包的编译和安装:</p> <div style="margin: 0px; padding: 0px;"> <div class="syntaxhighlighter notranslate shell ie" id="highlighter_965703" style="margin: 0px; padding: 0px;"> <table style="width: 641px; border-collapse: collapse; border-spacing: 0px; background-color: rgb(255, 255, 255);" border="0" cellspacing="0" cellpadding="0"><tbody><tr> <td class="gutter" style="margin: 0px; padding: 5px; border: 1px solid rgb(221, 221, 221);"> <div class="line number1 index0 alt2" style="margin: 0px 10px 10px; padding: 0px;">1</div> <div class="line number2 index1 alt1" style="margin: 0px 10px 10px; padding: 0px;">2</div> <div class="line number3 index2 alt2" style="margin: 0px 10px 10px; padding: 0px;">3</div> </td> <td class="code" style="margin: 0px; padding: 5px; border: 1px solid rgb(221, 221, 221);"> <div class="container" style="margin: auto; padding: 0px; width: 530.16px; overflow: hidden; background-color: rgb(255, 255, 255);"> <div class="line number1 index0 alt2" style="margin: 0px 10px 10px; padding: 0px;"><code class="shell comments" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>#tar xzvf jail_1.9a.tar.gz</code></div> <div class="line number2 index1 alt1" style="margin: 0px 10px 10px; padding: 0px;"> <code class="shell spaces" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>&#160;</code><code class="shell comments" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>#cd jail/src</code> </div> <div class="line number3 index2 alt2" style="margin: 0px 10px 10px; padding: 0px;"> <code class="shell spaces" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>&#160;</code><code class="shell comments" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>#make</code> </div> </div> </td> </tr></tbody></table> </div> </div> <p style="margin: 1em 0px; padding: 0px; text-indent: 2em;">jail 软件包提供了几个 Perl 脚本作为其核心命令,包括 mkjailenv、addjailuser 和 addjailsw,他们位于解压后的目录 jail/bin 中。这几个命令的基本用途如下所示:</p> <ul style="margin: 1em 0px; padding: 0px 0px 0px 30px; list-style-type: disc;"> <li style="list-style: inherit; margin: 0px 0px 5px; padding: 0px;">mkjailenv:用于创建 chroot“监牢”目录,并且从真实文件系统中拷贝基本的软件环境。</li> <li style="list-style: inherit; margin: 0px 0px 5px; padding: 0px;">addjailsw:用于从真实文件系统中拷贝二进制可执行文件及其相关的其它文件(包括库文件、辅助性文件和设备文件)到该“监牢”中。</li> <li style="list-style: inherit; margin: 0px 0px 5px; padding: 0px;">addjailuser:创建新的 chroot“监牢”用户。</li> </ul> <p style="margin: 1em 0px; padding: 0px; text-indent: 2em;">采用 jail 创建监牢的步骤如下所示;</p> <p style="margin: 1em 0px; padding: 0px; text-indent: 2em;">(1)首先需要停止目前运行的 httpd 服务,然后建立 chroot 目录,命令如下所示。该命令将 chroot 目录建立在路径 /root/chroot/httpd 下:</p> <div style="margin: 0px; padding: 0px;"> <div class="syntaxhighlighter notranslate shell ie" id="highlighter_134380" style="margin: 0px; padding: 0px;"> <table style="width: 641px; border-collapse: collapse; border-spacing: 0px; background-color: rgb(255, 255, 255);" border="0" cellspacing="0" cellpadding="0"><tbody><tr> <td class="gutter" style="margin: 0px; padding: 5px; border: 1px solid rgb(221, 221, 221);"> <div class="line number1 index0 alt2" style="margin: 0px 10px 10px; padding: 0px;">1</div> <div class="line number2 index1 alt1" style="margin: 0px 10px 10px; padding: 0px;">2</div> <div class="line number3 index2 alt2" style="margin: 0px 10px 10px; padding: 0px;">3</div> <div class="line number4 index3 alt1" style="margin: 0px 10px 10px; padding: 0px;">4</div> <div class="line number5 index4 alt2" style="margin: 0px 10px 10px; padding: 0px;">5</div> <div class="line number6 index5 alt1" style="margin: 0px 10px 10px; padding: 0px;">6</div> <div class="line number7 index6 alt2" style="margin: 0px 10px 10px; padding: 0px;">7</div> <div class="line number8 index7 alt1" style="margin: 0px 10px 10px; padding: 0px;">8</div> <div class="line number9 index8 alt2" style="margin: 0px 10px 10px; padding: 0px;">9</div> <div class="line number10 index9 alt1" style="margin: 0px 10px 10px; padding: 0px;">10</div> <div class="line number11 index10 alt2" style="margin: 0px 10px 10px; padding: 0px;">11</div> <div class="line number12 index11 alt1" style="margin: 0px 10px 10px; padding: 0px;">12</div> <div class="line number13 index12 alt2" style="margin: 0px 10px 10px; padding: 0px;">13</div> <div class="line number14 index13 alt1" style="margin: 0px 10px 10px; padding: 0px;">14</div> <div class="line number15 index14 alt2" style="margin: 0px 10px 10px; padding: 0px;">15</div> </td> <td class="code" style="margin: 0px; padding: 5px; border: 1px solid rgb(221, 221, 221);"> <div class="container" style="margin: auto; padding: 0px; width: 558.58px; overflow: hidden; background-color: rgb(255, 255, 255);"> <div class="line number1 index0 alt2" style="margin: 0px 10px 10px; padding: 0px;"><code class="shell comments" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'># service httpd stop</code></div> <div class="line number2 index1 alt1" style="margin: 0px 10px 10px; padding: 0px;"> <code class="shell spaces" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>&#160;</code><code class="shell comments" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'># mkjailenv /root/chroot/httpd</code> </div> <div class="line number3 index2 alt2" style="margin: 0px 10px 10px; padding: 0px;"> <code class="shell spaces" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>&#160;</code><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>kjailenv</code> </div> <div class="line number4 index3 alt1" style="margin: 0px 10px 10px; padding: 0px;"> <code class="shell spaces" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>&#160;</code><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>A component of Jail (version 1.9<span class="Apple-converted-space">&#160;</span></code><code class="shell keyword" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>for</code><span class="Apple-converted-space">&#160;</span><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>linux)</code> </div> <div class="line number5 index4 alt2" style="margin: 0px 10px 10px; padding: 0px;"> <code class="shell spaces" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>&#160;</code>&#160;</div> <div class="line number6 index5 alt1" style="margin: 0px 10px 10px; padding: 0px;"> <code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>http:</code><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>//www</code><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>.gsyc.inf.uc3m.es/~assman</code><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>/jail/</code> </div> <div class="line number7 index6 alt2" style="margin: 0px 10px 10px; padding: 0px;"> <code class="shell spaces" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>&#160;</code>&#160;</div> <div class="line number8 index7 alt1" style="margin: 0px 10px 10px; padding: 0px;"> <code class="shell spaces" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>&#160;</code><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>Juan M. Casillas &lt;assman@gsyc.inf.uc3m.es&gt;&#160;</code> </div> <div class="line number9 index8 alt2" style="margin: 0px 10px 10px; padding: 0px;"> <code class="shell spaces" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>&#160;</code>&#160;</div> <div class="line number10 index9 alt1" style="margin: 0px 10px 10px; padding: 0px;"> <code class="shell spaces" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>&#160;</code><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>Making chrooted environment into<span class="Apple-converted-space">&#160;</span></code><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>/root/chroot/httpd</code> </div> <div class="line number11 index10 alt2" style="margin: 0px 10px 10px; padding: 0px;"> <code class="shell spaces" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</code><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>Doing preinstall()</code> </div> <div class="line number12 index11 alt1" style="margin: 0px 10px 10px; padding: 0px;"> <code class="shell spaces" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</code><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>Doing special_devices()</code> </div> <div class="line number13 index12 alt2" style="margin: 0px 10px 10px; padding: 0px;"> <code class="shell spaces" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</code><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>Doing gen_template_password()</code> </div> <div class="line number14 index13 alt1" style="margin: 0px 10px 10px; padding: 0px;"> <code class="shell spaces" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</code><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>Doing postinstall()</code> </div> <div class="line number15 index14 alt2" style="margin: 0px 10px 10px; padding: 0px;"> <code class="shell spaces" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>&#160;</code><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>Done.</code> </div> </div> </td> </tr></tbody></table> </div> </div> <p style="margin: 1em 0px; padding: 0px; text-indent: 2em;">(2)为“监牢”添加 httpd 程序,命令如下:</p> <div style="margin: 0px; padding: 0px;"> <div class="syntaxhighlighter notranslate shell ie" id="highlighter_106027" style="margin: 0px; padding: 0px;"> <table style="width: 641px; border-collapse: collapse; border-spacing: 0px; background-color: rgb(255, 255, 255);" border="0" cellspacing="0" cellpadding="0"><tbody><tr> <td class="gutter" style="margin: 0px; padding: 5px; border: 1px solid rgb(221, 221, 221);"> <div class="line number1 index0 alt2" style="margin: 0px 10px 10px; padding: 0px;">1</div> <div class="line number2 index1 alt1" style="margin: 0px 10px 10px; padding: 0px;">2</div> <div class="line number3 index2 alt2" style="margin: 0px 10px 10px; padding: 0px;">3</div> <div class="line number4 index3 alt1" style="margin: 0px 10px 10px; padding: 0px;">4</div> <div class="line number5 index4 alt2" style="margin: 0px 10px 10px; padding: 0px;">5</div> <div class="line number6 index5 alt1" style="margin: 0px 10px 10px; padding: 0px;">6</div> <div class="line number7 index6 alt2" style="margin: 0px 10px 10px; padding: 0px;">7</div> <div class="line number8 index7 alt1" style="margin: 0px 10px 10px; padding: 0px;">8</div> <div class="line number9 index8 alt2" style="margin: 0px 10px 10px; padding: 0px;">9</div> <div class="line number10 index9 alt1" style="margin: 0px 10px 10px; padding: 0px;">10</div> <div class="line number11 index10 alt2" style="margin: 0px 10px 10px; padding: 0px;">11</div> <div class="line number12 index11 alt1" style="margin: 0px 10px 10px; padding: 0px;">12</div> <div class="line number13 index12 alt2" style="margin: 0px 10px 10px; padding: 0px;">13</div> </td> <td class="code" style="margin: 0px; padding: 5px; border: 1px solid rgb(221, 221, 221);"> <div class="container" style="margin: auto; padding: 0px; width: 565.45px; overflow: hidden; background-color: rgb(255, 255, 255);"> <div class="line number1 index0 alt2" style="margin: 0px 10px 10px; padding: 0px;"><code class="shell comments" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'># ./addjailsw&#160; /root/chroot/httpd/ -P /usr/sbin/httpd&#160;</code></div> <div class="line number2 index1 alt1" style="margin: 0px 10px 10px; padding: 0px;"> <code class="shell spaces" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>&#160;</code>&#160;</div> <div class="line number3 index2 alt2" style="margin: 0px 10px 10px; padding: 0px;"> <code class="shell spaces" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>&#160;</code><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>addjailsw</code> </div> <div class="line number4 index3 alt1" style="margin: 0px 10px 10px; padding: 0px;"> <code class="shell spaces" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>&#160;</code><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>A component of Jail (version 1.9<span class="Apple-converted-space">&#160;</span></code><code class="shell keyword" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>for</code><span class="Apple-converted-space">&#160;</span><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>linux)</code> </div> <div class="line number5 index4 alt2" style="margin: 0px 10px 10px; padding: 0px;"> <code class="shell spaces" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>&#160;</code>&#160;</div> <div class="line number6 index5 alt1" style="margin: 0px 10px 10px; padding: 0px;"> <code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>http:</code><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>//www</code><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>.gsyc.inf.uc3m.es/~assman</code><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>/jail/</code> </div> <div class="line number7 index6 alt2" style="margin: 0px 10px 10px; padding: 0px;"> <code class="shell spaces" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>&#160;</code>&#160;</div> <div class="line number8 index7 alt1" style="margin: 0px 10px 10px; padding: 0px;"> <code class="shell spaces" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>&#160;</code><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>Juan M. Casillas &lt;assman@gsyc.inf.uc3m.es&gt;&#160;</code> </div> <div class="line number9 index8 alt2" style="margin: 0px 10px 10px; padding: 0px;"> <code class="shell spaces" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>&#160;</code>&#160;</div> <div class="line number10 index9 alt1" style="margin: 0px 10px 10px; padding: 0px;"> <code class="shell spaces" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>&#160;</code><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>Guessing<span class="Apple-converted-space">&#160;</span></code><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>/usr/sbin/httpd</code><span class="Apple-converted-space">&#160;</span><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>args(0)</code> </div> <div class="line number11 index10 alt2" style="margin: 0px 10px 10px; padding: 0px;"> <code class="shell spaces" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>&#160;</code><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>Warning: can't create<span class="Apple-converted-space">&#160;</span></code><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>/proc/mounts</code><span class="Apple-converted-space">&#160;</span><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>from the<span class="Apple-converted-space">&#160;</span></code><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>/proc</code><span class="Apple-converted-space">&#160;</span><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>filesystem&#160;</code> </div> <div class="line number12 index11 alt1" style="margin: 0px 10px 10px; padding: 0px;"> <code class="shell spaces" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>&#160;</code>&#160;</div> <div class="line number13 index12 alt2" style="margin: 0px 10px 10px; padding: 0px;"> <code class="shell spaces" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>&#160;</code><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>Done.</code> </div> </div> </td> </tr></tbody></table> </div> </div> <p style="margin: 1em 0px; padding: 0px; text-indent: 2em;">在上述过程中,用户不需要在意那些警告信息,因为 jail 会调用 ldd 检查 httpd 用到的库文件。而几乎所有基于共享库的二进制可执行文件都需要上述的几个库文件。</p> <p style="margin: 1em 0px; padding: 0px; text-indent: 2em;">(3)然后,将 httpd 的相关文件拷贝到“监牢”的相关目录中,命令如下所示:</p> <div style="margin: 0px; padding: 0px;"> <div class="syntaxhighlighter notranslate shell ie" id="highlighter_574679" style="margin: 0px; padding: 0px;"> <table style="width: 641px; border-collapse: collapse; border-spacing: 0px; background-color: rgb(255, 255, 255);" border="0" cellspacing="0" cellpadding="0"><tbody><tr> <td class="gutter" style="margin: 0px; padding: 5px; border: 1px solid rgb(221, 221, 221);"> <div class="line number1 index0 alt2" style="margin: 0px 10px 10px; padding: 0px;">1</div> <div class="line number2 index1 alt1" style="margin: 0px 10px 10px; padding: 0px;">2</div> <div class="line number3 index2 alt2" style="margin: 0px 10px 10px; padding: 0px;">3</div> </td> <td class="code" style="margin: 0px; padding: 5px; border: 1px solid rgb(221, 221, 221);"> <div class="container" style="margin: auto; padding: 0px; width: 559.56px; overflow: hidden; background-color: rgb(255, 255, 255);"> <div class="line number1 index0 alt2" style="margin: 0px 10px 10px; padding: 0px;"><code class="shell comments" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'># mkdir -p /root/chroot/httpd/etc</code></div> <div class="line number2 index1 alt1" style="margin: 0px 10px 10px; padding: 0px;"> <code class="shell spaces" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>&#160;</code><code class="shell comments" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'># cp &#8211; a /etc/httpd /root/chroot/httpd/etc/</code> </div> <div class="line number3 index2 alt2" style="margin: 0px 10px 10px; padding: 0px;"><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>。。。。。。</code></div> </div> </td> </tr></tbody></table> </div> </div> <p style="margin: 1em 0px; padding: 0px; text-indent: 2em;">添加后的目录结构如下所示:</p> <div style="margin: 0px; padding: 0px;"> <div class="syntaxhighlighter notranslate shell ie" id="highlighter_915988" style="margin: 0px; padding: 0px;"> <table style="width: 641px; border-collapse: collapse; border-spacing: 0px; background-color: rgb(255, 255, 255);" border="0" cellspacing="0" cellpadding="0"><tbody><tr> <td class="gutter" style="margin: 0px; padding: 5px; border: 1px solid rgb(221, 221, 221);"> <div class="line number1 index0 alt2" style="margin: 0px 10px 10px; padding: 0px;">1</div> <div class="line number2 index1 alt1" style="margin: 0px 10px 10px; padding: 0px;">2</div> <div class="line number3 index2 alt2" style="margin: 0px 10px 10px; padding: 0px;">3</div> <div class="line number4 index3 alt1" style="margin: 0px 10px 10px; padding: 0px;">4</div> <div class="line number5 index4 alt2" style="margin: 0px 10px 10px; padding: 0px;">5</div> <div class="line number6 index5 alt1" style="margin: 0px 10px 10px; padding: 0px;">6</div> <div class="line number7 index6 alt2" style="margin: 0px 10px 10px; padding: 0px;">7</div> <div class="line number8 index7 alt1" style="margin: 0px 10px 10px; padding: 0px;">8</div> <div class="line number9 index8 alt2" style="margin: 0px 10px 10px; padding: 0px;">9</div> </td> <td class="code" style="margin: 0px; padding: 5px; border: 1px solid rgb(221, 221, 221);"> <div class="container" style="margin: auto; padding: 0px; width: 563.5px; overflow: hidden; background-color: rgb(255, 255, 255);"> <div class="line number1 index0 alt2" style="margin: 0px 10px 10px; padding: 0px;"><code class="shell comments" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'># ll</code></div> <div class="line number2 index1 alt1" style="margin: 0px 10px 10px; padding: 0px;"><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>总计 56</code></div> <div class="line number3 index2 alt2" style="margin: 0px 10px 10px; padding: 0px;"> <code class="shell spaces" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>&#160;</code><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>drwxr-xr-x 2 root root 4096 03-23 13:44 dev</code> </div> <div class="line number4 index3 alt1" style="margin: 0px 10px 10px; padding: 0px;"> <code class="shell spaces" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>&#160;</code><code class="shell plain" style='margin: 0px; padding: 0px; font-family: Consolas, "Courier New", monospace;'>drwxr-xr-x 3 root root 4096 03-23 13:46 etc</code> </div> <div class="line number5 index4 alt2" style="margin