Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement/RefangURL (master) #1101

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion assemblyline_ui/helper/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,11 @@ def refang_url(url):
'''
Refangs a url of text. Based on source of: https://pypi.org/project/defang/
'''
new_url = re.sub(r'[\(\[](\.|dot)[\)\]]', '.', url, flags=re.IGNORECASE)
new_url = re.sub(r'[\(\[\{](\.|dot)[\)\]\}]', '.', url, flags=re.IGNORECASE)
new_url = re.sub(r'\\.', '.', new_url, flags=re.IGNORECASE)
new_url = re.sub(r'[\(\[\{]/[\)\]\}]', '/', new_url, flags=re.IGNORECASE)
new_url = re.sub(r'[\(\[\{]:[\)\]\}]', ':', new_url, flags=re.IGNORECASE)
new_url = re.sub(r'[\(\[\{]://[\)\]\}]', '://', new_url, flags=re.IGNORECASE)
new_url = re.sub(r'^h[x]{1,2}p([s]?)\[?:\]?//', r'http\1://', new_url, flags=re.IGNORECASE)
new_url = re.sub(r'^fxp(s?)\[?:\]?//', r'ftp\1://', new_url, flags=re.IGNORECASE)
return new_url
Expand Down
39 changes: 39 additions & 0 deletions assemblyline_ui/helper/test/test_submission_helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from assemblyline_ui.helper.submission import refang_url


# noinspection PyUnusedLocal
def test_refang_url():

# Testing the
assert refang_url('http://examples[.]com') == 'http://examples.com'
assert refang_url('http://examples(.)com') == 'http://examples.com'
assert refang_url('http://examples{.}com') == 'http://examples.com'
assert refang_url('http://examples[.)com') == 'http://examples.com'
assert refang_url('http://examples(.}com') == 'http://examples.com'
assert refang_url('http://examples{.]com') == 'http://examples.com'

assert refang_url('http://examples[dot]com') == 'http://examples.com'
assert refang_url('http://examples(dot)com') == 'http://examples.com'
assert refang_url('http://examples{dot}com') == 'http://examples.com'
assert refang_url('http://examples[dot)com') == 'http://examples.com'
assert refang_url('http://examples(dot}com') == 'http://examples.com'
assert refang_url('http://examples{dot]com') == 'http://examples.com'

assert refang_url('http://examples\\.com') == 'http://examples.com'

assert refang_url('http://examples.com[/]path') == 'http://examples.com/path'
assert refang_url('http://examples.com[/)path') == 'http://examples.com/path'
assert refang_url('http://examples.com[/}path') == 'http://examples.com/path'

assert refang_url('http[:]//examples.com') == 'http://examples.com'
assert refang_url('http[:)//examples.com') == 'http://examples.com'
assert refang_url('http[:}//examples.com') == 'http://examples.com'
assert refang_url('http[://]examples.com') == 'http://examples.com'
assert refang_url('http[://)examples.com') == 'http://examples.com'
assert refang_url('http[://}examples.com') == 'http://examples.com'

assert refang_url('hxxp://examples.com') == 'http://examples.com'
assert refang_url('hxXp://examples.com') == 'http://examples.com'
assert refang_url('hXXp://examples.com') == 'http://examples.com'

assert refang_url('hxXps[:]//test\\.example[.)com{.]uk[dot)test[/]path') == 'https://test.example.com.uk.test/path'