Proxmark3 community

Research, development and trades concerning the powerful Proxmark3 device.

Remember; sharing is caring. Bring something back to the community.


"Learn the tools of the trade the hard way." +Fravia

You are not logged in.

Announcement

Time changes and with it the technology
Proxmark3 @ discord

Users of this forum, please be aware that information stored on this site is not private.

#1 2019-06-24 11:28:05

Lcardil
Contributor
Registered: 2018-10-28
Posts: 9

Convert C function to Lua

Hi there all proxmarkers,

I'm trying to convert the C function of writing block into mifare 1k card (mf hf wrbl) as shown here as C:

int CmdHF14AMfWrBl(const char *Cmd)
{
	uint8_t blockNo = 0;
	uint8_t keyType = 0;
	uint8_t key[6] = {0, 0, 0, 0, 0, 0};
	uint8_t bldata[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

//i removed the check conditions the checks the args

  UsbCommand c = {CMD_MIFARE_WRITEBL, {blockNo, keyType, 0}};
	memcpy(c.d.asBytes, key, 6);
	memcpy(c.d.asBytes + 10, bldata, 16);
  SendCommand(&c);

	UsbCommand resp;
	if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
		uint8_t isOK  = resp.arg[0] & 0xff;
		PrintAndLog("isOk:%02x", isOK);
	} else {
		PrintAndLog("Command execute timeout");
	}

	return 0;
}

and I managed to write in like this in Lua:

function mf_write_cmd(blockNo, KeyType, blk)
	core.clearCommandBuffer()
	-- build mifare command
	local key={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x0,0x0,
	0x00,0xC6,0x76,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x24,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00}
	
	print(#key)
	local cmds = require('commands')
	
	cmd = Command:new{cmd = cmds.CMD_MIFARE_WRITEBL,{blockNo,KeyType,key}}
	
	local res, err = core.SendCommand(cmd:getBytes())
	return res,err

But didn't managed to do it well, i got this messges:

#db# Authentication failed. Error card response.
#db# Auth error
#db# WRITE BLOCK FINISHED

What am I missing?

thanks smile

Last edited by Lcardil (2019-06-24 11:33:51)

Offline

Board footer

Powered by FluxBB