Linux 中的最佳安全实践

发布于 2024-07-07 17:23:24 字数 191 浏览 6 评论 0 原文

在维护 Linux 服务器时,您强烈推荐哪些安全最佳实践?
(即启动防火墙、禁用不必要的服务、提防 suid 可执行文件等等。)

另外:是否有关于 Selinux 的明确参考?

编辑:是的,我计划将机器放在互联网上,至少有 openvpn、ssh 和 apache(目前没有动态内容),并为某些人提供 shell 访问。

What security best-practices would you strongly recommend in maintaining a Linux server?
(i.e. bring up a firewall, disable unnecessary services, beware of suid executables, and so on.)

Also: is there a definitive reference on Selinux?

EDIT: Yes, I'm planning to put the machine on the Internet, with at least openvpn, ssh and apache (at the moment, without dynamic content), and to provide shell access to some people.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

七颜 2024-07-14 17:23:24

对于 SELinux,我发现SELinux 示例非常有用。 它非常深入地探讨了如何确保服务器尽可能安全,并且针对如此广泛的主题写得非常好。

但总的来说:

  • 禁用任何你不需要的东西。 攻击范围越广,出现漏洞的可能性就越大。
  • 在任何有意义的服务器前面使用入侵检测系统 (IDS) 层。
  • 将服务器置于与内部网络不同的安全区域中。
  • 尽快部署更新。
  • 及时了解针对您的远程访问应用程序的 0day 攻击。

For SELinux I've found SELinux By Example to be really useful. It goes quite in-depth into keeping a sever as secure as possible and is pretty well written for such a wide topic.

In general though:

  • Disable anything you don't need. The wider the attack domain, the more likely you'll have a breach.
  • Use an intrusion detection system (IDS) layer in front of any meaningful servers.
  • Keep servers in a different security zone from your internal network.
  • Deploy updates as fast as possible.
  • Keep up to date on 0-day attacks for your remotely-accessible apps.
云之铃。 2024-07-14 17:23:24

简短的回答是,这取决于。 这取决于您使用它的目的,这反过来又会影响您应该投入多少精力来保护该东西。

这个问题的答案中有一些方便的提示:
保护 Linux Web 服务器以供公共访问

如果您不将盒子扔到互联网上,其中一些答案不相关。 如果您将其扔到互联网上并在其上托管一些甚至模糊有趣的内容,那么这些答案对您来说就太自由放任了。

The short answer is, it depends. It depends on what you're using it for, which in turn influences how much effort you should put into securing the thing.

There are some handy hints in the answers to this question:
Securing a linux webserver for public access

If you're not throwing the box up onto the internet, some of those answers won't be relevant. if you're throwing it up onto the internet and hosting something even vaguely interesting on it, those answers are far too laissez-faire for you.

兮颜 2024-07-14 17:23:24

NSA 文档“NSA Security Guide for RHEL5”位于:

http://www.nsa.gov/ia/_files/os/redhat/rhel5-guide-i731.pdf

这非常有帮助,至少是系统的。

There's an NSA document "NSA Security Guide for RHEL5" available at:

http://www.nsa.gov/ia/_files/os/redhat/rhel5-guide-i731.pdf

which is pretty helpful and at least systematic.

若能看破又如何 2024-07-14 17:23:24
  • 软件限制为您真正使用的唯一软件
  • 通过 sudo、ACL、内核功能和 SELinux/AppArmor/PaX 策略限制用户的权限
  • 强制使用硬密码(没有人类可以理解的单词、没有生日日期等)
  • 将 用于“危险”应用程序的 LXC 计数器、chroot 或虚拟服务器监狱
  • 安装一些 IDS,例如用于网络流量的 Snort 和用于日志分析的 OSSEC
  • 监控服务器
  • 加密您的敏感数据(truecrypt 是众神的礼物)
  • 使用 GRSecurity 修补您的内核:这增加了一种非常好的偏执水平,

这或多或少就是我会做的。

编辑:我添加了一些我之前忘记命名的想法......

  • Limit the software to the only ones you really use
  • Limit the rights of the users, through sudo, ACLs, kernel capabilities and SELinux/AppArmor/PaX policies
  • Enforce use of hard passwords (no human understandable words, no birthday dates, etc.)
  • Make LXC countainers, chroot or vserver jails for the "dangerous" applications
  • Install some IDS, e.g. Snort for the network traffic and OSSEC for the log analysis
  • Monitor the server
  • Encrypt your sensible datas (truecrypt is a gift of the gods)
  • Patch your kernel with GRSecurity : this add a really nice level of paranoïa

That's more or less what I would do.

Edit : I added some ideas that I previously forgot to name ...

情愿 2024-07-14 17:23:24

1.) 仅启用必要且相关的端口。

2.) 定期扫描网络数据输入 - 输出

3.) 定期扫描访问服务器的 IP 地址,并验证是否从日志/跟踪中发现与这些 IP 地址相关的任何异常数据活动

4.) 如果存在某些关键和机密的情况数据和代码,需要存在于服务器上,可能可以加密

-AD

1.) Enabling only necessary and relevant ports.

2.) Regular scan of the network data in - out

3.) Regular Scan of ip addresses accessing the server and verify if any unusual data activity associated with those ip address as found from logs/traces

4.) If some some critical and confidential data and code, needs to be present on the server , may be it can be encrypted

-AD

梦年海沫深 2024-07-14 17:23:24

目标:
最困难的部分始终是定义您的安全目标。 那时其他一切都相对容易。

探索/研究:
考虑攻击者会采取的相同方法,即网络侦察(namp对此非常有帮助)。

更多信息:
SELinux 的例子是一本很有帮助的书,但找到一个好的集中的 SELinux 信息源仍然很困难。
我有一小部分有用的链接,我有时觉得它们很有用 http://delicious.com/reverand_13/selinux有用

的解决方案/工具:
就像大多数人会说的那样,少即是多。 对于带有 SELinux 的开箱即用的精简框,我建议使用 Clip (http://oss.tresys. com/projects/clip)。 我的一个朋友在一次学术模拟中使用了它,其中该盒子受到其他参与者的直接攻击。 我记得这个故事的结局对这个盒子来说非常有利。

您需要熟悉 SELinux 策略的编写。 模块化政策也可能会有所帮助。 诸如 SLIDE 和 seeedit(尚未尝试)之类的工具可能会对您有所帮助。

Goals:
The hardest part is always defining your security goals. Everything else is relatively easy at that point.

Probing/research:
Consider the same approach that attackers would take, ie network reconnaissance (namp is pretty helpful for that).

More information:
SELinux by example is a helpful book, finding a good centralized source for SELinux information is still hard.
I have a small list of helpful links that I find useful time to time http://delicious.com/reverand_13/selinux

Helpful solution/tools:
As with what most people will say less is more. For an out of the box stripped down box with SELinux I would suggest clip (http://oss.tresys.com/projects/clip). A friend of mine used it in an academic simulation in which the box was under direct attack from other participants. I recall the story concluded very favorably for said box.

You will want to become familiar with writing SELinux policy. Modular policy can also become helpful. such tools as SLIDE and seedit (have not tried) may help you.

少钕鈤記 2024-07-14 17:23:24

除非必要,否则不要使用 DNS 服务器。 BIND 一直是安全问题和漏洞利用的热点。

Don't use a DNS Server unless you have to . BIND has been a hotspot of security issues and exploits.

娇柔作态 2024-07-14 17:23:24

强化 Linux 服务器是一个广泛的话题,它主要取决于您的需求。

一般来说,您需要考虑以下几组问题(我将给出每组中的最佳实践示例):

  1. 启动和磁盘
    Ex1:禁用从外部设备启动。
    示例2:为 GRUB 引导加载程序设置密码 - 参考

  2. 文件系统分区
    Ex1:将用户分区(/home/tmp/var)与操作系统分区分开。
    示例 2:在分区上设置 nosuid – 以防止使用 setuid 位进行权限升级。

  3. 内核
    Ex1:更新安全补丁。
    示例 2:在此处了解更多信息。

  4. 网络
    Ex1:关闭未使用的端口。
    Ex2: 禁用 IP 转发。
    Ex3:禁用发送数据包重定向。

  5. 用户/帐户
    Ex1:强制执行强密码 (SHA512)。
    例2:设置密码时效和过期时间。
    Ex3:限制用户使用旧密码。

  6. 审核和记录
    示例1:配置 auditd - ref
    示例2:使用journald配置日志记录 - ref

  7. 服务
    Ex1:删除未使用的服务,例如:FTP、DNS、LDAP、SMB、DHCP、NFS、SNMP 等。
    EX2:如果您使用的是 Apache 或 nginx 等 Web 服务器 - 不要以 root 身份运行它们 - 阅读更多内容 这里
    Ex3:安全 SSH ref

  8. 软件
    确保删除未使用的软件包。

阅读更多:

https://www.computerworld.com/article/3144985/linux-hardening-a-15-step-checklist-for-a-secure-linux-server.html

https://www.howtoing.com/linux-server-hardening-security-tips/

https://cisofy.com/checklist/linux-security/

https://www.ucd.ie/t4cms/UCD%20Linux%20Security%20Checklist。 pdf

https://www.cyberciti。 biz/faq/linux-kernel-etcsysctl-conf-security-hardening/

https ://securecompliance.co/linux-server-hardening-checklist/


现在专门针对 SELinux:
首先,确保您的计算机启用了 SELinux。

继续以下指南:
https: //www.digitalocean.com/community/tutorials/an-introduction-to-selinux-on-centos-7-part-1-basic-concepts

https://linuxtechlab.com/beginners-guide-to-selinux/

https://www.computernetworkingnotes.com/rhce-study-guide/selinux-explained- with-examples-in-easy-language.html

Hardening a Linux server is a vast topic and it primarily depend on your needs.

In general, you need to consider the following groups of concern (I'll give example of best practices in each group):

  1. Boot and Disk
    Ex1: Disable booting from external devices.
    Ex2: Set a password for the GRUB bootloader - Ref.

  2. File system partitioning
    Ex1: Separate user Partitions (/home, /tmp, /var) from OS Partitions.
    Ex2: Setup nosuid on partitions – in order to prevent privilege escalation with the setuid bit.

  3. Kernel
    Ex1: Update security patches.
    Ex2: Read more in here.

  4. Networking
    Ex1: Close unused ports.
    Ex2: Disable IP forwarding.
    Ex3: Disable send packet redirects.

  5. Users / Accounts
    Ex1 : Enforce strong passwords (SHA512).
    Ex2: Set up password aging and expiration.
    Ex3: Restrict Users to Use Old Passwords.

  6. Auditing and logging
    Ex1: Configure auditd - ref.
    Ex2: Configure logging with journald - ref.

  7. Services
    Ex1: Remove unused services like: FTP, DNS, LDAP, SMB, DHCP, NFS, SNMP, etc'.
    EX2: If you're using a web server like Apache or nginx - don't run them as root - read more here.
    Ex3: Secure SSH ref.

  8. Software
    Make sure you remove unused packages.

Read more:

https://www.computerworld.com/article/3144985/linux-hardening-a-15-step-checklist-for-a-secure-linux-server.html

https://www.tecmint.com/linux-server-hardening-security-tips/

https://cisofy.com/checklist/linux-security/

https://www.ucd.ie/t4cms/UCD%20Linux%20Security%20Checklist.pdf

https://www.cyberciti.biz/faq/linux-kernel-etcsysctl-conf-security-hardening/

https://securecompliance.co/linux-server-hardening-checklist/


Now specifically for SELinux:
First of all, make sure that SELinux is enabled in your machine.

Continue with the following guides:
https://www.digitalocean.com/community/tutorials/an-introduction-to-selinux-on-centos-7-part-1-basic-concepts

https://linuxtechlab.com/beginners-guide-to-selinux/

https://www.computernetworkingnotes.com/rhce-study-guide/selinux-explained-with-examples-in-easy-language.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文