ANTICHAT — форум по информационной безопасности, OSINT и технологиям
ANTICHAT — русскоязычное сообщество по безопасности, OSINT и программированию.
Форум ранее работал на доменах antichat.ru, antichat.com и antichat.club,
и теперь снова доступен на новом адресе —
forum.antichat.xyz.
Форум восстановлен и продолжает развитие: доступны архивные темы, добавляются новые обсуждения и материалы.
⚠️ Старые аккаунты восстановить невозможно — необходимо зарегистрироваться заново.

09.07.2008, 19:51
|
|
Banned
Регистрация: 16.07.2007
Сообщений: 79
Провел на форуме: 801879
Репутация:
337
|
|
Точим exploit Разбор ошибок выдаваемых компилятором gcc при попытке трансляции файла beta.cpp
Исходник - http://milw0rm.com/shellcode/656
Часть исходника:
Код:
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
#include <windows.h>
#define MAX_BUFFER_SIZE 0x1000
#define DEFAULT_PAD_BYTE 0x90
#define MAX_MARKER_SIZE 0x10
#define bool char
#define true 1
#define false 0
char* hex = "0123456789abcdef";
void version(void) {
printf(
"______________________________________________________________________________\n"
"\n"
" ,sSSSis ,sSSSs, Beta v2.0.\n"
" iS\" dP dY\" ,SP Encodes binary data to/from a variety of formats.\n"
" .SP dSS\" ,sS\" Copyright (C) 2003-2005 by Berend-Jan Wever\n"
" dS' Sb ,sY\" <skylined@edup.tudelft.nl>\n"
" .SP dSSP' sSSSSSSP http://spaces.msn.com/members/berendjanwever\n"
"_ iS:_________________________________________________________________________\n"
"\n"
);
return;
}
void help(void) {
printf(
"Beta was developed to convert raw binary shellcode into text that can be\n"
"used in exploit source-code. It can convert raw binary data to a large\n"
"number of encodings.\n"
"\n"
" Usage: BETA [options] [input file name]\n"
"\n"
" input file name Read input from the given file. By default BETA\n"
" reads input from stdin.\n"
"\n"
"General options:\n"
" --help Display this help and exit\n"
" --version Output version information and exit\n"
" --verbose Displays additional information.\n"
" --pause Wait for keypress before exiting.\n"
"\n"
"Encoding options: (default = AA BB CC ...)\n"
" \\x \\xAA\\xBB\\xCC ...\n"
" 0x 0xAA 0xBB 0xCC ...\n"
" %% %%AA%%BB%%CC...\n"
" # oÞ!...\n"
" %%u %%uBBAA%%uDDCC...\n"
" --noencode Don't encode (only do checks).\n"
"\n"
"Layout options: (default = none)\n"
" --chars/line=X Output a new line after every X encoded bytes.\n"
" --quotes Wrap output in quotes. Only usefull in combination\n"
" with chars/line argument.\n"
" --quotesplus Wrap output in quotes and add a '+' at the end\n"
" of each line. Only usefull in combination with\n"
" chars/line argument.\n"
" --spaces Seperate encoding entities by spaces.\n"
" --commas Seperate encoding entities by commas and spaces.\n"
"\n"
"Additional options:\n"
" --padbyte=AA When using a multibyte encoding (e.g. %%uXXXX)\n"
" the data might need some padding. The given byte\n"
" will be used, the default value is %02x.\n"
" --badbytes[=AA[,BB[...]]] Check the input for presence of the given char-\n"
" acters and report where they are found. You can\n"
" supply a comma seperated list of hexadecimal\n"
" character codes and the keywords \"alpha\" and\n"
" \"print\" (to check for the presence of nonalpha-\n"
" numeric or non-printable characters). If no char-\n"
" acters are supplied, the input will be checked for\n"
" the presence of 00, 0A and 0D. \n"
" --marker[=AA[,BB[...]]] The input contains both garbage and data. The data\n"
" is wrapped by the marker bytes, everything before\n"
" the first set and after the last set of marker\n"
" bytes will be ignored. If no marker bytes are\n"
" supplied, \"CC CC CC\" (3xInt3) will be used.\n"
" You can supply up to %d bytes as marker.\n",
DEFAULT_PAD_BYTE, MAX_MARKER_SIZE
);
return;
}
// Find a set of bytes in another set of bytes
char* find_bytes(char* haystack, int haystack_length, char* needle, int needle_length) {
int needle_start = -1, needle_checked = 1;
do {
if (haystack[needle_start+needle_checked] == needle[needle_checked])
// Yes, bytes match, check next byte of needle
needle_checked++;
else {
// No, no match, check next byte of haystack
needle_start++;
needle_checked = 0;
}
if (needle_start + needle_length > haystack_length)
// Not found.
return 0;
} while (needle_checked != needle_length);
// Found!
return haystack + needle_start;
}
int main(int argc, char** argv, char** envp) {
// This will contain the input data
char* buffer;
int buffer_length = 0;
// This will contain the marker
char marker[MAX_MARKER_SIZE];
int marker_length = 0;
// This will keep track of all "bad" bytes
char char_is_bad[0x100];
for (int i = 0; i < sizeof(char_is_bad)/sizeof(*char_is_bad); i++)
char_is_bad[i] = false;
// These will store some values supplied by command line arguments
bool switch_verbose = false, switch_encode = true, switch_pause = false;
char pad_byte = DEFAULT_PAD_BYTE;
int chars_per_line = -1;
char *input_filename = 0;
char *line_header = "", *line_footer = "\n", *footer = "\n";
char *bytes_format = "%02X", *byte_seperator = "";
int bytes = 1;
//--------------------------------------------------------------------------
// Read and handle arguments
for (int argn = 1; argn < argc; argn++) {
//--help ---------------------------------------------------------------
if (stricmp(argv[argn], "--help") == 0) {
version();
help();
if (switch_pause) getchar();
exit(EXIT_SUCCESS);
//--version ------------------------------------------------------------
} else if (stricmp(argv[argn], "--version") == 0) {
version();
if (switch_pause) getchar();
exit(EXIT_SUCCESS);
//--verbose ------------------------------------------------------------
} else if (stricmp(argv[argn], "--verbose") == 0) {
switch_verbose = true;
//--noencode -----------------------------------------------------------
} else if (stricmp(argv[argn], "--noencode") == 0) {
switch_encode = false;
//--noencode -----------------------------------------------------------
} else if (stricmp(argv[argn], "--pause") == 0) {
switch_pause = true;
//--chars/line= --------------------------------------------------------
} else if (strnicmp(argv[argn], "--chars/line=", 13)==0) {
if ((chars_per_line = strtol(&(argv[argn][13]), NULL, 10)) < 1) {
printf("Illegal number of characters per line: \"%s\".\n", &(argv[argn][13]));
if (switch_pause) getchar();
exit(EXIT_FAILURE);
}
//--layout options -----------------------------------------------------
} else if (strcmp(argv[argn], "--quote") == 0 || strcmp(argv[argn], "--quotes") == 0) {
line_header = "\"";
line_footer = "\"\n";
footer = "\"\n";
} else if (strcmp(argv[argn], "--quoteplus") == 0 || strcmp(argv[argn], "--quotesplus") == 0) {
line_header = "\"";
line_footer = "\" +\n";
footer = "\"\n";
} else if (strcmp(argv[argn], "--comma") == 0 || strcmp(argv[argn], "--commas") == 0) {
byte_seperator = ", ";
} else if (strcmp(argv[argn], "--space") == 0 || strcmp(argv[argn], "--spaces") == 0) {
byte_seperator = " ";
//--encoding options ---------------------------------------------------
} else if (stricmp(argv[argn], "\\x")==0) {
bytes_format = "\\x%02X";
} else if (stricmp(argv[argn], "0x")==0) {
bytes_format = "0x%02X";
} else if (stricmp(argv[argn], "#")==0) {
bytes_format = "&#%d;";
} else if (stricmp(argv[argn], "%")==0) {
bytes_format = "%%%02X";
} else if (stricmp(argv[argn], "%u")==0) {
bytes_format = "%%u%04X";
bytes = 2;
//--padbyte ------------------------------------------------------------
} else if (strnicmp(argv[argn], "--padbyte=", 10) == 0) {
char* next_xarg;
pad_byte = strtol(&(argv[argn][10]), &next_xarg, 0x10);
if ((pad_byte & 0xFF) != pad_byte) {
printf("Incorrect value in padbyte argument: \"%s\".\n", &(argv[argn][11]));
printf(" Value cannot be converted to a byte ");
for (int i = 0; i < strlen(&(argv[argn][10])); i++)
printf("^");
printf("\n");
if (switch_pause) getchar();
exit(EXIT_FAILURE);
}
if (next_xarg == &(argv[argn][10])) {
printf("Incorrect byte encoding in padbyte argument: \"%s\".\n", &(argv[argn][10]));
if (switch_pause) getchar();
exit(EXIT_FAILURE);
}
//--badbytes -----------------------------------------------------------
} else if (stricmp(argv[argn], "--badbytes") == 0) {
char_is_bad[0x0] = true;
char_is_bad[0xA] = true;
char_is_bad[0xD] = true;
//--badbytes=XX,XX,... -------------------------------------------------
} else if (strnicmp(argv[argn], "--badbytes=", 11) == 0) {
char* xarg = &(argv[argn][11]);
while (strlen(xarg) > 0) {
if (strnicmp(xarg, "alpha", 5) == 0) {
for (int i = 0; i < 0x100; i++) {
if (!isalnum(i)) char_is_bad[i] = true;
}
xarg += 5;
} else if (strnicmp(xarg, "print", 5) == 0) {
for (int i = 0; i < 0x100; i++) {
if (!isprint(i)) char_is_bad[i] = true;
}
xarg += 5;
} else {
char* next_xarg;
int decoded = strtol(xarg, &next_xarg, 0x10);
if ((decoded & 0xFF) != decoded) {
printf("Incorrect value in badbytes argument: \"%s\".\n", &(argv[argn][11]));
for (char* i = &(argv[argn][9]); i < xarg; i++)
printf(" ");
printf(" Value cannot be converted to a byte ");
for (char* i = xarg; i < next_xarg; i++)
printf("^");
printf("\n");
if (switch_pause) getchar();
exit(EXIT_FAILURE);
}
if (next_xarg == xarg) {
printf("Incorrect byte encoding in badbytes argument: \"%s\".\n", &(argv[argn][11]));
for (char* i = &(argv[argn][11]); i < xarg; i++)
printf(" ");
printf(" Character '%c' not expected ^\n", *xarg);
if (switch_pause) getchar();
exit(EXIT_FAILURE);
}
char_is_bad[decoded] = true;
xarg = next_xarg;
}
if (*xarg == ',') xarg++;
}
А это список ошибок выдаваемых компилятором(не считая варнигов):
Код HTML:
beta.cpp:34:21: windows.h: No such file or directory
beta.cpp: In function `int main(int, char**, char**)':
beta.cpp:165: error: `stricmp' undeclared (first use this function)
beta.cpp:185: error: `strnicmp' undeclared (first use this function)
beta.cpp:245: error: `isalnum' undeclared (first use this function)
beta.cpp:250: error: `isprint' undeclared (first use this function)
beta.cpp:339: error: invalid conversion from `void*' to `char*'
beta.cpp:356: error: `O_BINARY' undeclared (first use this function)
beta.cpp:361: error: `lseek' undeclared (first use this function)
beta.cpp:377: error: invalid conversion from `void*' to `char*'
beta.cpp:384: error: `read' undeclared (first use this function)
beta.cpp:398: error: `close' undeclared (first use this function)
Ну, с ошибкой 34 все понятно — программа усиленно косит под форточки, не понятно за каким хреном таща за собой файл <windows.h>, но тут же использует стандартные POSIX- вызовы: open (со странным флагом O_BINARY), lseek, read и close, которых ни в самом windows, ни в одном из win32-компиляторов никогда не существовало (см. ошибки 356, 361, 384 и 398). Убираем строку "#include <windows.h>", заменяя ее на "#include <unistd.h>" и удаляем глупый флаг O_BINARY, поскольку по умолчанию файл уже является двоичным (узнать какие заголовочные файлы соответствуют данной функции можно из man'а, например, "man 2 open"). Для избавления от ругательства "this file include <malloc.h> witch is deprecated, use <stdlib.h> instead" удаляем и "#include <malloc.h>".
Ошибки 245 и 250 устраняются подключением их "родного" заголовочного файла, в котором они были объявлены "#include <ctype.h>" (см. "man isalnum"). А вот функций stricmp и strnicmp в gcc действительно нет, однако, они могут быть заменены на аналогичные им strcmp и strncmp даже без коррекции аргументов!
Ошибки 339 и 377 исправляется еще проще: достаточно взять строку "buffer=malloc(MAX_BUFFER_SIZE)" и добавить явное преобразование типов, так же называемое ксатингом: "buffer=(char*)malloc(MAX_BUFFER_SIZE)".
Еще дополню разбором shell-кода, как только воткну в него =)
|
|
|
|
|
Здесь присутствуют: 1 (пользователей: 0 , гостей: 1)
|
|
|
|