From 42be620fa5a07027c41bfb2b4f8b23a1ac794c55 Mon Sep 17 00:00:00 2001 From: shellster Date: Wed, 4 Jan 2023 16:43:44 -0700 Subject: [PATCH 1/2] Initial updates --- .gitignore | 3 +- Source Code/esprfidtool/WiegandNG.cpp | 4 +- Source Code/esprfidtool/aba2str.h | 3 - Source Code/esprfidtool/api.h | 59 ++++++----- Source Code/esprfidtool/api_server.h | 12 +-- Source Code/esprfidtool/esprfidtool.ino | 131 +++++++++++------------- Source Code/esprfidtool/version.h | 4 +- 7 files changed, 104 insertions(+), 112 deletions(-) diff --git a/.gitignore b/.gitignore index fb673bb..df8aff6 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -*bin \ No newline at end of file +*bin +Source Code/esprfidtool/build/ \ No newline at end of file diff --git a/Source Code/esprfidtool/WiegandNG.cpp b/Source Code/esprfidtool/WiegandNG.cpp index d3d8653..8866081 100644 --- a/Source Code/esprfidtool/WiegandNG.cpp +++ b/Source Code/esprfidtool/WiegandNG.cpp @@ -86,13 +86,13 @@ bool WiegandNG::available() { return ret; } -void WiegandNG::ReadD0 () { +ICACHE_RAM_ATTR void WiegandNG::ReadD0 () { _bitCounted++; // increment bit count for Interrupt connected to D0 shift_left(_buffer,_bufferSize,1); // shift 0 into buffer _lastPulseTime = millis(); // keep track of time last wiegand bit received } -void WiegandNG::ReadD1() { +ICACHE_RAM_ATTR void WiegandNG::ReadD1() { _bitCounted++; // increment bit count for Interrupt connected to D1 if (_bitCounted > (_bufferSize * 8)) { _bitCounted=0; // overflowed, diff --git a/Source Code/esprfidtool/aba2str.h b/Source Code/esprfidtool/aba2str.h index 57ee4b9..c2a4d72 100644 --- a/Source Code/esprfidtool/aba2str.h +++ b/Source Code/esprfidtool/aba2str.h @@ -1,10 +1,7 @@ String aba2str (String magstripe, int magStart, int magEnd, String swipeDirection) { - //f.println(String()+"Start pos:"+magStart); - //f.println(String()+"Start pos:"+magEnd); String ABA=""; String aba2str=""; int magCount=abs(magEnd-magStart); - //f.println(String()+"magCount:"+magCount); aba2str=(String()+"\"Cleaned\" Binary:"+magstripe.substring(magStart,magEnd)+"\n"); aba2str+=(String()+" * Possible "+swipeDirection+" Card Data\(ASCII\):"); while (magCount>0) { diff --git a/Source Code/esprfidtool/api.h b/Source Code/esprfidtool/api.h index 952d0fe..d3b9942 100644 --- a/Source Code/esprfidtool/api.h +++ b/Source Code/esprfidtool/api.h @@ -40,13 +40,12 @@ void apiinfo(int prettify) { freespace=fs_info.totalBytes-fs_info.usedBytes; const size_t bufferSize = JSON_ARRAY_SIZE(5) + JSON_OBJECT_SIZE(3); - DynamicJsonBuffer jsonAPIbuffer(bufferSize); - JsonObject& apilog = jsonAPIbuffer.createObject(); + DynamicJsonDocument apilog(bufferSize); apilog["Device"] = "ESP-RFID-Tool"; apilog["Firmware"] = version; apilog["API"] = APIversion; - JsonObject& apifs = apilog.createNestedObject("File System"); + JsonObject apifs = apilog.createNestedObject("File System"); apifs["Total Space"]=total; apifs["Used Space"]=used; apifs["Free Space"]=freespace; @@ -54,14 +53,15 @@ void apiinfo(int prettify) { String API_Response=""; if (prettify==1) { - apilog.prettyPrintTo(API_Response); + serializeJsonPretty(apilog, API_Response); } else { - apilog.printTo(API_Response); + serializeJson(apilog, API_Response); } server.send(200, "application/json", API_Response); delay(50); - jsonAPIbuffer.clear(); + apifs.clear(); + apilog.clear(); } void apilistlogs(int prettify) { @@ -72,15 +72,14 @@ void apilistlogs(int prettify) { while (dir.next()) { File f = dir.openFile("r"); String FileName = dir.fileName(); - if((!FileName.startsWith("/payloads/"))&&(!FileName.startsWith("/esploit.json"))&&(!FileName.startsWith("/esportal.json"))&&(!FileName.startsWith("/esprfidtool.json"))&&(!FileName.startsWith("/config.json"))) { + if((!FileName.startsWith("/esprfidtool.json"))&&(!FileName.startsWith("/config.json"))) { logcount++; } f.close(); } const size_t bufferSize = JSON_ARRAY_SIZE(5) + JSON_OBJECT_SIZE(1); - DynamicJsonBuffer jsonAPIbuffer(bufferSize); - JsonObject& apilog = jsonAPIbuffer.createObject(); + DynamicJsonDocument apilog(bufferSize); apilog["Device"] = "ESP-RFID-Tool"; apilog["Firmware"] = version; @@ -92,10 +91,10 @@ void apilistlogs(int prettify) { while (dir2ndrun.next()) { File f = dir2ndrun.openFile("r"); String FileName = dir2ndrun.fileName(); - if ((!FileName.startsWith("/payloads/"))&&(!FileName.startsWith("/esploit.json"))&&(!FileName.startsWith("/esportal.json"))&&(!FileName.startsWith("/esprfidtool.json"))&&(!FileName.startsWith("/config.json"))) { + if ((!FileName.startsWith("/esprfidtool.json"))&&(!FileName.startsWith("/config.json"))) { currentlog++; FileName.remove(0,1); - JsonObject& apilistlogs = apilog.createNestedObject(String(currentlog)); + JsonObject apilistlogs = apilog.createNestedObject(String(currentlog)); apilistlogs["File Name"]=FileName; } f.close(); @@ -103,14 +102,14 @@ void apilistlogs(int prettify) { String API_Response=""; if (prettify==1) { - apilog.prettyPrintTo(API_Response); + serializeJsonPretty(apilog, API_Response); } else { - apilog.printTo(API_Response); + serializeJson(apilog, API_Response);; } server.send(200, "application/json", API_Response); delay(50); - jsonAPIbuffer.clear(); + apilog.clear(); } void apilog(String logfile,int prettify) { @@ -131,33 +130,35 @@ void apilog(String logfile,int prettify) { } } f.close(); - const size_t bufferSize = JSON_ARRAY_SIZE(6) + JSON_OBJECT_SIZE(4); - DynamicJsonBuffer jsonAPIbuffer(bufferSize); - JsonObject& apilog = jsonAPIbuffer.createObject(); + DynamicJsonDocument apilog(2048); apilog["Device"] = "ESP-RFID-Tool"; apilog["Firmware"] = version; apilog["API"] = APIversion; apilog["Log File"] = logfile; - apilog["Captures"] = apiCAPTUREcount; + apilog["CaptureCount"] = apiCAPTUREcount; + + JsonArray captures = apilog.createNestedArray("Captures"); int apiCURRENTcapture=0; File f = SPIFFS.open(String()+"/"+logfile, "r"); + DynamicJsonDocument apiCURRENTcaptureOBJECT(1024); + while(f.available()) { String line = f.readStringUntil('\n'); - if(line.indexOf(",Binary:") > 0) { + int firstIndex = line.indexOf(",Binary:"); + + if(firstIndex > -1) { apiCURRENTcapture++; - int firstIndex = line.indexOf(",Binary:"); int secondIndex = line.indexOf(",", firstIndex + 1); String binaryCaptureLINE=line.substring(firstIndex+8, secondIndex); if ( binaryCaptureLINE.indexOf(" ") > 0 ) { binaryCaptureLINE=binaryCaptureLINE.substring(binaryCaptureLINE.indexOf(" ")+1); } binaryCaptureLINE.replace("\r",""); - JsonObject& apiCURRENTcaptureOBJECT = apilog.createNestedObject(String(apiCURRENTcapture)); - apiCURRENTcaptureOBJECT["Bit Count"]=binaryCaptureLINE.length(); - apiCURRENTcaptureOBJECT["Binary"]=binaryCaptureLINE; + apiCURRENTcaptureOBJECT["Bit Count"] = binaryCaptureLINE.length(); + apiCURRENTcaptureOBJECT["Binary"] = binaryCaptureLINE; if(line.indexOf(",HEX:") > 0) { int hfirstIndex = line.indexOf(",HEX:"); int hsecondIndex = line.indexOf(",", hfirstIndex + 1); @@ -168,22 +169,24 @@ void apilog(String logfile,int prettify) { if(line.indexOf(",Keypad Code:") > 0) { int kfirstIndex = line.indexOf(",Keypad Code:"); int ksecondIndex = line.indexOf(",", kfirstIndex + 1); - String pinCURRENT=line.substring(kfirstIndex+13, ksecondIndex); + String pinCURRENT = line.substring(kfirstIndex + 13, ksecondIndex); pinCURRENT.replace("\r",""); - apiCURRENTcaptureOBJECT["Keypad Press"]=pinCURRENT; + apiCURRENTcaptureOBJECT["Keypad Press"] = pinCURRENT; } + + captures.add(apiCURRENTcaptureOBJECT); } } f.close(); String API_Response=""; if (prettify==1) { - apilog.prettyPrintTo(API_Response); + serializeJsonPretty(apilog, API_Response); } else { - apilog.printTo(API_Response); + serializeJson(apilog, API_Response);; } server.send(200, "application/json", API_Response); delay(50); - jsonAPIbuffer.clear(); + apilog.clear(); } } diff --git a/Source Code/esprfidtool/api_server.h b/Source Code/esprfidtool/api_server.h index bb0c9f1..00c0e57 100644 --- a/Source Code/esprfidtool/api_server.h +++ b/Source Code/esprfidtool/api_server.h @@ -21,14 +21,13 @@ server.on("/api/tx/bin", [](){ } const size_t bufferSize = JSON_ARRAY_SIZE(4) + JSON_OBJECT_SIZE(5); - DynamicJsonBuffer jsonAPIbuffer(bufferSize); - JsonObject& apitxbin = jsonAPIbuffer.createObject(); + DynamicJsonDocument apitxbin(bufferSize); apitxbin["Device"] = "ESP-RFID-Tool"; apitxbin["Firmware"] = version; apitxbin["API"] = APIversion; - JsonObject& apitxbinary = apitxbin.createNestedObject("Transmission"); + JsonObject apitxbinary = apitxbin.createNestedObject("Transmission"); int commacount=0; for (int commalook=0; commalook<=api_binary.length(); commalook++) { if (api_binary.charAt(commalook)==',') { @@ -52,14 +51,15 @@ server.on("/api/tx/bin", [](){ else { String API_Response=""; if (prettify==1) { - apitxbin.prettyPrintTo(API_Response); + serializeJsonPretty(apitxbin, API_Response); } else { - apitxbin.printTo(API_Response); + serializeJson(apitxbin, API_Response); } server.send(200, "application/json", API_Response); delay(50); - jsonAPIbuffer.clear(); + apitxbinary.clear(); + apitxbin.clear(); apiTX(api_binary,api_pulsewidth,api_datainterval,api_wait); } }); diff --git a/Source Code/esprfidtool/esprfidtool.ino b/Source Code/esprfidtool/esprfidtool.ino index ed08978..45da74a 100644 --- a/Source Code/esprfidtool/esprfidtool.ino +++ b/Source Code/esprfidtool/esprfidtool.ino @@ -36,7 +36,7 @@ #include #include #include -#include // ArduinoJson library 5.11.0 by Benoit Blanchon https://github.com/bblanchon/ArduinoJson +#include // ArduinoJson library 6.19.4 by Benoit Blanchon https://github.com/bblanchon/ArduinoJson #include // https://github.com/exploitagency/esp8266FTPServer/tree/feature/bbx10_speedup #include #include @@ -384,6 +384,11 @@ void LogWiegand(WiegandNG &tempwg) { break; } + //This happens on boot so we filter it. + if(unknown && countedBits == 2) { + return; + } + File f = SPIFFS.open("/"+String(logname), "a"); //Open the log in append mode to store capture int preambleLen; if (unknown==true && countedBits!=4 && countedBits!=8 && countedBits!=248) { @@ -568,7 +573,6 @@ void LogWiegand(WiegandNG &tempwg) { int endSentinel=(magstripe.lastIndexOf("11111")+4); int magStart=0; int magEnd=1; - //f.print("
");
   
     f.print(" * Trying \"Forward\" Swipe,");
     magStart=startSentinel;
@@ -579,19 +583,11 @@ void LogWiegand(WiegandNG &tempwg) {
     char magchar[249];
     magstripe.toCharArray(magchar,249);
     magstripe=String(strrev(magchar));
-    //f.println(String()+"Reverse: "+magstripe);
     magStart=magstripe.indexOf("11010");
     magEnd=(magstripe.lastIndexOf("11111")+4);
     f.println(aba2str(magstripe,magStart,magEnd,"\"Reverse\" Swipe"));
-  
-    //f.print("
"); - //f.println(String()+F(" * You can verify the data at the following URL: https://www.legacysecuritygroup.com/aba-decode.php?binary=")+magstripe+F("")); } -//Debug -// f.print(F("Free heap:")); -// f.println(ESP.getFreeHeap(),DEC); - unknown=false; binChunk3=""; binChunk2exists=false; @@ -599,7 +595,7 @@ void LogWiegand(WiegandNG &tempwg) { cardChunk1 = 0; cardChunk2 = 0; binChunk2len=0; - f.close(); //done + f.close(); } #include "api.h" @@ -798,8 +794,7 @@ void handleSubmitSettings() } bool loadDefaults() { - StaticJsonBuffer<500> jsonBuffer; - JsonObject& json = jsonBuffer.createObject(); + StaticJsonDocument<500> json; json["version"] = version; json["accesspointmode"] = "1"; json["ssid"] = "ESP-RFID-Tool"; @@ -822,9 +817,9 @@ bool loadDefaults() { json["txdelayms"] = "2"; json["safemode"] = "0"; File configFile = SPIFFS.open("/esprfidtool.json", "w"); - json.printTo(configFile); + serializeJson(json, configFile); configFile.close(); - jsonBuffer.clear(); + json.clear(); loadConfig(); } @@ -839,8 +834,8 @@ bool loadConfig() { std::unique_ptr buf(new char[size]); configFile.readBytes(buf.get(), size); - StaticJsonBuffer<500> jsonBuffer; - JsonObject& json = jsonBuffer.parseObject(buf.get()); + StaticJsonDocument<500> json; + deserializeJson(json, buf.get()); if (!json["version"]) { delay(3500); @@ -885,60 +880,29 @@ bool loadConfig() { IPAddress subnet; subnet.fromString(subnetstr); -/* - Serial.println(accesspointmode); - Serial.println(ssid); - Serial.println(password); - Serial.println(channel); - Serial.println(hidden); - Serial.println(local_IP); - Serial.println(gateway); - Serial.println(subnet); -*/ WiFi.persistent(false); - //ESP.eraseConfig(); -// Determine if set to Access point mode + if (accesspointmode == 1) { WiFi.disconnect(true); WiFi.mode(WIFI_AP); - -// Serial.print("Starting Access Point ... "); -// Serial.println(WiFi.softAP(ssid, password, channel, hidden) ? "Success" : "Failed!"); WiFi.softAP(ssid, password, channel, hidden); - -// Serial.print("Setting up Network Configuration ... "); -// Serial.println(WiFi.softAPConfig(local_IP, gateway, subnet) ? "Success" : "Failed!"); WiFi.softAPConfig(local_IP, gateway, subnet); - -// WiFi.reconnect(); - -// Serial.print("IP address = "); -// Serial.println(WiFi.softAPIP()); } // or Join existing network else if (accesspointmode != 1) { WiFi.disconnect(true); WiFi.mode(WIFI_STA); -// Serial.print("Setting up Network Configuration ... "); WiFi.config(local_IP, gateway, subnet); -// WiFi.config(local_IP, gateway, subnet); - -// Serial.print("Connecting to network ... "); -// WiFi.begin(ssid, password); WiFi.begin(ssid, password); WiFi.reconnect(); - -// Serial.print("IP address = "); -// Serial.println(WiFi.localIP()); } configFile.close(); - jsonBuffer.clear(); + json.clear(); return true; } bool saveConfig() { - StaticJsonBuffer<500> jsonBuffer; - JsonObject& json = jsonBuffer.createObject(); + StaticJsonDocument<500> json; json["version"] = version; json["accesspointmode"] = accesspointmode; json["ssid"] = ssid; @@ -962,9 +926,9 @@ bool saveConfig() { json["safemode"] = safemode; File configFile = SPIFFS.open("/esprfidtool.json", "w"); - json.printTo(configFile); + serializeJson(json, configFile); configFile.close(); - jsonBuffer.clear(); + json.clear(); return true; } @@ -1073,12 +1037,9 @@ void setup() { server.on("/",[]() { FSInfo fs_info; SPIFFS.info(fs_info); - String total; - total=fs_info.totalBytes; - String used; - used=fs_info.usedBytes; - String freespace; - freespace=fs_info.totalBytes-fs_info.usedBytes; + String total = String(fs_info.totalBytes); + String used = String(fs_info.usedBytes); + String freespace = String(fs_info.totalBytes-fs_info.usedBytes); server.send(200, "text/html", String()+F("ESP-RFID-Tool v")+version+F("
" "
" "by Corey Harding
" @@ -1088,6 +1049,7 @@ void setup() { "File System Info Calculated in Bytes
" "Total: ")+total+" Free: "+freespace+" "+" Used: "+used+F("
-----
" "List Exfiltrated Data
-
" + "Beep and show when card is recorded
-
" "Experimental TX Mode
-
" "Data Conversion Tools
-
" "Configure Settings
-
" @@ -1139,6 +1101,46 @@ void setup() { SPIFFS.remove(deletelog); }); + server.on("/cardbeep", [](){ + server.send(200, "text/html", String()+F( + "Card Beeper\n" + "
\n" + "\n\n\n")); + }); + server.on("/format", [](){ server.send(200, "text/html", F("<- BACK TO INDEX

This will reformat the SPIFFS File System.

Are you sure?

YES - NO")); }); @@ -1739,8 +1741,6 @@ void setup() { wg.clear(); TXstatus=0; dos=0; - - //experimentalStatus=String()+"Transmitting alternating bits: "+binALT; binALT=""; } @@ -1904,8 +1904,6 @@ void setup() { WiFiClient client; client.setNoDelay(1); -// Serial.println("Web Server Started"); - MDNS.begin("ESP"); httpUpdater.setup(&httpServer, update_path, update_username, update_password); @@ -1917,7 +1915,6 @@ void setup() { ftpSrv.begin(String(ftp_username),String(ftp_password)); } -//Start RFID Reader pinMode(LED_BUILTIN, OUTPUT); // LED if (ledenabled==1){ digitalWrite(LED_BUILTIN, LOW); @@ -1927,9 +1924,6 @@ void setup() { } } -// - -//Do It! /////////////////////////////////////////////////////// // LOOP function @@ -1948,9 +1942,6 @@ void loop() } } -//Serial.print("Free heap-"); -//Serial.println(ESP.getFreeHeap(),DEC); - if(wg.available()) { wg.pause(); // pause Wiegand pin interrupts LogWiegand(wg); diff --git a/Source Code/esprfidtool/version.h b/Source Code/esprfidtool/version.h index 2fecc8d..927a1cd 100644 --- a/Source Code/esprfidtool/version.h +++ b/Source Code/esprfidtool/version.h @@ -1,2 +1,2 @@ -String version = "1.2.1"; -String APIversion = "1.0.4"; +String version = "1.3.0"; +String APIversion = "1.0.5"; From 427bdecec19d5d4da3c5246a2d451acab2bc4261 Mon Sep 17 00:00:00 2001 From: shellster Date: Wed, 4 Jan 2023 16:53:30 -0700 Subject: [PATCH 2/2] Update api major version due to breaking changes --- Source Code/esprfidtool/version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source Code/esprfidtool/version.h b/Source Code/esprfidtool/version.h index 927a1cd..f5e2464 100644 --- a/Source Code/esprfidtool/version.h +++ b/Source Code/esprfidtool/version.h @@ -1,2 +1,2 @@ String version = "1.3.0"; -String APIversion = "1.0.5"; +String APIversion = "2.0.0";