bond socket provider a server/client channel like ssh tunneling, it can forward port between multi node.
- auto reconnect and keep alive between client to server.
- control forward by dynamic uri like
node1->node2->tcp://xxxx:xx - port forward between multi node, it can be
normal client -> bsck server -> normal serverornormal client -> bsck server -> bsck slaver -> normal serverornormal client -> bsck client -> bsck server -> bsck slaver -> normal serveror ...- case1:
ssh client -> bsck client -> bsck server -> ssh serverfor solving ssh connect lost frequently and ssh once to inner server. - case2:
browser -> bsck client -> bsck server -> web serverfor browser to inner web server.
- case1:
bsckthe main code to implement bond socket, it export all api to embed bond socket in app.dialerthe main code to implement dial to raw socket or other useful feature like socks5/web.echorun an echo server, it always is using when usingbs-pingcommandwebstart http server on node and pipe it as bsck connect.tcpdial tcp connect to other server and pipe it as bsck connect.
bsrouterthe app to start bond socket node, it run bsck server/client/slaver at the same time.bsconsolethe agent app to make normal app can using bond socket.
- install basic command
go get github.com/codingeasygo/bsck/bsrouter
go get github.com/codingeasygo/bsck/bsconsole- install other command
$GOPATH/bin/bsconsole install- download binary from releases
- decompress to
xx cd xx/bsrouter./bsrouter-install.sh install clientfor client or./bsrouter-install.sh install servicefor service
bsrouterstart bond socket server/client/slaver by configure, it will auto scan configure ordered byargs,./.bsrouter.json",./bsrouter.json,HOME/.bsrouter/bsrouter.json,HOME/.bsrouter.json,/etc/bsrouter/bsrouter.json,/etc/bsrouter.jsonbsconsolethe node agent command, it will auto scan configure ordered likebsrouterbsconsole conn 'node1->tcp://127.0.0.1:xxx'connect to uri and redirect to stdin/stdout, likencbsconsole proxy 'node1'start proxy server and redirect local connection to remote uri- all
bsconsolesub command is having alias bybsconsole install
bs-conn <target uri>redirecting uri to stdin/stdout, equal tobsconsole conn <uri>bs-conn 'node1->tcp://127.0.0.1:xxx'connect to uri
bs-proxy <node uri> <listen proxy address>start http/socks proxy server and redirecting connection to uribs-proxy node1 127.0.0.1:1880start http/socks proxy server on 127.0.0.1:1880 and redirect all connection to node1
bs-proxychains <node uri> <command>start command and redirecting all connection to uri by proxychains toolsbs-proxychains node1 curl http://xxxit will redirect xxx:80 to node1
bs-ping <node uri>ping to nodebs-ping node1ping to node1bs-ping 'node1->node2'ping to node2 by routernode1->node2
bs-state <node uri>list node statebs-state node1list node1 statebs-state 'node1->node2'list node2 state
bs-shell <node uri> <env key> <shell command>start http/socks proxy server, set the environment value by env key, then run new bash with that envbs-shell node1 http_proxy,https_proxy bashthe new running bash will having http_proxy,https_proxy environmentbs-shell node1 proxy_server=http://${PROXY_HOST} bashthe new running bash will having proxy_server environment
bs-ssh <bsck uri> <ssh options>start ssh connectbs-ssh 'node1->tcp://xxx:22' -l rootstart connect ssh server which after node1
bs-sftp <bsck uri> <ssh options>start sftp connectbs-sftp 'node1->tcp://xxx:22' -l rootstart sftp to ssh server which after node1
bs-scp <bsck uri> <scp options>start scp connectbs-scp 'node1->tcp://xxx:22' xxx root@bshost:/tmp/copy xxx file to server after node1, thebshostwill be auto repealed.
-
namethe node name -
listenthe node listen port. -
cert,keythe ssl cert -
dialerthe raw connect dialer configure.stdenable all standard dialer by1, it containerecho,web,tcpdialer. if only want enable some dialer, can be
{ "dialer": { "echo":{ } } }- see Dialer Reference for more.
-
aclthe login access control on bsck server -
accessthe dial access control on bsck server -
weblisten web and websocket on address, it will be used forwarding host or websocket to remote -
consolelisten console on address, it always is used bybsconsole. -
logthe log level LogLevelDebug = 40,LogLevelInfo = 30,LogLevelWarn = 20,LogLevelError = 10
- generate ssl cert by
openssl req -new -nodes -x509 -out "/etc/bsrouter/bsrouter.pem" -keyout "/etc/bsrouter/bsrouter.key" -days 3650 -subj "/C=CN/ST=NRW/L=Earth/O=Random Company/OU=IT/CN=xxx/emailAddress=cert@xxxx"- edit configure on
/etc/bsrouter/bsrouter.json
{
"name": "server1",
"listen": ":12023",
"cert": "/etc/bsrouter/bsrouter.pem",
"key": "/etc/bsrouter/bsrouter.key",
"dialer": {
"std": 1
},
"acl": {
"slave1": "1111",
"client1": "2222"
},
"access": [
[
".*",
".*"
]
],
"log": 30
}- generate ssl cert by
openssl req -new -nodes -x509 -out "/etc/bsrouter/bsrouter.pem" -keyout "/etc/bsrouter/bsrouter.key" -days 3650 -subj "/C=CN/ST=NRW/L=Earth/O=Random Company/OU=IT/CN=xxx/emailAddress=cert@xxxx"- edit configure on
/etc/bsrouter/bsrouter.json
{
"name": "slave1",
"cert": "/etc/bsrouter/bsrouter.pem",
"key": "/etc/bsrouter/bsrouter.key",
"dialer": {
"std": 1
},
"channels": [
{
"enable": true,
"token": "1111",
"local": "",
"remote": "xxx:12023",
"index": 0,
"tls_cert": "/etc/bsrouter/bsrouter.pem",
"tls_key": "/etc/bsrouter/bsrouter.key"
}
],
"log": 30
}- generate ssl cert by
openssl req -new -nodes -x509 -out "$HOME/.bsrouter/bsrouter.pem" -keyout "$HOME/.bsrouter/bsrouter.key" -days 3650 -subj "/C=CN/ST=NRW/L=Earth/O=Random Company/OU=IT/CN=xxx/emailAddress=cert@xxxx"- edit configure on
$HOME/.bsrouter/bsrouter.json
{
"name": "client1",
"web": {},
"console": "127.0.01:1701",
"channels": [
{
"enable": true,
"token": "2222",
"local": "",
"remote": "xxx:12023",
"index": 0,
"cert": "/xx/.bsrouter/bsrouter.pem",
"key": "/xx/.bsrouter/bsrouter.key"
}
],
"log": 30
}bs-ping server1test connect to server1 (optional)
bsconsole using config /xxx/.bsrouter/bsrouter.json
64 Bytes from server1->tcp://echo time=9.600463ms
64 Bytes from server1->tcp://echo time=5.248072msbs-ping 'server1->slaver1'test connect to slaver1 (optional)
bsconsole using config /xxx/.bsrouter/bsrouter.json
64 Bytes from server1->slaver1->tcp://echo time=11.600463ms
64 Bytes from server1->slaver1->tcp://echo time=12.248072msbs-stateget client1 state when do ping (optional)
bsconsole using config /Users/vty/.bsrouter/bsrouter.json
[Channels]
->server1
0 5 2018-10-24 11:30:33 channel{name:server1,index:0,cid:44,info:x.x.x.x:12023}
[Table]
channel{name:server1,index:0,cid:44,info:x.x.x.x:12023} 52 <-> raw{uri:tcp://echo,router:server1->tcp://echo,info:ws://:12024} 52bsconsole server1start bash on server1 (optional)
bsconsole using config /xxx/.bsrouter/bsrouter.json
[bsrouter@xx ~]$bs-ssh 'server1->slaver1->tcp://x.x.x.x:22' -l roottest connect to ssh server (optional)
- edit
/xx/.bsrouter/bsrouter.jsonand addforwardsconfigure.
{
"name": "client1",
"web": {},
"channels": [
{
"enable": true,
"token": "2222",
"local": "",
"remote": "xxx:12023",
"index": 0,
"tls_cert": "/xx/.bsrouter/bsrouter.pem",
"tls_key": "/xx/.bsrouter/bsrouter.key"
}
],
"forwards": {
"test1~ws://": "server1->tcp://host1:22",
"test1-1~tcp://localhost:10022": "server1->slaver1->tcp://host1:22",
"test2~vnc://localhost": "server1->slaver1->tcp://host2:5900",
"test2-1~tcp://localhost:15900": "server1->slaver1->tcp://host2:5900",
"test3~rdp://localhost": "server1->slaver1->tcp://host3:3389",
"test3-1~tcp://localhost:13389": "server1->slaver1->tcp://host3:3389",
"test4~ws://": "server1->slaver1->tcp://cmd?exec=ping www.google.com"
},
"rdp_dir": "/tmp/bsrouter/",
"vnc_dir": "/tmp/bsrouter/",
"log": 30
}-
in this case, bsck forward ssh/vnc/rdp
bs-ssh test1 -l rootto ssh connect host1ssh -p 10022 localhost -l rootto ssh connect host1- connect host2 by vnc client: open vnc client then open
test2.vncfile on/tmp/bsrouter/ - connect host2 by vnc client: open vnc client then using localhost:15900 to connect
- connect host3 by rdp client: open rdp client then open
test3.rdpfile on/tmp/bsrouter/ - connect host3 by rdp client: open rdp client then using localhost:13389 to connect
bsconsole test4execute ping on slaver1
-
more for forward configure, see Forward Reference
-
in this case, having two proxy dialer in two router
server,slaver1and one upstream proxy, only host contain x1,x2 can connect, and limit x1,x2 connect count by 10 time per 3000ms. this case is always used on crawler.
{
"dialer": {
"echo": {}
}
}{
"dialer": {
"socks": {
"id": "s1",
"address": "xxx:xx",
"matcher": "^.*$"
}
}
}idthe dialer id (required)addressthe socks5 server address (required)matchermatch uri to access to connect. (optional)
{
"dialer": {
"web": {}
}
}{
"dialer": {
"tcp": {
"bind": "xxxx:xx"
}
}
}bindbind to local address before connect to remote.
the remote uri scheme is node1->node2->..->node3->protocol://host:port?arg=val
supported protocol
tcp://host:port?arg=valnormal tcp dialer, the argumentsbindbind to local address before connect to remote (optional)
tcp://cmd?arg=valexecute command on nodeexecthe command and command argument to exec (required)LCthe i/o encodingreuseenable/disable reuse session, 1 is enable, 0 is disable.
tcp://echostart echo serverhttp://webstart web server on nodedirthe webdav work directory.
the local uri scheme is alias~protocol://user:password@host:port, the alias can be used on bsconsole,bs-sftp,bs-scp,bs-ssh
supported protocol
alias~tcp://host:portlisten tcp by host:portalias~socks://host:portlisten socks5 by host:port,alias~rdp://user@host:portlisten tcp by host:port, and generate rdp file onrdp_dirby alias.rdp, password is not supported by rdp filealias~vnc://:password@host:portlisten tcp by host:port, and generate rdp file onvnc_dirby alias.vnc, user is not needed, password is encryptedalias~web://forward web byhttp://localhost:port/dav/aliasto uri whenwebconfigure is enabled.alias~ws://forward websocket byws://localhost:port/ws/aliasto uri whenwebconfigure is enabled.