2

I want some way of getting an online content on the command prompt window (Windows CMD).

Imagine some content online stored either on a hosting service or the MySql database provided to you by that hosting service. It can be any data stored in any form. I just want to remotely view it with the help of a CMD window anywhere in the world. What command should I be using?

To make it more clear, lets just say you have one day to prepare for your exam. Rather than preparing for it, you are making a plan to cheat.

Now your exam is going to be conducted on a computer that has been allotted to you and you are not allowed to use a browser or download any new application on the PC. But you can use Command Prompt, so your task being a cheat is to put the answers somewhere online. You cannot install anything new.

How will you go about if you are stuck in the above scene?

P.S This is for educational purpose only. I have no such such exams.

Ryan Bemrose
  • 8,148
  • 35
  • 51
Prakhar Sharma
  • 145
  • 1
  • 2
  • 8
  • It depends entirely on how the content is stored and accessed. CMD knows how to get things from SMB network shares (`\\computername\folder`), but you need to run a program to access most other stuff (ie: sqlcmd for a database, or iexplore for web content) – Ryan Bemrose Apr 24 '16 at 21:19
  • @RyanBemrose imagine i have a text file uploaded www.mywebsite.com/myfile.txt is dere any way i can view the content of this file on CMD, or open this file in Notepad, anything but not a Browser or a third party application – Prakhar Sharma Apr 24 '16 at 21:22
  • CMD doesn't support it without using a browser or other program like UnxUtils `wget` to download the page. If you are allowed to run PowerShell then you might have some luck using `Invoke-Webrequest`. – Ryan Bemrose Apr 24 '16 at 21:26
  • @RyanBemrose is dere any way i can download UncUtils using CMD only, straightaway, also, Lets just say i am allowed to use PowerShell, how do i go about it? – Prakhar Sharma Apr 24 '16 at 21:30
  • @RyanBemrose, That worked amazing, though i will keep looking for CMD method, but till then, this shud solve my purpose. Thank You so much. – Prakhar Sharma Apr 24 '16 at 21:44
  • 2
    check [this](http://stackoverflow.com/questions/28143160/how-can-i-download-a-file-with-batch-file-without-using-any-external-tools) – npocmaka Apr 25 '16 at 08:02

5 Answers5

4

You can check this question.The easiest way is with bitsadmin command:

bitsadmin /transfer myDownloadJob /download /priority normal http://downloadsrv/10mb.zip c:\10mb.zip

You can try also winhttpjs.bat:

call winhhtpjs.bat https://example.com/files/some.zip -saveTo c:\somezip.zip
Community
  • 1
  • 1
npocmaka
  • 51,748
  • 17
  • 123
  • 166
3

It depends entirely on how the content is stored and accessed. CMD knows how to get things from SMB network shares (\computername\folder), but you need to run a program to access most other stuff. (eg: sqlcmd for a database)

CMD does not support downloading web content. You will need to use another program to connect to the website and download the page. Obviously a browser would work. Another option is to download wget.exe from UnxUtils. Or use another scripting language like PowerShell or Wscript.

If you have access to launch PowerShell (pre-installed on Windows 7-10), you can use the .NET library to download web resources.

PS> Invoke-Webrequest 'www.mywebsite.com/myfile.txt' -OutFile '.\myfile.txt'

This will use .NET to connect to the page and download it into the local directory. To download to another directory or filename, change the -OutFile argument.

To launch this from CMD, go into a PowerShell prompt by simply typing powershell in CMD, and running the PS commands from there. Alternatively, you can run PS commands from CMD using the powershell -c command.

powershell.exe -c "invoke-webrequest 'www.mywebsite.com/myfile.txt' -outfile .\myfile.txt"
Ryan Bemrose
  • 8,148
  • 35
  • 51
1
Set Arg = WScript.Arguments
set WshShell = createObject("Wscript.Shell")
Set Inp = WScript.Stdin
Set Outp = Wscript.Stdout
On Error Resume Next
    Set File = WScript.CreateObject("Microsoft.XMLHTTP")
    File.Open "GET", Arg(1), False
    File.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 1.1.4322; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C; .NET4.0E; BCD2000; BCD2000)"
    File.Send
    txt=File.ResponseText
    'Putting in line endings
    Outp.write txt
    If err.number <> 0 then 
        Outp.writeline "" 
        Outp.writeline "Error getting file" 
        Outp.writeline "==================" 
        Outp.writeline "" 
        Outp.writeline "Error " & err.number & "(0x" & hex(err.number) & ") " & err.description 
        Outp.writeline "Source " & err.source 
        Outp.writeline "" 
        Outp.writeline "HTTP Error " & File.Status & " " & File.StatusText
        Outp.writeline  File.getAllResponseHeaders
        Outp.writeline LCase(Arg(1))
    End If

General Use

Filter is for use in a command prompt. Filter.vbs must be run with cscript.exe. If you just type filter it will run a batch file that will do this automatically.

filter subcommand [parameters]

Filter reads and writes standard in and standard out only. These are only available in a command prompt.

filter <inputfile >outputfile
filter <inputfile | other_command
other_command | filter >outputfile
other_command | filter | other_command

Web

filter web webaddress
filter ip webaddress

Retrieves a file from the web and writes it to standard out.

webaddress - a web address fully specified including http://

Example

Gets Microsoft's home page

filter web http://www.microsoft.com

Filter with 19 example command prompt scripts avaialable at https://onedrive.live.com/redir?resid=E2F0CE17A268A4FA!121&authkey=!AAFg7j814-lJtmI&ithint=folder%2cres

0

Apart from VBScript & JScripts, there's a utility (resides with CMD) on Windows which can be run from CMD (if you have write access):

set url=https://www.nsa.org/content/hl-images/2017/02/09/NSA.jpg
set file=file.jpg
certutil -urlcache -split -f %url% %file%

Cmdlets in Powershell:

$url = "https://www.nsa.org/content/hl-images/2017/02/09/NSA.jpg"
$file = "file.jpg"
$ProgressPreference = "SilentlyContinue";
Invoke-WebRequest -Uri $url -outfile $file

.Net under PowerShell:

$url = "https://www.nsa.org/content/hl-images/2017/02/09/NSA.jpg"
$file = "file.jpg"
# Add the necessary .NET assembly
Add-Type -AssemblyName System.Net.Http
# Create the HttpClient object
$client = New-Object -TypeName System.Net.Http.Httpclient
$task = $client.GetAsync($url)
$task.wait();
[io.file]::WriteAllBytes($file, $task.Result.Content.ReadAsByteArrayAsync().Result)

C# application built on command-line with csc.exe:

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-options/command-line-building-with-csc-exe

using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;

namespace DownloadImage
{
    class Program
    {
        static async Task Main(string[] args)
        {
            using var httpClient = new HttpClient();
            var url = "https://www.nsa.org/content/hl-images/2017/02/09/NSA.jpg";
            byte[] imageBytes = await httpClient.GetByteArrayAsync(url);

            using var fs = new FileStream("file.jpg", FileMode.Create);
            fs.Write(imageBytes, 0, imageBytes.Length);

        }
    }
}

Built in Windows applications. No need for external downloads.

Tested on Win 10

Zimba
  • 1,095
  • 9
  • 13
  • The certutil one gives me 'access denied' (and it is not write access to %file% that id denied) – Hagen von Eitzen Mar 06 '21 at 20:38
  • By default, only TrustedInstaller has access to `-urlcache`. You may change user permissions, take file ownership, or edit admin group policy, or disable Windows Defender or Antivirus monitoring. When you have access, your response will similar to `**** Online **** 000000 ... 05193f CertUtil: -URLCache command completed successfully.` instead of `Access is denied.` You may also `finger` to bypass Windows Defender from interfering file download via C2 servers. LoLBins can bypass UAC & WDAC. – Zimba Mar 10 '21 at 17:19
0

Windows 10 build 17063 and later ships curl.exe (ref: https://techcommunity.microsoft.com/t5/containers/tar-and-curl-come-to-windows/ba-p/382409). Assuming you don't need to support earlier Windows versions, including earlier Windows 10 builds, you can use it in your batch files like this

curl http://example.com/ --output content.txt
notepad content.txt
Esme Povirk
  • 2,670
  • 13
  • 23