From 957a4b5cab4979004aef814cc436a442862aad77 Mon Sep 17 00:00:00 2001 From: DavidVentura Date: Thu, 25 Jan 2024 10:09:41 +0100 Subject: [PATCH] add SendUsrChk and test it --- .mocharc.json | 8 ++++++++ Makefile | 8 +++++++- impl.ts | 4 ++-- tests/fn.test.js | 13 ++++++++++++- 4 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 .mocharc.json diff --git a/.mocharc.json b/.mocharc.json new file mode 100644 index 0000000..1b2a178 --- /dev/null +++ b/.mocharc.json @@ -0,0 +1,8 @@ +{ + "extensions": ["ts", "js"], + "node-option": [ + "experimental-specifier-resolution=node", + "loader=ts-node/esm" + ] +} + diff --git a/Makefile b/Makefile index c6e5955..50e52c9 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: run install-wireshark-dissector +.PHONY: run install-wireshark-dissector test bundle.js: asd.js func_replacements.js ~/node_modules/.bin/frida-compile -o $@ asd.js @@ -11,6 +11,12 @@ venv: requirements.txt run: bundle.js venv ./venv/bin/python3 -u loader3.py +node_modules: + npm install + +test: node_modules + ./node_modules/.bin/mocha --require ts-node/register tests/fn.test.js + install-wireshark-dissector: mkdir -p ~/.local/lib/wireshark/plugins ln -s $(PWD)/dissector.lua ~/.local/lib/wireshark/plugins/dissector.lua diff --git a/impl.ts b/impl.ts index 1fd8818..6c0edce 100644 --- a/impl.ts +++ b/impl.ts @@ -7,7 +7,7 @@ const str2byte = (s: string): number[] => { return Array.from(s).map((_, i) => s.charCodeAt(i)); }; -const SendUsrChk = (username: string, password: string): DataView => { +export const SendUsrChk = (username: string, password: string): DataView => { // type is char account[0x20]; char password[0x80]; let buf = new Uint8Array(0x20 + 0x80); buf.fill(0); @@ -40,4 +40,4 @@ const SendUsrChk = (username: string, password: string): DataView => { return retret; }; -console.log(hexdump(SendUsrChk("admin", "admin").buffer, { ansi: true })); +//console.log(hexdump(SendUsrChk("admin", "admin").buffer, { ansi: true })); diff --git a/tests/fn.test.js b/tests/fn.test.js index 51ff1df..0e75dc5 100644 --- a/tests/fn.test.js +++ b/tests/fn.test.js @@ -1,9 +1,10 @@ -import "../shim.js"; +import "../shim.ts"; import assert from "assert"; import { placeholderTypes, sprintf } from "../utils.js"; import { XqBytesDec, XqBytesEnc } from "../func_replacements.js"; +import { SendUsrChk } from "../impl.ts"; describe("debug_tools", () => { it("parses printed data", () => { @@ -89,3 +90,13 @@ describe("module", () => { assert.deepEqual(new Uint8Array(in_buf.buffer), long_dec_bytes); //DEC }); }); + +const hstrToBA = (hs) => new Uint8Array(hs.match(/../g).map((h) => parseInt(h, 16))).buffer; +describe("make packet", () => { + it("builds a good SendUsrChk", () => { + const expected_str = + "f1d000b0d1000000110a2010a400ff00000000006f01010101010101010101010101010101010101010101010101010160656c686f01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010160656c68"; + const expected = hstrToBA(expected_str); + assert.deepEqual(SendUsrChk("admin", "admin").buffer, expected); + }); +});