User Tools

Site Tools


apuntes:servicios_transferencia

This is an old revision of the document!


Servicios de transferencia de archivos

Servicio FTP (File Transfer Protocol)

El protocolo FTP (File Transfer Protocol) es un protocolo utilizado para la transferencia de ficheros entre una máquina local y otra remota. Básicamente son dos operaciones las que se pueden realizar, subir ficheros a la máquina remota o bien descargarlos. Además existen más comandos pero se utilizan para manejarse dentro del servidor con el objetivo de poder navegar por la estructura de directorios, crear nuevos, eliminar ficheros y alguna otra tarea.

Print
Figure 1: FTP Activo/Pasivo

Servidores FTP

Proftpd es uno de los servidores FTP más utilizados en entornos Linux. En nuestro caso, que contamos con Debian 9, podemos instalarlo directamente utilizando apt-get

santi@zenbook:$ sudo apt-get install proftpd

El fichero de configuración principal lo podemos encontrar en /etc/proftpd/proftpd.conf, donde podremos configurar algunos parámetros como pueden ser los mensajes de bienvenida (será útil ocultarlos o modificarlos para no dar pistas a futuros atacantes) y el puerto donde escucha el servicio.

/etc/proftpd/proftpd.conf
. . .
Include         /etc/proftdp/modules.conf
ServerName      "Debian"
DisplayLogin    welcome.msg
Port            21
. . .

Servidores SFTP

En el caso de que queramos utilizar una opción segura a este protocolo, podemos utilizar también sftp que permite, utilizando SSH, realizar las mismas operaciones que un servidor FTP y de forma segura.

santi@zenbook:$ sudo apt-get install openssh-server openssh-sftp-server

En este caso el fichero de configuración lo encontraremos en /etc/ssh/sshd_config

Clientes FTP

Como cliente FTP de consola tendremos el comando ftp

santi@zenbook:$ ftp misitio.com
Connected to misitio.com.
220 ProFTPD 1.3.5b Server (Debian) [::ffff:127.0.0.1]
Name (misitio.com:santi): santi
331 Password required for santi
Password:
230 User santi logged in
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> |

Utilizando el comando help podemos contar con ayuda interactiva acerca de todos los comandos disponibles

ftp> help
Commands may be abbreviated.  Commands are:
 
!		dir		mdelete		qc		site
$		disconnect	mdir		sendport	size
account		exit		mget		put		status
append		form		mkdir		pwd		struct
ascii		get		mls		quit		system
bell		glob		mode		quote		sunique
binary		hash		modtime		recv		tenex
bye		help		mput		reget		tick
case		idle		newer		rstatus		trace
cd		image		nmap		rhelp		type
cdup		ipany		nlist		rename		user
chmod		ipv4		ntrans		reset		umask
close		ipv6		open		restart		verbose
cr		lcd		prompt		rmdir		?
delete		ls		passive		runique
debug		macdef		proxy		send

A continuación se describen los más utilizados

Comando Descripción
bye Cierra la sesión FTP
cd Cambia de directorio en la máquina remota
delete Elimina un fichero en la máquina remota
get Descarga un fichero de la máquina remota
lcd Cambia/Muestra directorio en la máquina local
ls Lista el contenido de un directorio de la máquina remota
mdelete Elimina múltiples ficheros en la máquina remota
mget Descarga múltiples ficheros en la máquina local
mkdir Crea un directorio en la máquina remota
mput Sube múltiples ficheros a la máquina remota
prompt Activa/Desactiva interacción en operaciones múltiples
put Sube un fichero a la máquina remota
pwd Muestra el directorio activo en la máquina remota
rmdir Elimina un directorio en la máquina remota
verbose Activa/Desactiva mostrar mensajes

Table 1: Resumen de comandos FTP

Hay que tener en cuenta que podemos obtener, interactivamente, ayuda específica de cada comando a través de help

ftp> help rmdir
rmdir     	remove directory on the remote machine

En el caso de que queramos conectar a un FTP seguro, utilizando el servicio SSH, podemos hacerlo conectando a través del comando sftp

santi@zenbook:$ sftp misitio.com
The authenticity of host 'misitio.com (::1)' cannot be established.
ECDSA key fingerprint is SHA256:B5y+uH5grBUJRLnN5ZNMvKHS4USELBfv5J2Gyf+s37s.
Are you sure you want to continue connecting (yes/no)? 

Igualmente contamos con ayuda sobre los diferentes comandos de que disponemos, muy del estilo a los que podemos encontrar en un servicio FTP

sftp> help
Available commands:
bye                                Quit sftp
cd path                            Change remote directory to 'path'
chgrp grp path                     Change group of file 'path' to 'grp'
chmod mode path                    Change permissions of file 'path' to 'mode'
chown own path                     Change owner of file 'path' to 'own'
df [-hi] [path]                    Display statistics for current directory or
                                   filesystem containing 'path'
exit                               Quit sftp
get [-afPpRr] remote [local]       Download file
reget [-fPpRr] remote [local]      Resume download file
reput [-fPpRr] [local] remote      Resume upload file
help                               Display this help text
lcd path                           Change local directory to 'path'
lls [ls-options [path]]            Display local directory listing
lmkdir path                        Create local directory
ln [-s] oldpath newpath            Link remote file (-s for symlink)
lpwd                               Print local working directory
ls [-1afhlnrSt] [path]             Display remote directory listing
lumask umask                       Set local umask to 'umask'
mkdir path                         Create remote directory
progress                           Toggle display of progress meter
put [-afPpRr] local [remote]       Upload file
pwd                                Display remote working directory
quit                               Quit sftp
rename oldpath newpath             Rename remote file
rm path                            Delete remote file
rmdir path                         Remove remote directory
symlink oldpath newpath            Symlink remote file
version                            Show SFTP version
!command                           Execute 'command' in local shell
!                                  Escape to local shell
?                                  Synonym for help
sftp> 
santi@zenbook:$ sftp misitio.com
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:B5y+uH5grBUJRLnN5ZNMvKHS4USELBfv5J2Gyf+s37s.
Please contact your system administrator.
Add correct host key in /home/santi/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /home/santi/.ssh/known_hosts:3
  remove with:
  ssh-keygen -f "/home/santi/.ssh/known_hosts" -R misitio.com
ECDSA host key for misitio.com has changed and you have requested strict checking.
Host key verification failed.
Couldn't read packet: Connection reset by peer
santi@zenbook:$ ssh-keygen -f "/home/santi/.ssh/known_hosts" -R misitio.com
# Host misitio.com found: line 13
/home/santi/.ssh/known_hosts updated.
Original contents retained as /home/santi/.ssh/known_hosts.old
Figure 2: Clientes gráficos para FTP/FTPS/SSH FTP

Configuración del servicio FTP

Creación de un sistema de cuentas de usuario

El primer paso será instalar el servidor FTP proftpd y el módulo para que éste sea capaz de trabajar con Bases de Datos MySQL, puesto que usaremos una Base de Datos para almacenar los diferentes usuarios junto con la información necesaria.

santi@zenbook:$ sudo apt-get install proftpd proftpd-mod-mysql
CREATE DATABASE ftp;
USE ftp;
 
CREATE TABLE usuarios (
 id VARCHAR(30) NOT NULL UNIQUE,
 password VARCHAR(80) NOT NULL,
 uid INTEGER DEFAULT 2001,
 gid INTEGER DEFAULT 2001,
 home VARCHAR(255),
 shell VARCHAR(255) DEFAULT NULL,
 bloqueado BOOLEAN DEFAULT 0
);
 
CREATE TABLE grupos (
 nombre VARCHAR(30) NOT NULL,
 gid INTEGER NOT NULL,
 miembros VARCHAR(255)
);

Servicio SSH (Secure SHell)

Servidores SSH

santi@zenbook:$ sudo apt-get install openssh-server

Clientes SSH

santi@zenbook:$ sudo apt-get install openssh-client

Protocolo SCP (Secure CoPy)

santi@zenbook:$ scp -r misitio santi@misitio.com:/var/www/html

Configuración del servicio SSH


Ejercicios


Proyectos de Ejemplo


Prácticas


© 2017 Santiago Faci

apuntes/servicios_transferencia.1518098192.txt.gz · Last modified: 2019/01/04 13:02 (external edit)