Chinaunix

标题: 在linux系统中如何禁止特定程序访问网络? [打印本页]

作者: lszh    时间: 2008-06-21 03:30
标题: 在linux系统中如何禁止特定程序访问网络?
如题。
在linux系统中如何禁止特定程序访问网络?基于对程序的控制,而不是基于端口。
提问前搜索过,但用了多种关键词组合都没有找到相关的资料。
作者: myhnet    时间: 2008-06-21 07:19
tcpwrap?
什么程序啊?
作者: c2shield    时间: 2008-06-21 11:48
限定软件访问网络……在windows下面是怎么实现的?如果能实现,那么linux下面也应该采用相同的方式,虽然系统不一样,但是方式或许是一样的。
作者: taoapca    时间: 2008-06-22 20:18
使用squid代理作应用层的处理也许可行
作者: lszh    时间: 2008-06-22 20:25
有谁可以详细说说tcpwrap或squid关于这方面的用途吗?
作者: ssffzz1    时间: 2008-06-22 20:55
LZ要的是禁止某个进程的方法。并且端口肯定是动态的。
因此目前LINUX无法做到。
作者: ljily000    时间: 2008-06-23 17:57
楼主的意图不是太清楚
作者: 志国    时间: 2008-06-23 19:22
没有第三方软件的话,不好实现!
作者: polokus    时间: 2008-06-24 14:03
Windows下面可以用 NetLimiter 2 Pro,效果还是很不错的

Linux下面就不清楚了
作者: kenduest    时间: 2008-06-24 14:37
原帖由 lszh 于 2008-6-21 03:30 发表
如题。
在linux系统中如何禁止特定程序访问网络?基于对程序的控制,而不是基于端口。
提问前搜索过,但用了多种关键词组合都没有找到相关的资料。


若是目前架構,可以用 iptables 來規範,不過好一點應該用 selinux 的 policy 來限制規範。前者比較簡單,後者比較通盤考量。

man iptables:

  1.    owner
  2.        This module attempts to match various characteristics of the packet creator, for locally-generated  pack-
  3.        ets.   It is only valid in the OUTPUT chain, and even this some packets (such as ICMP ping responses) may
  4.        have no owner, and hence never match.

  5.        --uid-owner userid
  6.               Matches if the packet was created by a process with the given effective user id.

  7.        --gid-owner groupid
  8.               Matches if the packet was created by a process with the given effective group id.

  9.        --pid-owner processid
  10.               Matches if the packet was created by a process with the given process id.

  11.        --sid-owner sessionid
  12.               Matches if the packet was created by a process in the given session group.

  13.        --cmd-owner name
  14.               Matches if the packet was created by a process with the  given  command  name.   (this  option  is
  15.               present only if iptables was compiled under a kernel supporting this feature)

  16.        NOTE: pid, sid and command matching are broken on SMP

复制代码


--cmd-owner 就是所需要的。不過依據我個人多台機器測試,早期的 iptables 可以使用,但是目前已經不大支援,跑 dmesg 會看到:

  1. ipt_owner: pid, sid and command matching not supported anymore
复制代码


所以 iptables 目前版本就無法達成所需要的項目。當然啦,若是要傳入 --uid-owner 這類參數還是可以的,只是這個作者需求無關就是。

那考慮用 selinux 的話自己寫 policy 是困難一點就是,若有研究的話倒是可以改用簡化的 selinux policy 來達成該需求。可以先參考 seedit project。

http://seedit.sourceforge.net/

這是一個簡化 selinux 規格配置並提供 policy 編寫的 project。若是要使用該 project 需要熟悉 selinux,而且要改用他的 policy database (一般預設系統是使用 targeted 的 selinux policy database),該 project 提供 GUI 的編寫工具,就可以設定相關 RBAC rule 設定相關程序是否可以存取某個文件甚至網路連線。

rule 像是:

http://seedit.sourceforge.net/doc/2.1/spdl_spec/node34.html
http://seedit.sourceforge.net/doc/2.1/spdl_spec/node32.html

--
作者: lszh    时间: 2008-06-24 18:35
谢谢各位,谢谢版主。

原帖由 ljily000 于 2008-6-23 17:57 发表
楼主的意图不是太清楚


在Windows系统下有很多防火墙可以控制应用程序对网络的访问,如允许Firefox浏览见面,而禁止ie等等。
我的本意是想问在linux下有没有类似的机制。

[ 本帖最后由 lszh 于 2008-6-24 18:38 编辑 ]
作者: ssffzz1    时间: 2008-06-24 20:34
已经告诉过你答案了。




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2