forked from Probely/API_Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_scanning_agent.py
executable file
·63 lines (52 loc) · 1.71 KB
/
create_scanning_agent.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
#!/usr/bin/env python
"""
Create a scanning agent using the API and assign it to a target
This action may only be performed by users with the required permissions.
Target API keys will not be able to create targets.
At the moment scanning agents are only available for Probely + accounts.
If you require this feature please contact our support at
support@probely.com.
This example is for python 3.5
"""
import getpass
from urllib.parse import urljoin
import requests
username = input("Username: ")
password = getpass.getpass()
api_base_url = "https://api.probely.com"
auth_endpoint = urljoin(api_base_url, "/enterprise/auth/obtain/")
scanning_agent_endpoint = urljoin(api_base_url, "/scanning-agents/")
target_endpoint = urljoin(api_base_url, "/targets/")
# Get login token
response = requests.post(
auth_endpoint, json={"username": username, "password": password}
)
headers = {"Authorization": "JWT {}".format(response.json()["token"])}
# Create scanning agent
response = requests.post(
scanning_agent_endpoint, headers=headers, json={"name": "Agent example"},
)
agent_id = response.json()["id"]
# Create target with agent assigned
target_url = "http://ox-test1.westeurope.cloudapp.azure.com"
response = requests.post(
target_endpoint,
headers=headers,
json={
"site": {"name": "Example", "url": target_url},
"scanning_agent": {"id": agent_id},
},
)
target_id = response.json()["id"]
# Unassign agent
response = requests.patch(
"{}{}/".format(target_endpoint, target_id),
headers=headers,
json={"scanning_agent": {"id": None}},
)
# Reassign agent
response = requests.patch(
"{}{}/".format(target_endpoint, target_id),
headers=headers,
json={"scanning_agent": {"id": agent_id}},
)