public override void Bad() { if (true) { TcpListener listener = null; TcpClient tcpConn = null; Stream streamOutput = null; int port = 20000; try { listener = new TcpListener(IPAddress.Parse("10.10.1.10"), port); listener.Start(); tcpConn = listener.AcceptTcpClient(); /* INCIDENTAL: Use of Socket */ /* FLAW: IP-based Logic */ IPEndPoint endPoint = (IPEndPoint)tcpConn.Client.RemoteEndPoint; IPAddress ipAddress = endPoint.Address; IPHostEntry hostEntry = Dns.GetHostEntry(ipAddress); if (hostEntry.Equals("192.168.30.123")) { streamOutput = tcpConn.GetStream(); streamOutput.Write(Encoding.UTF8.GetBytes("Welcome, admin!"), 0, "Welcome, admin!".Length); } else { streamOutput = tcpConn.GetStream(); streamOutput.Write(Encoding.UTF8.GetBytes("Welcome, user."), 0, "Welcome, user.".Length); } } catch (IOException exceptIO) { IO.Logger.Log(NLog.LogLevel.Warn, exceptIO, "Could not connect to port " + port.ToString()); } finally { try { if (streamOutput != null) { streamOutput.Close(); } } catch (IOException exceptIO) { IO.Logger.Log(NLog.LogLevel.Warn, exceptIO, "Error closing objects"); } try { if (tcpConn != null) { tcpConn.Close(); } } catch (IOException exceptIO) { IO.Logger.Log(NLog.LogLevel.Warn, exceptIO, "Error closing objects"); } try { if (listener != null) { listener.Stop(); } } catch (IOException exceptIO) { IO.Logger.Log(NLog.LogLevel.Warn, exceptIO, "Error closing objects"); } } } }