-
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.
- Loading branch information
Showing
3 changed files
with
48 additions
and
1 deletion.
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 DBConnAnalyser(RegexAnalyzer): | ||
"""Analyzer to match on email addresses via regex""" | ||
name = "DBConnAnalyser" | ||
|
||
def __init__(self, actions): | ||
# https:// should be ignored | ||
regex = r"(\b(?!https\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,33 @@ | ||
# -*- coding: utf-8 -*- | ||
import unittest | ||
from unittest import mock | ||
|
||
from pastepwn.analyzers.dbconnstringanalyser import DBConnAnalyser | ||
|
||
|
||
class TestDBConnAnalyser(unittest.TestCase): | ||
def setUp(self): | ||
self.analyzer = DBConnAnalyser(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)) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |