Transferring files to an isolated DOS-based virtual machine using ... keyboard

    Consider transferring files to a virtual machine by simulating user activity.

    Imagine that we have some virtual machine running the DOS operating system (FreeDOS 1.1 / MS-DOS 6.22) with a full range of programs, but without removable media, serial and parallel ports, network access and installed guest add-ons. The only thing available is the console.

    Let's try to copy files to the virtual machine from the client’s machine through ... the keyboard! Although virtual :)

    Since copying files on the keyboard is a long process even when using the Key Paste keyboard emulator , we stock up on free time and proceed.

    Test stand


    First, prepare a test bench for our experiment:
    1. QEMU Virtualization Host and Client - GNU / Linux
    2. Virtual machines:
      1. VM "DOS"
      2. VM “Windows XP” (also a client of VM “DOS”)

    Access to the Windows XP virtual machine is through the SPICE protocol. Guest add-ons are installed and work, there is access to the network.

    Access to the DOS virtual machine is via the VNC protocol. No additional software has been installed.

    On the Windows XP virtual machine, the Key Paste program is launched, ready to emulate typing. Since typing paralyzes work in the operating system, moving the client of the DOS virtual machine to a virtual machine or a separate computer is justified.

    Creating a simple binary file


    Let's try to create a simple binary file with a size of 5 bytes in the DOS VM in which each byte contains a value corresponding to its position, namely, 1,2,3,4,5 in hexadecimal notation.

    Create a 5.txt file with the following contents:

    n 5.bit
    e 0000 01 02 03 04 05
    rcx
    5
    w 0
    q
    

    where, the first line defines the name of the created file, the second - the contents of the file in hexadecimal format, the fourth - the file size.

    Send the file for processing by the Debug program.

    debug < 5.txt

    Using the dir command, make sure that the file is created.

    dir 1.bit

    Preparing to transfer a large file


    Debug allows you to create binary files only up to 64Kb. To create large files, we will use Base64 encoding, which is used in e-mail. In DOS, by default, there are no tools for working with Base64 encoding, so copy the program for working with base64 encoding and the program for checking md5 checksums.

    First of all, copy the md5sum program to check the md5 checksums using the hexadecimal representation.

    In Linux, using the hexdump program, we create a file preparation for transfer to the debug program.

    hexdump -v -e '"e %04_ax "' -e '10/1 "%02X "' -e '"\n"' md5sum.exe > md5sum_.hex

    At the output, we get a file with contents of the form:
    e 0000 4D 5A 73 01 3C 00 01 00 02 00
    e 000a F1 0F FF FF 66 12 00 50 00 00
    e 0014 00 00 00 00 00 1C 00 00 00 0E 00
    e 001e 74 07 B9 80 3B BE FE 76 89 F7
    e 0028 1E A9 B5 80 8C C8 05 05 00 8E
    e 0032 D8 05 FC 0A 8E C0 FD F3 A5 FC
    e 003c 2E 80 6C 12 10 73 E7 92 AF AD
    


    We calculate the size of the md5sum.exe file using the command

    ls -l md5sum.exe

    As a result, we get the number "30579". Converting this number to a hexadecimal number system from decimal we get the number "7773".

    Using the blank and file size information, create the source file to create the binary file using the debug program.

    Check the file’s operability in the “Windows XP” VM.

    debug < md5sum.txt

    The file is compiled. Rename the md5sum.bin file to the md5sum.exe file and try to calculate the checksum of the md5sum.exe file.

    md5sum.exe md5sum.exe

    the checksum is calculated and matches.

    Now you can transfer the file to DOS and check the checksum





    Similarly, copy the base64.exe file .


    Copy large file


    Let's try to copy a large file. As an example, take the DOS Navigator distribution from RIT-labs. We encode the distribution file “dn151.zip” into Base64 format using the command:

    base64 dn151.zip > dn.b64

    Similarly, we will unzip.exe,

    base64 UNZIP.EXE > unzip.b64

    since the edit text editor in DOS is very difficult to digest large text files, we will split the “dn.b64” file into files of 3500 lines each using split commands

    split -d -l 3500 dn.b64 dn

    As a result of the command, we get the files: “dn.00”, “dn.01”, “dn.02” and “dn.03”.

    Using edit and keyboard, copy the resulting files to DOS. Using stream redirection, combine four text files into one

    type dn.00 >> dn.txt
    type dn.01 >> dn.txt
    type dn.02 >> dn.txt
    type dn.03 >> dn.txt
    


    Decode the resulting file using base64,
    base64 dn.txt dn.zip

    decode the unpacker:
    base64 unzip.txt unzip.exe

    Unpack the archive of the DOS Navigator distribution package.
    unzip -e dn.zip -d c:\dn

    After unpacking, you can run the DOS Navigator command:
    c:\dn\dn

    Conclusion


    As a result of this experiment, we learned using a keyboard emulator to transfer large amounts of text, copy files to virtual machines, even under DOS. Which would seem at first glance to not contain any means of interacting with the clipboard and creating binary files.

    The file transfer process is extremely slow, but on the other hand it works and can be used in emergency situations or paranoid conditions. Before proceeding with the actual transfer of files via the keyboard, you can copy text files from a specially prepared CD .

    Used software:


    Also popular now: