-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcreate_target.py
executable file
·85 lines (68 loc) · 2.86 KB
/
create_target.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
#!/usr/bin/env python
"""
Create a target using the API
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 only the user that created the account is able to create targets.
If you require enabling other users please contact our support at
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, "auth-obtain/")
target_endpoint = urljoin(api_base_url, "targets/")
site_endpoint = urljoin(api_base_url, "targets/{target_id}/site/")
verification_endpoint = urljoin(api_base_url,
"targets/{target_id}/site/verify/")
# Get login token
response = requests.post(auth_endpoint,
data={'username': username, 'password': password})
token = response.json()['token']
headers = {'Authorization': "JWT {}".format(token)}
# Create target
response = requests.post(target_endpoint, headers=headers)
target_id = response.json()['id']
# Input target name and url
response = requests.put(
site_endpoint.format(target_id=target_id), headers=headers,
data={
'name': "Example",
'url': "http://ox-test1.westeurope.cloudapp.azure.com",
})
verification_token = response.json()['verification_token']
# Verify the site
# MANUAL STEP!!
# Site verification must be done either by file or DNS record
verification_type = "dns"
response = requests.post(
verification_endpoint.format(target_id=target_id), headers=headers,
data={'type': verification_type})
if not response.json()['site']['verified']:
if verification_type == "dns":
print("Add the following DNS TXT record to your target's (sub)domain:")
print("Probe.ly={verification_token}".format(
verification_token=verification_token))
elif verification_type == "file":
print("Add the following file your target's root path:")
print("Filename: {verification_token}.txt".format(
verification_token=verification_token))
print("File content: Probe.ly")
# Add site to subscription
# Trial
# During your trial period do not worry the first target you scan
# will be automatically added to your subscription (trials usually allow only
# one site).
# Site Pool
# Sites are added to your subscription as soon as they are created.
# On Demand
# You are paying per target added to your subscription.
# Please go to the user interface and in the user drop down (top right corner)
# select account. Afterwards click "Subscribe to out plans" and follow the
# regular billing flow to add the target.
# We do not recommend adding targets to the subscription using the API (since
# it incurs a payment) but if you really want to don't be shy and ask us.