you can download files with certutil

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
npocmaka_
Posts: 512
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

you can download files with certutil

#1 Post by npocmaka_ » 09 Apr 2018 10:14

https://groups.google.com/forum/#!topic ... %5B1-25%5D

Code: Select all

certutil.exe -urlcache -split -f "https://download.sysinternals.com/files/PSTools.zip" pstools.zip

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: you can download files with certutil

#2 Post by dbenham » 09 Apr 2018 10:20

Wow, that is cool 8) and scary :shock: :evil:

ShadowThief
Expert
Posts: 1162
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: you can download files with certutil

#3 Post by ShadowThief » 09 Apr 2018 12:43

I imagine -f is "force", but what does "-split" do?

Squashman
Expert
Posts: 4470
Joined: 23 Dec 2011 13:59

Re: you can download files with certutil

#4 Post by Squashman » 09 Apr 2018 12:58

ShadowThief wrote:
09 Apr 2018 12:43
I imagine -f is "force", but what does "-split" do?

Code: Select all

C:\Users\Squashman\Desktop>certutil -urlcache -?
Usage:
  CertUtil [Options] -URLCache [URL | CRL | * [delete]]
  Display or delete URL cache entries
    URL -- cached URL
    CRL -- operate on all cached CRL URLs only
    * -- operate on all cached URLs
    delete -- delete relevant URLs from the current user's local cache
    Use -f to force fetching a specific URL and updating the cache.

Options:
  -f                -- Force overwrite
  -gmt              -- Display times as GMT
  -seconds          -- Display times with seconds and milliseconds
  -split            -- Split embedded ASN.1 elements, and save to files
  -v                -- Verbose operation
  -privatekey       -- Display password and private key data

CertUtil -?              -- Display a verb list (command list)
CertUtil -URLCache -?    -- Display help text for the "URLCache" verb
CertUtil -v -?           -- Display all help text for all verbs

penpen
Expert
Posts: 1992
Joined: 23 Jun 2013 06:15
Location: Germany

Re: you can download files with certutil

#5 Post by penpen » 09 Apr 2018 14:49

This should work since windows vista (i have no windows vista to test):
https://blogs.technet.microsoft.com/pki ... -certutil/


penpen

miskox
Posts: 554
Joined: 28 Jun 2010 03:46

Re: you can download files with certutil

#6 Post by miskox » 12 Apr 2018 02:38

Very good!

At work I cannot use wget.exe - it does not work. BITS transfer works but it is veeeery slow.

certutil.exe solution can be compared with wget.exe - downloads at full speed. Though input and output files must (probably) be set (no wildcard downloading for example, or complete web sites). Or your list can be generated with wget.exe on another computer...

Also I did some tests with parameters:
- if I remove -f - split download is very slow

Thanks again - very useful.

Saso

miskox
Posts: 554
Joined: 28 Jun 2010 03:46

Re: you can download files with certutil

#7 Post by miskox » 13 Apr 2018 00:19

Update:

target folders must exist (the same goes for BITS).

Saso

npocmaka_
Posts: 512
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: you can download files with certutil

#8 Post by npocmaka_ » 13 Apr 2018 01:37

miskox wrote:
13 Apr 2018 00:19
Update:

target folders must exist (the same goes for BITS).

Saso
But unlike bitsadmin works with relative paths.

carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

Re: you can download files with certutil

#9 Post by carlos » 13 Apr 2018 11:09

Very interesting. The only disadvantage is that the file is cached in two additional locations like this:

%UserProfile%\AppData\LocalLow\Microsoft\CryptnetUrlCache\Content
%UserProfile%\AppData\Local\Microsoft\Windows\INetCache\IE\43LG2WYW\

I found this using the -v parameter that show more info.

Code: Select all

certutil.exe -v -urlcache -split "https://download.sysinternals.com/files/PSTools.zip"
Thus, if you download a file, it would be save on the disk on 3 folders.

penpen
Expert
Posts: 1992
Joined: 23 Jun 2013 06:15
Location: Germany

Re: you can download files with certutil

#10 Post by penpen » 13 Apr 2018 16:11

carlos wrote:
13 Apr 2018 11:09
Very interesting. The only disadvantage is that the file is cached in two additional locations
Just delete the urlcache after downloading (shouldn't cause any issues if and only if the same process that created the cache, deletes that cache, which here is the case):

Code: Select all

@echo off
setlocal enableExtensions disableDelayedExpansion

set "url=https://download.sysinternals.com/files/PSTools.zip"
call :download "url"

goto :eof

:download 
:: %~1 name of the environment variable that holds the url
setlocal enableDelayedExpansion

:: downloading file
certutil.exe -urlcache -split -f "!%~1!" pstools.zip
::deleting cache
certutil -urlcache "!%~1!" delete
:: check referenced urlcache is deleted
certutil.exe -v -urlcache -split "!%~1!"

endlocal
goto :eof
penpen

Post Reply