|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +from base64 import encodebytes |
| 4 | + |
| 5 | +from mmh3 import hash |
| 6 | +from requests import get |
| 7 | +from requests.exceptions import RequestException |
| 8 | + |
| 9 | +from src.core.base.recon import ReconRunner, PossibleKeys |
| 10 | +from src.core.utils.response import ScriptResponse |
| 11 | +from src.core.utils.validators import validate_kwargs |
| 12 | + |
| 13 | + |
| 14 | +class Runner(ReconRunner): |
| 15 | + def __init__(self, logger: str = __name__): |
| 16 | + super(Runner, self).__init__(logger) |
| 17 | + |
| 18 | + @validate_kwargs(PossibleKeys.KEYS) |
| 19 | + def run(self, *args, **kwargs): |
| 20 | + """ |
| 21 | + Returns hash of favicon.ico of given url. |
| 22 | + :param args: args from core runner |
| 23 | + :param kwargs: kwargs from core runner |
| 24 | + :return: ScriptResponse message |
| 25 | + """ |
| 26 | + url = kwargs.get("url") |
| 27 | + |
| 28 | + try: |
| 29 | + response = get(f"{url}/favicon.ico") |
| 30 | + except RequestException as req_err: |
| 31 | + return ScriptResponse.error( |
| 32 | + result=None, |
| 33 | + message=f"Can't connect to {url}!" |
| 34 | + f"Error message: {req_err}", |
| 35 | + ) |
| 36 | + |
| 37 | + favicon = encodebytes(response.content) |
| 38 | + favicon_hash = hash(favicon) |
| 39 | + |
| 40 | + return ScriptResponse.success( |
| 41 | + result=favicon_hash, |
| 42 | + message=f"Successfully made favicon hash of {url}! " |
| 43 | + f"Use https://www.shodan.io/search?query=http.favicon.hash:{favicon_hash}", |
| 44 | + ) |
0 commit comments