Click here to Skip to main content
Licence 
First Posted 7 Jun 2003
Views 159,527
Bookmarked 32 times

Fake (or Anonymous) NetSend for Windows NT/2000/XP

By | 17 Jun 2003 | Article
The Fake NetSend is a little utility that can be used to send anonymous (or fake) messages through your Windows Network.

Introduction

A few years ago I was working at a software development company and one day my co-worker asked me if would be possible to use the Windows Net Send mechanism to send messages through the corporate network using some programming language like C++. I found the idea very interesting since we could implement this functionality in some of our applications so they could send messages to our computers when an exception occurs and/or something goes wrong.

After some time of MSDN and Google, learning about MailSlots, I could write the first test program and, for our surprise, worked like a charm.

With our program ready, we've started do create a generic function to send the messages, so we could make it avaliable at our "shared" directory, when I got an idea: "What if we use an invalid User Name to send the message?". Well, I think I don't need to tell you how this history ends :)

Background Information

The FakeSend (and Net Send) mechanism is very simple. It uses an Interprocess Communication (IPC) resource called "MailSlots". We can create MailSlots to swap messages between applications on a network environment just like we do with Sockets, Named Pipes, etc... The MailSlot internally uses a datagram socket, which means that we cannot be sure if the message has arrived. To learn more about MailSlots read the MailSlot Reference from MSDN Library.

Using the code

The code is very straightforward. We have the main function NetSend() that receives three values:

  • szSender - The name of the person who is sending the message (Any name you want);
  • szReceiver - The User Name (Network Login) or Machine name of the person who will receive the message;
  • szMessage - The Message you want to send.
bool NetSend(const char * szSender, const char * szReceiver,
             const char * szMessage)
{
    // Our main variables
    char * pszMailSlot = NULL;
    unsigned char * pucMessage = NULL;
    unsigned int nMailSlotLen, nMsgFormatLen;

    HANDLE hHandle;
    DWORD dwBytesWritten;
    bool bRet = false;

    // Get the length of the strings
    nMailSlotLen  = strlen(szReceiver) + sizeof(szMailSlotPath);
    nMsgFormatLen = strlen(szSender) + strlen(szReceiver) +
                    strlen(szMessage) + sizeof(szMsgFormat);

    // Allocate necessary memory
    pszMailSlot = new char[nMailSlotLen];
    pucMessage  = new unsigned char[nMsgFormatLen];

    // Network path for <Receiver> MailSlot:
    // "\\Receiver\MAILSLOT\messngr"
    sprintf(pszMailSlot, szMailSlotPath, szReceiver);

    // Message Format:
    // "Sender\0Receiver\0Message\0"
    // sprintf doesn't work with \0 so here I'm using \r
    sprintf((char *)pucMessage, szMsgFormat, szSender,
                                szReceiver, szMessage);

    // Replace all '\r' characters with '\0'
    for (unsigned short i = 0; i < nMsgFormatLen; i++)
    {
        if (pucMessage[i] == '\r')
            pucMessage[i] = '\0';

        else if (pucMessage[i] == '\0')
            break;
    }

    // Create the file into Receiver's MailSlot and get a Handle to this file
    hHandle = CreateFile(pszMailSlot, GENERIC_WRITE, FILE_SHARE_READ, NULL,
                            OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

    // Do we have a valid handle?
    if (hHandle)
    {
        // Write the message to file
        bRet = (WriteFile(hHandle, pucMessage, (DWORD)nMsgFormatLen,
                    &dwBytesWritten, NULL) == TRUE);

        // Free the handle
        CloseHandle(hHandle);
    }

    return bRet;
}

History

  • 2003-06-08 - First version of FakeSend. Bugs: Zero, I hope :)
  • 2003-06-11 - Version 1.01. Just improving the code.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Caio Proiete

Software Developer (Senior)

Portugal Portugal

Member

Follow on Twitter Follow on Twitter
Caio Proiete has been programming for over 10 years, having first started with Clipper Summer'87.
 
He loves software development and reverse engineering. Today his main development technologies includes ASP .NET MVC, jQuery, HTML5, Silverlight, and WCF. He also has the following titles:
 
MVP - Microsoft Most Valuable Professional;
MCT - Microsoft Certified Trainer;
MCPD - Microsoft Certified Professional Developer;
MCTS - Microsoft Certified Technology Specialist;
MCSD - Microsoft Certified Solution Developer;
MCDBA - Microsoft Certified Database Administrator.
 
Technical blog:
http://caioproiete.net

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Questiondelphi? Pinmemberp2bf6:01 28 Feb '07  
GeneralNo messages received PinmemberPolovski2:27 11 Feb '07  
QuestionForce line feed in message Pinmemberzhur10:48 18 Oct '06  
Generalfake netSend from c# form PinmemberStojaneee13:41 17 May '06  
Generalsend to all Pinmemberyaewo10:10 10 May '06  
GeneralProblem, program ends very fast PinmemberIustus-aTw10:47 31 Mar '06  
GeneralRe: Problem, program ends very fast PinmemberIustus-aTw7:28 3 Apr '06  
GeneralRe: Problem, program ends very fast PinmemberStojaneee13:33 17 May '06  
QuestionI didn't get a popup box, Why ??? PinmemberKENyroj16:47 20 Mar '06  
GeneralVB6 Code Pinmembermattwright9:59 21 Dec '05  
Generalsudden end of program encounter Pinmembercharllyyy4eva2:23 22 Jul '05  
GeneralSend by IP address PinsussYaroslav A. Golovach11:32 9 Jul '05  
GeneralHi dude! PinmemberGoldSight10:19 6 Jun '05  
GeneralReceive message! PinmemberTailana16:04 1 Jun '05  
GeneralQbasic PinmemberUnknown00418:05 25 Jan '05  
QuestionHow to delete the renamed file PinmemberShadow2921:59 4 Oct '04  
AnswerRe: How to delete the renamed file PinsussDrakonas19:47 13 Oct '04  
GeneralANSI or UNICODE Pinmemberponkin21:09 28 Sep '04  
GeneralRe: ANSI or UNICODE PinmemberHernan7:01 5 Nov '04  
Generalmessage length PinmemberHernan4:12 23 Jul '04  
GeneralRe: message length PinmemberCaio Proiete11:37 29 Jun '05  
GeneralMultiple Sends Pinmembermatrixprogrammer16:09 20 May '04  
GeneralRe: Multiple Sends PinmemberCaio Proiete11:34 29 Jun '05  
Generalthank you Pinmemberjalcot2:01 27 Apr '04  
GeneralRe: thank you PinmemberCaio Proiete11:39 29 Jun '05  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 18 Jun 2003
Article Copyright 2003 by Caio Proiete
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid