Support hardnested(), darkside(), readblk(),

readsec() in latest Iceman repo
pull/14/head
wh201906 4 years ago
parent 6baa09221e
commit 24a6e1869b

@ -1,11 +1,12 @@
#include "util.h" #include "util.h"
Util::ClientType Util::clientType = CLIENTTYPE_OFFICIAL;
Util::Util(QObject *parent) : QObject(parent) Util::Util(QObject *parent) : QObject(parent)
{ {
isRequiringOutput = false; isRequiringOutput = false;
requiredOutput = new QString(); requiredOutput = new QString();
timeStamp = QTime::currentTime(); timeStamp = QTime::currentTime();
this->clientType = CLIENTTYPE_OFFICIAL;
qRegisterMetaType<Util::ClientType>("Util::ClientType"); qRegisterMetaType<Util::ClientType>("Util::ClientType");
} }
@ -79,14 +80,15 @@ void Util::delay(unsigned int msec)
while(QTime::currentTime() < timer) while(QTime::currentTime() < timer)
QApplication::processEvents(QEventLoop::AllEvents, 100); QApplication::processEvents(QEventLoop::AllEvents, 100);
} }
Util::ClientType Util::getClientType() Util::ClientType Util::getClientType()
{ {
return this->clientType; return Util::clientType;
} }
void Util::setClientType(Util::ClientType clientType) void Util::setClientType(Util::ClientType clientType)
{ {
this->clientType = clientType; Util::clientType = clientType;
} }
void Util::setRunningState(bool st) void Util::setRunningState(bool st)

@ -52,12 +52,12 @@ public:
void execCMD(const QString& cmd); void execCMD(const QString& cmd);
QString execCMDWithOutput(const QString& cmd, ReturnTrigger trigger = 10000); QString execCMDWithOutput(const QString& cmd, ReturnTrigger trigger = 10000);
void delay(unsigned int msec); void delay(unsigned int msec);
ClientType getClientType(); static ClientType getClientType();
static const int rawTabIndex = 1; static const int rawTabIndex = 1;
static bool chooseLanguage(QSettings *guiSettings, QMainWindow *window); static bool chooseLanguage(QSettings *guiSettings, QMainWindow *window);
public slots: public slots:
void processOutput(const QString& output); void processOutput(const QString& output);
void setClientType(Util::ClientType clientType); static void setClientType(Util::ClientType clientType);
void setRunningState(bool st); void setRunningState(bool st);
private: private:
@ -65,7 +65,7 @@ private:
bool isRunning; bool isRunning;
QString* requiredOutput; QString* requiredOutput;
QTime timeStamp; QTime timeStamp;
ClientType clientType; static ClientType clientType;
signals: signals:
void refreshOutput(const QString& output); void refreshOutput(const QString& output);
void write(QString data); // connected to PM3Process::write(QString data); void write(QString data); // connected to PM3Process::write(QString data);

@ -989,56 +989,56 @@ or &quot;-p &lt;port&gt; -f&quot;</source>
<context> <context>
<name>Mifare</name> <name>Mifare</name>
<message> <message>
<location filename="../module/mifare.cpp" line="613"/> <location filename="../module/mifare.cpp" line="617"/>
<source>Success!</source> <source>Success!</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../module/mifare.cpp" line="225"/> <location filename="../module/mifare.cpp" line="229"/>
<location filename="../module/mifare.cpp" line="613"/>
<location filename="../module/mifare.cpp" line="617"/> <location filename="../module/mifare.cpp" line="617"/>
<location filename="../module/mifare.cpp" line="641"/> <location filename="../module/mifare.cpp" line="621"/>
<location filename="../module/mifare.cpp" line="680"/> <location filename="../module/mifare.cpp" line="645"/>
<location filename="../module/mifare.cpp" line="693"/> <location filename="../module/mifare.cpp" line="684"/>
<location filename="../module/mifare.cpp" line="739"/> <location filename="../module/mifare.cpp" line="697"/>
<location filename="../module/mifare.cpp" line="743"/>
<source>Info</source> <source>Info</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../module/mifare.cpp" line="225"/> <location filename="../module/mifare.cpp" line="229"/>
<source>Plz provide at least one known key</source> <source>Plz provide at least one known key</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../module/mifare.cpp" line="464"/> <location filename="../module/mifare.cpp" line="468"/>
<location filename="../module/mifare.cpp" line="617"/> <location filename="../module/mifare.cpp" line="621"/>
<source>Failed!</source> <source>Failed!</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../module/mifare.cpp" line="642"/> <location filename="../module/mifare.cpp" line="646"/>
<source>The Access Bits is invalid! <source>The Access Bits is invalid!
It could make the whole sector blocked irreversibly! It could make the whole sector blocked irreversibly!
Continue to write?</source> Continue to write?</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../module/mifare.cpp" line="680"/> <location filename="../module/mifare.cpp" line="684"/>
<source>Successful!</source> <source>Successful!</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../module/mifare.cpp" line="693"/> <location filename="../module/mifare.cpp" line="697"/>
<source>Failed to write to these blocks:</source> <source>Failed to write to these blocks:</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../module/mifare.cpp" line="697"/> <location filename="../module/mifare.cpp" line="701"/>
<source>Select them?</source> <source>Select them?</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../module/mifare.cpp" line="739"/> <location filename="../module/mifare.cpp" line="743"/>
<source>Failed to read card.</source> <source>Failed to read card.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>

@ -532,13 +532,13 @@ It could make the whole sector blocked irreversibly!</source>
<location filename="../ui/mainwindow.ui" line="757"/> <location filename="../ui/mainwindow.ui" line="757"/>
<location filename="../ui/mainwindow.ui" line="891"/> <location filename="../ui/mainwindow.ui" line="891"/>
<source>Read One</source> <source>Read One</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../ui/mainwindow.ui" line="770"/> <location filename="../ui/mainwindow.ui" line="770"/>
<location filename="../ui/mainwindow.ui" line="904"/> <location filename="../ui/mainwindow.ui" line="904"/>
<source>Write One</source> <source>Write One</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../ui/mainwindow.ui" line="783"/> <location filename="../ui/mainwindow.ui" line="783"/>
@ -997,34 +997,34 @@ or &quot;-p &lt;port&gt; -f&quot;</source>
<context> <context>
<name>Mifare</name> <name>Mifare</name>
<message> <message>
<location filename="../module/mifare.cpp" line="613"/> <location filename="../module/mifare.cpp" line="617"/>
<source>Success!</source> <source>Success!</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../module/mifare.cpp" line="225"/> <location filename="../module/mifare.cpp" line="229"/>
<location filename="../module/mifare.cpp" line="613"/>
<location filename="../module/mifare.cpp" line="617"/> <location filename="../module/mifare.cpp" line="617"/>
<location filename="../module/mifare.cpp" line="641"/> <location filename="../module/mifare.cpp" line="621"/>
<location filename="../module/mifare.cpp" line="680"/> <location filename="../module/mifare.cpp" line="645"/>
<location filename="../module/mifare.cpp" line="693"/> <location filename="../module/mifare.cpp" line="684"/>
<location filename="../module/mifare.cpp" line="739"/> <location filename="../module/mifare.cpp" line="697"/>
<location filename="../module/mifare.cpp" line="743"/>
<source>Info</source> <source>Info</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../module/mifare.cpp" line="225"/> <location filename="../module/mifare.cpp" line="229"/>
<source>Plz provide at least one known key</source> <source>Plz provide at least one known key</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../module/mifare.cpp" line="464"/> <location filename="../module/mifare.cpp" line="468"/>
<location filename="../module/mifare.cpp" line="617"/> <location filename="../module/mifare.cpp" line="621"/>
<source>Failed!</source> <source>Failed!</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../module/mifare.cpp" line="642"/> <location filename="../module/mifare.cpp" line="646"/>
<source>The Access Bits is invalid! <source>The Access Bits is invalid!
It could make the whole sector blocked irreversibly! It could make the whole sector blocked irreversibly!
Continue to write?</source> Continue to write?</source>
@ -1033,22 +1033,22 @@ Continue to write?</source>
</translation> </translation>
</message> </message>
<message> <message>
<location filename="../module/mifare.cpp" line="680"/> <location filename="../module/mifare.cpp" line="684"/>
<source>Successful!</source> <source>Successful!</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../module/mifare.cpp" line="693"/> <location filename="../module/mifare.cpp" line="697"/>
<source>Failed to write to these blocks:</source> <source>Failed to write to these blocks:</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../module/mifare.cpp" line="697"/> <location filename="../module/mifare.cpp" line="701"/>
<source>Select them?</source> <source>Select them?</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../module/mifare.cpp" line="739"/> <location filename="../module/mifare.cpp" line="743"/>
<source>Failed to read card.</source> <source>Failed to read card.</source>
<translation></translation> <translation></translation>
</message> </message>

@ -298,6 +298,7 @@ QString Mifare::_readblk(int blockId, KeyType keyType, const QString& key, Targe
{ {
QString data; QString data;
QString result; QString result;
QRegularExpressionMatch currMatch;
bool isTrailerBlock = (blockId < 128 && ((blockId + 1) % 4 == 0)) || ((blockId + 1) % 16 == 0); bool isTrailerBlock = (blockId < 128 && ((blockId + 1) % 4 == 0)) || ((blockId + 1) % 16 == 0);
if(util->getClientType() == Util::CLIENTTYPE_OFFICIAL || util->getClientType() == Util::CLIENTTYPE_ICEMAN) if(util->getClientType() == Util::CLIENTTYPE_OFFICIAL || util->getClientType() == Util::CLIENTTYPE_ICEMAN)
@ -317,9 +318,10 @@ QString Mifare::_readblk(int blockId, KeyType keyType, const QString& key, Targe
+ " " + " "
+ key, + key,
waitTime); waitTime);
if(result.indexOf("isOk:01") != -1) currMatch = dataPattern->match(result);
if(currMatch.hasMatch())
{ {
data = dataPattern->match(result).captured().toUpper(); data = currMatch.captured().toUpper();
data.remove(" "); data.remove(" ");
// when the target block is a key block and the given key type is KeyA, try to check whether the KeyB is valid(by Access Bits) // when the target block is a key block and the given key type is KeyA, try to check whether the KeyB is valid(by Access Bits)
// if the given key type is KeyB, it will never get the KeyA from the key block // if the given key type is KeyB, it will never get the KeyA from the key block
@ -347,15 +349,19 @@ QString Mifare::_readblk(int blockId, KeyType keyType, const QString& key, Targe
"hf mf cgetblk " "hf mf cgetblk "
+ QString::number(blockId), + QString::number(blockId),
waitTime); waitTime);
if(result.indexOf("Chinese magic") != -1) currMatch = dataPattern->match(result);
if(currMatch.hasMatch())
{ {
data = dataPattern->match(result).captured().toUpper(); data = currMatch.captured().toUpper();
data.remove(" "); data.remove(" ");
} }
else else
data = ""; data = "";
} }
else if(targetType == TARGET_EMULATOR) }
if(util->getClientType() == Util::CLIENTTYPE_OFFICIAL)
{
if(targetType == TARGET_EMULATOR)
{ {
result = util->execCMDWithOutput( result = util->execCMDWithOutput(
"hf mf eget " "hf mf eget "
@ -365,6 +371,18 @@ QString Mifare::_readblk(int blockId, KeyType keyType, const QString& key, Targe
data.remove(" "); data.remove(" ");
} }
} }
else if(util->getClientType() == Util::CLIENTTYPE_ICEMAN)
{
if(targetType == TARGET_EMULATOR)
{
result = util->execCMDWithOutput(
"hf mf egetblk "
+ QString::number(blockId),
150);
data = dataPattern->match(result).captured().toUpper();
data.remove(" ");
}
}
return data; return data;
} }
@ -373,7 +391,7 @@ QStringList Mifare::_readsec(int sectorId, KeyType keyType, const QString& key,
QStringList data; QStringList data;
QString result, tmp; QString result, tmp;
QRegularExpressionMatch reMatch; QRegularExpressionMatch reMatch;
int offset = -1; int offset = -1; // for targetType == TARGET_EMULATOR
for(int i = 0; i < cardType.blk[sectorId]; i++) for(int i = 0; i < cardType.blk[sectorId]; i++)
{ {
@ -397,7 +415,7 @@ QStringList Mifare::_readsec(int sectorId, KeyType keyType, const QString& key,
+ " " + " "
+ key, + key,
waitTime); waitTime);
offset = result.indexOf("isOk:01"); offset = result.indexOf("isOk:01"); // find successful flag
} }
else if(targetType == TARGET_UID) else if(targetType == TARGET_UID)
{ {
@ -405,7 +423,7 @@ QStringList Mifare::_readsec(int sectorId, KeyType keyType, const QString& key,
"hf mf cgetsc " "hf mf cgetsc "
+ QString::number(sectorId), + QString::number(sectorId),
waitTime); waitTime);
offset = result.indexOf("Chinese magic"); offset = result.indexOf("error") == -1 ? 0 : -1; // find failed flag
} }
if(offset != -1) if(offset != -1)
{ {
@ -424,7 +442,7 @@ QStringList Mifare::_readsec(int sectorId, KeyType keyType, const QString& key,
} }
// if failed, try to read them seperately. // if failed, try to read them seperately.
// (when one of the block cannot be read, the rdsc will return nothing, so you need to read the rest of blocks manually) // (when one of the block cannot be read, the rdsc will return nothing, so you need to read the rest of blocks manually)
else if(targetType != TARGET_UID) // if the targetType is Chinese Magic Card, then the result implies the backdoor command is invalid. else if(targetType == TARGET_UID || targetType == TARGET_EMULATOR) // if the targetType is Chinese Magic Card, then the result implies the backdoor command is invalid.
{ {
for(int i = 0; i < cardType.blk[sectorId]; i++) for(int i = 0; i < cardType.blk[sectorId]; i++)
data[i] = _readblk(cardType.blks[sectorId] + i, keyType, key, targetType, waitTime); data[i] = _readblk(cardType.blks[sectorId] + i, keyType, key, targetType, waitTime);

@ -21,6 +21,18 @@ MF_Attack_hardnestedDialog::~MF_Attack_hardnestedDialog()
void MF_Attack_hardnestedDialog::on_buttonBox_accepted() void MF_Attack_hardnestedDialog::on_buttonBox_accepted()
{ {
if(Util::getClientType() == Util::CLIENTTYPE_OFFICIAL)
emit sendCMD("hf mf hardnested "
+ ui->knownKeySectorBox->currentText()
+ " "
+ ui->knownKeyTypeBox->currentText()
+ " "
+ ui->knownKeyBox->text()
+ " "
+ ui->targetKeySectorBox->currentText()
+ " "
+ ui->targetKeyTypeBox->currentText());
else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN) // same format in v4.9237
emit sendCMD("hf mf hardnested " emit sendCMD("hf mf hardnested "
+ ui->knownKeySectorBox->currentText() + ui->knownKeySectorBox->currentText()
+ " " + " "

@ -2,6 +2,7 @@
#define MF_ATTACK_HARDNESTEDDIALOG_H #define MF_ATTACK_HARDNESTEDDIALOG_H
#include <QDialog> #include <QDialog>
#include "common/util.h"
namespace Ui namespace Ui
{ {

Loading…
Cancel
Save