External command config file

pull/33/head
wh201906 3 years ago
parent 12a0837c50
commit 5a8ab42281

@ -59,6 +59,7 @@ Great thanks to him.
make make
make clean make clean
cp -r ../lang ./ cp -r ../lang ./
cp ../configs.json ./
./Proxmark3GUI ./Proxmark3GUI
*** ***

@ -109,7 +109,7 @@ void PM3Process::onTimeout() //when the proxmark3 client is unexpectedly termina
{ {
// isBusy() is a deprecated function. // isBusy() is a deprecated function.
// It will always return false on Raspbian. // It will always return false on Raspbian.
// SerialListener need to be removed. // SerialListener needs to be removed.
// //
// qDebug()<<portInfo->isBusy(); // qDebug()<<portInfo->isBusy();
// if(!portInfo->isBusy()) // if(!portInfo->isBusy())

@ -0,0 +1,52 @@
{
"mifare classic": {
"nested":{
"cmd":"hf mf nested --<card type> --blk <block> -<key type> -k <key>",
"card type": {
"mini": "mini",
"1k": "1k",
"2k": "2k",
"4k": "4k"
},
"key type":{
"A": "a",
"B": "b"
},
"key pattern": "\\|\\s*\\d{3}\\s*\\|\\s*.+?\\s*\\|\\s*.+?\\s*\\|\\s*.+?\\s*\\|\\s*.+?\\s*\\|"
},
"chk": {
"cmd": "hf mf chk --<card type>",
"card type": {
"mini": "mini",
"1k": "1k",
"2k": "2k",
"4k": "4k"
},
"key pattern": "\\|\\s*\\d{3}\\s*\\|\\s*.+?\\s*\\|\\s*.+?\\s*\\|\\s*.+?\\s*\\|\\s*.+?\\s*\\|"
},
"info": {
"cmd": "hf 14a info"
},
"sniff": {
"cmd": "hf sniff"
},
"sniff 14a": {
"cmd": "hf 14a sniff"
},
"list": {
"cmd": "trace list -t mf"
},
"dump": {
"cmd": "hf mf dump"
},
"restore": {
"cmd": "hf mf restore"
},
"wipe emulator": {
"cmd": "hf mf eclr"
},
"wipe Magic Card": {
"cmd": "hf mf cwipe"
}
}
}

@ -87,13 +87,19 @@ Mifare::Mifare(Ui::MainWindow *ui, Util *addr, QWidget *parent): QObject(parent)
keyPattern = new QRegularExpression("\\|\\s*\\d{3}\\s*\\|\\s*.+?\\s*\\|\\s*.+?\\s*\\|"); keyPattern = new QRegularExpression("\\|\\s*\\d{3}\\s*\\|\\s*.+?\\s*\\|\\s*.+?\\s*\\|");
} }
void Mifare::setConfigMap(const QVariantMap& configMap)
{
this->configMap = configMap;
qDebug() << configMap;
}
// TODO: change result type QString->QMap
QString Mifare::info(bool isRequiringOutput) QString Mifare::info(bool isRequiringOutput)
{ {
if(Util::getClientType() == Util::CLIENTTYPE_OFFICIAL || Util::getClientType() == Util::CLIENTTYPE_ICEMAN) QVariantMap config = configMap["info"].toMap();
{
if(isRequiringOutput) if(isRequiringOutput)
{ {
QString result = util->execCMDWithOutput("hf 14a info", 500); QString result = util->execCMDWithOutput(config["cmd"].toString(), 500);
int begin, end; int begin, end;
begin = result.indexOf("UID"); begin = result.indexOf("UID");
if(begin != -1) if(begin != -1)
@ -105,13 +111,13 @@ QString Mifare::info(bool isRequiringOutput)
} }
else else
{ {
util->execCMD("hf 14a info"); util->execCMD(config["cmd"].toString());
Util::gotoRawTab(); Util::gotoRawTab();
} }
}
return ""; return "";
} }
// TODO: Remove ClientType() detect, detect valid key by [0-9A-Fa-f]
void Mifare::chk() void Mifare::chk()
{ {
QRegularExpressionMatch reMatch; QRegularExpressionMatch reMatch;
@ -148,14 +154,18 @@ void Mifare::chk()
} }
else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN) else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN)
{ {
QVariantMap config = configMap["chk"].toMap();
QString cmd = config["cmd"].toString();
QRegularExpression keyPattern = QRegularExpression(config["key pattern"].toString());
cmd.replace("<card type>", config["card type"].toMap()[cardType.typeText].toString());
result = util->execCMDWithOutput( result = util->execCMDWithOutput(
"hf mf chk --" cmd,
+ cardType.typeText, Util::ReturnTrigger(1000 + cardType.sector_size * 200, {"No valid", keyPattern.pattern()}));
Util::ReturnTrigger(1000 + cardType.sector_size * 200, {"No valid", keyPattern_res->pattern()}));
qDebug() << "mf_chk_iceman_result" << result; qDebug() << "mf_chk_iceman_result" << result;
for(int i = 0; i < cardType.sector_size; i++) for(int i = 0; i < cardType.sector_size; i++)
{ {
reMatch = keyPattern_res->match(result, offset); reMatch = keyPattern.match(result, offset);
offset = reMatch.capturedStart(); offset = reMatch.capturedStart();
if(reMatch.hasMatch()) if(reMatch.hasMatch())
{ {
@ -179,6 +189,9 @@ void Mifare::chk()
void Mifare::nested() void Mifare::nested()
{ {
QVariantMap config = configMap["nested"].toMap();
QString cmd = config["cmd"].toString();
QRegularExpression keyPattern = QRegularExpression(config["key pattern"].toString());
QRegularExpressionMatch reMatch; QRegularExpressionMatch reMatch;
QString result; QString result;
int offset = 0; int offset = 0;
@ -193,32 +206,33 @@ void Mifare::nested()
} }
else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN) else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN)
{ {
QString knownKeyInfo = ""; QString knownKey, knownKeyType;
int knownKeySector = -1;
for(int i = 0; i < cardType.sector_size; i++) for(int i = 0; i < cardType.sector_size; i++)
{ {
if(data_isKeyValid(keyAList->at(i))) if(data_isKeyValid(keyAList->at(i)))
{ {
knownKeyInfo = " --blk " + QString::number(i * 4) + " -a -k " + keyAList->at(i); knownKeyType = "A";
knownKey = keyAList->at(i);
knownKeySector = i;
break; break;
} }
} else if(data_isKeyValid(keyBList->at(i)))
if(knownKeyInfo == "")
{ {
for(int i = 0; i < cardType.sector_size; i++) knownKeyType = "B";
{ knownKey = keyBList->at(i);
if(data_isKeyValid(keyBList->at(i))) knownKeySector = i;
{
knownKeyInfo = " --blk " + QString::number(i * 4) + " -b -k " + keyBList->at(i);
break; break;
} }
} }
} if(knownKeySector != -1)
if(knownKeyInfo != "")
{ {
cmd.replace("<card type>", config["card type"].toMap()[cardType.typeText].toString());
cmd.replace("<block>", QString::number(cardType.blks[knownKeySector]));
cmd.replace("<key type>", config["key type"].toMap()[knownKeyType].toString());
cmd.replace("<key>", knownKey);
result = util->execCMDWithOutput( result = util->execCMDWithOutput(
"hf mf nested --" cmd,
+ cardType.typeText
+ knownKeyInfo,
Util::ReturnTrigger(15000, {"Can't authenticate", keyPattern_res->pattern()})); Util::ReturnTrigger(15000, {"Can't authenticate", keyPattern_res->pattern()}));
} }
else else
@ -229,7 +243,7 @@ void Mifare::nested()
} }
for(int i = 0; i < cardType.sector_size; i++) for(int i = 0; i < cardType.sector_size; i++)
{ {
reMatch = keyPattern_res->match(result, offset); reMatch = keyPattern.match(result, offset);
offset = reMatch.capturedStart(); offset = reMatch.capturedStart();
if(reMatch.hasMatch()) if(reMatch.hasMatch())
{ {
@ -270,30 +284,33 @@ void Mifare::darkside()
void Mifare::sniff() void Mifare::sniff()
{ {
QVariantMap config = configMap["sniff"].toMap();
if(Util::getClientType() == Util::CLIENTTYPE_OFFICIAL) if(Util::getClientType() == Util::CLIENTTYPE_OFFICIAL)
util->execCMD("hf mf sniff"); util->execCMD("hf mf sniff");
else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN) else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN)
util->execCMD("hf sniff"); util->execCMD(config["cmd"].toString());
Util::gotoRawTab(); Util::gotoRawTab();
} }
void Mifare::sniff14a() void Mifare::sniff14a()
{ {
QVariantMap config = configMap["sniff 14a"].toMap();
if(Util::getClientType() == Util::CLIENTTYPE_OFFICIAL) if(Util::getClientType() == Util::CLIENTTYPE_OFFICIAL)
util->execCMD("hf 14a snoop"); util->execCMD("hf 14a snoop");
else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN) else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN)
util->execCMD("hf 14a sniff"); util->execCMD(config["cmd"].toString());
Util::gotoRawTab(); Util::gotoRawTab();
} }
void Mifare::list() void Mifare::list()
{ {
QVariantMap config = configMap["sniff 14a"].toMap();
if(Util::getClientType() == Util::CLIENTTYPE_OFFICIAL) if(Util::getClientType() == Util::CLIENTTYPE_OFFICIAL)
util->execCMD("hf list mf"); util->execCMD("hf list mf");
else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN) else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN)
util->execCMD("trace list -t mf"); util->execCMD(config["cmd"].toString());
Util::gotoRawTab(); Util::gotoRawTab();
} }
@ -759,15 +776,15 @@ void Mifare::writeSelected(TargetType targetType)
void Mifare::dump() void Mifare::dump()
{ {
if(Util::getClientType() == Util::CLIENTTYPE_OFFICIAL || Util::getClientType() == Util::CLIENTTYPE_ICEMAN) QVariantMap config = configMap["dump"].toMap();
util->execCMD("hf mf dump"); util->execCMD(config["cmd"].toString());
Util::gotoRawTab(); Util::gotoRawTab();
} }
void Mifare::restore() void Mifare::restore()
{ {
if(Util::getClientType() == Util::CLIENTTYPE_OFFICIAL || Util::getClientType() == Util::CLIENTTYPE_ICEMAN) QVariantMap config = configMap["restore"].toMap();
util->execCMD("hf mf restore"); util->execCMD(config["cmd"].toString());
Util::gotoRawTab(); Util::gotoRawTab();
} }
@ -782,7 +799,8 @@ void Mifare::wipeC()
} }
else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN) else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN)
{ {
util->execCMD("hf mf cwipe"); QVariantMap config = configMap["wipe Magic Card"].toMap();
util->execCMD(config["cmd"].toString());
} }
Util::gotoRawTab(); Util::gotoRawTab();
} }
@ -833,8 +851,8 @@ void Mifare::lockC()
void Mifare::wipeE() void Mifare::wipeE()
{ {
if(Util::getClientType() == Util::CLIENTTYPE_OFFICIAL || Util::getClientType() == Util::CLIENTTYPE_ICEMAN) QVariantMap config = configMap["wipe emulator"].toMap();
util->execCMD("hf mf eclr"); util->execCMD(config["cmd"].toString());
} }
void Mifare::simulate() void Mifare::simulate()

@ -11,6 +11,7 @@
#include <QStringList> #include <QStringList>
#include <QRegularExpression> #include <QRegularExpression>
#include <QMessageBox> #include <QMessageBox>
#include <QJsonObject>
class Mifare : public QObject class Mifare : public QObject
{ {
Q_OBJECT Q_OBJECT
@ -113,6 +114,7 @@ public:
static bool data_isACBitsValid(const QString& text, QList<quint8> *returnHalfBytes = nullptr); static bool data_isACBitsValid(const QString& text, QList<quint8> *returnHalfBytes = nullptr);
QString data_getUID(); QString data_getUID();
quint16 getTrailerBlockId(quint8 sectorId, qint8 cardTypeId = -1); // -1: use current cardtype quint16 getTrailerBlockId(quint8 sectorId, qint8 cardTypeId = -1); // -1: use current cardtype
void setConfigMap(const QVariantMap& configMap);
public slots: public slots:
signals: signals:
@ -121,6 +123,8 @@ private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
Util* util; Util* util;
QVariantMap configMap;
QStringList* keyAList; QStringList* keyAList;
QStringList* keyBList; QStringList* keyBList;
QStringList* dataList; QStringList* dataList;

@ -1,6 +1,8 @@
#include "mainwindow.h" #include "mainwindow.h"
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
#include <QJsonDocument>
MainWindow::MainWindow(QWidget *parent): MainWindow::MainWindow(QWidget *parent):
QMainWindow(parent) QMainWindow(parent)
, ui(new Ui::MainWindow) , ui(new Ui::MainWindow)
@ -38,6 +40,16 @@ MainWindow::MainWindow(QWidget *parent):
mifare = new Mifare(ui, util, this); mifare = new Mifare(ui, util, this);
lf = new LF(ui, util, this); lf = new LF(ui, util, this);
QFile configList("configs.json");
if(!configList.open(QFile::ReadOnly | QFile::Text))
{
;
}
QByteArray configData = configList.readAll();
QJsonDocument configJson(QJsonDocument::fromJson(configData));
mifare->setConfigMap(configJson.object()["mifare classic"].toObject().toVariantMap());
keyEventFilter = new MyEventFilter(QEvent::KeyPress); keyEventFilter = new MyEventFilter(QEvent::KeyPress);
resizeEventFilter = new MyEventFilter(QEvent::Resize); resizeEventFilter = new MyEventFilter(QEvent::Resize);

Loading…
Cancel
Save