A Fake Telnet Server effective?
Posted: Mon Dec 01, 2008 5:11 am
As I have seen several people rely on telnet functionality to do the hacking for them, but I find that unreliable and outdated. So I decided to make a "make-shift" program to host a fake telnet that logged their activity. Would this be effective to teaching them that action may have consequences for their action?
You can use this code for whatever you want.
You can use this code for whatever you want.
Code: Select all
using System;
using System.Collections.Generic;
using System.Text;
namespace FakeServer
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Initializing");
System.Net.Sockets.TcpListener listen = new System.Net.Sockets.TcpListener(23);
List<System.Net.Sockets.TcpClient> clients = new List<System.Net.Sockets.TcpClient>();
listen.Start();
Console.WriteLine("Initialized");
while (listen != null)
{
string log = "";
if (listen.Pending())
{
clients.Add(listen.AcceptTcpClient());
Console.WriteLine("A client connected... " + clients.ToArray()[clients.ToArray().Length - 1].Client.RemoteEndPoint.ToString());
log += clients.ToArray()[clients.ToArray().Length - 1].Client.RemoteEndPoint.ToString() + "\r\n";
clients.ToArray()[clients.ToArray().Length - 1].GetStream().Write(Encoding.Default.GetBytes("Hello and welcome to Telnet Server\r\n"), 0, Encoding.Default.GetByteCount("Hello and welcome to Telnet Server\r\n"));
}
foreach (System.Net.Sockets.TcpClient client in clients.ToArray())
{
if (client.GetStream().DataAvailable == true)
{
byte[] info = new byte[2048];
client.GetStream().Read(info, 0, info.Length);
for (int I = info.Length - 1; I > -1; I--)
{
if (info[I] == 0)
Array.Resize(ref info, info.Length - 1);
else
break;
}
Console.Write(Encoding.Default.GetString(info));
log += client.Client.RemoteEndPoint.ToString() + ": " + Encoding.Default.GetString(info) + "\r\n";
}
}
if (log != "")
{
System.IO.File.AppendAllText("Log.txt", log);
log = "";
}
}
}
}
}