security workshop 20131213
TRANSCRIPT
脆弱性と管理 n 脆弱性
n 製作者の意図しない挙動が攻撃等に利用される状態
n バグともいわれる:ソフトウェア,システム,プロトコル
n 脆弱性の種類:バッファオーバフロー,サニタイジング失敗/無視,など
n 管理方法
n 最新のソフトウェアバージョンへの更新
n ペネトレーションテストの実施:Metasploit, OpenVAS, Nessus
3
Linuxディストリビューションの 進化図(参考)
4 http://www.cyberciti.biz/tips/wp-content/uploads/2007/06/44218-linuxdistrotimeline-7.2.png
Ubuntuシリーズ
Ubuntuのパッケージ管理システム
n UbuntuはDebian系列のLinuxディストリビューション
n Debian Projectが開発したAPT (Advanced Packaging Tool)を採用
5
Ubuntuクライアント
インターネット
Ubuntuリポジトリサーバ
1. apt-get install apache2 2. apache2と依存ソフトウェア取得要求
3.ソフトウェアダウンロード
APTのリポジトリサーバは複数存在
n 公式,地域毎のミラーリング,サードパーティ
n セキュリティアップデート用 (http://security.ubuntu.com/)
n /etc/apt/sources.list にリポジトリサーバが記述される
n less /etc/apt/sources.list を実行して,リポジトリサーバに何処を設定されているか確認せよ
n (基本的には何も考えずに,apt-get update, apt-get upgradeで最新のソフトウェアとなる)
6
CVE (Common Vulnerability and Exposures) 共通脆弱性辞書
8
n 脆弱性情報の辞書
n アメリカの非営利団体MITER社が提案
n Ubuntu,Debian,RedHatなどでも利用
Ubuntu Security NoticesのCVE情報
OpenVASのサーバ証明書を作成 n openvas-mkcert コマンドで作成
12
$ sudo openvas-mkcert /usr/sbin/openvas-mkcert: 63: /usr/sbin/openvas-mkcert: 0: not found -------------------------------------------------------------------------------
Creation of the OpenVAS SSL Certificate ------------------------------------------------------------------------------- This script will now ask you the relevant information to create the SSL certificate of OpenVAS. Note that this information will *NOT* be sent to anybody (everything stays local), but anyone with the ability to connect to your OpenVAS daemon will be able to retrieve this information. CA certificate life time in days [1460]: Server certificate life time in days [365]: Your country (two letter code) [FR]: JP Your state or province name [none]: Your location (e.g. town) [Paris]: Tokyo Your organization [OpenVAS Users United]: Tuda College
OpenVASのユーザを追加 n openvas-adduserコマンドで作成
n 最後まで行ったらCtrl+Dで終了
13
$ sudo openvas-adduser /usr/sbin/openvas-adduser: 53: /usr/sbin/openvas-adduser: 0: not found Using /var/tmp as a temporary file holder. Add a new openvasd user --------------------------------- Login : ytakano Authentication (pass/cert) [pass] : Login password : Login password (again) : User rules ---------------
ファイアウォール n ネットワーク的にファイアウォール(防火壁)の役割を果たす
n IPアドレスやポート番号で通信を制御(許可)
19
インターネット 家庭内,社内 学校内,組織内
許された通信のみ通す
iptables n Linux用ファイアウォール
n IPヘッダ,TCP・UDPヘッダ,パケットの内容でフィルタリング
n chainという概念
n どこでフィルタリングを行うか
n INPUT/OUTPUT/FORWARD
n NATのためにも用いられる
n IPアドレスやポート番号の変換
n 今回は割愛
20
iptables INPUT/OUTPUT chains
n IPパケットの入力時/出力時にフィルタルールが適用される
21
Linux Kernel
NW IF
input
input filter
Application
app1
output filter
output
iptables chains
iptables FORWARD chaing
22
Linux Kernel
NW IF1
forward forward filter iptables chaings
NW IF2
n パケットフォワード時に適用される
routing decision
IPルーティング基礎 n IPパケットは最長マッチによりルーティング先が決定
23
$ netstat -rn カーネルIP経路テーブル 受信先サイト ゲートウェイ ネットマスク フラグ MSS Window irtt インタフェース 0.0.0.0 150.65.32.1 0.0.0.0 UG 0 0 0 eth0 150.65.32.0 0.0.0.0 255.255.255.128 U 0 0 0 eth0 192.50.109.0 0.0.0.0 255.255.255.128 U 0 0 0 eth1
150.65.32/25
192.50.109/25 150.65.32.1
デフォルトルータ
IPアドレスの最長マッチ n アドレスとネットマスクで最長マッチを行い転送先を決定
n 以下のルーティングテーブルがあった時,次のアドレスはどちらに転送されるか?
n 192.168.20.2
n 192.168.10.5
24
ネットワーク 次ホップ 192.168.0.0/16 -> 192.168.0.1 192.168.10.0/24 -> 192.168.10.1
最長マッチの考え方 n IPアドレスは8ビットごとに区切って表示されている
n 192.168.0.0/16の16というのは上位16ビットまで有効という意味.すなわち192.168までが有効
n 従って,192.168 と 192.168.10 と,対象を比較して,最も長くマッチした方が採用される
n 実際は2進数で行われる
25
192.168.100.200 8bit 8bit 8bit 8bit 合計32bit
INPUT/OUTPUTフィルタの 利用ケース
n INPUTフィルタ:許可した送信元からのパケットのみ受信
n OUTPUTフィルタ:許可した送信先へのパケットのみ送信
26
192.168/16 172.16/16
192.168/16からの通信のみ許可
× 10.100/16 172.16/16
10.100/16への通信のみ許可
×
INPUTフィルタ
OUTPUTフィルタ
www.google.comへの通信を遮断(1) www.google.comのIPアドレスを調べる
n digコマンドでドメイン名からIPアドレスを調べる
29
$ dig www.google.com ;; QUESTION SECTION: ;www.google.com. IN A ;; ANSWER SECTION: www.google.com. 177 IN A 173.194.38.82 www.google.com. 177 IN A 173.194.38.84 www.google.com. 177 IN A 173.194.38.81 www.google.com. 177 IN A 173.194.38.83 www.google.com. 177 IN A 173.194.38.80
www.google.comに割り当てられたIPアドレス
www.google.comへの通信を遮断(2) アドレスレンジを確認
n whoisでアドレスレンジを確認
30
$ whois 173.194.38.82 NetRange: 173.194.0.0 - 173.194.255.255 CIDR: 173.194.0.0/16 OriginAS: AS15169 NetName: GOOGLE NetHandle: NET-173-194-0-0-1 Parent: NET-173-0-0-0-0 NetType: Direct Allocation RegDate: 2009-08-17 Updated: 2012-02-24 Ref: http://whois.arin.net/rest/net/NET-173-194-0-0-1
IPアドレスレンジ
www.google.comへの通信を遮断(3) OUTPUT chainにフィルタ設定
n -I: chain を指定
n -d: 宛先アドレスを指定
n -j: 動作を指定,ACCEPT, DROP, LOG, REJECT, RETURN
n -L: 現在のフィルタ設定を表示
n -n: 逆引きしない
31
$ sudo iptables -I OUTPUT -d 173.194.0.0/16 -j DROP $ sudo iptables -L -n 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 DROP all -- 0.0.0.0/0 173.194.0.0/16
OUTPUTフィルタ
iptables設定の消去 n 消去は--flushオプションで行う
33
$ sudo iptables --flush $ sudo iptables -L -n 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
www.google.comへの通信のみ許可 (1) OUTPUTのデフォルトポリシをDROPに
n -Pオプションで各chainのデフォルトポリシを設定
34
$ sudo iptables -P OUTPUT DROP $ sudo iptables -L -n Chain INPUT (policy ACCEPT) target prot opt source destination Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy DROP) target prot opt source destination
デフォルト動作がDROP(破棄)
www.google.comへの通信のみ許可 (3) OUTPUT chainにフィルタ設定
n 今度はwww.google.comへの通信をACCEPTと追加
n さらにローカルネットワーク,ループバックへの通信もACCEPTへと追加
36
$ sudo iptables -I OUTPUT -d 173.194.0.0/16 -j ACCEPT $ sudo iptables -I OUTPUT -d 192.168.0.0/16 -j ACCEPT $ sudo iptables -I OUTPUT -d 127.0.0.0/8 -j ACCEPT $ sudo iptables -L -n Chain INPUT (policy ACCEPT) target prot opt source destination Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy DROP) target prot opt source destination ACCEPT all -- 0.0.0.0/0 173.194.0.0/16 ACCEPT all -- 0.0.0.0/0 192.168.0.0/16
IDS/IPS 侵入検知(防御)システム
n 不正なアクセスを検出するシステム
n アノマリ型(異常検出):正常な状態を定義しておいて,それに外れたものを検出
n シグネチャ型:攻撃など不正な状態を定義しておいて,それにマッチしたものを検出
38
Snortのアラートログ n Ubuntuでは /var/log/snort/alert にアラートのログが置かれる
41
$ cat /var/log/snort/alert [**] [1:527:8] BAD-TRAFFIC same SRC/DST [**] [Classification: Potentially Bad Traffic] [Priority: 2] 12/12-16:41:25.656957 0.0.0.0 -> 224.0.0.1 IGMP TTL:1 TOS:0xC0 ID:0 IpLen:24 DgmLen:32 DF IP Options (1) => RTRALT [Xref => http://www.cert.org/advisories/CA-1997-28.html][Xref => http://cve.mitre.org/cgi-bin/cvename.cgi?name=1999-0016][Xref => http://www.securityfocus.com/bid/2666] [**] [1:100000160:2] COMMUNITY SIP TCP/IP message flooding directed to SIP proxy [**] [Classification: Attempted Denial of Service] [Priority: 2] 12/12-16:44:51.464387 192.168.0.102:57299 -> 192.168.0.103:22 TCP TTL:64 TOS:0x10 ID:4292 IpLen:20 DgmLen:100 DF ***AP*** Seq: 0x3E67C58A Ack: 0xF97BBBD6 Win: 0x2000 TcpLen: 32 TCP Options (3) => NOP NOP TS: 1212047155 1811368
Snortのシグネチャ n /etc/snort/rules 以下に置かれる
n 設定ファイル /etc/snort/snort.conf で読込まれる
42
$ less /etc/snort/rules/backdoor.rules alert tcp $EXTERNAL_NET 27374 -> $HOME_NET any (msg:"BACKDOOR subseven 22"; flow:to_server,established; content:"|0D 0A|[RPL]002|0D 0A|"; reference:arachnids,485; reference:url,www.hackfix.org/subseven/; classtype:misc-activity; sid:103; rev:7;) alert tcp $HOME_NET 16959 -> $EXTERNAL_NET any (msg:"BACKDOOR subseven DEFCON8 2.1 access"; flow:from_server,established; content:"PWD"; classtype:trojan-activity; sid:107; rev:6;)
バックドアのシグネチャ