Browse Source

random choice a host name (http_simple/http_post/tls1.2_ticket_auth)

dev
BreakWa11 8 years ago
parent
commit
f3808a306f
  1. 38
      shadowsocks/obfsplugin/http_simple.py
  2. 2
      shadowsocks/obfsplugin/obfs_tls.py

38
shadowsocks/obfsplugin/http_simple.py

@ -96,10 +96,21 @@ class http_simple(plain.plain):
port = b'' port = b''
if self.server_info.port != 80: if self.server_info.port != 80:
port = b':' + to_bytes(str(self.server_info.port)) port = b':' + to_bytes(str(self.server_info.port))
body = None
hosts = (self.server_info.obfs_param or self.server_info.host)
pos = hosts.find("#")
if pos >= 0:
body = hosts[pos + 1:].replace("\\n", "\r\n")
hosts = hosts[:pos]
hosts = hosts.split(',')
host = random.choice(hosts)
http_head = b"GET /" + self.encode_head(headdata) + b" HTTP/1.1\r\n" http_head = b"GET /" + self.encode_head(headdata) + b" HTTP/1.1\r\n"
http_head += b"Host: " + to_bytes(self.server_info.obfs_param or self.server_info.host) + port + b"\r\n" http_head += b"Host: " + to_bytes(host) + port + b"\r\n"
http_head += b"User-Agent: " + random.choice(self.user_agent) + b"\r\n" if body:
http_head += b"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nAccept-Language: en-US,en;q=0.8\r\nAccept-Encoding: gzip, deflate\r\nDNT: 1\r\nConnection: keep-alive\r\n\r\n" http_head += body + "\r\n\r\n"
else:
http_head += b"User-Agent: " + random.choice(self.user_agent) + b"\r\n"
http_head += b"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nAccept-Language: en-US,en;q=0.8\r\nAccept-Encoding: gzip, deflate\r\nDNT: 1\r\nConnection: keep-alive\r\n\r\n"
self.has_sent_header = True self.has_sent_header = True
return http_head + buf return http_head + buf
@ -199,12 +210,23 @@ class http_post(http_simple):
port = b'' port = b''
if self.server_info.port != 80: if self.server_info.port != 80:
port = b':' + to_bytes(str(self.server_info.port)) port = b':' + to_bytes(str(self.server_info.port))
body = None
hosts = (self.server_info.obfs_param or self.server_info.host)
pos = hosts.find("#")
if pos >= 0:
body = hosts[pos + 1:].replace("\\n", "\r\n")
hosts = hosts[:pos]
hosts = hosts.split(',')
host = random.choice(hosts)
http_head = b"POST /" + self.encode_head(headdata) + b" HTTP/1.1\r\n" http_head = b"POST /" + self.encode_head(headdata) + b" HTTP/1.1\r\n"
http_head += b"Host: " + to_bytes(self.server_info.obfs_param or self.server_info.host) + port + b"\r\n" http_head += b"Host: " + to_bytes(host) + port + b"\r\n"
http_head += b"User-Agent: " + random.choice(self.user_agent) + b"\r\n" if body:
http_head += b"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nAccept-Language: en-US,en;q=0.8\r\nAccept-Encoding: gzip, deflate\r\n" http_head += body + "\r\n\r\n"
http_head += b"Content-Type: multipart/form-data; boundary=" + self.boundary() + b"\r\nDNT: 1\r\n" else:
http_head += "Connection: keep-alive\r\n\r\n" http_head += b"User-Agent: " + random.choice(self.user_agent) + b"\r\n"
http_head += b"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nAccept-Language: en-US,en;q=0.8\r\nAccept-Encoding: gzip, deflate\r\n"
http_head += b"Content-Type: multipart/form-data; boundary=" + self.boundary() + b"\r\nDNT: 1\r\n"
http_head += "Connection: keep-alive\r\n\r\n"
self.has_sent_header = True self.has_sent_header = True
return http_head + buf return http_head + buf

2
shadowsocks/obfsplugin/obfs_tls.py

@ -312,6 +312,8 @@ class tls_ticket_auth(plain.plain):
host = self.server_info.obfs_param or self.server_info.host host = self.server_info.obfs_param or self.server_info.host
if host and host[-1] in string.digits: if host and host[-1] in string.digits:
host = '' host = ''
hosts = host.split(',')
host = random.choice(hosts)
ext += self.sni(host) ext += self.sni(host)
ext += b"\x00\x17\x00\x00" ext += b"\x00\x17\x00\x00"
ext += b"\x00\x23\x00\xd0" + os.urandom(208) # ticket ext += b"\x00\x23\x00\xd0" + os.urandom(208) # ticket

Loading…
Cancel
Save