securityの最近のブログ記事

IPTABLE

| | コメント(0) | トラックバック(0)

久々にIPTABLEの設定を見直すことにしたので,現在の設定をまず確認。

 

[root@desktop conf]#  service iptables status
テーブル: filter
Chain INPUT (policy DROP)
num  target     prot opt source               destination
1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
2    ACCEPT     icmp --  0.0.0.0/0            192.168.11.5        icmp type 8
3    ACCEPT     icmp --  0.0.0.0/0            192.168.11.5        icmp type 0
4    ACCEPT     tcp  --  192.168.11.0/24      192.168.11.5        tcp dpt:22
5    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:80
6    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:443
7    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
8    LOGGING    all  --  0.0.0.0/0            0.0.0.0/0

Chain FORWARD (policy DROP)
num  target     prot opt source               destination

Chain OUTPUT (policy DROP)
num  target     prot opt source               destination
1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
2    ACCEPT     icmp --  192.168.11.5         0.0.0.0/0           icmp type 0
3    ACCEPT     icmp --  192.168.11.5         0.0.0.0/0           icmp type 8
4    ACCEPT     tcp  --  192.168.11.5         192.168.11.0/24     tcp spt:22
5    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp spt:80
6    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp spt:443
7    LOGGING    all  --  0.0.0.0/0            0.0.0.0/0

Chain LOGGING (2 references)
num  target     prot opt source               destination
1    LOG        all  --  0.0.0.0/0            0.0.0.0/0           limit: avg 3/hour burst 5 LOG flags 0 level 4 prefix `DROP:'
2    DROP       all  --  0.0.0.0/0            0.0.0.0/0

[root@desktop conf]#

 

[root@desktop conf]# iptables -v -L INPUT
Chain INPUT (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
    8   560 ACCEPT     all  --  lo     any     anywhere             anywhere
    0     0 ACCEPT     icmp --  eth0   any     anywhere             desktop.localdomain icmp echo-request
    0     0 ACCEPT     icmp --  eth0   any     anywhere             desktop.localdomain icmp echo-reply
 1062 71555 ACCEPT     tcp  --  eth0   any     192.168.11.0/24      desktop.localdomain tcp dpt:ssh
    0     0 ACCEPT     tcp  --  any    any     anywhere             anywhere            tcp dpt:http
    0     0 ACCEPT     tcp  --  any    any     anywhere             anywhere            tcp dpt:https
    0     0 ACCEPT     all  --  any    any     anywhere             anywhere            state RELATED,ESTABLISHED
   15  2088 LOGGING    all  --  any    any     anywhere             anywhere

[root@desktop conf]# iptables -v -L OUTPUT
Chain OUTPUT (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
    8   560 ACCEPT     all  --  any    lo      anywhere             anywhere
    0     0 ACCEPT     icmp --  any    eth0    desktop.localdomain  anywhere            icmp echo-reply
    0     0 ACCEPT     icmp --  any    eth0    desktop.localdomain  anywhere            icmp echo-request
 1144  149K ACCEPT     tcp  --  any    eth0    desktop.localdomain  192.168.11.0/24     tcp spt:ssh
    0     0 ACCEPT     tcp  --  any    any     anywhere             anywhere            tcp spt:http
    0     0 ACCEPT     tcp  --  any    any     anywhere             anywhere            tcp spt:https
   86  7988 LOGGING    all  --  any    any     anywhere             anywhere
[root@desktop conf]#


[root@desktop conf]# /sbin/iptables -L
Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere
ACCEPT     icmp --  anywhere             desktop.localdomain icmp echo-request
ACCEPT     icmp --  anywhere             desktop.localdomain icmp echo-reply
ACCEPT     tcp  --  192.168.11.0/24      desktop.localdomain tcp dpt:ssh
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:http
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:https
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED
LOGGING    all  --  anywhere             anywhere

Chain FORWARD (policy DROP)
target     prot opt source               destination

Chain OUTPUT (policy DROP)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere
ACCEPT     icmp --  desktop.localdomain  anywhere            icmp echo-reply
ACCEPT     icmp --  desktop.localdomain  anywhere            icmp echo-request
ACCEPT     tcp  --  desktop.localdomain  192.168.11.0/24     tcp spt:ssh
ACCEPT     tcp  --  anywhere             anywhere            tcp spt:http
ACCEPT     tcp  --  anywhere             anywhere            tcp spt:https
LOGGING    all  --  anywhere             anywhere

Chain LOGGING (2 references)
target     prot opt source               destination
LOG        all  --  anywhere             anywhere            limit: avg 3/hour burst 5 LOG level warning prefix `DROP:'
DROP       all  --  anywhere             anywhere

[root@desktop conf]# /sbin/iptables -L -v
Chain INPUT (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
    8   560 ACCEPT     all  --  lo     any     anywhere             anywhere
    0     0 ACCEPT     icmp --  eth0   any     anywhere             desktop.localdomain icmp echo-request
    0     0 ACCEPT     icmp --  eth0   any     anywhere             desktop.localdomain icmp echo-reply
 1137 76219 ACCEPT     tcp  --  eth0   any     192.168.11.0/24      desktop.localdomain tcp dpt:ssh
    0     0 ACCEPT     tcp  --  any    any     anywhere             anywhere            tcp dpt:http
    0     0 ACCEPT     tcp  --  any    any     anywhere             anywhere            tcp dpt:https
    0     0 ACCEPT     all  --  any    any     anywhere             anywhere            state RELATED,ESTABLISHED
   15  2088 LOGGING    all  --  any    any     anywhere             anywhere

Chain FORWARD (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
    8   560 ACCEPT     all  --  any    lo      anywhere             anywhere
    0     0 ACCEPT     icmp --  any    eth0    desktop.localdomain  anywhere            icmp echo-reply
    0     0 ACCEPT     icmp --  any    eth0    desktop.localdomain  anywhere            icmp echo-request
 1205  157K ACCEPT     tcp  --  any    eth0    desktop.localdomain  192.168.11.0/24     tcp spt:ssh
    0     0 ACCEPT     tcp  --  any    any     anywhere             anywhere            tcp spt:http
    0     0 ACCEPT     tcp  --  any    any     anywhere             anywhere            tcp spt:https
   98  8840 LOGGING    all  --  any    any     anywhere             anywhere

Chain LOGGING (2 references)
 pkts bytes target     prot opt in     out     source               destination
    6   673 LOG        all  --  any    any     anywhere             anywhere            limit: avg 3/hour burst 5 LOG level warning prefix `DROP:'
  113 10928 DROP       all  --  any    any     anywhere             anywhere
[root@desktop conf]#

[root@desktop conf]# /sbin/iptables -nvxL
Chain INPUT (policy DROP 0 packets, 0 bytes)
    pkts      bytes target     prot opt in     out     source               destination
       8      560 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0
       0        0 ACCEPT     icmp --  eth0   *       0.0.0.0/0            192.168.11.5        icmp type 8
       0        0 ACCEPT     icmp --  eth0   *       0.0.0.0/0            192.168.11.5        icmp type 0
    1230    82035 ACCEPT     tcp  --  eth0   *       192.168.11.0/24      192.168.11.5        tcp dpt:22
       0        0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:80
       0        0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:443
       0        0 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
      15     2088 LOGGING    all  --  *      *       0.0.0.0/0            0.0.0.0/0

Chain FORWARD (policy DROP 0 packets, 0 bytes)
    pkts      bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy DROP 0 packets, 0 bytes)
    pkts      bytes target     prot opt in     out     source               destination
       8      560 ACCEPT     all  --  *      lo      0.0.0.0/0            0.0.0.0/0
       0        0 ACCEPT     icmp --  *      eth0    192.168.11.5         0.0.0.0/0           icmp type 0
       0        0 ACCEPT     icmp --  *      eth0    192.168.11.5         0.0.0.0/0           icmp type 8
    1318   172832 ACCEPT     tcp  --  *      eth0    192.168.11.5         192.168.11.0/24     tcp spt:22
       0        0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp spt:80
       0        0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp spt:443
     106     9408 LOGGING    all  --  *      *       0.0.0.0/0            0.0.0.0/0

Chain LOGGING (2 references)
    pkts      bytes target     prot opt in     out     source               destination
       6      673 LOG        all  --  *      *       0.0.0.0/0            0.0.0.0/0           limit: avg 3/hour burst 5 LOG flags 0 level 4 prefix `DROP:'
     121    11496 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0
[root@desktop conf]#

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

IPテーブルの再設定

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

「メモ:スクリプト作成用」

[root@desktop conf]# myhost=`ifconfig eth0 | grep "inet addr" | awk '{print $2}' | sed 's/addr://'`
[root@desktop conf]# echo $myhost
192.168.11.5
[root@desktop conf]#

[root@desktop conf]# bcast=`ifconfig eth0 | grep "inet addr" | awk '{print $3}' | sed 's/Bcast://'`
[root@desktop conf]# echo $bcast
192.168.11.255
[root@desktop conf]#

[root@desktop conf]# mask=`ifconfig eth0 | grep "inet addr" | awk '{print $4}' | sed 's/Mask://'`
[root@desktop conf]# echo $mask
255.255.255.0
[root@desktop conf]#

 

① 既存の設定を初期化して,削除。(SAVEはしない)

[root@desktop ~]# /sbin/iptables -L
Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere
ACCEPT     icmp --  anywhere             desktop.localdomain icmp echo-request
ACCEPT     icmp --  anywhere             desktop.localdomain icmp echo-reply
ACCEPT     tcp  --  192.168.11.0/24      desktop.localdomain tcp dpt:ssh
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:http
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:https
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED
LOGGING    all  --  anywhere             anywhere

Chain FORWARD (policy DROP)
target     prot opt source               destination

Chain OUTPUT (policy DROP)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere
ACCEPT     icmp --  desktop.localdomain  anywhere            icmp echo-reply
ACCEPT     icmp --  desktop.localdomain  anywhere            icmp echo-request
ACCEPT     tcp  --  desktop.localdomain  192.168.11.0/24     tcp spt:ssh
ACCEPT     tcp  --  anywhere             anywhere            tcp spt:http
ACCEPT     tcp  --  anywhere             anywhere            tcp spt:https
LOGGING    all  --  anywhere             anywhere

Chain LOGGING (2 references)
target     prot opt source               destination
LOG        all  --  anywhere             anywhere            limit: avg 3/hour burst 5 LOG level warning prefix `DROP:'
DROP       all  --  anywhere             anywhere
[root@desktop ~]# /sbin/iptables -P INPUT ACCEPT
[root@desktop ~]# /sbin/iptables -P FORWARD DROP
[root@desktop ~]# /sbin/iptables -P OUTPUT ACCEPT
[root@desktop ~]# /sbin/iptables -F
[root@desktop ~]# /sbin/iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy DROP)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Chain LOGGING (0 references)
target     prot opt source               destination
[root@desktop ~]#

②INPUT基本設定

[root@desktop ~]# /sbin/iptables -A INPUT -i lo -j ACCEPT
[root@desktop ~]# /sbin/iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere

Chain FORWARD (policy DROP)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Chain LOGGING (0 references)
target     prot opt source               destination
[root@desktop ~]#

③INPUT詳細設定と確認

[root@desktop ~]# /sbin/iptables -A INPUT -i eth0 -p icmp -j ACCEPT
[root@desktop ~]# /sbin/iptables -A INPUT -i eth0 -p tcp --dport 22 -j ACCEPT
[root@desktop ~]# /sbin/iptables -A INPUT -i eth0 -p tcp --dport 80 -j ACCEPT
[root@desktop ~]# /sbin/iptables -A INPUT -i eth0 -s 192.168.11.0/24 -p all -j ACCEPT
[root@desktop ~]# /sbin/iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
[root@desktop ~]# /sbin/iptables -P INPUT DROP
[root@desktop ~]# /sbin/iptables -L
Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere
ACCEPT     icmp --  anywhere             anywhere
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ssh
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:http
ACCEPT     all  --  192.168.11.0/24      anywhere
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED

Chain FORWARD (policy DROP)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Chain LOGGING (0 references)
target     prot opt source               destination
[root@desktop ~]#

 

④OUTPUT詳細設定と確認

 

[root@desktop ~]# /sbin/iptables -A OUTPUT -o lo -j ACCEPT
[root@desktop ~]# /sbin/iptables -L
Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere
ACCEPT     icmp --  anywhere             anywhere
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ssh
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:http
ACCEPT     all  --  192.168.11.0/24      anywhere
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED

Chain FORWARD (policy DROP)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere

Chain LOGGING (0 references)
target     prot opt source               destination
[root@desktop ~]# /sbin/iptables -A OUTPUT -o eth0 -p icmp -j ACCEPT
[root@desktop ~]# /sbin/iptables -A OUTPUT -o eth0 -p tcp --dport 22 -j ACCEPT
[root@desktop ~]# /sbin/iptables -A OUTPUT -o eth0 -p tcp --dport 80 -j ACCEPT
[root@desktop ~]# /sbin/iptables -A OUTPUT -o eth0 -s 192.168.11.0/24 -p all -j ACCEPT
[root@desktop ~]# /sbin/iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
[root@desktop ~]# /sbin/iptables -P OUTPUT DROP
[root@desktop ~]# /sbin/iptables -L
Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere
ACCEPT     icmp --  anywhere             anywhere
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ssh
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:http
ACCEPT     all  --  192.168.11.0/24      anywhere
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED

Chain FORWARD (policy DROP)
target     prot opt source               destination

Chain OUTPUT (policy DROP)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere
ACCEPT     icmp --  anywhere             anywhere
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ssh
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:http
ACCEPT     all  --  192.168.11.0/24      anywhere
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED

Chain LOGGING (0 references)
target     prot opt source               destination
[root@desktop ~]#

⑤設定の確認と保存

[root@desktop ~]# /sbin/iptables -L
Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere
ACCEPT     icmp --  anywhere             anywhere
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ssh
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:http
ACCEPT     all  --  192.168.11.0/24      anywhere
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED

Chain FORWARD (policy DROP)
target     prot opt source               destination

Chain OUTPUT (policy DROP)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere
ACCEPT     icmp --  anywhere             anywhere
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ssh
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:http
ACCEPT     all  --  192.168.11.0/24      anywhere
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED

Chain LOGGING (0 references)
target     prot opt source               destination
[root@desktop ~]#

[root@desktop ~]# /etc/init.d/iptables save
ファイアウォールのルールを /etc/sysconfig/iptables に保存中[  OK  ]
[root@desktop ~]# /etc/init.d/iptables restart
ファイアウォールルールを適用中:                            [  OK  ]
チェインポリシーを ACCEPT に設定中filter                   [  OK  ]
iptables モジュールを取り外し中                            [  OK  ]
iptables ファイアウォールルールを適用中:                   [  OK  ]
iptables モジュールを読み込み中ip_conntrack_netbios_ns     [  OK  ]
[root@desktop ~]# /sbin/iptables -L
Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere
ACCEPT     icmp --  anywhere             anywhere
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ssh
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:http
ACCEPT     all  --  192.168.11.0/24      anywhere
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED

Chain FORWARD (policy DROP)
target     prot opt source               destination

Chain OUTPUT (policy DROP)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere
ACCEPT     icmp --  anywhere             anywhere
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ssh
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:http
ACCEPT     all  --  192.168.11.0/24      anywhere
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED

Chain LOGGING (0 references)
target     prot opt source               destination
[root@desktop ~]#

 

※ /etc/hosts.allow & /etc/hosts.denyも利用しているので上記の設定でもSSHも特定のセグメントのみしか

 利用出来ないようにしている。

/sbin/iptables -A INPUT -i eth0 -s 192.168.11.0/24 -p all -j ACCEPT に関しては,よりセキュアにするには

外して良いかと考えている。

ユーザープロファイル管理

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
パスワードに有効期限を設定
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━


[root@localhost ~]# chage
Usage: chage [options] user

Options:
  -d, --lastday LAST_DAY        set last password change to LAST_DAY
  -E, --expiredate EXPIRE_DATE  set account expiration date to EXPIRE_DATE
  -h, --help                    display this help message and exit
  -I, --inactive INACTIVE       set password inactive after expiration
                                to INACTIVE
  -l, --list                    show account aging information
  -m, --mindays MIN_DAYS        set minimum number of days before password
                                change to MIN_DAYS
  -M, --maxdays MAX_DAYS        set maximim number of days before password
                                change to MAX_DAYS
  -W, --warndays WARN_DAYS      set expiration warning days to WARN_DAYS

[root@localhost ~]#

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
アカウントの確認
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

[root@localhost ~]# chage -l admin
Last password change                                    : 10月 04, 2007
Password expires                                        : never
Password inactive                                       : never
Account expires                                         : never
Minimum number of days between password change          : 0
Maximum number of days between password change          : 99999
Number of days of warning before password expires       : 7
[root@localhost ~]#

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
↑のアカウントはディフォルトのままなので,設定を変更する
パスワード変更には最低1日
パスワード有効期限90日
パスワードが切れる30日前から警告が出る
パスワードが切れると7日間待ってアカウントロック
アカウント無効化の日は2010年4月1日に設定
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

[root@localhost ~]# chage -m 1 -M 90 -W 30 -I 7 -E 2010-04-01 admin
[root@localhost ~]# chage -l admin
Last password change                                    : 10月 04, 2007
Password expires                                        :  1月 02, 2008
Password inactive                                       :  1月 09, 2008
Account expires                                         :  4月 01, 2010
Minimum number of days between password change          : 1
Maximum number of days between password change          : 90
Number of days of warning before password expires       : 30
[root@localhost ~]#


[root@localhost ~]# cat /etc/shadow | grep admin
admin:$1$FssAdbea$.hYb8/RSdjmqZ4yDuFcAd1:13790:1:90:30:7:14700:
administrator:!!:13835:0:99999:7:::
[root@localhost ~]#
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
パスワード変更
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
[root@localhost ~]# chage -l admin
Last password change                                    : 12月 30, 2007
Password expires                                        :  3月 29, 2008
Password inactive                                       :  4月 05, 2008
Account expires                                         :  4月 01, 2010
Minimum number of days between password change          : 1
Maximum number of days between password change          : 90
Number of days of warning before password expires       : 30
[root@localhost ~]#


※ 一般ユーザーのログインを禁止する設定
/etc/nologinファイルを作成しておく。 (touch /etc/nologin)

※ usermod -s /bin/false ユーザー名 (特定ユーザーのログイン禁止)
※ /etc/passwdファイルを直接編集でも可

ユーザーのリソース利用制限をulimitにて変更できます。
[root@localhost ~]# ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
max nice                        (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 5119
max locked memory       (kbytes, -l) 32
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
max rt priority                 (-r) 0
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 5119
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited
[root@localhost ~]#

SUID

| | コメント(0) | トラックバック(0)

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

suid(set user id)やsgidが設定された実行ファイルを実行すると,そのプログラムは実行ファイルの所有ユーザ

または所有グループの権限で動作します。なのでスーパーユーザーが所有者であるプログラムにSUIDを設定

すると,ユーザーが実行した場合でもそのプログラムはスーパーユーザー権限で動作します。

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

[root@localhost ~]# find  / -perm -u+s -exec ls -la '{}' ';'
-rwsr-xr-x 1 root root 55016  3月 15  2007 /sbin/mount.nfs4
-rwsr-xr-x 1 root root 12280  3月 15  2007 /sbin/pam_timestamp_check
-rwsr-xr-x 1 root root 55012  3月 15  2007 /sbin/mount.nfs
-rwsr-xr-x 1 root root 20796  3月 15  2007 /sbin/unix_chkpwd
-rwsr-xr-x 1 root root 55016  3月 15  2007 /sbin/umount.nfs4
-rwsr-xr-x 1 root root 55016  3月 15  2007 /sbin/umount.nfs
--wS--xr-x 1 root root 0 10月  5 04:59 /media/.hal-mtab-lock
-rwsr-xr-x 1 root root 31244  3月 15  2007 /bin/ping6
-rwsr-xr-x 1 root root 57588  3月 15  2007 /bin/mount
-rwsr-xr-x 1 root root 38552  3月 15  2007 /bin/umount
-rwsr-xr-x 1 root root 24060  3月 22  2007 /bin/su
-rwsr-xr-x 1 root root 35864  3月 15  2007 /bin/ping
-rwsr-xr-x 1 root root 6808  3月 22  2007 /usr/sbin/usernetctl
-rws--x--x 1 root root 34824  3月 15  2007 /usr/sbin/userhelper
-rwsr-xr-x 1 root root 6240  1月  6  2007 /usr/sbin/ccreds_validate
-rwsr-xr-x 1 root root 172200  3月 22  2007 /usr/libexec/openssh/ssh-keysign
-rwsr-xr-x 1 root root 144537  3月 15  2007 /usr/kerberos/bin/ksu
-rwsr-xr-x 1 root root 18544  3月 15  2007 /usr/bin/rcp
-rws--x--x 1 root root 17900  3月 15  2007 /usr/bin/chfn
-rwsr-xr-x 1 root root 13108  3月 15  2007 /usr/bin/rlogin
-rws--x--x 1 root root 70892  1月 10  2007 /usr/bin/sperl5.8.8
-rwsr-xr-x 1 root root 46748  3月 15  2007 /usr/bin/chage
---s--x--x 2 root root 159096  1月  7  2007 /usr/bin/sudoedit
-rws--x--x 1 root root 1820868  3月 15  2007 /usr/bin/Xorg
-rwsr-xr-x 1 root root 8876  3月 15  2007 /usr/bin/rsh
-rwsr-sr-x 1 root root 311288  3月 15  2007 /usr/bin/crontab
-rwsr-xr-x 1 root root 47352  3月 15  2007 /usr/bin/gpasswd
-rwsr-xr-x 1 root root 43976  1月  6  2007 /usr/bin/at
-rws--x--x 1 root root 19064  3月 15  2007 /usr/bin/chsh
---s--x--x 2 root root 159096  1月  7  2007 /usr/bin/sudo
-rwsr-xr-x 1 root root 24556  3月 15  2007 /usr/bin/newgrp
-rwsr-xr-x 1 root root 22984  1月  7  2007 /usr/bin/passwd
[root@localhost ~]#

「chmod u+s」 コマンドや「chmod 4755」 コマンドにてコマンドにsuidを付与する事が出来ます。

 

 

iptables

| | コメント(0) | トラックバック(0)

[root@localhost ~]# /sbin/iptables -[AD] チェイン ルール
[root@localhost ~]# /sbin/iptables -P チェイン ターゲット
[root@localhost ~]# /sbin/iptables -L チェイン


オプション,チェイン,ターゲット,ルール
━━━━━━━━━━━━━━━━━━━━━━━
オプション  概要
━━━━━━━━━━━━━━━━━━━━━━━
-A <チェイン> チェインの最後にルールを追加
-D <チェイン> チェインからルールを削除する
-P <チェイン> <ターゲット> チェインのポリシーを変更する
-L <チェイン> ルールのリストを表示

━━━━━━━━━━━━━━━━━━━━━━━
チェイン      設定
━━━━━━━━━━━━━━━━━━━━━━━
INPUT  入力パケット
OUTPUT   出力パケット
FORWARD         転送パケット

━━━━━━━━━━━━━━━━━━━━━━━
ターゲット     設定
━━━━━━━━━━━━━━━━━━━━━━━
ACCEPT  許可
DROP  破棄
REJECT  拒否(送信元に通知)

━━━━━━━━━━━━━━━━━━━━━━━
ターゲット     設定
━━━━━━━━━━━━━━━━━━━━━━━
-s <送信元>     送信元のIPアドレスを指定
-d <送信先> 送信先のIPアドレスを指定
--support <ポート番号> 送信元のポート番号指定
--drop    <ポート番号> 送信先のポート番号指定
-j <ターゲット> ターゲットを指定
-p <プロトコル> プロトコルを指定
-i <インターフェース> インターフェースを指定(eth0,eth1,ppp0など)


『設定の確認』
[root@localhost ~]# /sbin/iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

[root@localhost ~]# /sbin/iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
[root@localhost ~]#


iptables0.jpg

 

 

 

 

 

 

 

 

 

まずは,SSHにてアクセスを許可させる設定をしてみる。

※ リモートから設定はアクセス出来なくなる可能性があるので注意(今回はシェルにしてリモートから対応してみた)

[root@localhost ~]# cat iptable_config_base.sh
#! /bin/sh

#すべてのiptables設定を削除#
/sbin/iptables -F
/sbin/iptables -X

#すべてのパケットを拒否#

/sbin/iptables -P INPUT DROP
/sbin/iptables -P OUTPUT DROP
/sbin/iptables -P FORWARD DROP

#ループバックアドレスからのパケットを全て許可#
/sbin/iptables -A INPUT -i lo -j ACCEPT
/sbin/iptables -A OUTPUT -o lo -j ACCEPT

#ICMP許可 全て->自分#
/sbin/iptables -A INPUT -p icmp --icmp-type echo-request -s 0.0.0.0/0 -d 192.168.11.5 -i eth0 -j ACCEPT
/sbin/iptables -A OUTPUT -p icmp --icmp-type echo-reply  -s 192.168.11.5 -d 0.0.0.0/0 -o eth0 -j ACCEPT

#ICMP許可 自分->全て#
/sbin/iptables -A OUTPUT -p icmp --icmp-type echo-request -s 192.168.11.5 -d 0.0.0.0/0 -o eth0 -j ACCEPT
/sbin/iptables -A INPUT -p icmp --icmp-type echo-reply -s 0.0.0.0/0 -d 192.168.11.5 -i eth0 -j ACCEPT

#sshパケットの許可 自分のセグメント->自分
/sbin/iptables -A INPUT -p tcp -s 192.168.11.0/24 -d 192.168.11.5 --dport 22 -i eth0 -j ACCEPT
/sbin/iptables -A OUTPUT -p tcp -s 192.168.11.5 --sport 22 -d 192.168.11.0/24 -o eth0 -j ACCEPT

#loggingの設定#
/sbin/iptables -N LOGGING
/sbin/iptables -A LOGGING -j LOG --log-level warning --log-prefix "DROP:" -m limit
/sbin/iptables -A LOGGING -j DROP
/sbin/iptables -A INPUT -j LOGGING
/sbin/iptables -A OUTPUT -j LOGGING

 

※SSHもICMPも接続可能Apache(Port80)は接続出来なくなってました。

iptables1.jpg

 

━━━━━━━━スクリプトの編集(Apache追加)━━━━━━━━━━━━

Apacheの接続を最後に設定に追加して,保存して終了。(またリモートからの作業なので,シェルスクリプトの編集)

[root@localhost ~]# cat iptable_config_base.sh
#! /bin/sh

#すべてのiptables設定を削除
/sbin/iptables -F
/sbin/iptables -X

#すべてのパケットを拒否

/sbin/iptables -P INPUT DROP
/sbin/iptables -P OUTPUT DROP
/sbin/iptables -P FORWARD DROP

#ループバックアドレスからのパケットを全て許可
/sbin/iptables -A INPUT -i lo -j ACCEPT
/sbin/iptables -A OUTPUT -o lo -j ACCEPT

#ICMPパケットの許可 (方向)trusthost->myhost
/sbin/iptables -A INPUT -p icmp --icmp-type echo-request -s 0.0.0.0/0 -d 192.168.11.5 -i eth0 -j ACCEPT
/sbin/iptables -A OUTPUT -p icmp --icmp-type echo-reply  -s 192.168.11.5 -d 0.0.0.0/0 -o eth0 -j ACCEPT

#ICMPの許可 (方向)myhost->trusthost
/sbin/iptables -A OUTPUT -p icmp --icmp-type echo-request -s 192.168.11.5 -d 0.0.0.0/0 -o eth0 -j ACCEPT
/sbin/iptables -A INPUT -p icmp --icmp-type echo-reply -s 0.0.0.0/0 -d 192.168.11.5 -i eth0 -j ACCEPT

#sshパケットの許可 (方向)trusthost-> myhost
/sbin/iptables -A INPUT -p tcp -s 192.168.11.0/24 -d 192.168.11.5 --dport 22 -i eth0 -j ACCEPT
/sbin/iptables -A OUTPUT -p tcp -s 192.168.11.5 --sport 22 -d 192.168.11.0/24 -o eth0 -j ACCEPT

# HTTP 80,443 許可#
/sbin/iptables -A INPUT -p tcp --dport 80 -j ACCEPT
/sbin/iptables -A INPUT -p tcp --dport 443 -j ACCEPT
/sbin/iptables -A OUTPUT -p tcp --sport 80 -j ACCEPT
/sbin/iptables -A OUTPUT -p tcp --sport 443 -j ACCEPT

# 内部から行ったアクセスに対する外部からの返答アクセスを許可#
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

#loggingの設定#
/sbin/iptables -N LOGGING
/sbin/iptables -A LOGGING -j LOG --log-level warning --log-prefix "DROP:" -m limit
/sbin/iptables -A LOGGING -j DROP
/sbin/iptables -A INPUT -j LOGGING
/sbin/iptables -A OUTPUT -j LOGGING

[root@localhost ~]#

━━━━━━━━保存と再起動━━━━━━━━━━━━

[root@localhost ~]# /etc/rc.d/init.d/iptables save
ファイアウォールのルールを /etc/sysconfig/iptables に保存中[  OK  ]
[root@localhost ~]# /etc/init.d/iptables restart
ファイアウォールルールを適用中:                            [  OK  ]
チェインポリシーを ACCEPT に設定中filter                   [  OK  ]
iptables モジュールを取り外し中                            [  OK  ]
iptables ファイアウォールルールを適用中:                   [  OK  ]
iptables モジュールを読み込み中ip_conntrack_netbios_ns     [  OK  ]
[root@localhost ~]#

 

iptables2.jpg

mod_security2

| | コメント(0) | トラックバック(0)

 

⑴ Source Fileのダウンロード

wget http://www.modsecurity.org/download/modsecurity-apache_2.1.4.tar.gz

⑵ インストール

make
make install

⑶ ルールファイルを読み込むために,httpd.confの変更

 

⑷ 設定完了したら,Apacheの再起動してみる。(設定ファイルは以下のような感じ)

設定ファイル例

 

※ mod_unique_idがApacheにロードされて無い場合は,予め追加しておく必要があるようです。

[root@localhost metadata]# /usr/local/apache2/bin/apxs -cia mod_unique_id.c
/usr/local/apache2/build/libtool --silent --mode=compile gcc -prefer-pic   -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE -g -O2 -pthread -I/usr/local/apache2/include  -I/usr/local/apache2/include   -I/usr/local/apache2/include   -c -o mod_unique_id.lo mod_unique_id.c && touch mod_unique_id.slo
/usr/local/apache2/build/libtool --silent --mode=link gcc -o mod_unique_id.la  -rpath /usr/local/apache2/modules -module -avoid-version    mod_unique_id.lo
/usr/local/apache2/build/instdso.sh SH_LIBTOOL='/usr/local/apache2/build/libtool' mod_unique_id.la /usr/local/apache2/modules
/usr/local/apache2/build/libtool --mode=install cp mod_unique_id.la /usr/local/apache2/modules/
cp .libs/mod_unique_id.so /usr/local/apache2/modules/mod_unique_id.so
cp .libs/mod_unique_id.lai /usr/local/apache2/modules/mod_unique_id.la
cp .libs/mod_unique_id.a /usr/local/apache2/modules/mod_unique_id.a
chmod 644 /usr/local/apache2/modules/mod_unique_id.a
ranlib /usr/local/apache2/modules/mod_unique_id.a
PATH="$PATH:/sbin" ldconfig -n /usr/local/apache2/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/apache2/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
chmod 755 /usr/local/apache2/modules/mod_unique_id.so
[activating module `unique_id' in /usr/local/apache2/conf/httpd.conf]
[root@localhost metadata]# ls -l /usr/local/

 

詳細は,オフィシャルサイト参照下さい。

 

lastlog

| | コメント(0) | トラックバック(0)

[root@localhost ~]# who
admin    pts/0        2007-11-24 22:25 (192.168.11.2)
[root@localhost ~]# w
 00:03:46 up  2:14,  1 user,  load average: 0.04, 0.01, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
admin    pts/0    192.168.11.2     22:25    0.00s  0.67s  0.49s sshd: admin [priv]
[root@localhost ~]# last
admin    pts/0        192.168.11.2     Sat Nov 24 22:25   still logged in
reboot   system boot  2.6.18-8.1.14.el Sat Nov 24 21:49          (02:14)
reboot   system boot  2.6.18-8.1.14.el Fri Nov 23 22:28          (14:50)
admin    pts/1        192.168.11.2     Mon Nov 19 00:27 - down   (00:32)
admin    pts/1        192.168.11.2     Mon Nov 19 00:27 - 00:27  (00:00)
admin    pts/0        192.168.11.2     Sun Nov 18 14:11 - down   (10:48)
reboot   system boot  2.6.18-8.1.14.el Sun Nov 18 14:09          (10:49)
admin    pts/1        192.168.11.2     Sun Nov 18 00:36 - down   (00:43)
admin    pts/0        192.168.11.2     Sat Nov 17 23:31 - 00:45  (01:13)
reboot   system boot  2.6.18-8.1.14.el Sat Nov 17 23:13          (02:07)
admin    pts/0        192.168.11.2     Sat Nov 17 02:31 - down   (00:28)
admin    pts/0        192.168.11.2     Fri Nov 16 00:00 - 00:19  (00:19)
reboot   system boot  2.6.18-8.1.14.el Thu Nov 15 23:51         (1+03:09)
admin    pts/0        192.168.11.2     Sat Nov 10 22:48 - down   (02:43)
reboot   system boot  2.6.18-8.1.14.el Sat Nov 10 22:19          (03:13)
admin    pts/0        192.168.11.2     Sat Nov 10 01:53 - down   (01:28)
reboot   system boot  2.6.18-8.1.14.el Sat Nov 10 00:53          (02:28)
admin    pts/0        192.168.11.2     Sun Nov  4 22:49 - down   (01:35)
reboot   system boot  2.6.18-8.1.14.el Sun Nov  4 22:26          (01:58)
admin    pts/1        192.168.11.2     Sun Nov  4 02:14 - 02:14  (00:00)
admin    pts/1        192.168.11.2     Sun Nov  4 02:14 - 02:14  (00:00)
admin    pts/1        192.168.11.2     Sun Nov  4 02:04 - 02:04  (00:00)
admin    pts/1        192.168.11.2     Sun Nov  4 02:00 - 02:01  (00:00)
admin    pts/0        192.168.11.2     Sat Nov  3 22:57 - down   (03:35)
reboot   system boot  2.6.18-8.1.14.el Sat Nov  3 21:37          (04:55)
admin    pts/0        192.168.11.2     Sat Nov  3 02:13 - down   (00:00)

wtmp begins Sat Nov  3 02:13:55 2007
[root@localhost ~]# lastlog
ユーザ名         ポート   場所             最近のログイン
root                                       **一度もログインはありません**
bin                                        **一度もログインはありません**
daemon                                     **一度もログインはありません**
adm                                        **一度もログインはありません**
lp                                         **一度もログインはありません**
sync                                       **一度もログインはありません**
shutdown                                   **一度もログインはありません**
halt                                       **一度もログインはありません**
mail                                       **一度もログインはありません**
news                                       **一度もログインはありません**
uucp                                       **一度もログインはありません**
operator                                   **一度もログインはありません**
games                                      **一度もログインはありません**
gopher                                     **一度もログインはありません**
ftp                                        **一度もログインはありません**
nobody                                     **一度もログインはありません**
rpm                                        **一度もログインはありません**
dbus                                       **一度もログインはありません**
avahi                                      **一度もログインはありません**
mailnull                                   **一度もログインはありません**
smmsp                                      **一度もログインはありません**
ntp                                        **一度もログインはありません**
apache                                     **一度もログインはありません**
nscd                                       **一度もログインはありません**
vcsa                                       **一度もログインはありません**
haldaemon                                  **一度もログインはありません**
rpc                                        **一度もログインはありません**
rpcuser                                    **一度もログインはありません**
sshd                                       **一度もログインはありません**
pcap                                       **一度もログインはありません**
xfs                                        **一度もログインはありません**
gdm                                        **一度もログインはありません**
admin            pts/0    192.168.11.2     土 11月 24 22:25:36 +0900 2007
mysql                                      **一度もログインはありません**
administrator                              **一度もログインはありません**
[root@localhost ~]#

 

━━━ 追記 ━━━

lastコマンド :  /var/log/wtmp
whoコマンド  :   /var/run/utmp 

umask

| | コメント(0) | トラックバック(0)

新規に作成されるファイルのディフォルトパーミッションをrw-r--r--にしたい場合。

rw-r--r-- = 644

ファイルの場合666からumaskを引いた値になります。なので必要なumaskの

値は以下のように出せます。 (※実行権限が必要ないファイル)

666 - 644 = 022

umask 022を実行すると以下のようになります。

[root@localhost ~]# umask 022

[root@localhost ~]# ls -l > Umasktest
[root@localhost ~]# ls -l
合計 112
drwxr-xr-x  4 root  root  4096  9月 22 22:13 BACKUP
drwxr-xr-x  2 admin admin 4096  7月 14 01:04 Desktop
-rw-r--r--  1 root  root    70  9月 29 23:55 T1
-rw-r--r--  1 root  root   762  9月 30 00:50 Umasktest
drwxr-xr-x 11 root  root  4096  7月  1 00:53 album
drwxrwxr-x  2 admin admin 4096  4月 21 02:12 db
drwxr-xr-x  2 root  root  4096  9月 16 23:11 linktest
-rw-r--r--  1 root  root   645  9月 30 00:07 ls-log.log
-rw-r--r--  1 root  root   706  9月 30 00:08 ls-teelog.log
drwx--x--x  2 root  root  4096  8月 12 20:59 permission
drwxr-xr-x  3 root  root  4096  9月 16 22:26 right
drwxrwxr-x 10 admin admin 4096  7月  5 00:10 share
drwxr-xr-x  2 root  root  4096  8月 12 00:45 split
drwxr-xr-x  3 root  root  4096  8月 12 20:49 worked

 

所有者だけがファイルにアクセスできるよう,パーミッション(マスク)を指定する
[root@localhost ~]# umask 077

 

 

[root@localhost etc]# ls -ld /tmp
drwxrwxrwt 5 root root 4096  9月 12 23:43 /tmp

drwxrwxrwt ← 書き込み権はあるが,他のユーザーが所有するファイルを削除する事は出来ない。

1000+通常権限で設定。若しくはchmod +tでスティッキービットの設定が出来ます。

SUID(4000), SGID(2000)も設定出来ます。

 

 

権限

| | コメント(0) | トラックバック(0)

読み取り     r

書き込み権  w

実行権        x

[root@localhost ~]# chmod 754 test.log
-rwxr-xr--  1 admin admin      149  8月 19 22:42 test.log

rwx -----> 7

r-w ------> 5

r----------->4

 

【オプション】

-R 指定したディレクトリー以下にある全ファイルのアクセス権を変更する。

 

-rw-rw-r--  1 admin admin      149  8月 19 22:42 test.log

[root@localhost ~]# chmod ug+w test.log

↓のようになります。=  [root@localhost ~]# chmod 664 test.log

-rw-rw-r--  1 admin admin      149  8月 19 22:42 test.log

u=所有者

g=グループ

o=その他ユーザー

a=全てのユーザー

このアーカイブについて

このページには、過去に書かれたブログ記事のうちsecurityカテゴリに属しているものが含まれています。

前のカテゴリはPHPです。

次のカテゴリはsymfonyです。

最近のコンテンツはインデックスページで見られます。過去に書かれたものはアーカイブのページで見られます。

Powered by Movable Type 4.0