-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from YellowFoxH4XOR/master
TASK: Analyser for DB connector strings
- Loading branch information
Showing
3 changed files
with
49 additions
and
0 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,12 @@ | ||
# -*- coding: utf-8 -*- | ||
from .regexanalyzer import RegexAnalyzer | ||
|
||
|
||
class DBConnAnalyzer(RegexAnalyzer): | ||
"""Analyzer to match on email addresses via regex""" | ||
name = "DBConnAnalyzer" | ||
|
||
def __init__(self, actions): | ||
# https:// should be ignored | ||
regex = r"(\b(?!http(s)?\b)\w+[a-zA-Z]+://[a-zA-z0-9.:,]+)" | ||
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,35 @@ | ||
# -*- coding: utf-8 -*- | ||
import unittest | ||
from unittest import mock | ||
|
||
from pastepwn.analyzers.dbconnstringanalyzer import DBConnAnalyzer | ||
|
||
|
||
class TestDBConnAnalyzer(unittest.TestCase): | ||
def setUp(self): | ||
self.analyzer = DBConnAnalyzer(None) | ||
self.paste = mock.Mock() | ||
|
||
def test_match_positive(self): | ||
"""Test if positives are recognized""" | ||
self.paste.body = "cassandra://194.3.5.2" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
self.paste.body = "postgresql://user:secret@localhost" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
self.paste.body = "mongodb://router1.example.com:27017" | ||
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)) | ||
self.paste.body = "https://www.google.com" | ||
self.assertFalse(self.analyzer.match(self.paste)) | ||
self.paste.body = "http://www.google.com" | ||
self.assertFalse(self.analyzer.match(self.paste)) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |