Installing wmic in Ubuntu 14.04 (LTS) 64-Bit

Exectuing wmic command

Thanks to some great responses in a previous article I decided to create an updated post for Ubuntu 14.04 since it is the incumbent LTS release at this time (September ’14).

Step 1 – Install autoconf which is used in the compilation process

sudo apt-get install autoconf

Step 2 – Download the ‘wmic’ source (I will work in my ‘Downloads’ directory)

cd ~/Downloads
wget http://www.openvas.org/download/wmi/wmi-1.3.14.tar.bz2

Step 3 – Untar the source

tar -xvf wmi-1.3.14.tar.bz2

Step 4 – Go into the directory and add a line of text to the top of ‘GNUmakefile’

#Go into the directory where the files were untarred to
cd wmi-1.4.14/ #or whatever version you installed
 
#Edit 'GNUmakefile' and add the following at the top (just after the License Info)
ZENHOME=../..

Step 5 – Compile (this part changed from the previous article)

sudo make "CPP=gcc -E -ffreestanding"
 
#Now grab a magazine or something - this can take a few minutes
 
#After a while you 'might' get something like this - I did
.....
cp: target `../../lib/python' is not a directory
make: *** [pywmi-installed] Error 1
 
#wmic is already compiled and usable at this stage so it's not an issue. Proceed to Step 6

Step 6 – Test wmic

#In the ~/Downloads/wmi-1.3.14/ directory you will find a file named 'bin'. Create a copy of this file and name it wmic
cp bin wmic
 
#Test it 
#./wmic -U[user]%[password] //[host/ip] "[WMI Query]"
./wmic -Utestuser%tstpass //172.16.2.2 "SELECT * FROM Win32_OperatingSystem"
 
#Output should be similar to this:
CLASS: Win32_OperatingSystem
BootDevice|BuildNumber|BuildType|Caption|CodeSet|CountryCode|CreationClassName|CSCreationClassName|CSDVersion|CSName|CurrentTimeZone|Debug|Description|Distributed|EncryptionLevel|ForegroundApplicationBoost|FreePhysicalMemory|FreeSpaceInPagingFiles|FreeVirtualMemory|InstallDate|LargeSystemCache|LastBootUpTime|LocalDateTime|Locale|Manufacturer|MaxNumberOfProcesses|MaxProcessMemorySize|Name|NumberOfLicensedUsers|NumberOfProcesses|NumberOfUsers|Organization|OSLanguage|OSProductSuite|OSType|OtherTypeDescription|PAEEnabled|PlusProductID|PlusVersionNumber|Primary|ProductType|QuantumLength|QuantumType|RegisteredUser|SerialNumber|ServicePackMajorVersion|ServicePackMinorVersion|SizeStoredInPagingFiles|Status|SuiteMask|SystemDevice|SystemDirectory|SystemDrive|TotalSwapSpaceSize|TotalVirtualMemorySize|TotalVisibleMemorySize|Version|WindowsDirectory
\Device\HarddiskVolume1|3790|Uniprocessor Free|Microsoft(R) Windows(R) Server 2003, Enterprise Edition|1252|1|Win32_OperatingSystem|Win32_ComputerSystem||WIN2003-VM-HS|120|False||False|168|2|779280|2348260|3127540|20121101081525.000000+120|1|20121101090258.411875+120|20121105103817.505000+120|0409|Microsoft Corporation|4294967295|2097024|Microsoft Windows Server 2003 Enterprise Edition|C:\WINDOWS|\Device\Harddisk0\Partition1|5|46|4|Sintrex Integration Services (Pty) Ltd|1033|274|18|(null)|False|(null)|(null)|True|3|0|0|Test User|69763-011-6394922-43753|0|0|2527020|OK|274|\Device\HarddiskVolume1|C:\WINDOWS\system32|C:|0|3575072|1048052|5.2.3790|C:\WINDOWS

Step 7 – Copy wmic to /usr/bin so you can use it from anywhere

 
sudo cp wmic /usr/bin/

That’s it, it should work now from anywhere.

Leave a Reply to Chandresh Prakash Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Comments

  1. nesfree

    Many thanks!

    Reply
  2. You can earn some additional money from your website, i
    see several opportunities here. You should search in google
    for:
    Yoogurn’s money making

    Reply
  3. Chandresh Prakash

    You may want to add a few lines about patching wmi:
    patch -p1 < ~/Downloads/openvas-wmi-1.3.14.patch
    patch -p1 < ~/Downloads/openvas-wmi-1.3.14.patch2
    patch -p1 < ~/Downloads/openvas-wmi-1.3.14.patch3v2
    patch -p1 < ~/Downloads/openvas-wmi-1.3.14.patch4
    patch -p1 < ~/Downloads/openvas-wmi-1.3.14.patch5

    Reply
  4. Chandresh Prakash

    Can also mention/correct:
    1. ZENHOME=../.. should be ZENHOME=
    2. Can create directory $ZENHOME/lib/python and $ZENHOME/bin directory.
    3. Test wmic & winexe in wmi-1.3.14/Samba/source/bin/

    Reply
    1. Chandresh Prakash

      It should be ZENHOME=$(HOME)

      Reply
      1. I can change this in the guide, but honestly, I just did this again on a 14.04 installation exactly as in the steps above and it works first time. So what is the correct way now?

        I think it depends from which directory you install this. If you install it from a 1 level down subdirectory of your $HOME directory, then it makes sense to leave it as per the guide:

        ZENHOME=../..

        If you are doing the install from somewhere else, an absolute path would be more correct and will be unique to your situation.

        EDIT: I did not have time to investigate this – it’s an assumption at best

        Reply
  5. Vee

    If you get the error Can’t use ‘defined(@array)’ (Maybe you should just omit the defined()?) at ./pidl/pidl line 583.
    (you are probably using Perl version 5.22+) then you need to edit line 583 of Samba/source//pidl/pidl and remove the “defined” from the start of the line (just like the error message says)

    Reply
    1. aaron

      If I do that I get the error message:
      Can’t use an undefined value as an ARRAY reference at ./pidl/pidl line 583.

      Reply
  6. timmy trussel

    Helpful article – I loved the points ! Does someone know if my assistant might get ahold of a blank Calendar copy to work with ?

    Reply
  7. ZENHOME=$(HOME)
    Edit the file /data/tools/wmi-1.3.14/Samba/source/pidl/pidl : remove the line number 583
    defined @$pidl || die “Failed to parse $idl_file”;
    Edit the file /data/tools/wmi-1.3.14/Samba/source/lib/tls/tls.c
    Line 508: replace gnutls_transport_set_lowat(tls->session, 0); by gnutls_record_check_pending(tls->session);
    Line 579: remove the line gnutls_certificate_type_set_priority(tls->session, cert_type_priority);
    Line 587: replace gnutls_transport_set_lowat(tls->session, 0); by gnutls_record_check_pending(tls->session);

    Reply
    1. Tx Loganathan,

      Just want to confirm, what will be the result of aforementioned changes?

      Reply