from bane.scanners.vulnerabilities.utils import *


class ADB_Exploit_Scanner:

    @staticmethod
    def scan(u, timeout=5, p=5555,proxy_host=None,proxy_port=None,proxy_username=None,proxy_password=None,proxy_type=None):
        if proxy_type=='socks4' or proxy_type=='s4':
            proxy_type=socks.PROXY_TYPE_SOCKS4
        elif proxy_type=='socks5' or proxy_type=='s5':
            proxy_type=socks.PROXY_TYPE_SOCKS5
        else:
            proxy_type=None
        try:
            s = socks.socksocket(socket.AF_INET, socket.SOCK_STREAM)
            if proxy_type!=None:
                s.setproxy( 
                        proxy_type=proxy_type,
                        addr=proxy_host,
                        port=proxy_port,
                        username=proxy_username,
                        password=proxy_password,
                )
            s.settimeout(timeout)
            s.connect((u, p))
            s.send(
                b"CNXN\x00\x00\x00\x01\x00\x10\x00\x00\x07\x00\x00\x00\x32\x02\x00\x00\xbc\xb1\xa7\xb1host::\x00"
            )
            c = s.recv(4096)
            s.close()
            if "CNXN" in str(c):
                return True
        except:
            pass
        return False

