|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Startwind\Inventorio\Collector\Website; |
|
4
|
|
|
|
|
5
|
|
|
use GuzzleHttp\Exception\ClientException; |
|
6
|
|
|
use GuzzleHttp\Exception\ServerException; |
|
7
|
|
|
use Startwind\Inventorio\Collector\BasicCollector; |
|
8
|
|
|
use Startwind\Inventorio\Collector\ClientAwareCollector; |
|
9
|
|
|
use Startwind\Inventorio\Collector\InventoryAwareCollector; |
|
10
|
|
|
use Startwind\Inventorio\Util\Client; |
|
11
|
|
|
use Startwind\Inventorio\Util\WebsiteUtil; |
|
12
|
|
|
|
|
13
|
|
|
class BadHeaderCollector extends BasicCollector implements InventoryAwareCollector, ClientAwareCollector |
|
14
|
|
|
{ |
|
15
|
|
|
protected string $identifier = "WebsiteBadHeader"; |
|
16
|
|
|
|
|
17
|
|
|
private array $inventory; |
|
18
|
|
|
private Client $client; |
|
19
|
|
|
|
|
20
|
|
|
public function setClient(Client $client): void |
|
21
|
|
|
{ |
|
22
|
|
|
$this->client = $client; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function setInventory(array $inventory): void |
|
26
|
|
|
{ |
|
27
|
|
|
$this->inventory = $inventory; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function collect(): array |
|
31
|
|
|
{ |
|
32
|
|
|
$domains = WebsiteUtil::extractDomains($this->inventory); |
|
33
|
|
|
|
|
34
|
|
|
$badHeaders = []; |
|
35
|
|
|
|
|
36
|
|
|
foreach ($domains as $domain) { |
|
37
|
|
|
try { |
|
38
|
|
|
$url = $domain; |
|
39
|
|
|
if (!str_starts_with($url, 'http')) $url = 'https://' . $url; |
|
40
|
|
|
$response = $this->client->get($url); |
|
41
|
|
|
} catch (ClientException $e) { |
|
42
|
|
|
$response = $e->getResponse(); |
|
43
|
|
|
} catch (ServerException $e) { |
|
44
|
|
|
$response = $e->getResponse(); |
|
45
|
|
|
} catch (\Exception $e) { |
|
46
|
|
|
continue; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$headers = $response->getHeaders(); |
|
50
|
|
|
|
|
51
|
|
|
if (array_key_exists('Server', $headers)) { |
|
52
|
|
|
if (str_contains($headers['Server'][0], 'Apache/')) { |
|
53
|
|
|
$badHeaders[$domain]['apache_version'] = $headers['Server'][0]; |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
if (array_key_exists('X-Powered-By', $headers)) { |
|
58
|
|
|
if (str_contains($headers['X-Powered-By'][0], 'PHP/')) { |
|
59
|
|
|
$badHeaders[$domain]['php_version'] = $headers['X-Powered-By'][0]; |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
var_dump($badHeaders); |
|
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
return $badHeaders; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|