최근에 uaf문제를 몇개 풀어봤는데 짧지만 uaf 문제를 풀면서 배운것을 적어보려한다


먼저 uaf란


메모리를 heap영역에 동적할당 하고 free할때 발생하는 취약점이다

크게 두가지로 나누어 보겠다. 


1. eip 조작


할당한 변수를 call하는 부분이 있는 경우


예를 들어 구조체를 동적할당한다고 생각해보자

구조체에는 변수가 들어갈 수도 있지만 함수도 들어갈 수 있다.

프로그램에서 그 함수를 call하는 경우가 있는데

그부분을 취약점을 찾아서 control하는 것이다. 


우리가 할당한 변수에 call



2. leak

uaf로 free된 부분에는 우리가 leak해서 도움이 될만한 주소들이 쌓이는 경우가 있다.

그 부분을 유의하면서 찾아도 좋다

'시스템 > 시스템 해킹' 카테고리의 다른 글

arm 환경 셋팅  (0) 2016.12.09
integer overflow  (0) 2016.12.09
gdb peda 설치방법  (0) 2016.11.21
tip 정리  (0) 2016.11.18
bind shellcode 소스코드  (0) 2016.10.16


https://hexa-unist.github.io/2015/02/25/PEDA-Introduction-Installation/

'시스템 > 시스템 해킹' 카테고리의 다른 글

integer overflow  (0) 2016.12.09
use after free  (0) 2016.11.25
tip 정리  (0) 2016.11.18
bind shellcode 소스코드  (0) 2016.10.16
버퍼오버플로우 문서  (0) 2016.10.13

write 함수의 size에 -1이 들어가면?

시작주소로부터 계속 출력함 -> 릭할때 써먹자!



sigalrm때문에 디버깅이 불편할떈?

hxd로 인자를 패치해주자


bof찾을때

문자열로 터지는 부분도 있지만

숫자입력에 음수를 넣엇을때 터지는 부분도 있다.

유의하고 넣어보자

'시스템 > 시스템 해킹' 카테고리의 다른 글

use after free  (0) 2016.11.25
gdb peda 설치방법  (0) 2016.11.21
bind shellcode 소스코드  (0) 2016.10.16
버퍼오버플로우 문서  (0) 2016.10.13
환경변수에 쉘코드 넣기(에그쉘 정리)  (0) 2016.10.12


 tail -f /tmp/race2.sh &


현재 백그라운드 작업 중인 목록
jobs

실행중인 프로세스 background전환
bg

백그라운드 -> 포그라운드
fg (%번호)



프로세스 죽이기

kill (%번호)

'시스템 > 리눅스 기본' 카테고리의 다른 글

glibc 소스코드  (0) 2016.12.27
objdump 사용법  (0) 2016.10.18
라이브러리 참조순서  (0) 2016.10.15
알아두면 좋은 명령어 모음  (0) 2016.10.13
gdb layout  (0) 2016.10.13

--help 쳐보면

많이 쓰는 옵션은

-D 옵션 -X 옵션 등이 있다



Usage: objdump <option(s)> <file(s)>

 Display information from object <file(s)>.

 At least one of the following switches must be given:

  -a, --archive-headers    Display archive header information

  -f, --file-headers       Display the contents of the overall file header

  -p, --private-headers    Display object format specific file header contents

  -P, --private=OPT,OPT... Display object format specific contents

  -h, --[section-]headers  Display the contents of the section headers

  -x, --all-headers        Display the contents of all headers

  -d, --disassemble        Display assembler contents of executable sections

  -D, --disassemble-all    Display assembler contents of all sections

  -S, --source             Intermix source code with disassembly

  -s, --full-contents      Display the full contents of all sections requested

  -g, --debugging          Display debug information in object file

  -e, --debugging-tags     Display debug information using ctags style

  -G, --stabs              Display (in raw form) any STABS info in the file

  -W[lLiaprmfFsoRt] or

  --dwarf[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,

          =frames-interp,=str,=loc,=Ranges,=pubtypes,

          =gdb_index,=trace_info,=trace_abbrev,=trace_aranges]

                           Display DWARF info in the file

  -t, --syms               Display the contents of the symbol table(s)

  -T, --dynamic-syms       Display the contents of the dynamic symbol table

  -r, --reloc              Display the relocation entries in the file

  -R, --dynamic-reloc      Display the dynamic relocation entries in the file

  @<file>                  Read options from <file>

  -v, --version            Display this program's version number

  -i, --info               List object formats and architectures supported

  -H, --help               Display this information


 The following switches are optional:

  -b, --target=BFDNAME           Specify the target object format as BFDNAME

  -m, --architecture=MACHINE     Specify the target architecture as MACHINE

  -j, --section=NAME             Only display information for section NAME

  -M, --disassembler-options=OPT Pass text OPT on to the disassembler

  -EB --endian=big               Assume big endian format when disassembling

  -EL --endian=little            Assume little endian format when disassembling

      --file-start-context       Include context from start of file (with -S)

  -I, --include=DIR              Add DIR to search list for source files

  -l, --line-numbers             Include line numbers and filenames in output

  -F, --file-offsets             Include file offsets when displaying information

  -C, --demangle[=STYLE]         Decode mangled/processed symbol names

                                  The STYLE, if specified, can be `auto', `gnu',

                                  `lucid', `arm', `hp', `edg', `gnu-v3', `java'

                                  or `gnat'

  -w, --wide                     Format output for more than 80 columns

  -z, --disassemble-zeroes       Do not skip blocks of zeroes when disassembling

      --start-address=ADDR       Only process data whose address is >= ADDR

      --stop-address=ADDR        Only process data whose address is <= ADDR

      --prefix-addresses         Print complete address alongside disassembly

      --[no-]show-raw-insn       Display hex alongside symbolic disassembly

      --insn-width=WIDTH         Display WIDTH bytes on a single line for -d

      --adjust-vma=OFFSET        Add OFFSET to all displayed section addresses

      --special-syms             Include special symbols in symbol dumps

      --prefix=PREFIX            Add PREFIX to absolute paths for -S

      --prefix-strip=LEVEL       Strip initial directory names for -S

      --dwarf-depth=N        Do not display DIEs at depth N or greater

      --dwarf-start=N        Display DIEs starting with N, at the same depth

                             or deeper



'시스템 > 리눅스 기본' 카테고리의 다른 글

glibc 소스코드  (0) 2016.12.27
백그라운드 실행 명령어  (0) 2016.10.20
라이브러리 참조순서  (0) 2016.10.15
알아두면 좋은 명령어 모음  (0) 2016.10.13
gdb layout  (0) 2016.10.13

https://www.exploit-db.com/exploits/25497/ 


IPADDR이랑

PORT정의해서 쓰면됨

'시스템 > 시스템 해킹' 카테고리의 다른 글

gdb peda 설치방법  (0) 2016.11.21
tip 정리  (0) 2016.11.18
버퍼오버플로우 문서  (0) 2016.10.13
환경변수에 쉘코드 넣기(에그쉘 정리)  (0) 2016.10.12
ROP exploit  (0) 2016.09.29

DYNAMIC_SECTION의 NEED가 설정된 라이브러리

LD_LIBRARY_PATH

/etc/ld.so.conf(동적로더 공유라이브러리를 로드하고 참조함수 확인)

/lib, /usr/lib와 같은 표준 라이브러리 경로


따라서 LD_LIBRARY_PATH를 이용해서 표준 라이브러리 함수들을 후킹할 수 있음



<혹시 궁금한 사람을 위한 참고(내가 헷갈렸음)>

헤더와 라이브러리

1. 라이브러리와 헤더는 엄연히 다릅니다. 라이브러리는 기계어로 번역된 바이너리이며, 헤더는 컴파일러가 컴파일하기전.. 그러니까 프로그래머가 알아먹을 수 있고 c/c++의 문법에 맞게 작성되어있는 선언들의 집합입니다.

라이브러리를 사용하기 위해서는 해당 라이브러리의 헤더파일이 있어야합니다. 그래야지만 링커가 알아먹을수 있는 심볼네임을 컴파일러가 만들어내기 때문입니다.

컴파일러가 이런 헤더파일을 가지고 심볼네임을 만들어서 오브젝트 파일에 넣어주면 링커가 해당 심볼네임을 가지고 라이브러리를 뒤져서 링크를 하게 됩니다.

헤더가 여러개 모이는게 라이브러리가 아닙니다. 라이브러리는 컴파일된 바이너리이므로 소스파일의 컴파일된 산물인 오브젝트(리눅스의 경우에는 .o , 윈도우의 경우에는 .obj)파일을 여러개 모아놓은게 라이브러리입니다.

라이브러리의 확장자는 리눅스의 경우에는 .a, 윈도우의 경우에는 .lib입니다.

2. 제가 리눅스를 많이 안써봐서 말씀하신 위치 이외에 라이브러리와 헤더가 들어가는지는 모르겠습니다. (물론 나열하신 위치 말고도 다른 위치를 컴파일러 옵션으로 지정이 가능합니다.)
다만 나열하신 위치에 들어있는 파일들이 라이브러리와 헤더들입니다..

3. visual c보다는 visual c++이라고 하셔야 맞을거 같습니다.. 물론 6.0, .net 2003 .net 2003, .net2005과 같이 여러버전이 존재합니다.

4. 일반적으로 표준 c라이브러리는 대부분의 c컴파일러가 지원합니다. 표준 함수를 알고 계시면 대부분의 컴파일러에서 동일하게 소스를 바꾸지 않고 컴파일이 가능합니다.

5. 컴파일러와 라이브러리는 별개입니다. 컴파일러를 설치하면 들어있는 표준 c라이브러리도 사실 없어도 프로그램이 컴파일되는데는 문제가 없습니다. 대신 직접 모든걸 다 해줘야하는게 문제입니다. c언어의 시작 함수가 main이지만 실제로는 이 main함수를 호출하기전에 해주는 것이 많습니다. 그런걸 직접 일일이 만들어줘야하는 것이죠..

그리고 라이브러리는 c표준 라이브러리 뿐만 아니라 누구든지 라이브러리로 구성하면 그게 다 라이브러리입니다.

https://kldp.org/node/84138


*깨알 팁 : 라이브러리 주소는 어떤 바이너리든 동일하다고 한다

'시스템 > 리눅스 기본' 카테고리의 다른 글

백그라운드 실행 명령어  (0) 2016.10.20
objdump 사용법  (0) 2016.10.18
알아두면 좋은 명령어 모음  (0) 2016.10.13
gdb layout  (0) 2016.10.13
find 명령어 정리  (0) 2016.09.30

strace -fi

eip추적


ltrace -fi

라이브러리 추적


xxd 


x/100s 0x0804800

문자열 찾기 쉬움!!

GNU 위치 0x08048174


메모리 맵

pid 보는법

gdb 돌린다음 info proc


gdb 에서 shell 치면 shell명령어 쓸수 있음

cat /proc/[pid]/maps

cat/proc/self/maps하면 지금 돌아가고 있는 맵스 볼 수 있음


bt

gdb디버깅중 프로그램이 죽었을 때 죽은 위치의 스택확인


ps -aux

실행중인 프로세스 목록


ldd 파일이름

프로그램실행시 로드되는 라이브러리 이름


plt주소 구하는법

그냥 어셈코드 보면됨

 


readelf -S

영역 주소



gcc -m32

32비트로 컴파일


strcpy("안쓰는 주소","/bin/sh")                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           proc [pid]

libc 베이스 주소                                                                                                                                                                                                                                                                                                                                                                                                             

python -c 'import sys; standout.~~                                                                                                                                                                                                                                                                                                                                                           maps -> libc basic add구할수 있음    ->계산해서 offset구하기 libcstart-libc시작주소=libc basic add

system offset - start offset 구해서 basic add에 더하면 system주소구할수 있음

system offset=                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    

return에 안쓰는주소(/bin/sh)덮어쓰기


gdb 에서 파이썬 인풋


r < <(python )



프로세스 서버 올리는 명령어(xinetd안될떄)


socat TCP-LISTEN:9999,reuseaddr,fork,bind=0.0.0.0 EXEC:"/home/rootbutcute/asdfas"


flush buffer

sudo socat TCP-LISTEN:7777,reuseaddr,fork,bind=0.0.0 exec:"stdbuf -i0 -o0 -e0 ./breakout"


socat TCP-LISTEN:7777,reuseaddr,fork,bind=0.0.0.0 exec:"./breakout",pty,ctty,echo=0 



pop ret gadget찾을때


objdump -d (파일명) | grep -03 "ret"


<gadget찾기>


ROPgadget --binary (파일) -ropchain


<gadget string찾기>

ROPgadget --binary (파일 ) --string (문자)



자식프로세스를 디버깅

set follow-fork-mode child


0<&(fd)

fd에서 stdin으로 입력을 받음

1>&(fd)

출력을 fd로 전달


system('/bin/sh 0<&(fd) 1>&(fd)')하면

서버에서 쉘을 띄웠을때 stdin stdout에 입출력이 가능하다!!



<gdb reg eip 편하게 보기>

gdb -tui -q 


layout asm

layout regs


끄기:

ctrl + x a



checksec 

메모리 보호기법 뭐 걸려있는지 보여줌



aslr끄기
sudo sysctl -w 'kernel.randomize_va_space=0'

python -c 'import sys; sys.stdout.write("a"*28+"b")'

-> 입력넣을때 \x0a안들어감

스크립트 > a
해놓고
gdb 에서 r < a

find /bin/sh libc
peda에서 하면 /ㅠbin/sh위치 찾아줌

set disable-randomization off
실함수 랜덤 설정
gdb에서


fsb에서 출력이 많으면 ./aa > /dev/null
쉘딴 후에는 flag를 다른 파일로 저장해서 chmod로 권한을 내려준다음 나와서 보면됨

scp로 파일 옮기기
파일 가져올때 
scp -P2222 asm@pwnable.kr:/home/asm/asm /


/bin/sh 오프셋 쉽게찾는법..
strings -tx /lib32/libc.so.6 | grep "/bin/sh"

gdb에서 hex edit하는법
set {int}0x8049838=0xe8e58955

gdb find -> 
0x12345678->0x41414141일떄
 find 0x41414141하면
 0x12345678을 보여준다

watch -> gdb hw bp


'시스템 > 리눅스 기본' 카테고리의 다른 글

objdump 사용법  (0) 2016.10.18
라이브러리 참조순서  (0) 2016.10.15
gdb layout  (0) 2016.10.13
find 명령어 정리  (0) 2016.09.30
shellcode  (0) 2016.09.20

stack smashing for fun and profit


버퍼오버플로우의 조상격 문서

'시스템 > 시스템 해킹' 카테고리의 다른 글

tip 정리  (0) 2016.11.18
bind shellcode 소스코드  (0) 2016.10.16
환경변수에 쉘코드 넣기(에그쉘 정리)  (0) 2016.10.12
ROP exploit  (0) 2016.09.29
기본 쉘코드  (0) 2016.07.14


gdb -tui

보기 되게 편한 것 같다


layout reg

layout asm



'시스템 > 리눅스 기본' 카테고리의 다른 글

라이브러리 참조순서  (0) 2016.10.15
알아두면 좋은 명령어 모음  (0) 2016.10.13
find 명령어 정리  (0) 2016.09.30
shellcode  (0) 2016.09.20
gdb사용법/ 명령어  (0) 2016.06.24

+ Recent posts