Пример #1
0
 def serverToSource(self):
     error = False
     baseServer.log(1, self.threadid, "----", "<")
     if self.lock.get() == "ok":
         try:
             count = 0
             while True:
                 if self.orignConn is None:
                     break
                 baseServer.log(1, self.threadid, "orignConn", "recv")
                 tmp = self.orignConn.recv(DDDProxyConfig.cacheSize)
                 if not tmp:
                     break
                 count += len(tmp)
                 baseServer.log(1, self.threadid, "localProxy", "send", tmp)
                 DDDProxySocketMessage.send(self.localProxy, tmp)
                 baseServer.log(1, self.threadid, "localProxy", "send", "end")
                 self.markActive("orignConn recv")
         except socket.timeout:
             pass
         except:
             baseServer.log(3, self.threadid, "serverToSource error!!!")
             error = True
     baseServer.log(1, self.threadid, "----", ">")
     return not error
Пример #2
0
	def sourceToServer(self):
		baseServer.log(1, self.threadid, "}}}}", "<")
		threading.currentThread().name = "worker%s-%s-send"%(self.threadid,self.addr)
		try:
			socetParser = socetMessageParser()
			count = 0
			while self.source != None:
				tmp = self.source.recv(DDDProxyConfig.cacheSize)
				if not tmp:
					break
				baseServer.log(1, "}}}}", tmp)
				length = len(tmp)
				self.dataCountSend += length;
				count += length;
				DDDProxySocketMessage.send(self.remoteSocket, tmp)
				
				#以下数据是为了时统计用
				if socetParser is not None:
					socetParser.putMessage(tmp)
					if socetParser.messageStatus():
						self.httpMessage = socetParser.httpMessage()
						host, port = hostParser.parserUrlAddrPort(self.httpMessage[1] if self.httpMessage[0] != "CONNECT" else "https://" + self.httpMessage[1])
						threading.currentThread().name = "worker%s-%s-%s:%d-send"%(self.threadid,self.addr,host,port)
						self.hostPort = (host, port)
						
						
						#代理host黑名单
						ipAddr = re.match("(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})", host)
						foundIp = False
						if ipAddr:
							ipAddr = ipAddr.groups()
							mathIp = "%s.%s.%s" % (ipAddr[0], ipAddr[1], ipAddr[2]);
							for i in self.blockHost:
								if i.startswith(mathIp):
									foundIp = True
									break
						if foundIp or host in self.blockHost:
							baseServer.log(2, self.threadid, "block", host)
							break
						
						baseServer.log(2, self.addr, self.httpMessage)
						self.domainAnalysisAddData("connect", 1)
						socetParser = None
		
				if self.domainAnalysisAddData("incoming", count):
					count = 0
				self.markActive()
		except socket.timeout:
			pass
		except:
			baseServer.log(3, self.threadid, "}}}} error!")
# 		sendPack.end(self.remoteSocket)
		threading.currentThread().name = "worker%s-IDLE-send"%(self.threadid)
		baseServer.log(1, self.threadid, "}}}}", ">")
		self.close()
Пример #3
0
    def sourceToServer(self):
        try:
            # 接收消息头
            socetParser = socetMessageParser()
            hasData = False
            for data in DDDProxySocketMessage.recv(self.localProxy):
                baseServer.log(1, self.threadid, ">>>>>", data, len(data))
                socetParser.putMessage(data)
                if socetParser.messageStatus():
                    self.httpMessage = socetParser.httpMessage()
                    hasData = True
                    break
                self.markActive("recv header")

            if not hasData:
                return False

                # 连接原始服务器
            self.method, path, protocol = self.httpMessage
            if self.method:
                baseServer.log(2, "httpMessage", self.threadid, self.method, path, protocol)
            if self.method == "CONNECT":
                self.httpData = False
                self.openOrignConn("https://" + path)
                baseServer.log(1, self.threadid, "CONNECT ", path)
                DDDProxySocketMessage.send(self.localProxy, "HTTP/1.1 200 OK\r\n\r\n")
            else:
                self.httpData = True
                baseServer.log(1, self.threadid, ">>>>>", "openOrignConn")
                self.openOrignConn(path)
                baseServer.log(1, self.threadid, ">>>>>", socetParser.messageData())
                self.orignConn.send(socetParser.messageData())

            self.lock.put("ok")

            # 转发原始请求到原始服务器
            for data in DDDProxySocketMessage.recv(self.localProxy):
                self.orignConn.send(data)
                self.markActive("localProxy recv")

            self.close()
            return True
        except TypeError:
            pass
        except:
            baseServer.log(3, self.threadid, "sourceToServer error!!!")
        self.lock.put("error")
        self.close()
        return False