To implement a Secure Shell (SSH) simulation in OMNeT++ has needs to emulate the behaviour of SSH where the cryptographic network protocol for working network services securely across the unsecured network. SSH is usually used for remote login and command execution that make sure the secure communication among a client and a server.
Since the OMNeT++ is not particularly designed for high-level protocol simulations such as SSH, then we need to emulate the key contexts of SSH, like secure communication (using encryption), authentication, and command execution over a network. The below is the procedure to execute the basic elements of SSH in OMNeT++:
Step-by-Step Implementation:
Example .ned file:
network SSHNetwork {
submodules:
client: StandardHost {
@display(“p=100,200”);
}
server: StandardHost {
@display(“p=300,200”);
}
router: Router {
@display(“p=200,100”);
}
connections:
client.ethg++ <–> Ethernet100M <–> router.pppg++;
router.pppg++ <–> Ethernet100M <–> server.ethg++;
}
This network consists of a client, a server, and a router connecting them.
Example of a basic SSH handshake and authentication:
class SSHClient : public cSimpleModule
{
protected:
virtual void initialize() override;
virtual void handleMessage(cMessage *msg) override;
void initiateSSH();
};
void SSHClient::initialize()
{
scheduleAt(simTime() + 1, new cMessage(“startSSH”));
}
void SSHClient::handleMessage(cMessage *msg)
{
if (strcmp(msg->getName(), “startSSH”) == 0) {
initiateSSH();
} else if (strcmp(msg->getName(), “authResponse”) == 0) {
EV << “SSH Authentication Successful” << endl;
// Continue to execute commands or exchange data
}
delete msg;
}
void SSHClient::initiateSSH()
{
EV << “Initiating SSH Handshake” << endl;
cMessage *authRequest = new cMessage(“authRequest”);
send(authRequest, “out”);
}
This client module starts an SSH handshake by sending an authentication request to the server.
On the server side, we need implement a simple response:
class SSHServer : public cSimpleModule
{
protected:
virtual void handleMessage(cMessage *msg) override;
void authenticate(cMessage *msg);
};
void SSHServer::handleMessage(cMessage *msg)
{
if (strcmp(msg->getName(), “authRequest”) == 0) {
authenticate(msg);
}
}
void SSHServer::authenticate(cMessage *msg)
{
EV << “Authenticating SSH Request” << endl;
// Simulate authentication process
cMessage *authResponse = new cMessage(“authResponse”);
send(authResponse, “out”);
delete msg;
}
This server module authenticates the client and sends back a response indicating success.
Example of encrypting and decrypting messages:
class SSHEngine : public cSimpleModule
{
protected:
virtual void handleMessage(cMessage *msg) override;
void encryptMessage(cMessage *msg);
void decryptMessage(cMessage *msg);
};
void SSHEngine::handleMessage(cMessage *msg)
{
if (strcmp(msg->getKind(), “encrypt”) == 0) {
encryptMessage(msg);
} else if (strcmp(msg->getKind(), “decrypt”) == 0) {
decryptMessage(msg);
}
send(msg, “out”);
}
void SSHEngine::encryptMessage(cMessage *msg)
{
EV << “Encrypting SSH Message: ” << msg->getName() << endl;
std::string encryptedData = “Encrypted_” + std::string(msg->getName());
msg->setName(encryptedData.c_str());
}
void SSHEngine::decryptMessage(cMessage *msg)
{
EV << “Decrypting SSH Message: ” << msg->getName() << endl;
std::string decryptedData = msg->getName();
decryptedData.erase(0, 10); // Remove “Encrypted_” prefix
msg->setName(decryptedData.c_str());
}
This module emulate the encryption and decryption of SSH messages by adjust the message content.
Example of sending a command from the client to the server:
void SSHClient::handleMessage(cMessage *msg)
{
if (strcmp(msg->getName(), “authResponse”) == 0) {
EV << “SSH Authentication Successful. Executing command…” << endl;
cMessage *command = new cMessage(“encrypt”);
command->setKind(“encrypt”);
command->addPar(“command”) = “ls -la”;
send(command, “out”);
}
delete msg;
}
The server would then decrypt and execute the command:
void SSHServer::handleMessage(cMessage *msg)
{
if (strcmp(msg->getKind(), “decrypt”) == 0) {
decryptMessage(msg);
EV << “Executing Command: ” << msg->par(“command”).stringValue() << endl;
// Simulate command execution (e.g., list files)
delete msg;
}
}
Example .ini file configuration:
network = SSHNetwork
sim-time-limit = 100s
*.client.numApps = 1
*.client.app[0].typename = “SSHClient”
*.server.numApps = 1
*.server.app[0].typename = “SSHServer”
*.router.pppg[*].queue.typename = “DropTailQueue” # Optional, for simulating network conditions
This configuration executes the SSH simulation with a client and server, and an optional router to emulate the network conditions.
In this module, we had gain knowledge about the network secure shell in the OMNeT++ tool that is helpful to transmit the information securely in the network simulation. It you have any query regarding the network secure shell we will help to provide it. Regarding Network Secure Shell in OMNeT++we are ready to support you with implementation process. Get your network performance done right from our developers.