コード例 #1
0
ファイル: remoteServerHandler.py プロジェクト: liyl/DDDProxy
 def openOrignConn(self, path):
     if self.orignConn is not None:
         return
     addr, port = hostParser.parserUrlAddrPort(path)
     ip = socket.gethostbyname(addr)
     self.orignConn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     self.orignConn.connect((ip, port))
コード例 #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 get(self,fromIp,domain,timeMark):
		try:
			url = parserUrlAddrPort(domain)[0]
			domain = url if url else domain
		except:
			pass
		for s in self.siteList:
			if domain == s.domain and fromIp == s.fromIp and timeMark == s.timeMark:
				return s

		site = analysisSite(domain,fromIp,timeMark)
		self.siteList.append(site)
		return site
コード例 #4
0
ファイル: domainAnalysis.py プロジェクト: tanKing/DDDProxy
	def get(self,fromIp,domain,timeMark):
		try:
			url = parserUrlAddrPort(domain)[0]
			domain = url if url else domain
		except:
			pass
		for s in self.siteList:
			if domain == s.domain and fromIp == s.fromIp and timeMark == s.timeMark:
				return s

		site = analysisSite(domain,fromIp,timeMark)
		self.siteList.append(site)
		return site
コード例 #5
0
	def onRecv(self, data):
		sockConnect.onRecv(self, data)
		self.recvCache += data
		if self.mode == "proxy":
			if self.remoteConnect and self.recvCache:
				if self.connectHost:
					analysis.incrementData(self.address[0], domainAnalysisType.incoming, self.connectHost, len(self.recvCache))
				self.remoteConnect.sendData(self.fileno(), self.recvCache)
				self.recvCache = ""
			return
		if self.messageParse.appendData(data):
			method = self.messageParse.method()
			path = self.messageParse.path()
			self.connectName = self.filenoStr() + "	" + method + "	" + path
			if not path.startswith("http://") and method in ["GET", "POST"]:
				path = path.split("?")
				self.onHTTP(self.messageParse.headers,
						method,
						path[0],
						path[1] if len(path) > 1 else "",
						self.messageParse.getBody() if method == "POST" else "")
				self.mode = "http"
			else:
				
				self.mode = "proxy"
				
				connect = remoteConnectManger.getConnect()
				if path.find("status.dddproxy.com")>0:
					try:
						connect = None
						jsonMessage = self.messageParse.getBody()
						jsonBody = json.loads(jsonMessage)
						connectList = remoteConnectManger.getConnectHost(jsonBody["host"],jsonBody["port"])
						if connectList:
							for _,v in connectList.items():
								connect = v
					except:
						pass
				
				if connect:
					connect.addAuthCallback(self.onRemoteConnectAuth)
					connect.setConnectCloseCallBack(self.fileno(), self.onRemoteConnectClose)
				else:
					self.close()
				
				self.connectHost = parserUrlAddrPort("https://" + path if method == "CONNECT" else path)[0]
				analysis.incrementData(self.address[0], domainAnalysisType.connect, self.connectHost, 1)
		else:
			pass
コード例 #6
0
ファイル: webHandler.py プロジェクト: liyl/DDDProxy
	def get(self):
		opt = self.get_argument('opt',"").encode('utf8')
		if opt == "":
			self.render("admin_temp.html")
		else:
			if opt == "puturl":
				addr,port = parserUrlAddrPort(self.get_argument("url").encode('utf8'))
				if addr:
					domain = getDomainName(addr)
					if domainConfig.config.addDomain(domain):
						domainConfig.config.save()
				self.redirect("/admin", False)
			else:
				domain = self.get_argument("domain",default="").encode('utf8')
				ok = False
				if opt == "delete":
					ok = domainConfig.config.removeDomain(domain)
				elif opt == "close":
					ok = domainConfig.config.closeDomain(domain)
				elif opt == "open":
					ok = domainConfig.config.openDomain(domain)
				if ok:
					domainConfig.config.save()
				self.redirect("/admin", False)
コード例 #7
0
	def onHTTP(self, header, method, path, query, post):
# 		log.log(1,self,header,method,path,query,post)
		if method == "POST":
			postJson = json.loads(post)
			opt = postJson["opt"]
			respons = {}

			if(opt == "status"):
				respons = self.server.dumpConnects()
			elif(opt == "serverList"):
				respons["pac"] = "http://" + self.messageParse.getHeader("host") + "/pac"
				respons["list"] = settingConfig.setting(settingConfig.remoteServerList)
			elif opt == "setServerList":
				settingConfig.setting(settingConfig.remoteServerList, postJson["data"])
				respons["status"] = "ok"
# 			elif opt == "testRemoteProxy":
# 				respons["status"] = ""
			elif opt == "domainList":
				
				if "action" in postJson:
					action = postJson["action"]
					domain = postJson["domain"]
					respons={"status":"ok"}
					if action == "delete":
						domainConfig.config.removeDomain(domain)
					elif action == "open":
						domainConfig.config.openDomain(domain)
					elif action == "close":
						domainConfig.config.closeDomain(domain)
					else:
						respons={"status":"no found action"}
				else:
					respons["domainList"] = domainConfig.config.getDomainListWithAnalysis()
			elif opt == "analysisData":
				respons["analysisData"] = analysis.getAnalysisData(
																selectDomain=postJson["domain"],
																startTime=postJson["startTime"],
																todayStartTime=postJson["todayStartTime"]
																)
			elif opt == "addDomain":
				url = postJson["url"]
				host = parserUrlAddrPort(url)[0]
				if host:
					host = getDomainName(host)
				else:
					host = url if getDomainName(url) else ""
				respons["status"] = "ok" if domainConfig.config.addDomain(host) else "error"
			self.reseponse(respons,connection=self.messageParse.connection())
		elif path == "/pac":
			content = self.getFileContent("/pac.js")
			domainList = domainConfig.config.getDomainOpenedList()
			domainListJs = ""
			for domain in domainList:
				domainListJs += "A(\"" + domain + "\")||"
			content = content.replace("{{domainList}}", domainListJs)
			content = content.replace("{{proxy_ddr}}", self.messageParse.getHeader("host"))
			self.reseponse(content,connection=self.messageParse.connection())
		else:
			if path == "/":
				path = "/index.html"
			content = self.getFileContent(path)
			if content:
				
				self.reseponse(content,ContentType=get_mime_type(path),connection=self.messageParse.connection())
			else:
				self.reseponse("\"" + path + "\" not found", code=404,connection=self.messageParse.connection())
コード例 #8
0
ファイル: webHandler.py プロジェクト: liyl/DDDProxy
	def getRequestHost(self):
		addrPort = parserUrlAddrPort(self.request.protocol + "://" + self.request.host);
		return addrPort[0]