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
1874aace
Commit
1874aace
authored
Mar 21, 2015
by
Sean Zeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refine firewall initlization
parent
4c31bc02
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
15 deletions
+31
-15
firewall.py
src/firewall.py
+31
-15
No files found.
src/firewall.py
View file @
1874aace
...
@@ -10,7 +10,8 @@ import os
...
@@ -10,7 +10,8 @@ import os
from
helpers
import
log
,
debug1
,
debug3
,
islocal
,
Fatal
,
family_to_string
,
\
from
helpers
import
log
,
debug1
,
debug3
,
islocal
,
Fatal
,
family_to_string
,
\
resolvconf_nameservers
resolvconf_nameservers
from
fcntl
import
ioctl
from
fcntl
import
ioctl
from
ctypes
import
c_char
,
c_uint8
,
c_uint16
,
c_uint32
,
Union
,
Structure
,
sizeof
,
addressof
,
memmove
from
ctypes
import
c_char
,
c_uint8
,
c_uint16
,
c_uint32
,
Union
,
Structure
,
\
sizeof
,
addressof
,
memmove
# python doesn't have a definition for this
# python doesn't have a definition for this
...
@@ -466,23 +467,28 @@ def do_ipfw(port, dnsport, family, subnets, udp):
...
@@ -466,23 +467,28 @@ def do_ipfw(port, dnsport, family, subnets, udp):
return
do_wait
return
do_wait
def
pfctl
(
*
args
):
def
pfctl
(
args
,
stdin
=
None
):
argv
=
[
'pfctl'
]
+
list
(
args
)
argv
=
[
'pfctl'
]
+
list
(
args
.
split
(
" "
))
debug1
(
'>>
%
s
\n
'
%
' '
.
join
(
argv
))
debug1
(
'>>
%
s, stdin:
%
s
\n
'
%
(
' '
.
join
(
argv
),
stdin
))
rv
=
ssubprocess
.
Popen
(
argv
,
stderr
=
ssubprocess
.
PIPE
)
.
wait
()
if
rv
:
raise
Fatal
(
'
%
r returned
%
d'
%
(
argv
,
rv
))
p
=
ssubprocess
.
Popen
(
argv
,
stdin
=
ssubprocess
.
PIPE
,
stdout
=
ssubprocess
.
PIPE
,
stderr
=
ssubprocess
.
PIPE
)
o
=
p
.
communicate
(
stdin
)
if
p
.
returncode
:
raise
Fatal
(
'
%
r returned
%
d'
%
(
argv
,
p
.
returncode
))
return
o
_pf_started_by_sshuttle
=
False
def
do_pf
(
port
,
dnsport
,
family
,
subnets
,
udp
):
def
do_pf
(
port
,
dnsport
,
family
,
subnets
,
udp
):
global
_pf_started_by_sshuttle
tables
=
[]
tables
=
[]
translating_rules
=
[]
translating_rules
=
[]
filtering_rules
=
[]
filtering_rules
=
[]
if
subnets
:
if
subnets
:
pf_add_anchor_rule
(
PF_PASS
,
"sshuttle"
)
pf_add_anchor_rule
(
PF_RDR
,
"sshuttle"
)
include_subnets
=
filter
(
lambda
s
:
not
s
[
2
],
sorted
(
subnets
,
reverse
=
True
))
include_subnets
=
filter
(
lambda
s
:
not
s
[
2
],
sorted
(
subnets
,
reverse
=
True
))
if
include_subnets
:
if
include_subnets
:
tables
.
append
(
'table <include_subnets> {
%
s}'
%
','
.
join
([
"
%
s/
%
s"
%
(
n
[
3
],
n
[
1
])
for
n
in
include_subnets
]))
tables
.
append
(
'table <include_subnets> {
%
s}'
%
','
.
join
([
"
%
s/
%
s"
%
(
n
[
3
],
n
[
1
])
for
n
in
include_subnets
]))
...
@@ -500,13 +506,23 @@ def do_pf(port, dnsport, family, subnets, udp):
...
@@ -500,13 +506,23 @@ def do_pf(port, dnsport, family, subnets, udp):
translating_rules
.
append
(
'rdr pass on lo0 proto udp to <dns_servers> port 53 -> 127.0.0.1 port
%
r'
%
dnsport
)
translating_rules
.
append
(
'rdr pass on lo0 proto udp to <dns_servers> port 53 -> 127.0.0.1 port
%
r'
%
dnsport
)
filtering_rules
.
append
(
'pass out route-to lo0 inet proto udp to <dns_servers> port 53 keep state'
)
filtering_rules
.
append
(
'pass out route-to lo0 inet proto udp to <dns_servers> port 53 keep state'
)
pf_config_file
=
'/etc/pf-sshuttle.conf'
rules
=
'
\n
'
.
join
(
tables
+
translating_rules
+
filtering_rules
)
+
'
\n
'
with
open
(
pf_config_file
,
'w+'
)
as
f
:
f
.
write
(
'
\n
'
.
join
(
tables
+
translating_rules
+
filtering_rules
)
+
'
\n
'
)
pf_status
=
pfctl
(
'-s all'
)[
0
]
if
not
'
\n
rdr-anchor "sshuttle" all
\n
'
in
pf_status
:
pf_add_anchor_rule
(
PF_RDR
,
"sshuttle"
)
if
not
'
\n
anchor "sshuttle" all
\n
'
in
pf_status
:
pf_add_anchor_rule
(
PF_PASS
,
"sshuttle"
)
if
not
'INFO:
\n
Status: Enabled'
in
pf_status
:
pfctl
(
'-e'
)
_pf_started_by_sshuttle
=
True
pfctl
(
'-
E'
,
'-a'
,
'sshuttle'
,
'-f'
,
pf_config_file
)
pfctl
(
'-
a sshuttle -f /dev/stdin'
,
rules
)
else
:
else
:
pfctl
(
'-a'
,
'sshuttle'
,
'-F'
,
'all'
)
pfctl
(
'-a sshuttle -F all'
)
if
_pf_started_by_sshuttle
:
pfctl
(
'-d'
)
def
program_exists
(
name
):
def
program_exists
(
name
):
...
...
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