cmdkey, rpcping, finger, rexec, rsh, lpq, lpr, ipxroute, qwinsta / query, rpcinfo, showmount
A toolbox video: cmdkey (stored credentials), rpcping (Microsoft RPC tests), qwinsta/query (Remote Desktop sessions), plus legacy UNIX-interop tools finger, rexec/rsh, lpq/lpr (LPD printing), ipxroute (IPX) and rpcinfo/showmount (NFS). Knowing which port and protocol each one uses is the key to troubleshooting with them.
205.1 Where each tool comes from
| Tool | Availability | Purpose |
|---|---|---|
| cmdkey | Built in | Save/list/delete credentials in Credential Manager |
| rpcping | Built in | Test Microsoft RPC (TCP 135 or RPC over HTTP) |
| qwinsta / query | Built in | List RDS sessions, users, processes, RD hosts |
| finger | Built in | Query a finger service (TCP 79) |
| lpq / lpr | LPR Port Monitor feature | LPD queue status / send a print job (TCP 515) |
| rpcinfo / showmount | Client for NFS feature | Sun RPC port mapper (111) / NFS exports |
| rexec / rsh / ipxroute | Removed (legacy) | Remote commands in plain text / IPX routing |
205.2 Practical: help only on the office PC
cmdkey /?rpcping /?qwinsta /?query /?where finger lpq lpr rexec rsh ipxroute rpcinfo showmount> cmdkey /?Creates, displays, and deletes stored user names and passwords.> rpcping /?Pings a server using RPC. Options are:> qwinsta /?Display information about Remote Desktop Services sessions.> query /?QUERY { PROCESS | SESSION | TERMSERVER | USER }> where (System32) finger lpq lpr rexec rsh ipxroute rpcinfo showmountC:\Windows\System32\finger.exeINFO: Could not find "C:\Windows\System32:lpq".INFO: Could not find "C:\Windows\System32:lpr".INFO: Could not find "C:\Windows\System32:rexec".INFO: Could not find "C:\Windows\System32:rsh".INFO: Could not find "C:\Windows\System32:ipxroute".INFO: Could not find "C:\Windows\System32:rpcinfo".INFO: Could not find "C:\Windows\System32:showmount".- Output was scanned for hostname, user, domain and IPs before saving: zero hits.
- Only finger exists in System32; the other seven tools are not on this PC.
205.3 cmdkey: stored credentials
cmdkey /list all stored credentialscmdkey /list:server01 one targetcmdkey /add:server01 /user:CONTOSO\u1 /pass domain credential, password promptcmdkey /generic:server01 /user:u1 /pass:<pw> generic credentialcmdkey /add:server01 /smartcardcmdkey /delete:server01cmdkey /delete /ras- /add saves a domain (Windows) credential; /generic saves one for other apps.
- /pass without a value prompts for the password; it is never shown again.
- /list was not run on the office PC because it prints every saved target.
- cmdkey sends nothing on the network: it only writes to Credential Manager (e.g. TERMSRV/rds01 for RDP).
205.4 rpcping: how it works
- Step 1
1.Admin PC runs rpcping /s server01
- Step 2
2.RPC call goes to the endpoint mapper on TCP 135
- Step 3
3.Server reply checks connectivity, latency and authentication in one go
- Step 4
4.Behind a firewall: /t ncacn_http sends the call over HTTPS 443
- Step 5
5.RPC proxy forwards it to the server (Outlook Anywhere style)
rpcping /s server01 /t ncacn_ip_tcp /i 100 latency over 100 callsrpcping /s server01 /e 135 specific endpointrpcping /s server01 /u Kerberos /a connect /i 10 auth testrpcping /t ncacn_http /s exchange_server /o RpcProxy=front_end_proxy /P username,domain,* /H Basic /u NTLM /a connect /F 3-t <protseq> - protocol sequence to use. Can be one of the standard RPC protocol sequences - ncacn_ip_tcp, ncacn_np, ncacn_http, etc. If not specified, default is ncacn_ip_tcp.-s <server_addr> - the server address. If not specified, the local machine will be pinged. E.g. server, server.com, 157.59.244.141-i <#_iterations> - number of calls to make. The default is 1. This option is useful for measuring connection latency if multiple iterations are specified.-a <authn_level> - the authentication level to use. Possible values are connect, call, pkt, integrity and privacy.| Option group | Switches | Meaning |
|---|---|---|
| Target | /s, /t, /e, /f, /i, /r, /v | Server, protocol (TCP default), endpoint/interface, iterations, stats, verbosity |
| Security | /u Negotiate|NTLM|Kerberos|SChannel, /a connect|call|pkt|integrity|privacy | Package and level (integrity = signing, privacy = encryption) |
| Identity | /N, /I, /M anonymous|identify|impersonate|delegate | Principal, alternate identity, impersonation (needs /u and /a) |
| RPC over HTTP | /o RpcProxy=, /P, /H, /F, /E, /R, /U | Proxy, front-end auth, SSL, ping proxy only, HTTP proxy |
205.5 qwinsta and query: Remote Desktop sessions
qwinsta /server:Server2 /counterquery sessionquery user USER1 /server:Server1query termserver /domain:CONTOSOquery process * /server:Server1C:\>query session SESSIONNAME USERNAME ID STATE TYPE DEVICE console Administrator1 0 active wdcon >rdp-tcp#1 User1 1 active wdtshare rdp-tcp 2 listen wdtshare 4 idle 5 idle- > marks the current session; Active = connected, Disc = disconnected with apps still running, listen = the rdp-tcp listener, idle = empty slots.
- qwinsta = query session; filter by session name, user or ID, /server for another RD host, /counter for created/disconnected/reconnected counts.
- query user shows logon and idle time; query termserver lists RD hosts; query process * shows processes of all sessions.
205.6 Legacy UNIX services: which port
- Step 1
1.finger asha -> unixhost TCP 79; fingerd returns plain-text user info
- Step 2
2.lpr sends a print job -> unixhost lpd TCP 515
- Step 3
3.rpcinfo -p -> nfssrv rpcbind (port mapper) port 111
- Step 4
4.Port mapper returns registered programs (nfs, mountd)
- Step 5
5.showmount gets the export list from mountd
205.7 finger and rexec/rsh
finger asha@192.168.225.20finger @192.168.225.20finger nobodyhere@192.168.225.20# from nfssrv: raw finger protocolprintf 'asha\r\n' | nc -w 3 192.168.225.20 79$ finger asha@192.168.225.20Login: asha Name: Asha VermaDirectory: /home/asha Shell: /bin/bashNever logged in.No mail.Plan:Lab hours: 10 to 6. Build server owner.$ finger @192.168.225.20No one logged on.$ finger nobodyhere@192.168.225.20finger: nobodyhere: no such user.- Raw netcat to port 79 returns the same text: finger is just plain text.
- Windows options start with - (finger -l user@host); @host alone lists all users.
- Only try finger in your own lab, never against office hosts.
rexec unixhost ls -l runs on rexecd (plain text, deprecated)rsh unixhost ls -l runs on rshd (plain text, deprecated)ssh user1@unixhost ls -l today's replacement205.8 LPD printing: lpr and lpq
lpc -P raw@192.168.225.20 stop rawlpr -P raw@192.168.225.20 -J 'Monthly report' -C Finance /tmp/report.txtlpq -P raw@192.168.225.20# from nfssrv: LPD 'send queue state' (03)printf '\003raw\n' | nc -w 3 192.168.225.20 515lpc -P raw@192.168.225.20 start rawcat /tmp/printer-out.txt$ ss -lnt | grep ':515 'LISTEN 0 64 0.0.0.0:515 0.0.0.0:*$ lpc -P raw@192.168.225.20 stop rawPrinter: raw@unixhostraw@unixhost: stopped$ lpq -P raw@192.168.225.20Printer: raw@unixhost (printing disabled) Queue: 1 printable job Server: no server active Rank Owner/ID Pr/Class Job Files Size Time1 root@unixhost+349 F/Finance 349 Monthly report 23 13:16:08[nfssrv]$ printf '\003raw\n' | nc -w 3 192.168.225.20 515raw@unixhost 1 job (printing disabled)raw@unixhost: started Queue: no printable jobs in queue Status: job 'root@unixhost+349' saved at 13:16:15.514done root@unixhost+349 F/Finance 349 Monthly report 23 13:16:08$ cat /tmp/printer-out.txtMonthly report: page 1lpq -S 10.0.0.45 -P Laserprinter1 [-l]lpr -S 10.0.0.45 -P Laserprinter1 -o Document.txtlpr -S 10.0.0.45 -P Laserprinter1 -o l PostScript_file.pslpr -S 10.0.0.45 -P Laserprinter1 -C "Finance" -J "Monthly report" file.txt- Windows: -S (server) and -P (printer) are capital and required; Linux LPRng uses printer@host.
- -o = text, -o l = binary (PostScript); -C = banner, -J = job name; -d and -x are for old printers.
205.9 ipxroute (legacy)
ipxroute servers [/type=x]ipxroute ripout <network>ipxroute resolve {guid | name} {GUID | <adaptername>}ipxroute board= N [def] [gbr] [mbr] [remove=xxxxxxxxxxxx]ipxroute configIPX was removed after Windows XP; ipxroute is reference only.
205.10 NFS: rpcinfo and showmount
rpcinfo -p 192.168.225.10rpcinfo -t 192.168.225.10 100005 3showmount -e 192.168.225.10showmount -a 192.168.225.10rpcinfo -p 192.168.225.30$ rpcinfo -p 192.168.225.10 program vers proto port service 100000 4 tcp 111 portmapper 100000 2 udp 111 portmapper 100003 3 tcp 2049 nfs 100005 3 udp 2049 mountd 100005 3 tcp 2049 mountd$ rpcinfo -t 192.168.225.10 100005 3program 100005 version 3 ready and waiting$ showmount -e 192.168.225.10Export list for 192.168.225.10:/srv/share 192.168.225.0/24/srv/backup 192.168.225.20$ showmount -a 192.168.225.10All mount points on 192.168.225.10:$ rpcinfo -p 192.168.225.30192.168.225.30: RPC: Remote system error - No route to hostrpcinfo /p nfsserver01rpcinfo /t nfsserver01 nfs 3rpcinfo /u nfsserver01 100005 3rpcinfo /b mountd 3showmount -e nfsserver01 exported file systemsshowmount -a nfsserver01 clients + mounted dirsshowmount -d nfsserver01 mounted directories- Lab server runs rpcbind + userspace unfsd: portmapper on 111, nfs and mountd v3 on 2049.
- showmount -a is empty because no client has mounted anything yet.
- No route to host on .30 = the RPC host is unreachable, not a port-mapper problem.
205.11 Comparison: rpcinfo vs rpcping
| Point | rpcinfo | rpcping |
|---|---|---|
| RPC type | ONC / Sun RPC | Microsoft RPC |
| Talks to | Port mapper (rpcbind) TCP/UDP 111 | Endpoint mapper TCP 135 or RPC proxy (HTTPS) |
| Typical use | NFS, mountd registration | AD, Exchange, file server RPC + auth |
| Availability | Client for NFS feature | Built in |
205.12 Common mistakes
- Thinking a cmdkey-saved password is safe on a shared PC: it is hidden, but any user of that PC can connect as you; /delete after work.
- Using rexec/rsh/finger on real networks: plain text; use ssh.
- Forgetting capital -S/-P with Windows lpq/lpr.
- Confusing port 111 (Sun RPC) with port 135 (Microsoft RPC).
205.13 Interview tips
- Check endpoint mapper + Kerberos: rpcping /s server01 /u Kerberos /a connect /i 10.
- rpcinfo = Sun RPC port mapper 111 (NFS); rpcping = Microsoft RPC endpoint mapper 135 / RPC over HTTP.
- qwinsta = query session; Disc means the user's apps are still running.
- Ports: finger 79, LPD 515, port mapper 111, NFS 2049.