zlown 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/etc/dnsmasq.conf +1 -1
- data/etc/hostapd/hostapd.conf +4 -5
- data/etc/rc.local +1 -1
- data/lib/zlown/cli/cmd/update_cmd.rb +12 -0
- data/lib/zlown/config.rb +42 -0
- data/lib/zlown/core/core.rb +137 -45
- data/lib/zlown/script/script.rb +4 -4
- data/lib/zlown/systemctl/systemctl.rb +7 -8
- data/lib/zlown/version.rb +1 -1
- data/scripts/enable-forwarding.sh +8 -0
- metadata +4 -2
- data/scripts/enable-rogue.sh +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b6ece0b0fb285bc512cae0a12d7a7455b14071a
|
4
|
+
data.tar.gz: ea1f3d87fe1404dbb06bc8db43197e5531174ed9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea460cde4a975bb2dd6d375827af0782f83fd80f7312353e2c52b9614fe594e088a2c28800a6c1c5dd3a49c72c059487535a391453f3b379facc36ee159f6a61
|
7
|
+
data.tar.gz: fbf83a149f6c70d12895b9b6db844f89041e0ebf84f7c109334cd78b38cfb8e3cb2600412e3fad787c4deae583e29fcaed83d90194ab4038570524258e397afc
|
data/etc/dnsmasq.conf
CHANGED
data/etc/hostapd/hostapd.conf
CHANGED
data/etc/rc.local
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
require_relative '../shared'
|
2
|
+
|
3
|
+
require_relative '../../core/core'
|
4
|
+
|
5
|
+
module Zlown::CLI
|
6
|
+
desc 'Update all required scripts based on config'
|
7
|
+
command 'update' do |c|
|
8
|
+
c.action do |global_options, options, args|
|
9
|
+
Core.update_configs(args, options)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/zlown/config.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Copyright (c) 2016 Tomas Korcak <korczis@gmail.com>. All rights reserved.
|
4
|
+
# This source code is licensed under the MIT-style license found in the
|
5
|
+
# LICENSE file in the root directory of this source tree.
|
6
|
+
|
7
|
+
module Zlown
|
8
|
+
module Config
|
9
|
+
APP_DIR = File.expand_path('~/.zlown')
|
10
|
+
APP_BINARY = File.expand_path('../../../bin/zlown', __FILE__)
|
11
|
+
|
12
|
+
CONFIG_FILE = File.join(APP_DIR, 'zlown.yml')
|
13
|
+
|
14
|
+
BOOT_SCRIPT = File.join(APP_DIR, 'enable-forwarding.sh')
|
15
|
+
BOOT_SCRIPT_TEMPLATE = File.expand_path('../../../scripts/enable-forwarding.sh', __FILE__)
|
16
|
+
|
17
|
+
DNSMASQ_CONFIG = '/etc/dnsmasq.conf'
|
18
|
+
DNSMASQ_TEMPLATE = File.expand_path('../../../etc/dnsmasq.conf', __FILE__)
|
19
|
+
|
20
|
+
HOSTAPD_CONFIG = '/etc/hostapd/hostapd.conf'
|
21
|
+
HOSTAPD_TEMPLATE = File.expand_path('../../../etc/hostapd/hostapd.conf', __FILE__)
|
22
|
+
|
23
|
+
HTTPRY_PID_FILE = File.join(APP_DIR, 'run', 'httpry.pid')
|
24
|
+
|
25
|
+
DATA_DIR = File.join(APP_DIR, 'data')
|
26
|
+
RUN_DIR = File.join(APP_DIR, 'run')
|
27
|
+
|
28
|
+
SERVICE_TEMPLATE = File.expand_path('../../../etc/systemd/system/zlown.service', __FILE__)
|
29
|
+
SERVICE_FILE = File.expand_path("#{APP_DIR}/zlown.service")
|
30
|
+
|
31
|
+
RCLOCAL_CONFIG = '/etc/rc.local'
|
32
|
+
RCLOCAL_TEMPLATE = File.expand_path('../../../etc/rc.local', __FILE__)
|
33
|
+
|
34
|
+
RUN_CMD = "#{APP_BINARY} run"
|
35
|
+
|
36
|
+
DNSMASQ_SERVICE = 'dnsmasq.service'
|
37
|
+
HOSTAPD_SERVICE = 'hostapd.service'
|
38
|
+
|
39
|
+
ZLOWN_SERVICE_FILE = File.expand_path('~/.zlown/zlown.service')
|
40
|
+
ZLOWN_SERVICE_NAME = 'zlown'
|
41
|
+
end
|
42
|
+
end
|
data/lib/zlown/core/core.rb
CHANGED
@@ -8,23 +8,23 @@ require 'fileutils'
|
|
8
8
|
require 'highline'
|
9
9
|
require 'yaml'
|
10
10
|
|
11
|
+
require_relative '../config'
|
12
|
+
|
11
13
|
module Zlown
|
12
14
|
class Core
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
DNSMASQ_SERVICE = 'dnsmasq.service'
|
27
|
-
HOSTAPD_SERVICE = 'hostapd.service'
|
15
|
+
def self.load_config(args = [], opts = {})
|
16
|
+
config = {
|
17
|
+
upstream: 'eth0',
|
18
|
+
ap: 'wlan0',
|
19
|
+
driver: 'nl80211',
|
20
|
+
ssid: 'FreeWifi',
|
21
|
+
channel: '6'
|
22
|
+
}
|
23
|
+
|
24
|
+
if File.exist?(Zlown::Config::CONFIG_FILE)
|
25
|
+
config = config.merge(YAML.load(File.open(Zlown::Config::CONFIG_FILE)))
|
26
|
+
end
|
27
|
+
end
|
28
28
|
|
29
29
|
def self.install(args = [], opts = {})
|
30
30
|
cmd = 'apt-get install -y hostapd dnsmasq wireless-tools iw wvdial'
|
@@ -32,67 +32,159 @@ module Zlown
|
|
32
32
|
system cmd
|
33
33
|
end
|
34
34
|
|
35
|
-
def self.
|
36
|
-
unless File.directory?(APP_DIR)
|
37
|
-
puts "Creating directory #{APP_DIR}"
|
38
|
-
FileUtils.mkdir_p(APP_DIR)
|
35
|
+
def self.init_dirs(args = [], opts = {})
|
36
|
+
unless File.directory?(Zlown::Config::APP_DIR)
|
37
|
+
puts "Creating directory #{Zlown::Config::APP_DIR}"
|
38
|
+
FileUtils.mkdir_p(Zlown::Config::APP_DIR)
|
39
39
|
end
|
40
40
|
|
41
|
-
unless File.directory?(DATA_DIR)
|
42
|
-
puts "Creating directory #{DATA_DIR}"
|
43
|
-
FileUtils.mkdir_p(DATA_DIR)
|
41
|
+
unless File.directory?(Zlown::Config::DATA_DIR)
|
42
|
+
puts "Creating directory #{Zlown::Config::DATA_DIR}"
|
43
|
+
FileUtils.mkdir_p(Zlown::Config::DATA_DIR)
|
44
44
|
end
|
45
45
|
|
46
|
-
unless File.directory?(RUN_DIR)
|
47
|
-
puts "Creating directory #{RUN_DIR}"
|
48
|
-
FileUtils.mkdir_p(RUN_DIR)
|
46
|
+
unless File.directory?(Zlown::Config::RUN_DIR)
|
47
|
+
puts "Creating directory #{Zlown::Config::RUN_DIR}"
|
48
|
+
FileUtils.mkdir_p(Zlown::Config::RUN_DIR)
|
49
49
|
end
|
50
|
+
end
|
50
51
|
|
51
|
-
|
52
|
-
|
52
|
+
def self.init_service_template(args = [], opts = {})
|
53
|
+
template = File.read(Zlown::Config::SERVICE_TEMPLATE)
|
54
|
+
content = template.gsub('#{RUN_CMD}', Zlown::Config::RUN_CMD)
|
53
55
|
|
54
56
|
# To write changes to the file, use:
|
55
|
-
File.open(SERVICE_FILE, 'w') do |file|
|
56
|
-
puts "Writting file #{SERVICE_FILE}"
|
57
|
+
File.open(Zlown::Config::SERVICE_FILE, 'w') do |file|
|
58
|
+
puts "Writting file #{Zlown::Config::SERVICE_FILE}"
|
57
59
|
file.puts content
|
58
60
|
end
|
61
|
+
end
|
59
62
|
|
60
|
-
|
61
|
-
|
62
|
-
config = YAML.load(File.open(CONFIG_FILE))
|
63
|
-
end
|
63
|
+
def self.init_config_file(args = [], opts = {})
|
64
|
+
config = Core.load_config(args, opts)
|
64
65
|
|
65
66
|
cli = HighLine.new
|
66
|
-
config[:upstream] = cli.ask('
|
67
|
-
config[:ap] = cli.ask('
|
68
|
-
|
69
|
-
|
70
|
-
|
67
|
+
config[:upstream] = cli.ask('Upstream Interface?') { |q| q.default = config[:upstream] }
|
68
|
+
config[:ap] = cli.ask('Wi-Fi ap Interface?') { |q| q.default = config[:ap] }
|
69
|
+
config[:driver] = cli.ask('Wi-Fi Driver?') { |q| q.default = config[:driver] }
|
70
|
+
config[:ssid] = cli.ask('Wi-Fi SSID?') { |q| q.default = config[:ssid] }
|
71
|
+
config[:channel] = cli.ask('Wi-Fi Channel?') { |q| q.default = config[:channel] }
|
72
|
+
|
73
|
+
puts "Writting config to #{Zlown::Config::CONFIG_FILE}"
|
74
|
+
File.open(Zlown::Config::CONFIG_FILE, 'w') do |f|
|
71
75
|
f.write config.to_yaml
|
72
76
|
end
|
73
77
|
|
74
|
-
|
75
|
-
|
78
|
+
config
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.init_systemctl(args = [], opts = {})
|
82
|
+
# TODO: Process dnsmasq.conf and hostapd.conf
|
83
|
+
|
84
|
+
cmd = "systemctl enable #{Zlown::Config::HOSTAPD_SERVICE}"
|
76
85
|
puts cmd
|
77
86
|
system cmd
|
78
87
|
|
79
|
-
|
88
|
+
cmd = "systemctl enable #{Zlown::Config::DNSMASQ_SERVICE}"
|
89
|
+
puts cmd
|
90
|
+
system cmd
|
80
91
|
|
81
|
-
cmd = "systemctl
|
92
|
+
cmd = "systemctl start #{Zlown::Config::HOSTAPD_SERVICE}"
|
82
93
|
puts cmd
|
83
94
|
system cmd
|
84
95
|
|
85
|
-
cmd = "systemctl
|
96
|
+
cmd = "systemctl start #{Zlown::Config::DNSMASQ_SERVICE}"
|
86
97
|
puts cmd
|
87
98
|
system cmd
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.init_dnsmaq(args = [], opts = {})
|
102
|
+
config = Core.load_config(args, opts)
|
88
103
|
|
89
|
-
|
104
|
+
template = File.read(Zlown::Config::DNSMASQ_TEMPLATE)
|
105
|
+
content = template.gsub('${IFACE_AP}', config[:ap])
|
106
|
+
|
107
|
+
# To write changes to the file, use:
|
108
|
+
File.open(Zlown::Config::DNSMASQ_CONFIG, 'w') do |file|
|
109
|
+
puts "Writting file #{Zlown::Config::DNSMASQ_CONFIG}"
|
110
|
+
file.puts content
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def self.init_hostapd(args = [], opts = {})
|
115
|
+
# See https://www.offensive-security.com/kali-linux/kali-linux-evil-wireless-access-point/
|
116
|
+
cmd = "sed -i 's#^DAEMON_CONF=.*#DAEMON_CONF=/etc/hostapd/hostapd.conf#' /etc/init.d/hostapd"
|
90
117
|
puts cmd
|
91
118
|
system cmd
|
92
119
|
|
93
|
-
|
120
|
+
config = Core.load_config(args, opts)
|
121
|
+
|
122
|
+
template = File.read(Zlown::Config::HOSTAPD_TEMPLATE)
|
123
|
+
content = template
|
124
|
+
.gsub('${IFACE}', config[:ap])
|
125
|
+
.gsub('${DRIVER}', config[:driver])
|
126
|
+
.gsub('${SSID}', config[:ssid])
|
127
|
+
.gsub('${CHANNEL}', config[:channel])
|
128
|
+
|
129
|
+
# To write changes to the file, use:
|
130
|
+
File.open(Zlown::Config::HOSTAPD_CONFIG, 'w') do |file|
|
131
|
+
puts "Writting file #{Zlown::Config::HOSTAPD_CONFIG}"
|
132
|
+
file.puts content
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def self.init_boot_script(args = [], opts = {})
|
137
|
+
config = Core.load_config(args, opts)
|
138
|
+
|
139
|
+
template = File.read(Zlown::Config::BOOT_SCRIPT_TEMPLATE)
|
140
|
+
content = template
|
141
|
+
.gsub('${IFACE_AP}', config[:ap])
|
142
|
+
.gsub('${IFACE_UPSTREAM}', config[:upstream])
|
143
|
+
|
144
|
+
# To write changes to the file, use:
|
145
|
+
File.open(Zlown::Config::BOOT_SCRIPT, 'w') do |file|
|
146
|
+
puts "Writting file #{Zlown::Config::BOOT_SCRIPT}"
|
147
|
+
file.puts content
|
148
|
+
end
|
149
|
+
|
150
|
+
cmd = "chmod +x #{Zlown::Config::BOOT_SCRIPT}"
|
94
151
|
puts cmd
|
95
152
|
system cmd
|
96
153
|
end
|
154
|
+
|
155
|
+
def self.init_rc_local(args = [], opts = {})
|
156
|
+
Core.init_boot_script(args, opts)
|
157
|
+
|
158
|
+
config = Core.load_config(args, opts)
|
159
|
+
|
160
|
+
template = File.read(Zlown::Config::RCLOCAL_TEMPLATE)
|
161
|
+
content = template
|
162
|
+
|
163
|
+
# To write changes to the file, use:
|
164
|
+
File.open(Zlown::Config::RCLOCAL_CONFIG, 'w') do |file|
|
165
|
+
puts "Writting file #{Zlown::Config::RCLOCAL_CONFIG}"
|
166
|
+
file.puts content
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def self.update_configs(args = [], opts = {})
|
171
|
+
Core.init_dnsmaq(args, opts)
|
172
|
+
|
173
|
+
Core.init_hostapd(args, opts)
|
174
|
+
|
175
|
+
Core.init_rc_local(args, opts)
|
176
|
+
|
177
|
+
Core.init_systemctl(args, opts)
|
178
|
+
end
|
179
|
+
|
180
|
+
def self.init(args = [], opts = {})
|
181
|
+
Core.init_dirs(args, opts)
|
182
|
+
|
183
|
+
Core.init_service_template(args, opts)
|
184
|
+
|
185
|
+
Core.init_config_file(args, opts)
|
186
|
+
|
187
|
+
Core.update_configs(args, opts)
|
188
|
+
end
|
97
189
|
end
|
98
190
|
end
|
data/lib/zlown/script/script.rb
CHANGED
@@ -4,18 +4,18 @@
|
|
4
4
|
# This source code is licensed under the MIT-style license found in the
|
5
5
|
# LICENSE file in the root directory of this source tree.
|
6
6
|
|
7
|
+
require_relative '../config'
|
8
|
+
|
7
9
|
module Zlown
|
8
10
|
class Script
|
9
|
-
HTTPRY_PID_FILE = '/root/.zlown/run/httpry.pid'
|
10
|
-
|
11
11
|
def self.httpry_start(args = [], opts = {})
|
12
|
-
cmd = "httpry -d -P #{HTTPRY_PID_FILE} -i wlan1 -o /root/.zlown/data/httpry.log -b /root/.zlown/data/httpry.bin"
|
12
|
+
cmd = "httpry -d -P #{Zlown::Config::HTTPRY_PID_FILE} -i wlan1 -o /root/.zlown/data/httpry.log -b /root/.zlown/data/httpry.bin"
|
13
13
|
puts cmd
|
14
14
|
system cmd
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.httpry_stop(args = [], opts = {})
|
18
|
-
pid = File.open(HTTPRY_PID_FILE).read.to_i
|
18
|
+
pid = File.open(Zlown::Config::HTTPRY_PID_FILE).read.to_i
|
19
19
|
cmd = "kill #{pid}"
|
20
20
|
puts cmd
|
21
21
|
system cmd
|
@@ -4,27 +4,26 @@
|
|
4
4
|
# This source code is licensed under the MIT-style license found in the
|
5
5
|
# LICENSE file in the root directory of this source tree.
|
6
6
|
|
7
|
+
require_relative '../config'
|
8
|
+
|
7
9
|
module Zlown
|
8
10
|
class Systemctl
|
9
|
-
SERVICE_FILE = File.expand_path('~/.zlown/zlown.service')
|
10
|
-
SERVICE_NAME = 'zlown'
|
11
|
-
|
12
11
|
def self.enable(args = [], opts = {})
|
13
12
|
puts 'Enabling systemctl service'
|
14
|
-
cmd = "systemctl enable #{
|
13
|
+
cmd = "systemctl enable #{Zlown::Config::ZLOWN_SERVICE_FILE}"
|
15
14
|
puts cmd
|
16
15
|
system cmd
|
17
16
|
end
|
18
17
|
|
19
18
|
def self.disable(args = [], opts = {})
|
20
19
|
puts 'Disabling systemctl service'
|
21
|
-
cmd = "systemctl disable #{
|
20
|
+
cmd = "systemctl disable #{Zlown::Config::ZLOWN_SERVICE_NAME}"
|
22
21
|
system cmd
|
23
22
|
end
|
24
23
|
|
25
24
|
def self.start(args = [], opts = {})
|
26
25
|
puts 'Starting systemctl service'
|
27
|
-
cmd = "systemctl start #{
|
26
|
+
cmd = "systemctl start #{Zlown::Config::ZLOWN_SERVICE_NAME}"
|
28
27
|
system cmd
|
29
28
|
end
|
30
29
|
|
@@ -35,12 +34,12 @@ module Zlown
|
|
35
34
|
end
|
36
35
|
|
37
36
|
def self.status(args = [], opts = {})
|
38
|
-
cmd = "systemctl status #{
|
37
|
+
cmd = "systemctl status #{Zlown::Config::ZLOWN_SERVICE_NAME}"
|
39
38
|
system cmd
|
40
39
|
end
|
41
40
|
|
42
41
|
def self.log(args = [], opts = {})
|
43
|
-
cmd = "journalctl -u #{
|
42
|
+
cmd = "journalctl -u #{Zlown::Config::ZLOWN_SERVICE_NAME}"
|
44
43
|
system cmd
|
45
44
|
end
|
46
45
|
end
|
data/lib/zlown/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zlown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomas Korcak
|
@@ -134,14 +134,16 @@ files:
|
|
134
134
|
- lib/zlown/cli/cmd/run_cmd.rb
|
135
135
|
- lib/zlown/cli/cmd/script_cmd.rb
|
136
136
|
- lib/zlown/cli/cmd/systemctl_cmd.rb
|
137
|
+
- lib/zlown/cli/cmd/update_cmd.rb
|
137
138
|
- lib/zlown/cli/cmd/version_cmd.rb
|
138
139
|
- lib/zlown/cli/shared.rb
|
140
|
+
- lib/zlown/config.rb
|
139
141
|
- lib/zlown/core/core.rb
|
140
142
|
- lib/zlown/daemon/daemon.rb
|
141
143
|
- lib/zlown/script/script.rb
|
142
144
|
- lib/zlown/systemctl/systemctl.rb
|
143
145
|
- lib/zlown/version.rb
|
144
|
-
- scripts/enable-
|
146
|
+
- scripts/enable-forwarding.sh
|
145
147
|
- scripts/sniff-httpry.sh
|
146
148
|
- scripts/sniff-ngrep.sh
|
147
149
|
- scripts/wifi-power.sh
|
data/scripts/enable-rogue.sh
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
#! /usr/bin/env bash
|
2
|
-
|
3
|
-
IF_WIFI=wlan1
|
4
|
-
IF_LTE=eth1
|
5
|
-
|
6
|
-
iptables -t nat -F
|
7
|
-
iptables -F
|
8
|
-
iptables -t nat -A POSTROUTING -o ${IF_LTE} -j MASQUERADE
|
9
|
-
iptables -A FORWARD -i ${IF_WIFI} -o ${IF_LTE} -j ACCEPT
|
10
|
-
|
11
|
-
# echo '1' > /proc/sys/net/ipv4/ip_forward
|
12
|
-
|