spior 0.3.6 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/.github/workflows/gem-push.yml +48 -0
- data/CHANGELOG.md +15 -0
- data/README.md +29 -5
- data/bin/spior +41 -1
- data/lib/auth.rb +7 -1
- data/lib/spior/dep.rb +22 -20
- data/lib/spior/helpers.rb +34 -8
- data/lib/spior/iptables/rules.rb +9 -57
- data/lib/spior/ipv6.rb +20 -14
- data/lib/spior/options.rb +0 -54
- data/lib/spior/service/enable.rb +49 -11
- data/lib/spior/service/restart.rb +13 -3
- data/lib/spior/status.rb +2 -0
- data/lib/spior/tor/config.rb +5 -25
- data/lib/spior/tor/data.rb +2 -0
- data/lib/spior/tor/start.rb +4 -10
- data/lib/spior/version.rb +1 -1
- data/lib/spior.rb +0 -15
- data/spior.gemspec +5 -5
- data.tar.gz.sig +0 -0
- metadata +7 -6
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35ecc00833e5ba627984058a35375d1773ebdb707fb9218bb5060029d91a08a8
|
4
|
+
data.tar.gz: d688befe355c53c3af9bdf110144f3d91f9a9f2c254b6a5b0ea995f8beec85ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df077eb2f83b2b084a2a78378fe1f46d5b8f47fc9482a60e980250fed407e4e662d9c14abe9e8880a3fb0307ad40e1be9e465a4e0ba9bf70bca082ce7b150401
|
7
|
+
data.tar.gz: 703939ff956cf9601aa367be2e28c987e63b3a8e5560318e7c16eb02ce5d956604a96b71270454d1d9de36fa7f26ade4ac463a2ab7ca0a67e644a6e57cafb41d
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -0,0 +1,48 @@
|
|
1
|
+
name: Ruby Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ "master" ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ "master" ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
build:
|
11
|
+
name: Build + Publish
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
permissions:
|
14
|
+
contents: read
|
15
|
+
packages: write
|
16
|
+
|
17
|
+
steps:
|
18
|
+
- uses: actions/checkout@v4
|
19
|
+
- name: Set up Ruby 2.6
|
20
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
21
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
22
|
+
# uses: ruby/setup-ruby@v1
|
23
|
+
uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0
|
24
|
+
with:
|
25
|
+
ruby-version: 2.6.10
|
26
|
+
|
27
|
+
- name: Publish to GPR
|
28
|
+
run: |
|
29
|
+
mkdir -p $HOME/.gem
|
30
|
+
touch $HOME/.gem/credentials
|
31
|
+
chmod 0600 $HOME/.gem/credentials
|
32
|
+
printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
33
|
+
gem build *.gemspec
|
34
|
+
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
|
35
|
+
env:
|
36
|
+
GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
|
37
|
+
OWNER: ${{ github.repository_owner }}
|
38
|
+
|
39
|
+
# - name: Publish to RubyGems
|
40
|
+
# run: |
|
41
|
+
# mkdir -p $HOME/.gem
|
42
|
+
# touch $HOME/.gem/credentials
|
43
|
+
# chmod 0600 $HOME/.gem/credentials
|
44
|
+
# printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
45
|
+
# gem build *.gemspec
|
46
|
+
# gem push *.gem
|
47
|
+
# env:
|
48
|
+
# GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
## 0.5.0, release 2024-10
|
2
|
+
* Correct runtime with openrc on Gentoo
|
3
|
+
* Remove a lots of old codes.
|
4
|
+
* Correct `root`, `doas` or `sudo` detection.
|
5
|
+
* For Debian, enable iptables-legacy instead of nftables, see
|
6
|
+
https://wiki.debian.org/iptables (you need to use `spior -i`).
|
7
|
+
* Persist Mode on Debian add a script under /etc/network/if-pre-up.d/iptables
|
8
|
+
like in the doc.
|
9
|
+
|
10
|
+
## 0.3.7, release 2023-10-27
|
11
|
+
* Persist mode may require manual intervention to work, look the [readme](https://github.com/szorfein/spior/tree/master#left-over)
|
12
|
+
* Persist and runtime corrected on Voidlinux.
|
13
|
+
* Spior check the presence of 'simple_firewall.rules' when you use the --clearnet
|
14
|
+
* Create a `/etc/sysctl.d/40-ipv6.conf` with the persist mode in order to block ipv6 at boot.
|
15
|
+
|
1
16
|
## 0.3.5, release 2023-10-26
|
2
17
|
* Better code style, only 11 alerts from rubocop.
|
3
18
|
* spior -t also block ipv6 traffic, no need to reboot.
|
data/README.md
CHANGED
@@ -4,13 +4,12 @@
|
|
4
4
|
<br/>
|
5
5
|
|
6
6
|
[![Gem Version](https://badge.fury.io/rb/spior.svg)](https://badge.fury.io/rb/spior)
|
7
|
-
![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/szorfein/spior/Rubocop/
|
7
|
+
![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/szorfein/spior/Rubocop/devel)
|
8
8
|
[![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop/rubocop)
|
9
9
|
![GitHub](https://img.shields.io/github/license/szorfein/spior)
|
10
10
|
|
11
11
|
</div>
|
12
12
|
|
13
|
-
|
14
13
|
(Spider|Tor) A tool to redirect all your local traffic to the [Tor](https://www.torproject.org/) network.
|
15
14
|
|
16
15
|
## Install
|
@@ -31,6 +30,20 @@ Spior use `iptables` and `tor`, which can be installed with (if your distro is s
|
|
31
30
|
|
32
31
|
$ spior --install
|
33
32
|
|
33
|
+
## Configuration
|
34
|
+
Spior look the /etc/tor/torrc for any of:
|
35
|
+
|
36
|
+
```conf
|
37
|
+
DNSPort 9061
|
38
|
+
TransPort 9040
|
39
|
+
VirtualAddrNetworkIpv4 10.192.0.0/10
|
40
|
+
```
|
41
|
+
|
42
|
+
You can customize any of theses variables.
|
43
|
+
|
44
|
+
When using `spior -c | --clearnet`, if you want Spior load custom iptables rules, place
|
45
|
+
them at `/etc/iptables/simple_firewall.rules`.
|
46
|
+
|
34
47
|
## Usage
|
35
48
|
|
36
49
|
$ spior -h
|
@@ -54,11 +67,22 @@ Return to clearnet navigation
|
|
54
67
|
|
55
68
|
## Left Over
|
56
69
|
|
70
|
+
### [Check for Leak](https://github.com/brainfucksec/kalitorify#checking-for-leaks)
|
71
|
+
### Troubleshoooting
|
72
|
+
When you enable the `--persist` mode, Spior try to block ipv6 with sysctl. It can fail on some system, so you may need to manually disable ipv6 via kernel argument.
|
73
|
+
An exemple with GRUB, edit `/etc/default/grub.cfg` and change the line bellow:
|
74
|
+
|
75
|
+
```
|
76
|
+
GRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=1 quiet"
|
77
|
+
```
|
78
|
+
|
79
|
+
Reload grub after that `grub-mkconfig -o /boot/grub/grub.cfg`
|
80
|
+
|
57
81
|
### Issues
|
58
82
|
For any questions, comments, feedback or issues, submit a [new issue](https://github.com/szorfein/spior/issues/new).
|
59
83
|
|
60
84
|
### links
|
61
|
-
+ https://rubyreferences.github.io/rubyref
|
62
|
-
+ https://rubystyle.guide/
|
63
85
|
+ https://gitlab.torproject.org/legacy/trac/-/wikis/doc/TransparentProxy
|
64
|
-
+ https://github.com/epidemics-scepticism/writing/blob/master/misconception.md
|
86
|
+
+ https://github.com/epidemics-scepticism/writing/blob/master/misconception.md
|
87
|
+
+ [in perl - Nipe](https://github.com/htrgouvea/nipe)
|
88
|
+
+ [in bash - Kalitorify](https://github.com/brainfucksec/kalitorify)
|
data/bin/spior
CHANGED
@@ -2,5 +2,45 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'spior'
|
5
|
+
require 'optparse'
|
5
6
|
|
6
|
-
|
7
|
+
Msg.banner
|
8
|
+
|
9
|
+
OptionParser.new do |opts|
|
10
|
+
opts.on('-i', '--install', 'Install the dependencies.') do
|
11
|
+
Spior::Dep.looking
|
12
|
+
end
|
13
|
+
|
14
|
+
opts.on('-t', '--tor', 'Redirect traffic through TOR.') do
|
15
|
+
Spior::Service.start
|
16
|
+
end
|
17
|
+
|
18
|
+
opts.on('-r', '--reload', 'Reload TOR to change your IP.') do
|
19
|
+
Spior::Service.restart
|
20
|
+
exit
|
21
|
+
end
|
22
|
+
|
23
|
+
opts.on('-c', '--clearnet', 'Reset iptables and return to clearnet navigation.') do
|
24
|
+
Spior::Service.stop
|
25
|
+
end
|
26
|
+
|
27
|
+
opts.on('-s', '--status', 'Look infos about your current IP.') do
|
28
|
+
Spior::Status.info
|
29
|
+
exit
|
30
|
+
end
|
31
|
+
|
32
|
+
opts.on('-p', '--persist', 'Active Spior at every boot.') do
|
33
|
+
Spior::Service::Enable.new
|
34
|
+
end
|
35
|
+
|
36
|
+
opts.on('-m', '--menu', 'Display an interactive menu.') do
|
37
|
+
Spior::Menu.run
|
38
|
+
end
|
39
|
+
|
40
|
+
begin
|
41
|
+
opts.parse!(['-m']) if ARGV.empty?
|
42
|
+
rescue OptionParser::ParseError => e
|
43
|
+
warn e.message, "\n", opts
|
44
|
+
exit(-1)
|
45
|
+
end
|
46
|
+
end.parse!
|
data/lib/auth.rb
CHANGED
@@ -10,7 +10,7 @@ class Auth
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def mkdir(path)
|
13
|
-
return if
|
13
|
+
return if Dir.exist?(path)
|
14
14
|
|
15
15
|
x("mkdir -p #{path}")
|
16
16
|
end
|
@@ -21,6 +21,12 @@ class Auth
|
|
21
21
|
x("sysctl -w #{flag}=#{value}")
|
22
22
|
end
|
23
23
|
|
24
|
+
def write(content, file)
|
25
|
+
temp = Tempfile.new
|
26
|
+
File.write(temp.path, "#{content}\n")
|
27
|
+
x("cp #{temp.path} #{file}")
|
28
|
+
end
|
29
|
+
|
24
30
|
protected
|
25
31
|
|
26
32
|
def search_app
|
data/lib/spior/dep.rb
CHANGED
@@ -11,42 +11,44 @@ module Spior
|
|
11
11
|
def looking
|
12
12
|
case Nomansland.distro?
|
13
13
|
when :archlinux
|
14
|
-
installing_deps('
|
14
|
+
installing_deps('pacman -S', %w[iptables tor])
|
15
15
|
when :debian
|
16
|
-
installing_deps('
|
16
|
+
installing_deps('apt-get install', %w[iptables tor])
|
17
|
+
use_iptables
|
17
18
|
when :gentoo
|
18
|
-
installing_deps('
|
19
|
+
installing_deps('emerge -av', %w[iptables tor])
|
19
20
|
when :void
|
20
|
-
installing_deps('
|
21
|
+
installing_deps('xbps-install -S', %w[iptables tor])
|
22
|
+
when :fedora
|
23
|
+
installing_deps('dnf install -y', %w[iptables tor])
|
24
|
+
when :suse
|
25
|
+
installing_deps('zypper install -y', %w[iptables tor])
|
21
26
|
else
|
22
27
|
Msg.report 'Install for your distro is not yet supported.'
|
23
28
|
end
|
24
29
|
end
|
25
30
|
|
26
|
-
def installing_deps(
|
31
|
+
def installing_deps(distro_cmd, names)
|
27
32
|
names.map do |n|
|
28
|
-
Msg.p "Search #{n}
|
29
|
-
install(n) unless search_dep(n)
|
33
|
+
Msg.p "Search #{n}..."
|
34
|
+
install(distro_cmd, n) unless search_dep(n)
|
30
35
|
end
|
31
36
|
end
|
32
37
|
|
33
|
-
def install(
|
34
|
-
|
35
|
-
when :apt_get
|
36
|
-
Helpers::Exec.new('apt-get').run("install #{name}")
|
37
|
-
when :emerge
|
38
|
-
Helpers::Exec.new('emerge').run("-av #{name}")
|
39
|
-
when :pacman
|
40
|
-
Helpers::Exec.new('pacman').run("-S #{name}")
|
41
|
-
when :void
|
42
|
-
Helpers::Exec.new('xbps-install').run("-y #{name}")
|
43
|
-
when :yum
|
44
|
-
Helpers::Exec.new('yum').run("install #{name}")
|
45
|
-
end
|
38
|
+
def install(cmd, package)
|
39
|
+
Helpers.cmd("#{cmd} #{package}")
|
46
40
|
end
|
47
41
|
|
48
42
|
def search_dep(name)
|
49
43
|
TTY::Which.exist?(name) ? true : false
|
50
44
|
end
|
45
|
+
|
46
|
+
# https://wiki.debian.org/iptables
|
47
|
+
def use_iptables
|
48
|
+
Helpers.cmd('update-alternatives --set iptables /usr/sbin/iptables-legacy')
|
49
|
+
Helpers.cmd('update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy')
|
50
|
+
Helpers.cmd('update-alternatives --set arptables /usr/sbin/arptables-legacy')
|
51
|
+
Helpers.cmd('update-alternatives --set ebtables /usr/sbin/ebtables-legacy')
|
52
|
+
end
|
51
53
|
end
|
52
54
|
end
|
data/lib/spior/helpers.rb
CHANGED
@@ -5,21 +5,47 @@ require 'tempfile'
|
|
5
5
|
require 'open3'
|
6
6
|
|
7
7
|
module Helpers
|
8
|
+
def self.auth?
|
9
|
+
return :root if Process.uid == '0'
|
10
|
+
return :doas if File.exist?('/bin/doas') || File.exist?('/sbin/doas')
|
11
|
+
return :sudo if File.exist?('/bin/sudo') || File.exist?('/sbin/sudo')
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.cmd(command)
|
15
|
+
case auth?
|
16
|
+
when :root
|
17
|
+
syscmd(command)
|
18
|
+
when :doas
|
19
|
+
syscmd("doas #{command}")
|
20
|
+
when :sudo
|
21
|
+
syscmd("sudo #{command}")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.syscmd(cmd)
|
26
|
+
Open3.popen2e(cmd) do |_, stdout_and_stderr, wait_thr|
|
27
|
+
puts stdout_and_stderr.gets while stdout_and_stderr.gets
|
28
|
+
exit_status = wait_thr.value
|
29
|
+
raise "Error, Running #{cmd}" unless exit_status.success?
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.mv(src, dest)
|
34
|
+
if Process::Sys.getuid == '0'
|
35
|
+
FileUtils.mv(src, dest)
|
36
|
+
else
|
37
|
+
cmd("mv #{src} #{dest}")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
8
41
|
# Execute program using sudo when permission is required
|
9
42
|
class Exec
|
10
43
|
def initialize(name)
|
11
|
-
@search_uid = Process::Sys.getuid
|
12
44
|
@name = name
|
13
45
|
end
|
14
46
|
|
15
47
|
def run(args)
|
16
|
-
cmd
|
17
|
-
Open3.popen2e("#{cmd} #{args}") do |_, stdout_err, wait_thr|
|
18
|
-
puts stdout_err.gets while stdout_err.gets
|
19
|
-
|
20
|
-
exit_status = wait_thr.value
|
21
|
-
raise "Error, Running #{cmd} #{args}" unless exit_status.success?
|
22
|
-
end
|
48
|
+
Helpers.cmd("#{@name} #{args}")
|
23
49
|
end
|
24
50
|
end
|
25
51
|
|
data/lib/spior/iptables/rules.rb
CHANGED
@@ -10,19 +10,17 @@ module Spior
|
|
10
10
|
class Rules
|
11
11
|
def initialize
|
12
12
|
@tmp_iptables_rules = Tempfile.new('iptables_rules')
|
13
|
-
@tmp_spior_rules = Tempfile.new('spior_rules')
|
14
13
|
@save_path = search_iptables_config
|
15
14
|
end
|
16
15
|
|
17
16
|
def save
|
18
|
-
|
19
|
-
|
20
|
-
create_file(@tmp_spior_rules, @save_path)
|
17
|
+
Helpers.cmd("iptables-save > #{@tmp_iptables_rules.path}")
|
18
|
+
Helpers.mv(@tmp_iptables_rules.path, @save_path)
|
21
19
|
Msg.p "Iptables rules saved at #{@save_path}"
|
22
20
|
end
|
23
21
|
|
24
22
|
def restore
|
25
|
-
return if restoring_older_rules
|
23
|
+
return if restoring_older_rules
|
26
24
|
|
27
25
|
Msg.p 'Adding clearnet navigation...'
|
28
26
|
Iptables::Default.new.run!
|
@@ -30,57 +28,15 @@ module Spior
|
|
30
28
|
|
31
29
|
protected
|
32
30
|
|
33
|
-
def
|
34
|
-
|
35
|
-
Helpers::Exec.new('iptables-save').run("> #{tmp_file.path}")
|
36
|
-
end
|
37
|
-
|
38
|
-
def insert_comment(spior_file, iptable_file)
|
39
|
-
outfile = File.open(spior_file.path, 'w')
|
40
|
-
outfile.puts '# Rules saved by Spior.'
|
41
|
-
outfile.puts(File.read(iptable_file.path))
|
42
|
-
outfile.close
|
43
|
-
end
|
44
|
-
|
45
|
-
def search_for_comment(filename)
|
46
|
-
return unless File.exist? filename
|
47
|
-
|
48
|
-
File.open(filename) do |f|
|
49
|
-
f.each do |line|
|
50
|
-
return true if line.match(/saved by Spior/)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
false
|
54
|
-
end
|
55
|
-
|
56
|
-
def move(src, dest)
|
57
|
-
if Process::Sys.getuid == '0'
|
58
|
-
FileUtils.mv(src, dest)
|
59
|
-
else
|
60
|
-
Helpers::Exec.new('mv').run("#{src} #{dest}")
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def create_file(tmpfile, dest)
|
65
|
-
if File.exist? dest
|
66
|
-
if search_for_comment(dest)
|
67
|
-
Msg.p "Older Spior rules found #{dest}, erasing..."
|
68
|
-
else
|
69
|
-
Msg.p "File exist #{dest}, create backup #{dest}-backup..."
|
70
|
-
move(dest, "#{dest}-backup")
|
71
|
-
end
|
72
|
-
end
|
73
|
-
move(tmpfile.path, dest)
|
74
|
-
end
|
75
|
-
|
76
|
-
def restoring_older_rules(filename)
|
77
|
-
files = %W[#{filename}-backup #{filename}]
|
31
|
+
def restoring_older_rules
|
32
|
+
files = %w[/etc/iptables/simple_firewall.rules /usr/share/iptables/simple_firewall.rules]
|
78
33
|
files.each do |f|
|
79
|
-
next unless File.exist?(f)
|
34
|
+
next unless File.exist?(f)
|
80
35
|
|
81
36
|
Iptables::Root.new.stop!
|
82
37
|
Msg.p "Found older rules #{f}, restoring..."
|
83
|
-
Helpers
|
38
|
+
Helpers.cmd("cp #{f} #{@save_path}")
|
39
|
+
Helpers.cmd("iptables-restore < #{@save_path}")
|
84
40
|
return true
|
85
41
|
end
|
86
42
|
false
|
@@ -90,16 +46,12 @@ module Spior
|
|
90
46
|
|
91
47
|
def search_iptables_config
|
92
48
|
case Nomansland.distro?
|
93
|
-
when :archlinux
|
94
|
-
'/etc/iptables/iptables.rules'
|
95
|
-
when :void
|
96
|
-
'/etc/iptables/iptables.rules'
|
97
49
|
when :debian
|
98
50
|
'/etc/iptables.up.rules'
|
99
51
|
when :gentoo
|
100
52
|
'/var/lib/iptables/rules-save'
|
101
53
|
else
|
102
|
-
|
54
|
+
'/etc/iptables/iptables.rules'
|
103
55
|
end
|
104
56
|
end
|
105
57
|
end
|
data/lib/spior/ipv6.rb
CHANGED
@@ -1,35 +1,41 @@
|
|
1
|
-
# lib/ipv6.rb
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
3
|
require 'auth'
|
4
|
+
require 'interfacez'
|
5
5
|
|
6
6
|
module Spior
|
7
7
|
# Block or Allow ipv6 traffic with sysctl
|
8
8
|
class Ipv6
|
9
9
|
def initialize
|
10
|
-
@
|
10
|
+
@dest = '/etc/sysctl.d/40-ipv6.conf'
|
11
|
+
gen_flags
|
11
12
|
end
|
12
13
|
|
13
14
|
def allow
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
@flags.each { |f| Helpers.cmd("sysctl -w '#{f}=0'") }
|
16
|
+
Msg.p 'ipv6 allowed'
|
17
|
+
Helpers.cmd("rm #{@dest}") if File.exist? @dest
|
17
18
|
end
|
18
19
|
|
19
20
|
def block
|
20
|
-
|
21
|
-
|
22
|
-
Msg.p 'ipv6 blocked' if @changed
|
21
|
+
@flags.each { |f| Helpers.cmd("sysctl -w '#{f}=1'") }
|
22
|
+
Msg.p 'ipv6 blocked'
|
23
23
|
end
|
24
24
|
|
25
|
-
|
25
|
+
def block_persist
|
26
|
+
Auth.new.mkdir '/etc/sysctl.d'
|
27
|
+
myflags = []
|
28
|
+
@flags.each { |f| myflags << "#{f}=1" }
|
29
|
+
File.write('/tmp/flags.conf', myflags.join("\n"))
|
30
|
+
Helpers.cmd("cp /tmp/flags.conf #{@dest}")
|
31
|
+
end
|
26
32
|
|
27
|
-
|
28
|
-
flag_path = flag.gsub('.', '/')
|
29
|
-
return unless File.exist?("/proc/sys/#{flag_path}")
|
33
|
+
private
|
30
34
|
|
31
|
-
|
32
|
-
@
|
35
|
+
def gen_flags
|
36
|
+
@flags = ['net.ipv6.conf.all.disable_ipv6',
|
37
|
+
'net.ipv6.conf.default.disable_ipv6']
|
38
|
+
Interfacez.all { |i| @flags << "net.ipv6.conf.#{i}.disable_ipv6" }
|
33
39
|
end
|
34
40
|
end
|
35
41
|
end
|
data/lib/spior/options.rb
CHANGED
@@ -1,61 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'optparse'
|
4
|
-
|
5
3
|
module Spior
|
6
4
|
# Options for the CLI
|
7
5
|
class Options
|
8
|
-
def initialize(argv)
|
9
|
-
parse(argv)
|
10
|
-
end
|
11
|
-
|
12
|
-
private
|
13
|
-
|
14
|
-
def parse(argv)
|
15
|
-
OptionParser.new do |opts|
|
16
|
-
opts.on('-i', '--install', 'Install the dependencies.') do
|
17
|
-
Dep.looking
|
18
|
-
end
|
19
|
-
|
20
|
-
opts.on('-t', '--tor', 'Redirect traffic through TOR.') do
|
21
|
-
Service.start
|
22
|
-
end
|
23
|
-
|
24
|
-
opts.on('-r', '--reload', 'Reload TOR to change your IP.') do
|
25
|
-
Service.restart
|
26
|
-
exit
|
27
|
-
end
|
28
|
-
|
29
|
-
opts.on('-c', '--clearnet', 'Reset iptables and return to clearnet navigation.') do
|
30
|
-
Service.stop
|
31
|
-
end
|
32
|
-
|
33
|
-
opts.on('-s', '--status', 'Look infos about your current IP.') do
|
34
|
-
Status.info
|
35
|
-
exit
|
36
|
-
end
|
37
|
-
|
38
|
-
opts.on('-p', '--persist', 'Active Spior at every boot.') do
|
39
|
-
Service::Enable.new
|
40
|
-
end
|
41
|
-
|
42
|
-
opts.on('-m', '--menu', 'Display an interactive menu.') do
|
43
|
-
Menu.run
|
44
|
-
end
|
45
|
-
|
46
|
-
opts.on('-h', '--help', 'Show this message.') do
|
47
|
-
puts opts
|
48
|
-
exit
|
49
|
-
end
|
50
|
-
|
51
|
-
begin
|
52
|
-
argv = ['-m'] if argv.empty?
|
53
|
-
opts.parse!(argv)
|
54
|
-
rescue OptionParser::ParseError => e
|
55
|
-
warn e.message, "\n", opts
|
56
|
-
exit(-1)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
6
|
end
|
61
7
|
end
|
data/lib/spior/service/enable.rb
CHANGED
@@ -17,6 +17,10 @@ module Spior
|
|
17
17
|
for_gentoo
|
18
18
|
when :archlinux
|
19
19
|
for_arch
|
20
|
+
when :void
|
21
|
+
for_void
|
22
|
+
when :debian
|
23
|
+
for_debian
|
20
24
|
else
|
21
25
|
Msg.report 'Your distro is not yet supported.'
|
22
26
|
end
|
@@ -25,41 +29,75 @@ module Spior
|
|
25
29
|
protected
|
26
30
|
|
27
31
|
def for_gentoo
|
28
|
-
Iptables::Rules.new.save
|
29
32
|
case Nomansland.init?
|
30
33
|
when :systemd
|
34
|
+
Iptables::Rules.new.save
|
31
35
|
systemd_enable('iptables-restore', 'tor')
|
32
36
|
when :openrc
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
rc_upd.run('rc-update add tor default')
|
37
|
+
Helpers.cmd('rc-service iptables save')
|
38
|
+
Helpers.cmd('rc-update add iptables boot') # default or boot ?
|
39
|
+
Helpers.cmd('rc-update add tor default')
|
37
40
|
else
|
38
41
|
Msg.report 'Init no yet supported for start Iptables at boot'
|
39
42
|
end
|
43
|
+
Ipv6.new.block_persist
|
44
|
+
Msg.p 'Persist enabled for Gentoo...'
|
40
45
|
end
|
41
46
|
|
42
47
|
def for_arch
|
43
48
|
Iptables::Rules.new.save
|
44
49
|
Tor::Config.new(Tempfile.new('torrc')).backup
|
45
50
|
systemd_enable('iptables', 'tor')
|
46
|
-
|
51
|
+
Ipv6.new.block_persist
|
52
|
+
Msg.p 'Persist enabled for Arch...'
|
53
|
+
end
|
54
|
+
|
55
|
+
def for_void
|
56
|
+
Iptables::Rules.new.save
|
57
|
+
Tor::Config.new(Tempfile.new('torrc')).backup
|
58
|
+
runit_enable('iptables', 'tor')
|
59
|
+
Ipv6.new.block_persist
|
60
|
+
Msg.p 'Persist enabled for Void...'
|
61
|
+
end
|
62
|
+
|
63
|
+
# https://wiki.debian.org/iptables
|
64
|
+
def for_debian
|
65
|
+
Iptables::Rules.new.save
|
66
|
+
Tor::Config.new(Tempfile.new('torrc')).backup
|
67
|
+
systemd_enable('tor')
|
68
|
+
File.write('/tmp/start_iptables',
|
69
|
+
"#!/bin/sh\n/sbin/iptables-restore < /etc/iptables.up.rules\n")
|
70
|
+
Helpers.mv('/tmp/start_iptables', '/etc/network/if-pre-up.d/iptables')
|
71
|
+
Helpers.cmd('chmod +x /etc/network/if-pre-up.d/iptables')
|
72
|
+
Ipv6.new.block_persist
|
73
|
+
Msg.p 'Persist mode enabled for Debian...'
|
47
74
|
end
|
48
75
|
|
49
76
|
private
|
50
77
|
|
51
78
|
def systemd_enable(*services)
|
52
|
-
systemctl = Helpers::Exec.new('systemctl')
|
53
79
|
services.each do |s|
|
54
|
-
|
55
|
-
|
80
|
+
next if system("systemctl is-enabled #{s} >/dev/null")
|
81
|
+
|
82
|
+
Helpers.cmd("systemctl enable #{s}")
|
83
|
+
Msg.p "Enabling #{s}..."
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def runit_enable(*services)
|
88
|
+
services.each do |s|
|
89
|
+
next if File.exist? "/var/service/#{s}"
|
90
|
+
|
91
|
+
Helpers.cmd("ln -s /etc/sv/#{s} /var/service/#{s}")
|
92
|
+
Msg.p "Enabling #{s}"
|
56
93
|
end
|
57
94
|
end
|
58
95
|
|
59
96
|
def systemd_start(service)
|
60
|
-
|
97
|
+
return if system("systemctl is-active #{service} >/dev/null")
|
98
|
+
|
61
99
|
Msg.p "Search for service #{service}..."
|
62
|
-
|
100
|
+
Helpers.cmd("systemctl start #{service}")
|
63
101
|
end
|
64
102
|
end
|
65
103
|
end
|
@@ -1,14 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'nomansland'
|
4
|
+
|
3
5
|
module Spior
|
4
6
|
# Interact with Spior::Tor and Spior::Iptables
|
5
7
|
module Service
|
6
8
|
module_function
|
7
9
|
|
8
10
|
def restart
|
9
|
-
|
10
|
-
|
11
|
-
|
11
|
+
case Nomansland.init?
|
12
|
+
when :systemd
|
13
|
+
Helpers.cmd('systemctl restart tor')
|
14
|
+
when :openrc
|
15
|
+
Helpers.cmd('/etc/init.d/tor restart')
|
16
|
+
when :runit
|
17
|
+
Helpers.cmd('sv restart tor')
|
18
|
+
else
|
19
|
+
puts 'No init found (systemd, openrc, runit)...'
|
20
|
+
end
|
21
|
+
Msg.p 'Tor restarting, ip changed.'
|
12
22
|
end
|
13
23
|
end
|
14
24
|
end
|
data/lib/spior/status.rb
CHANGED
data/lib/spior/tor/config.rb
CHANGED
@@ -32,7 +32,7 @@ module Spior
|
|
32
32
|
cn = @content.join("\n")
|
33
33
|
File.write(@filename.path, "#{cn}\n")
|
34
34
|
Msg.p "Generating #{@config_spiorrc}..."
|
35
|
-
|
35
|
+
Helpers.mv(@filename.path, @config_spiorrc)
|
36
36
|
end
|
37
37
|
|
38
38
|
def write_file(content, file, mode = 'a')
|
@@ -55,7 +55,7 @@ module Spior
|
|
55
55
|
write_file @content_torrc, @filename.path, 'w'
|
56
56
|
|
57
57
|
Msg.p 'Saving Tor options...'
|
58
|
-
|
58
|
+
Helpers.mv(@filename.path, @config_spiorrc)
|
59
59
|
end
|
60
60
|
|
61
61
|
protected
|
@@ -64,9 +64,9 @@ module Spior
|
|
64
64
|
return if Dir.exist? @config_dir
|
65
65
|
|
66
66
|
if Process::Sys.getuid == '0'
|
67
|
-
|
67
|
+
FileUtils.mkdir_p @config_dir
|
68
68
|
else
|
69
|
-
|
69
|
+
Helpers.cmd("mkdir -p #{@config_dir}")
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
@@ -75,7 +75,7 @@ module Spior
|
|
75
75
|
content = File.read(@config_torrc)
|
76
76
|
adding content, "%include #{@config_dir}/*.conf"
|
77
77
|
write_file content, temp.path
|
78
|
-
|
78
|
+
Helpers.mv(temp.path, @config_torrc)
|
79
79
|
end
|
80
80
|
|
81
81
|
def generate_content(content)
|
@@ -112,26 +112,6 @@ module Spior
|
|
112
112
|
md5_dest = Digest::MD5.file dest
|
113
113
|
md5_src == md5_dest
|
114
114
|
end
|
115
|
-
|
116
|
-
# Permission for Archlinux on a torrc are chmod 644, chown root:root
|
117
|
-
def fix_perm(file)
|
118
|
-
if Process::Sys.getuid == '0'
|
119
|
-
file.chown(0, 0)
|
120
|
-
else
|
121
|
-
Helpers::Exec.new('chown').run("root:root #{file}")
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
def move(src, dest)
|
126
|
-
return if digest_match? src, dest
|
127
|
-
|
128
|
-
fix_perm(@filename.path)
|
129
|
-
if Process::Sys.getuid == '0'
|
130
|
-
FileUtils.mv(src, dest)
|
131
|
-
else
|
132
|
-
Helpers::Exec.new('mv').run("#{src} #{dest}")
|
133
|
-
end
|
134
|
-
end
|
135
115
|
end
|
136
116
|
end
|
137
117
|
end
|
data/lib/spior/tor/data.rb
CHANGED
data/lib/spior/tor/start.rb
CHANGED
@@ -38,28 +38,22 @@ module Spior
|
|
38
38
|
return if state == 'active'
|
39
39
|
|
40
40
|
Msg.p 'Starting Tor with Systemd...'
|
41
|
-
Helpers
|
41
|
+
Helpers.cmd('systemctl start tor')
|
42
42
|
end
|
43
43
|
|
44
44
|
def start_openrc
|
45
45
|
Msg.p 'Starting Tor with OpenRC...'
|
46
|
-
Helpers
|
46
|
+
Helpers.cmd('/etc/init.d/tor start')
|
47
47
|
end
|
48
48
|
|
49
49
|
def start_runit
|
50
50
|
Msg.p 'Starting Tor with Runit...'
|
51
51
|
if File.exist? '/var/service/tor'
|
52
|
-
Helpers
|
52
|
+
Helpers.cmd('sv start tor')
|
53
53
|
else
|
54
|
-
Helpers
|
54
|
+
Helpers.cmd('ln -s /etc/sv/tor /var/service/tor')
|
55
55
|
end
|
56
56
|
end
|
57
|
-
|
58
|
-
def x(arg)
|
59
|
-
auth = (Process::Sys.getuid == '0' ? '' : 'sudo')
|
60
|
-
pid = spawn("#{auth} #{arg}", out: '/dev/null') or raise 'Error'
|
61
|
-
Process.wait pid
|
62
|
-
end
|
63
57
|
end
|
64
58
|
end
|
65
59
|
end
|
data/lib/spior/version.rb
CHANGED
data/lib/spior.rb
CHANGED
@@ -21,19 +21,4 @@ module Spior
|
|
21
21
|
# Spior::CONFIG.user = 'Tor-User-System'
|
22
22
|
# Spior::CONFIG.virt_addr = '10.192.0.0/10'
|
23
23
|
CONFIG = Tor::Data.new
|
24
|
-
|
25
|
-
# Main for the CLI
|
26
|
-
class Main
|
27
|
-
def initialize(argv)
|
28
|
-
@argv = argv
|
29
|
-
x
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def x
|
35
|
-
Msg.banner
|
36
|
-
Options.new(@argv)
|
37
|
-
end
|
38
|
-
end
|
39
24
|
end
|
data/spior.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require_relative "lib/spior/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = 'spior'
|
@@ -31,8 +31,8 @@ Gem::Specification.new do |s|
|
|
31
31
|
|
32
32
|
s.test_files = Dir['test/test_*.rb']
|
33
33
|
|
34
|
-
s.cert_chain = ['certs/szorfein.pem']
|
35
|
-
s.signing_key = File.expand_path('~/.ssh/gem-private_key.pem')
|
34
|
+
#s.cert_chain = ['certs/szorfein.pem']
|
35
|
+
#s.signing_key = File.expand_path('~/.ssh/gem-private_key.pem')
|
36
36
|
|
37
37
|
s.requirements << 'tor'
|
38
38
|
s.requirements << 'iptables'
|
@@ -40,7 +40,7 @@ Gem::Specification.new do |s|
|
|
40
40
|
s.required_ruby_version = '>= 2.6'
|
41
41
|
|
42
42
|
s.add_runtime_dependency('interfacez', '~> 1.0')
|
43
|
-
s.add_runtime_dependency('nomansland', '~> 0.0')
|
43
|
+
s.add_runtime_dependency('nomansland', '~> 0.0.5')
|
44
44
|
s.add_runtime_dependency('rainbow', '~> 3.1')
|
45
|
-
s.add_runtime_dependency('tty-which', '~> 0.5')
|
45
|
+
s.add_runtime_dependency('tty-which', '~> 0.5.0')
|
46
46
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spior
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- szorfein
|
@@ -36,7 +36,7 @@ cert_chain:
|
|
36
36
|
urXgRIzALxd/xazPCnoLSXPzfJSI6Y77S1EBvhPd9RaSO8IyH9RhPDP9mnTvW2Kl
|
37
37
|
NAUnoL+txK5a
|
38
38
|
-----END CERTIFICATE-----
|
39
|
-
date:
|
39
|
+
date: 2024-10-10 00:00:00.000000000 Z
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: interfacez
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 0.0.5
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 0.0.5
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rainbow
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 0.5.0
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 0.5.0
|
97
97
|
description: " A tool to make TOR your default gateway\n"
|
98
98
|
email: szorfein@protonmail.com
|
99
99
|
executables:
|
@@ -103,6 +103,7 @@ extra_rdoc_files:
|
|
103
103
|
- README.md
|
104
104
|
- CHANGELOG.md
|
105
105
|
files:
|
106
|
+
- ".github/workflows/gem-push.yml"
|
106
107
|
- ".github/workflows/rubocop-analysis.yml"
|
107
108
|
- ".gitignore"
|
108
109
|
- CHANGELOG.md
|
metadata.gz.sig
CHANGED
Binary file
|