JFIFxxC      C  " }!1AQa"q2#BR$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz w!1AQaq"2B #3RbrJFIFxxC      C  " }!1AQa"q2#BR$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz w!1AQaq"2B #3RbrB "@Wu @sdZdZddlZddlZddlmZmZmZddlm Z ddl m Z ddl m Z ddlmZd ZZd ZZd ZZeeed ZeeeeZejZZGd ddeZGdddeZ GdddeZ!GdddeZ"GdddeZ#GdddeZ$GdddeZ%ddddZ&dd d!d"d#d$d%d&d'Z'ed(ed(ed)iZ(d:d+d,Z)e)Z*d-d.Z+e+Z,d/d0Z-e-Z.d;d1d2Z/Gd3d4d4ejZ0d5d6Z1xBd7D]:Z2e3e0e2dZ4e5e4e se0j67e2e8e0e2e1e2qWGd8d9d9e0Z9dS) SOCKS5 etc. -Improved exception handling and output -Removed irritating use of sequence indexes, replaced with tuple unpacked variables -Fixed up Python 3 bytestring handling - chr(0x03).encode() -> b"" -Other general fixes -Added clarification that the HTTP proxy connection method only supports CONNECT-style tunneling HTTP proxies -Various small bug fixes z1.5.7N) EOPNOTSUPPEINVALEAGAIN)BytesIO)SEEK_CUR)Callable) b64encode)SOCKS4SOCKS5HTTPc@s"eZdZdZdddZddZdS) ProxyErrorz> socket_err contains original socket.error exception. NcCs(||_||_|r$|jd|7_dS)Nz: {0})msg socket_errformat)selfrrr6/opt/alt/python37/lib/python3.7/site-packages/socks.py__init__NszProxyError.__init__cCs|jS)N)r)rrrr__str__UszProxyError.__str__)N)__name__ __module__ __qualname____doc__rrrrrrrJs rc@s eZdZdS)GeneralProxyErrorN)rrrrrrrrXsrc@s eZdZdS)ProxyConnectionErrorN)rrrrrrrrYsrc@s eZdZdS)SOCKS5AuthErrorN)rrrrrrrrZsrc@s eZdZdS) SOCKS5ErrorN)rrrrrrrr[src@s eZdZdS) SOCKS4ErrorN)rrrrrrrr \sr c@s eZdZdS) HTTPErrorN)rrrrrrrr!]sr!zRequest rejected or failedzLRequest rejected because SOCKS server cannot connect to identd on the clientzPRequest rejected because the client program and identd report different user-ids)[\]zGeneral SOCKS server failurez!Connection not allowed by rulesetzNetwork unreachablezHost unreachablezConnection refusedz TTL expiredz(Command not supported, or protocol errorzAddress type not supported)r r r i8iTcCs.|||||r|nd|r"|ndft_dS)z set_default_proxy(proxy_type, addr[, port[, rdns[, username, password]]]) Sets a default proxy which all further socksocket objects will use, unless explicitly changed. All parameters are as for socket.set_proxy(). N)encode socksocket default_proxy) proxy_typeaddrportrdnsusernamepasswordrrrset_default_proxyssr3cCstjS)z> Returns the default proxy, set by set_default_proxy. )r+r,rrrrget_default_proxysr4cCstjrt|j_ntddS)a" Attempts to replace a module's socket library with a SOCKS socket. Must set a default proxy using set_default_proxy(...) first. This will only work on modules that import socket directly into the namespace; most of the Python Standard Library falls into this category. zNo default proxy specifiedN)r+r,socketr)modulerrr wrap_modules r7c  CsH|\} } | dr| d} |r4|dr4|d}d} xt||dtjD]} | \}}}}}d}yt|||}| dk rx| D]}|j|q~Wt|tt fr| ||dk r| |||||||dk r| || | | f|Stjk r&}z|} |dk r|d}Wdd}~XYqLXqLW| dk r:| tddS)acreate_connection(dest_pair, *[, timeout], **proxy_args) -> socket object Like socket.create_connection(), but connects to proxy before returning the socket object. dest_pair - 2-tuple of (IP/hostname, port). **proxy_args - Same args passed to socksocket.set_proxy() if present. timeout - Optional socket timeout value, in seconds. source_address - tuple (host, port) for the socket to bind to as its source address before connecting (only for compatibility) [z[]Nrzgai returned empty list.) startswithstripr5 getaddrinfo SOCK_STREAMr+Z setsockopt isinstanceintfloatZ settimeout set_proxybindconnecterrorclose) dest_pairr- proxy_addr proxy_portZ proxy_rdnsZproxy_usernameZproxy_passwordtimeoutZsource_addressZsocket_optionsZ remote_hostZ remote_porterrrfamilyZ socket_typeprotoZ canonnameZsaZsockopterrrcreate_connections>          rOc@seZdZdZddZeZdS) _BaseSocketzJAllows Python 2's "delegated" methods such as send() to be overridden cOsHtj|f||t|_x(|jD]}t|||j|<t||q"WdS)N) _orig_socketrdict _savedmethods _savenamesgetattrdelattr)rposkwnamerrrrs  z_BaseSocket.__init__N)rrrrrlistrTrrrrrPsrPcs fddS)Ncs|j||S)N)rS)rrWrX)rYrrz_makemethod..r)rYr)rYr _makemethodsr])sendtosendrecvfromrecvc@seZdZdZdZejejdfddZddZ d-d d Z e Z d d Z d dZ d.ddZd/ddZddZddZddZeZddZeZddZeZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zeeeee eiZ!d)d*Z"d+d,Z#dS)0r+a2socksocket([family[, type[, proto]]]) -> socket object Open a SOCKS enabled socket. The parameters are the same as those of the standard socket init. In order for SOCKS to work, you must specify family=AF_INET and proto=0. The "type" argument must be either SOCK_STREAM or SOCK_DGRAM. NrcOsf|tjtjfkr"d}t||tj||||f||d|_|jrP|j|_ nd|_ d|_ d|_ dS)Nz0Socket type must be stream or datagram, not {!r})NNNNNN) r5r< SOCK_DGRAM ValueErrorrrPr _proxyconnr,proxyproxy_socknameproxy_peername)rrKtyperLargskwargsrrrrrs zsocksocket.__init__cCs@d}x6t||kr:||t|}|s0td||7}qW|S)z Receive EXACTLY the number of bytes requested from the file object. Blocks until the required number of bytes have been received. r\zConnection closed unexpectedly)lenreadr)rfilecountdatadrrr_readalls zsocksocket._readallTcCs.|||||r|nd|r"|ndf|_dS)aset_proxy(proxy_type, addr[, port[, rdns[, username[, password]]]]) Sets the proxy to be used. proxy_type - The type of the proxy to be used. Three types are supported: PROXY_TYPE_SOCKS4 (including socks4a), PROXY_TYPE_SOCKS5 and PROXY_TYPE_HTTP addr - The address of the server (IP or DNS). port - The port of the server. Defaults to 1080 for SOCKS servers and 8080 for HTTP proxy servers. rdns - Should DNS queries be performed on the remote side (rather than the local side). The default is True. Note: This has no effect with SOCKS4 servers. username - Username to authenticate with to the server. The default is no authentication. password - Password to authenticate with to the server. Only relevant when username is also provided. N)r*re)rr-r.r/r0r1r2rrrr@szsocksocket.set_proxycOs|j\}}}}}}|r"|jtjkr4tj|f||S|jrFttd|t kr^d} tt | t j|f||| \} } d| f} t|_| } |j| d}||j|| \} }| \}} |\} } t ||| fd|_dS)zm Implements proxy connection for UDP sockets, which happens during the bind() phase. z"Socket already bound to an addressz'UDP only supported by SOCKS5 proxy type0)z0.0.0.0rN)rerhr5rbrQrArdrCrr rrPZ getsockname _proxy_addrrB_SOCKS5_requestrf)rrWrXr-rFrGr0r1r2r_r/dstreZ UDP_ASSOCIATEZrelayhostrrrrA*s(    zsocksocket.bindc Os|jtjkr tj||f||S|js0|d|d}|dd}t}d}||d}||| ||tj || |f||} | | S)N)rs) rhr5rbrPr^rdrArwrite_write_SOCKS5_addressr_getvaluetell) rbytesrirjZaddressflagsheaderZRSVZ STANDALONEZsentrrrr^Ns      zsocksocket.sendtocKs6|jtjkr |j|||jf|Stj|||f|SdS)N)rhr5rbr^rgrPr_)rrrrjrrrr_as zsocksocket.sendc Cs|jtjkrt|||S|js*|dtt|||}| dt | d}t |rbt d||\}}|jr|j\}}||ks|d|fkrttd| ||ffS)N)ryrr r zReceived UDP packet fragmentrzPacket filtered)rhr5rbrPr`rdrArraseekrrlordNotImplementedError_read_SOCKS5_addressrgrCr) rbufsizerbufZfragZfromhostZfromportZpeerhostZpeerportrrrr`gs      zsocksocket.recvfromcOs|j||\}}|S)N)r`)rrWrXrrvrrrra{szsocksocket.recvcCs|jr|jt|S)N)rdrDrP)rrrrrDs zsocksocket.closecCs|jS)zL Returns the bound IP address and port number at the proxy. )rf)rrrrget_proxy_socknameszsocksocket.get_proxy_socknamecCs t|S)z> Returns the IP and port number of the proxy. )rP getpeername)rrrrget_proxy_peernameszsocksocket.get_proxy_peernamecCs|jS)z Returns the IP address and port number of the destination machine (note: get_proxy_peername returns the proxy) )rg)rrrr get_peernameszsocksocket.get_peernamecGsd}||||\|_|_dS)zI Negotiates a stream connection through a SOCKS5 server. N)rurgrf)r dest_addrZCONNECTrrr_negotiate_SOCKS5szsocksocket._negotiate_SOCKS5cCs|j\}}}}}} |d} |dd} z|r@| r@| dn | d| || d} | dddkrvtd | ddd kr| d tt||tt| | | || d} | ddd krtd | ddd krt d n6| ddd kr4| dddkr,t dntd | d|d | || }| || d}|dddkrtd t |dd}|dkrt |d}td|||| }||fS| | XdS)z Send SOCKS5 request with given command (CMD field) and address (DST field). Returns resolved DST address that was used. wbrbrssr r z%SOCKS5 proxy server sent invalid datarr{zSOCKS5 authentication failedz7All offered SOCKS5 authentication methods were rejectedr z Unknown errorz {0:#04x}: {1}N)remakefiler|flushrqrchrrkr*rr}r SOCKS5_ERRORSgetrrrrD)rZconncmdrwr-r.r/r0r1r2writerreaderZ chosen_authZ auth_statusZresolvedrespstatusrCZbndrrrrusL     .        zsocksocket._SOCKS5_requestc CsH|\}}|j\}}}}}} tjdtjdi} xrtjtjfD]b} yDt| |} || | | t| | }|td|||fStj k rw8Yq8Xq8W|r| d} |dt t |  | nbt ||tjtjtjtj}|d}|d} |dd}t| |} || | | t| | }|td|||fS)z~ Return the host and port packed for the SOCKS5 protocol, and the resolved address as a tuple object. rz>Hidnarsrr%)rer5AF_INETAF_INET6Z inet_ptonr| inet_ntopstructpackrCr*rrkr;Z AF_UNSPECr<Z IPPROTO_TCPZ AI_ADDRCONFIG)rr.rmrxr/r-rvr0r1r2Zfamily_to_byterK addr_bytesZ host_bytesZ addressesZ target_addrrrrr}s0        z socksocket._write_SOCKS5_addresscCs||d}|dkr(t||d}nN|dkrN||d}||t|}n(|dkrnttj||d}ntdtd||d d }||fS) Nr rr%rsrz%SOCKS5 proxy server sent invalid dataz>Hr r) rqr5 inet_ntoarrrrrunpack)rrmZatypr.lengthr/rrrr!s  zsocksocket._read_SOCKS5_addresscCs|j\}}}}}}|d} |dd} zLd} yt|} Wn4tjk rr|r^d} d} ntt|} YnX| tddd || | |r| || d | r| | d d | | | d } | dd d krt d t | d d}|dkr&t|d}td||t| ddtd| dddf|_| rjt| |f|_n ||f|_Wd| | XdS)zB Negotiates a connection through a SOCKS4 server. rrrFsTz>BBHr%r r{rr)z%SOCKS4 proxy server sent invalid datar Zz Unknown errorz {0:#04x}: {1}Nz>H)rerr5Z inet_atonrC gethostbynamer|rrr*rrqrr SOCKS4_ERRORSrr rrrrfrgrD)rr dest_portr-r.r/r0r1r2rrZremote_resolverrrrCrrr_negotiate_SOCKS40sB        ,zsocksocket._negotiate_SOCKS4cCsj|j\}}}}}}|r|nt|}d|ddt|dd|dg} |rv|rv| dt|d|| d|d| | } | } | | st dy| d d \} } }Wntk rt d YnX| d st d y t| } Wntk r$tdYnX| dkrVd| |}| dkrN|d7}t|d|_||f|_dS)z Negotiates a connection through an HTTP server. NOTE: This currently only supports HTTP CONNECT-style proxies. sCONNECT r:s HTTP/1.1sHost: sProxy-Authorization: basic s zConnection closed unexpectedly r z'HTTP proxy server sent invalid responsezHTTP/z0Proxy server does not appear to be an HTTP proxyz4HTTP proxy server did not return a valid HTTP statusz{0}: {1})iiiza [*] Note: The HTTP proxy server may not be supported by PySocks (must be a CONNECT tunnel proxy))s0.0.0.0rN)rer5rr*strappendrZsendalljoinrreadlinerDrsplitrcr9r>r!rrfrg)rrrr-r.r/r0r1r2Z http_headersZfobjZ status_linerLZ status_codeZ status_msgrCrrr_negotiate_HTTPks<       zsocksocket._negotiate_HTTPc Cst|dks|ddr$td|\}}|jtjkrt|jsH|dt|}|dkrf|sfd|_ n ||f|_ dS|j \}}}}}} t |t t frt|dks|rt |tstd|dkr||_ t|||fdS|}yt||Wn`tjk rP} z>||\}}d ||} t|} d | | } t| | Wdd} ~ XYntXy|j|}||||WnVtjk r} z|td | Wdd} ~ XYn tk r|YnXdS) z Connects to the specified destination through a proxy. Uses the same API as socket's connect(). To select the proxy server, use set_proxy(). dest_pair - 2-tuple of (IP/hostname, port). r rr8zPySocks doesn't support IPv6)ryrz0.0.0.0Nz0Invalid destination-connection (host, port) pairz{0}:{1}z!Error connecting to {0} proxy {1}z Socket error)rkr9r5rCrhrbrdrArrgrer=rZtupler>rrPrBrtrDrPRINTABLE_PROXY_TYPESr_proxy_negotiatorsr)rrErrr-rFrGr0r1r2rCZ proxy_serverZprintable_typerZ negotiaterrrrBsR          zsocksocket.connectcCs4|j\}}}}}}|pt|}|s,td||fS)zD Return proxy address to connect to as tuple object zInvalid proxy type)re DEFAULT_PORTSrr)rr-rFrGr0r1r2rrrrts zsocksocket._proxy_addr)NNNTNN)r)r)$rrrrr,r5rr<rrqr@ZsetproxyrAr^r_r`rarDrZgetproxysocknamerZgetproxypeernamerrrrur}rrrr r rrrBrtrrrrr+s: $  R*;7Mr+)NNNTNN) NNNTNNNNN):r __version__r5rerrnorrriorosr collectionsrbase64rZPROXY_TYPE_SOCKS4r ZPROXY_TYPE_SOCKS5r ZPROXY_TYPE_HTTPrZ PROXY_TYPESrRzipvalueskeysrZ _orgsocketrQIOErrorrrrrrr r!rrrr3Zsetdefaultproxyr4Zgetdefaultproxyr7Z wrapmodulerOrPr]rYrUmethodr=rTrsetattrr+rrrr5sl         7