ÿØÿàJFIFÿþ ÿÛC       ÿÛC ÿÀÿÄÿÄ"#QrÿÄÿÄ&1!A"2qQaáÿÚ ?Øy,æ/3JæÝ¹È߲؋5êXw²±ÉyˆR”¾I0ó2—PI¾IÌÚiMö¯–þrìN&"KgX:Šíµ•nTJnLK„…@!‰-ý ùúmë;ºgµŒ&ó±hw’¯Õ@”Ü— 9ñ-ë.²1<yà‚¹ïQÐU„ہ?.’¦èûbß±©Ö«Âw*VŒ) `$‰bØÔŸ’ëXÖ-ËTÜíGÚ3ð«g Ÿ§¯—Jx„–’U/ÂÅv_s(Hÿ@TñJÑãõçn­‚!ÈgfbÓc­:él[ðQe 9ÀPLbÃãCµm[5¿ç'ªjglå‡Ûí_§Úõl-;"PkÞÞÁQâ¼_Ñ^¢SŸx?"¸¦ùY騐ÒOÈ q’`~~ÚtËU¹CڒêV  I1Áß_ÿÙ "@Wc @sdZdZddlZddlZddlmZmZmZddlm Z ddl m Z ddl m Z ddlmZd ZZd ZZd ZZied 6ed 6ed6ZeeejejZejZZdefdYZdefdYZ defdYZ!defdYZ"defdYZ#defdYZ$defdYZ%idd6dd 6d!d"6Z&id#d 6d$d 6d%d 6d&d'6d(d)6d*d+6d,d-6d.d/6Z'id0e6d0e6d1e6Z(ddde*ddd2Z+e+Z,d3Z-e-Z.d4Z/e/Z0ddde*dddddd5 Z1d6ejfd7YZ2d8Z3xXd?D]PZ4e5e2e4dZ6e7e6e se2j8j9e4e:e2e4e3e4qqWd=e2fd>YZ;dS(@s SocksiPy - Python SOCKS module. Version 1.5.7 Copyright 2006 Dan-Haim. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of Dan Haim nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY DAN HAIM "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAN HAIM OR HIS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMANGE. This module provides a standard socket-like interface for Python for tunneling connections through SOCKS proxies. =============================================================================== Minor modifications made by Christopher Gilbert (http://motomastyle.com/) for use in PyLoris (http://pyloris.sourceforge.net/) Minor modifications made by Mario Vilas (http://breakingcode.wordpress.com/) mainly to merge bug fixes found in Sourceforge Modifications made by Anorov (https://github.com/Anorov) -Forked and renamed to PySocks -Fixed issue with HTTP proxy failure checking (same bug that was in the old ___recvall() method) -Included SocksiPyHandler (sockshandler.py), to be used as a urllib2 handler, courtesy of e000 (https://github.com/e000): https://gist.github.com/869791#file_socksipyhandler.py -Re-styled code to make it readable -Aliased PROXY_TYPE_SOCKS5 -> 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 s1.5.7iN(t EOPNOTSUPPtEINVALtEAGAIN(tBytesIO(tSEEK_CUR(tCallable(t b64encodeiiitSOCKS4tSOCKS5tHTTPt ProxyErrorcBs#eZdZddZdZRS(s> socket_err contains original socket.error exception. cCs7||_||_|r3|jdj|7_ndS(Ns: {0}(tmsgt socket_errtformat(tselfR R ((s6/opt/alt/python27/lib/python2.7/site-packages/socks.pyt__init__Ns  cCs|jS(N(R (R((s6/opt/alt/python27/lib/python2.7/site-packages/socks.pyt__str__UsN(t__name__t __module__t__doc__tNoneRR(((s6/opt/alt/python27/lib/python2.7/site-packages/socks.pyR Js tGeneralProxyErrorcBseZRS((RR(((s6/opt/alt/python27/lib/python2.7/site-packages/socks.pyRXstProxyConnectionErrorcBseZRS((RR(((s6/opt/alt/python27/lib/python2.7/site-packages/socks.pyRYstSOCKS5AuthErrorcBseZRS((RR(((s6/opt/alt/python27/lib/python2.7/site-packages/socks.pyRZst SOCKS5ErrorcBseZRS((RR(((s6/opt/alt/python27/lib/python2.7/site-packages/socks.pyR[st SOCKS4ErrorcBseZRS((RR(((s6/opt/alt/python27/lib/python2.7/site-packages/socks.pyR\st HTTPErrorcBseZRS((RR(((s6/opt/alt/python27/lib/python2.7/site-packages/socks.pyR]ssRequest rejected or failedi[sLRequest rejected because SOCKS server cannot connect to identd on the clienti\sPRequest rejected because the client program and identd report different user-idsi]sGeneral SOCKS server failures!Connection not allowed by rulesetsNetwork unreachablesHost unreachableisConnection refusedis TTL expiredis(Command not supported, or protocol errorisAddress type not supportedii8icCsC|||||r|jnd|r3|jndft_dS(s 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(tencodeRt socksockett default_proxy(t proxy_typetaddrtporttrdnstusernametpassword((s6/opt/alt/python27/lib/python2.7/site-packages/socks.pytset_default_proxyss cCstjS(s> Returns the default proxy, set by set_default_proxy. (RR(((s6/opt/alt/python27/lib/python2.7/site-packages/socks.pytget_default_proxyscCs(tjrt|j_n tddS(s" 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. sNo default proxy specifiedN(RRtsocketR(tmodule((s6/opt/alt/python27/lib/python2.7/site-packages/socks.pyt wrap_modules c Cs|\} } | jdr-| jd} n|rT|jdrT|jd}nd} xBtj||dtjD]%} | \}}}}}d}yt|||}| dk rx| D]}|j|qWnt|t t fr|j |n|dk r)|j ||||||n|dk rE|j |n|j| | f|SWqvtjk r}|} |dk r|jd}qqvXqvW| dk r| ntjddS(screate_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) t[s[]isgai returned empty list.N(t startswithtstripRR&t getaddrinfot SOCK_STREAMRt setsockoptt isinstancetinttfloatt settimeoutt set_proxytbindtconnectterrortclose(t dest_pairRt proxy_addrt proxy_portt proxy_rdnstproxy_usernametproxy_passwordttimeouttsource_addresstsocket_optionst remote_hostt remote_portterrtrtfamilyt socket_typetprotot canonnametsatsocktoptte((s6/opt/alt/python27/lib/python2.7/site-packages/socks.pytcreate_connections> "         t _BaseSocketcBs eZdZdZeZRS(sJAllows Python 2's "delegated" methods such as send() to be overridden cOsZtj|||t|_x4|jD])}t|||j|t((RW((RWs6/opt/alt/python27/lib/python2.7/site-packages/socks.pyt _makemethodstsendtotsendtrecvfromtrecvRcBs"eZdZdZejejddZdZ ddde dddZ e Z dZ dZddZddZd Zd Zd ZeZd ZeZd ZeZdZdZdZdZdZdZiee6ee 6ee!6Z"dZ#dZ$RS(s2socksocket([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. icOs|tjtjfkr6d}t|j|ntj||||||d|_|j rs|j |_ n d|_ d|_ d|_ dS(Ns0Socket type must be stream or datagram, not {!r}(NNNNNN( R&R-t SOCK_DGRAMt ValueErrorR RNRRt _proxyconnRtproxytproxy_socknametproxy_peername(RREttypeRGtargstkwargsR ((s6/opt/alt/python27/lib/python2.7/site-packages/socks.pyRs    cCs[d}xNt||krV|j|t|}|sItdn||7}q W|S(s Receive EXACTLY the number of bytes requested from the file object. Blocks until the required number of bytes have been received. RZsConnection closed unexpectedly(tlentreadR(Rtfiletcounttdatatd((s6/opt/alt/python27/lib/python2.7/site-packages/socks.pyt_readallscCsC|||||r|jnd|r3|jndf|_dS(sset_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(RRRc(RRRR R!R"R#((s6/opt/alt/python27/lib/python2.7/site-packages/socks.pyR3s cOsD|j\}}}}}}| s4|jtjkrGtj|||S|jretjtdn|t krd} tjt | nt j||||j \} } d| f} t|_|j } |jj| d}|j|j|| \} }| \}} |\} } t j||| fd|_dS( sm Implements proxy connection for UDP sockets, which happens during the bind() phase. s"Socket already bound to an addresss'UDP only supported by SOCKS5 proxy typet0ss0.0.0.0iN(s0.0.0.0i(RcRfR&R`ROR4RbR6RRRRNt getsocknamet _proxy_addrR5t_SOCKS5_requestRd(RRURVRR9R:R!R"R#R t_R tdstRct UDP_ASSOCIATEtrelaythost((s6/opt/alt/python27/lib/python2.7/site-packages/socks.pyR4*s(       c Os|jtjkr(tj||||S|jsA|jdn|d}|d }t}d}|j|d}|j||j ||tj ||j |||} | |j S(NRZiiss(RZi( RfR&R`RNR\RbR4Rtwritet_write_SOCKS5_addressR]tgetvaluettell( RtbytesRgRhtaddresstflagstheadertRSVt STANDALONEtsent((s6/opt/alt/python27/lib/python2.7/site-packages/socks.pyR\Ns      "cKsE|jtjkr+|j|||j|Stj||||SdS(N(RfR&R`R\ReRNR](RR}RRh((s6/opt/alt/python27/lib/python2.7/site-packages/socks.pyR]asc Cs |jtjkr%tj|||S|js>|jdnttj|||}|j d t |j d}t |rt dn|j|\}}|jr|j\}}||ks|d|fkrtjtdqn|j ||ffS(NRZiiisReceived UDP packet fragmentsPacket filtered(RZi(RfR&R`RNR^RbR4RR_tseekRRjtordtNotImplementedErrort_read_SOCKS5_addressReR6R( RtbufsizeRtbuftfragtfromhosttfromporttpeerhosttpeerport((s6/opt/alt/python27/lib/python2.7/site-packages/socks.pyR^gs   cOs|j||\}}|S(N(R^(RRURVR}Rt((s6/opt/alt/python27/lib/python2.7/site-packages/socks.pyR_{scCs&|jr|jjntj|S(N(RbR7RN(R((s6/opt/alt/python27/lib/python2.7/site-packages/socks.pyR7s cCs|jS(sL Returns the bound IP address and port number at the proxy. (Rd(R((s6/opt/alt/python27/lib/python2.7/site-packages/socks.pytget_proxy_socknamescCs tj|S(s> Returns the IP and port number of the proxy. (RNt getpeername(R((s6/opt/alt/python27/lib/python2.7/site-packages/socks.pytget_proxy_peernamescCs|jS(s Returns the IP address and port number of the destination machine (note: get_proxy_peername returns the proxy) (Re(R((s6/opt/alt/python27/lib/python2.7/site-packages/socks.pyt get_peernamescGs+d}|j|||\|_|_dS(sI Negotiates a stream connection through a SOCKS5 server. sN(RsReRd(Rt dest_addrtCONNECT((s6/opt/alt/python27/lib/python2.7/site-packages/socks.pyt_negotiate_SOCKS5s cCs|j\}}}}}} |jd} |jdd} z0|r[| r[| jdn | jd| j|j| d} | dd!dkrtd n| dd!d kr]| jd tt|j|tt| j| | j|j| d} | dd!d kr8td n| dd!d krt d qnD| dd!d kr| dd!dkrt dqtd n| jd|d |j || }| j|j| d}|dd!dkrtd nt |dd!}|dkrRt j |d}tdj||n|j| }||fSWd| j| jXdS(s Send SOCKS5 request with given command (CMD field) and address (DST field). Returns resolved DST address that was used. twbtrbissiiss%SOCKS5 proxy server sent invalid datassssSOCKS5 authentication failedss7All offered SOCKS5 authentication methods were rejectedis Unknown errors {0:#04x}: {1}N(RctmakefileRytflushRoRtchrRiRRRzRt SOCKS5_ERRORStgetRR RR7(RtconntcmdRuRRR R!R"R#twritertreadert chosen_autht auth_statustresolvedtresptstatusR6tbnd((s6/opt/alt/python27/lib/python2.7/site-packages/socks.pyRssL   ;    cCs|\}}|j\}}}}}} idtj6dtj6} xtjtjfD]} y`tj| |} |j| | | tj| | }|jtjd|||fSWqTtj k rqTqTXqTW|r|j d} |jdt t | j | ntj ||tjtjtjtj}|d}|d} |dd}tj| |} |j| | | tj| | }|jtjd|||fS(s~ Return the host and port packed for the SOCKS5 protocol, and the resolved address as a tuple object. sss>Htidnasii(RcR&tAF_INETtAF_INET6t inet_ptonRyt inet_ntoptstructtpackR6RRRiR,t AF_UNSPECR-t IPPROTO_TCPt AI_ADDRCONFIG(RRRkRxR RRtR!R"R#tfamily_to_byteREt addr_bytest host_bytest addressest target_addr((s6/opt/alt/python27/lib/python2.7/site-packages/socks.pyRzs0  **  cCs|j|d}|dkr<tj|j|d}nu|dkru|j|d}|j|t|}n<|dkrtjtj|j|d}n tdtjd|j|d d }||fS( Nisissis%SOCKS5 proxy server sent invalid datas>Hii( RoR&t inet_ntoaRRRRRtunpack(RRktatypRtlengthR ((s6/opt/alt/python27/lib/python2.7/site-packages/socks.pyR!s   $ "cCs|j\}}}}}}|jd} |jdd} zt} ytj|} WnAtjk r|rd} t} qtjtj|} nX| jt j ddd|| j| |r| j|n| jd| r| j|j d dn| j |j | d } | dd!dkrLtd nt| dd !}|d krtj|d}tdj||ntj| dt jd| d d!df|_| rtj| |f|_n||f|_Wd| j| jXdS(sB Negotiates a connection through a SOCKS4 server. RRiss>BBHiisRis%SOCKS4 proxy server sent invalid dataiiZs Unknown errors {0:#04x}: {1}s>HN(RcRtFalseR&t inet_atonR6tTruet gethostbynameRyRRRRRoRRt SOCKS4_ERRORSRRR RRRdReR7(RRt dest_portRRR R!R"R#RRtremote_resolveRRRR6((s6/opt/alt/python27/lib/python2.7/site-packages/socks.pyt_negotiate_SOCKS40sB     3 cCs|j\}}}}}}|r'|n tj|}d|jddt|jdd|jdg} |r|r| jdt|d|n| jd|jdj| |j } | j } | j | st dny| j d d \} } }Wntk r:t d nX| jd sYt d nyt| } Wntk rtdnX| dkrdj| |}| dkr|d7}nt|nd|_||f|_dS(s Negotiates a connection through an HTTP server. NOTE: This currently only supports HTTP CONNECT-style proxies. sCONNECT Rt:s HTTP/1.1sHost: sProxy-Authorization: basic s sConnection closed unexpectedlyt is'HTTP proxy server sent invalid responsesHTTP/s0Proxy server does not appear to be an HTTP proxys4HTTP proxy server did not return a valid HTTP statusis{0}: {1}iiisa [*] Note: The HTTP proxy server may not be supported by PySocks (must be a CONNECT tunnel proxy)s0.0.0.0iN(iii(s0.0.0.0i(RcR&RRtstrtappendRtsendalltjoinRtreadlineR7RtsplitRaR*R0RR RdRe(RRRRRR R!R"R#t http_headerstfobjt status_lineRGt status_codet status_msgR6((s6/opt/alt/python27/lib/python2.7/site-packages/socks.pyt_negotiate_HTTPks<( "          cCsGt|dks%|djdr7tjdn|\}}|jtjkr|jsn|jd ntj|}|dkr| rd|_ n||f|_ dS|j \}}}}}} t |t tf s t|dks | s t |t rtdn|dkrG||_ tj|||fdS|j}ytj||Wnitjk r} |j|\}}d j||} t|} d j| | } t| | nqXy!|j|}||||WnLtjk r%} |jtd | ntk rB|jnXdS( s 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). iiR)sPySocks doesn't support IPv6RZs0.0.0.0Ns0Invalid destination-connection (host, port) pairs{0}:{1}s!Error connecting to {0} proxy {1}s Socket error(RZi(RiR*R&R6RfR`RbR4RRReRcR/RXttupleR0RRNR5RrR7R tPRINTABLE_PROXY_TYPESRt_proxy_negotiatorsR (RR8RRRR9R:R!R"R#R6t proxy_servertprintable_typeR t negotiate((s6/opt/alt/python27/lib/python2.7/site-packages/socks.pyR5sR%               cCsO|j\}}}}}}|p-tj|}|sEtdn||fS(sD Return proxy address to connect to as tuple object sInvalid proxy type(Rct DEFAULT_PORTSRR(RRR9R:R!R"R#((s6/opt/alt/python27/lib/python2.7/site-packages/socks.pyRrs N(%RRRRRR&RR-RRoRR3tsetproxyR4R\R]R^R_R7RtgetproxysocknameRtgetproxypeernameRRRRsRzRRRRRR RR5Rr(((s6/opt/alt/python27/lib/python2.7/site-packages/socks.pyRs<  $          R *  ; 6  M(R\R]R^R_(<Rt __version__R&RterrnoRRRtioRtosRt collectionsRtbase64RtPROXY_TYPE_SOCKS4RtPROXY_TYPE_SOCKS5RtPROXY_TYPE_HTTPR t PROXY_TYPESRPtziptvaluestkeysRt _orgsocketROtIOErrorR RRRRRRRRRRRR$tsetdefaultproxyR%tgetdefaultproxyR(t wrapmoduleRMRNR[RWRStmethodR/RRRtsetattrR(((s6/opt/alt/python27/lib/python2.7/site-packages/socks.pyt5sl     !           7