4

I am in a bit of a sticky situation. I started my current job a few months ago, and I have a web application running on an apache web server (a simple PHP-based one). I need to update this code to fix some problems in the application, and I'd like to get the code into a proper source code environment (IE. Version Control).

Skipping explanation of irrelevant details, I need to retrieve a directory (folder) from an Ubuntu Server 14.04 (CLI) Virtual Machine without adding or removing any software or other files to the machine. Currently the machine has no FTP or SCP server on it, so I cannot use those. And it's missing the /sbin/mount.nfs helper program to allow the mounting of an NFS share (we have a series of shared folders here that I could potentially use to retrieve the files if I could mount an NFS share).

Currently I only have one idea, which is to insert a USB Flash Drive into the ESXi host that is running the machine, and copying the files to that. However, the machine doesn't have a USB controller, and because it is a production machine I cannot shut it down during the workday to install one, so I'll only be able to do this after business hours. Because of this, (TLDR:) I was wondering if anyone else had any other ideas on how to retrieve a directory from a Ubuntu Server 14.04 VM without FTP, SCP, Mounting an NFS Share, or installing any new files or software.

Edit: Didn't expect all the great responses. Removing my accepted answer for now. I'll assign it elsewhere when I have a good chance to go through these responses and experiment.

Brandon S.
  • 149
  • 6
  • 4
    So, no ssh even? – EEAA Jul 28 '16 at 13:12
  • Unfortunately no : (. I know it makes it really difficult. When I asked the previous guy how he got the files out there in the first place, he has no idea. I don't know how this happened, but it did. The problem is the server runs a lot of important databases as well, so I can't shut it down easily. EDIT: Unfortunately, I don't even have the capability of installing open-ssh. The big problem is also that I'm so low on drive space that installing anything will cause the databases to stop due to insufficient space. – Brandon S. Jul 28 '16 at 13:14
  • 7
    Cripes dude, honestly. This is a completely unreasonable situation, and you've put unreasonable constraints on it. Root into the console of the server and get SSH running. – EEAA Jul 28 '16 at 13:15
  • If it's a VM - and similarly to what VirtualBox can do - is there a "shared folder" facility that's in place allowing you to access anything through the host? – Kinnectus Jul 28 '16 at 13:20
  • @BigChris ESXi does not have that functionality. – EEAA Jul 28 '16 at 13:23
  • Is Samba installed on the VM? – Kinnectus Jul 28 '16 at 13:29
  • I've not noticed samba on the machine, and there is no samba directory under /etc/ or /var/lib so I assume the answer is no. – Brandon S. Jul 28 '16 at 13:33
  • TBH I don't see the problem here. You have a webserver running on the machine. What prevents you from symlinking/zipping the files and downloading them via http? – s1lv3r Jul 28 '16 at 15:52
  • 5
    But you are able to somehow _run_ commands (via shell access) on that server, right? Could you use existing _clients_ on that server (_e.g._ `ftp`, `scp`, _etc_) to _upload_ the tar'd up directory _from_ your Ubuntu server _to_ some other machine on which you _can_ install server software for receiving that folder? – Castaglia Jul 28 '16 at 16:51
  • Can you enable WebDAV on the Apache server? – TMN Jul 28 '16 at 16:52
  • @EEAA Can't he stick a thumb drive into the ESXi box, attach it to the vm in question, mount the drive on some directory, and copy the files to it? – SnakeDoc Jul 28 '16 at 18:55
  • @SnakeDoc He said the guest doesn't have a USB controller, otherwise that might work. – EEAA Jul 28 '16 at 19:13
  • @EEAA Ah, missed that part. Ya, that's a tough situation. Downtime is going to be mandatory. – SnakeDoc Jul 28 '16 at 19:17
  • 8
    It would have been useful to know what you *can* do. Can you execute commands on the machine? As root? How do you do that if not via ssh? Create files? Set executable bit? Execute programs and scripts? Is tar available? bash? netcat aka. nc? socat? curl? wget? telnet? busybox? zmodem support e.g. via lrzsz? Could you transfer and use a static copy of any of these programs, typing in hex digits if you had to? – MvG Jul 28 '16 at 23:32
  • Do you have netcat? – user253751 Jul 29 '16 at 07:26
  • 8
    `...so low on drive space that installing anything will cause the databases to stop...` Is this **prodiuction server** expected to continue running in the future? – user2338816 Jul 29 '16 at 09:24
  • 2
    You might wanna think about changing the accepted answer... – gxx Jul 29 '16 at 10:04
  • do you have ssh access to the machine? root or non-root? – ksm Jul 29 '16 at 14:33
  • how can there be no ssh? – njzk2 Jul 30 '16 at 04:55
  • 1
    if it's a VM, get a snapshot, and voila – njzk2 Jul 30 '16 at 04:58
  • 2
    The space required to install ssh is so tiny, if that is an actual constraint then I'm sure you can find some log files that can be deleted. You obviously don't have any recent logs as there is no space for them to be written to – Darren H Jul 30 '16 at 13:30

8 Answers8

37

As well as saying all the things it doesn't have, what about saying the things it does have? How big is the folder and how much free disk space is there?

Assuming you have no access to the CLI at all, even from the console:

  1. If it's ESXi 5.0 or above, and the server has VMware Tools installed, use PowerCLI and the Copy-VMGuestFile cmdlet to copy files from it.
  2. It's a VM, restore a backup of it somewhere isolated, boot it, make all the changes you like to get at the files.
  3. It's a VM, restore a backup of the disk and download and mount the VMDK file.

Even though you don't have SSH access, assuming you have some kind of access to type commands and manage the server via the VM console:

  1. It's a web server, download the files through a browser
    1. Maybe gzip them into /tmp (memory) and symbolic link into the webserver folder to avoid changing Apache config
  2. Does it have FTP client installed? FTP from the server to somewhere else and upload the files.

    1. Does it have SSH client installed? SCP them from the server to a remote SSH server
    2. Email them to yourself
    3. WGET/Curl POST them to a remote web server upload
    4. TFTP them out
  3. Does it have netcat (nc) installed? You can pipe tar | nc and stream the data to a socket, and use nc | tar on another computer on the network to receive. example

  4. If it's a typical Linux install, it might have Python on it, Python comes with SimpleHTTPServer module which defaults to serving the current directory as a website, run that on a different port to the main webserver and download the files from there.
  5. Script stuffing them into your database as a binary blob into an in-memory table, and then selecting them out from a client maybe relevant
  6. Does the server syslog to a remote destination? Base64 encode the files and stream them into the syslog... ymmv on reading it back.
TessellatingHeckler
  • 5,726
  • 3
  • 26
  • 44
  • 1
    Upvoting for #2 - one of the great benefits of VMs is the ability to make copies to mess with in a test environment. OP is lucky enough to have this server in a VM - use it, install any software on the copy, then delete the copy. – Jake Jul 28 '16 at 18:03
  • 1
    What @Jake said, but I'm upvoting for all the other points raised as well. Good job! The accepted answer stating "[...] You literally have zero options here [...]" is just nonsense. – gxx Jul 28 '16 at 23:13
  • +1 for comprehensive brainstorm of plausible out-of-the-box solutions. – Skyhawk Jul 28 '16 at 23:45
  • sshfs is a really nice way to work with remote files over ssh. – Thorbjørn Ravn Andersen Jul 29 '16 at 15:12
  • Another option would be to make a copy of the disk and mount the copy on another VM, where you can access with a different system and read the contents in the disk (assuming it isn't encrypted). – Ismael Miguel Jul 30 '16 at 15:56
9

If the server has Python installed -- which it almost certainly does; Python is used by enough system services that it's pretty much guaranteed to be present -- you can start up a HTTP server to serve files from the current directory using the command:

python -m SimpleHTTPServer 9999

to start up a web server on port 9999.

Keep in mind that there are no access controls on this server, so you may not want to do this if the server is accessible to the public.


Another option will be to pipe a tar archive over the network. Assuming that you have another computer (host name "client") at IP address 1.2.3.4 that's reachable from the Ubuntu server, you can do this by running the following command on the client:

nc -lp 9999 > files.tar.gz

and running on the host:

tar cz /path/to/directory > /dev/tcp/1.2.3.4/9999

While this does create an archive, the archive is never written to disk -- it's streamed directly over the network -- so there is no risk of running out of disk space.

6

The virtual machine disk is hopefully stored in a way that is backed up regularly - so you can restore the backup to a new location and then use the VM disk as a second disk in a new VM.

If there are no official backups, then there should be, and this needs sorting - but if the disk is stored on a LVM partition, you may be able to create a snapshot partition, and then copy the disk from there as though it was a back up

Michael Shaw
  • 673
  • 4
  • 9
5

Well, there is already an accepted answer, and in addition, there is a real good answer making use of the fact it is a web server.

But just to point out a line of attack that I don't think is addressed much is if you have command line access, you are probably using a terminal program, and most of those have some sort of way to log stuff that scrolls off of the screen.

So maybe this answer could help in the future for someone who doesn't have a web server running. Basically what might be called a field expedient file transfer using common Linux tools

One could send the folder as ASCII. Tar the folder, convert that from binary to ASCII using a number of possibilities. Then on the machine running the terman program, recover the ASCII blob from scrollback, and extract the binary from it.

tar czf - folderpath | uuencode temp.tar.gz

or

tar cvf - folderpath | base64

will dump a huge block of text to your terminal. If you can capture that as scrollback, clean it up a bit in a text editor, then decode it back to binary, you'll have a tar.gz of the folder. Sure, you might have to do something like set your scroll back in putty to a huge amount of lines.

I think you could even use xxd to do the encoding and decoding if you wanted to.

If you couldn't fit it in scrollback in one time, you could even break it up using head and tail and send the ASCII over a chunk at a time.

Details depend on what utilities you have access to and how much effort you want to take squeezing that data through a console data stream

(OP should use the web server)

infixed
  • 176
  • 4
4

While that is the ESXi VM you have to get another vmdisk attached to it. Then move everything noncritical to that disk and install tool of yor choice - ssh/scp/rsync/everything else.

Kondybas
  • 6,964
  • 2
  • 20
  • 24
3

From another host, do:

 dd if=/dev/zero of=some-file.img bs=1k count=1000
 mkfs.fat some-file.img

Take file some-file.img on your desktop. The VMware client should be able to mount it as a floppy drive.

  • Adjust count=1000 to fit your need.
Peter Mortensen
  • 2,318
  • 5
  • 23
  • 24
Archemar
  • 1,369
  • 11
  • 19
3

If you are able to run shell commands on the server, then you can run tar with the right arguments to create a .tar (or .tar.gz) archive containing the files, and then you can run curl or wget to upload the archive to https://transfer.sh/ . From another computer you can retrieve the archive.

If you are unable to run shell commands on the server, then you should ask the sysadmin or DBA of the server how they run commands. (You mentioned that the server runs an important database, so there must be a way to run maintenance tasks.)

If you are able to upload .php files and make them run (i.e. serve web pages), then you can find an admin .php script which exposes a directory tree, upload it, and run it.

pts
  • 435
  • 1
  • 5
  • 16
2

Create a new Vmdk on the data store. Attach it to the VM in runtime, discover it on the VM, partition it, create file system on it, mount it on a mount point and then copy over the data to it. Once done, unmount it, disconnect the Vmdk and then connect to a VM on which you have the ssh/sftp/nfs access. Then discover, mount and copy over to wherever needed.

yetdot
  • 174
  • 5