amnesie 0.0.2 → 0.0.7
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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/CHANGELOG.md +24 -0
- data/README.md +6 -2
- data/Rakefile +12 -3
- data/amnesie.gemspec +1 -1
- data/lib/amnesie/helpers.rb +54 -2
- data/lib/amnesie/options.rb +9 -1
- data/lib/amnesie/persist.rb +94 -0
- data/lib/amnesie/process.rb +56 -10
- data/lib/amnesie/runner.rb +20 -3
- metadata +4 -3
- 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: 32a693e395e10dae6902936ee92ccee0f5c88f26dd2c3f35b4af0aaf84d6336d
|
4
|
+
data.tar.gz: f9f3cc186a25d643add3f3856bbbe41d18bc876cfbad76f0451d6715a9d99359
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87c5a5990c9a64110f2db7ae5346b76be2f1190e85984cc52bb6c28b8cf62051113e8a327ef9d701c221dafc448cdbf0d89c7b77a71ce249117c9bbe4caacb0e
|
7
|
+
data.tar.gz: 6c095d7d1be44fff68d0527cff8509db7d8a171d74ae5e1fcba75d5610396f4b16215e3c71251cc7b0517a36ea572594fae46170249b4f2527e6008e28d07a19
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,27 @@
|
|
1
|
+
## 0.0.7, release 2020-05-29
|
2
|
+
* Shortcut action for service (e/d)
|
3
|
+
* Correct permission on amnesie-mac@.service
|
4
|
+
* Enhance lib/amnesie/helper
|
5
|
+
|
6
|
+
## 0.0.6, release 2020-05-20
|
7
|
+
* Init a doc with RDoc.
|
8
|
+
* Add -i|--init to start init process properly.
|
9
|
+
* Add dhcpcd to the mac@.service, dhclient doesn't seem necessary.
|
10
|
+
* Correct the mac@.service.
|
11
|
+
|
12
|
+
## 0.0.5, release 2020-05-19
|
13
|
+
* Create a amnesie-mac@.service (work only if the gem is install system-wide)
|
14
|
+
* Add -p|--persist
|
15
|
+
* Replace Makefile by a Rakefile
|
16
|
+
|
17
|
+
## 0.0.4, release 2020-05-16
|
18
|
+
* Debian10 need to reload ifup@card-name too
|
19
|
+
* Correct path where search dhclient (/bin,/sbin)
|
20
|
+
* Enhance stuff for kill and reload dhclient (tested on debian 10)
|
21
|
+
|
22
|
+
## 0.0.3, release 2020-05-15
|
23
|
+
* Add stuff for kill and reload dhclient (tested on debian 10)
|
24
|
+
|
1
25
|
## 0.0.2, release 2020-05-15
|
2
26
|
* Rakefile, add rake as dev dependencie
|
3
27
|
* Check if process/program exist before kill/restart
|
data/README.md
CHANGED
@@ -10,7 +10,7 @@ Inspiration come from a post found on [Qubes-OS](https://www.qubes-os.org/doc/an
|
|
10
10
|
## Install
|
11
11
|
Amnesie is cryptographically signed, so add my public key (if you haven’t already) as a trusted certificate.
|
12
12
|
|
13
|
-
$ gem cert --add <(curl -Ls https://raw.githubusercontent.com/szorfein/
|
13
|
+
$ gem cert --add <(curl -Ls https://raw.githubusercontent.com/szorfein/amnesie/master/certs/szorfein.pem)
|
14
14
|
|
15
15
|
And install the gem
|
16
16
|
|
@@ -28,10 +28,14 @@ To change the MAC address for eth0:
|
|
28
28
|
|
29
29
|
$ amnesie -n eth0 -m
|
30
30
|
|
31
|
+
Create or Disable all systemd services for a network card:
|
32
|
+
|
33
|
+
$ amnesie -p -n wlp2s0
|
34
|
+
|
31
35
|
## Left Over
|
32
36
|
|
33
37
|
### Issues
|
34
|
-
For any questions, comments, feedback or issues, submit a [new issue](https://github.com/szorfein/
|
38
|
+
For any questions, comments, feedback or issues, submit a [new issue](https://github.com/szorfein/amnesie/issues/new).
|
35
39
|
|
36
40
|
### links
|
37
41
|
+ https://rubyreferences.github.io/rubyref
|
data/Rakefile
CHANGED
@@ -2,9 +2,18 @@
|
|
2
2
|
require "rake/testtask"
|
3
3
|
|
4
4
|
Rake::TestTask.new(:test) do |t|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
t.libs << "test"
|
6
|
+
t.libs << "lib"
|
7
|
+
t.test_files = FileList["test/test_*.rb"]
|
8
|
+
end
|
9
|
+
|
10
|
+
namespace :gem do
|
11
|
+
desc "build the gem"
|
12
|
+
task :build do
|
13
|
+
Dir["amnesie*.gem"].each {|f| File.unlink(f) }
|
14
|
+
system("gem build amnesie.gemspec")
|
15
|
+
system("gem install amnesie-0.0.7.gem -P MediumSecurity")
|
16
|
+
end
|
8
17
|
end
|
9
18
|
|
10
19
|
task :default => :test
|
data/amnesie.gemspec
CHANGED
data/lib/amnesie/helpers.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'tempfile'
|
3
|
+
|
1
4
|
module Helpers
|
2
5
|
class Exec
|
3
6
|
def initialize(name)
|
4
|
-
@search_uid
|
5
|
-
@search_uid ||= 1000 unless $?.success?
|
7
|
+
@search_uid= Process::Sys.getuid
|
6
8
|
@name = name
|
7
9
|
end
|
8
10
|
|
@@ -16,4 +18,54 @@ module Helpers
|
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|
21
|
+
|
22
|
+
class NewFile
|
23
|
+
def initialize(string, name, dest = "/tmp")
|
24
|
+
@string = string
|
25
|
+
@name = name
|
26
|
+
@dest = dest + "/" + @name
|
27
|
+
end
|
28
|
+
|
29
|
+
def add
|
30
|
+
@mv = Helpers::Exec.new("mv")
|
31
|
+
tmp = Tempfile.new(@name)
|
32
|
+
File.open(tmp.path, 'w') do |file|
|
33
|
+
file.puts @string
|
34
|
+
end
|
35
|
+
@mv.run("#{tmp.path} #{@dest}")
|
36
|
+
end
|
37
|
+
|
38
|
+
def perm(user, perm)
|
39
|
+
chown = Helpers::Exec.new("chown")
|
40
|
+
chmod = Helpers::Exec.new("chmod")
|
41
|
+
chown.run("#{user}:#{user} #{@dest}")
|
42
|
+
chmod.run("#{perm} #{@dest}")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class NewSystemd < NewFile
|
47
|
+
def initialize(string, name)
|
48
|
+
super
|
49
|
+
@systemd_dir = search_systemd_dir
|
50
|
+
@dest = @systemd_dir + "/" + @name
|
51
|
+
end
|
52
|
+
|
53
|
+
def add
|
54
|
+
@systemctl = Helpers::Exec.new("systemctl")
|
55
|
+
super
|
56
|
+
@systemctl.run("daemon-reload")
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
def search_systemd_dir
|
61
|
+
if Dir.exist? "/lib/systemd/system"
|
62
|
+
"/lib/systemd/system"
|
63
|
+
elsif Dir.exist? "/usr/lib/systemd/system"
|
64
|
+
"/usr/lib/systemd/system"
|
65
|
+
else
|
66
|
+
raise "No directory systemd found"
|
67
|
+
exit
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
19
71
|
end
|
data/lib/amnesie/options.rb
CHANGED
@@ -2,7 +2,7 @@ require 'optparse'
|
|
2
2
|
|
3
3
|
module Amnesie
|
4
4
|
class Options
|
5
|
-
attr_reader :mac, :netcard
|
5
|
+
attr_reader :init, :mac, :netcard, :persist
|
6
6
|
|
7
7
|
def initialize(argv)
|
8
8
|
parse(argv)
|
@@ -11,6 +11,10 @@ module Amnesie
|
|
11
11
|
def parse(argv)
|
12
12
|
OptionParser.new do |opts|
|
13
13
|
|
14
|
+
opts.on("-i", "--init", "Used with init process (systemd, etc...)") do
|
15
|
+
@init = true
|
16
|
+
end
|
17
|
+
|
14
18
|
opts.on("-m", "--mac", "What is my MAC address?") do
|
15
19
|
@mac = true
|
16
20
|
end
|
@@ -19,6 +23,10 @@ module Amnesie
|
|
19
23
|
@netcard = net
|
20
24
|
end
|
21
25
|
|
26
|
+
opts.on("-p", "--persist", "Enable systemd service") do |net|
|
27
|
+
@persist = true
|
28
|
+
end
|
29
|
+
|
22
30
|
opts.on("-h", "--help", "Show this message") do
|
23
31
|
puts opts
|
24
32
|
exit
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'tempfile'
|
3
|
+
require 'tty-which'
|
4
|
+
require_relative 'helpers'
|
5
|
+
|
6
|
+
module Amnesie
|
7
|
+
class Persist
|
8
|
+
|
9
|
+
def initialize(card)
|
10
|
+
@card = card
|
11
|
+
@systemd_dir = search_systemd_dir
|
12
|
+
@systemctl = Helpers::Exec.new("systemctl")
|
13
|
+
end
|
14
|
+
|
15
|
+
def mac_exist?
|
16
|
+
File.exist? "#{@systemd_dir}/amnesie-mac@.service"
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_s
|
20
|
+
@systemd_dir
|
21
|
+
end
|
22
|
+
|
23
|
+
def mac_service
|
24
|
+
dhcp=''
|
25
|
+
if TTY::Which.exist?('dhcpcd')
|
26
|
+
dhcp='dhcpcd.service'
|
27
|
+
end
|
28
|
+
@string=<<EOF
|
29
|
+
[Unit]
|
30
|
+
Description=Spoof MAC Address on %I
|
31
|
+
Wants=network-pre.target
|
32
|
+
Before=network-pre.target #{dhcp}
|
33
|
+
BindsTo=sys-subsystem-net-devices-%i.device
|
34
|
+
After=sys-subsystem-net-devices-%i.device
|
35
|
+
|
36
|
+
[Service]
|
37
|
+
Type=oneshot
|
38
|
+
ExecStart=/usr/bin/env bash -lc "amnesie -i -m -n %I"
|
39
|
+
TimeoutSec=30
|
40
|
+
|
41
|
+
[Install]
|
42
|
+
WantedBy=multi-user.target
|
43
|
+
EOF
|
44
|
+
end
|
45
|
+
|
46
|
+
def services
|
47
|
+
mac_service
|
48
|
+
new_service = Helpers::NewSystemd.new(@string, "amnesie-mac@.service")
|
49
|
+
new_service.add
|
50
|
+
new_service.perm("root", "644")
|
51
|
+
end
|
52
|
+
|
53
|
+
def update_mac
|
54
|
+
print "Found a old amnesie-mac@.service, update? (y|n) "
|
55
|
+
answer = gets.chomp
|
56
|
+
case answer
|
57
|
+
when /^y|^Y/
|
58
|
+
services
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def menu_mac
|
63
|
+
print "Action on amnesie-mac@.service for #{@card} (enable/disable) ? (e/d) "
|
64
|
+
answer = gets.chomp
|
65
|
+
case answer
|
66
|
+
when /^e|^E/
|
67
|
+
mac_enable
|
68
|
+
when /^d|^D/
|
69
|
+
mac_disable
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def mac_enable
|
76
|
+
@systemctl.run("enable amnesie-mac@#{@card}.service")
|
77
|
+
end
|
78
|
+
|
79
|
+
def mac_disable
|
80
|
+
@systemctl.run("disable amnesie-mac@#{@card}.service")
|
81
|
+
end
|
82
|
+
|
83
|
+
def search_systemd_dir
|
84
|
+
if Dir.exist? "/lib/systemd/system"
|
85
|
+
"/lib/systemd/system"
|
86
|
+
elsif Dir.exist? "/usr/lib/systemd/system"
|
87
|
+
"/usr/lib/systemd/system"
|
88
|
+
else
|
89
|
+
raise "No directory systemd found"
|
90
|
+
exit
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
data/lib/amnesie/process.rb
CHANGED
@@ -3,25 +3,71 @@ require_relative 'helpers'
|
|
3
3
|
|
4
4
|
module Amnesie
|
5
5
|
class Process
|
6
|
-
def initialize
|
7
|
-
@procs = [ "dhcpcd", "tor" ]
|
6
|
+
def initialize(card)
|
8
7
|
@systemctl = Helpers::Exec.new("systemctl")
|
9
8
|
@pkill = Helpers::Exec.new("pkill")
|
9
|
+
@rm = Helpers::Exec.new("rm")
|
10
|
+
@card = card
|
10
11
|
end
|
11
12
|
|
12
13
|
def kill
|
14
|
+
kill_dhcpcd
|
15
|
+
kill_dhclient
|
16
|
+
end
|
17
|
+
|
18
|
+
def restart
|
19
|
+
restart_dhcpcd
|
20
|
+
restart_dhclient
|
21
|
+
restart_tor
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def kill_dhcpcd
|
13
27
|
return if not TTY::Which.exist?('dhcpcd')
|
14
|
-
|
28
|
+
`pgrep -x dhcpcd`
|
29
|
+
@pkill.run("dhcpcd") if $?.success?
|
15
30
|
puts "Killed dhcpcd"
|
16
31
|
end
|
17
32
|
|
18
|
-
def
|
19
|
-
return if not TTY::Which.exist?('
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
33
|
+
def kill_dhclient
|
34
|
+
return if not TTY::Which.exist?('dhclient', paths: ['/sbin'])
|
35
|
+
`pgrep -x dhclient`
|
36
|
+
@pkill.run("dhclient") if $?.success?
|
37
|
+
@rm.run("/run/dhclient.#{@card}.pid") if File.exist? "/run/dhclient.#{@card}.pid"
|
38
|
+
@rm.run("/var/lib/dhcp/dhclient.#{@card}.leases") if File.exist? "/var/lib/dhcp/dhclient.#{@card}.leases"
|
39
|
+
puts "Killed dhclient"
|
40
|
+
end
|
41
|
+
|
42
|
+
def restart_dhcpcd
|
43
|
+
return if not TTY::Which.exist?('dhcpcd')
|
44
|
+
if TTY::Which.exist?('systemctl')
|
45
|
+
@systemctl.run("restart dhcpcd")
|
46
|
+
else
|
47
|
+
dhcpcd = Helpers::Exec.new("dhcpcd")
|
48
|
+
dhcpcd.run("-q")
|
49
|
+
end
|
50
|
+
puts "Restarted dhcpcd"
|
51
|
+
end
|
52
|
+
|
53
|
+
def restart_dhclient
|
54
|
+
return if not TTY::Which.exist?('dhclient', paths: ['/sbin'])
|
55
|
+
dhclient = Helpers::Exec.new("dhclient")
|
56
|
+
# command tested on debian, not try on another system yet...
|
57
|
+
dhclient.run("-4 -v -i -pf /run/dhclient.#{@card}.pid -lf /var/lib/dhcp/dhclient.#{@card}.leases -I -df /var/lib/dhcp/dhclient6.#{@card}.leases #{@card}")
|
58
|
+
if TTY::Which.exist?('systemctl')
|
59
|
+
`systemctl is-active ifup@#{@card}`
|
60
|
+
@systemctl.run("restart ifup@#{@card}") if $?.success?
|
61
|
+
end
|
62
|
+
puts "Restarted dhclient"
|
63
|
+
end
|
64
|
+
|
65
|
+
def restart_tor
|
66
|
+
return if not TTY::Which.exist?('tor')
|
67
|
+
if TTY::Which.exist?('systemctl')
|
68
|
+
`systemctl is-active tor`
|
69
|
+
@systemctl.run("restart tor") if $?.success?
|
70
|
+
puts "Restarted tor"
|
25
71
|
end
|
26
72
|
end
|
27
73
|
end
|
data/lib/amnesie/runner.rb
CHANGED
@@ -2,6 +2,7 @@ require_relative 'options'
|
|
2
2
|
require_relative 'mac'
|
3
3
|
require_relative 'process'
|
4
4
|
require_relative 'network'
|
5
|
+
require_relative 'persist'
|
5
6
|
|
6
7
|
module Amnesie
|
7
8
|
class Runner
|
@@ -10,21 +11,37 @@ module Amnesie
|
|
10
11
|
@options = Options.new(argv)
|
11
12
|
@network = false
|
12
13
|
end
|
14
|
+
|
13
15
|
def run
|
14
16
|
if @options.mac then
|
15
17
|
if not @network
|
16
18
|
@network = Amnesie::Network.new(@options.netcard)
|
17
19
|
end
|
18
20
|
puts @network.card
|
19
|
-
process = Amnesie::Process.new
|
21
|
+
process = Amnesie::Process.new(@network.card)
|
20
22
|
card = Amnesie::MAC.new(@network.card)
|
21
23
|
|
22
|
-
process.kill
|
24
|
+
process.kill unless @options.init
|
23
25
|
card.save_origin
|
24
26
|
card.rand
|
25
27
|
card.apply
|
26
28
|
puts card.to_s
|
27
|
-
process.restart
|
29
|
+
process.restart unless @options.init
|
30
|
+
end
|
31
|
+
if @options.persist then
|
32
|
+
if not @network
|
33
|
+
@network = Amnesie::Network.new(@options.netcard)
|
34
|
+
end
|
35
|
+
puts @network.card
|
36
|
+
persist = Amnesie::Persist.new(@network.card)
|
37
|
+
if ! persist.mac_exist?
|
38
|
+
puts "Create service..."
|
39
|
+
persist.services
|
40
|
+
elsif persist.mac_exist?
|
41
|
+
persist.update_mac
|
42
|
+
end
|
43
|
+
persist.menu_mac
|
44
|
+
puts persist.to_s
|
28
45
|
end
|
29
46
|
end
|
30
47
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amnesie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- szorfein
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
J/zT/q2Ac7BWpSLbv6p9lChBiEnD9j24x463LR5QQjDNS5SsjzRQfFuprsa9Nqf2
|
36
36
|
Tw==
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date: 2020-05-
|
38
|
+
date: 2020-05-29 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: rake
|
@@ -136,6 +136,7 @@ files:
|
|
136
136
|
- lib/amnesie/mac.rb
|
137
137
|
- lib/amnesie/network.rb
|
138
138
|
- lib/amnesie/options.rb
|
139
|
+
- lib/amnesie/persist.rb
|
139
140
|
- lib/amnesie/process.rb
|
140
141
|
- lib/amnesie/runner.rb
|
141
142
|
- test/test_mac.rb
|
@@ -161,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
162
|
- !ruby/object:Gem::Version
|
162
163
|
version: '0'
|
163
164
|
requirements: []
|
164
|
-
rubygems_version: 3.1.
|
165
|
+
rubygems_version: 3.1.3
|
165
166
|
signing_key:
|
166
167
|
specification_version: 4
|
167
168
|
summary: A tool to make your computer amnesic
|
metadata.gz.sig
CHANGED
Binary file
|