-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmmfunctions.py
More file actions
191 lines (168 loc) · 7.63 KB
/
mmfunctions.py
File metadata and controls
191 lines (168 loc) · 7.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
100
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
134
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import os
import subprocess as sub
from sys import platform
import getpass
from threading import *
# from Script_Runner import scriptrunnerGUI as srg
import distro #for figuring out what linux distro
#global variables
OS = distro.linux_distribution()
ops = OS[0]
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
class mmfunc:
def updates(self):
if ops == 'Ubuntu' or ops == 'debian':
command = 'sudo apt update && upgrade -y'
sub.Popen(command.split())
print('Updates Completed!')
elif platform == 'darwin':
command = 'sudo softwareupdate -i -a'
sub.Popen(command.split())
elif ops == 'Manjaro Linux':
command = 'sudo pacman -Syu'
sub.Popen(command.split())
elif platform == 'win32':
#command = "C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\powershell.exe", ". \"./mmfucntions.ps1\";", "&winupd"
#sub.Popen(command)
commands = """ Write-Host("Installing module PSWindowsUpdate if not already installed... ")
Install-Module PSWindowsUpdate
Write-Host("PSWindowsUpdate is now installed.")
Write-Host("")
Write-Host("Getting Windows Updates...")
Import-Module PSWindowsUpdate
$updates = Invoke-Command -ScriptBlock {Get-Wulist -verbose}
$updatenumber = ($updates.kb).count
if ($null -ne $updates){
Get-WindowsUpdate -AcceptAll -Install | Out-File C:\PSWindowsUpdate.log
do {$updatestatus = Get-Content c:\PSWindowsUpdate.log
"Currently processing the following update:"
Get-Content c:\PSWindowsUpdate.log | select-object -last 1
Start-Sleep -Seconds 10
$ErrorActionPreference = 'SilentlyContinue'
$installednumber = ([regex]::Matches($updatestatus, "Installed" )).count
$ErrorActionPreference = ‘Continue’
}until ( $installednumber -eq $updatenumber)
}
Remove-Item -path C:\PSWindowsUpdate.log -ErrorAction SilentlyContinue
Write-Host("")
Write-Host("All updates are installed!")"""
sub.Popen(["powershell","& {" + commands + "}"])
# Definitely is executing but it needs to be run as admin. Must figure out a way to do that.
# print('This function (updates) does not currently support this OS.')
else:
print('This command does not currently support this OS')
def srchmedia(self):
if platform == 'linux' or platform == 'darwin':
extensions = ('.jpg', '.mp4', '.flv', '.avi', '.wmv', '.mov', '.png', '.tif', '.gif', '.mp3', '.wma', '.aif', '.jar')
for root, dirs, files in os.walk('/home/'):
for filename in files:
if any(filename.endswith(extension) for extension in extensions):
# f = open('Q:\\Cyber Patriots\\my_scripts_and_STIGS\\Scripts\\CP_ScriptsREPAIR\\Script Runner GUI\\logTest.txt', 'a+')
f = open('/home/' + getpass.getuser() + '/Desktop/LogTest.txt', 'a+')
filepath = os.path.join(root, filename)
f.write(filepath + '\n')
f.close()
print(filepath)
print('Scan for unapproved media complete.')
elif platform == 'win32':
extensions = ('.jpg', '.mp4', '.flv', '.avi', '.wmv', '.mov', '.png', '.tif', '.gif', '.mp3', '.wma', '.aif', '.jar')
for root, dirs, files in os.walk('C:\\Users\\'):
for filename in files:
if any(filename.endswith(extension) for extension in extensions):
f = open('C:\\Users\\' + getpass.getuser() + '\\Desktop\\logTest.txt', 'a+')
#f = open('/home/' + getpass.getuser() + '/Desktop/LogTest.txt', 'a+')
filepath = os.path.join(root, filename)
f.write(filepath + '\n')
f.close()
print(filepath)
print('Scan for unapproved media complete.')
def fwl(self):
print('This command is currently in developement')
def servSet(self):
print('This command is currently in developement')
def malRem(self):
print('This command is currently in developement')
def alyn(self):
if ops == 'Ubuntu' or ops == 'debian':
command = 'sudo apt install lynis -y'
sub.Popen(command.split())
command2 = 'sudo lynis audit system'
sub.Popen(command2.split())
elif ops == 'darwin':
print('This function does not currently support this OS')
elif ops == 'Manjaro Linux':
command = 'sudo pacman -S lynis'
sub.Popen(command.split())
command2 = 'sudo lynis audit system'
sub.Popen(command2.split())
elif platform == 'win32':
print('This function (alyn) does not currently support this OS.')
def basConf(self):
print('This command is currently in developement')
def rmProCont(self):
print('This command is currently in developement')
class ThreadmmFunc():
def threaderSRCH(self):
try:
self.threader = Thread(target=mmfunc.srchmedia)
self.threader.start()
except Exception as e:
print(e)
#print(com)
print('Could not start thread')
def threaderUPDT(self):
try:
self.threader = Thread(target=lambda: mmfunc.updates(self))
self.threader.start()
except Exception as e:
print(e)
print('Could not start thread')
def threaderFWL(self):
try:
self.threader = Thread(target=lambda: mmfunc.fwl(self))
self.threader.start()
except Exception as e:
print(e)
print('Could not start thread')
def threaderServ(self):
try:
self.threader = Thread(target=lambda: mmfunc.servSet(self))
self.threader.start()
except Exception as e:
print(e)
print('Could not start thread')
def threaderMALREM(self):
try:
self.threader = Thread(target=lambda: mmfunc.malRem(self))
self.threader.start()
except Exception as e:
print(e)
print('Could not start thread')
def threaderALYN(self):
try:
self.threader = Thread(target=lambda: mmfunc.alyn(self))
self.threader.start()
except Exception as e:
print(e)
print('Could not start thread')
def threaderBASEconf(self):
try:
self.threader = Thread(target=lambda: mmfunc.basconf(self))
self.threader.start()
except Exception as e:
print(e)
print('Could not start thread')
def threaderRMproCont(self):
try:
self.threader = Thread(target=lambda: mmfunc.rmProCont(self))
self.threader.start()
except Exception as e:
print(e)
print('Could not start thread')