Skip to content

Instantly share code, notes, and snippets.

@bobquest33
Created October 18, 2017 08:43
Show Gist options
  • Save bobquest33/aed86f2880f8a646f5bd9da16a7202b1 to your computer and use it in GitHub Desktop.
Save bobquest33/aed86f2880f8a646f5bd9da16a7202b1 to your computer and use it in GitHub Desktop.
Script for Accessing Tor from Windows PC
from fabric.api import *
def query():
run("ls /")
import paramiko
import socks
import sys
import socket
from fabric.api import *
import getpass
import traceback
from fabfile import *
# The proxy post for Tor SOCKS5 proxy
proxyhost="127.0.0.1"
proxyport=9150
# Set the defult SOCKS5 proxy to be used by python program
socks.set_default_proxy(socks.SOCKS5, proxyhost,proxyport, True) # SOCKS4 and SOCKS5 use port 1080 by default
socket.socket = socks.socksocket
# Overide code to Perform DNS resolution through the socket
def getaddrinfo(*args):
#print(args[0],args[1])
return [(socket.AF_INET, socket.SOCK_STREAM, 6, '', (args[0], args[1]))]
socket.getaddrinfo = getaddrinfo
if __name__ == '__main__':
# Get the host, user, and post details from commandline and type in the password when prompted
host = sys.argv[1]
user = sys.argv[2]
passwd = getpass.getpass(prompt='Password: ')
port = 22
if len(sys.argv) > 3:
port = int(sys.argv[3])
# Now setup the host,port,password in the the settings object and connect to Tor server to execute query function
try:
with settings(host_string="%s:%s"%(host,port),user=user, password = passwd):
query()
except Exception as e:
print('Connection failed: %s', str(e))
traceback.print_exc()
sys.exit('Could not connect')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment