Module: Macos::Artifacts::State

Defined in:
lib/macos/artifacts/state.rb

Class Method Summary collapse

Class Method Details

.adminUsersObject



23
24
25
26
27
28
29
30
31
# File 'lib/macos/artifacts/state.rb', line 23

def self.adminUsers
    admins=`dscl . -read /Groups/admin GroupMembership`.split(" ")
    admins.shift()
  
    puts "Admins:"
    admins.each do |name|
      puts "  #{name}"
    end
end

.networkInterfacesObject



184
185
186
187
188
189
190
191
192
193
194
# File 'lib/macos/artifacts/state.rb', line 184

def self.networkInterfaces
  listOfNetworkInterfaces = `ifconfig`.split("\n")
  puts "Network Interfaces:"
  listOfNetworkInterfaces.each do |item|
    if item.start_with?(/^*:/)
      puts item.strip
    else
      puts "  #{item}"
    end
  end
end

.openNetworkConnectionsObject



169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/macos/artifacts/state.rb', line 169

def self.openNetworkConnections
  listOfOpenConnections = `lsof -i`.split("\n")
  listOfOpenConnections.shift
  puts "Open Network Connections:"
  listOfOpenConnections.each do |line|
    line = line.split(" ")
    puts "  Command: #{line[0]}"
    puts "    PID: #{line[1]}"
    puts "    USER: #{line[2]}"
    puts "    TYPE: #{line[4]}"
    puts "    NODE: #{line[7]}"
    puts "    NAME: #{line[8]}"
  end 
end

.processCPUObject



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/macos/artifacts/state.rb', line 101

def self.processCPU
  $psArray = []
  $psHash = {}
  processes = `ps axc -o user,pid,%cpu,%mem,start,time,command`.split("\n")
  processes.shift()

  processes.each do |item|
    data = item.split(" ")
    psHash = {
      :user => "#{data[0].strip}",
      :pid => "#{data[1].strip}",
      :cpu => "#{data[2].to_f}",
      :mem => "#{data[3].strip}",
      :start => "#{data[4].strip}",
      :time => "#{data[5].strip}",
      :command => "#{data[6].strip}"
    }
    $psArray.push(psHash)
  end

  $psArray.sort_by! { |hash| hash[:cpu] }
  puts "Top 10 CPU Processes:"

  $psArray.last(10).reverse.each do |ps|
    ps.each do |key,value|
      if key.to_s == "user"
         puts "  #{key}: #{value}"
      else
        puts "    #{key}: #{value}"
      end
    end
  end
end

.processMemoryObject



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/macos/artifacts/state.rb', line 135

def self.processMemory
  $psArray = []
  $psHash = {}
  processes = `ps axc -o user,pid,%cpu,%mem,start,time,command`.split("\n")
  processes.shift()

  processes.each do |item|
    data = item.split(" ")
    psHash = {
      :user => "#{data[0].strip.to_s}",
      :pid => "#{data[1].strip}",
      :cpu => "#{data[2].to_f}",
      :mem => "#{data[3].strip}",
      :start => "#{data[4].strip}",
      :time => "#{data[5].strip}",
      :command => "#{data[6].strip}"
    }
    $psArray.push(psHash)
  end

  $psArray.sort_by! { |hash| hash[:mem] }
  puts "Top 10 Memory Processes:"

  $psArray.last(10).reverse.each do |ps|
    ps.each do |key,value|
      if key.to_s == "user"
         puts "  #{key}: #{value}"
      else
        puts "    #{key}: #{value}"
      end
    end
  end
end

.systemExtensionsObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/macos/artifacts/state.rb', line 33

def self.systemExtensions
  sysext = `systemextensionsctl list`.split("\n")
  sysext.shift()
  
  puts "System Extensions:"
  sysext.each do |line|
    
    if line.start_with?('---')
      line = line.split(" ")
      $extType = line[1]
    elsif !line.start_with?("enabled")
      line = line.split(" ")
      if line[0] = "*"
        extEnabled = "true"
      else
        extEnabled = "false"
      end
      if line[1] = "*"
        extActive = "true"
      else
        extActive = "false"
      end
      teamID = line[2]
      bunldeID = line[3]
      versionExt = line[4]
  
      if line[5] != "[activated"
        if line[6] != "[activated"
          if line[7] != "[activated"
            if line[8] != "[activated"
              nameExt = "#{line[5]} #{line[6]} #{line[7]} #{line[8]}"
            else
              nameExt = "#{line[5]} #{line[6]} #{line[7]}"
            end
          end
        else
          nameExt = "#{line[5]}"
        end
      else
        nameExt = "#{line[5]}"
      end

      if line[6] == "[activated"
        stateExt = "#{line[6]} #{line[7]}"
      elsif line[7]  == "[activated"
        stateExt = "#{line[7]} #{line[8]}"
      elsif line[8]  == "[activated"
        stateExt = "#{line[8]} #{line[9]}"
      elsif line[9]  == "[activated"
        stateExt = "#{line[9]} #{line[10]}"
      else
        stateExt = "#{line[6]} #{line[7]}"
      end
      puts "  Type: #{$extType}"
      puts "    Enabled: #{extEnabled}"
      puts "    Active: #{extActive}"
      puts "    Team ID: #{teamID}"
      puts "    Bundle ID: #{bunldeID}"
      puts "    Version:  #{versionExt}"
      puts "    Name: #{nameExt}"
      puts "    State: #{stateExt}"
    end
    
 end
 

end

.usersObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/macos/artifacts/state.rb', line 6

def self.users
  $userHash={}
  Dir.entries("/Users").each do |username|
    if !username.start_with?(".")
      if username != "Shared" and username != "Guest"
        uid = `id -u #{username}`.strip
        $userHash["#{username}"] = uid
      end
    end
  end

  puts "Local Users:"
  $userHash.each do |key, value|
    puts "  #{key}: #{value}"
  end
end