A robust discovery service for detecting and recording malicious port access, enhancing network security through active monitoring.
$ dotnet add package Walter.Net.HoneyPotThe honey pot detector allows to detect and interact with applications that are attempting to communicate with your server via a particular port. Understanding who is maliciously trying to exploit the system helps identify bad actors and will allow you to tune the system alerting an attempt by a system classified as being a bad actor and will allow the framework to block any requests and or return a payload.
Integrating the honey-pot listener takes 3 steps.
Foreword ports in your edge switch to ports monitored by the honey-pot configuration. A recommendation is to map the ports to a free port not used by the server. An example map port 22 to port 60022 and configure the honey-port to watch any communication on port 4000
Configure the firewall to allow communication on port 4000.
Configure the application to subscribe to the port detections. To do this in the firewall you should use a configuration similar to this:
services.AddFireWall()
.UsePortScannerProtection(connectionString: DatabaseConnections.FireWallState, options =>
{
/* map the service ports to a local port on your computer
* Redirect the requests to your computer and open the firewall
* for the redirected ports */
options.SSH = 4000; // map port 22 to port 4000 on your router
options.TSQL = 4001; // map port 1433 to port 4001 on your router
options.Telnet = 4002; // map port 23 to port 4002 on your router
options.MYSQL = 4005; // map port 3306 to port 4005 on your router
options.DNS = 4006; // map port 53 to port 4005 on your router
options.Telnet 4007; //map port 23 to port 4007 on your router;
/*you can manually map port aliases in the range from 0 till 65535*/
options.AddOrUpdate(externalPort: 587, internalPort: 4007, name: "ESMTP Extended Simple Mail Transfer Protocol");
options.AddOrUpdate(externalPort: 647, internalPort: 4008, name: "DHCP Fail-over");
/*Record up-to 8,000 character when someone is trying to attack the service for legal reporting*/
options.MaximumDataSizeToAccept = 254;
/*Look between every 100ms and 30000ms if someone is trying to gain access to the system */
options.PoolFrequency = 100;
/* Add a default reply to any connection, you can send an auto-reply
* You can use the template values:
* {IP} - the attackers IP address
* {Port}- the port being attacked
* {Name}- the name of the alias being used
* {ISP} - the name of the Internet service provider that the attacker is using will be injected
* {Country} - the country name will be injected
* to personalize the message or leave it blank to record silently*/
options.DefaultReply = "This service is being monitored and we have detected your intentions attack {Name}" +
" via {IP}:{Port} to gain unlawful access to the system, please note that any unlawful" +
" activity will be reported to {ISP} as well as the relevant authorities in {Country}";
})
The above code assumes that you are using the FireWall from NuGet package Walter.Web.FireWall. If you are using any of the services that you are monitoring then map the default ports to custom ports on your router there are 2 steps for this:
You can configure the honey-pot service to enable ports and protocols via json file and there is no need to hard-code this using the action ad compile time
A sample of how to integrate and bind the options using configuration by binding using IConfiguration section, in this sample the section is named HoneyPot and is consumed like so:
public static T ConfigureDI<T>(this T service, IConfiguration configuration) where T : IServiceCollection
{
// your other configurations
service.AddSingleton<IConfiguration>(configuration);
service.UsePortScannerProtection( connectionString: configuration.GetConnectionString("PortScanner")! //-> connection string to log in database tables will be generated as needed but the connections needs DDL rights
, configurationSection: configuration.GetRequiredSection("HoneyPot")); //-> configure honey pot ports
return service;
}
To allow the binding to work you can use the bellow sample json setting:
"HoneyPot": {
"DefaultReply": null,
"BlockThePort": true,
"EnableLogging": true,
"IgnoreAfterDetection": "DoNotIgnore",
"LogDataForAudit": true,
"MaximumDataSizeToAccept": 512,
"PoolFrequency": 1000,
"RemoteHoneyPotClientName": "Remove-To-Use-Machine-Name",
"RemoteHoneyPotClientPort": 1200,
"TracertAttackers": true,
"Caching": {
"SlidingExpiration": "00:20:00",
"Priority": "Normal"
},
"ConnectionDetails": {
"DataRetention": "30.00:00:00" // 30 days in TimeSpan format
},
"DNS": 4053,
"Echo": 4007,
"Finger": 4079,
"FTP": 4020,
"ICP": 4029,
"IMAP": 4143,
"IPsec": 4050,
"LDAP": 4389,
"MYSQL": 4306,
"NetBIOS_CIFS": 4137,
"NetBIOS_PNS": 4136,
"NetBIOS_RPC": 4135,
"NetBIOS_SMB": 4139,
"NNTP": 4119,
"OpenEdge": 42031,
"Oracle": 41521,
"POP3": 4110,
"RemoteDesktop": 4389,
"SecureFTP": 4989,
"SecureIMAP": 4993,
"SMTP": 4025,
"SNMP": 4161,
"SSH": 4022,
"Sybase": 42638,
"Telnet": 4023,
"Tomcat": 4843,
"TSQL": 4433,
"WindowsAdministrationCenter": 46516
},
The Default is IPAddressAndPort, this will ignore the IPAddress and port as the detector assumes you block any future requests from the IP address.
The values assignable to IgnoreAfterDetection are:
/// <summary>
/// The scope of how to ignore future request after having been detected
/// </summary>
/// <remarks>The Default is to ignore the IPAddress and port as the detector assumes you block any future requests from the IP address </remarks>
public enum IgnoreScope
{
/// <summary>
/// Ignore the IP address and port on future requests
/// </summary>
IPAddressAndPort = 0,
/// <summary>
/// Ignore the IP Address but any other requests from the IP address with a different port trigger a response
/// </summary>
IPAddress = 1,
/// <summary>
/// Do not ignore any future requests and trigger a honey-pot response
/// </summary>
DoNotIgnore = 2,
}
Please note that a lot of attackers are looking for victims using port scanners to target venerable IP addresses before attacking a system. You can have a look here and see how these attacks are being executed.