amnesie 0.0.4 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 81455c8939114e8211b6c21844ad35e88d0422c29be33d36cafff2ea5210bfa6
4
- data.tar.gz: 6dcc45de41fbfbf84b3e6f4a0af45fe139af8296ce5a444ecc3e4d5997baf243
3
+ metadata.gz: fee6ddb83b07b28a9196dfddbef713a7f3a6f9a5d32129e7f0952e65c4ed9857
4
+ data.tar.gz: 8e31162f07c03bb4fda8f9774d940adee9df0f9764002176a6c67f0b6687ab88
5
5
  SHA512:
6
- metadata.gz: bc53a51bed717b6e931d35d0a1e19ba45c8b6ee250a811ed08e5956e6f64c419167112e1329f32019b0fa0204e0b98fc8ebb9d16f368923b959d45504769591c
7
- data.tar.gz: 4a78f282cc125ce8dd2e7248ebfa9b3126dcff206a257a04157f7d01582728944fcdf0da62638dc16e079e700055b657bad0c043eef3d175e887d610552db288
6
+ metadata.gz: 5db556f79185ecd0098584d9ad2862d97f659461918beb39f625da1b4d804b5af5fe5c7cbd2d5245fe96280deaa5f5abb0dc2c362f73b59c0385c8d66ab4cb2f
7
+ data.tar.gz: 928261af07f2fc37e8f6801dc7b3480ee76854231b08e3ac45d8668fef917d145997788d8ccd87929b81c9eea409a7fdbffe47ec37d7c832f22039dab01d29bb
Binary file
data.tar.gz.sig CHANGED
Binary file
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  *.gem
2
2
  *.rbc
3
+ *.swp
3
4
  /.config
4
5
  /coverage/
5
6
  /InstalledFiles
@@ -1,3 +1,30 @@
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
+
7
+ ## 0.0.8, release 2020-09-22
8
+ * Enhance code
9
+ * Update the class MAC, more ruby like
10
+ * Use securerandom (>= ruby2.5)
11
+
12
+ ## 0.0.7, release 2020-05-29
13
+ * Shortcut action for service (e/d)
14
+ * Correct permission on amnesie-mac@.service
15
+ * Enhance lib/amnesie/helper
16
+
17
+ ## 0.0.6, release 2020-05-20
18
+ * Init a doc with RDoc.
19
+ * Add -i|--init to start init process properly.
20
+ * Add dhcpcd to the mac@.service, dhclient doesn't seem necessary.
21
+ * Correct the mac@.service.
22
+
23
+ ## 0.0.5, release 2020-05-19
24
+ * Create a amnesie-mac@.service (work only if the gem is install system-wide)
25
+ * Add -p|--persist
26
+ * Replace Makefile by a Rakefile
27
+
1
28
  ## 0.0.4, release 2020-05-16
2
29
  * Debian10 need to reload ifup@card-name too
3
30
  * Correct path where search dhclient (/bin,/sbin)
data/README.md CHANGED
@@ -2,15 +2,13 @@
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 your MAC Address
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.
12
10
 
13
- $ gem cert --add <(curl -Ls https://raw.githubusercontent.com/szorfein/spior/master/certs/szorfein.pem)
11
+ $ gem cert --add <(curl -Ls https://raw.githubusercontent.com/szorfein/amnesie/master/certs/szorfein.pem)
14
12
 
15
13
  And install the gem
16
14
 
@@ -24,14 +22,22 @@ 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 for eth0:
25
+ To change the MAC address only on `eth0`:
28
26
 
29
27
  $ amnesie -n eth0 -m
30
28
 
29
+ Create or Disable all systemd services for a network card:
30
+
31
+ $ amnesie -p
32
+
33
+ Forge a random hostname with `-H`
34
+
35
+ $ amnesie -H
36
+
31
37
  ## Left Over
32
38
 
33
39
  ### Issues
34
- For any questions, comments, feedback or issues, submit a [new issue](https://github.com/szorfein/spior/issues/new).
40
+ For any questions, comments, feedback or issues, submit a [new issue](https://github.com/szorfein/amnesie/issues/new).
35
41
 
36
42
  ### links
37
43
  + https://rubyreferences.github.io/rubyref
data/Rakefile CHANGED
@@ -1,10 +1,21 @@
1
1
  # https://github.com/seattlerb/minitest#running-your-tests-
2
2
  require "rake/testtask"
3
+ require File.dirname(__FILE__) + "/lib/amnesie/version"
3
4
 
4
5
  Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
7
- t.test_files = FileList["test/test_*.rb"]
6
+ t.libs << "test"
7
+ t.libs << "lib"
8
+ t.test_files = FileList["test/test_*.rb"]
9
+ end
10
+
11
+ # rake gem:build
12
+ namespace :gem do
13
+ desc "build the gem"
14
+ task :build do
15
+ Dir["amnesie*.gem"].each {|f| File.unlink(f) }
16
+ system("gem build amnesie.gemspec")
17
+ system("gem install amnesie-#{Amnesie::VERSION}.gem -P MediumSecurity")
18
+ end
8
19
  end
9
20
 
10
21
  task :default => :test
@@ -1,6 +1,8 @@
1
+ require File.dirname(__FILE__) + "/lib/amnesie/version"
2
+
1
3
  Gem::Specification.new do |s|
2
4
  s.name = "amnesie"
3
- s.version = "0.0.4"
5
+ s.version = Amnesie::VERSION
4
6
  s.summary = "A tool to make your computer amnesic"
5
7
  s.description = <<-EOF
6
8
  A tool to make your computer amnesic"
@@ -34,4 +36,5 @@ Gem::Specification.new do |s|
34
36
  s.add_runtime_dependency('interfacez', '1.0.3')
35
37
  s.add_runtime_dependency('nomansland', '0.0.2')
36
38
  s.add_runtime_dependency('tty-which', '0.4.2')
39
+ s.add_runtime_dependency('highline', '2.0.3')
37
40
  end
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'amnesie/runner'
3
+ require 'amnesie'
4
4
 
5
- runner = Amnesie::Runner.new(ARGV)
6
- runner.run
5
+ Amnesie::Main.new(ARGV)
@@ -0,0 +1,99 @@
1
+ require_relative 'amnesie/options'
2
+ require_relative 'amnesie/persist'
3
+ require_relative 'amnesie/process'
4
+ require_relative 'amnesie/network'
5
+ require_relative 'amnesie/mac'
6
+ require_relative 'amnesie/host'
7
+ require_relative 'amnesie/config'
8
+ require_relative 'amnesie/helpers'
9
+
10
+ module Amnesie
11
+
12
+ OPTIONS = {
13
+ mac: true,
14
+ hostname: false,
15
+ card_match: /^en/
16
+ }.freeze
17
+
18
+ def self.random_mac(network)
19
+ mac = Amnesie::MAC.new(network)
20
+ mac.set_addr
21
+ puts "New MAC for " + mac.to_s
22
+ end
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
+
33
+ def self.services(network)
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
45
+ end
46
+ end
47
+
48
+ def self.random_mac_and_kill(network)
49
+ process = Amnesie::Process.new(network)
50
+ mac = Amnesie::MAC.new(network)
51
+
52
+ process.kill
53
+ mac.down
54
+ mac.set_addr
55
+ puts "New MAC for " + mac.to_s
56
+ mac.up
57
+ process.restart
58
+
59
+ end
60
+
61
+ class Main
62
+ def initialize(argv)
63
+ @argv = argv
64
+ run
65
+ end
66
+
67
+ private
68
+
69
+ def run
70
+ options = Options.new(@argv)
71
+ networks = Network.new(options.card_match, options.net_dev).search
72
+ puts "cards #{networks}"
73
+
74
+ if options.init
75
+ networks.each { |net|
76
+ Amnesie.random_mac(net)
77
+ }
78
+ end
79
+
80
+ if options.persist
81
+ networks.each { |net|
82
+ Amnesie.services(net)
83
+ }
84
+ Amnesie.persist_wifi
85
+ exit
86
+ end
87
+
88
+ if options.mac
89
+ networks.each { |net|
90
+ Amnesie.random_mac_and_kill(net)
91
+ }
92
+ end
93
+
94
+ if options.hostname
95
+ Amnesie::Host.new
96
+ end
97
+ end
98
+ end
99
+ 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
@@ -1,13 +1,15 @@
1
+ require 'fileutils'
2
+ require 'tempfile'
3
+
1
4
  module Helpers
2
5
  class Exec
3
6
  def initialize(name)
4
- @search_uid=`id -u`.chomp
5
- @search_uid ||= 1000 unless $?.success?
7
+ @search_uid = Process::Sys.getuid
6
8
  @name = name
7
9
  end
8
10
 
9
11
  def run(args)
10
- if @search_uid == '0' then
12
+ if @search_uid == 0 then
11
13
  #puts "found root - uid #{@search_uid}"
12
14
  system(@name + " " + args)
13
15
  else
@@ -16,4 +18,53 @@ 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 "Systemd is no found..."
67
+ end
68
+ end
69
+ end
19
70
  end
@@ -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
@@ -1,47 +1,50 @@
1
- require_relative 'helpers'
1
+ require 'securerandom'
2
2
 
3
3
  module Amnesie
4
4
  class MAC
5
5
  def initialize(card)
6
6
  @card = card
7
7
  @ip = Helpers::Exec.new("ip")
8
+ save_origin
9
+ new_mac
8
10
  end
9
11
 
10
- # TODO yep...
11
- def rand
12
- first=`printf ""; dd bs=1 count=1 if=/dev/urandom 2>/dev/null | hexdump -v -e '/1 "%02X"'`
13
- last=`printf ""; dd bs=1 count=5 if=/dev/urandom 2>/dev/null | hexdump -v -e '/1 ":%02X"'`
14
- mac="#{first}#{last}"
15
- lastfive=`echo #{mac} | cut -d: -f 2-6`.chomp
16
- firstbyte=`echo #{mac} | cut -d: -f 1`.chomp
17
- firstbyte=`printf '%02X' $(( 0x#{firstbyte} & 254 | 2))`
18
- @mac="#{firstbyte}:#{lastfive}"
12
+ def set_addr
13
+ @ip.run("link set dev #{@card} address #{@mac}")
14
+ end
15
+
16
+ def down
17
+ @ip.run("link set dev #{@card} down")
18
+ end
19
+
20
+ def up
21
+ @ip.run("link set dev #{@card} up")
19
22
  end
20
23
 
21
24
  def to_s
22
- rand
23
25
  @card + " " + @mac
24
26
  end
25
27
 
26
- def search_curr_mac
27
- @curr = `ip addr show dev #{@card} | grep -i ether | awk '{print $2}'`
28
+ private
29
+
30
+ def new_mac
31
+ first = SecureRandom.hex(1)
32
+ last = SecureRandom.hex(5)
33
+ lastfive = last.split(//).each_slice(2).to_a.map(&:join).join(':')
34
+ firstbyte = `printf '%02X' $(( 0x#{first} & 254 | 2))`
35
+ @mac = "#{firstbyte}:#{lastfive}".downcase
28
36
  end
29
37
 
38
+ def search_curr_mac
39
+ @curr = `ip addr show dev #{@card} | grep -i ether | awk '{print $2}'`.chomp
40
+ end
41
+
30
42
  def save_origin
43
+ return if File.exist? "/tmp/mac_#{@card}"
31
44
  search_curr_mac
32
- txt="/tmp/mac_#{@card}"
33
- if not File.exist?(txt)
34
- file = File.open(txt, 'a+')
35
- file.puts(@curr)
36
- file.close
37
- puts "Origin saved"
38
- end
39
- end
40
-
41
- def apply
42
- @ip.run("link set dev #{@card} down")
43
- @ip.run("link set dev #{@card} address #{@mac}")
44
- @ip.run("link set dev #{@card} up")
45
+ filename="/tmp/mac_#{@card}"
46
+ File.write(filename, @curr)
47
+ puts "Origin saved"
45
48
  end
46
49
  end
47
50
  end
@@ -2,43 +2,39 @@ require 'interfacez'
2
2
 
3
3
  module Amnesie
4
4
  class Network
5
- attr_accessor :card
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 card
13
- verify_card
14
- if @check == false then
15
- ask_for_card
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 not @check then
30
- puts "Your interface #{@name} is no found"
30
+ if !@check then
31
+ raise ArgumentError, "Interface no found" if !@check
31
32
  end
32
33
  end
33
34
 
34
- def ask_for_card
35
- until @check == true
36
- Interfacez.all do |interface|
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
@@ -2,21 +2,39 @@ require 'optparse'
2
2
 
3
3
  module Amnesie
4
4
  class Options
5
- attr_reader :mac, :netcard
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
 
15
+ private
16
+
11
17
  def parse(argv)
12
18
  OptionParser.new do |opts|
13
19
 
14
- opts.on("-m", "--mac", "What is my MAC address?") do
20
+ opts.on("-i", "--init", "When used with a init process (systemd, etc...)") do
21
+ @init = true
22
+ end
23
+
24
+ opts.on("-m", "--mac", "Forge a random MAC address.") do
15
25
  @mac = true
16
26
  end
17
27
 
18
- opts.on("-n", "--net-card NAME", "The name of the card to use") do |net|
19
- @netcard = net
28
+ opts.on("-n", "--net-card NAME", "Card to use, default use card_match from the config file.") do |net|
29
+ @net_dev = net
30
+ end
31
+
32
+ opts.on("-p", "--persist", "Enable systemd service") do |net|
33
+ @persist = true
34
+ end
35
+
36
+ opts.on("-H", "--hostname", "Generate a new random hostname") do |host|
37
+ @hostname = true
20
38
  end
21
39
 
22
40
  opts.on("-h", "--help", "Show this message") do
@@ -25,7 +43,6 @@ module Amnesie
25
43
  end
26
44
 
27
45
  begin
28
- argv = ["-h"] if argv.empty?
29
46
  opts.parse!(argv)
30
47
  rescue OptionParser::ParseError => e
31
48
  STDERR.puts e.message, "\n", opts
@@ -0,0 +1,18 @@
1
+ module Amnesie
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
10
+ end
11
+ is_found
12
+ end
13
+ end
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
@@ -1,11 +1,10 @@
1
1
  require 'tty-which'
2
- require_relative 'helpers'
3
2
 
4
3
  module Amnesie
5
4
  class Process
6
5
  def initialize(card)
7
6
  @systemctl = Helpers::Exec.new("systemctl")
8
- @pkill = Helpers::Exec.new("pkill")
7
+ @kill = Helpers::Exec.new("kill")
9
8
  @rm = Helpers::Exec.new("rm")
10
9
  @card = card
11
10
  end
@@ -25,15 +24,16 @@ module Amnesie
25
24
 
26
25
  def kill_dhcpcd
27
26
  return if not TTY::Which.exist?('dhcpcd')
28
- `pgrep -x dhcpcd`
29
- @pkill.run("dhcpcd") if $?.success?
27
+ pids=`pgrep -i dhcpcd`.chomp
28
+ kill_pids(pids) if $?.success?
30
29
  puts "Killed dhcpcd"
31
30
  end
32
31
 
33
32
  def kill_dhclient
34
- return if not TTY::Which.exist?('dhclient', paths: ['/bin, /sbin'])
35
- `pgrep -x dhclient`
36
- @pkill.run("dhclient") if $?.success?
33
+ return if not TTY::Which.exist?('dhclient', paths: ['/sbin'])
34
+ pids=`pgrep -i dhclient`.chomp
35
+ kill_pids(pids) if $?.success?
36
+
37
37
  @rm.run("/run/dhclient.#{@card}.pid") if File.exist? "/run/dhclient.#{@card}.pid"
38
38
  @rm.run("/var/lib/dhcp/dhclient.#{@card}.leases") if File.exist? "/var/lib/dhcp/dhclient.#{@card}.leases"
39
39
  puts "Killed dhclient"
@@ -51,7 +51,7 @@ module Amnesie
51
51
  end
52
52
 
53
53
  def restart_dhclient
54
- return if not TTY::Which.exist?('dhclient', paths: ['/bin, /sbin'])
54
+ return if not TTY::Which.exist?('dhclient', paths: ['/sbin'])
55
55
  dhclient = Helpers::Exec.new("dhclient")
56
56
  # command tested on debian, not try on another system yet...
57
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}")
@@ -70,5 +70,12 @@ module Amnesie
70
70
  puts "Restarted tor"
71
71
  end
72
72
  end
73
+
74
+ def kill_pids(pids)
75
+ pids.lines.each { |p|
76
+ ps = p.gsub(/\n/, '')
77
+ @kill.run("-9 #{ps}")
78
+ }
79
+ end
73
80
  end
74
81
  end
@@ -0,0 +1,3 @@
1
+ module Amnesie
2
+ VERSION = '0.0.9'.freeze
3
+ end
@@ -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
@@ -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
@@ -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
@@ -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
@@ -0,0 +1,14 @@
1
+ require 'highline/import'
2
+
3
+ module Nito
4
+ class Pass
5
+ attr_reader :secret
6
+ def initialize
7
+ get
8
+ end
9
+ private
10
+ def get(prompt = 'Password: ')
11
+ @secret = ask(prompt) { |q| q.echo = false }
12
+ end
13
+ end
14
+ end
@@ -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
@@ -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
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-05-15 00:00:00.000000000 Z
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
  '
@@ -132,12 +146,27 @@ files:
132
146
  - Rakefile
133
147
  - amnesie.gemspec
134
148
  - bin/amnesie
149
+ - lib/amnesie.rb
150
+ - lib/amnesie/config.rb
135
151
  - lib/amnesie/helpers.rb
152
+ - lib/amnesie/host.rb
136
153
  - lib/amnesie/mac.rb
137
154
  - lib/amnesie/network.rb
138
155
  - lib/amnesie/options.rb
156
+ - lib/amnesie/persist.rb
157
+ - lib/amnesie/persist/iwd.rb
158
+ - lib/amnesie/persist/systemd.rb
159
+ - lib/amnesie/persist/wpa_supplicant.rb
139
160
  - lib/amnesie/process.rb
140
- - lib/amnesie/runner.rb
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
141
170
  - test/test_mac.rb
142
171
  homepage: https://github.com/szorfein/amnesie
143
172
  licenses:
@@ -161,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
190
  - !ruby/object:Gem::Version
162
191
  version: '0'
163
192
  requirements: []
164
- rubygems_version: 3.1.2
193
+ rubygems_version: 3.0.3
165
194
  signing_key:
166
195
  specification_version: 4
167
196
  summary: A tool to make your computer amnesic
metadata.gz.sig CHANGED
Binary file
@@ -1,31 +0,0 @@
1
- require_relative 'options'
2
- require_relative 'mac'
3
- require_relative 'process'
4
- require_relative 'network'
5
-
6
- module Amnesie
7
- class Runner
8
-
9
- def initialize(argv)
10
- @options = Options.new(argv)
11
- @network = false
12
- end
13
- def run
14
- if @options.mac then
15
- if not @network
16
- @network = Amnesie::Network.new(@options.netcard)
17
- end
18
- puts @network.card
19
- process = Amnesie::Process.new(@network.card)
20
- card = Amnesie::MAC.new(@network.card)
21
-
22
- process.kill
23
- card.save_origin
24
- card.rand
25
- card.apply
26
- puts card.to_s
27
- process.restart
28
- end
29
- end
30
- end
31
- end