from bane.scanners.vulnerabilities.utils import *


def adb_exploit(u, timeout=5, p=5555,proxy_host=None,proxy_port=None,proxy_username=None,proxy_password=None,proxy_type=None):
    if proxy_type=='http':
        proxy_type=socks.PROXY_TYPE_HTTP
    if proxy_type=='socks4':
        proxy_type=socks.PROXY_TYPE_SOCKS4
    if proxy_type=='socks5':
        proxy_type=socks.PROXY_TYPE_SOCKS5
    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

