mirror of https://github.com/MISP/MISP
fix: [internal] Reduce number of regexp in refang table
parent
9150c2be85
commit
e908a80656
|
@ -4,37 +4,12 @@ class ComplexTypeTool
|
|||
{
|
||||
private $__refangRegexTable = array(
|
||||
array(
|
||||
'from' => '/^(hxxp|hxtp|htxp)/i',
|
||||
'from' => '/^(hxxp|hxtp|htxp|meow|h\[tt\]p)/i',
|
||||
'to' => 'http',
|
||||
'types' => array('link', 'url')
|
||||
),
|
||||
array(
|
||||
'from' => '/^meow/i',
|
||||
'to' => 'http',
|
||||
'types' => array('link', 'url')
|
||||
),
|
||||
array(
|
||||
'from' => '/^h\[tt\]p/i',
|
||||
'to' => 'http',
|
||||
'types' => array('link', 'url')
|
||||
),
|
||||
array(
|
||||
'from' => '/\[\.\]/',
|
||||
'to' => '.',
|
||||
'types' => array('link', 'url', 'ip-dst', 'ip-src', 'domain|ip', 'domain', 'hostname')
|
||||
),
|
||||
array(
|
||||
'from' => '/\[dot\]/',
|
||||
'to' => '.',
|
||||
'types' => array('link', 'url', 'ip-dst', 'ip-src', 'domain|ip', 'domain', 'hostname')
|
||||
),
|
||||
array(
|
||||
'from' => '/\(dot\)/',
|
||||
'to' => '.',
|
||||
'types' => array('link', 'url', 'ip-dst', 'ip-src', 'domain|ip', 'domain', 'hostname')
|
||||
),
|
||||
array(
|
||||
'from' => '/\\\\\./',
|
||||
'from' => '/(\[\.\]|\[dot\]|\(dot\)|\\\\\.)/',
|
||||
'to' => '.',
|
||||
'types' => array('link', 'url', 'ip-dst', 'ip-src', 'domain|ip', 'domain', 'hostname')
|
||||
),
|
||||
|
@ -65,7 +40,7 @@ class ComplexTypeTool
|
|||
public function refangValue($value, $type)
|
||||
{
|
||||
foreach ($this->__refangRegexTable as $regex) {
|
||||
if (!isset($regex['types']) || in_array($type, $regex['types'])) {
|
||||
if (in_array($type, $regex['types'])) {
|
||||
$value = preg_replace($regex['from'], $regex['to'], $value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -158,4 +158,21 @@ class ComplexTypeToolTest extends TestCase
|
|||
$this->assertEquals('url', $results[0]['default_type']);
|
||||
}
|
||||
}
|
||||
|
||||
public function testRefangValueUrl(): void
|
||||
{
|
||||
$complexTypeTool = new ComplexTypeTool();
|
||||
foreach (['meow://example.com', 'h[tt]p://example.com'] as $test) {
|
||||
$this->assertEquals('http://example.com', $complexTypeTool->refangValue($test, 'url'));
|
||||
$this->assertEquals('http://example.com', $complexTypeTool->refangValue($test, 'link'));
|
||||
}
|
||||
}
|
||||
|
||||
public function testRefangValueDot(): void
|
||||
{
|
||||
$complexTypeTool = new ComplexTypeTool();
|
||||
foreach (['127.0.0.1', '127[.]0.0.1', '127[.]0[.]0[.]1', '127[dot]0[dot]0[dot]1', '127(dot)0(dot)0(dot)1', '127\.0.0.1'] as $test) {
|
||||
$this->assertEquals('127.0.0.1', $complexTypeTool->refangValue($test, 'ip-src'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue