Skip to content

Commit

Permalink
Added no-redirection, and few misc. changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
naryal2580 committed Jun 10, 2020
1 parent 96c504e commit c347f72
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 28 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ build/
dist/
*.egg-info/
*_dontAdd_*
.vscode
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SéCh3r v4.2
# SéCh3r v4.3
A Security HTTP-Header Checker. # Demoisturize it!


Expand Down Expand Up @@ -32,7 +32,7 @@ In order to get this tool running, follow the instruction below:



## Usgae
## Usage

```
$ sech3r -h
Expand Down Expand Up @@ -64,11 +64,9 @@ Examples:
sech3r -vsrc
```

**NOTE**: I am still working on no-redirection feature.

## TODOs

- Added No redirect support
- Input of URLs from a textfile
- Output to a file
- Additional Header Assesments for better output
Expand Down
24 changes: 15 additions & 9 deletions sech3r.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
"""

__author__ = "naryal2580"
__version__ = "4.2"
__version__ = "4.3"

from sech3r import *
from docopt import docopt

def main(urls=[], verbose=False, search4cves=False, color=True):
def main(urls=[], verbose=False, search4cves=False, noRedirects=False, color=True):
if urls:
print(takenInput(f"URL(s) separated with double <space> -> {' '.join(urls)}", color))

Expand All @@ -49,12 +49,12 @@ def main(urls=[], verbose=False, search4cves=False, color=True):
url = validateUrl(url)
if url.startswith('http://'):
print(warn('Warning -> Crafting a non TLS request', color))
heads = getHeaders(url)
heads = getHeaders(url, noRedirects)
if heads:
if verbose:
print(info('Response Headers -> ', color))
print(info('Response Headers -> below:', color))
for head in heads:
print(f'{head}: {heads[head]}')
print(takenInput(f'{head}: {heads[head]}', color))
secHeads = checkSecHeads(heads)
secHeadsPresent = secHeads[0]
secHeadsNotPresent = secHeads[1]
Expand All @@ -76,15 +76,17 @@ def main(urls=[], verbose=False, search4cves=False, color=True):


if __name__ == "__main__":
args = docopt(__doc__, version=__version__)
args = docopt(__doc__, version='SéCh3r v{}'.format(__version__))
color = True
verbose = search4cves = False
verbose = search4cves = noRedirects = False
if args['--noColor']:
color = False
if args['--verbose']:
verbose = True
if args['--searchForVuln']:
search4cves = True
if args['--noRedirects']:
noRedirects = True
banner(__version__, color)
if verbose:
print(info('Verbosity -> Enabled', color))
Expand All @@ -96,10 +98,14 @@ def main(urls=[], verbose=False, search4cves=False, color=True):
print(info('Google for CVEs -> Yup!'))
else:
print(info('Interested in CVEs -> Nah'))
if noRedirects:
print(info('Follow Redirects -> No'))
else:
print(info('Do Follow redirects -> Sure'))

if args['<urls>']:
main(args['<urls>'], verbose, search4cves, color)
main(args['<urls>'], verbose, search4cves, noRedirects, color)
else:
main([], verbose, search4cves, color)
main([], verbose, search4cves, noRedirects, color)

coolExit(0, color)
2 changes: 1 addition & 1 deletion sech3r/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
from .extra import *

__author__ = "naryal2580"
__version__ = "4.2"
__version__ = "4.3"
38 changes: 25 additions & 13 deletions sech3r/core.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
from re import compile as reCompile
from urllib.request import urlopen as request
from urllib.request import Request
from urllib import request
from .style import *


class NoRedirects(request.HTTPRedirectHandler):
def redirect_request(self, req, fp, code, msg, headers, newurl):
return None


def parseUrl(url):
"""Regex based URL parser"""
"""Regex based URL parser, copied and pasted but lost the source :("""
pattern = (
r'^'
r'((?P<protocol>.+?)://)?'
Expand All @@ -23,24 +27,32 @@ def parseUrl(url):


def validateUrl(url):
"""Validation if protocol is specified"""
"""Validation if protocol is specified, prepend if not"""
parsedUrl = parseUrl(url)
if not parsedUrl['protocol']:
url = 'http://' + url
return url


def getHeaders(url):
def getHeaders(url, noRedirects=False, color=True):
"""Requests Headers of queried URL"""
try:
req = Request(
url,
data=None,
headers={'User-Agent': 'sech3r/4.2'}
)
resp = request(req)
if noRedirects:
opener = request.build_opener(NoRedirects)
request.install_opener(opener)
req = request.Request(
url,
data=None,
headers={'User-Agent': 'sech3r/4.2'}
)
resp = request.urlopen(req)
if resp.url != url:
if resp.url.startswith('https://'):
print(good(f'Redirected to -> {resp.url}', color))
else:
print(info(f'Redirected to -> {resp.url}', color))
except Exception as excptn:
print(bad(str(excptn).replace(': ', ' -> ')))
print(bad(str(excptn).replace(': ', ' -> '), color))
if 'HTTP Error' in str(excptn):
resp = excptn
else:
Expand Down Expand Up @@ -75,7 +87,7 @@ def checkSecHeads(headers):


def checkInfoHeads(headers, searchForVuln=False, color=True):
"""Checking for informative headers"""
"""Checks for informative headers"""
version_disclosure_headers = [
'Server',
'X-AspNet-Version',
Expand Down
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='sech3r',
version='4.2',
version='4.3',
author="Captain Nick Lucifer",
author_email="naryal2580@gmail.com",
url="https://github.com/naryal2580/sech3r",
Expand All @@ -16,6 +16,10 @@
packages=find_packages(),
py_modules=['sech3r'],
scripts=['bin/sech3r'],
install_requires=[
'stoyled',
'docopt'
],
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
Expand Down

0 comments on commit c347f72

Please sign in to comment.