Пример #1
0
    def prepareConnect(self,
                       userId=None,
                       destinationPort=None,
                       destinationIp=None,
                       destinationType=None,
                       reserved=None):
        """
		Connect request
		"""
        if self.cfg['proxy-type'] == PROXY_SOCKS4:
            tpl = templates.socks(version=4,
                                  more=templates.connect(
                                      userId=userId,
                                      destIp=destinationIp,
                                      destPort=destinationPort))
            req, summary = self.sockCodec4.encode(socks_tpl=tpl)

        if self.cfg['proxy-type'] == PROXY_SOCKS5:
            tpl = templates.socks(version=5,
                                  reserved=reserved,
                                  more=templates.connect(
                                      destIp=destinationIp,
                                      destPort=destinationPort,
                                      destType=destinationType))
            req, summary = self.sockCodec5.encode(socks_tpl=tpl)

        return (tpl, req, summary)
Пример #2
0
    def decode(self, sock):
        """
		"""
        self.debug('decode sock rsp: %s' % sock)
        tpl = None
        summary = 'response'
        try:
            sock_rsp = struct.unpack('!2BH4B', sock)

            # CD is the result code with one of the following values:
            CD = str(sock_rsp[1])

            #		90: request granted
            #		91: request rejected or failed
            #		92: request rejected becasue SOCKS server cannot connect to
            #		    identd on the client
            #		93: request rejected because the client program and identd
            #		    report different user-ids.
            if sock_rsp[1] == 90:
                summary = 'granted'
            if sock_rsp[1] == 91:
                summary = 'rejected'

            # VN is the version of the reply code and should be 0
            VN = str(sock_rsp[0])

            tpl = templates.socks(version=VN,
                                  result=CD,
                                  remotePort=str(sock_rsp[2]),
                                  remoteAddress='.'.join(map(
                                      str, sock_rsp[3:])),
                                  more=templates.received())
        except Exception as e:
            self.error('unable to decode sock4 response: %s' % e)
        return (tpl, summary)
Пример #3
0
	def prepareNego(self):
		"""
		Negociation with socks version 5
		only user/password supported 
		"""
		if self.cfg['proxy-type'] != PROXY_SOCKS5:
			return
		# support user/password authen
		tpl = templates.socks(version=5, nmethods=1, methods=0)
		req, summary = self.sockCodec5.encodenego(socks_tpl=tpl)			
		return (tpl,req, summary)
Пример #4
0
    def decodenego(self, sock):
        """
	
		"""
        self.debug('decode sock nego rsp')
        tpl = None
        summary = 'response'
        try:
            sock_rsp = struct.unpack('!2B', sock)

            # extract version
            V = str(sock_rsp[0])

            #		'00' NO AUTHENTICATION REQUIRED
            #		'01' GSSAPI
            #		'02' USERNAME/PASSWORD
            #		'03' to X'7F' IANA ASSIGNED
            #		'80' to X'FE' RESERVED FOR PRIVATE METHODS
            #		'FF' NO ACCEPTABLE METHODS
            METHOD = 'unknown'
            if sock_rsp[1] == 0:
                METHOD = 'no authentication required'

            if sock_rsp[1] == 1:
                METHOD = 'gssapi'

            if sock_rsp[1] == 2:
                METHOD = 'username/password'

            if sock_rsp[1] == 255:
                METHOD = 'no acceptable methods'

            summary = METHOD
            tpl = templates.socks(version=V,
                                  methods=str(sock_rsp[1]),
                                  methods_str=METHOD,
                                  more=templates.received())
        except Exception as e:
            self.error('unable to decode sock5 nego response: %s' % e)
        return (tpl, summary)
Пример #5
0
    def decode(self, sock):
        """
		Support ipv4 only for now
		"""
        self.debug('decode sock rsp')
        tpl = None
        summary = 'response'
        try:
            sock_rsp = struct.unpack('!4B4BH', sock)

            if sock_rsp[1] == 0:
                summary = 'succeeded'

            tpl = templates.socks(version=str(sock_rsp[0]),
                                  result=str(sock_rsp[1]),
                                  reserved=str(sock_rsp[2]),
                                  remoteType=str(sock_rsp[3]),
                                  remotePort=str(sock_rsp[8]),
                                  remoteAddress='.'.join(
                                      map(str, sock_rsp[4:8])),
                                  more=templates.received())
        except Exception as e:
            self.error('unable to decode sock5 response: %s' % e)
        return (tpl, summary)