September 20, 2019
  • 6:30 pm Office 365 – Yksittäisten tai useiden käyttäjätilien luominen | Office 365 Admin Center & PowerShell
  • 10:09 pm Office 365 – Yhdistäminen tenanttiin PowerShellillä
  • 2:15 pm NameCheap – Kaupallisen SSL-sertifikaatin uusiminen
  • 9:48 pm Ubuntu Server 18.04.3 – Tietoturvapäivitysten automatisointi
  • 1:54 am Tuotantopalvelimen päivitys – Ubuntu Server 16.04 -> 18.04

Testasin töissä hiljaisella ajalla Chocolatey-paketinhallintaa Windowsilla.
Chocolatey on debianin apt-get paketinhallintaa vastaava vastine Windows-koneille. Tuki ei toki ole yhtä laajaa, kuin Linux puolella, mutta chocolateystä löytyy silti noin 5000 asennettavaa pakettia.
Asennus Powershellillä järjestelmänvalvojan oikeuksin:

Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

Tulos:

Getting latest version of the Chocolatey package for download.
Getting Chocolatey from https://chocolatey.org/api/v2/package/chocolatey/0.10.10.
Downloading 7-Zip commandline tool prior to extraction.
Extracting C:\Users\MARKUS~1.PYH\AppData\Local\Temp\chocolatey\chocInstall\chocolatey.zip to C:\Users\MARKUS~1.PYH\AppData\Local\Temp\chocolatey\chocInstall...
Installing chocolatey on this machine
Creating ChocolateyInstall as an environment variable (targeting 'Machine')
 Setting ChocolateyInstall to 'C:\ProgramData\chocolatey'
WARNING: It's very likely you will need to close and reopen your shell
 before you can use choco.
Restricting write permissions to Administrators
We are setting up the Chocolatey package repository.
The packages themselves go to 'C:\ProgramData\chocolatey\lib'
 (i.e. C:\ProgramData\chocolatey\lib\yourPackageName).
A shim file for the command line goes to 'C:\ProgramData\chocolatey\bin'
 and points to an executable in 'C:\ProgramData\chocolatey\lib\yourPackageName'.
Creating Chocolatey folders if they do not already exist.
WARNING: You can safely ignore errors related to missing log files when
 upgrading from a version of Chocolatey less than 0.9.9.
 'Batch file could not be found' is also safe to ignore.
 'The system cannot find the file specified' - also safe.
chocolatey.nupkg file not installed in lib.
 Attempting to locate it from bootstrapper.
PATH environment variable does not have C:\ProgramData\chocolatey\bin in it. Adding...
WARNING: Not setting tab completion: Profile file does not exist at
'C:\Users\markus.pyharanta\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1'.
Chocolatey (choco.exe) is now ready.
You can call choco from anywhere, command line or powershell by typing choco.
Run choco /? for a list of functions.
You may need to shut down and restart powershell and/or consoles
 first prior to using choco.
Ensuring chocolatey commands are on the path
Ensuring chocolatey.nupkg is in the lib folder

choco1
Varmistin, että tuli asennettua uusin versio kokeilemalla chocolatey-paketin päivitystä:

choco upgrade chocolatey

Tulos:

Chocolatey v0.10.10
Upgrading the following packages:
chocolatey
By upgrading you accept licenses for the packages.
chocolatey v0.10.10 is the latest version available based on your source(s).
Chocolatey upgraded 0/1 packages.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

Asentamani Chocolatey-versio oli jo uusin.
Testataas asentaa vaikka PuTTY:

choco install putty

Kun kysyttiin haluanko jatkaa asennusta, vastasin “y” eli yes.
Tulos:

Chocolatey v0.10.10
Installing the following packages:
putty
By installing you accept licenses for the packages.
Progress: Downloading putty.portable 0.70.0.20171219... 100%
Progress: Downloading putty 0.70.0.20171219... 100%
putty.portable v0.70.0.20171219 [Approved]
putty.portable package files install completed. Performing other installation steps.
The package putty.portable wants to run 'chocolateyInstall.ps1'.
Note: If you don't run this script, the installation will fail.
Note: To confirm automatically next time, use '-y' or consider:
choco feature enable -n allowGlobalConfirmation
Do you want to run the script?([Y]es/[N]o/[P]rint): y
Extracting 64-bit C:\ProgramData\chocolatey\lib\putty.portable\tools\putty_x64.zip to C:\ProgramData\chocolatey\lib\putty.portable\tools...
C:\ProgramData\chocolatey\lib\putty.portable\tools
 ShimGen has successfully created a gui shim for PAGEANT.EXE
 ShimGen has successfully created a shim for PLINK.EXE
 ShimGen has successfully created a shim for PSCP.EXE
 ShimGen has successfully created a shim for PSFTP.EXE
 ShimGen has successfully created a gui shim for PUTTY.EXE
 ShimGen has successfully created a gui shim for PUTTYGEN.EXE
 The install of putty.portable was successful.
 Software installed to 'C:\ProgramData\chocolatey\lib\putty.portable\tools'
putty v0.70.0.20171219 [Approved]
putty package files install completed. Performing other installation steps.
 The install of putty was successful.
 Software install location not explicitly set, could be in package or
 default install location if installer.
Chocolatey installed 2/2 packages.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
PS C:\WINDOWS\system32>

choco2
Lokeista voi halutessaan katsoa, mitä kaikkea tapahtui taustalla asennuksen aikana:
cat-komento toimii myös Powershellissä, sillä se on alias Powershellin Get-Content cmdlet:ille.

cat C:\ProgramData\chocolatey\logs\chocolatey.log | Select-String "putty"

Jouduin tarkistamaan, mikä oli grep:n vastine Powershellissä. Tämän yhteydessä tajusin, että Powershellissä voi asettaa cmdletille aliaksen:

New-Alias grep Select-String

Nyt voin käyttää grep-komentoa Select-Stringin sijasta. Kätevää:
EDIT: Tämä toimii vain nykyisessä sessiossa. Jos haluaa säilyttää aliaksen, niin se kannattaa tallentaa profiiliin. Profiiliin tallennetut komennot ajetaan aina Powershellin-käynnistyksen yhteydessä.

cd C:\Users\markus.pyharanta\Documents\WindowsPowerShell\
New-Item profile.ps1

profile.ps1 tiedoston sisään:

New-Alias grep Select-String
New-Alias nano notepad

rerere

PS C:\WINDOWS\system32> cat C:\ProgramData\chocolatey\logs\chocolatey.log | grep "putty"

Kun yritin etsiä PuTTyä koneelta, huomasin, että chocolatey ei asenna ohjelmia oletuksena ProgramFiles-hakemistojen alle, vaan sijaintiin:

C:\ProgramData\chocolatey\

Suurin osa ohjelmista menee \bin\ alle, mutta osa löytyy myös \lib\.
Tämä on varmaankin tietoturvasyistä, eikä se oikeastaan minua haittaa. Komentoon voi sisällyttää “–install-directory=value”, jossa arvoksi laitetaan se sijainti, johon ohjelman halutaan asentuvan. Esimerkiksi:

choco install putty --install-directory 'C:\Program Files\'

EDIT: Asentaessani Wiresharkin huomasin, että se kyllä asentui ProgramFiles-hakemiston alle. Näyttäisi siis siltä, että asennussijainti on hyvin ohjelmakohtaista.

C:\Program Files\Wireshark

Wireshark vaatii toimiakseen WinPcap, joten asensin molemmat samassa komennossa:

choco install -y wincap wireshark

Tulos:

PS C:\WINDOWS\system32> choco install -y winpcap wireshark
Chocolatey v0.10.10
Installing the following packages:
winpcap;wireshark
By installing you accept licenses for the packages.
Progress: Downloading WinPcap 4.1.3.20161116... 100%
WinPcap v4.1.3.20161116 [Approved]
winpcap package files install completed. Performing other installation steps.
Downloading WinPcap
 from 'https://www.winpcap.org/install/bin/WinPcap_4_1_3.exe'
Progress: 100% - Completed download of C:\Users\markus.pyharanta\AppData\Local\Temp\chocolatey\WinPcap\4.1.3.20161116\WinPcapInstall.exe (893.68 KB).
Download of WinPcapInstall.exe (893.68 KB) completed.
Hashes match.
C:\Users\markus.pyharanta\AppData\Local\Temp\chocolatey\WinPcap\4.1.3.20161116\WinPcapInstall.exe
Running Autohotkey installer
 The install of winpcap was successful.
 Software install location not explicitly set, could be in package or
 default install location if installer.
Progress: Downloading wireshark 2.4.5... 100%
wireshark v2.4.5 [Approved]
wireshark package files install completed. Performing other installation steps.
Downloading WireShark 64 bit
 from 'https://1.na.dl.wireshark.org/win64/Wireshark-win64-2.4.5.exe'
Progress: 100% - Completed download of C:\Users\markus.pyharanta\AppData\Local\Temp\chocolatey\wireshark\2.4.5\Wireshark-win64-2.4.5.exe (55.23 MB).
Download of Wireshark-win64-2.4.5.exe (55.23 MB) completed.
Hashes match.
Installing WireShark...
WireShark has been installed.
 wireshark may be able to be automatically uninstalled.
 The install of wireshark was successful.
 Software installed to 'C:\Program Files\Wireshark'
Chocolatey installed 2/2 packages.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

Asennus meni läpi ilman ongelmia.
Asensin lisäksi sysinternals-työkalut.

choco install -y sysinternals

Tulos:

PS C:\WINDOWS\system32> choco install -y sysinternals
Chocolatey v0.10.10
Installing the following packages:
sysinternals
By installing you accept licenses for the packages.
Progress: Downloading sysinternals 2018.2.13... 100%
sysinternals v2018.2.13 [Approved]
sysinternals package files install completed. Performing other installation steps.
Sysinternals Suite is going to be installed in 'C:\ProgramData\chocolatey\lib\sysinternals\tools'
Downloading sysinternals
 from 'https://download.sysinternals.com/files/SysinternalsSuite.zip'
Progress: 100% - Completed download of C:\Users\markus.pyharanta\AppData\Local\Temp\chocolatey\sysinternals\2018.2.13\SysinternalsSuite.zip (23.94 MB).
Download of SysinternalsSuite.zip (23.94 MB) completed.
Hashes match.
Extracting C:\Users\markus.pyharanta\AppData\Local\Temp\chocolatey\sysinternals\2018.2.13\SysinternalsSuite.zip to C:\ProgramData\chocolatey\lib\sysinternals\tools...
C:\ProgramData\chocolatey\lib\sysinternals\tools
 ShimGen has successfully created a shim for accesschk.exe
 ShimGen has successfully created a shim for accesschk64.exe
 ShimGen has successfully created a shim for AccessEnum.exe
 ShimGen has successfully created a shim for ADExplorer.exe
 ShimGen has successfully created a shim for ADInsight.exe
 ShimGen has successfully created a shim for adrestore.exe
 ShimGen has successfully created a shim for Autologon.exe
 ShimGen has successfully created a shim for Autoruns.exe
 ShimGen has successfully created a shim for Autoruns64.exe
 ShimGen has successfully created a shim for autorunsc.exe
 ShimGen has successfully created a shim for autorunsc64.exe
 ShimGen has successfully created a shim for Bginfo.exe
 ShimGen has successfully created a shim for Bginfo64.exe
 ShimGen has successfully created a shim for Cacheset.exe
 ShimGen has successfully created a shim for Clockres.exe
 ShimGen has successfully created a shim for Clockres64.exe
 ShimGen has successfully created a shim for Contig.exe
 ShimGen has successfully created a shim for Contig64.exe
 ShimGen has successfully created a shim for Coreinfo.exe
 ShimGen has successfully created a shim for ctrl2cap.exe
 ShimGen has successfully created a shim for Dbgview.exe
 ShimGen has successfully created a shim for Desktops.exe
 ShimGen has successfully created a shim for disk2vhd.exe
 ShimGen has successfully created a shim for diskext.exe
 ShimGen has successfully created a shim for diskext64.exe
 ShimGen has successfully created a shim for Diskmon.exe
 ShimGen has successfully created a shim for DiskView.exe
 ShimGen has successfully created a shim for du.exe
 ShimGen has successfully created a shim for du64.exe
 ShimGen has successfully created a shim for efsdump.exe
 ShimGen has successfully created a shim for FindLinks.exe
 ShimGen has successfully created a shim for FindLinks64.exe
 ShimGen has successfully created a shim for handle.exe
 ShimGen has successfully created a shim for handle64.exe
 ShimGen has successfully created a shim for hex2dec.exe
 ShimGen has successfully created a shim for hex2dec64.exe
 ShimGen has successfully created a shim for junction.exe
 ShimGen has successfully created a shim for junction64.exe
 ShimGen has successfully created a shim for ldmdump.exe
 ShimGen has successfully created a shim for Listdlls.exe
 ShimGen has successfully created a shim for Listdlls64.exe
 ShimGen has successfully created a shim for livekd.exe
 ShimGen has successfully created a shim for livekd64.exe
 ShimGen has successfully created a shim for LoadOrd.exe
 ShimGen has successfully created a shim for LoadOrd64.exe
 ShimGen has successfully created a shim for LoadOrdC.exe
 ShimGen has successfully created a shim for LoadOrdC64.exe
 ShimGen has successfully created a shim for logonsessions.exe
 ShimGen has successfully created a shim for logonsessions64.exe
 ShimGen has successfully created a shim for movefile.exe
 ShimGen has successfully created a shim for movefile64.exe
 ShimGen has successfully created a shim for notmyfault.exe
 ShimGen has successfully created a shim for notmyfault64.exe
 ShimGen has successfully created a shim for notmyfaultc.exe
 ShimGen has successfully created a shim for notmyfaultc64.exe
 ShimGen has successfully created a shim for ntfsinfo.exe
 ShimGen has successfully created a shim for ntfsinfo64.exe
 ShimGen has successfully created a shim for pagedfrg.exe
 ShimGen has successfully created a shim for pendmoves.exe
 ShimGen has successfully created a shim for pendmoves64.exe
 ShimGen has successfully created a shim for pipelist.exe
 ShimGen has successfully created a shim for pipelist64.exe
 ShimGen has successfully created a shim for portmon.exe
 ShimGen has successfully created a shim for procdump.exe
 ShimGen has successfully created a shim for procdump64.exe
 ShimGen has successfully created a shim for procexp.exe
 ShimGen has successfully created a shim for procexp64.exe
 ShimGen has successfully created a shim for Procmon.exe
 ShimGen has successfully created a shim for PsExec.exe
 ShimGen has successfully created a shim for PsExec64.exe
 ShimGen has successfully created a shim for psfile.exe
 ShimGen has successfully created a shim for psfile64.exe
 ShimGen has successfully created a shim for PsGetsid.exe
 ShimGen has successfully created a shim for PsGetsid64.exe
 ShimGen has successfully created a shim for PsInfo.exe
 ShimGen has successfully created a shim for PsInfo64.exe
 ShimGen has successfully created a shim for pskill.exe
 ShimGen has successfully created a shim for pskill64.exe
 ShimGen has successfully created a shim for pslist.exe
 ShimGen has successfully created a shim for pslist64.exe
 ShimGen has successfully created a shim for PsLoggedon.exe
 ShimGen has successfully created a shim for PsLoggedon64.exe
 ShimGen has successfully created a shim for psloglist.exe
 ShimGen has successfully created a shim for pspasswd.exe
 ShimGen has successfully created a shim for pspasswd64.exe
 ShimGen has successfully created a shim for psping.exe
 ShimGen has successfully created a shim for psping64.exe
 ShimGen has successfully created a shim for PsService.exe
 ShimGen has successfully created a shim for PsService64.exe
 ShimGen has successfully created a shim for psshutdown.exe
 ShimGen has successfully created a shim for pssuspend.exe
 ShimGen has successfully created a shim for pssuspend64.exe
 ShimGen has successfully created a shim for RAMMap.exe
 ShimGen has successfully created a shim for RegDelNull.exe
 ShimGen has successfully created a shim for RegDelNull64.exe
 ShimGen has successfully created a shim for regjump.exe
 ShimGen has successfully created a shim for ru.exe
 ShimGen has successfully created a shim for ru64.exe
 ShimGen has successfully created a shim for sdelete.exe
 ShimGen has successfully created a shim for sdelete64.exe
 ShimGen has successfully created a shim for ShareEnum.exe
 ShimGen has successfully created a shim for ShellRunas.exe
 ShimGen has successfully created a shim for sigcheck.exe
 ShimGen has successfully created a shim for sigcheck64.exe
 ShimGen has successfully created a shim for streams.exe
 ShimGen has successfully created a shim for streams64.exe
 ShimGen has successfully created a shim for strings.exe
 ShimGen has successfully created a shim for strings64.exe
 ShimGen has successfully created a shim for sync.exe
 ShimGen has successfully created a shim for sync64.exe
 ShimGen has successfully created a shim for Sysmon.exe
 ShimGen has successfully created a shim for Sysmon64.exe
 ShimGen has successfully created a shim for Tcpvcon.exe
 ShimGen has successfully created a shim for Tcpview.exe
 ShimGen has successfully created a shim for Testlimit.exe
 ShimGen has successfully created a shim for Testlimit64.exe
 ShimGen has successfully created a shim for vmmap.exe
 ShimGen has successfully created a shim for Volumeid.exe
 ShimGen has successfully created a shim for Volumeid64.exe
 ShimGen has successfully created a shim for whois.exe
 ShimGen has successfully created a shim for whois64.exe
 ShimGen has successfully created a shim for Winobj.exe
 ShimGen has successfully created a shim for ZoomIt.exe
 The install of sysinternals was successful.
 Software installed to 'C:\ProgramData\chocolatey\lib\sysinternals\tools'
Chocolatey installed 1/1 packages.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

Päätin kuitenkin, etten tarvitsekaan kaikkia noita työkaluja, vaan asennan sitten tarvitsemani yksittäin paketista tarvitsemani työkalut myöhemmin. Poistin koko asennuksen komennolla:

choco uninstall sysinternals

Tulos:

PS C:\WINDOWS\system32> choco uninstall sysinternals
Chocolatey v0.10.10
Uninstalling the following packages:
sysinternals
sysinternals v2018.2.13
 Skipping auto uninstaller - No registry snapshot.
 sysinternals has been successfully uninstalled.
Chocolatey uninstalled 1/1 packages.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

Sysinternalia ei löydy enää asennushakemistosta:
choco3
TÄHÄN KEKSIN LISÄÄ TEKEMISTÄ MYÖHEMMIN. KOKEILE METAPAKETTIA!


TÄTÄ DOKUMENTTIA SAA KOPIOIDA JA MUOKATA GNU GENERAL PUBLIC LICENSE (VERSIO 3 TAI UUDEMPI) MUKAISESTI. HTTP://WWW.GNU.ORG/LICENSES/GPL.HTML
MARKUS PYHÄRANTA

 

Markus Pyhäranta

RELATED ARTICLES
LEAVE A COMMENT