spior 0.1.0 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '01991c016f887cb41723c10909810d4bc7c762ad844d85a3bd094653123b891f'
4
- data.tar.gz: 6df20aa83ef6b7c2201bde879f4927183476b3b35d41eec6415ca7d0c3d0c8c5
3
+ metadata.gz: 52ad58e21c256642931525e2625cb10e14a74ad17ea95825940b87f6d667fdac
4
+ data.tar.gz: 143940314f5a3e3387f094cdeb6c371a0e34a2227b803f9cb0eaeebc8ebb512d
5
5
  SHA512:
6
- metadata.gz: 4b0d5ab4e4ccd4a8563eaae7e1aee31f77041b5d1dd593e79719ec82cb51868b24958cd8b92973fbc03303d8e54d9f0f9d9837913af9474e3099f4c867e14902
7
- data.tar.gz: f3bf8c16db8f5d8ec3e42b65f30567921ac4b0de3fffe2615e5ad045228920eed77ca5520c77b4b776ab75cbeda9455dab5bfe715a14b351e5711b5ca7b46ec9
6
+ metadata.gz: eadbf46e6b47eb820fbd88fd3d71c31183ca49a611ac0c6e0576724abc6357d6409fbf2edc9f69d38441889f262102af47f6fecadc2fe82bcbeea856d0557dc1
7
+ data.tar.gz: f774d5a4bec3474eccaf71e8495fc813cf71681fe609e7f7d1b6bf8e386d46c525bb138b4538f23cb4634706a578cbca96bac80fc85bb37c9700c99aff984ef1
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,35 @@
1
+ ## 0.1.5, release 2020-11-01
2
+ * Simplify lib/spior/copy, lib/spior/clear
3
+ * Write iptables rules for --clearnet and --tor
4
+ * Refacto code
5
+ * Enhance --status with open-uri and json
6
+ * Remove argument --net-card
7
+
8
+ ## 0.1.4, release 2020-05-21
9
+ * torrc and resolv.conf are generate dynamically
10
+ * Remove conf/resolv
11
+ * Correct path of conf_dir for the install on gentoo
12
+ * Remove self from lib/copy
13
+ * Correct little error on lib/copy with undefined method `deps`
14
+
15
+ ## 0.1.3, release 2020-05-14
16
+ * Rename conf dir by ext
17
+ * Clearing all codes about MAC
18
+ * Remove deceitmac
19
+ * Mac change and other randomize features will go on another gem amnesie
20
+
21
+ ## 0.1.2, release 2020-05-13
22
+ * Add instructions for the persistent mode
23
+ * Add dependency iptables-persistant for distro based on debian
24
+ * Avoid to use sudo if no need
25
+ * Add lib/spior/helpers
26
+
27
+ ## 0.1.1, release 2020-05-09
28
+ * The tor class now check for dependencies and service start|restart
29
+ * Call Spior without arguments now display the interactive menu
30
+ * New option -m|--menu
31
+ * Reorder the spior.gemspec
32
+
1
33
  ## 0.1.0, release 2020-05-08
2
34
  * Will manage differents version of torrc, if your distro fail to start TOR, report an issue.
3
35
  * Ensure than TOR is start before proceed.
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # spior
2
- (Spider|Tor) A tool to make TOR your default gateway and randomize your hardware (MAC).
2
+ (Spider|Tor) A tool to make TOR your default gateway.
3
3
 
4
4
  ## Install
5
5
  Spior is cryptographically signed, so add my public key (if you haven’t already) as a trusted certificate.
@@ -15,18 +15,21 @@ And install the gem
15
15
  $ spior -h
16
16
 
17
17
  ### Examples
18
- To change the MAC address for eth0
18
+ Redirect traffic through TOR:
19
19
 
20
- $ spior -n eth0 -m
20
+ $ spior --tor
21
21
 
22
- Redirect traffic through TOR
22
+ Change your ip address by reloading the TOR circuit:
23
23
 
24
- $ spior -t
25
- $ spior -t -n eth0
24
+ $ spior --reload
26
25
 
27
- Look informations about your current ip address
26
+ Look informations about your current ip address:
28
27
 
29
- $ spior -s
28
+ $ spior --status
29
+
30
+ Return to clearnet navigation
31
+
32
+ $ spior --clearnet
30
33
 
31
34
  ## Left Over
32
35
 
@@ -0,0 +1,20 @@
1
+ # https://github.com/seattlerb/minitest#running-your-tests-
2
+ require "rake/testtask"
3
+ require File.dirname(__FILE__) + "/lib/spior/version"
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << "test"
7
+ t.libs << "lib"
8
+ t.test_files = FileList["test/test_*.rb"]
9
+ end
10
+
11
+ namespace :gem do
12
+ desc "build the gem"
13
+ task :build do
14
+ Dir["spior*.gem"].each {|f| File.unlink(f) }
15
+ system("gem build spior.gemspec")
16
+ system("gem install spior-#{Spior::VERSION}.gem -P MediumSecurity")
17
+ end
18
+ end
19
+
20
+ task :default => :test
data/bin/spior CHANGED
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'spior/runner'
3
+ require 'spior'
4
4
 
5
- runner = Spior::Runner.new(ARGV)
6
- runner.run
5
+ Spior::Main.new(ARGV)
File without changes
File without changes
@@ -0,0 +1,42 @@
1
+ require_relative 'spior/clear'
2
+ require_relative 'spior/copy'
3
+ require_relative 'spior/install'
4
+ require_relative 'spior/iptables'
5
+ require_relative 'spior/msg'
6
+ require_relative 'spior/options'
7
+ require_relative 'spior/status'
8
+ require_relative 'spior/tor'
9
+ require_relative 'spior/persist'
10
+ require_relative 'spior/network'
11
+ require_relative 'spior/menu'
12
+ require_relative 'spior/helpers'
13
+
14
+ module Spior
15
+ class Main
16
+ def initialize(argv)
17
+ @argv = argv
18
+ run
19
+ end
20
+
21
+ private
22
+
23
+ def run
24
+ options = Options.new(@argv)
25
+
26
+ if options.install
27
+ Msg.head
28
+ Install::check_deps
29
+ Copy.new.save
30
+ end
31
+
32
+ if options.tor
33
+ Msg.head
34
+ Iptables::Tor.new.run!
35
+ end
36
+
37
+ if options.persist
38
+ Persist.enable
39
+ end
40
+ end
41
+ end
42
+ end
@@ -1,7 +1,5 @@
1
1
  require 'tty-which'
2
2
  require 'nomansland'
3
- require_relative 'copy'
4
- require_relative 'msg'
5
3
 
6
4
  module Spior
7
5
  module Clear
@@ -9,32 +7,30 @@ module Spior
9
7
 
10
8
  def all
11
9
  iptables
12
- rez_configs
10
+ Spior::Copy.new.restore
13
11
  end
14
12
 
15
13
  private
16
14
 
17
15
  def iptables
18
16
  puts "Clearing rules.."
19
- Spior::Iptables::flush_rules
20
- if File.exist?("/var/lib/iptables/rules-save")
21
- ipt_restore "/var/lib/iptables/rules-save"
22
- elsif File.exist?("/etc/iptables/rules.save")
23
- ipt_restore "/etc/iptables/iptables.rules"
24
- elsif File.exist?("/etc/iptables.rules")
25
- ipt_restore "/etc/iptables.rules"
26
- else
27
- Msg.p "I couldn't find any old rules for iptables to restore, skipping..."
28
- end
17
+ ipt = Spior::Iptables::Default.new
18
+ ipt.stop!
19
+ #if File.exist?("/var/lib/iptables/rules-save")
20
+ # ipt_restore "/var/lib/iptables/rules-save"
21
+ #elsif File.exist?("/etc/iptables/rules.save")
22
+ # ipt_restore "/etc/iptables/iptables.rules"
23
+ #elsif File.exist?("/etc/iptables.rules")
24
+ # ipt_restore "/etc/iptables.rules"
25
+ #else
26
+ #Msg.p "Couldn't find any previous rules for iptables, create basic rules..."
27
+ ipt.run!
28
+ #end
29
29
  end
30
30
 
31
31
  def ipt_restore(path)
32
32
  puts "Restoring rules #{path}..."
33
- system("sudo iptables-restore #{path}")
34
- end
35
-
36
- def rez_configs
37
- Spior::Copy::restore_files
33
+ Helpers::Exec.new("iptables-restore").run("#{path}")
38
34
  end
39
35
  end
40
36
  end
@@ -1,103 +1,85 @@
1
- require 'nomansland'
2
- require 'date'
3
1
  require 'digest'
4
- require_relative 'msg'
5
2
 
6
3
  module Spior
7
4
  class Copy
8
-
9
- def self.config_files
10
- @conf_dir = File.expand_path('../..' + '/conf', __dir__)
11
- copy_torrc
12
- copy_file(@conf_dir + "/resolv.conf", "/etc/resolv.conf")
13
- copy_file(@conf_dir + "/ipt_mod.conf", "/etc/modules-load.d/ipt_mod.conf")
14
- end
15
-
16
- def self.restore_files
17
- backup_exist("/etc/tor/torrc")
18
- backup_exist("/etc/resolv.conf")
5
+ def initialize
6
+ @cp = Helpers::Exec.new("cp -a")
7
+ @files = []
8
+ search_conf_dir
9
+ config_files
10
+ list
19
11
  end
20
12
 
21
- def self.search_systemd_dir
22
- if Dir.exist?("/usr/lib/systemd/system")
23
- @systemd_dir = '/usr/lib/systemd/system'
24
- elsif Dir.exist?("/lib/systemd/system")
25
- @systemd_dir = '/lib/systemd/system'
26
- else
27
- Msg.report "Directory systemd/system is no found on your system."
28
- exit(-1)
29
- end
13
+ def save
14
+ @files.each { |f|
15
+ backup = "#{f}_backup"
16
+ if ! File.exist? backup
17
+ Msg.p "#{f} saved"
18
+ @cp.run("#{f} #{backup}")
19
+ end
20
+ }
30
21
  end
31
22
 
32
- def self.systemd_services
33
- search_systemd_dir
34
- case Nomansland::installer?
35
- when :gentoo
36
- Msg.p "Copy #{@conf_dir}/iptables.service"
37
- copy_file(@conf_dir + "/iptables.service", @systemd_dir + "/iptables.service")
38
- end
23
+ def restore
24
+ @files.each { |f|
25
+ backup = "#{f}_backup"
26
+ if File.exist? backup
27
+ Msg.p "#{f} restored"
28
+ @cp.run("#{backup} #{f}")
29
+ end
30
+ }
39
31
  end
40
32
 
41
33
  private
42
34
 
43
- def self.copy_file(conf, target)
44
- @config_file = conf
45
- return if check_hash(@config_file, target)
46
- if File.exist? target then
47
- if ! previous_copy target
48
- backup_file(target)
49
- end
50
- add_file target
51
- else
52
- add_file target
53
- end
35
+ def config_files
36
+ copy_file("#{@conf_dir}/ipt_mod.conf", "/etc/modules-load.d/ipt_mod.conf")
54
37
  end
55
38
 
56
- def self.copy_torrc
57
- case Nomansland::distro?
58
- when :archlinux
59
- copy_file(@conf_dir + "/torrc/torrc_archlinux", "/etc/tor/torrc")
60
- else
61
- copy_file(@conf_dir + "/torrc/torrc_default", "/etc/tor/torrc")
62
- Msg.report "If tor fail to start with the default torrc"
63
- end
39
+ def list
40
+ add "/etc/resolv.conf"
41
+ add "/etc/tor/torrc"
42
+ add "/etc/systemd/resolved.conf"
43
+ add "/var/lib/iptables/rules-save" # gentoo
44
+ add "/etc/iptables/iptables.rules" # arch
45
+ add "/etc/iptables/rules.v4" # debian
64
46
  end
65
47
 
66
- def self.previous_copy(target)
67
- backup=`ls #{target}.backup-* | head -n 1`.chomp
68
- return false if !File.exist?(backup)
69
- check_hash(backup, target)
48
+ def add(file)
49
+ @files << file if File.exist? file
70
50
  end
71
51
 
72
- def self.check_hash(src, target)
73
- return if not File.exist?(target)
74
- sha256conf = Digest::SHA256.file src
75
- sha256target = Digest::SHA256.file target
76
- sha256conf === sha256target
52
+ def search_conf_dir
53
+ # ebuild on gentoo copy the ext dir at lib/ext
54
+ @conf_dir = File.expand_path('../..' + '/lib/ext', __dir__)
55
+ if ! Dir.exist?(@conf_dir)
56
+ @conf_dir = File.expand_path('../..' + '/ext', __dir__)
57
+ end
77
58
  end
78
59
 
79
- def self.backup_file(target)
80
- d = DateTime.now
81
- backup = target + ".backup-" + d.strftime('%b-%d_%I-%M')
82
- system("sudo cp -a #{target} #{backup}")
83
- puts "Renamed file #{backup}"
60
+ def previous_copy(target)
61
+ backup=`ls #{target}.backup-* | head -1`.chomp
62
+ return false if ! File.exist? backup
63
+ check_hash(backup, target)
84
64
  end
85
65
 
86
- def self.add_file(target)
87
- system("sudo cp -a #{@config_file} #{target}")
66
+ def add_file(target)
67
+ @cp.run("#{@config_file} #{target}")
88
68
  Msg.p "File #{@config_file} has been successfully copied at #{target}"
89
69
  end
90
70
 
91
- def self.backup_exist(target)
92
- backup=`ls #{target}.backup-* | head -n 1`.chomp
93
- if File.exist? backup
94
- if ! check_hash(target, backup)
95
- system("sudo cp -a #{backup} #{target}")
96
- Msg.p "Restored #{backup}"
97
- end
98
- else
99
- puts "No found previous backup for #{target}"
100
- end
71
+ def copy_file(conf, target)
72
+ @config_file = conf
73
+ add_file target if ! File.exist? target
74
+ return if check_hash(@config_file, target)
75
+ add_file target
76
+ end
77
+
78
+ def check_hash(src, target)
79
+ return if not File.exist?(target)
80
+ sha256conf = Digest::SHA256.file src
81
+ sha256target = Digest::SHA256.file target
82
+ sha256conf === sha256target
101
83
  end
102
84
  end
103
85
  end
@@ -0,0 +1,118 @@
1
+ require 'fileutils'
2
+ require 'tempfile'
3
+ require 'open3'
4
+
5
+ module Helpers
6
+ class Exec
7
+ def initialize(name)
8
+ @search_uid = Process::Sys.getuid
9
+ @name = name
10
+ end
11
+
12
+ def run(args)
13
+ cmd = @search_uid == '0' ? @name : "sudo #{@name}"
14
+ Open3.popen2e("#{cmd} #{args}") do |stdin, stdout_err, wait_thr|
15
+ while line = stdout_err.gets
16
+ puts line
17
+ end
18
+
19
+ exit_status = wait_thr.value
20
+ unless exit_status.success?
21
+ raise "Error, Running #{cmd} #{args}"
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ # Class Newfile
28
+ # Create a file and move at the dest
29
+ # === Example
30
+ # string = "nameserver 127.0.0.1"
31
+ # name = "resolv.conf"
32
+ # dest = "/etc"
33
+ # new_file = Helpers::Newfile.new(string, name, dest)
34
+ # new_file.add
35
+ class NewFile
36
+ # Method #new
37
+ # === Parameters
38
+ # * _string_ = string for the whole file
39
+ # * _name_ = name of the file (e.g: resolv.conf)
40
+ # * _dest_ = path (e.g: /etc)
41
+ def initialize(string, name, dest = "/tmp")
42
+ @string = string
43
+ @name = name
44
+ @dest = dest + "/" + @name
45
+ end
46
+
47
+ # Method #add
48
+ # Add the file at @dest
49
+ def add
50
+ @mv = Helpers::Exec.new("mv")
51
+ tmp = Tempfile.new(@name)
52
+ File.open(tmp.path, 'w') do |file|
53
+ file.puts @string
54
+ end
55
+ puts "move #{tmp.path} to #{@dest}"
56
+ @mv.run("#{tmp.path} #{@dest}")
57
+ end
58
+
59
+ def perm(user, perm)
60
+ chown = Helpers::Exec.new("chown")
61
+ chmod = Helpers::Exec.new("chmod")
62
+ chown.run("#{user}:#{user} #{@dest}")
63
+ chmod.run("#{perm} #{@dest}")
64
+ end
65
+ end
66
+
67
+ # Class NewSystemd
68
+ # Used to create a systemd service
69
+ #
70
+ # === Example:
71
+ # require Helpers
72
+ # string = <<EOF
73
+ # [Description]
74
+ #
75
+ # [Service]
76
+ # Type=simple
77
+ #
78
+ # [Installation]
79
+ # WantedBy =
80
+ # EOF
81
+ # new_systemd = Helpers::NewSystemd.new(string, "tor.service")
82
+ # new_systemd.add
83
+ class NewSystemd < NewFile
84
+ # Method #new
85
+ # === Parameters:
86
+ # * _string_ = the string of for whole content file
87
+ # * _name_ = the name of the service (e.g: tor.service)
88
+ def initialize(string, name)
89
+ super
90
+ @systemd_dir = search_systemd_dir
91
+ @dest = @systemd_dir + "/" + @name
92
+ end
93
+
94
+ # Method #add
95
+ # Create a temporary file and move
96
+ # the service @name to the systemd directory
97
+ def add
98
+ @systemctl = Helpers::Exec.new("systemctl")
99
+ super
100
+ @systemctl.run("daemon-reload")
101
+ end
102
+
103
+ private
104
+ # Method search_systemd_dir
105
+ # Search the current directory for systemd services
106
+ # + Gentoo can install at /lib/systemd/system or /usr/lib/systemd/system
107
+ def search_systemd_dir
108
+ if Dir.exist? "/lib/systemd/system"
109
+ "/lib/systemd/system"
110
+ elsif Dir.exist? "/usr/lib/systemd/system"
111
+ "/usr/lib/systemd/system"
112
+ else
113
+ raise "No directory systemd found"
114
+ exit
115
+ end
116
+ end
117
+ end
118
+ end