When one says "Ping", they refer to ICMP ping, as that is what the original ping is. ICMP actually works on a lower level than the UDP & TCP transport protocols and does not use ports[1]:
ICMP, uses the basic support of IP as if it were a higher level
protocol, however, ICMP is actually an integral part of IP, and must be implemented by every IP module.
That is mostly because ICMP is used to report errors as IP is not completely reliable on its own. So, ICMP is a lower-level protocol that uses IP, not TCP/UDP. Ping is just a tool that uses ICMP (thanks to low-level C), however, ICMP isn't just ping or traceroute, its main purpose is completely different as I noted.
And I don't know how you've learned that layers are blind for below layers. That is not true, or at least to my knowledge.
Ping can use any protocol it wishes by implementing it in C.
Low-level languages like C have direct access to system IP-based modules, thus it is possible to use any such protocol by using C (and almost any other language written in C nowadays).
To explain more explicitly (tl;dr):
Ping is an ICMP-based tool, it does not use TCP and UDP, thus it doesn't work with ports (as a protocol does not need ports, only services do). It does not require the functionality of higher-level protocols such as TCP, so it doesn't implement them. And despite ping being an application, it works on ICMP and uses no port.
1
The OSI model is an abstract that has never been fully implemented as written in any stack, so keep in mind that none of the layers above 2 are actually mandatory. an application at layer 7 can perform tasks at layer 2, or 3, or 4 should it choose. check out my answer here, on how an application uses the Sockets library to setup a connection using sockets function calls that work at differant layers of the stack: https://superuser.com/questions/984182/what-are-the-detailed-osi-model-steps-involved-in-connecting-to-a-website/984253#984253
– Frank Thomas – 2018-07-02T18:56:59.707