http://www.hackerschool.org/HS_Boards/zboard.php?id=Free_Board&no=37877 [º¹»ç]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define MAX_LEN 256
// Convert input string like "\\x31\\xc0..." into actual byte array
int decode_shellcode(const char *input, unsigned char *output) {
int len = strlen(input);
int out_idx = 0;
for (int i = 0; i < len;) {
// Check for "\xNN" pattern
if (input[i] == '\\' && input[i+1] == 'x' &&
isxdigit(input[i+2]) && isxdigit(input[i+3])) {
char hex[3] = { input[i+2], input[i+3], '\0' };
output[out_idx++] = (unsigned char)strtol(hex, NULL, 16);
i += 4;
} else {
return -1; // Invalid format
}
}
return out_idx; // Number of bytes converted
}
int main(void)
{
char your_answer[MAX_LEN];
char *shellcode_25bytes = "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e"
"\x89\xe3\x50\x53\x89\xe1\x31\xd2\xb0\x0b\xcd\x80";
unsigned char decoded_input[MAX_LEN];
while (1) {
// Prompt user for shellcode input
printf("Enter the shellcode('q' to exit) : ");
fgets(your_answer, MAX_LEN, stdin);
your_answer[strcspn(your_answer, "\n")] = '\0'; // Remove newline character
// Exit if input is "q"
if (strcmp(your_answer, "q") == 0) {
exit(0);
}
// Decode input into raw bytes
int decoded_len = decode_shellcode(your_answer, decoded_input);
if (decoded_len < 0) {
printf("Invalid format. Use \\xNN format.\n");
continue;
}
// Compare decoded input with actual shellcode
if (decoded_len == strlen(shellcode_25bytes) &&
memcmp(decoded_input, shellcode_25bytes, decoded_len) == 0) {
printf("correct!!!\n");
break;
} else {
printf("fail...\n");
}
}
return 0;
} |
Hit : 155 Date : 2025/05/07 06:30
|