guess_os 0.1.10 → 0.1.12

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: ba356d23160fed5e9c5140051e7730c5809d009c652abd46853602860f4ea95b
4
- data.tar.gz: 40cfd67eab46e8b660674485f376cef975bdc8c8750340250c08082d749d02e2
3
+ metadata.gz: 0be86469e07373cbb16f984b73bb740c26b014c352bcb8a3112cd90cc4aa3418
4
+ data.tar.gz: a7a7760ab74ffc209f7f3e852e5674a13108de1ebaf250408ee8397d9fed9123
5
5
  SHA512:
6
- metadata.gz: ae9c0fdebc54324cc87354185cacd60c80e031c0e6a6a39600787b876736dfc17d4901c57711f0814133d571ce04309ddfa1363e9c7b230ee9ebeb870372c92f
7
- data.tar.gz: 0d781a88af5f58df23274f325fc1a61da06752bb6ec847e3607b5f65883aa58b7bc3092e59f699286c991792d7198964a83084b342262a08644665cf5e851888
6
+ metadata.gz: 214db1350922347cfff01b453669258e67ea2b33ad92558c3eb7f6421ae92751c22c5308ea85c7a822b7a65270d0f3e3a33b5a1b2af5c30c0608eea7425165a4
7
+ data.tar.gz: dc4c9df949498c7246201d69b549f59de51680918f828bac1fae95cbdfbabba9e869f32ba4a3ba293b297879c225dd5cd6dc2592c20b16812212cd496f48b6b7
data/README.md CHANGED
@@ -1,7 +1,15 @@
1
1
 
2
2
  # GuessOS
3
3
 
4
- Try to guess the operating system installed on the host (local or remote)
4
+ Try to guess the operating system installed on the host (local or remote). Using SSH to connect remote host.
5
+
6
+ **But, What about nmap?**
7
+
8
+ It is true that nmap already performs the function of finding out the OS. We didn't want to repeat the work of nmap. The idea of the gem is:
9
+
10
+ * Work without nmap installed. Its posible some host have not installed.
11
+ * nmap is fine but slow to return results. We wanted to integrate this functionality into another application and were not completely satisfied with the nmap response times.
12
+ * In an extension of this gem we are thinking that it will use of nmap to obtain the results when it is a remote machine and we do not have SSH access to it.
5
13
 
6
14
  # Documentation
7
15
 
@@ -12,10 +20,17 @@ Try to guess the operating system installed on the host (local or remote)
12
20
 
13
21
  # Usage
14
22
 
23
+ > **WARNING**
24
+ >
25
+ > **guess_os** accepts several parameters (ip, username, password) to open an SSH connection to the remote host, and guess remote OS.
26
+ >
27
+ > In the case of writing IP="localhost" SSH is not used.
28
+
15
29
  ## Command
16
30
 
17
31
  ```console
18
- ./bin/guess_os
32
+ ❯ guess_os
33
+
19
34
  [GuessOS]
20
35
  ip? localhost
21
36
  port?
data/bin/guess-os ADDED
@@ -0,0 +1 @@
1
+ guess_os
data/bin/guess_os CHANGED
@@ -2,29 +2,43 @@
2
2
 
3
3
  require_relative '../lib/guess_os/host'
4
4
 
5
- puts "[GuessOS]"
5
+ def get_input_options
6
+ puts "[GuessOS]"
6
7
 
7
- print ' ip? '; ip = gets.chomp
8
- if ip.empty?
9
- ip = 'localhost' if ip.empty?
10
- else
11
- print ' port? '; port = gets.chomp
12
- print 'username? '; username = gets.chomp
13
- print 'password? '; password = gets.chomp
8
+ print ' ip? '; ip = gets.chomp
9
+ if ip.empty?
10
+ ip = "localhost"
11
+ elsif ip != "localhost"
12
+ print ' port? '; port = gets.chomp
13
+ print 'username? '; username = gets.chomp
14
+ print 'password? '; password = gets.chomp
14
15
 
15
- port = nil if port.empty?
16
- username = nil if username.empty?
17
- password = nil if password.empty?
16
+ port = nil if port.empty?
17
+ username = nil if username.empty?
18
+ password = nil if password.empty?
19
+ end
20
+ {
21
+ ip: ip,
22
+ port: port,
23
+ username: username,
24
+ password: password
25
+ }
18
26
  end
19
27
 
20
- host = GuessOS::Host.new(
21
- ip: ip,
22
- port: port,
23
- username: username,
24
- password: password
25
- )
28
+ def try_guess_with(options)
29
+ host = GuessOS::Host.new(
30
+ ip: options[:ip],
31
+ port: options[:port],
32
+ username: options[:username],
33
+ password: options[:password]
34
+ )
26
35
 
27
- puts "-" * 50 + "\n"
28
- puts " Type: #{host.os.type}"
29
- puts " Name: #{host.os.name}"
30
- puts " Desc: #{host.os.desc}"
36
+ puts "-" * 50 + "\n"
37
+ puts "[Results]"
38
+ puts " Type: #{host.os.type}"
39
+ puts " Name: #{host.os.name}"
40
+ puts " Desc: #{host.os.desc}"
41
+ end
42
+
43
+ options = get_input_options
44
+ try_guess_with options
data/lib/guess_os/host.rb CHANGED
@@ -22,5 +22,9 @@ module GuessOS
22
22
  def remote?
23
23
  !local?
24
24
  end
25
+
26
+ def self.unkown
27
+ GuessOS::OS.new(:unkown, :unkown, "Unkown")
28
+ end
25
29
  end
26
30
  end
@@ -1,22 +1,82 @@
1
1
  class Windows
2
2
  def self.guess(host)
3
3
  conn = GuessOS::Conn.new(host)
4
- command = "ver"
4
+
5
+ os = try_with_regedit(conn)
6
+ return os unless os.type == :unkown
7
+
8
+ os = try_with_ver(conn)
9
+ return os unless os.type == :unkown
10
+
11
+ os = try_with_folder(conn)
12
+ return os unless os.type == :unkown
13
+ end
14
+
15
+ def self.try_with_regedit(conn)
16
+ command = 'run "reg query \"HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\" /t REG_SZ'
5
17
  conn.exec(command)
18
+
19
+ identified = conn.ok && conn.last_output.include?("Windows")
20
+ return GuessOS::OS.unkown unless identified
21
+
22
+ output = conn.last_output
23
+ begin
24
+ lines = output.split("\n")
25
+ filter = lines.filter { _1.include? "ProductName" }
26
+ filter[0].gsub!("ProductName", "")
27
+ filter[0].gsub!("REG_SZ", "")
28
+
29
+ desc = filter[0].strip
30
+ items = desc.split
31
+ name = "#{items[0]} #{items[1]}"
32
+
33
+ GuessOS::OS.new(:windows, name, desc)
34
+ rescue
35
+ GuessOS::OS.unkown
36
+ end
37
+ end
38
+
39
+ def self.try_with_ver(conn)
6
40
  # ver => Microsoft Windows [Version 10.0.20348.469]
41
+ command = "ver"
42
+ conn.exec(command)
43
+
44
+ identified = conn.ok && conn.last_output.include?("Windows")
45
+ return GuessOS::OS.unkown unless identified
46
+
47
+ output = conn.last_output
48
+ begin
49
+ output.tr!("\r", "")
50
+ output.tr!("\n", "")
51
+ items = output.split
52
+ type = :windows
53
+ name = "windows #{items[3].split(".").first}"
54
+ desc = output
55
+ GuessOS::OS.new(type, name, desc)
56
+ rescue
57
+ GuessOS::OS.unkown
58
+ end
59
+ end
60
+
61
+ def self.try_with_folder(conn)
7
62
  # command = 'echo %windir%' => Windows
63
+ command = "cd c:\windows"
64
+ conn.exec(command)
8
65
 
9
66
  identified = conn.ok && conn.last_output.include?("Windows")
10
- return GuessOS::OS.new(:unkown, :unkown, conn.status) unless identified
67
+ return GuessOS::OS.unkown unless identified
11
68
 
12
69
  output = conn.last_output
13
- output.delete!("\r")
14
- output.delete!("\n")
15
- items = output.split
16
-
17
- type = :windows
18
- name = "windows #{items[3].split(".").first}"
19
- desc = output
20
- GuessOS::OS.new(type, name, desc)
70
+ begin
71
+ lines = output.split("\n")
72
+ filter = lines.filter { _1.include? "Volume" }
73
+ items = filter[0].split
74
+ type = :windows
75
+ name = items[-2, 2].join(" ").to_s
76
+ desc = filter[0]
77
+ GuessOS::OS.new(type, name, desc)
78
+ rescue
79
+ GuessOS::OS.unkown
80
+ end
21
81
  end
22
82
  end
data/lib/guess_os/type.rb CHANGED
@@ -2,22 +2,13 @@ require_relative "type/all"
2
2
 
3
3
  module GuessOS
4
4
  class Type
5
- def self.guess(host)
6
- os = GNULinux.guess(host)
7
- return os unless os.type == :unkown
8
-
9
- os = MacOS.guess(host)
10
- return os unless os.type == :unkown
11
-
12
- os = Windows.guess(host)
13
- return os unless os.type == :unkown
14
-
15
- os = Cygwin.guess(host)
16
- return os unless os.type == :unkown
17
-
18
- os = Minix.guess(host)
19
- return os unless os.type == :unkown
5
+ TYPES = [Windows, GNULinux, MacOS, Cygwin, Minix]
20
6
 
7
+ def self.guess(host)
8
+ TYPES.each do |klass|
9
+ os = klass.send :guess, host
10
+ return os unless os.type == :unkown
11
+ end
21
12
  os
22
13
  end
23
14
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GuessOS
4
- VERSION = "0.1.10"
4
+ VERSION = "0.1.12"
5
5
  NAME = "guess_os"
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guess_os
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Vargas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-16 00:00:00.000000000 Z
11
+ date: 2023-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh
@@ -24,7 +24,8 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '7.0'
27
- description: Guess local or remote OS.
27
+ description: Try to guess the operating system installed on the host (local or remote).
28
+ Using SSH to connect remote host.
28
29
  email:
29
30
  - dvarrui@protonmail.com
30
31
  executables:
data/bin/guess-os DELETED
@@ -1,30 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require_relative '../lib/guess_os/host'
4
-
5
- puts "[GuessOS]"
6
-
7
- print ' ip? '; ip = gets.chomp
8
- if ip.empty?
9
- ip = 'localhost' if ip.empty?
10
- else
11
- print ' port? '; port = gets.chomp
12
- print 'username? '; username = gets.chomp
13
- print 'password? '; password = gets.chomp
14
-
15
- port = nil if port.empty?
16
- username = nil if username.empty?
17
- password = nil if password.empty?
18
- end
19
-
20
- host = GuessOS::Host.new(
21
- ip: ip,
22
- port: port,
23
- username: username,
24
- password: password
25
- )
26
-
27
- puts "-" * 50 + "\n"
28
- puts " Type: #{host.os.type}"
29
- puts " Name: #{host.os.name}"
30
- puts " Desc: #{host.os.desc}"