Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. -rw-r--r-- 1 root root
  2.  
  3. path = "/etc/hosts"
  4. fr = open(path,'r')
  5. b = fr.read()
  6. b = b+'something to write'
  7. fr.close()
  8. fw = open(path,'w')
  9. fw = os.system('echo %s|sudo -S python %s' % ('root', fw.write(b)))
  10.  
  11. os.popen("sudo -S %s"%(open(path,'w')), 'w').write(admin_password)
  12.  
  13. sudo chmod u+rwx /etc/hosts
  14.  
  15. os.system("echo %s| sudo -S python etcedit.py %s" % ('rootpassword', 'host_name'))
  16.  
  17. import os, subprocess
  18. import sys
  19. from sys import argv
  20.  
  21. def etc_update(host_name, *args):
  22. path = "/etc/hosts"
  23. host_name = host_name[0]
  24. fw = open(path,'w')
  25. fw.write(host_name)
  26.  
  27. etc_update(sys.argv[1:])
  28.  
  29. import os
  30. import pexpect
  31. import sys
  32. import argparse
  33.  
  34. def get_args():
  35. parser = argparse.ArgumentParser(description="Run as sudo!")
  36. parser.add_argument('-p', dest='privelege', action='store', help='also has rights')
  37. args = parser.parse_args()
  38. return vars(args)
  39.  
  40. full_path = os.path.abspath(__file__)
  41. print("full_path = %s", full_path)
  42.  
  43. if __name__ == '__main__':
  44. args = get_args()
  45. if args.get('privelege') == None:
  46. #check if it has sudo privelege and if not rerun with it.
  47. child = pexpect.spawn("sh", logfile = sys.stdout)
  48. child.sendline("sudo python %s -p root" % full_path)
  49. child.expect("assword", timeout = 100)
  50. child.logfile = None
  51. child.sendline("YOUR_PASSWORD")
  52. child.logfile_read = sys.stdout
  53. elif args.get('privelege') == 'root':
  54. #if it have root privelege do action
  55. path = "/etc/hosts"
  56. fr = open(path,'r')
  57. b = fr.read()
  58. b = b+'something to write'
  59. fr.close()
  60. fw = open(path,'w')
  61. fw.write(b)
  62. fw.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement