Sinh policy bằng Polgen

Một phần của tài liệu Nghiên cứu khả năng an toàn của hệ điều hành mạng (Trang 96 - 98)

Chúng ta sẽ sử dụng bộ ECommerce đi kèm với polgen để minh họa. Script

ecomm-config sẽ copy file của bộ ECommerce vào thư mục hiện tại. Lưu ý là chế độ hoạt động của SELinux là permissive.

# cd /usr/local # mkdir ecomm # cd ecomm

# chown user:group . # ecomm-config

Việc đầu tiên là tạo một policy tối thiểu. Đi kèm với ứng dụng này đã có sẵn file .psl (Polgen Specification Language). Prefix là đường dẫn của thư mục chứa chương trình. prefix=/usr/local/ecomm exec_prefix=$prefix/bin datadir = $prefix/share pkgdatadir=$datadir/ecomm component $exec_prefix/esales.py { type process entry_point 1 writes {$pkgdatadir/orders(/.*)?} } component $exec_prefix/acct_rcv.py { type process entry_point 1 reads {$pkgdatadir/orders(/.*)?} writes {$pkgdatadir/paid(/.*)?}

} component $exec_prefix/shipping.py { type process entry_point 1 reads {$pkgdatadir/paid(/.*)?} }

Bước tiếp theo là chạy spar. Lưu ý là phải chạy trong chế độ đồ họa để có thể thực hiện tương tác với polgen.

# spar -n ecommerce

Bây giờ chúng ta có thể kiểm tra việc sinh policy ban đầu có thành công hay không. # cd results # cat temp_ecommerce.fc /usr/local/ecomm/paid(/.*)? gen_context(system_u:object_r:ecommerce_pipeline_t, s0) /usr/local/ecomm/orders(/.*)? gen_context(system_u:object_r:ecommerce_pipeline_t, s0) /usr/local/ecomm/bin/shipping.py gen_context(system_u:object_r:polgen_temp_shipping_exec_t, s0) /usr/local/ecomm/bin/acct_rcv.py gen_context(system_u:object_r:polgen_temp_acct_rcv_exec_t, s0) /usr/local/ecomm/bin/esales.py gen_context(system_u:object_r:polgen_temp_esales_exec_t, s0)

Bây giờ chúng ta sẽ kết hợp policy tạm thời của ECommerce vào hệ thống. # make -f /usr/share/selinux/devel/Makefile

# /usr/sbin/semodule -i temp_ecommerce.pp # /sbin/restorecon -v -r ..

Sau khi đã có policy tạm thời cho ECommerce, chúng ta tiến hành việc theo dõi hành vi của các chương trình con trong ECommerce( esales server, accounts receivable, shipping) bằng stracesc. Chúng ta bỏ qua client vì client chạy trên một máy khác.

# cd /usr/local/ecomm/share/ecomm

# stracesc -fX -o esales.py ../../bin/esales.py & Chạy client để cho chúng ta một lệnh đặt hàng. # ../../bin/salesclient.py

# fg Ctrol + C

Lệnh trên sẽ kill tiến trình esales. Bình thường, server sẽ chạy liên tục, nhưng ở đây chúng ta không cần server nữa.

# stracesc -fX -o acct_rcv.py ../../bin/acct_rcv.py # stracesc -fX -o shipping.py ../../bin/shipping.py # trackall -o /usr/local/ecomm *.py

Thư mục /usr/local/ecomm sẽ chứa các file output của trackall: esales.py.tracked, acct_rcv.py.tracked, shipping.py.tracked. Tiếp theo là chạy spar một lần nữa:

# cd /usr/local/ecomm # spar -n ecommerce

Sau quá trình tự động và tương tác với người dùng, /usr/results sẽ chứa output của spar, gồm các file .te, .fc và .if.

Cuối cùng là cài đặt module mới vào policy đang chạy trên hệ thống. # cd results

# make -f /usr/share/selinux/devel/Makefile # /usr/sbin/semodule -i ecommerce.pp # /sbin/restorecon -v -r ..

Một phần của tài liệu Nghiên cứu khả năng an toàn của hệ điều hành mạng (Trang 96 - 98)