tftp (Windows, Linux, macOS) + winrs and mstsc (Remote Desktop)
TFTP gets or puts a single file over UDP port 69 with no login and no encryption; it is still used to load firmware and router configs and for PXE boot. winrs runs a command on a remote Windows machine over WinRM, and mstsc opens a full Remote Desktop session over RDP.
154.1 Why is it used?
- TFTP: upload or download firmware/configs to routers and switches, PXE boot files (pxelinux.0); tiny and works without a login.
- winrs: run one command on a remote Windows server and get only text back, good for scripts.
- mstsc: a full graphical desktop on a remote PC or server.
- Where they run: Windows tftp is an optional feature (TFTP Client), Linux uses tftp-hpa, macOS has a built-in BSD tftp; winrs.exe and mstsc.exe are built into Windows.
154.2 How TFTP works: blocks and ACKs
- The client sends RRQ (read) or WRQ (write) to UDP 69.
- The server answers from a new random port; the rest of the transfer uses that port.
- Data goes in 512-byte blocks, and each block must be ACKed before the next one (lockstep).
- A block shorter than 512 bytes means end of file.
- Step 1
1.Client 192.168.174.20:50006 -> server :69: RRQ firmware.bin octet
- Step 2
2.Server replies from new port 46470: DATA block 1 (512 B)
- Step 3
3.Client: ACK 1
- Step 4
4.Server: DATA block 2 (512 B), client: ACK 2
- Step 5
5.Server: DATA block 3 (276 B, shorter = last), client: ACK 3
- Step 6
6.1300 bytes received, transfer complete
516-byte UDP packets = 4-byte header + 512 data; ACKs are 4 bytes
154.3 Windows tftp
- Syntax: tftp [-i] host get|put src [dest]; no interactive mode.
- Without -i the transfer is ASCII and changes line endings: always use -i for firmware.
- On the office PC the feature was not installed, so both commands failed (it was deliberately not installed on an office PC).
$ where tftpINFO: Could not find files for the given pattern(s).$ C:\Windows\System32\tftp.exe'C:\Windows\System32\tftp.exe' is not recognized as an internal or external command,operable program or batch file.tftp -i 192.168.1.10 get boot.imgtftp -i 192.168.1.10 put startup.txt# enable (admin):dism /online /Enable-Feature /FeatureName:TFTP154.4 Linux tftp-hpa: command-line options
- Lab: Debian tftp-hpa client 192.168.174.20, Alpine tftpd-hpa server 192.168.174.10.
- -V version, -v verbose, -c runs one command (always last).
- config.txt took 78 bytes on the wire because netascii turns each line end into CR LF.
- -m binary: md5 of firmware.bin matched the server hash.
- -4 IPv4 only; a port after the host for a non-standard port; -R 50000:50010 pins the client source port range.
tftp -Vtftp -v 192.168.174.10 -c get config.txttftp -m binary 192.168.174.10 -c get firmware.binls -l firmware.bin; md5sum firmware.bintftp -4 -v -m binary 192.168.174.10 69 -c get pxelinux.0tftp -R 50000:50010 -m binary 192.168.174.10 -c get firmware.bin$ tftp -v 192.168.174.10 -c get config.txtReceived 78 bytes in 0.0 seconds [18108 bit/s]$ ls -l firmware.bin; md5sum firmware.bin-rw-r--r-- 1 root root 1300 Nov 9 06:52 firmware.bin5f317bdfe03d7991852272381868b69c firmware.binserver: 5f317bdfe03d7991852272381868b69c firmware.bin[srv]$ tcpdump -lni eth0 -c 8 udpIP 192.168.174.20.50006 > 192.168.174.10.69: TFTP, length 21, RRQ "firmware.bin" octetIP 192.168.174.10.46470 > 192.168.174.20.50006: UDP, length 516IP 192.168.174.20.50006 > 192.168.174.10.46470: UDP, length 4IP 192.168.174.10.46470 > 192.168.174.20.50006: UDP, length 516IP 192.168.174.20.50006 > 192.168.174.10.46470: UDP, length 4IP 192.168.174.10.46470 > 192.168.174.20.50006: UDP, length 280IP 192.168.174.20.50006 > 192.168.174.10.46470: UDP, length 4| Option | Meaning |
|---|---|
| host [port] | Default host; non-standard UDP port |
| -4 / -6 | IPv4 only / IPv6 only (if compiled) |
| -c command | One command, always last |
| -l | Literal: ':' is not a host separator |
| -m mode | ascii/netascii or binary/octet |
| -R port:port | Local source port range |
| -v / -V | Verbose / print version |
154.5 Real errors
- Missing file: Error code 1: File not found.
- Without -l, 'C:config.txt' made tftp treat C as a host (unknown host).
- Server without -c (create) refuses put of a new file with File not found; a put to an existing writable file worked.
- After restarting the server with in.tftpd -L -c -s /srv/tftp, the same put succeeded.
# server restarted: in.tftpd -L -c -s /srv/tftp$ tftp -v 192.168.174.10 -c put router.cfgConnected to 192.168.174.10 (192.168.174.10), port 69putting router.cfg to 192.168.174.10:router.cfg [netascii]Sent 31 bytes in 0.0 seconds [8870 bit/s]154.6 tftp-hpa interactive commands
- connect only remembers host and port: TFTP has no real connection.
- status shows host, mode (default netascii), verbose/trace and timeouts.
- mode binary = binary = mode octet; ascii goes back to text.
- put a.cfg b.cfg / sends several files to a dir; put file newname renames.
- trace shows each DATA/ACK; rexmt sets per-packet retransmit, timeout the total wait.
connect 192.168.174.10 69statusbinaryverboseget firmware.bin fw-copy.binput a.cfg b.cfg /put router.cfg router-new.cfgconnect 192.168.174.99rexmt 1timeout 4statusget firmware.binquittftp> put router.cfg router-new.cfgputting router.cfg to 192.168.174.10:router-new.cfg [octet]Sent 29 bytes in 0.0 seconds [15293 bit/s]tftp> connect 192.168.174.99tftp> rexmt 1tftp> timeout 4tftp> statusConnected to 192.168.174.99.Mode: netascii Verbose: off Tracing: off Literal: offRexmt-interval: 1 seconds, Max-timeout: 4 secondstftp> get firmware.binTransfer timed out.154.7 macOS tftp (BSD)
- Interactive like Linux, but the default mode is binary (octet).
- -e starts with max blocksize and timeout options.
- blocksize (RFC 2348, 8-65464) makes blocks bigger than 512 so big firmware is faster; windowsize (RFC 7440) allows several blocks per ACK.
- With 512-byte blocks, files over 33488896 bytes need blocksize or rollover (block counter wraps after 65535).
- debug packet/simple/options/access and packetdrop (testing) help troubleshooting.
154.8 winrs (WinRM)
- Target must have WinRM enabled (winrm quickconfig).
- Commands go to WinRM on HTTP 5985 (encrypted with Kerberos/NTLM) or HTTPS 5986; only text output comes back.
- -r: target (NetBIOS name or URL, default localhost); -usessl uses the default HTTPS port.
- -u: user; without -p a password prompt appears (safer); -ad allows delegation to a third machine's share.
- -d start dir, -env:VAR=val (repeat), -nop (no profile, needed for non-admin), first Ctrl-C goes remote, second kills winrs.
- Step 1
1.On server01 once: winrm quickconfig
- Step 2
2.Admin PC: winrs -r:server01 -u:contoso\admin ipconfig
- Step 3
3.Request goes to server01:5985 (HTTP WS-Management, Kerberos/NTLM encrypted)
- Step 4
4.WinRM runs ipconfig in a remote shell
- Step 5
5.Only the text output returns to the admin PC
- Step 6
6.-r:https://server01.contoso.com uses TLS on 5986
winrs -r:server01 -u:contoso\admin ipconfigwinrs -r:server01 -ad -u:contoso\admin dir \\fileserver\sharewinrs -r:https://server01 ipconfigwinrs -r:server01 cmdwinrm enumerate shell/cmdwinrm get winrm/config/winrs-comp[ression] - Turn on compression. Older installations on remote machines may not support compression so it is off by default.-[use]ssl - Use an SSL connection when using a remote endpoint. Specifying this instead of the transport "https:" will use the default WinRM default port.154.9 mstsc (Remote Desktop, RDP 3389)
- mstsc /v:server01 connects on RDP 3389; with NLA (CredSSP) credentials are checked before any desktop is created.
- /g:rdgw.contoso.com goes through an RD Gateway over HTTPS 443 from outside the office.
- /restrictedAdmin sends no credentials to the remote PC; /remoteGuard keeps them on your device.
- /admin admin session, /public no password/bitmap cache, /prompt always ask.
- Display: /f full screen, /w /h size, /span stretches, /multimon copies your monitor layout, /l lists monitors.
- Shadowing: query session gives IDs, /shadow:3 view, /control to control, /noConsentPrompt if policy allows.
- Step 1
1.mstsc /v:server01 -> TCP/UDP 3389
- Step 2
2.NLA (CredSSP): credentials checked first
- Step 3
3.Only if OK does server01 create a desktop
- Step 4
4.Server sends desktop screen frames
- Step 5
5.From outside: /g:rdgw -> HTTPS 443 to gateway -> RDP 3389 inside
mstsc /v:server01:3390 /fmstsc /v:server01 /g:rdgw.contoso.commstsc /v:server01 /remoteGuardquery session /server:server01mstsc /v:server01 /shadow:3 /control154.10 Comparison: TFTP vs winrs vs mstsc
| Point | TFTP | winrs | mstsc |
|---|---|---|---|
| Port | UDP 69 (+ random data port) | TCP 5985 / 5986 | TCP/UDP 3389 |
| Login | None | Kerberos / NTLM | NLA / CredSSP |
| Encryption | None | Yes (Kerberos/TLS) | Yes (TLS) |
| Output | One file | Text of one command | Full desktop |
| Typical use | Firmware, PXE | Scripts, admin commands | GUI admin, support |
154.11 Common mistakes
- Uploading firmware in ASCII mode: transfer 'completes' but bytes change and the router will not boot. Use -i / -m binary.
- Thinking only the admin can use a TFTP server: there is no login, so any LAN laptop can fetch the router config.
- Firewall allowing only UDP 69: the server replies from a random port.
- Putting -p:PASSWORD on the winrs command line instead of using the prompt.
154.12 Interview tips
- TFTP = UDP 69, 512-byte blocks, one ACK per block, short block = end, no auth.
- Keep TFTP only on a trusted LAN and stop it after the job.
- winrs = one command over WinRM 5985/5986, text output; mstsc = full desktop over RDP 3389.
- /remoteGuard and /restrictedAdmin protect credentials if the RDP server is compromised.