Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement Mega Link Analyzer * Fixed failed test changed regex to match url boundary
- Loading branch information
1 parent
f9bd202
commit c884cb6
Showing
3 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# -*- coding: utf-8 -*- | ||
from .regexanalyzer import RegexAnalyzer | ||
|
||
|
||
class MegaLinkAnalyzer(RegexAnalyzer): | ||
""" | ||
Analyzer to match mega links via regex | ||
""" | ||
name = "MegaLinkAnalyzer" | ||
|
||
def __init__(self, actions): | ||
regex = r"\b(https?:\/\/)?mega\.nz\/#F![\w-]{8}(![\w-]{22}(![\w-]{8})?)?\b" | ||
super().__init__(actions, regex) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# -*- coding: utf-8 -*- | ||
import unittest | ||
from unittest import mock | ||
|
||
from pastepwn.analyzers.megalinkanalyzer import MegaLinkAnalyzer | ||
|
||
|
||
class TestMegaLinkAnalyzer(unittest.TestCase): | ||
def setUp(self): | ||
self.analyzer = MegaLinkAnalyzer(None) | ||
self.paste = mock.Mock() | ||
|
||
def test_match_positive(self): | ||
"""Test if positives are recognized""" | ||
# working mega link (short version) | ||
self.paste.body = "https://mega.nz/#F!XTQVEAZZ" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
|
||
# working mega link (medium version) | ||
self.paste.body = "https://mega.nz/#F!XTQVEAZZ!eqxlOvTxJKnvAkYvjC0O8g" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
|
||
# working mega link (long version) | ||
self.paste.body = "https://mega.nz/#F!PB8SSawR!SUokSlF2Zy8CR004DNFfNw!LQtniCoa" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
|
||
# without https header | ||
self.paste.body = "mega.nz/#F!XTQVEAZZ!eqxlOvTxJKnvAkYvjC0O8g" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
|
||
# http header | ||
self.paste.body = "http://mega.nz/#F!XTQVEAZZ!eqxlOvTxJKnvAkYvjC0O8g" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
|
||
# in a sentence | ||
self.paste.body = "check out this file:https://mega.nz/#F!PB8SSawR!SUokSlF2Zy8CR004DNFfNw!LQtniCoa" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
|
||
def test_match_negative(self): | ||
"""Test if negatives are not recognized""" | ||
self.paste.body = "" | ||
self.assertFalse(self.analyzer.match(self.paste)) | ||
|
||
self.paste.body = None | ||
self.assertFalse(self.analyzer.match(self.paste)) | ||
|
||
# Invalid segment length | ||
self.paste.body = "https://mega.nz/#F!XTQVEAZZ1!eqxlOvTxJKnvAkYvjC0O8g" | ||
self.assertFalse(self.analyzer.match(self.paste)) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |