Querying a service from the client side

curl, dig, nc, openssl s_client, ssh and sftp: composing the request, reading the answer, speaking a text protocol by hand and interpreting error messages.

  • 28 cards
  • 4 topics
  • Free

The outline, topic by topic

Each topic is weighted the way the exam weighs it.

  1. Concepts
  2. Questions
  3. Sort and link
  4. Scenarios

A few cards from the deck

  • Client-server model: what is it?

    Show the answer

    An organisation where one program waits for requests on a port and answers them, while another takes the initiative of opening the connection and asking.

    Each tool in this deck plays the client: it talks to a service that is already listening. If nothing listens, the failure is immediate (Connection refused).

  • Which command asks 1.1.1.1 for the mail servers of example.org?

    • dig @1.1.1.1 example.org MX
    • dig @example.org 1.1.1.1 MX
    • dig 1.1.1.1 example.org SMTP
    • dig -x example.org MX
    Show the answer

    dig @1.1.1.1 example.org MX

    The server queried follows @, then come the name and the record type: MX gives the mail servers. SMTP is not a record type, and -x is for the reverse lookup of an address.

  • In curl -v output, lines starting with … are sent by the client and those starting with … are received from the server.

    Show the answer

    In curl -v output, lines starting with > are sent by the client and those starting with < are received from the server.

    Lines starting with * are curl's own comments (connection, TLS); they do not travel on the network.

  • curl: what is it?

    Show the answer

    A command-line tool that sends an HTTP (or HTTPS) request to a URL and prints the server's response.

    -I asks only for the headers, -v shows the request sent and the response, -L follows redirects, -o file writes the body to a file.

  • curl https://api.example.org/ answers curl: (6) Could not resolve host: api.example.org. What is the probable cause?

    • The server refused the connection on port 443 of its address
    • The certificate presented by the server expired yesterday
    • The name was not turned into an address: a DNS problem
    • The server answered with a 500 error instead of the page
    Show the answer

    The name was not turned into an address: a DNS problem

    The request never left: curl got no address. Check with dig api.example.org (typo, missing record, resolver down). A refused connection would give (7).