Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathdetectify.php
More file actions
Latest commit
137 lines (115 loc) · 4.03 KB
/
Copy pathdetectify.php
File metadata and controls
137 lines (115 loc) · 4.03 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
<?php
// This example uses the Httpful library to make requests. http://phphttpclient.com/
include('httpful.phar');
class Detectify
{
// Detectify API endpoint, no trailing slash
privateconstENDPOINT = "https://api.detectify.com/rest";
private$api_key;
private$secret_key;
function__construct($api_key, $secret_key)
{
$this->api_key = $api_key;
$this->secret_key = $secret_key;
}
functionmakeHeaders($method, $path, $timestamp, $body = null)
{
$method = strtoupper($method);
if ($body != null) {
$body = '';
}
$msg = "$method;$path;$this->api_key;$timestamp;$body";
$key = base64_decode($this->secret_key);
$signature_bytes = hash_hmac('sha256', $msg, $key, true);
$signature = base64_encode($signature_bytes);
$headers = array(
"X-Detectify-Key" => $this->api_key,
"X-Detectify-Signature" => $signature,
"X-Detectify-Timestamp" => $timestamp
);
return$headers;
}
/**
* Start a scan
* @param string $scan_profile scan profile to start a scan on
* @return bool true if a scan was started, false if not
*/
functionstartScan($scan_profile)
{
$path = "/v2/scans/$scan_profile/";
$url = self::ENDPOINT . $path;
$timestamp = time();
$headers = $this->makeHeaders("POST", $path, $timestamp);
$response = \Httpful\Request::post($url)
->addHeaders($headers)
->send();
switch ($response->code) {
case202:
print("Scan start request accepted");
returntrue;
case400:
print("Invalid scan profile token");
returnfalse;
case401:
print("Missing/invalid API key or message signature, or invalid timestamp");
returnfalse;
case403:
print("The API key cannot access this functionality");
returnfalse;
case404:
print("The specified scan profile does not exist or the API cannot access the profile");
returnfalse;
case409:
print("A scan is already running on the specified profile");
returnfalse;
case423:
print("The domain is not verified");
returnfalse;
case500:
case503:
print("An error occurred while processing the request");
returnfalse;
}
returnfalse;
}
/**
* Get scan status
* @param string $scan_profile scan profile to get the scan status for
*/
functionscanStatus($scan_profile)
{
$path = "/v2/scans/$scan_profile/";
$url = self::ENDPOINT . $path;
$timestamp = time();
$headers = $this->makeHeaders("GET", $path, $timestamp);
$response = \Httpful\Request::get($url)
->addHeaders($headers)
->send();
switch ($response->code) {
case200:
print_r($response->body);
break;
case400:
print("Invalid scan profile token");
break;
case401:
print("Missing/invalid API key or message signature, or invalid timestamp");
break;
case403:
print("The API key cannot access this functionality");
break;
case404:
print("The specified scan profile does not exist or the API cannot access the profile");
break;
case500:
case503:
print("An error occurred while processing the request");
}
}
}
$api_key = "d4bf676ee6146557cbf0f28fe6cbc290";
$secret_key = "SGVsbG8sIHdvcmxkISBJIGFtIGEgdGVhcG90IQ==";
$scan_profile = "5605b488634efe810dff4276e28ca7f9";
$dtfy = newDetectify($api_key, $secret_key);
$dtfy->startScan($scan_profile);
$dtfy->scanStatus($scan_profile);