📄 00000030.htm
字号:
在 log 档里面没看到任何东西的话, 记得重新启动 inetd 和 syslogd: <BR> <BR># kill -HUP `cat /var/run/syslog.pig` `cat /var/run/inetd.pid` <BR> <BR>o Filesystem <BR> <BR> 既然 Unix 把什麽东西都当作档案来看待, 好好的保护你的档案系统便是很重要的事。 <BR> 有件事是在你安装作业系统前便要完成的: 必须要计划并设计好你的 partition 该怎 <BR> 麽切割。有几个很重要的原因让你要这麽做: 一个是你可以 mount 不同的档案系统以 <BR> 赋与不同的选项 (下面有几个例子)。别一个是,如果你想要把你的 filesystem export <BR> 出去, 你须要更加细微的控制。如果你是一个从 Linux 转入 FreeBSD 的使用者, 你会 <BR> 发现 Linux 是把任何东西都往 root partition "/" 塞, 而 FreeBSD 预设便要 "/", <BR> "/usr", 和 "/var"。这也使得要使用如 dump 般的工具较容易。且让我们来讨论 se- <BR> curity 吧! 有一件事我通常会做的是, 我会把一般 users 可以写入的 partition 分 <BR> 开来割, 而这些 partitons 便可以用 "nosuid" 的方式来 mount。从 mount 的 man <BR> page 可以知道: <BR> <BR> nosuid Do not allow set-user-identifier or set-group-identifier <BR> bits to take effect. Note: this option is worthless if a <BR> public available suid or sgid wrapper like suidperl is <BR> installed on your system. <BR> <BR> 让 suid 或 sgid bit 失效。又: 对於像 suidperl 这些公开使用 <BR> 的程式, 设这个选项便没用。 <BR> <BR> 因此你会有个 partition 给一般使用者使用: /home 或 /usr/home。然後你可以另外 <BR> 开个 partion 给 /var/tmp 然後再把你的 /tmp 指到这里: <BR> <BR># rm -rf /tmp <BR># ln -s /var/tmp /tmp <BR> <BR> 你可以叁考这个例子: <BR> <BR># cat /etc/fstab <BR># Device Mountpoint FStype Options Dump Pass# <BR>/dev/sd0s1b none swap sw 0 0 <BR>/dev/sd0s1a / ufs rw 1 1 <BR>/dev/sd0s1g /usr ufs rw 2 2 <BR>/dev/sd0s1h /usr/home ufs rw 2 2 <BR>/dev/sd0s1f /var ufs rw 2 2 <BR>/dev/sd0s1e /var/tmp ufs rw,nosuid 2 2 <BR>proc /proc procfs rw 0 0 <BR> <BR> 现在你可以确定一般 users 可以写入的目录不是以 "-nosuid" 的方式被 mount, 就是 <BR> 没有可以写入。现在你还要关心的就是 /var/spool/uucppublic"。 <BR> 你可以把 "/var" 以 "-nosuid" 的方式来 mount , 或下这个命令: <BR> <BR># chmod o-w /var/spool/uucppublic <BR> <BR> 如果你想要找出你所有的可写入目录, 下这个命令: <BR> <BR># find / -perm -0777 -type d -ls <BR> <BR> 如同 man page 指出的, 具有 suid/sgid 的程式会让你的 nosuid 失效。找出那些程 <BR> 式是 suid 或 sgid 的吧: <BR> <BR># find / -perm -2000 -ls <BR># find / -perm -4000 -ls <BR> <BR> 同时你不止可以用 "-ls" 而只是知道有那些程式。你可以把不是很有用的程式 "chmod <BR> 000"。像是 uustat, uucico 等, 如果你从来不碰 uucp 的话。或是 ppp 和 pppd, 如 <BR> 果你绝不会用到他们。又, 你不会去用到印表机的话, 把 lpr lprd 也 chmod 000 吧! <BR> 也许改天会有个人写个 shell script 来问你那些东西要 chmod 000 掉。 <BR> <BR> 现在你也许想问, 有什麽方式可以防止攻击者重新以非 "-nosuid" 的方式 mount 你的 <BR> filesystem ? Well, 没有, 除非你改变你的 securelevel。 <BR> <BR>o securelevel <BR> <BR> FreeBSD kernel 有个观念叫 securelevel。当还有人在争论这是不是够完美时,这个 <BR> 机制已经够防止大部份的 "script kiddiez"。Securelevel 是指你的 kernel 在执行时 <BR> 的安全等级。每一个等级具有不同的保护和检查机制。这些是 init(8) 的 man page: <BR> <BR> The kernel runs with four different levels of security. Any superuser <BR> process can raise the security level, but only init can lower it. The <BR> security levels are: <BR> Kernel 可以以四种不同的安全等级来执行。任何 superuser process 可以提高安全 <BR> 等级, 但是只有 init 可以降低它。这四种等级分别是: <BR> <BR> -1 Permanently insecure mode - always run the system in level 0 mode. <BR> 永远不安全模式 - 切换到 level 0 吧! <BR> <BR> 0 Insecure mode - immutable and append-only flags may be turned off. <BR> All devices may be read or written subject to their permissions. <BR> 不安全模式 - "不可更动"和"只能附加"这两个旗标(flag)可以被改变。所有的 <BR> devices 可以照着它们的读写权限被读写。 <BR> <BR> 1 Secure mode - the system immutable and system append-only flags may <BR> not be turned off; disks for mounted filesystems, /dev/mem, and <BR> /dev/kmem may not be opened for writing. <BR> 安全模式 - "不可更动"和"只能附加" 的旗标不能被取消; mount 上来的档案系 <BR> 统, /dev/mem, 和 /dev/kmem 不能写入。 <BR> <BR> 2 Highly secure mode - same as secure mode, plus disks may not be <BR> opened for writing (except by mount(2)) whether mounted or not. <BR> his level precludes tampering with filesystems by unmounting them, <BR> but also inhibits running newfs(8) while the system is multi-user. <BR> 高安全模式 - 和安全模式一样, 又多加了不管硬碟有没有被 mount 起来, <BR> 除了 mount(2) 之外都不能写入。它防止一个档案系统在 umount 的时候被 <BR> 搞乱。而且在这个等级也禁止在 multi-user 时执行 newfs(8)。 <BR> <BR> 如果安全等级最初是 -1, 那麽 init 就会保持原状。否则在 single user mode 时, <BR> init 会把安全等级调到 0, 而在 multiuser mode 时会以 1 来跑。如果你希望在 <BR> multiuser 模式是以等级 2 在跑, 你可以先进入 single user mode, 编辑 /etc/rc, <BR> 使用 sysctl 来更动。 <BR> <BR> 若是你的系统只拿来跑 web server 之类的, 你可以放心的将 securelevel调高到2。 <BR> 但若是你要跑 X server, 把你的 securelevel 调至 1 或更高会导致一些问题。因为 <BR> X server 必须要写入 /dev/mem 和 /dev/kmem, 而 securelevel 1 不允许你这麽做。 <BR> 有一个解决的方法是, 在启动 X server 後再调高 securelevel。但我的意见是, 如果 <BR> 你跑 X server 的话, 你已经有了其它的安全问题须要考量, 而不止是 securelevel。 <BR> 以下这个指令会显示出你目前的 securelevel 设定值。 <BR> <BR># sysctl kern.securelevel <BR> <BR> <BR> 如果要提高你的 securelevel: <BR># sysctl -w kern.securelevel=X <BR> X 可以是 0, 1 或 2。 <BR> <BR> 又在 securelevel 是 1 的话, 你在 "make world" 时也会有些问题。因为 "make <BR> install" 时会在 kernel 上加上 immutable flag: <BR> <BR># ls -lo /kernel <BR>-r-xr-xr-x 1 root wheel schg 1061679 Jun 30 01:27 /kernel <BR> <BR> "schg" flag 会防止你安装新的 kernel: <BR> <BR>nfr# id <BR>uid=0(root) gid=0(wheel) groups=0(wheel), 2(kmem) <BR> <BR>nfr# sysctl kern.securelevel <BR>kern.securelevel: 2 <BR> <BR>nfr# rm -rf /kernel <BR>rm: /kernel: Operation not permitted <BR> <BR>nfr# mv /kernel /tmp/ <BR>mv: rename /kernel to /tmp//kernel: Operation not permitted <BR> <BR> 如果你在 securelevel 1 或 2, 那麽 schg flag 是不能被改变的。 <BR> <BR># chflags noschg /kernel <BR>chflags: /kernel: Operation not permitted <BR> <BR> 值得留意的是, /boot.config 可以改变你开机时的系统设定,要预防有心人篡改 <BR> 你应该这麽做: <BR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -