Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming for the java Virtual machine

Similar presentations


Presentation on theme: "Programming for the java Virtual machine"— Presentation transcript:

1 Programming for the java Virtual machine
15. 보안과 자바 가상 머신 ps lab 김윤경

2 목차 1. 보안 구조와 보안 정책 1-1.기본적인 애플릿 보안정책 1-2. 세밀한 보안 정책 1-3. 잠재적 공격의 가능성

3 1. 보안 구조와 보안 정책 SecurityManager 클래스 ->SecurityException발생
어떠한 코드가 어떠한 동작을 할 수 있는 권한이 있는지 판별하는 클래스 잠재적으로 위험한 동작을 하기 전에 해당메소드를 호출하여 금지된 동작인지 검사 ->SecurityException발생 Ex) 표15.1참고(p.476)

4 예제 public FileInputStream (String filename) throws FileNotFoundException { SecurityManager security=System.getSecurityManager(); if(security !=null) security.checkRead(filename); //해당 파일을 읽을 권한이 없을 경우, SecurityException발생 //파일을 읽을 권한이 있을 경우, FileInputStream객체 생성후 read()메소드호출하여 해당파일을 읽음 }

5 1-1.기본적인 애플릿 보안정책 Class클래스의 getClassLoader()
애플릿의 클래스가 어느 클래스로더를 통해서 로드되었는지 알 수 있음. Class 클래스는 final클래스이기 때문에 getClassLoader()는 오버라이드될 수 없음.

6 예제 : NastyApplet이 file을 읽기를 시도
<자바스택> 메소드 클래스 클래스로더 checkRead AppletSecurityManager none <init> FileInputStream attack NastyApplet AppletClassLoader run Class AppletSecurityManager extends SecurityManger { public void checkRead(String name) throws SecurityException{ ClassLoader loader=currentClassLoader(); if(loader instanceof AppletClassLoader throw new SecurityException(“file.read”); }

7 1-2. 세밀한 보안 정책 시스템프로퍼티를 이용 Ex) Acl.read를 /sandbox라고 설정한 경우 : 애플릿은 /sandbox 절대경로하에 있는 파일에만 접근가능 Digital signature : private key로 암호화 -> public key로 애플릿이 누구로부터 서명되었는지 확인

8 1-3. 잠재적 공격의 가능성 1) 보안 관리자에 대한 방어.
Java.lang.System클래스 : 오직 하나의 SecurityManager 인스턴스가 시스템에 보안 관리자로써 등록될 수 있으며, 한 번 등록이 되고 난 후에는 등록된 보안 관리자는 없앨 수 없다.

9 AppletSecurityManager asm=new AppletSecurityManager();
System.setSecurityManager(asm); package java.lang; public final class System{ private static SecurityManager security; public static setSecurityManager(SecurityManager sm){ If(security !=null) throw new SecurityException(“SecurityManager already set”); //securityManger가 이미 존재 한다면 exception발생 security=sm;}}

10 2) 자바 보안에 대한 우회 클래스 로더에서 클래스를 로딩할 때 resolveClass 메소드가 실행되면서 검증이 자동으로 일어남 System.security = null; //검증 알고리즘에서 private인 security필드에 접근할 수 없으므로 해당 클래스 로딩을 중지

11 3) 생성되지 않은 객체에 대한 사용 검증 알고리즘에서 각 생성자들이 슈퍼클래스의 생성자를 호출하도록 체크
class WimpySecurityManager extends SecurityManager { //보안을 체크하는데 사용되는 메소드를 오버라이드 하//고 오버라이드한 메소드에서는 아무런 일도 하지 않도//록 한다.} public class SecurityManager{ protected SecurityManager(){ if(System.getSecurityManager()!=null) throw new SecurityException(“security manager already installed.”); }}

12 4) 유효하지 않은 캐스팅 public class Message{ private PrivateKey private_key; }
public class SneakeyMessage{ public Privatekey private_key; void attack(Message m){ SneakyMessage hack=(SneakyMessage)m;//검증 알고리즘에서 거부

13 5) 클래스에 대한 참조바꾸기 Checkcast 검증 알고리즘에서 특정 객체를 특정 클래스로 간주할 수 있게 해준다.
프로그램이 수행되면서 자바 가상 머신에서 checkcast명령어를 만날 때 마다 스택 최상위 값의 실제 타입을 구함. => ClassCastException발생

14 .method attack(LMessage;)V
aload_1 ; 변수1에는 Message를 담고 있다. checkcast SneakyMessage ; 검증알고리즘에서 Message를 SneakyMessage라고 믿게 한다. Getfield SneakyMessage/private_key Ljava/security/PrivateKey;

15 6) 초기화되지 않은 필드에 대한 접근 어떤 필드를 명확하게 초기화하는 부분이 없을 때 : 숫자=0, 참조 필드=null로 초기화 Class : Connection Password : “foobar” Class : MyObject Field1 :

16 7) 배열 범위 체크 접근하려는 원소가 배열 경계안에 들어 있는지 판단함 = > ArrayIndexOutOfBoundsException발생 Class : Connection Password : “foobar”

17 8) 예외처리 시스템에 대한 유해한 작업을 할 때 발생하는 예외를 처리함으로써 예외무시
.class WimpySecurityManager .method <init>V .catch java/lang/SecurityException from begin to end using handler begin : aload_0 ; 수퍼클래스의 생성자 호출 invokevirtual java/lang/SecurityManager/<init>()V end : return handler : ; SecurityException이 발생하면 제어가 넘어온다. return ; SecurityManger 생성자의 호출이 완전하게 끝나지 않은 상태에서 반환 .end method

18 9) 숨겨진 코드 위치 값 의미 0050 11 sipush 0051 b3 Oxb300=-19712 0052 00 0053 74
ineg 0054 a7 goto 0055 ff Oxfffd=-3 0056 fd


Download ppt "Programming for the java Virtual machine"

Similar presentations


Ads by Google