sokcs5软件dante配置指南

来源:互联网 发布:淘宝达人贴怎么写 编辑:程序博客网 时间:2024/06/11 13:39
近来公司业务有需要做socks5代理的需求,研究了一下,主要的开源实现有2个:
dante http://www.inet.no/dante/
ss5 http://ss5.sourceforge.net/

比较了一下,还是比较倾向于dante,因为看到有人这样评价ss5:

Project has an incredibly poor source code quality. There are lot of buffer overflows caused by inconsistencies of hard coded and real buffer sizes or broken error detection due to signed/unsigned mismatch. Developer uses either an very compiler or is unaware of flags like '-W' or '-D_FORTIFY_SOURCE' which would detect most of these issues.

当然,这个是人家的评价,不代表我的观点。

闲话少说,下边进入正题。

1.安装Dante


Redhat/CentOS:
#yum install gcc make bison flex rpm-build.x86_64
#yum install openldap-devel.x86_64 pam-devel.x86_64 openssl-devel.x86_64 libgssapi-devel.x86_64 libgssapi-devel.x86_64
#wget -c wget http://www.inet.no/dante/files/dante-1.4.0-pre1.tar.gz
#rpmbuild -ta dante-1.4.0-pre1.tar.gz
#cd rpmbuild/RPMS
#rpm -ivh dante-1.4.0-0.pre1.el6.x86_64.rpm dante-server-1.4.0-0.pre1.el6.x86_64.rpm
#useradd sockd
#usermod -s /sbin/nologin sockd

或者源码安装:
#tar -zxvf dante-1.4.0-pre1.tar.gz
#cd dante-1.4.0-pre1
#./configure --with-sockd-conf=/etc/danted.conf
#make
#make install

2.Dnate配置文件解析

默认的配置文件是/etc/sockd.conf,在debian下则是/etc/danted.conf

整个配置文件由3个大部分组成。

1)server settings 控制dante的一般行为;
2)rules 用户的访问控制;
3)routes 通常用于"server-chaining";

配置由关键字组成,关键字后边跟":"指定值。

配置文件的推荐书写顺序如下:
  Server settings:
              logoutput
              internal
              external
              method
              clientmethod
              users
              compatibility
              extension
              timeout
              srchost
#
 Rules:
       client block/pass
               from to
               libwrap
               log
#
       block/pass
               from to
               method
               command
               libwrap
               log
               protocol
               proxyprotocol
#
 Routes:


下边就举一个简单的配置说明一下:

logoutput: /var/log/sockd.log
internal: eth0 port = 1080
external: 111.111.1111.111
method: username none
user.privileged: sockd
user.unprivileged: sockd

#定义"client-rules",明确指明哪些IP可以访问这个socks5 server
client pass {
from: <your ip here>/32 port 1-65535 to: 0.0.0.0/0
}

#Loopback地址也允许访问
client pass {
from: 127.0.0.0/8 port 1-65535 to: 0.0.0.0/0
}

#封闭其他所有人访问,避免成为公共的proxy
client block {
from: 0.0.0.0/0 to: 0.0.0.0/0
log: connect error
}

# 定义"socks-rules",指明允许连接的这些IP可以通过这个socks5 server访问哪些地址
# 禁止所有地址访问本地loopback地址
block {
from: 0.0.0.0/0 to: 127.0.0.0/8
log: connect error
}

# 允许自己的IP访问任何地址
pass {
from: <your ip here>/32 to: 0.0.0.0/0
protocol: tcp udp
}

pass {
from: 127.0.0.0/8 to: 0.0.0.0/0
protocol: tcp udp
}

#封闭其他任何人的访问
block {
from: 0.0.0.0/0 to: 0.0.0.0/0
log: connect error
}

logoutput 关键字
定义了日志的输出位置,可以是syslog[/facility], stdout, stderr,一个指定文件,或者上述的组合。

internal关键字
定义了接受用户连接的IP地址,也可以写接口名称,如eth0

external关键字
定义了向外访问的IP地址,也可以写接口名称,如果有多个地址可以写多个。

method关键字
控制用户认证的方法,可以是以下之一或组合。
none 不需要认证
username 用户名密码
gssapi kerberos认证
rfc931 需要用户主机提供一个rfc931 reply,这个reply必须匹配一个/etc/passwd中的用户名
pam 通过PAM方式认证
badauth 通过BSD认证系统

user.privileged关键字
如果需要读取sockd.conf,写入sockd.pid等文件,或使用密码认证等需要特权的操作,则最好将此值设为root,如果不需要特权操作,则可以设成user.unprivileged相同的用户即可。

user.unprivileged关键字
用于运行dante进程的用户名

pass/block
定义rules,放行或者阻断。在dante的配置中,有两个层面的rules,一个是"client-rules",另一个是"socks-rules"。
"client-rules"和"socks-rules"都由pass和block关键字组成,区别在于client-rules带有"client"前缀。
"client-rules"会首先被检查,用来判别用户是否可以与sockd通讯,这些规则工作在TCP层。
"socks-rules"是在通过client-rules判定,确认用户可以与sockd通讯以后,用来判别用户发送的连接的具体请求内容,并根据这些内容判定通过还是拒绝。
"client-rules"和"socks-rules"都遵循"first match is best match"原则,即如果有多条规则匹配,则第一个匹配指定client或socket的规则会被执行。

在以上两种rules中,针对IP地址这个值,还有一套可选的关键字,其中client-rules中的可选关键字是socks-rules中的一个子集。
对于每条规则,规则中所有的条件类关键字都会被检查 ,如果匹配用户请求,则所有的动作都会被执行。

IP地址中可选关键字主要包含两类:

条件类:
to
from
port
user
group
method
protocol
proxyprotocol
clientcompatibility
command

动作类:
bandwidth
libwrap
log
maxsessions
redirect
timeout.connect
timeout.negotiate
timeout.io
timeout.tcp_fin_wait
udp.portrange

参考资料:

Dante官方网站 http://www.inet.no/dante/
0 0
原创粉丝点击