35. Banzai (GET TO WORK) - Linux (mysql, sys_exec(), lib_mysqludf_sys)
1. Enumeration
: Port Scanning

: smtp user enum

> 도메인 확인

> 사용자 확인 후 user list로 등록

: ftp 계정 확인

: ftp 로그인 및 파일 업로드 테스트



> 업로드 가능함
2. Exploitation
: php shell 업로드

: 리스너 기동 후 호스팅 하면

침투 성공!
3. Privilege Escalation
: SUID

: creds

: sql 돌고 있는지 확인

: mysql 로그인 시도

> root로 로그인이 가능한 시점에서
공격 가능한 시나리오가 있는데
전에는 mariadb에 했었지만
mysql 역시 방법은 동일하다.
# 공격 방법 및 순서
- mysql 외부 파일 실행시키기 -
: UDF(User Define Function) 활용
> UDF lib_mysqludf_sys.so (리눅스이기 때문에, 윈도우는 dll)
파일 내 sys_exec() 함수를 활용해 os 커맨드를 실행시킨다.
1) mysql udf 파일을 하위 경로에서 받은 후 타깃 서버에 업로드
https://github.com/rapid7/metasploit-framework/tree/master/data/exploits/mysql
2) 타깃 서버 mysql에 접속한 뒤 임의의 db를 골라
lib_mysqludf_sys.so 파일을 mysql plugin 경로에
넣어주기
3) lib_mysqludf_sys.so 파일을 이용해
sys_exec() 함수 생성
4) sys_exec() 함수를 통해
os 커맨드 실행 (리버스 쉘)
# 실행
0) 프로세서 종류 확인

> 64bit
1) mysql udf 파일 업로드


2~3) 아무 database 선택 > 새로운 table 생성 >
새로운 table에 lib_mysqludf_sys_64.so 파일 insert >
새로운 table * 선택 후 mysql plugin 경로에 dump >
새로운 plugin에 sys_exec() 함수 생성

4) 시스템 명령어 실행 및 리버스 쉘 생성
: 핑 날려보면


> 정상 실행되고
: 리버스 쉘 요청
리스너 기동 후 리버스 쉘 생성 요청 시


끝