askanton

proxy

Feb 13th, 2021 (edited)
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.98 KB | None | 0 0
  1. def main_deploy(host, user, secret, pport, proxy_pass):  # функция разворачивает Socks5 proxy на сервер, используя
  2.     # стандартный порт 1080, подключаться пожно под пользователем root или proxy
  3.     client = paramiko.SSHClient()
  4.     client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  5.     client.connect(hostname=host, username=user, password=secret, port=22)
  6.     ssh = client.invoke_shell()
  7.     time.sleep(2)
  8.     out = ssh.recv(60000)
  9.     # print(out)
  10.     name = str(out[-16:])
  11.     print("Server user:" + name)
  12.     print("Work starting")
  13.     ssh.send("sudo apt update && sudo apt install dante-server" + "\n")
  14.     time.sleep(1)
  15.     while True:
  16.         out = ssh.recv(60000)
  17.         # print(out)
  18.         if str(out[-16:]) == name:
  19.             print("Update and dante install complete")
  20.             break
  21.         else:
  22.             print("Wait fo it!")
  23.             time.sleep(5)
  24.     ssh.send("echo logoutput: stderr > /etc/danted.conf" + "\n")
  25.     ssh.send("ifacer=`ip r | grep default | grep -Po '(?<=dev )(\S+)'`" + "\n")
  26.     ssh.send("echo internal: ${ifacer} port = " + pport + "  >> /etc/danted.conf" + "\n")
  27.     ssh.send("echo external: ${ifacer} >> /etc/danted.conf" + "\n")
  28.     ssh.send("echo method: username >> /etc/danted.conf" + "\n")
  29.     ssh.send("echo user.privileged: root >> /etc/danted.conf" + "\n")
  30.     ssh.send("echo user.notprivileged: nobody >> /etc/danted.conf" + "\n")
  31.     ssh.send("echo user.libwrap: nobody >> /etc/danted.conf" + "\n")
  32.     ssh.send("echo  client pass { >> /etc/danted.conf" + "\n")
  33.     ssh.send('echo  -e "\\tfrom: 0.0.0.0/0 to: 0.0.0.0/0" >> /etc/danted.conf' + "\n")
  34.     ssh.send('echo  -e "\\tlog: error connect disconnect">> /etc/danted.conf' + "\n")
  35.     ssh.send("echo  } >> /etc/danted.conf" + "\n")
  36.     ssh.send("echo  client block { >> /etc/danted.conf" + "\n")
  37.     ssh.send('echo  -e "\\tfrom: 0.0.0.0/0 to: 0.0.0.0/0" >> /etc/danted.conf' + "\n")
  38.     ssh.send('echo  -e "\\tlog: connect error" >> /etc/danted.conf' + "\n")
  39.     ssh.send("echo  } >> /etc/danted.conf" + "\n")
  40.     ssh.send("echo  pass { >> /etc/danted.conf" + "\n")
  41.     ssh.send('echo  -e "\\tfrom: 0.0.0.0/0 to: 0.0.0.0/0" >> /etc/danted.conf' + "\n")
  42.     ssh.send('echo  -e "\\tlog: error connect disconnect" >> /etc/danted.conf' + "\n")
  43.     ssh.send("echo  } >> /etc/danted.conf" + "\n")
  44.     ssh.send("echo  block { >> /etc/danted.conf" + "\n")
  45.     ssh.send('echo  -e "\\tfrom: 0.0.0.0/0 to: 0.0.0.0/0" >> /etc/danted.conf' + "\n")
  46.     ssh.send('echo  -e "\\tlog: connect error" >> /etc/danted.conf' + "\n")
  47.     ssh.send("echo  } >> /etc/danted.conf" + "\n")
  48.     print("Config file created")
  49.     ssh.send("service danted restart" + "\n")
  50.     time.sleep(5)
  51.     print("Dante restarted")
  52.     ssh.send('passwd proxy' + "\n")
  53.     print("Password changing")
  54.     ssh.send(proxy_pass + "\n")
  55.     time.sleep(1)
  56.     print("Password changed")
  57.     ssh.send(proxy_pass + "\n")
  58.     print("Done")
Add Comment
Please, Sign In to add comment