Download - Security Seminar

Transcript
Page 1: Security Seminar

Security SeminarSPARCS 10 wiki

Page 2: Security Seminar

Security for who?

Security for… Developers▪ Vulnerabilities in▪ In Web▪ In System

Administrators - Wheel 이 되세요 !▪ System-Level Settings▪ Log Analysis

Page 3: Security Seminar

Vulnerabilities

Web Vulnerabilities SQL Injection Cross-Site Scripting

System Vulnerabilities Stack Overflow Format String Bug Heap Overflow

Page 4: Security Seminar

SQL Injection

SQL Query 를 조작

select * from user where ‘id’=‘$id’ and ‘pw’=‘$pw’

유저의 id 와 pw 를 입력 받아서 user 라는 table 에서 가져오는 코드

select * from user where ‘id’=‘asdf’ and ‘pw’=‘1234’

Page 5: Security Seminar

SQL Injection

select * from user where ‘id’=‘$id’ and ‘pw’=‘$pw’

$pw = ‘or 1=1# 이라면 ?

Page 6: Security Seminar

SQL Injection

select * from user where ‘id’=‘asdf’ and ‘pw’=‘’ or 1=1#’

And 가 먼저 연산되고 or 가 연산되어서 where 문이 항상 true 가 됨

보통 첫 번째는 admin 계정

원하는 계정이 아니라면 ’ or 1=1 and id<>나온 id#

Page 7: Security Seminar

SQL Injection

Select 1 union select 3 -> 1 3

Union 은 두 쿼리의 결과값을 합쳐준다 .

Page 8: Security Seminar

SQL Injection

If(mysql_query(select key from users where id=‘$id’ and password=‘$pw’) == ‘hello’)

$pw = ‘ union select hello#

원하는 Query 결과를 만들 수 있다 .

Page 9: Security Seminar

Solution

입력 데이터 필터링 Quotes ‘ Select Union 주석

SQL-Injection 을 미리 방지한 Library 사용

Page 10: Security Seminar

Cross-Site Scripting

스크립트 삽입이 가능했을때 발생

스크립트로 특정 페이지를 강제로 open시켜 쿠키값을 빼낸다

<img src=“” onload=“”> 등 여러 편법이 가능

Page 11: Security Seminar

Stack Overflow

Stack overflow

가장 기초적인 System Hacking 방법

Buffer Checking 을 하지 않는 프로그램 이용

Page 12: Security Seminar

Setuid bit

rwx 권한과 별개로 , 프로그램 실행 도중에 작용하는 권한을 바꿀 수 있다

Setuid 비트가 되면 그 실행 프로그램의 소유자의 권한으로 작동할 수 있음

$find / -perm -4000 2>/dev/null

Page 13: Security Seminar

Buffer Overflow

Buffer 의 크기 검사를 안하고 값을 쓸 때 발생

Setuid 비트가 걸려있는 프로그램을 공격

Page 14: Security Seminar

Stack Structure

Page 15: Security Seminar

Vulnerable Functions

Strcpy(src,dest)

Src 의 값을 dest 에 덮는데 , 크기 검사를 안함

Return addr 까지 덮일 수 있음

Page 16: Security Seminar

Stack Overflow

Local Variable 에 Shellcode 의 Op-code 를 저장

Shellcode 가 들어있는 Local Variable 의 Address 로 Return Addr 를 Overwrite

환경변수에 넣으면 더 쉽게 할 수 있음

Page 17: Security Seminar

Solution

Plan A 프로그램을 잘 짜자 -_-;

ASLR Address space layout randomization Offset 이 랜덤으로 정해지기 때문에 Exploit 이

매우 힘듬 Non-executable Stack

스택 영역의 실행이 불가

Page 18: Security Seminar

Format String Bug

Printf(“1234%n”,&i);

i 에 지금까지 String 의 길이 , 4 가 저장됨

이를 이용해 원하는 곳에 원하는 데이터를 덮어씌우기가 가능

Page 19: Security Seminar

Vulnerable Code

Printf(argv[1]);

Str 에 format string 을 넣으면 format string 이 실행됨

Payload Example \x5c\xf9\xff\xbfAAAA\x5d\xf9\xff\xbf-

BBBB\x5e\xf9\xff\xbfCCCC\x5f\xf9\xff\xbf%c%c%c%c%128c%n%230c%n%126c%n%4c%n

Page 20: Security Seminar

Solution

Printf(str) -> printf(“%s”,str)

Page 21: Security Seminar

Programmer’s Perspec-tive

사용자의 input 을 믿지 말자 악의적인 input 에 대한 체크 귀찮다고 넘어가기 없음 !

권한이 걸린 프로그램은 특별히 신경쓰기

미리 Safe 하다고 검증된 Library 등을 쓰면 훨씬 편하다

Page 22: Security Seminar

Questions?

[email protected]


Top Related