Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sshuttle
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
pub
sshuttle
Commits
71d65f38
Commit
71d65f38
authored
Nov 11, 2017
by
vieira
Committed by
Brian May
Nov 13, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes some style issues and minor bugs
parent
9f238ebc
Changes
17
Show whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
78 additions
and
86 deletions
+78
-86
.prospector.yml
.prospector.yml
+5
-0
client.py
sshuttle/client.py
+6
-6
cmdline.py
sshuttle/cmdline.py
+2
-2
firewall.py
sshuttle/firewall.py
+6
-5
hostwatch.py
sshuttle/hostwatch.py
+1
-1
__init__.py
sshuttle/methods/__init__.py
+2
-1
ipfw.py
sshuttle/methods/ipfw.py
+11
-22
nat.py
sshuttle/methods/nat.py
+6
-5
pf.py
sshuttle/methods/pf.py
+14
-20
tproxy.py
sshuttle/methods/tproxy.py
+6
-5
options.py
sshuttle/options.py
+10
-7
sdnotify.py
sshuttle/sdnotify.py
+1
-1
ssh.py
sshuttle/ssh.py
+1
-1
ssnet.py
sshuttle/ssnet.py
+3
-3
test_options.py
sshuttle/tests/client/test_options.py
+2
-2
test_sdnotify.py
sshuttle/tests/client/test_sdnotify.py
+1
-3
test_server.py
sshuttle/tests/server/test_server.py
+1
-2
No files found.
.prospector.yml
View file @
71d65f38
...
@@ -10,6 +10,11 @@ pylint:
...
@@ -10,6 +10,11 @@ pylint:
-
bare-except
-
bare-except
-
protected-access
-
protected-access
-
no-else-return
-
no-else-return
-
unused-argument
-
method-hidden
-
arguments-differ
-
wrong-import-position
-
raising-bad-type
pep8
:
pep8
:
options
:
options
:
...
...
sshuttle/client.py
View file @
71d65f38
...
@@ -112,8 +112,8 @@ def daemon_cleanup():
...
@@ -112,8 +112,8 @@ def daemon_cleanup():
class
MultiListener
:
class
MultiListener
:
def
__init__
(
self
,
type
=
socket
.
SOCK_STREAM
,
proto
=
0
):
def
__init__
(
self
,
kind
=
socket
.
SOCK_STREAM
,
proto
=
0
):
self
.
type
=
type
self
.
type
=
kind
self
.
proto
=
proto
self
.
proto
=
proto
self
.
v6
=
None
self
.
v6
=
None
self
.
v4
=
None
self
.
v4
=
None
...
@@ -746,22 +746,22 @@ def main(listenip_v6, listenip_v4,
...
@@ -746,22 +746,22 @@ def main(listenip_v6, listenip_v4,
# Last minute sanity checks.
# Last minute sanity checks.
# These should never fail.
# These should never fail.
# If these do fail, something is broken above.
# If these do fail, something is broken above.
if
len
(
subnets_v6
)
>
0
:
if
subnets_v6
:
assert
required
.
ipv6
assert
required
.
ipv6
if
redirectport_v6
==
0
:
if
redirectport_v6
==
0
:
raise
Fatal
(
"IPv6 subnets defined but not listening"
)
raise
Fatal
(
"IPv6 subnets defined but not listening"
)
if
len
(
nslist_v6
)
>
0
:
if
nslist_v6
:
assert
required
.
dns
assert
required
.
dns
assert
required
.
ipv6
assert
required
.
ipv6
if
dnsport_v6
==
0
:
if
dnsport_v6
==
0
:
raise
Fatal
(
"IPv6 ns servers defined but not listening"
)
raise
Fatal
(
"IPv6 ns servers defined but not listening"
)
if
len
(
subnets_v4
)
>
0
:
if
subnets_v4
:
if
redirectport_v4
==
0
:
if
redirectport_v4
==
0
:
raise
Fatal
(
"IPv4 subnets defined but not listening"
)
raise
Fatal
(
"IPv4 subnets defined but not listening"
)
if
len
(
nslist_v4
)
>
0
:
if
nslist_v4
:
if
dnsport_v4
==
0
:
if
dnsport_v4
==
0
:
raise
Fatal
(
"IPv4 ns servers defined but not listening"
)
raise
Fatal
(
"IPv4 ns servers defined but not listening"
)
...
...
sshuttle/cmdline.py
View file @
71d65f38
...
@@ -45,8 +45,8 @@ def main():
...
@@ -45,8 +45,8 @@ def main():
if
opt
.
listen
:
if
opt
.
listen
:
ipport_v6
=
None
ipport_v6
=
None
ipport_v4
=
None
ipport_v4
=
None
l
i
st
=
opt
.
listen
.
split
(
","
)
lst
=
opt
.
listen
.
split
(
","
)
for
ip
in
l
i
st
:
for
ip
in
lst
:
family
,
ip
,
port
=
parse_ipport
(
ip
)
family
,
ip
,
port
=
parse_ipport
(
ip
)
if
family
==
socket
.
AF_INET6
:
if
family
==
socket
.
AF_INET6
:
ipport_v6
=
(
ip
,
port
)
ipport_v6
=
(
ip
,
port
)
...
...
sshuttle/firewall.py
View file @
71d65f38
...
@@ -2,6 +2,7 @@ import errno
...
@@ -2,6 +2,7 @@ import errno
import
socket
import
socket
import
signal
import
signal
import
sshuttle.ssyslog
as
ssyslog
import
sshuttle.ssyslog
as
ssyslog
import
sshuttle.sdnotify
as
sdnotify
import
sys
import
sys
import
os
import
os
import
platform
import
platform
...
@@ -164,7 +165,7 @@ def main(method_name, syslog):
...
@@ -164,7 +165,7 @@ def main(method_name, syslog):
_
,
_
,
ports
=
line
.
partition
(
" "
)
_
,
_
,
ports
=
line
.
partition
(
" "
)
ports
=
ports
.
split
(
","
)
ports
=
ports
.
split
(
","
)
if
len
(
ports
)
!=
4
:
if
len
(
ports
)
!=
4
:
raise
Fatal
(
'firewall: expected 4 ports but got
%
n
'
%
len
(
ports
))
raise
Fatal
(
'firewall: expected 4 ports but got
%
d
'
%
len
(
ports
))
port_v6
=
int
(
ports
[
0
])
port_v6
=
int
(
ports
[
0
])
port_v4
=
int
(
ports
[
1
])
port_v4
=
int
(
ports
[
1
])
dnsport_v6
=
int
(
ports
[
2
])
dnsport_v6
=
int
(
ports
[
2
])
...
@@ -203,14 +204,14 @@ def main(method_name, syslog):
...
@@ -203,14 +204,14 @@ def main(method_name, syslog):
try
:
try
:
debug1
(
'firewall manager: setting up.
\n
'
)
debug1
(
'firewall manager: setting up.
\n
'
)
if
len
(
subnets_v6
)
>
0
or
len
(
nslist_v6
)
>
0
:
if
subnets_v6
or
nslist_v6
:
debug2
(
'firewall manager: setting up IPv6.
\n
'
)
debug2
(
'firewall manager: setting up IPv6.
\n
'
)
method
.
setup_firewall
(
method
.
setup_firewall
(
port_v6
,
dnsport_v6
,
nslist_v6
,
port_v6
,
dnsport_v6
,
nslist_v6
,
socket
.
AF_INET6
,
subnets_v6
,
udp
,
socket
.
AF_INET6
,
subnets_v6
,
udp
,
user
)
user
)
if
len
(
subnets_v4
)
>
0
or
len
(
nslist_v4
)
>
0
:
if
subnets_v4
or
nslist_v4
:
debug2
(
'firewall manager: setting up IPv4.
\n
'
)
debug2
(
'firewall manager: setting up IPv4.
\n
'
)
method
.
setup_firewall
(
method
.
setup_firewall
(
port_v4
,
dnsport_v4
,
nslist_v4
,
port_v4
,
dnsport_v4
,
nslist_v4
,
...
@@ -249,7 +250,7 @@ def main(method_name, syslog):
...
@@ -249,7 +250,7 @@ def main(method_name, syslog):
pass
pass
try
:
try
:
if
len
(
subnets_v6
)
>
0
or
len
(
nslist_v6
)
>
0
:
if
subnets_v6
or
nslist_v6
:
debug2
(
'firewall manager: undoing IPv6 changes.
\n
'
)
debug2
(
'firewall manager: undoing IPv6 changes.
\n
'
)
method
.
restore_firewall
(
port_v6
,
socket
.
AF_INET6
,
udp
,
user
)
method
.
restore_firewall
(
port_v6
,
socket
.
AF_INET6
,
udp
,
user
)
except
:
except
:
...
@@ -262,7 +263,7 @@ def main(method_name, syslog):
...
@@ -262,7 +263,7 @@ def main(method_name, syslog):
pass
pass
try
:
try
:
if
len
(
subnets_v4
)
>
0
or
len
(
nslist_v4
)
>
0
:
if
subnets_v4
or
nslist_v4
:
debug2
(
'firewall manager: undoing IPv4 changes.
\n
'
)
debug2
(
'firewall manager: undoing IPv4 changes.
\n
'
)
method
.
restore_firewall
(
port_v4
,
socket
.
AF_INET
,
udp
,
user
)
method
.
restore_firewall
(
port_v4
,
socket
.
AF_INET
,
udp
,
user
)
except
:
except
:
...
...
sshuttle/hostwatch.py
View file @
71d65f38
...
@@ -251,7 +251,7 @@ def _enqueue(op, *args):
...
@@ -251,7 +251,7 @@ def _enqueue(op, *args):
def
_stdin_still_ok
(
timeout
):
def
_stdin_still_ok
(
timeout
):
r
,
w
,
x
=
select
.
select
([
sys
.
stdin
.
fileno
()],
[],
[],
timeout
)
r
,
_
,
_
=
select
.
select
([
sys
.
stdin
.
fileno
()],
[],
[],
timeout
)
if
r
:
if
r
:
b
=
os
.
read
(
sys
.
stdin
.
fileno
(),
4096
)
b
=
os
.
read
(
sys
.
stdin
.
fileno
(),
4096
)
if
not
b
:
if
not
b
:
...
...
sshuttle/methods/__init__.py
View file @
71d65f38
...
@@ -74,7 +74,8 @@ class BaseMethod(object):
...
@@ -74,7 +74,8 @@ class BaseMethod(object):
"Feature
%
s not supported with method
%
s.
\n
"
%
"Feature
%
s not supported with method
%
s.
\n
"
%
(
key
,
self
.
name
))
(
key
,
self
.
name
))
def
setup_firewall
(
self
,
port
,
dnsport
,
nslist
,
family
,
subnets
,
udp
,
user
):
def
setup_firewall
(
self
,
port
,
dnsport
,
nslist
,
family
,
subnets
,
udp
,
user
):
raise
NotImplementedError
()
raise
NotImplementedError
()
def
restore_firewall
(
self
,
port
,
family
,
udp
,
user
):
def
restore_firewall
(
self
,
port
,
family
,
udp
,
user
):
...
...
sshuttle/methods/ipfw.py
View file @
71d65f38
import
os
import
os
import
sys
import
struct
import
subprocess
as
ssubprocess
import
subprocess
as
ssubprocess
from
sshuttle.methods
import
BaseMethod
from
sshuttle.methods
import
BaseMethod
from
sshuttle.helpers
import
log
,
debug1
,
debug3
,
\
from
sshuttle.helpers
import
log
,
debug1
,
debug3
,
\
...
@@ -31,9 +29,9 @@ IPV6_RECVDSTADDR = 74
...
@@ -31,9 +29,9 @@ IPV6_RECVDSTADDR = 74
if
recvmsg
==
"python"
:
if
recvmsg
==
"python"
:
def
recv_udp
(
listener
,
bufsize
):
def
recv_udp
(
listener
,
bufsize
):
debug3
(
'Accept UDP python using recvmsg.
\n
'
)
debug3
(
'Accept UDP python using recvmsg.
\n
'
)
data
,
ancdata
,
msg_flags
,
srcip
=
listener
.
recvmsg
(
4096
,
socket
.
CMSG_SPACE
(
4
))
data
,
ancdata
,
_
,
srcip
=
\
listener
.
recvmsg
(
4096
,
socket
.
CMSG_SPACE
(
4
))
dstip
=
None
dstip
=
None
family
=
None
for
cmsg_level
,
cmsg_type
,
cmsg_data
in
ancdata
:
for
cmsg_level
,
cmsg_type
,
cmsg_data
in
ancdata
:
if
cmsg_level
==
socket
.
SOL_IP
and
cmsg_type
==
IP_RECVDSTADDR
:
if
cmsg_level
==
socket
.
SOL_IP
and
cmsg_type
==
IP_RECVDSTADDR
:
port
=
53
port
=
53
...
@@ -44,13 +42,13 @@ if recvmsg == "python":
...
@@ -44,13 +42,13 @@ if recvmsg == "python":
elif
recvmsg
==
"socket_ext"
:
elif
recvmsg
==
"socket_ext"
:
def
recv_udp
(
listener
,
bufsize
):
def
recv_udp
(
listener
,
bufsize
):
debug3
(
'Accept UDP using socket_ext recvmsg.
\n
'
)
debug3
(
'Accept UDP using socket_ext recvmsg.
\n
'
)
srcip
,
data
,
adata
,
flags
=
listener
.
recvmsg
((
bufsize
,),
socket
.
CMSG_SPACE
(
4
))
srcip
,
data
,
adata
,
_
=
\
listener
.
recvmsg
((
bufsize
,),
socket
.
CMSG_SPACE
(
4
))
dstip
=
None
dstip
=
None
family
=
None
for
a
in
adata
:
for
a
in
adata
:
if
a
.
cmsg_level
==
socket
.
SOL_IP
and
a
.
cmsg_type
==
IP_RECVDSTADDR
:
if
a
.
cmsg_level
==
socket
.
SOL_IP
and
a
.
cmsg_type
==
IP_RECVDSTADDR
:
port
=
53
port
=
53
ip
=
socket
.
inet_ntop
(
socket
.
AF_INET
,
cmsg_data
[
0
:
4
])
ip
=
socket
.
inet_ntop
(
socket
.
AF_INET
,
a
.
cmsg_data
[
0
:
4
])
dstip
=
(
ip
,
port
)
dstip
=
(
ip
,
port
)
break
break
return
(
srcip
,
dstip
,
data
[
0
])
return
(
srcip
,
dstip
,
data
[
0
])
...
@@ -193,7 +191,8 @@ class Method(BaseMethod):
...
@@ -193,7 +191,8 @@ class Method(BaseMethod):
#if udp_listener.v6 is not None:
#if udp_listener.v6 is not None:
# udp_listener.v6.setsockopt(SOL_IPV6, IPV6_RECVDSTADDR, 1)
# udp_listener.v6.setsockopt(SOL_IPV6, IPV6_RECVDSTADDR, 1)
def
setup_firewall
(
self
,
port
,
dnsport
,
nslist
,
family
,
subnets
,
udp
,
user
):
def
setup_firewall
(
self
,
port
,
dnsport
,
nslist
,
family
,
subnets
,
udp
,
user
):
# IPv6 not supported
# IPv6 not supported
if
family
not
in
[
socket
.
AF_INET
]:
if
family
not
in
[
socket
.
AF_INET
]:
raise
Exception
(
raise
Exception
(
...
@@ -224,7 +223,7 @@ class Method(BaseMethod):
...
@@ -224,7 +223,7 @@ class Method(BaseMethod):
ipfw_noexit
(
'table'
,
'124'
,
'flush'
)
ipfw_noexit
(
'table'
,
'124'
,
'flush'
)
dnscount
=
0
dnscount
=
0
for
f
,
ip
in
[
i
for
i
in
nslist
if
i
[
0
]
==
family
]:
for
_
,
ip
in
[
i
for
i
in
nslist
if
i
[
0
]
==
family
]:
ipfw
(
'table'
,
'124'
,
'add'
,
'
%
s'
%
(
ip
))
ipfw
(
'table'
,
'124'
,
'add'
,
'
%
s'
%
(
ip
))
dnscount
+=
1
dnscount
+=
1
if
dnscount
>
0
:
if
dnscount
>
0
:
...
@@ -232,15 +231,6 @@ class Method(BaseMethod):
...
@@ -232,15 +231,6 @@ class Method(BaseMethod):
'udp'
,
'udp'
,
'from'
,
'any'
,
'to'
,
'table(124)'
,
'from'
,
'any'
,
'to'
,
'table(124)'
,
'not'
,
'ipttl'
,
'42'
)
'not'
,
'ipttl'
,
'42'
)
"""if udp:
ipfw('add', '1', 'skipto', '2',
'udp',
'from', 'any', 'to', 'table(125)')
ipfw('add', '1', 'fwd', '127.0.0.1,
%
d'
%
port,
'udp',
'from', 'any', 'to', 'table(126)',
'not', 'ipttl', '42')
"""
ipfw
(
'add'
,
'1'
,
'allow'
,
ipfw
(
'add'
,
'1'
,
'allow'
,
'udp'
,
'udp'
,
'from'
,
'any'
,
'to'
,
'any'
,
'from'
,
'any'
,
'to'
,
'any'
,
...
@@ -248,7 +238,7 @@ class Method(BaseMethod):
...
@@ -248,7 +238,7 @@ class Method(BaseMethod):
if
subnets
:
if
subnets
:
# create new subnet entries
# create new subnet entries
for
f
,
swidth
,
sexclude
,
snet
\
for
_
,
swidth
,
sexclude
,
snet
\
in
sorted
(
subnets
,
key
=
lambda
s
:
s
[
1
],
reverse
=
True
):
in
sorted
(
subnets
,
key
=
lambda
s
:
s
[
1
],
reverse
=
True
):
if
sexclude
:
if
sexclude
:
ipfw
(
'table'
,
'125'
,
'add'
,
'
%
s/
%
s'
%
(
snet
,
swidth
))
ipfw
(
'table'
,
'125'
,
'add'
,
'
%
s/
%
s'
%
(
snet
,
swidth
))
...
@@ -265,4 +255,3 @@ class Method(BaseMethod):
...
@@ -265,4 +255,3 @@ class Method(BaseMethod):
ipfw_noexit
(
'table'
,
'124'
,
'flush'
)
ipfw_noexit
(
'table'
,
'124'
,
'flush'
)
ipfw_noexit
(
'table'
,
'125'
,
'flush'
)
ipfw_noexit
(
'table'
,
'125'
,
'flush'
)
ipfw_noexit
(
'table'
,
'126'
,
'flush'
)
ipfw_noexit
(
'table'
,
'126'
,
'flush'
)
sshuttle/methods/nat.py
View file @
71d65f38
...
@@ -12,7 +12,8 @@ class Method(BaseMethod):
...
@@ -12,7 +12,8 @@ class Method(BaseMethod):
# the multiple copies shouldn't have overlapping subnets, or only the most-
# the multiple copies shouldn't have overlapping subnets, or only the most-
# recently-started one will win (because we use "-I OUTPUT 1" instead of
# recently-started one will win (because we use "-I OUTPUT 1" instead of
# "-A OUTPUT").
# "-A OUTPUT").
def
setup_firewall
(
self
,
port
,
dnsport
,
nslist
,
family
,
subnets
,
udp
,
user
):
def
setup_firewall
(
self
,
port
,
dnsport
,
nslist
,
family
,
subnets
,
udp
,
user
):
# only ipv4 supported with NAT
# only ipv4 supported with NAT
if
family
!=
socket
.
AF_INET
:
if
family
!=
socket
.
AF_INET
:
raise
Exception
(
raise
Exception
(
...
@@ -50,7 +51,7 @@ class Method(BaseMethod):
...
@@ -50,7 +51,7 @@ class Method(BaseMethod):
_ipt
(
'-I'
,
'PREROUTING'
,
'1'
,
*
args
)
_ipt
(
'-I'
,
'PREROUTING'
,
'1'
,
*
args
)
# create new subnet entries.
# create new subnet entries.
for
f
,
swidth
,
sexclude
,
snet
,
fport
,
lport
\
for
_
,
swidth
,
sexclude
,
snet
,
fport
,
lport
\
in
sorted
(
subnets
,
key
=
subnet_weight
,
reverse
=
True
):
in
sorted
(
subnets
,
key
=
subnet_weight
,
reverse
=
True
):
tcp_ports
=
(
'-p'
,
'tcp'
)
tcp_ports
=
(
'-p'
,
'tcp'
)
if
fport
:
if
fport
:
...
@@ -65,7 +66,7 @@ class Method(BaseMethod):
...
@@ -65,7 +66,7 @@ class Method(BaseMethod):
'--dest'
,
'
%
s/
%
s'
%
(
snet
,
swidth
),
'--dest'
,
'
%
s/
%
s'
%
(
snet
,
swidth
),
*
(
tcp_ports
+
(
'--to-ports'
,
str
(
port
))))
*
(
tcp_ports
+
(
'--to-ports'
,
str
(
port
))))
for
f
,
ip
in
[
i
for
i
in
nslist
if
i
[
0
]
==
family
]:
for
_
,
ip
in
[
i
for
i
in
nslist
if
i
[
0
]
==
family
]:
_ipt_ttl
(
'-A'
,
chain
,
'-j'
,
'REDIRECT'
,
_ipt_ttl
(
'-A'
,
chain
,
'-j'
,
'REDIRECT'
,
'--dest'
,
'
%
s/32'
%
ip
,
'--dest'
,
'
%
s/32'
%
ip
,
'-p'
,
'udp'
,
'-p'
,
'udp'
,
...
@@ -97,8 +98,8 @@ class Method(BaseMethod):
...
@@ -97,8 +98,8 @@ class Method(BaseMethod):
# basic cleanup/setup of chains
# basic cleanup/setup of chains
if
ipt_chain_exists
(
family
,
table
,
chain
):
if
ipt_chain_exists
(
family
,
table
,
chain
):
if
user
is
not
None
:
if
user
is
not
None
:
nonfatal
(
_ipm
,
'-D'
,
'OUTPUT'
,
'-m'
,
'owner'
,
'--uid-owner'
,
str
(
user
),
nonfatal
(
_ipm
,
'-D'
,
'OUTPUT'
,
'-m'
,
'owner'
,
'--uid-owner'
,
'-j'
,
'MARK'
,
'--set-mark'
,
str
(
port
))
str
(
user
),
'-j'
,
'MARK'
,
'--set-mark'
,
str
(
port
))
args
=
'-m'
,
'mark'
,
'--mark'
,
str
(
port
),
'-j'
,
chain
args
=
'-m'
,
'mark'
,
'--mark'
,
str
(
port
),
'-j'
,
chain
else
:
else
:
args
=
'-j'
,
chain
args
=
'-j'
,
chain
...
...
sshuttle/methods/pf.py
View file @
71d65f38
...
@@ -115,14 +115,14 @@ class Generic(object):
...
@@ -115,14 +115,14 @@ class Generic(object):
if
(
'
\n
anchor "
%
s"'
%
anchor
)
.
encode
(
'ASCII'
)
not
in
status
:
if
(
'
\n
anchor "
%
s"'
%
anchor
)
.
encode
(
'ASCII'
)
not
in
status
:
self
.
_add_anchor_rule
(
self
.
PF_PASS
,
anchor
.
encode
(
'ASCII'
))
self
.
_add_anchor_rule
(
self
.
PF_PASS
,
anchor
.
encode
(
'ASCII'
))
def
_add_anchor_rule
(
self
,
type
,
name
,
pr
=
None
):
def
_add_anchor_rule
(
self
,
kind
,
name
,
pr
=
None
):
if
pr
is
None
:
if
pr
is
None
:
pr
=
self
.
pfioc_rule
()
pr
=
self
.
pfioc_rule
()
memmove
(
addressof
(
pr
)
+
self
.
ANCHOR_CALL_OFFSET
,
name
,
memmove
(
addressof
(
pr
)
+
self
.
ANCHOR_CALL_OFFSET
,
name
,
min
(
self
.
MAXPATHLEN
,
len
(
name
)))
# anchor_call = name
min
(
self
.
MAXPATHLEN
,
len
(
name
)))
# anchor_call = name
memmove
(
addressof
(
pr
)
+
self
.
RULE_ACTION_OFFSET
,
memmove
(
addressof
(
pr
)
+
self
.
RULE_ACTION_OFFSET
,
struct
.
pack
(
'I'
,
type
),
4
)
# rule.action = type
struct
.
pack
(
'I'
,
kind
),
4
)
# rule.action = kind
memmove
(
addressof
(
pr
)
+
self
.
ACTION_OFFSET
,
struct
.
pack
(
memmove
(
addressof
(
pr
)
+
self
.
ACTION_OFFSET
,
struct
.
pack
(
'I'
,
self
.
PF_CHANGE_GET_TICKET
),
4
)
# action = PF_CHANGE_GET_TICKET
'I'
,
self
.
PF_CHANGE_GET_TICKET
),
4
)
# action = PF_CHANGE_GET_TICKET
...
@@ -176,9 +176,6 @@ class FreeBsd(Generic):
...
@@ -176,9 +176,6 @@ class FreeBsd(Generic):
freebsd
.
pfioc_natlook
=
pfioc_natlook
freebsd
.
pfioc_natlook
=
pfioc_natlook
return
freebsd
return
freebsd
def
__init__
(
self
):
super
(
FreeBsd
,
self
)
.
__init__
()
def
enable
(
self
):
def
enable
(
self
):
returncode
=
ssubprocess
.
call
([
'kldload'
,
'pf'
])
returncode
=
ssubprocess
.
call
([
'kldload'
,
'pf'
])
super
(
FreeBsd
,
self
)
.
enable
()
super
(
FreeBsd
,
self
)
.
enable
()
...
@@ -197,14 +194,14 @@ class FreeBsd(Generic):
...
@@ -197,14 +194,14 @@ class FreeBsd(Generic):
self
.
_add_anchor_rule
(
self
.
PF_RDR
,
anchor
.
encode
(
'ASCII'
))
self
.
_add_anchor_rule
(
self
.
PF_RDR
,
anchor
.
encode
(
'ASCII'
))
super
(
FreeBsd
,
self
)
.
add_anchors
(
anchor
,
status
=
status
)
super
(
FreeBsd
,
self
)
.
add_anchors
(
anchor
,
status
=
status
)
def
_add_anchor_rule
(
self
,
type
,
nam
e
):
def
_add_anchor_rule
(
self
,
kind
,
name
,
pr
=
Non
e
):
pr
=
self
.
pfioc_rule
()
pr
=
pr
or
self
.
pfioc_rule
()
ppa
=
self
.
pfioc_pooladdr
()
ppa
=
self
.
pfioc_pooladdr
()
ioctl
(
pf_get_dev
(),
self
.
DIOCBEGINADDRS
,
ppa
)
ioctl
(
pf_get_dev
(),
self
.
DIOCBEGINADDRS
,
ppa
)
# pool ticket
# pool ticket
memmove
(
addressof
(
pr
)
+
self
.
POOL_TICKET_OFFSET
,
ppa
[
4
:
8
],
4
)
memmove
(
addressof
(
pr
)
+
self
.
POOL_TICKET_OFFSET
,
ppa
[
4
:
8
],
4
)
super
(
FreeBsd
,
self
)
.
_add_anchor_rule
(
type
,
name
,
pr
=
pr
)
super
(
FreeBsd
,
self
)
.
_add_anchor_rule
(
kind
,
name
,
pr
=
pr
)
def
add_rules
(
self
,
anchor
,
includes
,
port
,
dnsport
,
nslist
,
family
):
def
add_rules
(
self
,
anchor
,
includes
,
port
,
dnsport
,
nslist
,
family
):
inet_version
=
self
.
_inet_version
(
family
)
inet_version
=
self
.
_inet_version
(
family
)
...
@@ -224,7 +221,7 @@ class FreeBsd(Generic):
...
@@ -224,7 +221,7 @@ class FreeBsd(Generic):
for
exclude
,
subnet
in
includes
for
exclude
,
subnet
in
includes
]
]
if
len
(
nslist
)
>
0
:
if
nslist
:
tables
.
append
(
tables
.
append
(
b
'table <dns_servers> {
%
s}'
%
b
'table <dns_servers> {
%
s}'
%
b
','
.
join
([
ns
[
1
]
.
encode
(
"ASCII"
)
for
ns
in
nslist
]))
b
','
.
join
([
ns
[
1
]
.
encode
(
"ASCII"
)
for
ns
in
nslist
]))
...
@@ -294,7 +291,7 @@ class OpenBsd(Generic):
...
@@ -294,7 +291,7 @@ class OpenBsd(Generic):
for
exclude
,
subnet
in
includes
for
exclude
,
subnet
in
includes
]
]
if
len
(
nslist
)
>
0
:
if
nslist
:
tables
.
append
(
tables
.
append
(
b
'table <dns_servers> {
%
s}'
%
b
'table <dns_servers> {
%
s}'
%
b
','
.
join
([
ns
[
1
]
.
encode
(
"ASCII"
)
for
ns
in
nslist
]))
b
','
.
join
([
ns
[
1
]
.
encode
(
"ASCII"
)
for
ns
in
nslist
]))
...
@@ -440,11 +437,8 @@ class Method(BaseMethod):
...
@@ -440,11 +437,8 @@ class Method(BaseMethod):
return
sock
.
getsockname
()
return
sock
.
getsockname
()
def
setup_firewall
(
self
,
port
,
dnsport
,
nslist
,
family
,
subnets
,
udp
,
user
):
def
setup_firewall
(
self
,
port
,
dnsport
,
nslist
,
family
,
subnets
,
udp
,
tables
=
[]
user
):
translating_rules
=
[]
filtering_rules
=
[]
if
family
not
in
[
socket
.
AF_INET
,
socket
.
AF_INET6
]:
if
family
not
in
[
socket
.
AF_INET
,
socket
.
AF_INET6
]:
raise
Exception
(
raise
Exception
(
'Address family "
%
s" unsupported by pf method_name'
'Address family "
%
s" unsupported by pf method_name'
...
@@ -452,12 +446,12 @@ class Method(BaseMethod):
...
@@ -452,12 +446,12 @@ class Method(BaseMethod):
if
udp
:
if
udp
:
raise
Exception
(
"UDP not supported by pf method_name"
)
raise
Exception
(
"UDP not supported by pf method_name"
)
if
len
(
subnets
)
>
0
:
if
subnets
:
includes
=
[]
includes
=
[]
# If a given subnet is both included and excluded, list the
# If a given subnet is both included and excluded, list the
# exclusion first; the table will ignore the second, opposite
# exclusion first; the table will ignore the second, opposite
# definition
# definition
for
f
,
swidth
,
sexclude
,
snet
,
fport
,
lport
\
for
_
,
swidth
,
sexclude
,
snet
,
fport
,
lport
\
in
sorted
(
subnets
,
key
=
subnet_weight
,
reverse
=
True
):
in
sorted
(
subnets
,
key
=
subnet_weight
,
reverse
=
True
):
includes
.
append
((
sexclude
,
b
"
%
s/
%
d
%
s"
%
(
includes
.
append
((
sexclude
,
b
"
%
s/
%
d
%
s"
%
(
snet
.
encode
(
"ASCII"
),
snet
.
encode
(
"ASCII"
),
...
...
sshuttle/methods/tproxy.py
View file @
71d65f38
...
@@ -33,7 +33,7 @@ IPV6_RECVORIGDSTADDR = IPV6_ORIGDSTADDR
...
@@ -33,7 +33,7 @@ IPV6_RECVORIGDSTADDR = IPV6_ORIGDSTADDR
if
recvmsg
==
"python"
:
if
recvmsg
==
"python"
:
def
recv_udp
(
listener
,
bufsize
):
def
recv_udp
(
listener
,
bufsize
):
debug3
(
'Accept UDP python using recvmsg.
\n
'
)
debug3
(
'Accept UDP python using recvmsg.
\n
'
)
data
,
ancdata
,
msg_flags
,
srcip
=
listener
.
recvmsg
(
data
,
ancdata
,
_
,
srcip
=
listener
.
recvmsg
(
4096
,
socket
.
CMSG_SPACE
(
24
))
4096
,
socket
.
CMSG_SPACE
(
24
))
dstip
=
None
dstip
=
None
family
=
None
family
=
None
...
@@ -64,7 +64,7 @@ if recvmsg == "python":
...
@@ -64,7 +64,7 @@ if recvmsg == "python":
elif
recvmsg
==
"socket_ext"
:
elif
recvmsg
==
"socket_ext"
:
def
recv_udp
(
listener
,
bufsize
):
def
recv_udp
(
listener
,
bufsize
):
debug3
(
'Accept UDP using socket_ext recvmsg.
\n
'
)
debug3
(
'Accept UDP using socket_ext recvmsg.
\n
'
)
srcip
,
data
,
adata
,
flags
=
listener
.
recvmsg
(
srcip
,
data
,
adata
,
_
=
listener
.
recvmsg
(
(
bufsize
,),
socket
.
CMSG_SPACE
(
24
))
(
bufsize
,),
socket
.
CMSG_SPACE
(
24
))
dstip
=
None
dstip
=
None
family
=
None
family
=
None
...
@@ -150,7 +150,8 @@ class Method(BaseMethod):
...
@@ -150,7 +150,8 @@ class Method(BaseMethod):
if
udp_listener
.
v6
is
not
None
:
if
udp_listener
.
v6
is
not
None
:
udp_listener
.
v6
.
setsockopt
(
SOL_IPV6
,
IPV6_RECVORIGDSTADDR
,
1
)
udp_listener
.
v6
.
setsockopt
(
SOL_IPV6
,
IPV6_RECVORIGDSTADDR
,
1
)
def
setup_firewall
(
self
,
port
,
dnsport
,
nslist
,
family
,
subnets
,
udp
,
user
):
def
setup_firewall
(
self
,
port
,
dnsport
,
nslist
,
family
,
subnets
,
udp
,
user
):
if
family
not
in
[
socket
.
AF_INET
,
socket
.
AF_INET6
]:
if
family
not
in
[
socket
.
AF_INET
,
socket
.
AF_INET6
]:
raise
Exception
(
raise
Exception
(
'Address family "
%
s" unsupported by tproxy method'
'Address family "
%
s" unsupported by tproxy method'
...
@@ -193,7 +194,7 @@ class Method(BaseMethod):
...
@@ -193,7 +194,7 @@ class Method(BaseMethod):
_ipt
(
'-A'
,
tproxy_chain
,
'-m'
,
'socket'
,
'-j'
,
divert_chain
,
_ipt
(
'-A'
,
tproxy_chain
,
'-m'
,
'socket'
,
'-j'
,
divert_chain
,
'-m'
,
'udp'
,
'-p'
,
'udp'
)
'-m'
,
'udp'
,
'-p'
,
'udp'
)
for
f
,
ip
in
[
i
for
i
in
nslist
if
i
[
0
]
==
family
]:
for
_
,
ip
in
[
i
for
i
in
nslist
if
i
[
0
]
==
family
]:
_ipt
(
'-A'
,
mark_chain
,
'-j'
,
'MARK'
,
'--set-mark'
,
'1'
,
_ipt
(
'-A'
,
mark_chain
,
'-j'
,
'MARK'
,
'--set-mark'
,
'1'
,
'--dest'
,
'
%
s/32'
%
ip
,
'--dest'
,
'
%
s/32'
%
ip
,
'-m'
,
'udp'
,
'-p'
,
'udp'
,
'--dport'
,
'53'
)
'-m'
,
'udp'
,
'-p'
,
'udp'
,
'--dport'
,
'53'
)
...
@@ -203,7 +204,7 @@ class Method(BaseMethod):
...
@@ -203,7 +204,7 @@ class Method(BaseMethod):
'-m'
,
'udp'
,
'-p'
,
'udp'
,
'--dport'
,
'53'
,
'-m'
,
'udp'
,
'-p'
,
'udp'
,
'--dport'
,
'53'
,
'--on-port'
,
str
(
dnsport
))
'--on-port'
,
str
(
dnsport
))
for
f
,
swidth
,
sexclude
,
snet
,
fport
,
lport
\
for
_
,
swidth
,
sexclude
,
snet
,
fport
,
lport
\
in
sorted
(
subnets
,
key
=
subnet_weight
,
reverse
=
True
):
in
sorted
(
subnets
,
key
=
subnet_weight
,
reverse
=
True
):
tcp_ports
=
(
'-p'
,
'tcp'
)
tcp_ports
=
(
'-p'
,
'tcp'
)
tcp_ports
=
_ipt_proto_ports
(
tcp_ports
,
fport
,
lport
)
tcp_ports
=
_ipt_proto_ports
(
tcp_ports
,
fport
,
lport
)
...
...
sshuttle/options.py
View file @
71d65f38
...
@@ -13,9 +13,9 @@ def parse_subnetport_file(s):
...
@@ -13,9 +13,9 @@ def parse_subnetport_file(s):
raw_config_lines
=
handle
.
readlines
()
raw_config_lines
=
handle
.
readlines
()
subnets
=
[]
subnets
=
[]
for
line_no
,
line
in
enumerate
(
raw_config_lines
):
for
_
,
line
in
enumerate
(
raw_config_lines
):
line
=
line
.
strip
()
line
=
line
.
strip
()
if
len
(
line
)
==
0
:
if
not
line
:
continue
continue
if
line
[
0
]
==
'#'
:
if
line
[
0
]
==
'#'
:
continue
continue
...
@@ -81,8 +81,8 @@ def parse_ipport(s):
...
@@ -81,8 +81,8 @@ def parse_ipport(s):
return
(
family
,)
+
addr
[:
2
]
return
(
family
,)
+
addr
[:
2
]
def
parse_list
(
l
i
st
):
def
parse_list
(
lst
):
return
re
.
split
(
r'[\s,]+'
,
l
ist
.
strip
())
if
li
st
else
[]
return
re
.
split
(
r'[\s,]+'
,
l
st
.
strip
())
if
l
st
else
[]
class
Concat
(
Action
):
class
Concat
(
Action
):
...
@@ -120,7 +120,8 @@ parser.add_argument(
...
@@ -120,7 +120,8 @@ parser.add_argument(
"-H"
,
"--auto-hosts"
,
"-H"
,
"--auto-hosts"
,
action
=
"store_true"
,
action
=
"store_true"
,
help
=
"""
help
=
"""
continuously scan for remote hostnames and update local /etc/hosts as they are found
continuously scan for remote hostnames and update local /etc/hosts as
they are found
"""
"""
)
)
parser
.
add_argument
(
parser
.
add_argument
(
...
@@ -151,7 +152,8 @@ parser.add_argument(
...
@@ -151,7 +152,8 @@ parser.add_argument(
metavar
=
"IP[:PORT]"
,
metavar
=
"IP[:PORT]"
,
type
=
parse_ipport
,
type
=
parse_ipport
,
help
=
"""
help
=
"""
the DNS server to forward requests to; defaults to servers in /etc/resolv.conf on remote side if not given.
the DNS server to forward requests to; defaults to servers in
/etc/resolv.conf on remote side if not given.
"""
"""
)
)
...
@@ -227,7 +229,8 @@ parser.add_argument(
...
@@ -227,7 +229,8 @@ parser.add_argument(
metavar
=
"HOSTNAME[,HOSTNAME]"
,
metavar
=
"HOSTNAME[,HOSTNAME]"
,
default
=
[],
default
=
[],
help
=
"""
help
=
"""
comma-separated list of hostnames for initial scan (may be used with or without --auto-hosts)
comma-separated list of hostnames for initial scan (may be used with
or without --auto-hosts)
"""
"""
)
)
parser
.
add_argument
(
parser
.
add_argument
(
...
...
sshuttle/sdnotify.py
View file @
71d65f38
sshuttle/ssh.py
View file @
71d65f38
...
@@ -69,7 +69,7 @@ def connect(ssh_cmd, rhostport, python, stderr, options):
...
@@ -69,7 +69,7 @@ def connect(ssh_cmd, rhostport, python, stderr, options):
rhost
=
result
[
0
]
.
strip
(
'['
)
rhost
=
result
[
0
]
.
strip
(
'['
)
if
len
(
result
)
>
1
:
if
len
(
result
)
>
1
:
result
[
1
]
=
result
[
1
]
.
strip
(
':'
)
result
[
1
]
=
result
[
1
]
.
strip
(
':'
)
if
result
[
1
]
is
not
''
:
if
result
[
1
]
!=
''
:
portl
=
[
'-p'
,
str
(
int
(
result
[
1
]))]
portl
=
[
'-p'
,
str
(
int
(
result
[
1
]))]
# can't disambiguate IPv6 colons and a port number. pass the hostname
# can't disambiguate IPv6 colons and a port number. pass the hostname
# through.
# through.
...
...
sshuttle/ssnet.py
View file @
71d65f38
...
@@ -271,7 +271,7 @@ class Handler:
...
@@ -271,7 +271,7 @@ class Handler:
def
callback
(
self
,
sock
):
def
callback
(
self
,
sock
):
log
(
'--no callback defined--
%
r
\n
'
%
self
)
log
(
'--no callback defined--
%
r
\n
'
%
self
)
(
r
,
w
,
x
)
=
select
.
select
(
self
.
socks
,
[],
[],
0
)
(
r
,
_
,
_
)
=
select
.
select
(
self
.
socks
,
[],
[],
0
)
for
s
in
r
:
for
s
in
r
:
v
=
s
.
recv
(
4096
)
v
=
s
.
recv
(
4096
)
if
not
v
:
if
not
v
:
...
@@ -350,7 +350,7 @@ class Mux(Handler):
...
@@ -350,7 +350,7 @@ class Mux(Handler):
def
next_channel
(
self
):
def
next_channel
(
self
):
# channel 0 is special, so we never allocate it
# channel 0 is special, so we never allocate it
for
timeout
in
range
(
1024
):
for
_
in
range
(
1024
):
self
.
chani
+=
1
self
.
chani
+=
1
if
self
.
chani
>
MAX_CHANNEL
:
if
self
.
chani
>
MAX_CHANNEL
:
self
.
chani
=
1
self
.
chani
=
1
...
@@ -479,7 +479,7 @@ class Mux(Handler):
...
@@ -479,7 +479,7 @@ class Mux(Handler):
_add
(
w
,
self
.
wsock
)
_add
(
w
,
self
.
wsock
)
def
callback
(
self
,
sock
):
def
callback
(
self
,
sock
):
(
r
,
w
,
x
)
=
select
.
select
([
self
.
rsock
],
[
self
.
wsock
],
[],
0
)
(
r
,
w
,
_
)
=
select
.
select
([
self
.
rsock
],
[
self
.
wsock
],
[],
0
)
if
self
.
rsock
in
r
:
if
self
.
rsock
in
r
:
self
.
handle
()
self
.
handle
()
if
self
.
outbuf
and
self
.
wsock
in
w
:
if
self
.
outbuf
and
self
.
wsock
in
w
:
...
...
sshuttle/tests/client/test_options.py
View file @
71d65f38
...
@@ -51,7 +51,7 @@ def test_parse_subnetport_ip4_with_port():
...
@@ -51,7 +51,7 @@ def test_parse_subnetport_ip4_with_port():
for
ip_repr
,
ip
in
_ip4_reprs
.
items
():
for
ip_repr
,
ip
in
_ip4_reprs
.
items
():
assert
sshuttle
.
options
.
parse_subnetport
(
':'
.
join
((
ip_repr
,
'80'
)))
\
assert
sshuttle
.
options
.
parse_subnetport
(
':'
.
join
((
ip_repr
,
'80'
)))
\
==
(
socket
.
AF_INET
,
ip
,
32
,
80
,
80
)
==
(
socket
.
AF_INET
,
ip
,
32
,
80
,
80
)
assert
sshuttle
.
options
.
parse_subnetport
(
':'
.
join
((
ip_repr
,
'80-90'
)))
\
assert
sshuttle
.
options
.
parse_subnetport
(
':'
.
join
((
ip_repr
,
'80-90'
)))
\
==
(
socket
.
AF_INET
,
ip
,
32
,
80
,
90
)
==
(
socket
.
AF_INET
,
ip
,
32
,
80
,
90
)
...
@@ -97,5 +97,5 @@ def test_parse_subnetport_ip6_with_mask_and_port():
...
@@ -97,5 +97,5 @@ def test_parse_subnetport_ip6_with_mask_and_port():
for
ip_repr
,
ip
in
_ip6_reprs
.
items
():
for
ip_repr
,
ip
in
_ip6_reprs
.
items
():
assert
sshuttle
.
options
.
parse_subnetport
(
'['
+
ip_repr
+
'/128]:80'
)
\
assert
sshuttle
.
options
.
parse_subnetport
(
'['
+
ip_repr
+
'/128]:80'
)
\
==
(
socket
.
AF_INET6
,
ip
,
128
,
80
,
80
)
==
(
socket
.
AF_INET6
,
ip
,
128
,
80
,
80
)
assert
sshuttle
.
options
.
parse_subnetport
(
'['
+
ip_repr
+
'/16]:80-90'
)
\
assert
sshuttle
.
options
.
parse_subnetport
(
'['
+
ip_repr
+
'/16]:80-90'
)
\
==
(
socket
.
AF_INET6
,
ip
,
16
,
80
,
90
)
==
(
socket
.
AF_INET6
,
ip
,
16
,
80
,
90
)
sshuttle/tests/client/test_sdnotify.py
View file @
71d65f38
from
mock
import
Mock
,
patch
,
call
from
mock
import
Mock
,
patch
,
call
import
sys
import
io
import
socket
import
socket
import
sshuttle.sdnotify
import
sshuttle.sdnotify
...
...
sshuttle/tests/server/test_server.py
View file @
71d65f38
import
os
import
io
import
io
import
socket
import
socket
import
sshuttle.server
import
sshuttle.server
from
mock
import
patch
,
Mock
,
call
from
mock
import
patch
,
Mock
def
test__ipmatch
():
def
test__ipmatch
():
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment