반응형
■ 사용법
sudo apt install nasm
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
section .text | |
global _start | |
_start: | |
jmp folder | |
main: | |
xor rax,rax | |
pop rdi | |
mov si,0x1ef | |
add al,83 | |
syscall | |
xor rax,rax | |
add al,60 | |
syscall | |
folder: | |
call main | |
fname db "test111" |
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
nasm -f elf64 shell.asm -o shell.o | |
ld shell.o -o shell | |
./shell |
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
objdump -d shell | |
for i in $(objdump -d shell | grep "^ " | cut -f 2); do echo -n \\x$i; done | |
\xeb\x13\x48\x31\xc0\x5f\x66\xbe\xef\x01\x04\x53\x0f\x05\x48\x31\xc0\x04\x3c\x0f\x05\xe8\xe8\xff\xff\xff\x74\x65\x73\x74\x31\x31\x31 | |
for i in $(objdump -d shell | grep "^ " | cut -f 2); do echo -n $i; done | |
eb134831c05f66beef0104530f054831c0043c0f05e8e8ffffff74657374313131 |
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 shellcode_type3 shellcode_type3.c -m64 | |
// | |
#include <stdio.h> | |
#include <sys/mman.h> | |
#include <sys/stat.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
int main(int argc, char ** argv ) | |
{ | |
if( argc < 2 ) { | |
printf("[-] usage : \n"); | |
printf("%s path \n", argv[0]); | |
printf("%s shellcode.bin \n", argv[0]); | |
return 0; | |
} | |
printf("[+] shllcode flle path = %s\n", argv[1]); | |
if( access( argv[1] , F_OK ) == -1 ){ | |
printf("[-] there are no file in the path \n"); | |
return 0; | |
} | |
FILE *file = fopen(argv[1], "r"); | |
unsigned char *buf; | |
int length = 0; | |
struct stat st; | |
int v; | |
fstat(fileno(file), &st); | |
buf = valloc(st.st_size); | |
while (fscanf(file, "\\x%02x", &v) == 1) | |
{ | |
buf[length++] = v; | |
} | |
fclose(file); | |
mprotect(buf, length, PROT_EXEC); | |
int (*ret)() = (int (*)())buf; | |
ret(); | |
return 0; | |
} |
반응형
'C 언어 > 0x08-shellcode' 카테고리의 다른 글
[c lang ] : shellcode 작성 ][test111 폴더 생성하기 (0) | 2019.09.04 |
---|---|
shell 코드 64bit코딩시 컴파일 방법 (0) | 2014.10.12 |