DNS
SPF
Assert a value is present in the DNS record of the zone.
Class: Drutiny\Audit\DNS\SPF
Extends: Drutiny\Audit
Package: drutiny/drutiny
Parameters
Name | Type | Description | Default |
---|---|---|---|
type | string | The type of DNS record to lookup | A |
zone | array | A list of fields returned from the query to be available globally (outside of a row). | null |
matching_value | string | A value that should be present in the queried DNS record. | null |
Tokens
Name | Type | Description | Default |
---|---|---|---|
type | string | The type of DNS record to lookup | A |
zone | array | A list of fields returned from the query to be available globally (outside of a row). | null |
matching_value | string | A value that should be present in the queried DNS record. | null |
Source
public function audit(Sandbox $sandbox)
{
$type = $sandbox->getParameter('type', 'A');
$uri = $sandbox->getTarget()->uri();
$domain = preg_match('/^http/', $uri) ? parse_url($uri, PHP_URL_HOST) : $uri;
$zone = $sandbox->getParameter('zone', $domain);
// Set the zone incase it wasn't set.
$sandbox->setParameter('zone', $zone);
$values = $sandbox->localExec(strtr('dig +short @type @zone', [
'@type' => $type,
'@zone' => $zone,
]));
$values = array_map('trim', explode(PHP_EOL, $values));
$values = array_filter($values);
$matching_value = $sandbox->getParameter('matching_value');
return (bool) count(array_filter($values, function ($txt) use ($matching_value) {
return strpos($txt, $matching_value) !== FALSE;
}));
}