2017-08-26 19:01:35 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Samy Kamkar, 2012
|
|
|
|
// Christian Herrmann, 2017
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//-----------------------------------------------------------------------------
|
2019-03-09 15:59:13 +08:00
|
|
|
// main code for LF aka SamyRun by Samy Kamkar
|
2017-08-26 19:01:35 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
2019-08-08 22:57:33 +08:00
|
|
|
#include "standalone.h" // standalone definitions
|
|
|
|
#include "proxmark3_arm.h"
|
|
|
|
#include "appmain.h"
|
|
|
|
#include "fpgaloader.h"
|
|
|
|
#include "lfops.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "dbprint.h"
|
|
|
|
#include "ticks.h"
|
|
|
|
|
|
|
|
#define OPTS 2
|
2017-08-26 19:01:35 +08:00
|
|
|
|
2019-04-26 03:44:34 +08:00
|
|
|
void ModInfo(void) {
|
2019-07-10 04:49:57 +08:00
|
|
|
DbpString(" LF HID26 standalone - aka SamyRun (Samy Kamkar)");
|
2019-04-26 03:44:34 +08:00
|
|
|
}
|
|
|
|
|
2017-08-26 19:01:35 +08:00
|
|
|
// samy's sniff and repeat routine for LF
|
2019-09-12 23:37:36 +08:00
|
|
|
|
|
|
|
// LEDS.
|
|
|
|
// A , B == which bank (recording)
|
|
|
|
// FLASHING A, B = clone bank
|
|
|
|
// C = playing bank A
|
|
|
|
// D = playing bank B
|
|
|
|
|
2019-03-10 18:20:22 +08:00
|
|
|
void RunMod() {
|
2019-03-09 18:19:45 +08:00
|
|
|
StandAloneMode();
|
|
|
|
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
|
2019-09-12 23:37:36 +08:00
|
|
|
Dbprintf(">> LF HID Read/Clone/Sim a.k.a SamyRun Started <<");
|
2019-03-09 18:19:45 +08:00
|
|
|
|
|
|
|
uint32_t high[OPTS], low[OPTS];
|
|
|
|
int selected = 0;
|
2017-08-26 19:01:35 +08:00
|
|
|
|
2019-09-12 23:37:36 +08:00
|
|
|
#define STATE_READ 0
|
|
|
|
#define STATE_SIM 1
|
2019-09-13 16:04:59 +08:00
|
|
|
#define STATE_CLONE 2
|
2019-09-12 23:37:36 +08:00
|
|
|
|
|
|
|
uint8_t state = STATE_READ;
|
2019-09-13 16:04:59 +08:00
|
|
|
|
2019-03-09 18:19:45 +08:00
|
|
|
for (;;) {
|
2019-09-13 16:04:59 +08:00
|
|
|
|
2019-03-09 18:19:45 +08:00
|
|
|
WDT_HIT();
|
2019-09-13 16:04:59 +08:00
|
|
|
|
2019-03-09 18:19:45 +08:00
|
|
|
// exit from SamyRun, send a usbcommand.
|
2019-06-03 06:01:08 +08:00
|
|
|
if (data_available()) break;
|
2019-03-09 18:19:45 +08:00
|
|
|
|
|
|
|
// Was our button held down or pressed?
|
2019-09-12 23:37:36 +08:00
|
|
|
int button_pressed = BUTTON_HELD(280);
|
2019-09-13 22:25:33 +08:00
|
|
|
if (button_pressed != BUTTON_HOLD)
|
2019-09-12 23:37:36 +08:00
|
|
|
continue;
|
2019-09-13 22:25:33 +08:00
|
|
|
/*
|
|
|
|
#define BUTTON_NO_CLICK 0
|
|
|
|
#define BUTTON_SINGLE_CLICK -1
|
|
|
|
#define BUTTON_DOUBLE_CLICK -2
|
|
|
|
*/
|
2019-09-12 23:37:36 +08:00
|
|
|
|
2019-09-13 22:25:33 +08:00
|
|
|
if (state == STATE_READ) {
|
2019-09-12 23:37:36 +08:00
|
|
|
|
|
|
|
if (selected == 0) {
|
2019-09-13 16:04:59 +08:00
|
|
|
LED_A_ON();
|
2019-09-12 23:37:36 +08:00
|
|
|
LED_B_OFF();
|
2019-09-13 16:04:59 +08:00
|
|
|
} else {
|
|
|
|
LED_B_ON();
|
2019-09-12 23:37:36 +08:00
|
|
|
LED_A_OFF();
|
|
|
|
}
|
2019-09-13 16:04:59 +08:00
|
|
|
|
2019-09-12 23:37:36 +08:00
|
|
|
LED_C_OFF();
|
|
|
|
LED_D_OFF();
|
2019-03-09 18:19:45 +08:00
|
|
|
|
2019-09-12 23:37:36 +08:00
|
|
|
WAIT_BUTTON_RELEASED();
|
2019-09-13 16:04:59 +08:00
|
|
|
|
2019-03-09 18:19:45 +08:00
|
|
|
// record
|
2019-09-13 16:17:58 +08:00
|
|
|
DbpString("[=] start recording");
|
2019-03-09 18:19:45 +08:00
|
|
|
|
2019-09-13 16:04:59 +08:00
|
|
|
// findone, high, low, no ledcontrol (A)
|
2019-09-12 23:37:36 +08:00
|
|
|
uint32_t hi = 0, lo = 0;
|
|
|
|
CmdHIDdemodFSK(1, &hi, &lo, 0);
|
|
|
|
high[selected] = hi;
|
|
|
|
low[selected] = lo;
|
2019-09-13 16:04:59 +08:00
|
|
|
|
2019-09-13 16:17:58 +08:00
|
|
|
Dbprintf("[=] recorded %x | %x%08x", selected, high[selected], low[selected]);
|
2019-09-12 23:37:36 +08:00
|
|
|
|
|
|
|
// got nothing. blink and loop.
|
2019-09-13 22:25:33 +08:00
|
|
|
if (hi == 0 && lo == 0) {
|
|
|
|
SpinErr((selected == 0) ? LED_A : LED_B, 100, 12);
|
2019-09-13 16:17:58 +08:00
|
|
|
DbpString("[=] only got zeros, retry recording after click");
|
2019-09-12 23:37:36 +08:00
|
|
|
continue;
|
|
|
|
}
|
2019-09-13 16:04:59 +08:00
|
|
|
|
2019-09-13 22:25:33 +08:00
|
|
|
SpinErr((selected == 0) ? LED_A : LED_B, 250, 2);
|
2019-09-12 23:37:36 +08:00
|
|
|
state = STATE_SIM;
|
|
|
|
continue;
|
|
|
|
|
2019-09-13 22:25:33 +08:00
|
|
|
} else if (state == STATE_SIM) {
|
2019-09-13 16:04:59 +08:00
|
|
|
|
|
|
|
LED_C_ON(); // Simulate
|
2019-09-12 23:37:36 +08:00
|
|
|
LED_D_OFF();
|
|
|
|
WAIT_BUTTON_RELEASED();
|
2019-09-13 16:04:59 +08:00
|
|
|
|
2019-09-12 23:37:36 +08:00
|
|
|
Dbprintf("[=] simulating %x | %x%08x", selected, high[selected], low[selected]);
|
|
|
|
|
|
|
|
// high, low, no led control(A) no time limit
|
2019-09-15 07:17:47 +08:00
|
|
|
CmdHIDsimTAGEx(0, high[selected], low[selected], 0, false, -1);
|
2019-09-13 16:17:58 +08:00
|
|
|
|
|
|
|
DbpString("[=] simulating done");
|
|
|
|
|
|
|
|
uint8_t leds = ((selected == 0) ? LED_A : LED_B) | LED_C;
|
2019-09-13 22:25:33 +08:00
|
|
|
SpinErr(leds, 250, 2);
|
2019-09-12 23:37:36 +08:00
|
|
|
state = STATE_CLONE;
|
|
|
|
continue;
|
2019-09-13 16:04:59 +08:00
|
|
|
|
2019-09-13 22:25:33 +08:00
|
|
|
} else if (state == STATE_CLONE) {
|
2019-09-12 23:37:36 +08:00
|
|
|
|
|
|
|
LED_C_OFF();
|
2019-09-13 16:04:59 +08:00
|
|
|
LED_D_ON(); // clone
|
2019-09-12 23:37:36 +08:00
|
|
|
WAIT_BUTTON_RELEASED();
|
2019-09-13 16:04:59 +08:00
|
|
|
|
2019-09-13 16:17:58 +08:00
|
|
|
Dbprintf("[=] cloning %x | %x%08x", selected, high[selected], low[selected]);
|
2019-09-12 23:37:36 +08:00
|
|
|
|
|
|
|
// high2, high, low, no longFMT
|
2019-03-09 18:19:45 +08:00
|
|
|
CopyHIDtoT55x7(0, high[selected], low[selected], 0);
|
2019-09-13 16:17:58 +08:00
|
|
|
|
|
|
|
DbpString("[=] cloned done");
|
|
|
|
|
2019-09-12 23:37:36 +08:00
|
|
|
state = STATE_READ;
|
2019-09-13 16:17:58 +08:00
|
|
|
uint8_t leds = ((selected == 0) ? LED_A : LED_B) | LED_D;
|
|
|
|
SpinErr(leds, 250, 2);
|
2019-09-12 23:37:36 +08:00
|
|
|
selected = (selected + 1) % OPTS;
|
2019-03-09 18:19:45 +08:00
|
|
|
LEDsoff();
|
|
|
|
}
|
|
|
|
}
|
2018-09-06 00:58:58 +08:00
|
|
|
|
2019-09-13 22:25:33 +08:00
|
|
|
SpinErr((LED_A | LED_B | LED_C | LED_D), 250, 5);
|
2019-09-13 16:17:58 +08:00
|
|
|
DbpString("[=] You can take shell back :) ...");
|
2019-03-09 18:19:45 +08:00
|
|
|
LEDsoff();
|
2019-03-12 07:12:26 +08:00
|
|
|
}
|