#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
#include "SSD1306Ascii.h" // not a default arduino library Used the SSD1306ASCII Libraries instead of adafruit to stop the warning of memory exceeds
#include "SSD1306AsciiAvrI2c.h" //not a default arduino library https://github.com/greiman/SSD1306Ascii
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
IPAddress ip (192, 168, 1, 177);
IPAddress gateway (192, 168, 1, 1);
IPAddress subnet (255, 255, 255, 0);
EthernetServer server (23);
boolean alreadyConnected = false;
String fakeuser = "";
String telnetinput = "";
String password = "";
byte x = 1;
unsigned short attempts;
File logFile;
bool dhcpstatus;
// for use of OLED display can be removed or commented out with no issue
#define I2C_ADDRESS 0x3C //I2C address can change depending on screen
SSD1306AsciiAvrI2c oled;
// end of OLED defines
//int LEDPIN = 3;
void setup()
{
Serial.begin (9600);
if(Ethernet.begin(mac) == 0) {
// Serial.println("Did not get DHCP address instead using defined IP settings");
Ethernet.begin (mac, ip, gateway, subnet);
dhcpstatus = false;
} else {
// Serial.println("Using DHCP IP address");
dhcpstatus = true;
}
Serial.print ("current IP address: ");
Serial.println (Ethernet.localIP ());
if (!SD.begin(4)) {
// Serial.println("SD card intialization failed!");
return;
}
//Serial.println("SD card initialized properly");
//commented out to get memory to useable state without warnings
// logFile = SD.open("attack.log", FILE_WRITE); // FAT 16 remember file name max '8+3
// if (logFile) {
// logFile.println("booted");
// logFile.close();
// Serial.println("file opened, then closed assuming working");
// } else {
// Serial.println("SD card error");
//}
oled.begin(&Adafruit128x64, I2C_ADDRESS);
oled.setFont(Adafruit5x7);
uint32_t m = micros();
oled.clear();
//notification led blink
//pinMode(LEDPIN, OUTPUT); //don't use pin 13 the default led on Arduino as it is used by the SD card on the ethernet shield
//digitalWrite(LEDPIN, LOW); Serial.println("LED OFF to start");
}
void loop() {
EthernetClient client = server.available ();
if (client) {
if (!alreadyConnected) {
client.flush();
Serial.println("telnet connected");
server.println("telnet connected");
server.print ("user: ");
alreadyConnected = true;
}
while (client.available()){
char newChar = client.read();
if (newChar == 0x0D){ //newline? could be '\n' username completed yet?
if(x == 1) {
fakeuser = telnetinput;
telnetinput = "";
++x;
} else {
password = telnetinput;
telnetinput = "";
++x;
}
if ( x <= 2) {
// digitalWrite(3, HIGH); //light up led for notification
// Serial.print("User:");
// Serial.print(fakeuser);
// Serial.println(" has started an attempt to login");
}
if ( x > 2) {
// digitalWrite(LEDPIN, HIGH); //light up led for notification
Serial.print("user:");
Serial.print(fakeuser);
Serial.print(":password:");
Serial.print(password);
//Serial.print(" counter: "); //debugging
//Serial.println(x); //debugging
++attempts;
Serial.print(":attempt#:");
Serial.println(attempts);
//oled display of current attempt comment out if not needed
oled.clear();
oled.print("IP:");
oled.println(Ethernet.localIP ());
oled.print("Using DHCP: ");
oled.print(dhcpstatus ? "Yes" : "No");
oled.println("");
oled.println("User:");
oled.println(fakeuser);
oled.println("Password:");
oled.println(password);
oled.print("attempt#: ");
oled.println(attempts);
//end of oled display to be commented out
logFile = SD.open("attack.log", FILE_WRITE); // FAT 16 remember file name max '8+3
if (logFile) {
logFile.print("user:");
logFile.print(fakeuser);
logFile.print(":Password:");
logFile.print(password);
logFile.print(":attempt#:");
logFile.println(attempts);
logFile.close();
Serial.println("Attempt logged to file");
} else {
Serial.println("SD card error attempt not logged");
}
}
if (x == 5) { // after 3rd password failure disconnect current attack and reset things to zero
client.stop();
alreadyConnected = false;
fakeuser = "";
telnetinput = "";
password = "";
x = 1;
//digitalWrite(3, LOW); Serial.println("LED OFF");//turn off LED for next try
}
client.flush();
delay(2000); // give a delay make the attacker think they are authenticating against something
oled.clear(); // turn off oled
server.print("password:");
// digitalWrite(3, LOW); Serial.println("LED OFF"); //turn off LED for next try
} else {
if(isPrintable(newChar)){ //clean up output likes to put newlines for passwords and lots of junk on intial login
if(x == 1) { //first attempt will be the login lets just capture alphanumberics
if(isAlphaNumeric(newChar)){
telnetinput += newChar;
}
} else {
telnetinput += newChar; //add adiditional character to the user trying to authenticate untill newline is entered
client.flush();
}
}
}
}
}
}