-
Notifications
You must be signed in to change notification settings - Fork 114
/
SolarWindsOrionAPI_Manage.py
348 lines (285 loc) · 13.2 KB
/
SolarWindsOrionAPI_Manage.py
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
#python3
import requests
import base64
import sys
import json
import os
import warnings
warnings.filterwarnings("ignore")
def SWIS_query(api_host, username, password, query, **params):
authentication = username + ":" + password
authentication = authentication.encode("utf-8")
credential = base64.b64encode(authentication).decode("utf8")
url = "https://" + api_host + ":17778/SolarWinds/InformationService/v3/Json/Query"
headers = {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0",
"Authorization": "Basic " + credential,
"Content-Type": "application/json"
}
data = {
"query": query,
"parameters":params
}
r = requests.post(url, headers = headers, data=json.dumps(data), verify = False)
if r.status_code ==200:
print("[+] query success")
for i in r.json()["results"]:
print(i)
else:
print("[!]")
print(r.status_code)
print(r.text)
exit(0)
def SWIS_invoke(api_host, username, password, entity, verb, *args):
authentication = username + ":" + password
authentication = authentication.encode("utf-8")
credential = base64.b64encode(authentication).decode("utf8")
url = "https://" + api_host + ":17778/SolarWinds/InformationService/v3/Json/Invoke/" + entity + "/" + verb
headers = {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0",
"Authorization": "Basic " + credential,
"Content-Type": "application/json"
}
r = requests.post(url, headers = headers, data=json.dumps(args), verify = False)
if r.status_code ==200:
print("[+] invoke success")
print(r.text)
else:
print("[!]")
print(r.status_code)
print(r.text)
exit(0)
def SWIS_create(api_host, username, password, entity, **properties):
authentication = username + ":" + password
authentication = authentication.encode("utf-8")
credential = base64.b64encode(authentication).decode("utf8")
url = "https://" + api_host + ":17778/SolarWinds/InformationService/v3/Json/Create/" + entity
headers = {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0",
"Authorization": "Basic " + credential,
"Content-Type": "application/json"
}
r = requests.post(url, headers = headers, data=json.dumps(properties), verify = False)
if r.status_code ==200:
print("[+] create success")
print(r.text)
else:
print("[!]")
print(r.status_code)
print(r.text)
exit(0)
def SWIS_read(api_host, username, password, uri):
authentication = username + ":" + password
authentication = authentication.encode("utf-8")
credential = base64.b64encode(authentication).decode("utf8")
url = "https://" + api_host + ":17778/SolarWinds/InformationService/v3/Json/" + uri
headers = {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0",
"Authorization": "Basic " + credential,
"Content-Type": "application/json"
}
r = requests.get(url, headers = headers, verify = False)
if r.status_code ==200:
print("[+] read success")
print(r.text)
else:
print("[!]")
print(r.status_code)
print(r.text)
exit(0)
def SWIS_update(api_host, username, password, uri, **properties):
authentication = username + ":" + password
authentication = authentication.encode("utf-8")
credential = base64.b64encode(authentication).decode("utf8")
url = "https://" + api_host + ":17778/SolarWinds/InformationService/v3/Json/" + uri
headers = {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0",
"Authorization": "Basic " + credential,
"Content-Type": "application/json"
}
r = requests.post(url, headers = headers, data=json.dumps(properties), verify = False)
if r.status_code ==200:
print("[+] update success")
print(r.text)
else:
print("[!]")
print(r.status_code)
print(r.text)
exit(0)
def SWIS_bulkupdate(api_host, username, password, uris, **properties):
authentication = username + ":" + password
authentication = authentication.encode("utf-8")
credential = base64.b64encode(authentication).decode("utf8")
url = "https://" + api_host + ":17778/SolarWinds/InformationService/v3/Json/BulkUpdate"
headers = {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0",
"Authorization": "Basic " + credential,
"Content-Type": "application/json"
}
data = {'uris': uris, 'properties': properties}
r = requests.post(url, headers = headers, data=json.dumps(data), verify = False)
if r.status_code ==200:
print("[+] bulkupdate success")
print(r.text)
else:
print("[!]")
print(r.status_code)
print(r.text)
exit(0)
def SWIS_delete(api_host, username, password, uri):
authentication = username + ":" + password
authentication = authentication.encode("utf-8")
credential = base64.b64encode(authentication).decode("utf8")
url = "https://" + api_host + ":17778/SolarWinds/InformationService/v3/Json/" + uri
headers = {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0",
"Authorization": "Basic " + credential,
"Content-Type": "application/json"
}
r = requests.delete(url, headers = headers, verify = False)
if r.status_code ==200:
print("[+] delete success")
print(r.text)
else:
print("[!]")
print(r.status_code)
print(r.text)
exit(0)
def SWIS_bulkdelete(api_host, username, password, uris):
authentication = username + ":" + password
authentication = authentication.encode("utf-8")
credential = base64.b64encode(authentication).decode("utf8")
url = "https://" + api_host + ":17778/SolarWinds/InformationService/v3/Json/BulkDelete"
headers = {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0",
"Authorization": "Basic " + credential,
"Content-Type": "application/json"
}
data = {'uris': uris}
r = requests.post(url, headers = headers, data=json.dumps(data), verify = False)
if r.status_code ==200:
print("[+] bulkdelete success")
print(r.text)
else:
print("[!]")
print(r.status_code)
print(r.text)
exit(0)
if __name__ == "__main__":
if len(sys.argv)!=5:
print("SolarWindsOrionAPI_Manage")
print("Use SolarWinds Orion API to manage the Orion platform")
print("Usage:")
print("%s <IP> <username> <password> <mode>"%(sys.argv[0]))
print("mode:")
print("- GetAccounts")
print("- GetAlertActive")
print("- GetAlertHistory")
print("- GetCredential")
print("- GetNodes")
print("- GetOrionServers")
print("- query")
print("- invoke")
print("- create")
print("- read")
print("- update")
print("- bulkupdate")
print("- delete")
print("- bulkdelete")
print("Eg.")
print("%s 192.168.1.1 admin Password123 GetAccounts"%(sys.argv[0]))
sys.exit(0)
else:
if sys.argv[4] == "GetAccounts":
print("[*] GetAccounts")
query = "SELECT TOP 1000 AccountID,MenuName,LastLogin FROM Orion.Accounts"
params = {}
SWIS_query(sys.argv[1], sys.argv[2], sys.argv[3], query, **params)
elif sys.argv[4] == "GetAlertActive":
print("[*] GetAlertActive")
query = "SELECT TOP 1000 TriggeredDateTime,TriggeredMessage FROM Orion.AlertActive"
params = {}
SWIS_query(sys.argv[1], sys.argv[2], sys.argv[3], query, **params)
elif sys.argv[4] == "GetAlertHistory":
print("[*] GetAlertHistory")
query = "SELECT TOP 1000 Message,TimeStamp FROM Orion.AlertHistory"
params = {}
SWIS_query(sys.argv[1], sys.argv[2], sys.argv[3], query, **params)
elif sys.argv[4] == "GetCredential":
print("[*] GetCredential")
query = "SELECT TOP 1000 ID,Name,Description,CredentialType,CredentialOwner FROM Orion.Credential"
params = {}
SWIS_query(sys.argv[1], sys.argv[2], sys.argv[3], query, **params)
elif sys.argv[4] == "GetNodes":
print("[*] GetNodes")
query = "SELECT TOP 1000 IP_Address,Caption,DNS,SysName,Vendor,Description,Location,IOSVersion,StatusDescription,MachineType,IsServer,SNMPVersion,EntityType FROM Orion.Nodes"
params = {}
SWIS_query(sys.argv[1], sys.argv[2], sys.argv[3], query, **params)
elif sys.argv[4] == "GetOrionServers":
print("[*] GetOrionServers")
query = "SELECT TOP 1000 ServerType,HostName,SWAKeepAlive,SWAVersion,Details FROM Orion.OrionServers"
params = {}
SWIS_query(sys.argv[1], sys.argv[2], sys.argv[3], query, **params)
elif sys.argv[4] == "query":
print("[*] query")
print("[*] parameter:")
print(" - query ")
query = input("input the query: (eg. SELECT AccountID FROM Orion.Accounts )")
params = {}
SWIS_query(sys.argv[1], sys.argv[2], sys.argv[3], query, **params)
elif sys.argv[4] == "invoke":
print("[*] invoke")
print("[*] parameter:")
print(" - entity")
print(" - verb")
print(" - args")
entity = input("input the entity: (eg. Metadata.Entity )")
verb = input("input the verb: (eg. GetAliases )")
args = input("input the args: (eg. SELECT B.Caption FROM Orion.Nodes B )")
SWIS_invoke(sys.argv[1], sys.argv[2], sys.argv[3], entity, verb, args)
elif sys.argv[4] == "create":
print("[*] create")
print("[*] parameter:")
print(" - entity")
print(" - properties")
entity = input("input the entity: (eg. Orion.Pollers )")
properties = input("input the properties: (eg. {\"PollerType\":\"hi from curl 2\", \"NetObject\":\"N:123\"} )")
SWIS_create(sys.argv[1], sys.argv[2], sys.argv[3], entity, **json.loads(properties))
elif sys.argv[4] == "read":
print("[*] read")
print("[*] parameter:")
print(" - uri")
uri = input("input the uri: (eg. swis://Server1./Orion/Orion.Pollers/PollerID=1 )")
SWIS_read(sys.argv[1], sys.argv[2], sys.argv[3], uri)
elif sys.argv[4] == "update":
print("[*] update")
print("[*] parameter:")
print(" - uri")
print(" - properties")
uri = input("input the uri: (eg. swis://Server1./Orion/Orion.Pollers/PollerID=1 )")
properties = input("input the properties: (eg. {\"PollerType\":\"hi from curl\"} )")
SWIS_update(sys.argv[1], sys.argv[2], sys.argv[3], uri, **json.loads(properties))
elif sys.argv[4] == "bulkupdate":
print("[*] bulkupdate")
print("[*] parameter:")
print(" - uris")
print(" - properties")
uris = input("input the uris: (eg. swis://Server1/Orion/Orion.Nodes/NodeID=1/CustomProperties,swis://Server1/Orion/Orion.Nodes/NodeID=2/CustomProperties )")
print("uris:")
print(uris.split(','))
properties = input("input the properties: (eg. {\"City\": \"Serenity Valley\"} )")
SWIS_bulkupdate(sys.argv[1], sys.argv[2], sys.argv[3], uris.split(','), **json.loads(properties))
elif sys.argv[4] == "delete":
print("[*] delete")
print("[*] parameter:")
print(" - uri")
uri = input("input the uri: (eg. swis://Server1./Orion/Orion.Pollers/PollerID=1 )")
SWIS_delete(sys.argv[1], sys.argv[2], sys.argv[3], uri)
elif sys.argv[4] == "bulkdelete":
print("[*] bulkdelete")
print("[*] parameter:")
print(" - uris")
uris = input("input the uris: (eg. swis://Server1/Orion/Orion.Nodes/NodeID=1/CustomProperties,swis://Server1/Orion/Orion.Nodes/NodeID=2/CustomProperties )")
print("uris:")
print(uris.split(','))
SWIS_bulkdelete(sys.argv[1], sys.argv[2], sys.argv[3], uris.split(','))