Click here to Skip to main content
11,437,638 members (32,212 online)
Click here to Skip to main content

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

, 17 Jun 2003
Rate this:
Please Sign up or sign in to vote.
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 Smile | :)

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 Smile | :)
  • 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

Share

About the Author

Caio Proiete
Team Leader Nephila Capital
Bermuda Bermuda
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
Follow on   Twitter   LinkedIn

Comments and Discussions

 
Questiondelphi? Pin
p2bf28-Feb-07 7:01
memberp2bf28-Feb-07 7:01 
GeneralNo messages received Pin
Polovski11-Feb-07 3:27
memberPolovski11-Feb-07 3:27 
GeneralRe: No messages received Pin
Matheus Lima16-Oct-14 7:49
memberMatheus Lima16-Oct-14 7:49 
QuestionForce line feed in message Pin
zhur18-Oct-06 11:48
memberzhur18-Oct-06 11:48 
Generalfake netSend from c# form Pin
Stojaneee17-May-06 14:41
memberStojaneee17-May-06 14:41 
Generalsend to all Pin
yaewo10-May-06 11:10
memberyaewo10-May-06 11:10 
GeneralProblem, program ends very fast Pin
Iustus-aTw31-Mar-06 11:47
memberIustus-aTw31-Mar-06 11:47 
GeneralRe: Problem, program ends very fast Pin
Iustus-aTw3-Apr-06 8:28
memberIustus-aTw3-Apr-06 8:28 
GeneralRe: Problem, program ends very fast Pin
Stojaneee17-May-06 14:33
memberStojaneee17-May-06 14:33 
QuestionI didn't get a popup box, Why ??? Pin
KENyroj20-Mar-06 17:47
memberKENyroj20-Mar-06 17:47 
GeneralVB6 Code Pin
mattwright21-Dec-05 10:59
membermattwright21-Dec-05 10:59 
Generalsudden end of program encounter Pin
charllyyy4eva22-Jul-05 3:23
membercharllyyy4eva22-Jul-05 3:23 
GeneralSend by IP address Pin
Yaroslav A. Golovach9-Jul-05 12:32
sussYaroslav A. Golovach9-Jul-05 12:32 
GeneralHi dude! Pin
GoldSight6-Jun-05 11:19
memberGoldSight6-Jun-05 11:19 
GeneralReceive message! Pin
Tailana1-Jun-05 17:04
memberTailana1-Jun-05 17:04 
GeneralQbasic Pin
Unknown00425-Jan-05 19:05
memberUnknown00425-Jan-05 19:05 
QuestionHow to delete the renamed file Pin
Shadow294-Oct-04 22:59
memberShadow294-Oct-04 22:59 
AnswerRe: How to delete the renamed file Pin
Drakonas13-Oct-04 20:47
sussDrakonas13-Oct-04 20:47 
GeneralANSI or UNICODE Pin
ponkin28-Sep-04 22:09
memberponkin28-Sep-04 22:09 
GeneralRe: ANSI or UNICODE Pin
Hernan5-Nov-04 8:01
memberHernan5-Nov-04 8:01 
Generalmessage length Pin
Hernan23-Jul-04 5:12
memberHernan23-Jul-04 5:12 
GeneralRe: message length Pin
Caio Proiete29-Jun-05 12:37
memberCaio Proiete29-Jun-05 12:37 
GeneralMultiple Sends Pin
matrixprogrammer20-May-04 17:09
membermatrixprogrammer20-May-04 17:09 
GeneralRe: Multiple Sends Pin
Caio Proiete29-Jun-05 12:34
memberCaio Proiete29-Jun-05 12:34 
Generalthank you Pin
jalcot27-Apr-04 3:01
memberjalcot27-Apr-04 3:01 

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.

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