Linux 安全组件比较和介绍。

Linux审计子系统(Linux Aduit Subsystem)
LAus可以用来监控文件访问和操作系统的一些情况,是linux为了通过evl-4级认证的一个完全策略。从下面的一个连接可以大体的推断其支持的 kernel和各发行版,http://www.securityfocus.com/bid/12309,尽管这是一个bug报告。

SELinux
SELinux 是 2.6 版本的 Linux 内核中提供的强制访问控制 (MAC)系统。对于目前可用的 Linux 安全模块来说,SELinux 是功能最全面,而且测试最充分的,它是在 20 年的 MAC 研究基础上建立的。SELinux 在类型强制服务器中合并了多级安全性或一种可选的多类策略,并采用了基于角色的访问控制概念。
参考连接:
SELinux实例:使用安全增强的Linux
从头开始生成 SELinux
揭开 SE Linux 的秘密:第 1部分
SELinux 中基于角色的访问控制
Gentoo SELinux Handbook

ACL
ACL是Access Control List的缩写,主要的目的是在提供传统的owner,group,others的read,write,execute权限之外的细部权限设定。 ACL可以针对单一使用者,单一档案或目录来进行r,w,x的权限规范,对于需要特殊权限的使用状况非常有帮助。 Grsecurity是其中比较典型和成熟的一种。
Grsecurity ACL系统
Linux 安全系列:用 grsecurity 保护 Linux

CHROOT
CHROOT就是Change Root,也就是改变程序执行时所参考的根目录位置。可以将程序限制在指定的目录之内。

iptables
Linux提供了一个非常优秀的防火墙工具—netfilter/iptables。它完全免费、功能强大、使用灵活、可以对流入和流出的信息进行细化控制,且可以在一台低配置机器上很好地运行。netfilter/iptabels应用程序,被认为是Linux中实现包过滤功能的第四代应用程序。netfilter/iptables包含在2.4以后的内核中,它可以实现防火墙、NAT(网络地址翻译)和数据包的分割等功能。 netfilter工作在内核内部,而iptables则是让用户定义规则集的表结构。netfilter/iptables从ipchains和 ipwadfm(IP防火墙管理)演化而来,功能更加强大。
参考资料:
iptables从入门到精通
Iptables 指南 1.1.19

Linux-PAM 的 limit
Linux-PAM 的 limit 也很有用,可以限制用户启动进程所占用的资源。(为用户级别的限制,不能为单个程序制定限制。)
配置文件在 /etc/security/limits.conf
参考资料:
Linux Shell命令ulimit的用法

Tripwire 或 AIDE(Advanced Intrusion Detection Environment)

AIDE即Advanced Intrusion Detection Environment,直译为高级入侵检测环境,AIDE,是一个文件完整性检测工具,AIDE 能够构造一个指定文件的数据库。

Tripwire 是目前最为著名的unix下文件系统完整性检查的软件工具,这一软件采用的技术核心就是对每个要监控的文件产生一个数字签名,保留下来。当文件现在的数字签名与保留的数字签名不一致时,那么现在这个文件必定被改动过了。

对了,各种虚拟技术也可以算上。
用户模式内核为了安全需要为主机内核打上补丁,不然虚拟机内的程序可以访问其他程序的内存。

Linux 安全:Linux 内核安全增强、系统安全及安全编程
让 Linux 更安全,第 1 部分:介绍
安全编程: 最小化特权
如何增强 Linux 系统的安全性,第一部分: Linux 安全模块(LSM)简介

Comments (4) »

linux 下的图形化分区管理工具 Gparted

比较好用,属于 gnome。
gentoo下的安装命令 sudo emerge gparted

No comment »

Linux下的fstab

Linux下的fstab

例子

# /etc/fstab: static file system information.
#
# <file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc defaults 0 0
# /dev/sda5
UUID=2b1686f1-bbd6-4991-8640-f6fc52c497eb / ext3 defaults,errors=remount-ro 0 1
# /dev/sda1
UUID=d7823e0c-8ad7-4596-977a-ea014899649a /boot ext2 defaults 0 2
# /dev/sda8
UUID=3dd51e75-e0ad-4a80-29f3-5cb518689d16 none swap sw 0 0

# source
# /dev/hda6
UUID=0985ae85-888f-46cd-8c72-e9e0362c5a04 /media/source reiserfs defaults 0 2

# home
# /dev/hda7
UUID=7a9503b2-0388-4b2b-8aa6-09a2458c76c3 /media/home reiserfs defaults 0 2

# bak
# /dev/hda9
UUID=bf1d472b-4f4c-4168-809c-4bdacd657ee6 /media/bak ext3 defaults 0 2

# windows
# /dev/hda2
# sudo mount -t vfat -o iocharset=utf8 /dev/sda2 /media/windows/ # OK
UUID=324B-1AE0 /media/windows vfat utf8,uid=1000,gid=1000 0 2

#install CD
#/media/source/feisty/ubuntu-7.04-alternate-i386.iso
/media/source/feisty/ubuntu-7.04-alternate-i386.iso /cdrom iso9660 ro,loop 0 0

#server1
#[email protected]:/ /media/server1 shfs noauto,user,uid=1000,gid=1000 0 0

#movie
//192.168.1.254/movie1 /media/movie1 smbfs username=Guest,password=,iocharset=utf8,codepage=cp936 0 0
//192.168.1.254/movie2 /media/movie2 smbfs username=Guest,password=,iocharset=utf8,codepage=cp936 0 0
//192.168.1.254/movie3 /media/movie3 smbfs username=Guest,password=,iocharset=utf8,codepage=cp936 0 0

UUID

UUID 可以用下面的命令找到

gamexg@gubuntu:~$ ls -l /dev/disk/by-uuid/
总用量 0
lrwxrwxrwx 1 root root 10 2007-08-01 20:40 0985ae85-888f-46cd-8c72-e9e0362c5a04 -> ../../sda6
lrwxrwxrwx 1 root root 10 2007-08-01 20:40 2b1686f1-bbd6-4991-8640-f6fc52c497eb -> ../../sda5
lrwxrwxrwx 1 root root 10 2007-08-01 20:48 324B-1AE0 -> ../../sda2
lrwxrwxrwx 1 root root 10 2007-08-01 20:40 3dd51e75-e0ad-4a80-29f3-5cb518689d16 -> ../../sda8
lrwxrwxrwx 1 root root 10 2007-08-01 20:40 7a9503b2-0388-4b2b-8aa6-09a2458c76c3 -> ../../sda7
lrwxrwxrwx 1 root root 10 2007-08-01 20:40 bf1d472b-4f4c-4168-809c-4bdacd657ee6 -> ../../sda9
lrwxrwxrwx 1 root root 10 2007-08-01 20:40 d7823e0c-8ad7-4596-977a-ea014899649a -> ../../sda1

标签(LABEL)

LABEL 卷标也可以使用。

LABEL=USB-FAT /media/USB-FAT vfat rw,user,utf8,auto,sync,umask=0 0 0
LABEL=USB-EXT3 /media/USB-EXT3 ext3 rw,user,auto,sync 0 0

mount 的类型

外部类型mount 类型注释
swapswap
ext2ext2
ext3ext3
reiserfsreiserfs
iso9660iso9660光盘镜像
sshshfs用户名用 用户名@ssh服务器地址的方式输入,密码使用密钥。
windows共享 或 smb共享smbfsusername=Guest,password=,iocharset=utf8,codepage=cp936
iocharset为本地编码,codepage为远程编码。

查看支持的文件系统

gamexg@gubuntu:~$ cat /proc/filesystems
nodev sysfs
nodev rootfs
nodev bdev
nodev proc
nodev cpuset
nodev debugfs
nodev securityfs
nodev sockfs
nodev pipefs
nodev futexfs
nodev tmpfs
nodev inotifyfs
nodev eventpollfs
nodev devpts
cramfs
nodev ramfs
nodev mqueue
nodev usbfs
ext3
nodev fuse
fuseblk
nodev fusectl
ext2
reiserfs
vfat
iso9660
nodev binfmt_misc
nodev smbfs

mount 的选项

选项说明
async使对这个设备的所有读写都异步进行(首先读写缓存而不直接写入设备),危险的
noasync对文件元数据的修改同步进行,对文件数据的读写异步进行。这是默认选项。
sync使对设备的所有读写都同步进行。
rw将设备挂载为可读写的,似乎是默认项。
ro将设备挂载为只读的。
noatime不自动修改设备中文件的访问时间戳(assecc time)。
noauto使用mount -a命令时,将跳过有这个选项的设备。因此,这个设备也不会在内核启动时自动挂载。
noexec避免执行设备中的二进制文件。这个选项在某些情况,例如一个为不同架构的系统提供网络文件系统的主机。但这个选项只能用来防范误操作,而不能提供安全性的保障。
user允许非root用户进行挂载。
owner允许设备拥有这进行挂载(linux专有)。
_netdev设备需要网络(linux专有)。
备份频率<dump>设置dump程序对设备进行备份的频率。默认为0,且设为0时不备份。
检查顺序<pass>设置fsck检查文件系统时的顺序。根文件系统应设为1以保证它最先被检查,其他设备可设为2或比2更大的数。默认为0,且设为0时设备不被检查。
uid某些特出的文件系统挂载后的所有者ID,这里好像只能使用数字ID。例:uid=1000,1000一般为第一个普通帐号的ID。
gid某些特出的文件系统挂载后的所有组ID,这里好像只能使用数字ID。例:uid=1000,1000一般为第一个普通组的ID。
umask用来设置某些特出文件系统挂载后的文件权限。umask使用的是补码。umask是将权限拿走。例:umask=000则不删除任何权限,所以任何人都有读写执行权限。
nls指定ntfs的编码。例:nls=utf8
iocharset本地操作系统的编码。例:iocharset=utf8
codepage远程文件系统的编码。例:codepage=cp936,cp936为微软的简体中文编码格式。gb2312是中国国家标准的简体中文编码。
utf8在vfat格式时 “utf8” = “iocharset=utf8”
loop将文件当作设备时使用的参数。

mount 命令

命令说明
mount -a自动挂载未挂载的/etc/fstab里的项。
mount -l列出以挂载的内容

mount 手工挂载的命令

sudo mount -t smbfs -o iocharset=utf8,codepage=cp936 //192.168.1.254/movie1 /media/movie1

No comment »

什么时候提供linux版就好了

No comment »

linux 下 l2tp 客户端配置

安装 l2tpd包

总配置文件
/etc/l2tpd/l2tpd.conf

;
; Sample l2tpd configuration file
;
; This example file should give you some idea of how the options for l2tpd
; should work. The best place to look for a list of all options is in
; the source code itself, until I have the time to write better documetation :)
; Specifically, the file “file.c” contains a list of commands at the end.
;
; You most definitely don’t have to spell out everything as it is done here
;
; [global] ; Global parameters:
; port = 1701 ; * Bind to port 1701
; auth file = /etc/l2tpd/l2tp-secrets ; * Where our challenge secrets are
; access control = yes ; * Refuse connections without IP match
; rand source = dev ; Source for entropy for random
; ; numbers, options are:
; ; dev – reads of /dev/urandom
; ; sys – uses rand()
; ; egd – reads from egd socket
; ; egd is not yet implemented
;
; [lns default] ; Our fallthrough LNS definition
; exclusive = no ; * Only permit one tunnel per host
; ip range = 192.168.0.1-192.168.0.20 ; * Allocate from this IP range
; no ip range = 192.168.0.3-192.168.0.9 ; * Except these hosts
; ip range = 192.168.0.5 ; * But this one is okay
; ip range = lac1-lac2 ; * And anything from lac1 to lac2’s IP
; lac = 192.168.1.4 – 192.168.1.8 ; * These can connect as LAC’s
; no lac = untrusted.marko.net ; * This guy can’t connect
; hidden bit = no ; * Use hidden AVP’s?
; local ip = 192.168.1.2 ; * Our local IP to use
; length bit = yes ; * Use length bit in payload?
; require chap = yes ; * Require CHAP auth. by peer
; refuse pap = yes ; * Refuse PAP authentication
; refuse chap = no ; * Refuse CHAP authentication
; refuse authentication = no ; * Refuse authentication altogether
; require authentication = yes ; * Require peer to authenticate
; unix authentication = no ; * Use /etc/passwd for auth.
; name = myhostname ; * Report this as our hostname
; ppp debug = no ; * Turn on PPP debugging
; pppoptfile = /etc/ppp/options.l2tpd.lns ; * ppp options file
; call rws = 10 ; * RWS for call (-1 is valid)
; tunnel rws = 4 ; * RWS for tunnel (must be > 0)
; flow bit = yes ; * Include sequence numbers
; challenge = yes ; * Challenge authenticate peer ;
;
; [lac marko] ; Example VPN LAC definition
; lns = lns.marko.net ; * Who is our LNS?
; lns = lns2.marko.net ; * A backup LNS (not yet used)
; redial = yes ; * Redial if disconnected?
; redial timeout = 15 ; * Wait n seconds between redials
; max redials = 5 ; * Give up after n consecutive failures
; hidden bit = yes ; * User hidden AVP’s?
; local ip = 192.168.1.1 ; * Force peer to use this IP for us
; remote ip = 192.168.1.2 ; * Force peer to use this as their IP
; length bit = no ; * Use length bit in payload?
; require pap = no ; * Require PAP auth. by peer
; require chap = yes ; * Require CHAP auth. by peer
; refuse pap = yes ; * Refuse PAP authentication
; refuse chap = no ; * Refuse CHAP authentication
; refuse authentication = no ; * Refuse authentication altogether
; require authentication = yes ; * Require peer to authenticate
; name = marko ; * Report this as our hostname
; ppp debug = no ; * Turn on PPP debugging
; pppoptfile = /etc/ppp/options.l2tpd.marko ; * ppp options file for this lac
; call rws = 10 ; * RWS for call (-1 is valid)
; tunnel rws = 4 ; * RWS for tunnel (must be > 0)
; flow bit = yes ; * Include sequence numbers
; challenge = yes ; * Challenge authenticate peer
;
; [lac cisco] ; Another quick LAC
; lns = cisco.marko.net ; * Required, but can take from default
; require authentication = yes

;拷贝了一份 lac marko 并改名为 lac xd
;注意:xd 为名称,拨号和断线时根据这个名来区分连接
[lac xd] ; Example VPN LAC definition
lns = ?.?.?.? ; * Who is our LNS? 服务器地址
lns = ?.?.?.? ; * A backup LNS (not yet used) 备份服务器地址
redial = yes ; * Redial if disconnected? 重播
redial timeout = 15 ; * Wait n seconds between redials
; max redials = 5 ; * Give up after n consecutive failures
; hidden bit = yes ; * User hidden AVP’s?
; local ip = 192.168.1.1 ; * Force peer to use this IP for us
; remote ip = 192.168.1.2 ; * Force peer to use this as their IP
; length bit = no ; * Use length bit in payload?
; require pap = no ; * Require PAP auth. by peer
; require chap = yes ; * Require CHAP auth. by peer
; refuse pap = yes ; * Refuse PAP authentication
; refuse chap = no ; * Refuse CHAP authentication
; refuse authentication = no ; * Refuse authentication altogether
; require authentication = yes ; * Require peer to authenticate
name = gh ; * Report this as our hostname
; ppp debug = no ; * Turn on PPP debugging
pppoptfile = /etc/ppp/options.l2tpd.xd ; * ppp options file for this lac ppp选项文件
; call rws = 10 ; * RWS for call (-1 is valid)
; tunnel rws = 4 ; * RWS for tunnel (must be > 0)
; flow bit = yes ; * Include sequence numbers
; challenge = yes ; * Challenge authenticate peer

ppp 选项文件
自己建立的

/etc/ppp/options.l2tpd.xd

ipcp-accept-local
ipcp-accept-remote
noccp
noauth
defaultroute
lock
proxyarp
usepeerdns
connect-delay 5000

帐号密码文件
/etc/ppp/options.l2tpd.xd

# Secrets for authentication using CHAP
# client server secret IP addresses

帐号 * 密码 *

拨号命令

echo ‘c xd’ > /var/run/l2tp-control

断线命令

echo ‘d xd’ > /var/run/l2tp-control

增加路由信息

route add -net 172.2.2.0 netmask 255.255.255.0 dev ppp0
route add -net 192.168.0.0 netmask 255.255.255.0 dev ppp0

删除路由的命令

route del -net 172.2.2.0
route del -net 172.2.2.0 netmask 255.255.255.0 dev ppp0
route del -net 192.168.0.0 netmask 255.255.255.0 dev ppp0

No comment »