Skip to content

Commit

Permalink
Version 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mudmin committed Feb 2, 2021
1 parent 815b232 commit 8a38463
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 23 deletions.
31 changes: 21 additions & 10 deletions ESPCanary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@
WiFiServer ftpServer( FTP_CTRL_PORT );
WiFiServer dataServer( FTP_DATA_PORT_PASV );

void FtpServer::begin(String uname, String pword, String canary)
void FtpServer::begin(String uname, String pword, String canary, bool append_ip, String append_char)
{
// Tells the ftp server to begin listening for incoming connection
_FTP_USER=uname;
_FTP_PASS = pword;
_FTP_CAN = canary;
_FTP_APPEND_IP = append_ip;
_FTP_APPEND_CHAR = append_char;

ftpServer.begin();
delay(10);
Expand Down Expand Up @@ -120,20 +122,29 @@ void FtpServer::handleFTP()
Serial.println(remoteip);
Serial.println("Attempting Canary");
HTTPClient http;
http.begin(_FTP_CAN);
http.addHeader("Content-Type", "text/plain");
String token = _FTP_CAN;
if(_FTP_APPEND_IP){
token = token + _FTP_APPEND_CHAR;
token = token + remoteip;
}
Serial.print("Connecting to ");
Serial.println(token);
http.begin(token);
http.setUserAgent(remoteip);


//if you have your own canary-type service and want to post paramaters,
//do it in JSON here
//feel free to use the ArduinoJSON libarary for more complicated JSON
String message = "{\"ip\":\"";
message = message + remoteip;
message = message + "\"}";
Serial.println("POSTing JSON");
Serial.println(message);
// String message = "{\"ip\":\"";
// message = message + remoteip;
// message = message + "\"}";
// http.addHeader("Content-Type", "text/plain");
// Serial.println("POSTing JSON");
// Serial.println(message);

int httpCode = http.POST(message);
http.end();
// String payload = http.getString();
// Serial.println(payload);
millisEndConnection = millis() + millisTimeOut;
}
else
Expand Down
4 changes: 3 additions & 1 deletion ESPCanary.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
class FtpServer
{
public:
void begin(String uname, String pword, String canary);
void begin(String uname, String pword, String canary, bool append_ip, String append_char);
void handleFTP();

private:
Expand Down Expand Up @@ -105,6 +105,8 @@ class FtpServer
String _FTP_USER;
String _FTP_PASS;
String _FTP_CAN;
bool _FTP_APPEND_IP;
String _FTP_APPEND_CHAR;



Expand Down
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,19 @@ someone is snooping. For a little bit more advanced tracking, use the other can

Note that although it looks like users can upload and rename the files on your FTP server, that's all smoke and mirrors. Those changes are flushed away when the user reloads the files and are never actually present on the ESP.

To connect to the ESP over FTP, grab the ip from the serial monitor and connect with admin, any password, port 21. You may have to check a box to allow insecure connections.
When you configure your FTP server, you can choose to specify a username and/or password that is allowed
to connect to the server or substitute % for either of those so that any string will do!

I'm clearly not a C developer if you want to contribute and help make this project better!
To connect to the ESP over FTP, grab the ip from the serial monitor and connect with your username and password along with port 21. You may have to check a box to allow insecure connections.

When someone connects to your FTP server, it will fire off the canary and you will get an email. In that
email, the Source IP will be the IP of your server and the User Agent will be the IP address of the
incoming connection to your server.

If you do not want to use canarytokens.org, you can specify any webhook url and the offending IP
can be appended to your query string as an additional parameter.

I'm clearly not a C developer if you want to contribute and help make this project better!

This is a fork of the https://github.com/nailbuster/esp8266FTPServer library by David Paiva.
Thanks to the people at https://thinkst.com for offering tech support and providing canary tokens for free.
20 changes: 12 additions & 8 deletions examples/SimpleHoneypot/SimpleHoneypot.ino
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ uint8_t newMACAddress[] = {0x00, 0x11, 0x32, 0x07, 0x0D, 0x66};

const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASS";
String canary = "PASTE_CANARY TOKEN HERE";


String canary = "PASTE_CANARY TOKEN HERE"; //grab FREE web bug/URL tokens at http://canarytokens.org
String ftp_user = "admin"; //if you replace this with "%" it will accept ANY username
String ftp_pass = "password"; //if you replace this with "%" it will accept ANY password
bool append_ip = false; //if you are using a canary token, leave this as false
String append_char = "?"; //if you are using a canary token, this doesn't matter
//if you are using your own webhook,with a bunch of GET
//parameters then you would want this to be "&" so the IP
//address becomes the final GET parameter

FtpServer ftpSrv; //set #define FTP_DEBUG in ESPCanary.h to see ftp verbose on serial


void setup(void){
Serial.begin(115200);

Expand Down Expand Up @@ -66,18 +70,18 @@ void setup(void){
Serial.print("MAC address: ");
Serial.println(WiFi.macAddress());

/////FTP Setup, ensure SPIFFS is started before ftp; /////////
/////FTP Setup, ensure SPIFFS is started before ftp; /////////
#ifdef ESP32 //esp32 we send true to format spiffs if cannot mount
if (SPIFFS.begin(true)) {
#elif defined ESP8266
if (SPIFFS.begin()) {
#endif
Serial.println("SPIFFS opened!");
ftpSrv.begin("admin","password",canary); //username, password for ftp. set ports in ESPCanary.h (default 21, 50009 for PASV)
ftpSrv.begin(ftp_user,ftp_pass,canary,append_ip,append_char); //username, password for ftp. set ports in ESPCanary.h (default 21, 50009 for PASV)
}
}
void loop(void){

void loop(){
ftpSrv.handleFTP(); //make sure in loop you call handleFTP()!!
// server.handleClient(); //example if running a webserver you still need to call .handleClient();

}
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name=ESPCanary
version=1.0.3
author=Dan Hoover <[email protected]>
version=2.0.0
author=Dan Hoover <[email protected]>
maintainer=Dan Hoover <[email protected]>
sentence=Create an ESP32 or ESP8266 OpenCanary Honeypot
paragraph=Create an ESP32 or ESP8266 OpenCanary Honeypot
Expand Down

0 comments on commit 8a38463

Please sign in to comment.