원격접속 설정
root로 접속이 안되는걸 풀어줘야한다
1) /etc/securetty
pts/0
pts/1
pst/2
pst/3
pst/4
pst/5
pst/6
2) PAM: /etc/pam.d/login
- 2번째 라인을 주석으로 처리
-#auth required /lib/security/pam_securetty
수업시간에 사용하는 도구
- C컴파일러 - GCC(GNU C Compiler)
- 어셈블러 : GAS( GNU Assembler): AT&T 문법을 지원
NASM(NETwired Assembler): Intel 문법을 지원
- 디버거 : GDB( GNU DeBugger) : 바이너리 분석도구
NASM 설치
#>wget http://www.nasm.us/pub/nasm/releasebuilds/0.99.05/nasm-0.99.05.tar.gz
#>tar xvfz nasm-0.99.05.tar.gz
#>cd nasm-0.99.05
#>./configure
#>make
#> make install
#>cp nasm /usr/bin/
! C 컴파일
-window: visual studio, eclips,...
-IDE: 개발환경(컴파일러+ 편집기+디버거+....)
- 컴파일러 : GCC, 편집기: vi 디버거 :GDB
-C로 hello world 짜서 출력해보기
-소스 코드 짜기
#>vi hello.c
-GCC로 컴파일 하기
저렇게 실행파일이 생깁니다
실행파일 이름을 지정을 안해서 default로 a.out이 생깁니다
gcc -o 옵션을 쓰면 설정한 이름으로 파일이 생깁니다
#>gcc -o hello hello.c
원래 있는 파일이면 덮어씁니다.
-실행파일로 실행하기
전처리 과정
/usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/cpp (c++이 아닙니다)
-lang-c -v -undef -D__GNUC__=2 -D__GNUC_MINOR__=91 -D__ELF__ -Dunix -Di386 -D__i386__ -Dlinux -D__ELF__ -D__unix__ -D__i386__ -D__i386__ -D__linux__ -D__unix -D__i386 -D__linux -Asystem(posix) -Asystem(unix) -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -D__tune_i386__ h ello.c /tmp/cc6bcPLj.i
#include로 헤더파일을 들고옵니다
지시문 같은거 처리 (Define이나 매크로)
컴파일러
/usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/cc1 hello.i -quiet -dumpbase hello.c -version -o hello.s
GNU C version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) (i386-redhat-linux) compiled by GNU C version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release).
as -V -Qy -o hello.o hello.s
어셈블리어 형태로 바꿉니다
어셈블러
오브젝트 파일을 만듭니다.
링커
실행프로그램과 다른 라이브러리들 과 링킹을 합니다
1.전처리 과정 cpp
/usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/cpp (c++이 아닙니다)
-lang-c -v -undef -D__GNUC__=2 -D__GNUC_MINOR__=91 -D__ELF__ -Dunix -Di386 -D__i386__ -Dlinux -D__ELF__ -D__unix__ -D__i386__ -D__i386__ -D__linux__ -D__unix -D__i386 -D__linux -Asystem(posix) -Asystem(unix) -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -D__tune_i386__ hello.c hello.o
이 파일들은 임시파일이라 컴파일이 끝나면 삭제 됩니다
하지만 임시파일들을 삭제하지 않고 그냥 둬보도록 하겠습니다
#>gcc -save-temps 옵션을 쓰면됩니다
include 문으로 전처리 하는것은 복잡하므로 define문으로 바꿔서 보겠습니다
이렇게 소스코드를 바꾸고 실행해보겠습니다
전처리에서 define 해놓았던 MAX가 10000으로 치환되었음을 볼 수 있습니다
2. 컴파일 과정 : cc1
/usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/cc1 hello.i -quiet -dumpbase hello.c -version -o hello.s
GNU C version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) (i386-redhat-linux) compiled by GNU C version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release).
as -V -Qy -o hello.o hello.s
이렇게 어셈블리어로 바꿔줍니다
여기서 에러가 나게 되면 우리가 아는 컴파일 에러라고 합니다
어셈블러 과정: as
as -V -Qy -o hello.o hello.s
여기서부터는 text 파일이 아닌 바이너리 파일로 됩니다
링킹 과정: ld, collect?2
/usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/collect2 -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o hello /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/crtbegin.o -L/usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66 -L/usr/i386-redhat-linux/lib hello.o -lgcc -lc -lgcc /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/crtend.o /usr/lib/crtn.o
'Security > System' 카테고리의 다른 글
[SYSTEM SECURITY]6.어셈블리 (scanf) (0) | 2017.10.19 |
---|---|
[SYSTEM SECURITY]5.어셈블리 (사칙연산) (0) | 2017.10.18 |
[SYSTEM SECURITY]4. 어셈블리 명령어(mov , lea) (0) | 2017.10.17 |
[SYSTEM SECURITY]3. 어셈블리 코드 분석 및 레지스터 (0) | 2017.10.16 |
[SYSTEM SECURITY]2. 실행파일 구조 및 메모리 (0) | 2017.10.13 |