Applicable Versions
NetSim StandardNetSim Pro

The payload of the packet is added in the application layer while generating the packet. NetSim adds its own payload to the packet as per the packet size specified in the application properties. However, the payload can be modified by the user by reading from a string, file, etc. 

In this example, the payload of a packet is modified by reading from a string. The steps involved may vary between different versions of NetSim. Choose the appropriate section of this article, as per the version of NetSim.


Applicable Releases
v11.1v12
 
Open NetSim source code in Visual Studio 2019 by clicking on the Open Code button present in NetSim Home Screen via Open Simulation->Workspace Options->Open Code. Go to the Application Project in the solution explorer. Code modifications are done in the copy_payload() function inside the application.c file of the Application project. To change the payload the follow the steps given below:


STEP 1: Create a string containing your data just before the function copy_payload()

For example, 

const char custom_data[]= "This is to demonstrate how users can add their own payload to the

the packet. The payload will further be encrypted if encryption is enabled";


STEP 2:  Inside the for loop in the function copy_payload(), make the modifications as given below (we have commented of the existing code and added the code shown in red) :


if (payload)
{
    size_t custom_data_len = strlen(custom_data);
for (i = 0; i < *payload; i++)
{
    /*if (info->encryption == Encryption_XOR)
real[i] = xor_encrypt('a' + i % 26, 16);
else
    real[i] = 'a' + i % 26;*/


    if (info->encryption == Encryption_XOR)
real[i] = xor_encrypt(custom_data[i%custom_data_len], 16);
else
        real[i] = custom_data[i%custom_data_len];

}

..


STEP 3: After the source code is modified, right-click on the Application project and select rebuild. After a successful build, NetSim will automatically take care of linking the modified source code with simulations performed.

 

STEP 4:To view the payload of the packet, Wireshark can be set to online in the Node properties. For instance, the user can create a simple scenario in Internetworks with two Wired Nodes connected to a router. Set an application between the two nodes. In either of the Nodes right click and select properties. In the global properties set Wireshark to online and run the simulation. 


Applicable Releases
v10v11.0
 
Open NetSim source code in Visual Studio 2015/2017 by double-clicking on the NetSim.sln file present in “<NetSim_Install_Directory>/src/Simulation” folder. Go to the Application Project in the solution explorer. Code modifications are done in the copy_payload()function inside the application.c file of the Application project. To change the payload the follow the steps given below:


STEP 1: Create a string containing your data just before the function copy_payload()

For example, 

const char custom_data[]= "This is to demonstrate how users can add their own payload to the

the packet. The payload will further be encrypted if encryption is enabled";


STEP 2:  Inside the for loop in the function copy_payload(), make the modifications as given below (we have commented of the existing code and added the code shown in red) :


if (payload)
{
    size_t custom_data_len = strlen(custom_data);
for (i = 0; i < *payload; i++)
{
    /*if (info->encryption == Encryption_XOR)
real[i] = xor_encrypt('a' + i % 26, 16);
else
    real[i] = 'a' + i % 26;*/


    if (info->encryption == Encryption_XOR)
real[i] = xor_encrypt(custom_data[i%custom_data_len], 16);
else
        real[i] = custom_data[i%custom_data_len];

}

..


STEP 3: After the source code is modified, right-click on the Application project and select rebuild. After a successful build, replace the newly built libApplication.dll file (can be found in the DLL folder created inside the Simulation directory) in the bin folder of NetSim after renaming the original libApplication.dll file to say, libApplication_original.dll as a backup.

 

STEP 4:To view the payload of the packet, Wireshark can be set to online in the Node properties. For instance, the user can create a simple scenario in Internetworks with two Wired Nodes connected to a router. Set an application between the two nodes. In either of the Nodes right click and select properties. In the global properties set Wireshark to online and run the simulation. 


During the simulation, Wireshark will automatically execute and will display the packets captured in the wired node. One can view the packet payload in the pane at the bottom, by clicking on the corresponding packet.


Users can also change the payload of the packet by reading content from a file.


Applicable Releases
v9
 
Open NetSim source code in Visual Studio 2015/2017 by double-clicking on the NetSim.sln file present in “<NetSim_Install_Directory>/src/Simulation” folder. Go to the Application Project in the solution explorer. Code modifications are done in the copy_payload()function inside the application.c file of the Application project. To change the payload the follow the steps given below:


STEP 1: Create a string containing your data just before the function copy_payload()

For example, 

const char custom_data[]= "This is to demonstrate how users can add their own payload to the

the packet. The payload will further be encrypted if encryption is enabled";


STEP 2:  Inside the for loop in the function copy_payload(), make the modifications as given below (we have commented of the existing code and added the code shown in red) : 


size_t custom_data_len = strlen(custom_data); 

for(i=0;i<*payload;i++)

  {

   /*if(i<len1)

   {

    real[i]=start_data[i];

   }

   else if(i>=*payload-len2)

   {

    real[i]=end_data[len2-*payload+i];

   }

   else

   {

    if(info->encryption==Encryption_XOR)

     real[i] = xor_encrypt('a'+i%26,16);

    else

     real[i] = 'a'+i%26;

   }*/

   if(info->encryption==Encryption_XOR)

     real[i] = xor_encrypt(custom_data[i%custom_data_len],16);

    else

     real[i] = custom_data[i%custom_data_len];

  }



STEP 3: After the source code is modified, right-click on the Application project and select rebuild. After a successful build, replace the newly built libApplication.dll file (can be found in the DLL folder created inside the Simulation directory) in the bin folder of NetSim after renaming the original libApplication.dll file to say, libApplication_original.dll as a backup.

 

STEP 4:To view the payload of the packet, Wireshark can be set to online in the Node properties. For instance, the user can create a simple scenario in Internetworks with two Wired Nodes connected to a router. Set an application between the two nodes. In either of the Nodes right click and select properties. In the global properties set Wireshark to online and run the simulation. 

Result and Analysis


During the simulation, Wireshark will automatically execute and will display the packets captured in the wired node. One can view the packet payload in the pane at the bottom, by clicking on the corresponding packet.



In a similar way, users can also change the payload of the packet by reading content from a file.