【问题标题】:Matching HTML anchors which display different URL from its href [closed]匹配显示与其 href 不同的 URL 的 HTML 锚 [关闭]
【发布时间】:2021-02-10 17:36:29
【问题描述】:

我们是网络钓鱼攻击的受害者,我们希望加强我们的 Postfix 垃圾邮件过滤器。

我们想要检测在 URL 周围包含锚点 (<a>) 但在其 href 中定位不同 URL 的电子邮件正文。

以下是示例列表:

VALID
<a href="www.google.com">www.google.com</a>
<a href="www.google.com">google.com</a>
<a href="https://www.google.com" id="someId">google.com</a>
<a id="ID" href="https://google.com">google.com</a>

INVALID
<a href="www.malicious.com">www.google.com</a>
<a href="www.malicious.com">google.com</a>
<a href="www.malicious.com" id="someId">google.com</a>
<a id="ID" href="https://google.evil.com">google.com</a>

https://regex101.com/r/kZUN84/1

我的计划是创建一个包含域 + TLD 的命名捕获组(即“https://www.google.com”的“google.com”),并检查锚标记内的文本是否匹配.如果不是,则可能是垃圾邮件。

正如您在 regex101 链接中看到的那样,我相信我必须使用捕获组和负前瞻,但我仍在努力编写它...(我知道 URL 验证可能很棘手)

有什么建议检查正则表达式是否匹配其子字符串之一?

【问题讨论】:

    标签: regex postfix-mta spam phishing


    【解决方案1】:

    我可以想出这个,这是匹配所有网络钓鱼类型而不是有效类型。但我认为它很容易出现这样的误报:

    • &lt;a id="ID" href="https://google.com"&gt;google&lt;/a&gt;
    • &lt;a id="ID" href="https://google.com"&gt;link here&lt;/a&gt;

    这是正则表达式:

    <a\b\s*(?:.*)?(?=\bhref=)href="((?:https?:\/\/)?(?:www\.)?)?+(?'href'(?'start'[^"])[^"]+)"([^>]*)?>((?:https?:\/\/)?(?:www\.)?)?+(((?!\k'href')(?=\k'start'))|(?!\k'href'))([^<]+)(<\/a>)
    

    我需要 start 命名组来获取第二个链接中的可能位置,因为从那里我可以检查整个 href 组。 href 中的第一个字符有可能丢失,这就是我放置|(?!\k'href') 的原因。

    https://regex101.com/r/kZUN84/7(某些捕获组仅用于在 regex101 中着色)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-06-07
      • 2014-03-21
      • 1970-01-01
      • 2015-05-12
      • 2021-11-29
      • 2011-05-29
      • 2013-11-20
      相关资源
      最近更新 更多