📜 ⬆️ ⬇️

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

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

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

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

Since copying files using the keyboard is a long process, even when using the Key Paste keyboard emulator, we save time and start working.
')

Test stand


To begin with, we will prepare a test stand for our experiment:
  1. QEMU Virtualization Host and Client - GNU / Linux
  2. Virtual machines:
    1. VM "DOS"
    2. VM "Windows XP" (also client VM "DOS")

Access to the Windows XP virtual machine is provided via the SPICE protocol. Guest add-ons are installed and working.

Access to the DOS virtual machine is provided via the VNC protocol. No additional programs installed.

On the Windows XP virtual machine, the Key Paste program is running, ready to emulate typing. Since typing paralyzes the work in the operating system, the removal of a DOS virtual machine client into a virtual machine or an individual computer is fully justified.

Creating a simple binary file


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

Create a 5.txt file with the following contents:

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

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

Send the file to the processing program "Debug"

debug < 5.txt

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

dir 1.bit

Preparing to transfer a large file


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

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

In Linux, using the hexdump program, create a file stub 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 the 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 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


Calculate the size of the file md5sum.exe using the command

ls -l md5sum.exe

As a result, we get the number "30579". Transforming this number into hexadecimal from decimal, we get the number "7773".

Using the template and file size information, we will create a source file for creating a binary file using the debug program.

Check the file performance in the VM "Windows XP".

debug < md5sum.txt

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

md5sum.exe md5sum.exe

checksum is calculated and matches.

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





Similarly, copy the file base64.exe .


Copy large file


Let's try to copy a large file. As an example, take the distribution "DOS Navigator" from the company "RIT-labs". Encode the distribution file "dn151.zip" in Base64 format with the command:

base64 dn151.zip > dn.b64

Similarly, we will pack the unzip.exe file.

base64 UNZIP.EXE > unzip.b64

Since the edit text editor in DOS is very hard to digest large text files, we split the “dn.b64” file into 3500 lines of files using the split command

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, we merge 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


The resulting file is decoded using base64
base64 dn.txt dn.zip

decode the unpacker:
base64 unzip.txt unzip.exe

Unpack the archive of the DOS Navigator distribution
unzip -e dn.zip -dc:\dn

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

Conclusion


As a result of this experiment, we learned using the keyboard emulator to transfer large amounts of text, copy files to virtual machines even under DOS control. Which at first glance would seem to contain no 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 or paranoid conditions. Before you begin the actual transfer of files through the keyboard, you can copy the text files from a specially prepared CD .

Used software:

Source: https://habr.com/ru/post/238831/


All Articles