Last active
February 5, 2016 22:29
-
-
Save aeppert/7dc7e67b9e32b21189e1 to your computer and use it in GitHub Desktop.
Force a binding to a specific local port and then SSL encapsulate everything outbound.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| import ssl | |
| import socket | |
| def get_outbound_ip(): | |
| ret = None | |
| s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
| s.connect(("gmail.com", 80)) | |
| ret = s.getsockname()[0] | |
| s.close() | |
| return ret | |
| def do_ssl_wrap_connect(sock, server_name): | |
| context = ssl.SSLContext(ssl.PROTOCOL_TLSv1) | |
| context.verify_mode = ssl.CERT_NONE | |
| context.check_hostname = False | |
| context.load_default_certs() | |
| s = context.wrap_socket(sock) | |
| return s | |
| def main(): | |
| ip_problem = 'www.google.com' | |
| s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
| s.bind((get_outbound_ip(), 6668)) | |
| s = do_ssl_wrap_connect(s, ip_problem) | |
| s.connect((ip_problem, 443)) | |
| s.write("GET / HTTP/1.1\r\nHost: " + ip_problem + "\r\n\r\n") | |
| print s.read() | |
| s.close() | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment