본문 바로가기

reversing/rootkit

rootkit - root [2]

SMALL

root 권한을 만들면서 찾아봤던 이론 내용을 정리하려고 함.


linux 상에서 namespaces 개념과 관련된 user_namespace , 권핰 코드 관련 내용을 이해하는데 목표가 있음


namespace 개념

c++에서도 namespace라는 개념이 나왔던것 같다.

그때의 개념과 linux 상에서의 개념이 비슷한 맥락을 가지는 느낌이다.

네임스페이스(namespace)'란 녀석으로 이름충돌을 미연에 방지할 수 있게 하는 역할을 했었다. 

네임스페이스를 간단히 말하면, 관련있는 녀석끼리 모여있는 공간을 말한다.

간단하게 설명하면 독립적?인 공간, 영역으로 구분하고 관리하는 개념이다.


그리고 리눅스 메뉴얼에서 namspace를 검색해보면 다음과 같이 나온다.

 A  namespace  wraps  a  global  system  resource  in  an  abstraction that makes it appear to the processes within the 

namespace that they have their own isolated instance of the global resource.  

Changes to the global resource are visible to other processes that are members of the namespace, but are invisible to other 

processes.  One use of namespaces is to  implement  containers.


간단하게 요약해보면 주요 자원을 인스턴스로 추상화해서 독립적인 역할을 하게 하는것이다.

그리고 해당 영역(namspace)에 존재하는 자원들은 내부에서의 변화를 알지만, 밖에서는 알지 못하게 한다고 하는 개념이다.


즉, A라는 나라에서 건물을 지어도, 다른 나라에서는 알지 못하게 한다? 라는 느낌으로 이해하였다.

독립적인 공간에서 간섭을 불허한다!!..?


user_namespaces

linux 상의 여러 namespace(독립적인 공간) 중 하나인 user_namespaces에 관해서 알아보려 한다.

linux에서 제공하는 namespace은 아래와 같이 존재한다.

       IPC         CLONE_NEWIPC    System V IPC, POSIX message queues

       Network     CLONE_NEWNET    Network devices, stacks, ports, etc.

       Mount       CLONE_NEWNS     Mount points

       PID         CLONE_NEWPID    Process IDs

       User        CLONE_NEWUSER   User and group IDs

       UTS         CLONE_NEWUTS    Hostname and NIS domain name


저기서 User        CLONE_NEWUSER   User and group IDs 이 user_namespace이다.


메뉴얼에서 영어로 다음과 같이 설명하고 있다.


       User namespaces isolate security-related identifiers and attributes, in particular, user IDs and group IDs (see credentials(7)), 

 the root directory, keys (see keyrings(7)), and capabilities (see capabilities(7)). 

 A process's user and group IDs can be different inside and outside a user namespace.  

 In particular, a process can have a normal unprivileged user ID outside a user namespace while at the same time having a user

 ID of 0 inside the namespace; in other words, the process has full privileges for operations inside the user namespace, 

 but is unprivileged for operations outside the namespace.


간단히 요약하면 아래와 같은 내용이다.

보안과 관련된 식별자 예를들면 uid, gid, key와 관련된 속성들을 독립적으로 구성한게 user_namespace이다.

user_namespace에서 외부 여기서 외부는 user_namespace에 속하지 않는(다른 나라)에서 보는 uid와 gid는 내부 user_namespace에

속해서 보는 uid와 gid는 다르다는 개념이다.


그림으로 간략하게 이해하기 쉽게 그리면 다음과 같을것 같다.




현재의 권한을 확인하는 함수 래퍼


[퍼옴] - 출처_1

#define task_uid(task) (task_cred_xxx((task), uid))
#define task_euid(task) (task_cred_xxx((task), euid))

#define current_cred_xxx(xxx) \
({ \
current->cred->xxx; \
})

#define current_uid() (current_cred_xxx(uid))
#define current_gid() (current_cred_xxx(gid))
#define current_euid() (current_cred_xxx(euid))
#define current_egid() (current_cred_xxx(egid))
#define current_suid() (current_cred_xxx(suid))
#define current_sgid() (current_cred_xxx(sgid))
#define current_fsuid() (current_cred_xxx(fsuid))
#define current_fsgid() (current_cred_xxx(fsgid))
#define current_cap() (current_cred_xxx(cap_effective))
#define current_user() (current_cred_xxx(user))
#define current_user_ns() (current_cred_xxx(user)->user_ns)
#define current_security() (current_cred_xxx(security))


[출처_1] https://swbae98.wordpress.com/2011/04/27/task_struct-%EC%97%90-%EC%9E%88%EB%8D%98-uid-euid-%ED%95%84%EB%93%9C/

--> 간단하게 나와있음

LIST

'reversing > rootkit' 카테고리의 다른 글

rootkit - packet sniff[1]  (0) 2017.06.21
rootkit - packet sniff[0]  (0) 2017.06.21
rootkit - root [1]  (0) 2017.06.02
rootkit - vfs hooking [readdir,iterate]  (0) 2017.05.25
rootkit - 자료정리 task  (0) 2017.05.11