Skip to content

Commit 0646341

Browse files
committed
commiting old notes
1 parent fb404b0 commit 0646341

4 files changed

Lines changed: 150 additions & 1 deletion

File tree

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Collection of notes on some random things I tinker with.
44

55
## Contents
66

7+
- [log.md](log.md) Mostly I will be putting interesting links I come across.
8+
79
- [EC315.md](EC315.md) Attempt to extract the firmware and reverse it to gain some internal understanding. My secret desire was to gain some code execution on the device after which I can mod the system as per my needs. I had a TATA Photon Huawei EC315 3G USB modem with Wi-Fi capabilities.
810

911
- [EC315_research.md](EC315_research.md) Links to online resources I explored while working on EC315 modem.
@@ -16,4 +18,7 @@ Collection of notes on some random things I tinker with.
1618
in public domain, will add a licence in some time. I would prefer if you just
1719
give me some credits.)
1820

19-
- [log.md](log.md) Mostly I will be putting interesting links I come across.
21+
- [rfid_reader.md](rfid_reader.md) Notes on analysis of a cheap RFID device I
22+
got off Ebay and it's protocol.
23+
24+
- [Tenda_N301.md](Tenda_N301.md) Basic analysis of Tendra N301 router firmware.

ideas.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,7 @@
122122
minimum one that starts very fast, starts the application and then gets out
123123
of the way. It may not be even required to boot, loading it from a image
124124
should work fine too.
125+
126+
- Run linux as a process on macOS. There was a article on HN on how to run linux
127+
as an application on Linux. Porting that may allow the above idea to be
128+
fulfilled.

log.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
- MacOS run a script as an App, use Automator -> Create Application -> Run a
1414
script -> Input as arguements -> path to the scirpt/directly input the
1515
script
16+
- Fixing Scaleway Ubuntu Kernel
17+
<https://blog.simos.info/how-to-run-the-stock-ubuntu-linux-kernel-on-scaleway-using-kexec-and-server-tags/>
18+
19+
- "HowTo: Use Tor for all network traffic by default on Mac OS X"
20+
<https://maymay.net/blog/2013/02/20/howto-use-tor-for-all-network-traffic-by-default-on-mac-os-x/>
21+
- Poor man's SSH VPN <https://github.com/sshuttle/sshuttle>
1622

1723
### Usenet (apparently they still exist)
1824

@@ -244,3 +250,53 @@
244250
`/usr/lib/debug/lib/x86_64-linux-gnu/ld-2.27.so` to
245251
`/lib64/.debug/ld-2.27.so`.
246252
253+
# WiFi monitor mode on macOC
254+
255+
- You need to dissociate from any AP before initiating the scanning:
256+
```
257+
sudo /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -z
258+
```
259+
260+
- Open Wireshark, while selecting interface check the monitor mode checkbox and
261+
start capturing.
262+
- The above command can also be used to switch channel with `-c` option, e.g.
263+
`-c5`
264+
265+
# OpenSSL on macOS
266+
267+
```
268+
export LDFLAGS=-L/usr/local/opt/openssl/lib
269+
export CPPFLAGS=-I/usr/local/opt/openssl/include
270+
export PKG_CONFIG_PATH="/usr/local/opt/openssl/lib/pkgconfig"
271+
```
272+
273+
# Patching android executables
274+
275+
- Copy the appropriate directory from <https://github.com/DexPatcher/dexpatcher-gradle-samples>
276+
- If you see invalid character in resources error:
277+
<https://github.com/DexPatcher/dexpatcher-gradle/issues/24>
278+
- If starting in debug mode fails with error "Session 'app': Error Launching
279+
activity"
280+
- Start in debug mode and let it fail
281+
- Goto "attach debugger to Android process" and select the application
282+
- If you see that certain classes already exits, have the name of the `package`
283+
`AndroidManifest.xml` in `app/src/main/` different from what you have for
284+
original `AndroidManifest.xml`
285+
- If the build fails due to 'aar' errors (can't reproduce the error messages
286+
now), run one of the dexpatcher gradle tasks like `decodeApk`
287+
288+
289+
# Windows RE
290+
291+
- Inno Setup extractor [InnoExtract](https://github.com/dscharrer/InnoExtract)
292+
293+
# Firmware chrooting
294+
295+
- Ref: <https://unix.stackexchange.com/a/222981>
296+
297+
$ cp $(which qemu-arm-static) /mnt/usr/bin
298+
299+
$ chroot /mnt qemu-arm-static /bin/bash
300+
301+
- You can activate the gdb server shim in Qemu using `QEMU_GBD=<port>` env var before
302+
running any program. Ref: <https://unix.stackexchange.com/q/129366>

rfid_reader.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# 125KHz RFID/ID EM USB IC Card Reader Writer Copier Duplicator
2+
3+
Analysis of a cheap RFID reader I got from Ebay.
4+
5+
## Initial analysis
6+
- `lsusb` identifies it as `1a86:dd01 QinHeng Electronics`.
7+
- Searched online for cheap RFID readers, found:
8+
<https://gist.github.com/pgaultier/b870578515a18becc39ce4501a751574>
9+
- The gist said that the reader had a "CH341 USB / Serial Chip". I don't
10+
know what that is, have very less experience in hardware stuff.
11+
- The gist also had some messages for hello, read and write.
12+
- Didn't try the driver mentioned in the gist though.
13+
- I also found
14+
https://github.com/adrianmihalko/ch340g-ch34g-ch34x-mac-os-x-driver which
15+
said that for newer Mac OS you don't need the OEM drivers.
16+
- Opened the cover and found that the one I had with me had "CH552T" chip.
17+
- Searching for the chip, I found
18+
<https://github.com/MarsTechHAN/ch552tool/blob/master/ch55xtool.py>, to flash
19+
firmware on it. I used to code for references.
20+
- Tried the device identification code. It didn't provide the required
21+
response. Maybe the device is in some other mode.
22+
- Note: I ran pyusb on Linux VMware with USB forwarded because Mac OS didn't
23+
allow easy access to the HID interface. Maybe when the protocol is figured
24+
out, I can try hidapi (it has python bidnings) to try and connect from MacOS.
25+
26+
- Found "USB Serial for Android" app. It had a connection profile for ch340, which
27+
was able to establish connection but erred out on some handshake profile.
28+
- Downloaded <https://github.com/mik3y/usb-serial-for-android> and looked at
29+
the code in `Ch34xSerialDriver` class. It has some control in, control out for
30+
init. When I reproduced the first one, it didn't work as expected.
31+
- Used chrome translate to reach <http://www.wch.cn/downloads/CH552EVT_ZIP.html>
32+
which lists some header files. The description also said about `CH554EVT.ZIP`
33+
which contains examples.
34+
- CH554EVT.ZIP had many C code, but a lot of them had comments in Chinese
35+
language. Used Google translate to read them.
36+
37+
- Imaged the disk provided on another laptop and transferred the file here. Found
38+
the DLL file with protocol.
39+
- Tried to imitate the protocol with pyusb, didn't work.
40+
- Ran it with Wireshark USB capture to iron out the details that I counldn't
41+
infer from the DLL, like all packets start with 0x01, and are 64 byte sized.
42+
The unused data is filled with 0xCC.
43+
- running in Windows VM, I couldn't get any HID Prox cards to read, so couldn't
44+
test the read/write opcodes.
45+
- Was able to write to one of the cards provided with the reader and then read
46+
back using pysub or hidapi to connect to the device.
47+
48+
## Protocol
49+
- All packets are 64 byte sized, input & output. Maybe larger data will require
50+
more packets, will cross the bridge when we need that.
51+
- the payload are structured like:
52+
```
53+
0xAA 0x55 0xWW 0xWW 0xOP 0xOP 0xPL 0xPL [payload in hex] 0xCX
54+
```
55+
where:
56+
- `0xAA 0x55` is the header.
57+
- `0xWW 0xWW` represents some data that I always have found to be 0 in request
58+
and 0x1112 in response.
59+
- `0xOP 0xOP` represents the opcode in big endian.
60+
- `0xPL 0xPL` represents the payload length in big endian.
61+
- `[payload]` represents the payload.
62+
- `0xCX` represents the XOR of all the bytes excluding the header bytes.
63+
- Any occurrence of by `0xAA` except in header is escaped as `0xAA 0x00`.
64+
65+
- Each packet is 64 bytes and starts with `0x01` followed by 63 bytes of payload
66+
data. Any unused bytes in the packet is filled with 0xCC.
67+
- The opcodes are as follows:
68+
```
69+
OPCODE_SET_AUTOREAD = 0x801 # one byte payload, always found to be 0
70+
OPCODE_SET_LED = 0x802 # one byte payload, 2 = green, anything else is red
71+
OPCODE_GET_FREQUENCY = 0x805 # no payload
72+
OPCODE_GET_MODEL = 0x806 # no payload
73+
OPCODE_GET_NUMBER = 0x808 # no payload
74+
OPCODE_READ_ID_CARD = 0x809 # no payload
75+
OPCODE_WRITE_EL4100 = 0x810 # 5 byte payload, data to be written
76+
OPCODE_WRITE_T4100 = 0x811 # 6 byte payload, first is 0 or 1, rest is data to be
77+
written. Maybe the first byte is to lock the card or not
78+
OPCODE_WRITE_E4100 = 0x812 # 6 byte payload, first is 0 or 1, rest is data to be written
79+
```
80+
81+
## Working with cards:
82+
- The device I had was not able to read HID cards.
83+
- The cards that came with the device were able to be written using
84+
`OPCODE_WRITE_T4100`.

0 commit comments

Comments
 (0)