示例#1
0
 def forward_hosts_tcp(self, addrs, req):
     self.remoteconn = create_connection_hosts(addrs, req.dstport,
                                               self.timeout)
     self.track_sock(self.remoteconn)
     addrtype, bndaddr, bndport = sock_addr_info(self.remoteconn)
     request_success(self.socksconn, addrtype, bndaddr, bndport)
     data = self.socksconn.recv(65536)
     if data[:3] == 'GET':
         request, rest = data.split('\r\n', 1)
         method, path, version = request.split()
         headers = mimetools.Message(StringIO(rest))
         host = headers.getheader("host", "")
         if self.matcher.need_redirect(method, host):
             response = [
                 "%s 301 Moved Permanently" % version,
                 "Location: https://%s" % "".join([host, path]),
                 "Connection: close", "", ""
             ]
             self.socksconn.sendall("\r\n".join(response))
         else:
             self.remoteconn.sendall(data)
             pipe_tcp(self.socksconn, self.remoteconn, self.timeout,
                      self.timeout)
     else:
         self.remoteconn.sendall(data)
         pipe_tcp(self.socksconn, self.remoteconn, self.timeout,
                  self.timeout)
示例#2
0
 def forward_hosts_tcp(self, addrs, req):
     self.remoteconn = create_connection_hosts(addrs, req.dstport, self.timeout)
     self.track_sock(self.remoteconn)
     addrtype, bndaddr, bndport = sock_addr_info(self.remoteconn)
     request_success(self.socksconn, addrtype, bndaddr, bndport)
     data = self.socksconn.recv(65536)
     if data[:3] == "GET":
         request, rest = data.split("\r\n", 1)
         method, path, version = request.split()
         headers = mimetools.Message(StringIO(rest))
         host = headers.getheader("host", "")
         if self.matcher.need_redirect(method, host):
             response = [
                 "%s 301 Moved Permanently" % version,
                 "Location: https://%s" % "".join([host, path]),
                 "Connection: close",
                 "",
                 "",
             ]
             self.socksconn.sendall("\r\n".join(response))
         else:
             self.remoteconn.sendall(data)
             pipe_tcp(self.socksconn, self.remoteconn, self.timeout, self.timeout)
     else:
         self.remoteconn.sendall(data)
         pipe_tcp(self.socksconn, self.remoteconn, self.timeout, self.timeout)
示例#3
0
 def cmd_udp_associate(self, req):
     self.udpsock = bind_local_udp(self.socksconn)
     self.allsocks.append(self.udpsock)
     addrtype, ip, port = sock_addr_info(self.udpsock)
     self.socksconn.sendall(Request(cmd=UDP_ASSOCIATE,
         addrtype=addrtype, dstaddr=ip, dstport=port).pack())
     reply = read_reply(self.socksconn)
     resp = reply.pack()
     headers = [
         (HEADER_SESSION_ID, self.sessionid),
         (HEADER_MSGTYPE, MSGTYPE_DATA)
     ]
     
     self.udp_associate = (reply.bndaddr, reply.bndport)
     self.threads.append(gevent.spawn(self.meeks_write_to_socks_thread))
     self.threads.append(gevent.spawn(self.meeks_read_from_socks_thread))
     # clean_thread will join the other two threads, then clean resources
     gevent.spawn(self.meeks_clean_thread)
     self.status = SESSION_UDP
     return resp, headers
示例#4
0
 def cmd_udp_associate(self, req):
     self.client_associate = (req.dstaddr, req.dstport)
     self.last_clientaddr = self.client_associate
     for (resp, err) in self.meek_roundtrip([req.pack()]):
         if err:
             return
         if resp:
             Reply(resp)
     
     self.udpsock = bind_local_udp(self.socksconn)
     if not self.udpsock:
         request_fail(self.socksconn, req, GENERAL_SOCKS_SERVER_FAILURE)
         return
     self.track_sock(self.udpsock)
     
     read_thread = gevent.spawn(self.meek_read_from_client_thread)
     write_thread = gevent.spawn(self.meek_write_to_client_thread)
     relay_thread = gevent.spawn(self.meek_relay_thread)
     
     request_success(self.socksconn, *sock_addr_info(self.udpsock))
     [t.join() for t in (read_thread, write_thread, relay_thread)]
     log.info("Session %s Ended" % self.sessionid)
示例#5
0
    def cmd_udp_associate(self, req):
        self.client_associate = (req.dstaddr, req.dstport)
        self.last_clientaddr = self.client_associate
        for (resp, err) in self.meek_roundtrip([req.pack()]):
            if err:
                return
            if resp:
                Reply(resp)

        self.udpsock = bind_local_udp(self.socksconn)
        if not self.udpsock:
            request_fail(self.socksconn, req, GENERAL_SOCKS_SERVER_FAILURE)
            return
        self.track_sock(self.udpsock)

        read_thread = gevent.spawn(self.meek_read_from_client_thread)
        write_thread = gevent.spawn(self.meek_write_to_client_thread)
        relay_thread = gevent.spawn(self.meek_relay_thread)

        request_success(self.socksconn, *sock_addr_info(self.udpsock))
        [t.join() for t in (read_thread, write_thread, relay_thread)]
        log.info("Session %s Ended" % self.sessionid)