mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-19 21:03:48 -07:00
ADD 'lf nexawatch' by marshmellow42
ADD 'lf securakey' by marshmellow42 ADD 'lf pac' by marshmellow42 chg: parity.h got some love from pm3 master.
This commit is contained in:
parent
c5e04ba927
commit
d2f79fa83f
12 changed files with 444 additions and 58 deletions
|
@ -139,9 +139,12 @@ CMDSRCS = mifarehost.c \
|
||||||
cmdlft55xx.c \
|
cmdlft55xx.c \
|
||||||
cmdlfpcf7931.c \
|
cmdlfpcf7931.c \
|
||||||
cmdlfviking.c \
|
cmdlfviking.c \
|
||||||
|
cmdlfpac.c \
|
||||||
cmdlfpresco.c \
|
cmdlfpresco.c \
|
||||||
cmdlfpyramid.c \
|
cmdlfpyramid.c \
|
||||||
|
cmdlfsecurakey.c \
|
||||||
cmdlfguard.c \
|
cmdlfguard.c \
|
||||||
|
cmdlfnexwatch.c \
|
||||||
cmdlfnedap.c \
|
cmdlfnedap.c \
|
||||||
cmdlfjablotron.c \
|
cmdlfjablotron.c \
|
||||||
cmdlfvisa2000.c \
|
cmdlfvisa2000.c \
|
||||||
|
|
|
@ -1865,51 +1865,6 @@ int CmdIndalaDecode(const char *Cmd)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CmdPSKNexWatch(const char *Cmd)
|
|
||||||
{
|
|
||||||
if (!PSKDemod("", false)) return 0;
|
|
||||||
|
|
||||||
uint8_t preamble[28] = {0,0,0,0,0,1,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
|
||||||
size_t startIdx = 0, size = DemodBufferLen;
|
|
||||||
|
|
||||||
// sanity check.
|
|
||||||
if ( size < sizeof(preamble) + 100) return 0;
|
|
||||||
|
|
||||||
bool invert = false;
|
|
||||||
if (!preambleSearch(DemodBuffer, preamble, sizeof(preamble), &size, &startIdx)){
|
|
||||||
// if didn't find preamble try again inverting
|
|
||||||
if (!PSKDemod("1", false)) return 0;
|
|
||||||
|
|
||||||
size = DemodBufferLen;
|
|
||||||
if (!preambleSearch(DemodBuffer, preamble, sizeof(preamble), &size, &startIdx)) return 0;
|
|
||||||
invert = true;
|
|
||||||
}
|
|
||||||
if (size != 128) return 0;
|
|
||||||
setDemodBuf(DemodBuffer, size, startIdx+4);
|
|
||||||
startIdx = 8+32; //4 = extra i added, 8 = preamble, 32 = reserved bits (always 0)
|
|
||||||
//get ID
|
|
||||||
uint32_t ID = 0;
|
|
||||||
for (uint8_t wordIdx=0; wordIdx<4; wordIdx++){
|
|
||||||
for (uint8_t idx=0; idx<8; idx++){
|
|
||||||
ID = (ID << 1) | DemodBuffer[startIdx+wordIdx+(idx*4)];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//parity check (TBD)
|
|
||||||
|
|
||||||
//checksum check (TBD)
|
|
||||||
|
|
||||||
//output
|
|
||||||
PrintAndLog("NexWatch ID: %d", ID);
|
|
||||||
if (invert){
|
|
||||||
PrintAndLog("DEBUG: Error - NexWatch had to Invert - probably NexKey");
|
|
||||||
for (uint8_t idx=0; idx<size; idx++)
|
|
||||||
DemodBuffer[idx] ^= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
CmdPrintDemodBuff("x");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int CmdPSKIdteck(const char *Cmd) {
|
int CmdPSKIdteck(const char *Cmd) {
|
||||||
|
|
||||||
if (!PSKDemod("", false)) {
|
if (!PSKDemod("", false)) {
|
||||||
|
@ -2624,7 +2579,6 @@ static command_t CommandTable[] =
|
||||||
{"plot", CmdPlot, 1, "Show graph window (hit 'h' in window for keystroke help)"},
|
{"plot", CmdPlot, 1, "Show graph window (hit 'h' in window for keystroke help)"},
|
||||||
{"printdemodbuffer",CmdPrintDemodBuff, 1, "[x] [o] <offset> [l] <length> -- print the data in the DemodBuffer - 'x' for hex output"},
|
{"printdemodbuffer",CmdPrintDemodBuff, 1, "[x] [o] <offset> [l] <length> -- print the data in the DemodBuffer - 'x' for hex output"},
|
||||||
{"pskindalademod", CmdIndalaDecode, 1, "[clock] [invert<0|1>] -- Demodulate an indala tag (PSK1) from GraphBuffer (args optional)"},
|
{"pskindalademod", CmdIndalaDecode, 1, "[clock] [invert<0|1>] -- Demodulate an indala tag (PSK1) from GraphBuffer (args optional)"},
|
||||||
{"psknexwatchdemod",CmdPSKNexWatch, 1, "Demodulate a NexWatch tag (nexkey, quadrakey) (PSK1) from GraphBuffer"},
|
|
||||||
{"rawdemod", CmdRawDemod, 1, "[modulation] ... <options> -see help (h option) -- Demodulate the data in the GraphBuffer and output binary"},
|
{"rawdemod", CmdRawDemod, 1, "[modulation] ... <options> -see help (h option) -- Demodulate the data in the GraphBuffer and output binary"},
|
||||||
{"samples", CmdSamples, 0, "[512 - 40000] -- Get raw samples for graph window (GraphBuffer)"},
|
{"samples", CmdSamples, 0, "[512 - 40000] -- Get raw samples for graph window (GraphBuffer)"},
|
||||||
{"save", CmdSave, 1, "<filename> -- Save trace (from graph window)"},
|
{"save", CmdSave, 1, "<filename> -- Save trace (from graph window)"},
|
||||||
|
|
|
@ -46,7 +46,6 @@ int CmdFSKdemodPyramid(const char *Cmd);
|
||||||
int CmdFSKrawdemod(const char *Cmd);
|
int CmdFSKrawdemod(const char *Cmd);
|
||||||
int CmdPSK1rawDemod(const char *Cmd);
|
int CmdPSK1rawDemod(const char *Cmd);
|
||||||
int CmdPSK2rawDemod(const char *Cmd);
|
int CmdPSK2rawDemod(const char *Cmd);
|
||||||
int CmdPSKNexWatch(const char *Cmd);
|
|
||||||
int CmdPSKIdteck(const char *Cmd);
|
int CmdPSKIdteck(const char *Cmd);
|
||||||
int CmdGrid(const char *Cmd);
|
int CmdGrid(const char *Cmd);
|
||||||
int CmdGetBitStream(const char *Cmd);
|
int CmdGetBitStream(const char *Cmd);
|
||||||
|
|
|
@ -1196,7 +1196,12 @@ int CmdLFfind(const char *Cmd) {
|
||||||
if (ans>0) {
|
if (ans>0) {
|
||||||
PrintAndLog("\nValid Presco ID Found!");
|
PrintAndLog("\nValid Presco ID Found!");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
ans=CmdPacDemod("");
|
||||||
|
if (ans>0) {
|
||||||
|
PrintAndLog("\nValid PAC/Stanley ID Found!");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// TIdemod?
|
// TIdemod?
|
||||||
PrintAndLog("\nNo Known Tags Found!\n");
|
PrintAndLog("\nNo Known Tags Found!\n");
|
||||||
|
@ -1273,12 +1278,15 @@ static command_t CommandTable[] = {
|
||||||
{"io", CmdLFIO, 1, "{ IOPROX RFIDs... }"},
|
{"io", CmdLFIO, 1, "{ IOPROX RFIDs... }"},
|
||||||
{"jablotron", CmdLFJablotron, 1, "{ Jablotron RFIDs... }"},
|
{"jablotron", CmdLFJablotron, 1, "{ Jablotron RFIDs... }"},
|
||||||
{"nedap", CmdLFNedap, 1, "{ Nedap RFIDs... }"},
|
{"nedap", CmdLFNedap, 1, "{ Nedap RFIDs... }"},
|
||||||
|
{"nexwatch", CmdLFNexWatch, 1, "{ NexWatch RFIDs... }"},
|
||||||
{"noralsy", CmdLFNoralsy, 1, "{ Noralsy RFIDs... }"},
|
{"noralsy", CmdLFNoralsy, 1, "{ Noralsy RFIDs... }"},
|
||||||
|
{"pac", CmdLFPac, 1, "{ PAC/Stanley RFIDs...}"},
|
||||||
{"pcf7931", CmdLFPCF7931, 1, "{ PCF7931 RFIDs... }"},
|
{"pcf7931", CmdLFPCF7931, 1, "{ PCF7931 RFIDs... }"},
|
||||||
{"presco", CmdLFPresco, 1, "{ Presco RFIDs... }"},
|
{"presco", CmdLFPresco, 1, "{ Presco RFIDs... }"},
|
||||||
{"pyramid", CmdLFPyramid, 1, "{ Farpointe/Pyramid RFIDs... }"},
|
{"pyramid", CmdLFPyramid, 1, "{ Farpointe/Pyramid RFIDs... }"},
|
||||||
{"ti", CmdLFTI, 1, "{ TI RFIDs... }"},
|
{"ti", CmdLFTI, 1, "{ TI RFIDs... }"},
|
||||||
{"t55xx", CmdLFT55XX, 1, "{ T55xx RFIDs... }"},
|
{"t55xx", CmdLFT55XX, 1, "{ T55xx RFIDs... }"},
|
||||||
|
{"securakey", CmdLFSecurakey, 1, "{ Securakey RFIDs... }"},
|
||||||
{"viking", CmdLFViking, 1, "{ Viking RFIDs... }"},
|
{"viking", CmdLFViking, 1, "{ Viking RFIDs... }"},
|
||||||
{"visa2000", CmdLFVisa2k, 1, "{ Visa2000 RFIDs... }"},
|
{"visa2000", CmdLFVisa2k, 1, "{ Visa2000 RFIDs... }"},
|
||||||
{"config", CmdLFSetConfig, 0, "Set config for LF sampling, bit/sample, decimation, frequency"},
|
{"config", CmdLFSetConfig, 0, "Set config for LF sampling, bit/sample, decimation, frequency"},
|
||||||
|
|
|
@ -44,6 +44,9 @@
|
||||||
#include "cmdlfnoralsy.h" // for NORALSY meny
|
#include "cmdlfnoralsy.h" // for NORALSY meny
|
||||||
#include "cmdlffdx.h" // for FDX-B meny
|
#include "cmdlffdx.h" // for FDX-B meny
|
||||||
#include "cmdlfcotag.h" // for COTAG meny
|
#include "cmdlfcotag.h" // for COTAG meny
|
||||||
|
#include "cmdlfnexwatch.h" //for nexwatch menu
|
||||||
|
#include "cmdlfsecurakey.h" //for securakey menu
|
||||||
|
#include "cmdlfpac.h" // for pac menu
|
||||||
|
|
||||||
#define T55XX_WRITE_TIMEOUT 1500
|
#define T55XX_WRITE_TIMEOUT 1500
|
||||||
|
|
||||||
|
|
100
client/cmdlfnexwatch.c
Normal file
100
client/cmdlfnexwatch.c
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||||
|
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||||
|
// the license.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Low frequency Honeywell NexWatch tag commands
|
||||||
|
// PSK1 RF/16, RF/2, 128 bits long (known)
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include "cmdlfnexwatch.h"
|
||||||
|
#include "proxmark3.h"
|
||||||
|
#include "ui.h"
|
||||||
|
#include "util.h"
|
||||||
|
#include "graph.h"
|
||||||
|
#include "cmdparser.h"
|
||||||
|
#include "cmddata.h"
|
||||||
|
#include "cmdlf.h"
|
||||||
|
#include "lfdemod.h"
|
||||||
|
|
||||||
|
static int CmdHelp(const char *Cmd);
|
||||||
|
|
||||||
|
int CmdPSKNexWatch(const char *Cmd)
|
||||||
|
{
|
||||||
|
if (!PSKDemod("", false)) return 0;
|
||||||
|
|
||||||
|
uint8_t preamble[28] = {0,0,0,0,0,1,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
||||||
|
size_t startIdx = 0, size = DemodBufferLen;
|
||||||
|
|
||||||
|
// sanity check.
|
||||||
|
if ( size < sizeof(preamble) + 100) return 0;
|
||||||
|
|
||||||
|
bool invert = false;
|
||||||
|
if (!preambleSearch(DemodBuffer, preamble, sizeof(preamble), &size, &startIdx)){
|
||||||
|
// if didn't find preamble try again inverting
|
||||||
|
if (!PSKDemod("1", false)) return 0;
|
||||||
|
|
||||||
|
size = DemodBufferLen;
|
||||||
|
if (!preambleSearch(DemodBuffer, preamble, sizeof(preamble), &size, &startIdx)) return 0;
|
||||||
|
invert = true;
|
||||||
|
}
|
||||||
|
if (size != 128) return 0;
|
||||||
|
setDemodBuf(DemodBuffer, size, startIdx+4);
|
||||||
|
//setClockGrid(g_DemodClock, g_DemodStartIdx + ((startIdx+4)*g_DemodClock));
|
||||||
|
startIdx = 8+32; // 8 = preamble, 32 = reserved bits (always 0)
|
||||||
|
//get ID
|
||||||
|
uint32_t ID = 0;
|
||||||
|
for (uint8_t wordIdx=0; wordIdx<4; wordIdx++){
|
||||||
|
for (uint8_t idx=0; idx<8; idx++){
|
||||||
|
ID = (ID << 1) | DemodBuffer[startIdx+wordIdx+(idx*4)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//parity check (TBD)
|
||||||
|
|
||||||
|
//checksum check (TBD)
|
||||||
|
|
||||||
|
//output
|
||||||
|
PrintAndLog("NexWatch ID: %d", ID);
|
||||||
|
if (invert){
|
||||||
|
PrintAndLog("Had to Invert - probably NexKey");
|
||||||
|
for (uint8_t idx=0; idx<size; idx++)
|
||||||
|
DemodBuffer[idx] ^= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
CmdPrintDemodBuff("x");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//by marshmellow
|
||||||
|
//see ASKDemod for what args are accepted
|
||||||
|
int CmdNexWatchRead(const char *Cmd) {
|
||||||
|
// read lf silently
|
||||||
|
//lf_read(true, 10000);
|
||||||
|
|
||||||
|
CmdLFRead("s");
|
||||||
|
getSamples("10000",TRUE);
|
||||||
|
|
||||||
|
// demod and output viking ID
|
||||||
|
return CmdPSKNexWatch(Cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
static command_t CommandTable[] = {
|
||||||
|
{"help", CmdHelp, 1, "This help"},
|
||||||
|
{"demod", CmdPSKNexWatch, 1, "Demodulate a NexWatch tag (nexkey, quadrakey) from the GraphBuffer"},
|
||||||
|
{"read", CmdNexWatchRead, 0, "Attempt to Read and Extract tag data from the antenna"},
|
||||||
|
{NULL, NULL, 0, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
int CmdLFNexWatch(const char *Cmd) {
|
||||||
|
CmdsParse(CommandTable, Cmd);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CmdHelp(const char *Cmd) {
|
||||||
|
CmdsHelp(CommandTable);
|
||||||
|
return 0;
|
||||||
|
}
|
14
client/cmdlfnexwatch.h
Normal file
14
client/cmdlfnexwatch.h
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||||
|
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||||
|
// the license.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Low frequency Honeywell NexWatch tag commands
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
#ifndef CMDLFNEXWATCH_H__
|
||||||
|
#define CMDLFNEXWATCH_H__
|
||||||
|
extern int CmdLFNexWatch(const char *Cmd);
|
||||||
|
extern int CmdPSKNexWatch(const char *Cmd);
|
||||||
|
extern int CmdNexWatchRead(const char *Cmd);
|
||||||
|
#endif
|
102
client/cmdlfpac.c
Normal file
102
client/cmdlfpac.c
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||||
|
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||||
|
// the license.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Low frequency Stanley/PAC tag commands
|
||||||
|
// NRZ, RF/32, 128 bits long (unknown cs)
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
#include "cmdlfpac.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include "proxmark3.h"
|
||||||
|
#include "ui.h"
|
||||||
|
#include "util.h"
|
||||||
|
#include "graph.h"
|
||||||
|
#include "cmdparser.h"
|
||||||
|
#include "cmddata.h"
|
||||||
|
#include "cmdmain.h"
|
||||||
|
#include "cmdlf.h"
|
||||||
|
#include "lfdemod.h" // preamble test
|
||||||
|
|
||||||
|
static int CmdHelp(const char *Cmd);
|
||||||
|
|
||||||
|
// by marshmellow
|
||||||
|
// find PAC preamble in already demoded data
|
||||||
|
int PacFind(uint8_t *dest, size_t *size) {
|
||||||
|
if (*size < 128) return -1; //make sure buffer has data
|
||||||
|
size_t startIdx = 0;
|
||||||
|
uint8_t preamble[] = {1,1,1,1,1,1,1,1,0,0,1,0,0,0,0,0,0,1,0};
|
||||||
|
if (!preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx))
|
||||||
|
return -2; //preamble not found
|
||||||
|
if (*size != 128) return -3; //wrong demoded size
|
||||||
|
//return start position
|
||||||
|
return (int)startIdx;
|
||||||
|
}
|
||||||
|
|
||||||
|
//see NRZDemod for what args are accepted
|
||||||
|
int CmdPacDemod(const char *Cmd) {
|
||||||
|
|
||||||
|
//NRZ
|
||||||
|
if (!NRZrawDemod(Cmd, false)) {
|
||||||
|
if (g_debugMode) PrintAndLog("DEBUG: Error - PAC: NRZ Demod failed");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
size_t size = DemodBufferLen;
|
||||||
|
int ans = PacFind(DemodBuffer, &size);
|
||||||
|
if (ans < 0) {
|
||||||
|
if (g_debugMode) {
|
||||||
|
if (ans == -1)
|
||||||
|
PrintAndLog("DEBUG: Error - PAC: too few bits found");
|
||||||
|
else if (ans == -2)
|
||||||
|
PrintAndLog("DEBUG: Error - PAC: preamble not found");
|
||||||
|
else if (ans == -3)
|
||||||
|
PrintAndLog("DEBUG: Error - PAC: Size not correct: %d", size);
|
||||||
|
else
|
||||||
|
PrintAndLog("DEBUG: Error - PAC: ans: %d", ans);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
setDemodBuf(DemodBuffer, 128, ans);
|
||||||
|
// setClockGrid(g_DemodClock, g_DemodStartIdx + (ans*g_DemodClock));
|
||||||
|
|
||||||
|
//got a good demod
|
||||||
|
uint32_t raw1 = bytebits_to_byte(DemodBuffer , 32);
|
||||||
|
uint32_t raw2 = bytebits_to_byte(DemodBuffer+32, 32);
|
||||||
|
uint32_t raw3 = bytebits_to_byte(DemodBuffer+64, 32);
|
||||||
|
uint32_t raw4 = bytebits_to_byte(DemodBuffer+96, 32);
|
||||||
|
|
||||||
|
// preamble then appears to have marker bits of "10" CS?
|
||||||
|
// 11111111001000000 10 01001100 10 00001101 10 00001101 10 00001101 10 00001101 10 00001101 10 00001101 10 00001101 10 00001101 10 10001100 10 100000001
|
||||||
|
// unknown checksum 9 bits at the end
|
||||||
|
|
||||||
|
PrintAndLog("PAC/Stanley Tag Found -- Raw: %08X%08X%08X%08X", raw1 ,raw2, raw3, raw4);
|
||||||
|
PrintAndLog("\nHow the Raw ID is translated by the reader is unknown");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CmdPacRead(const char *Cmd) {
|
||||||
|
//lf_read(true, 4096*2 + 20);
|
||||||
|
CmdLFRead("s");
|
||||||
|
getSamples("8192",TRUE);
|
||||||
|
return CmdPacDemod(Cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
static command_t CommandTable[] = {
|
||||||
|
{"help", CmdHelp, 1, "This help"},
|
||||||
|
{"demod", CmdPacDemod,1, "Attempt to read and extract tag data from the GraphBuffer"},
|
||||||
|
{"read", CmdPacRead, 0, "Attempt to read and extract tag data from the antenna"},
|
||||||
|
{NULL, NULL, 0, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
int CmdLFPac(const char *Cmd) {
|
||||||
|
clearCommandBuffer();
|
||||||
|
CmdsParse(CommandTable, Cmd);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CmdHelp(const char *Cmd) {
|
||||||
|
CmdsHelp(CommandTable);
|
||||||
|
return 0;
|
||||||
|
}
|
17
client/cmdlfpac.h
Normal file
17
client/cmdlfpac.h
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||||
|
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||||
|
// the license.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Low frequency Securakey tag commands
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
#ifndef CMDLFPAC_H__
|
||||||
|
#define CMDLFPAC_H__
|
||||||
|
|
||||||
|
extern int CmdLFPac(const char *Cmd);
|
||||||
|
extern int CmdPacRead(const char *Cmd);
|
||||||
|
extern int CmdPacDemod(const char *Cmd);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
148
client/cmdlfsecurakey.c
Normal file
148
client/cmdlfsecurakey.c
Normal file
|
@ -0,0 +1,148 @@
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||||
|
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||||
|
// the license.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Low frequency Securakey tag commands
|
||||||
|
// ASK/Manchester, RF/40, 96 bits long (unknown cs)
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
#include "cmdlfsecurakey.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include "proxmark3.h"
|
||||||
|
#include "ui.h"
|
||||||
|
#include "util.h"
|
||||||
|
#include "graph.h"
|
||||||
|
#include "cmdparser.h"
|
||||||
|
#include "cmddata.h"
|
||||||
|
#include "cmdmain.h"
|
||||||
|
#include "cmdlf.h"
|
||||||
|
#include "protocols.h" // for T55xx config register definitions
|
||||||
|
#include "lfdemod.h" // preamble test
|
||||||
|
#include "parity.h" // for wiegand parity test
|
||||||
|
|
||||||
|
static int CmdHelp(const char *Cmd);
|
||||||
|
|
||||||
|
// by marshmellow
|
||||||
|
// find Securakey preamble in already demoded data
|
||||||
|
int SecurakeyFind(uint8_t *dest, size_t *size) {
|
||||||
|
if (*size < 96) return -1; //make sure buffer has data
|
||||||
|
size_t startIdx = 0;
|
||||||
|
uint8_t preamble[] = {0,1,1,1,1,1,1,1,1,1,0,0,1};
|
||||||
|
if (!preambleSearch(dest, preamble, sizeof(preamble), size, &startIdx))
|
||||||
|
return -2; //preamble not found
|
||||||
|
if (*size != 96) return -3; //wrong demoded size
|
||||||
|
//return start position
|
||||||
|
return (int)startIdx;
|
||||||
|
}
|
||||||
|
|
||||||
|
//see ASKDemod for what args are accepted
|
||||||
|
int CmdSecurakeyDemod(const char *Cmd) {
|
||||||
|
|
||||||
|
//ASK / Manchester
|
||||||
|
bool st = false;
|
||||||
|
if (!ASKDemod_ext("40 0 0", false, false, 1, &st)) {
|
||||||
|
if (g_debugMode) PrintAndLog("DEBUG: Error - Securakey: ASK/Manchester Demod failed");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (st) return 0;
|
||||||
|
size_t size = DemodBufferLen;
|
||||||
|
int ans = SecurakeyFind(DemodBuffer, &size);
|
||||||
|
if (ans < 0) {
|
||||||
|
if (g_debugMode) {
|
||||||
|
if (ans == -1)
|
||||||
|
PrintAndLog("DEBUG: Error - Securakey: too few bits found");
|
||||||
|
else if (ans == -2)
|
||||||
|
PrintAndLog("DEBUG: Error - Securakey: preamble not found");
|
||||||
|
else if (ans == -3)
|
||||||
|
PrintAndLog("DEBUG: Error - Securakey: Size not correct: %d", size);
|
||||||
|
else
|
||||||
|
PrintAndLog("DEBUG: Error - Securakey: ans: %d", ans);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
setDemodBuf(DemodBuffer, 96, ans);
|
||||||
|
//setClockGrid(g_DemodClock, g_DemodStartIdx + (ans*g_DemodClock));
|
||||||
|
|
||||||
|
//got a good demod
|
||||||
|
uint32_t raw1 = bytebits_to_byte(DemodBuffer , 32);
|
||||||
|
uint32_t raw2 = bytebits_to_byte(DemodBuffer+32, 32);
|
||||||
|
uint32_t raw3 = bytebits_to_byte(DemodBuffer+64, 32);
|
||||||
|
|
||||||
|
// 26 bit format
|
||||||
|
// preamble ??bitlen reserved EPx xxxxxxxy yyyyyyyy yyyyyyyOP CS? CS2?
|
||||||
|
// 0111111111 0 01011010 0 00000000 0 00000010 0 00110110 0 00111110 0 01100010 0 00001111 0 01100000 0 00000000 0 0000
|
||||||
|
|
||||||
|
// 32 bit format
|
||||||
|
// preamble ??bitlen reserved EPxxxxxxx xxxxxxxy yyyyyyyy yyyyyyyOP CS? CS2?
|
||||||
|
// 0111111111 0 01100000 0 00000000 0 10000100 0 11001010 0 01011011 0 01010110 0 00010110 0 11100000 0 00000000 0 0000
|
||||||
|
|
||||||
|
// x = FC?
|
||||||
|
// y = card #
|
||||||
|
// standard wiegand parities.
|
||||||
|
// unknown checksum 11 bits? at the end
|
||||||
|
uint8_t bits_no_spacer[85];
|
||||||
|
memcpy(bits_no_spacer, DemodBuffer + 11, 85);
|
||||||
|
|
||||||
|
// remove marker bits (0's every 9th digit after preamble) (pType = 3 (always 0s))
|
||||||
|
size = removeParity(bits_no_spacer, 0, 9, 3, 85);
|
||||||
|
if ( size != 85-9 ) {
|
||||||
|
if (g_debugMode) PrintAndLog("DEBUG: Error removeParity: %d", size);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t bitLen = (uint8_t)bytebits_to_byte(bits_no_spacer+2, 6);
|
||||||
|
uint32_t fc=0, lWiegand=0, rWiegand=0;
|
||||||
|
if (bitLen > 40) { //securakey's max bitlen is 40 bits...
|
||||||
|
if (g_debugMode) PrintAndLog("DEBUG: Error bitLen too long: %u", bitLen);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// get left 1/2 wiegand & right 1/2 wiegand (for parity test and wiegand print)
|
||||||
|
lWiegand = bytebits_to_byte(bits_no_spacer + 48 - bitLen, bitLen/2);
|
||||||
|
rWiegand = bytebits_to_byte(bits_no_spacer + 48 - bitLen + bitLen/2, bitLen/2);
|
||||||
|
// get FC
|
||||||
|
fc = bytebits_to_byte(bits_no_spacer+49-bitLen, bitLen-2-16);
|
||||||
|
|
||||||
|
// test bitLen
|
||||||
|
if (bitLen != 26 && bitLen != 32)
|
||||||
|
PrintAndLog("***unknown securakey bitLen - share with forum***");
|
||||||
|
|
||||||
|
uint32_t cardid = bytebits_to_byte(bits_no_spacer+8+23, 16);
|
||||||
|
// test parities - evenparity32 looks to add an even parity returns 0 if already even...
|
||||||
|
bool parity = !evenparity32(lWiegand) && !oddparity32(rWiegand);
|
||||||
|
|
||||||
|
PrintAndLog("Securakey Tag Found--BitLen: %u, Card ID: %u, FC: 0x%X, Raw: %08X%08X%08X", bitLen, cardid, fc, raw1 ,raw2, raw3);
|
||||||
|
if (bitLen <= 32)
|
||||||
|
PrintAndLog("Wiegand: %08X, Parity: %s", (lWiegand<<(bitLen/2)) | rWiegand, parity ? "Passed" : "Failed");
|
||||||
|
PrintAndLog("\nHow the FC translates to printed FC is unknown");
|
||||||
|
PrintAndLog("How the checksum is calculated is unknown");
|
||||||
|
PrintAndLog("Help the community identify this format further\n by sharing your tag on the pm3 forum or with forum members");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CmdSecurakeyRead(const char *Cmd) {
|
||||||
|
//lf_read(true, 8000);
|
||||||
|
CmdLFRead("s");
|
||||||
|
getSamples("8000",TRUE);
|
||||||
|
return CmdSecurakeyDemod(Cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
static command_t CommandTable[] = {
|
||||||
|
{"help", CmdHelp, 1, "This help"},
|
||||||
|
{"demod", CmdSecurakeyDemod,1, "Attempt to read and extract tag data from the GraphBuffer"},
|
||||||
|
{"read", CmdSecurakeyRead, 0, "Attempt to read and extract tag data from the antenna"},
|
||||||
|
{NULL, NULL, 0, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
int CmdLFSecurakey(const char *Cmd) {
|
||||||
|
clearCommandBuffer();
|
||||||
|
CmdsParse(CommandTable, Cmd);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CmdHelp(const char *Cmd) {
|
||||||
|
CmdsHelp(CommandTable);
|
||||||
|
return 0;
|
||||||
|
}
|
19
client/cmdlfsecurakey.h
Normal file
19
client/cmdlfsecurakey.h
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||||
|
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||||
|
// the license.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Low frequency Securakey tag commands
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
#ifndef CMDLFSECURAKEY_H__
|
||||||
|
#define CMDLFSECURAKEY_H__
|
||||||
|
|
||||||
|
extern int CmdLFSecurakey(const char *Cmd);
|
||||||
|
extern int CmdSecurakeyClone(const char *Cmd);
|
||||||
|
extern int CmdSecurakeySim(const char *Cmd);
|
||||||
|
extern int CmdSecurakeyRead(const char *Cmd);
|
||||||
|
extern int CmdSecurakeyDemod(const char *Cmd);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -3,9 +3,11 @@
|
||||||
// at your option, any later version. See the LICENSE.txt file for the text of
|
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||||
// the license.
|
// the license.
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Generic CRC calculation code.
|
// Parity functions
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// all functions defined in header file by purpose. Allows compiler optimizations.
|
||||||
|
|
||||||
#ifndef __PARITY_H
|
#ifndef __PARITY_H
|
||||||
#define __PARITY_H
|
#define __PARITY_H
|
||||||
|
|
||||||
|
@ -14,25 +16,42 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
extern const uint8_t OddByteParity[256];
|
extern const uint8_t OddByteParity[256];
|
||||||
extern const uint8_t EvenByteParity[256];
|
|
||||||
|
|
||||||
static inline uint8_t oddparity8(uint8_t bt)
|
|
||||||
{
|
static inline bool oddparity8(const uint8_t x) {
|
||||||
return OddByteParity[bt];
|
return OddByteParity[x];
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint8_t evenparity8(const uint8_t bt)
|
|
||||||
{
|
static inline bool evenparity8(const uint8_t x) {
|
||||||
return EvenByteParity[bt];
|
return !OddByteParity[x];
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint8_t evenparity32(uint32_t x)
|
|
||||||
|
static inline bool evenparity32(uint32_t x)
|
||||||
{
|
{
|
||||||
|
#if !defined __GNUC__
|
||||||
x ^= x >> 16;
|
x ^= x >> 16;
|
||||||
x ^= x >> 8;
|
x ^= x >> 8;
|
||||||
return EvenByteParity[x & 0xff];
|
return evenparity8(x);
|
||||||
|
#else
|
||||||
|
return __builtin_parity(x);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static inline bool oddparity32(uint32_t x)
|
||||||
|
{
|
||||||
|
#if !defined __GNUC__
|
||||||
|
x ^= x >> 16;
|
||||||
|
x ^= x >> 8;
|
||||||
|
return oddparity8(x);
|
||||||
|
#else
|
||||||
|
return !__builtin_parity(x);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue