14

as you may know one is unable to create RAW sockets using Windows Sockets without having administrative priviliges. The problem is, that I need to send ICMP messages, thus I need RAW sockets. The Problem: My program needs to run without administrative privileges.

That lead me to the question, how does the ping tool send ICMP messages w/o administrative privileges?

dom0
  • 7,356
  • 3
  • 28
  • 50
  • Try making a system call to `ping [hostname]` within your application - I don't think that needs administrative privileges. Also, what have you tried, and if it's failing, what's the error message? – jefflunt Oct 07 '11 at 12:44
  • I'm not sure it does work without admin privileges. I've previously had ping come back with some kind of "access denied" error message in Vista. My Win7 doesn't, but I have UAC turned off, so my current situation may be atypical. – Marcelo Cantos Oct 07 '11 at 12:48
  • @normalocity: I don't need ping, I need some other ICMP messages. Thats why I want to know, how ping is able to send ICMP w/o admin rights... ;) – dom0 Oct 07 '11 at 13:53
  • 1
    @Marcelo Cantos: Ping definitivly works w/o admin – dom0 Oct 07 '11 at 13:54
  • 1
    Isn't this what IcmpSendEcho() is for? – Luke Oct 07 '11 at 15:01
  • @Luke: Ow man... I can't believe there's a dedicated API function _just for that_. But yeah, you are right, that must be how it works. Good catch really. – Damon Oct 07 '11 at 19:24

1 Answers1

16

Although ICMP uses RAW sockets (which require admin rights on Win2K and later), Microsoft circumvents its own security rules to allow its ICMP APIs to get through. As such, don't use RAW sockets directly to send your own ICMP ping messages. Use IcmpSendEcho() and related functions instead.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • @Remy Lebeau In which unit or wrapper is `IcmpSendEcho` implemented? – user1580348 Feb 28 '15 at 15:35
  • @user1580348: if you [read the documentation](https://msdn.microsoft.com/en-us/library/windows/desktop/aa366050.aspx), you will see that it is an exported function in `Icmp.dll` (Win2K) and `Iphlpapi.dll` (XP and later). – Remy Lebeau Feb 28 '15 at 20:40