Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ExeBy/exe_root.../usr/lib/python2..../site-pac...
File: sockshandler.py
#!/usr/bin/env python
[0] Fix | Delete
"""
[1] Fix | Delete
SocksiPy + urllib2 handler
[2] Fix | Delete
[3] Fix | Delete
version: 0.3
[4] Fix | Delete
author: e<e@tr0ll.in>
[5] Fix | Delete
[6] Fix | Delete
This module provides a Handler which you can use with urllib2 to allow it to tunnel your connection through a socks.sockssocket socket, with out monkey patching the original socket...
[7] Fix | Delete
"""
[8] Fix | Delete
import ssl
[9] Fix | Delete
[10] Fix | Delete
try:
[11] Fix | Delete
import urllib2
[12] Fix | Delete
import httplib
[13] Fix | Delete
except ImportError: # Python 3
[14] Fix | Delete
import urllib.request as urllib2
[15] Fix | Delete
import http.client as httplib
[16] Fix | Delete
[17] Fix | Delete
import socks # $ pip install PySocks
[18] Fix | Delete
[19] Fix | Delete
def merge_dict(a, b):
[20] Fix | Delete
d = a.copy()
[21] Fix | Delete
d.update(b)
[22] Fix | Delete
return d
[23] Fix | Delete
[24] Fix | Delete
class SocksiPyConnection(httplib.HTTPConnection):
[25] Fix | Delete
def __init__(self, proxytype, proxyaddr, proxyport=None, rdns=True, username=None, password=None, *args, **kwargs):
[26] Fix | Delete
self.proxyargs = (proxytype, proxyaddr, proxyport, rdns, username, password)
[27] Fix | Delete
httplib.HTTPConnection.__init__(self, *args, **kwargs)
[28] Fix | Delete
[29] Fix | Delete
def connect(self):
[30] Fix | Delete
self.sock = socks.socksocket()
[31] Fix | Delete
self.sock.setproxy(*self.proxyargs)
[32] Fix | Delete
if type(self.timeout) in (int, float):
[33] Fix | Delete
self.sock.settimeout(self.timeout)
[34] Fix | Delete
self.sock.connect((self.host, self.port))
[35] Fix | Delete
[36] Fix | Delete
class SocksiPyConnectionS(httplib.HTTPSConnection):
[37] Fix | Delete
def __init__(self, proxytype, proxyaddr, proxyport=None, rdns=True, username=None, password=None, *args, **kwargs):
[38] Fix | Delete
self.proxyargs = (proxytype, proxyaddr, proxyport, rdns, username, password)
[39] Fix | Delete
httplib.HTTPSConnection.__init__(self, *args, **kwargs)
[40] Fix | Delete
[41] Fix | Delete
def connect(self):
[42] Fix | Delete
sock = socks.socksocket()
[43] Fix | Delete
sock.setproxy(*self.proxyargs)
[44] Fix | Delete
if type(self.timeout) in (int, float):
[45] Fix | Delete
sock.settimeout(self.timeout)
[46] Fix | Delete
sock.connect((self.host, self.port))
[47] Fix | Delete
self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file)
[48] Fix | Delete
[49] Fix | Delete
class SocksiPyHandler(urllib2.HTTPHandler, urllib2.HTTPSHandler):
[50] Fix | Delete
def __init__(self, *args, **kwargs):
[51] Fix | Delete
self.args = args
[52] Fix | Delete
self.kw = kwargs
[53] Fix | Delete
urllib2.HTTPHandler.__init__(self)
[54] Fix | Delete
[55] Fix | Delete
def http_open(self, req):
[56] Fix | Delete
def build(host, port=None, timeout=0, **kwargs):
[57] Fix | Delete
kw = merge_dict(self.kw, kwargs)
[58] Fix | Delete
conn = SocksiPyConnection(*self.args, host=host, port=port, timeout=timeout, **kw)
[59] Fix | Delete
return conn
[60] Fix | Delete
return self.do_open(build, req)
[61] Fix | Delete
[62] Fix | Delete
def https_open(self, req):
[63] Fix | Delete
def build(host, port=None, timeout=0, **kwargs):
[64] Fix | Delete
kw = merge_dict(self.kw, kwargs)
[65] Fix | Delete
conn = SocksiPyConnectionS(*self.args, host=host, port=port, timeout=timeout, **kw)
[66] Fix | Delete
return conn
[67] Fix | Delete
return self.do_open(build, req)
[68] Fix | Delete
[69] Fix | Delete
if __name__ == "__main__":
[70] Fix | Delete
import sys
[71] Fix | Delete
try:
[72] Fix | Delete
port = int(sys.argv[1])
[73] Fix | Delete
except (ValueError, IndexError):
[74] Fix | Delete
port = 9050
[75] Fix | Delete
opener = urllib2.build_opener(SocksiPyHandler(socks.PROXY_TYPE_SOCKS5, "localhost", port))
[76] Fix | Delete
print("HTTP: " + opener.open("http://httpbin.org/ip").read().decode())
[77] Fix | Delete
print("HTTPS: " + opener.open("https://httpbin.org/ip").read().decode())
[78] Fix | Delete
[79] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function