Find file Copy path
ef01329 Dec 30, 2014
1 contributor

Users who have contributed to this file

executable file 147 lines (118 sloc) 4.66 KB
# -*- coding: utf-8 -*-
__author__ = 'arul'
from fabric.contrib.files import *
import sys
env.use_ssh_config = True
Python Script to setup Anomaly environmental using TOR and Privoxy
class SystemInfo():
def __init__(self):
def __get_os_info__(self):
self.OS_ARCH = run(r"uname -m | sed 's/x86_//;s/i[3-6]86/32/'")
if exists('/etc/lsb-release'):
with prefix(". /etc/lsb-release"):
self.OS_NAME = run("echo -n $DISTRIB_ID")
self.OS_VERSION = run("echo -n $DISTRIB_RELEASE")
elif exists('/etc/debian_version'):
self.OS_NAME = "Debian"
elif exists('/etc/redhat-release'):
self.OS_NAME = "Redhat"
self.OS_NAME = run("uname -s")
self.OS_VERSION = run("uname -r")
def __install_deps_debian__():
run("sudo apt-get update")
run("sudo apt-get install tor -y")
run("sudo apt-get install privoxy -y")
def __install_deps_redhat__():
if not __is_repo_present__("epel"):
with cd("/tmp"):
# TODO install the correct version, arch of rpm file.
run("rpm -Uvh epel-release*rpm")
run("yum install ntp -y")
run("chkconfig --add ntpd")
run("chkconfig ntpd on")
run("service ntpd restart")
run("yum install tor -y")
run("yum install privoxy -y")
run("yum install python-devel python-pip unzip -y")
def __is_repo_present__(reponame):
repolist = run("yum repolist %s | grep repolist" % reponame)
import re
match ="[0-9,]+", repolist)
if match:
repo_length =",", "")
if int(repo_length) > 0:
return True
return False
def __is_already_installed__(package_name):
packages = run("yum list installed %s" % package_name)
import re
match ="Installed Packages", packages)
if match:
return True
return False
def __tor_config__():
with cd("/etc/tor/"):
# run("cp torrc.sample torrc")
# Here hashed password is "Pas`sword12"
torrc_config = """
ControlPort 9051
HashedControlPassword 16:79C8734C30ABD944604B839CEAF5AAC0F61AA500832A4B8BB9BC8042A5
uncomment("torrc", r"ControlPort(\s)+9051")
uncomment("torrc", r"HashedControlPassword(\s)+16")
with cd("/etc/privoxy"):
uncomment("config", r"forward-socks5t(\s)+\/(\s)+")
uncomment("config", r"forward(\s)+192")
uncomment("config", r"forward(\s)+10")
uncomment("config", r"forward(\s)+127")
def __set_system_proxy__(sysinfo):
proxy_string = """http_proxy=""
_JAVA_OPTIONS="-Dhttp.proxyHost=localhost -Dhttp.proxyPort=8118"
if sysinfo.OS_NAME.lower() in ["debian", "ubuntu"]:
run('touch /etc/environment')
append("/etc/environment", proxy_string)
elif sysinfo.OS_NAME.lower() in ["redhat", "centos", "fadora"]:
run('touch /etc/profile.d/')
proxy_string = proxy_string + "export http_proxy https_proxy ftp_proxy HTTP_PROXY HTTPS_PROXY FTP_PROXY _JAVA_OPTIONS"
append("/etc/profile.d/", proxy_string)
def __setup_renew_ip__():
# TODO Tor config control port password
run("wget --no-check-certificate -O /tmp/pytorctl.tar.gz")
run("mkdir /tmp/pytorctl")
run("tar -xzvf /tmp/pytorctl.tar.gz -C /tmp/pytorctl --strip-components=1")
run("pip install /tmp/pytorctl/")
run("rm -rf /tmp/pytorctl*")
put(local_path="../assets/", remote_path="/opt/", mode=0755)
def install():
global sysinfo
sysinfo = SystemInfo()
print "Name : %s, Version : %s, Arch : %s" % (sysinfo.OS_NAME, sysinfo.OS_VERSION, sysinfo.OS_ARCH)
if sysinfo.OS_NAME.lower() in ["debian", "ubuntu"]:
elif sysinfo.OS_NAME.lower() in ["redhat", "centos", "fadora"]:
run('sudo /etc/init.d/tor restart')
run('sudo /etc/init.d/privoxy restart')
run('curl -s --socks5-hostname localhost:9050')
run('curl -s')
if __name__ == '__main__':
print "Usage: fab -H hostname -f %s install" % sys.argv[0]