amnesie 0.0.8 → 0.0.9
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.tar.gz.sig +0 -0
- data/CHANGELOG.md +6 -0
- data/README.md +7 -5
- data/amnesie.gemspec +1 -0
- data/lib/amnesie.rb +46 -13
- data/lib/amnesie/config.rb +34 -0
- data/lib/amnesie/helpers.rb +3 -4
- data/lib/amnesie/host.rb +16 -0
- data/lib/amnesie/network.rb +15 -19
- data/lib/amnesie/options.rb +11 -4
- data/lib/amnesie/persist.rb +13 -87
- data/lib/amnesie/persist/iwd.rb +34 -0
- data/lib/amnesie/persist/systemd.rb +88 -0
- data/lib/amnesie/persist/wpa_supplicant.rb +41 -0
- data/lib/amnesie/version.rb +1 -1
- data/lib/nito.rb +11 -0
- data/lib/nito/cat.rb +21 -0
- data/lib/nito/cp.rb +35 -0
- data/lib/nito/hostname.rb +24 -0
- data/lib/nito/mkdir.rb +19 -0
- data/lib/nito/pass.rb +14 -0
- data/lib/nito/sed.rb +25 -0
- data/lib/nito/sudo.rb +16 -0
- metadata +30 -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: fee6ddb83b07b28a9196dfddbef713a7f3a6f9a5d32129e7f0952e65c4ed9857
|
4
|
+
data.tar.gz: 8e31162f07c03bb4fda8f9774d940adee9df0f9764002176a6c67f0b6687ab88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5db556f79185ecd0098584d9ad2862d97f659461918beb39f625da1b4d804b5af5fe5c7cbd2d5245fe96280deaa5f5abb0dc2c362f73b59c0385c8d66ab4cb2f
|
7
|
+
data.tar.gz: 928261af07f2fc37e8f6801dc7b3480ee76854231b08e3ac45d8668fef917d145997788d8ccd87929b81c9eea409a7fdbffe47ec37d7c832f22039dab01d29bb
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## 0.0.9, release 2020-11-06
|
2
|
+
* Support for iwd
|
3
|
+
* Support for wpa_supplicant
|
4
|
+
* Config file (per user in ~/.config/amnesie/ or system wide /etc/amnesie/)
|
5
|
+
* Can generate a random hostname between 8-25 characters
|
6
|
+
|
1
7
|
## 0.0.8, release 2020-09-22
|
2
8
|
* Enhance code
|
3
9
|
* Update the class MAC, more ruby like
|
data/README.md
CHANGED
@@ -2,10 +2,8 @@
|
|
2
2
|
A tool to make your computer amnesic.
|
3
3
|
|
4
4
|
Inspiration come from a post found on [Qubes-OS](https://www.qubes-os.org/doc/anonymizing-your-mac-address/) and the [Whonix](https://www.whonix.org/) project.
|
5
|
-
+ Anonymizing
|
6
|
-
+ Randomize all Ethernet and Wifi connections
|
5
|
+
+ Anonymizing MAC Address (wifi, ethernet)
|
7
6
|
+ Randomize your hostname
|
8
|
-
+ [Boot Clock Randomization](https://www.whonix.org/wiki/Boot_Clock_Randomization)
|
9
7
|
|
10
8
|
## Install
|
11
9
|
Amnesie is cryptographically signed, so add my public key (if you haven’t already) as a trusted certificate.
|
@@ -24,13 +22,17 @@ To be able to use the `persist mode` (with systemd for now), the gem should be i
|
|
24
22
|
If you can, i recommend that you create a package for your distribution.
|
25
23
|
|
26
24
|
## Usage
|
27
|
-
To change the MAC address
|
25
|
+
To change the MAC address only on `eth0`:
|
28
26
|
|
29
27
|
$ amnesie -n eth0 -m
|
30
28
|
|
31
29
|
Create or Disable all systemd services for a network card:
|
32
30
|
|
33
|
-
$ amnesie -p
|
31
|
+
$ amnesie -p
|
32
|
+
|
33
|
+
Forge a random hostname with `-H`
|
34
|
+
|
35
|
+
$ amnesie -H
|
34
36
|
|
35
37
|
## Left Over
|
36
38
|
|
data/amnesie.gemspec
CHANGED
data/lib/amnesie.rb
CHANGED
@@ -3,25 +3,46 @@ require_relative 'amnesie/persist'
|
|
3
3
|
require_relative 'amnesie/process'
|
4
4
|
require_relative 'amnesie/network'
|
5
5
|
require_relative 'amnesie/mac'
|
6
|
+
require_relative 'amnesie/host'
|
7
|
+
require_relative 'amnesie/config'
|
6
8
|
require_relative 'amnesie/helpers'
|
7
9
|
|
8
10
|
module Amnesie
|
11
|
+
|
12
|
+
OPTIONS = {
|
13
|
+
mac: true,
|
14
|
+
hostname: false,
|
15
|
+
card_match: /^en/
|
16
|
+
}.freeze
|
17
|
+
|
9
18
|
def self.random_mac(network)
|
10
19
|
mac = Amnesie::MAC.new(network)
|
11
20
|
mac.set_addr
|
12
21
|
puts "New MAC for " + mac.to_s
|
13
22
|
end
|
14
23
|
|
24
|
+
# For wifi card, no need systemd
|
25
|
+
def self.persist_wifi
|
26
|
+
if TTY::Which.exist?('iwctl')
|
27
|
+
Amnesie::Persist::Iwd.new
|
28
|
+
elsif TTY::Which.exist?('wpa_supplicant')
|
29
|
+
Amnesie::Persist::WpaSupplicant.new
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
15
33
|
def self.services(network)
|
16
|
-
|
17
|
-
if
|
18
|
-
|
19
|
-
persist.
|
20
|
-
|
21
|
-
|
34
|
+
# For ethernet card
|
35
|
+
if TTY::Which.exist?('systemctl') && network.match(/^en/)
|
36
|
+
persist = Amnesie::Persist::Systemd.new(network)
|
37
|
+
if ! persist.mac_exist?
|
38
|
+
puts "Create service..."
|
39
|
+
persist.services
|
40
|
+
elsif persist.mac_exist?
|
41
|
+
puts "service exist"
|
42
|
+
persist.update_mac
|
43
|
+
end
|
44
|
+
persist.menu_mac
|
22
45
|
end
|
23
|
-
persist.menu_mac
|
24
|
-
puts persist.to_s
|
25
46
|
end
|
26
47
|
|
27
48
|
def self.random_mac_and_kill(network)
|
@@ -47,19 +68,31 @@ module Amnesie
|
|
47
68
|
|
48
69
|
def run
|
49
70
|
options = Options.new(@argv)
|
50
|
-
|
71
|
+
networks = Network.new(options.card_match, options.net_dev).search
|
72
|
+
puts "cards #{networks}"
|
51
73
|
|
52
74
|
if options.init
|
53
|
-
|
54
|
-
|
75
|
+
networks.each { |net|
|
76
|
+
Amnesie.random_mac(net)
|
77
|
+
}
|
55
78
|
end
|
56
79
|
|
57
80
|
if options.persist
|
58
|
-
|
81
|
+
networks.each { |net|
|
82
|
+
Amnesie.services(net)
|
83
|
+
}
|
84
|
+
Amnesie.persist_wifi
|
85
|
+
exit
|
59
86
|
end
|
60
87
|
|
61
88
|
if options.mac
|
62
|
-
|
89
|
+
networks.each { |net|
|
90
|
+
Amnesie.random_mac_and_kill(net)
|
91
|
+
}
|
92
|
+
end
|
93
|
+
|
94
|
+
if options.hostname
|
95
|
+
Amnesie::Host.new
|
63
96
|
end
|
64
97
|
end
|
65
98
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Amnesie
|
4
|
+
class Config
|
5
|
+
def initialize
|
6
|
+
@file = File.join(find_conf)
|
7
|
+
#puts "Config file in #{@file}"
|
8
|
+
end
|
9
|
+
|
10
|
+
def load
|
11
|
+
if !File.exist? @file
|
12
|
+
puts "[+] Config file created at #{@file}"
|
13
|
+
save
|
14
|
+
end
|
15
|
+
YAML.load_file @file
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def find_conf
|
21
|
+
if !ENV["HOME"] || ENV["HOME"] == '/root'
|
22
|
+
"/etc/conf.d/amnesie.yaml"
|
23
|
+
else
|
24
|
+
"#{ENV['HOME']}/.config/amnesie/amnesie.yaml"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def save
|
29
|
+
dir = File.dirname @file
|
30
|
+
Nito::Mkdir.new(dir)
|
31
|
+
File.open(@file, 'w') { |f| YAML::dump(OPTIONS, f) }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/amnesie/helpers.rb
CHANGED
@@ -4,12 +4,12 @@ require 'tempfile'
|
|
4
4
|
module Helpers
|
5
5
|
class Exec
|
6
6
|
def initialize(name)
|
7
|
-
@search_uid= Process::Sys.getuid
|
7
|
+
@search_uid = Process::Sys.getuid
|
8
8
|
@name = name
|
9
9
|
end
|
10
10
|
|
11
11
|
def run(args)
|
12
|
-
if @search_uid ==
|
12
|
+
if @search_uid == 0 then
|
13
13
|
#puts "found root - uid #{@search_uid}"
|
14
14
|
system(@name + " " + args)
|
15
15
|
else
|
@@ -63,8 +63,7 @@ module Helpers
|
|
63
63
|
elsif Dir.exist? "/usr/lib/systemd/system"
|
64
64
|
"/usr/lib/systemd/system"
|
65
65
|
else
|
66
|
-
raise "
|
67
|
-
exit
|
66
|
+
raise "Systemd is no found..."
|
68
67
|
end
|
69
68
|
end
|
70
69
|
end
|
data/lib/amnesie/host.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
3
|
+
module Amnesie
|
4
|
+
class Host
|
5
|
+
def initialize
|
6
|
+
@nb = rand(8..25)
|
7
|
+
@hostname = SecureRandom.alphanumeric(@ng)
|
8
|
+
Nito::Hostname.new(@hostname)
|
9
|
+
puts to_s
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
"Your hostname will become #{@hostname}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/amnesie/network.rb
CHANGED
@@ -2,43 +2,39 @@ require 'interfacez'
|
|
2
2
|
|
3
3
|
module Amnesie
|
4
4
|
class Network
|
5
|
-
|
6
|
-
|
7
|
-
def initialize(name = false)
|
5
|
+
def initialize(card_match, name = nil)
|
6
|
+
@card_match = card_match
|
8
7
|
@name = name
|
8
|
+
@devs = []
|
9
9
|
@check = false
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
def search
|
13
|
+
if @name
|
14
|
+
verify_card
|
15
|
+
@devs << @name
|
16
|
+
else
|
17
|
+
search_cards
|
18
|
+
@devs
|
16
19
|
end
|
17
|
-
@name
|
18
20
|
end
|
19
21
|
|
20
22
|
private
|
21
23
|
|
22
24
|
def verify_card
|
23
|
-
return if @check or not @name
|
24
25
|
Interfacez.all do |interface|
|
25
26
|
if interface == @name then
|
26
27
|
@check = true
|
27
28
|
end
|
28
29
|
end
|
29
|
-
if
|
30
|
-
|
30
|
+
if !@check then
|
31
|
+
raise ArgumentError, "Interface no found" if !@check
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
34
|
-
def
|
35
|
-
|
36
|
-
|
37
|
-
print interface + " "
|
38
|
-
end
|
39
|
-
printf "\nWhat is the name of the card to be used? "
|
40
|
-
@name = gets.chomp
|
41
|
-
verify_card
|
35
|
+
def search_cards
|
36
|
+
Interfacez.all do |interface|
|
37
|
+
@devs << interface if interface.match(@card_match)
|
42
38
|
end
|
43
39
|
end
|
44
40
|
end
|
data/lib/amnesie/options.rb
CHANGED
@@ -2,9 +2,13 @@ require 'optparse'
|
|
2
2
|
|
3
3
|
module Amnesie
|
4
4
|
class Options
|
5
|
-
attr_reader :init, :mac, :net_dev, :persist
|
5
|
+
attr_reader :init, :mac, :net_dev, :persist, :hostname, :card_match
|
6
6
|
|
7
7
|
def initialize(argv)
|
8
|
+
@default = Config.new.load
|
9
|
+
@mac = @default[:mac]
|
10
|
+
@hostname = @default[:hostname]
|
11
|
+
@card_match = @default[:card_match]
|
8
12
|
parse(argv)
|
9
13
|
end
|
10
14
|
|
@@ -13,7 +17,7 @@ module Amnesie
|
|
13
17
|
def parse(argv)
|
14
18
|
OptionParser.new do |opts|
|
15
19
|
|
16
|
-
opts.on("-i", "--init", "
|
20
|
+
opts.on("-i", "--init", "When used with a init process (systemd, etc...)") do
|
17
21
|
@init = true
|
18
22
|
end
|
19
23
|
|
@@ -21,7 +25,7 @@ module Amnesie
|
|
21
25
|
@mac = true
|
22
26
|
end
|
23
27
|
|
24
|
-
opts.on("-n", "--net-card NAME", "
|
28
|
+
opts.on("-n", "--net-card NAME", "Card to use, default use card_match from the config file.") do |net|
|
25
29
|
@net_dev = net
|
26
30
|
end
|
27
31
|
|
@@ -29,13 +33,16 @@ module Amnesie
|
|
29
33
|
@persist = true
|
30
34
|
end
|
31
35
|
|
36
|
+
opts.on("-H", "--hostname", "Generate a new random hostname") do |host|
|
37
|
+
@hostname = true
|
38
|
+
end
|
39
|
+
|
32
40
|
opts.on("-h", "--help", "Show this message") do
|
33
41
|
puts opts
|
34
42
|
exit
|
35
43
|
end
|
36
44
|
|
37
45
|
begin
|
38
|
-
argv = ["-h"] if argv.empty?
|
39
46
|
opts.parse!(argv)
|
40
47
|
rescue OptionParser::ParseError => e
|
41
48
|
STDERR.puts e.message, "\n", opts
|
data/lib/amnesie/persist.rb
CHANGED
@@ -1,92 +1,18 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
require 'tempfile'
|
3
|
-
require 'tty-which'
|
4
|
-
|
5
1
|
module Amnesie
|
6
|
-
|
7
|
-
def
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
File.exist? "#{@systemd_dir}/amnesie-mac@.service"
|
15
|
-
end
|
16
|
-
|
17
|
-
def to_s
|
18
|
-
@systemd_dir
|
19
|
-
end
|
20
|
-
|
21
|
-
def mac_service
|
22
|
-
dhcp=''
|
23
|
-
if TTY::Which.exist?('dhcpcd')
|
24
|
-
dhcp='dhcpcd.service'
|
25
|
-
end
|
26
|
-
@string=<<EOF
|
27
|
-
[Unit]
|
28
|
-
Description=Spoof MAC Address on %I
|
29
|
-
Wants=network-pre.target
|
30
|
-
Before=network-pre.target #{dhcp}
|
31
|
-
BindsTo=sys-subsystem-net-devices-%i.device
|
32
|
-
After=sys-subsystem-net-devices-%i.device
|
33
|
-
|
34
|
-
[Service]
|
35
|
-
Type=oneshot
|
36
|
-
ExecStart=/usr/bin/env bash -lc "amnesie -i -m -n %I"
|
37
|
-
TimeoutSec=30
|
38
|
-
|
39
|
-
[Install]
|
40
|
-
WantedBy=multi-user.target
|
41
|
-
EOF
|
42
|
-
end
|
43
|
-
|
44
|
-
def services
|
45
|
-
mac_service
|
46
|
-
new_service = Helpers::NewSystemd.new(@string, "amnesie-mac@.service")
|
47
|
-
new_service.add
|
48
|
-
new_service.perm("root", "644")
|
49
|
-
end
|
50
|
-
|
51
|
-
def update_mac
|
52
|
-
print "Found a old amnesie-mac@.service, update? (y|n) "
|
53
|
-
answer = gets.chomp
|
54
|
-
case answer
|
55
|
-
when /^y|^Y/
|
56
|
-
services
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def menu_mac
|
61
|
-
print "Action on amnesie-mac@.service for #{@card} (enable/disable) ? (e/d) "
|
62
|
-
answer = gets.chomp
|
63
|
-
case answer
|
64
|
-
when /^e|^E/
|
65
|
-
mac_enable
|
66
|
-
when /^d|^D/
|
67
|
-
mac_disable
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
private
|
72
|
-
|
73
|
-
def mac_enable
|
74
|
-
@systemctl.run("enable amnesie-mac@#{@card}.service")
|
75
|
-
end
|
76
|
-
|
77
|
-
def mac_disable
|
78
|
-
@systemctl.run("disable amnesie-mac@#{@card}.service")
|
79
|
-
end
|
80
|
-
|
81
|
-
def search_systemd_dir
|
82
|
-
if Dir.exist? "/lib/systemd/system"
|
83
|
-
"/lib/systemd/system"
|
84
|
-
elsif Dir.exist? "/usr/lib/systemd/system"
|
85
|
-
"/usr/lib/systemd/system"
|
86
|
-
else
|
87
|
-
raise "No directory systemd found"
|
88
|
-
exit
|
2
|
+
module Persist
|
3
|
+
def self.grep?(file, regex)
|
4
|
+
is_found = false
|
5
|
+
return is_found if ! File.exist? file
|
6
|
+
File.open(file) do |f|
|
7
|
+
f.each do |line|
|
8
|
+
is_found = true if line.match(regex)
|
9
|
+
end
|
89
10
|
end
|
11
|
+
is_found
|
90
12
|
end
|
91
13
|
end
|
92
14
|
end
|
15
|
+
|
16
|
+
require_relative 'persist/iwd'
|
17
|
+
require_relative 'persist/wpa_supplicant'
|
18
|
+
require_relative 'persist/systemd'
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'nito'
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
module Amnesie
|
5
|
+
module Persist
|
6
|
+
class Iwd
|
7
|
+
def initialize
|
8
|
+
@tmp = Tempfile.new("main.conf")
|
9
|
+
apply
|
10
|
+
end
|
11
|
+
|
12
|
+
def apply
|
13
|
+
File.write(@tmp, iwd_conf)
|
14
|
+
if ! File.exist? "/etc/iwd/main.conf" ||
|
15
|
+
! grep?("/etc/iwd/main.conf", /AddressRandomization/)
|
16
|
+
puts "Add iwd/main.conf"
|
17
|
+
Nito::Cp.new(@tmp.path, "/etc/iwd/main.conf")
|
18
|
+
else
|
19
|
+
puts "MAC random on iwd seem enable."
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def iwd_conf
|
26
|
+
<<EOF
|
27
|
+
[General]
|
28
|
+
AddressRandomization=network
|
29
|
+
AddressRandomizationRange=full
|
30
|
+
EOF
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Amnesie
|
2
|
+
module Persist
|
3
|
+
class Systemd
|
4
|
+
def initialize(card = nil)
|
5
|
+
@card = card
|
6
|
+
@systemd_dir = search_systemd_dir
|
7
|
+
@systemctl = Helpers::Exec.new("systemctl")
|
8
|
+
end
|
9
|
+
|
10
|
+
def mac_exist?
|
11
|
+
File.exist? "#{@systemd_dir}/amnesie-mac@.service"
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
@systemd_dir
|
16
|
+
end
|
17
|
+
|
18
|
+
def services
|
19
|
+
mac_service
|
20
|
+
new_service = Helpers::NewSystemd.new(@string, "amnesie-mac@.service")
|
21
|
+
new_service.add
|
22
|
+
new_service.perm("root", "644")
|
23
|
+
end
|
24
|
+
|
25
|
+
def update_mac
|
26
|
+
print "Found a old amnesie-mac@.service, update? (y|n) "
|
27
|
+
answer = gets.chomp
|
28
|
+
case answer
|
29
|
+
when /^y|^Y/
|
30
|
+
services
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def menu_mac
|
35
|
+
print "Action on amnesie-mac@.service for #{@card} (enable/disable) ? (e/d) "
|
36
|
+
answer = gets.chomp
|
37
|
+
case answer
|
38
|
+
when /^e|^E/
|
39
|
+
mac_enable
|
40
|
+
when /^d|^D/
|
41
|
+
mac_disable
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def mac_enable
|
48
|
+
@systemctl.run("enable amnesie-mac@#{@card}.service")
|
49
|
+
end
|
50
|
+
|
51
|
+
def mac_disable
|
52
|
+
@systemctl.run("disable amnesie-mac@#{@card}.service")
|
53
|
+
end
|
54
|
+
|
55
|
+
def search_systemd_dir
|
56
|
+
if Dir.exist? "/lib/systemd/system"
|
57
|
+
"/lib/systemd/system"
|
58
|
+
elsif Dir.exist? "/usr/lib/systemd/system"
|
59
|
+
"/usr/lib/systemd/system"
|
60
|
+
else
|
61
|
+
raise "No directory systemd found"
|
62
|
+
exit
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def mac_service
|
67
|
+
dhcp = TTY::Which.exist?("dhcpcd") ? 'dhcpcd.service' : ''
|
68
|
+
@string=<<EOF
|
69
|
+
[Unit]
|
70
|
+
Description=Spoof MAC Address on %I
|
71
|
+
Wants=network-pre.target
|
72
|
+
Before=network-pre.target #{dhcp}
|
73
|
+
BindsTo=sys-subsystem-net-devices-%i.device
|
74
|
+
After=sys-subsystem-net-devices-%i.device
|
75
|
+
|
76
|
+
[Service]
|
77
|
+
Type=oneshot
|
78
|
+
ExecStart=/usr/bin/env bash -lc "amnesie -i -n %I"
|
79
|
+
ExecReload=/usr/bin/env bash -lc "amnesie -m -n %I"
|
80
|
+
TimeoutSec=30
|
81
|
+
|
82
|
+
[Install]
|
83
|
+
WantedBy=multi-user.target
|
84
|
+
EOF
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'nito'
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
module Amnesie
|
5
|
+
module Persist
|
6
|
+
class WpaSupplicant
|
7
|
+
def initialize
|
8
|
+
@cards = Network.new(/wl^/, nil).search
|
9
|
+
@tmp = Tempfile.new("main.conf")
|
10
|
+
apply_cards
|
11
|
+
end
|
12
|
+
|
13
|
+
def apply_cards
|
14
|
+
@cards.each { |card|
|
15
|
+
apply(card)
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def apply(card)
|
22
|
+
file = "/etc/wpa_supplicant/wpa_supplicant-#{card}.conf"
|
23
|
+
if ! File.exist? file ||
|
24
|
+
! grep?(file, /gas_rand_mac/)
|
25
|
+
puts "Add #{file}"
|
26
|
+
Nito::Cat.new(file, wpa_conf)
|
27
|
+
else
|
28
|
+
puts "MAC random on wpa_supplicant seem enable."
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def wpa_conf
|
33
|
+
<<EOF
|
34
|
+
mac_addr=1
|
35
|
+
preassoc_mac_addr=1
|
36
|
+
gas_rand_mac_addr=1
|
37
|
+
EOF
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/amnesie/version.rb
CHANGED
data/lib/nito.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require_relative 'nito/pass'
|
2
|
+
require_relative 'nito/sudo'
|
3
|
+
require_relative 'nito/cp'
|
4
|
+
require_relative 'nito/cat'
|
5
|
+
require_relative 'nito/sed'
|
6
|
+
require_relative 'nito/hostname'
|
7
|
+
require_relative 'nito/mkdir'
|
8
|
+
|
9
|
+
module Nito
|
10
|
+
ID = `id -u`.chomp.freeze
|
11
|
+
end
|
data/lib/nito/cat.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Nito
|
2
|
+
class Cat
|
3
|
+
def initialize(conf, string)
|
4
|
+
@conf = conf
|
5
|
+
@string = string
|
6
|
+
write_file
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
def write_file
|
11
|
+
tmp = Tempfile.new(@conf)
|
12
|
+
if File.exist? @conf
|
13
|
+
File.open(@conf).each { |l|
|
14
|
+
File.write(tmp, l, mode: 'a')
|
15
|
+
}
|
16
|
+
end
|
17
|
+
File.write(tmp, @string, mode: 'a')
|
18
|
+
Nito::Cp.new(tmp.path, @conf)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/nito/cp.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Nito
|
4
|
+
class Cp
|
5
|
+
#@@pass = nil
|
6
|
+
|
7
|
+
def initialize(src, dst, perm = 0644)
|
8
|
+
@src = src
|
9
|
+
@dst = dst
|
10
|
+
@perm = perm
|
11
|
+
if ID == "0"
|
12
|
+
root
|
13
|
+
else
|
14
|
+
#@@pass = Pass.new if ! @@pass
|
15
|
+
sudo
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def root
|
22
|
+
FileUtils.copy_file(@src, @dst)
|
23
|
+
FileUtils.chmod(@perm, @dst)
|
24
|
+
end
|
25
|
+
|
26
|
+
def sudo
|
27
|
+
#Sudo.run("cp #{@src} #{@dst}", @@pass.secret)
|
28
|
+
Sudo.run("cp #{@src} #{@dst}")
|
29
|
+
perm = sprintf "%o", @perm
|
30
|
+
#puts "Applying perm #{perm}"
|
31
|
+
#Sudo.run("chmod #{perm} #{@dst}", @@pass.secret)
|
32
|
+
Sudo.run("chmod #{perm} #{@dst}")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
|
3
|
+
module Nito
|
4
|
+
class Hostname
|
5
|
+
def initialize(hostname)
|
6
|
+
@hostname = hostname
|
7
|
+
@hostname_file = '/etc/hostname'
|
8
|
+
@hosts_file = '/etc/hosts'
|
9
|
+
new
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def new
|
15
|
+
tmp = Tempfile.new('hostname')
|
16
|
+
File.write(tmp, @hostname)
|
17
|
+
Nito::Cp.new(tmp.path, @hostname_file)
|
18
|
+
reg_1 = /^127.0.0.1[\s]+localhost/
|
19
|
+
reg_2 = /^::1[\s]+localhost/
|
20
|
+
Nito::Sed.new(@hosts_file, reg_1, "127.0.0.1 localhost #{@hostname}")
|
21
|
+
Nito::Sed.new(@hosts_file, reg_2, "::1 localhost #{@hostname}")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/nito/mkdir.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Nito
|
4
|
+
class Mkdir
|
5
|
+
def initialize(dir)
|
6
|
+
@dir = dir
|
7
|
+
mkdir
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
def mkdir
|
12
|
+
begin
|
13
|
+
FileUtils.mkdir_p @dir if ! Dir.exist? @dir
|
14
|
+
rescue Errno::EACCES
|
15
|
+
FileUtils.mkdir_p @dir if ! Dir.exist? @dir
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/nito/pass.rb
ADDED
data/lib/nito/sed.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
|
3
|
+
module Nito
|
4
|
+
class Sed
|
5
|
+
def initialize(file, regex, change)
|
6
|
+
@file = file
|
7
|
+
@regex = regex
|
8
|
+
@change = change
|
9
|
+
apply
|
10
|
+
end
|
11
|
+
|
12
|
+
def apply
|
13
|
+
raise ArgumentError "No file #{@file} exist" if ! File.exist? @file
|
14
|
+
tmp = Tempfile.new('sed')
|
15
|
+
File.open(@file).each { |l|
|
16
|
+
if l.match(@regex)
|
17
|
+
File.write(tmp, "#{@change}\n", mode: 'a')
|
18
|
+
else
|
19
|
+
File.write(tmp, l, mode: 'a')
|
20
|
+
end
|
21
|
+
}
|
22
|
+
Nito::Cp.new(tmp.path, @file)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/nito/sudo.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
module Nito
|
2
|
+
module Sudo
|
3
|
+
def self.run(command, input = nil)
|
4
|
+
#IO.popen("sudo -S #{command}", 'r+') do |io|
|
5
|
+
IO.popen("sudo #{command}", 'r+') do |io|
|
6
|
+
begin
|
7
|
+
io.puts input
|
8
|
+
io.close_write
|
9
|
+
io.read
|
10
|
+
rescue Interrupt
|
11
|
+
puts "\nInterrupt"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
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.9
|
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-
|
38
|
+
date: 2020-11-06 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: rake
|
@@ -113,6 +113,20 @@ dependencies:
|
|
113
113
|
- - '='
|
114
114
|
- !ruby/object:Gem::Version
|
115
115
|
version: 0.4.2
|
116
|
+
- !ruby/object:Gem::Dependency
|
117
|
+
name: highline
|
118
|
+
requirement: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - '='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: 2.0.3
|
123
|
+
type: :runtime
|
124
|
+
prerelease: false
|
125
|
+
version_requirements: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - '='
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: 2.0.3
|
116
130
|
description: ' A tool to make your computer amnesic"
|
117
131
|
|
118
132
|
'
|
@@ -133,13 +147,26 @@ files:
|
|
133
147
|
- amnesie.gemspec
|
134
148
|
- bin/amnesie
|
135
149
|
- lib/amnesie.rb
|
150
|
+
- lib/amnesie/config.rb
|
136
151
|
- lib/amnesie/helpers.rb
|
152
|
+
- lib/amnesie/host.rb
|
137
153
|
- lib/amnesie/mac.rb
|
138
154
|
- lib/amnesie/network.rb
|
139
155
|
- lib/amnesie/options.rb
|
140
156
|
- lib/amnesie/persist.rb
|
157
|
+
- lib/amnesie/persist/iwd.rb
|
158
|
+
- lib/amnesie/persist/systemd.rb
|
159
|
+
- lib/amnesie/persist/wpa_supplicant.rb
|
141
160
|
- lib/amnesie/process.rb
|
142
161
|
- lib/amnesie/version.rb
|
162
|
+
- lib/nito.rb
|
163
|
+
- lib/nito/cat.rb
|
164
|
+
- lib/nito/cp.rb
|
165
|
+
- lib/nito/hostname.rb
|
166
|
+
- lib/nito/mkdir.rb
|
167
|
+
- lib/nito/pass.rb
|
168
|
+
- lib/nito/sed.rb
|
169
|
+
- lib/nito/sudo.rb
|
143
170
|
- test/test_mac.rb
|
144
171
|
homepage: https://github.com/szorfein/amnesie
|
145
172
|
licenses:
|
@@ -163,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
190
|
- !ruby/object:Gem::Version
|
164
191
|
version: '0'
|
165
192
|
requirements: []
|
166
|
-
rubygems_version: 3.
|
193
|
+
rubygems_version: 3.0.3
|
167
194
|
signing_key:
|
168
195
|
specification_version: 4
|
169
196
|
summary: A tool to make your computer amnesic
|
metadata.gz.sig
CHANGED
Binary file
|