Introduction

This's my personal wiki (brain dump), detailing almost everything I know.

Tools

Notes

Todo

  1. Update dotfiles.
  2. Update repo.

TabNine

Tested on sublime text, high memory usage so turned off local usage. More tests required.

Programming

I'm still a beginner.

Raspberry

Change password to password

Edit /etc/shadow on SD card, change the hashed password to

$1$salt$qJH7.N4xYta3aEG/dfqo/0

Bash

Special characters in file names

- is recognized as stdin, so use ./- for checking filenames beginning with -.

Use "hello world" when names contain spaces.

IO redirection

Note: Basic file descriptor (fd) for shell's operation are 0 for STDIN, 1 for STDOUT, 2 for STDERR.

I used this code for OverTheWire Bandit 25.

#!/bin/bash

# Link fd3 to localhost:30002 bidirectional
exec 3<>/dev/tcp/localhost/30002	
# Print out first line from fd3
head -1 <&3							

old_password="UoMYTrfrBFHyQXmg6gzctqAwOmw1IohZ"

for i in {0000..9999}
do
    answer="${old_password} ${i}"
    # Send to fd3
    echo $answer >&3				
    response=$(head -1 <&3)
    if ! [[ $response =~ "Wrong" ]]
    then
        echo $i
        break
    fi
done

# Reset fd3 to normal
exec 3>&-

Variables

No spaces between =, ie. x=23. String interpolation uses ${}.

x="hello"
y="world"
z="${x} ${y}"

netcat

Use nc to create a server/client to send tcp.

# Server
nc -l 1234
# Client
nc localhost 1234

Server

I'm using Ansible playbook to automate setting up vps.

TODO

Add:

  • security
  • wireguard
  • pihole

Projects

A few personal projects.

Homepass

StreetPass

3DS has a built-in feature StreetPass which lets nearby users to exchange data from games and applications. This is great if you live in a big city where there are a lot of 3DS devices. However, if you live in a small town, you would be lucky to just get a handful of streetpasses monthly.

StreetPass Relay

Due to that, Nintendo introduced another feature called StreetPass Relay. Every 3DS device has a whitelist of public wifi AP which it can automatically connect to. If connected, some data will be sent and stored on Nintendo server. When another 3DS user connects to the same AP, Nintendo server will send the stored data to the latter device. Consequently, 3DS devices don't have to be in close proximity to exchange data.

The whitelist contains the SSID and MAC of public wifi AP. Thus, some nice people figured out ways to create homemade StreetPass relays by spoofing MAC and SSID1. The basic idea to create a public wifi AP with the same SSID and MAC as in the whitelist.

For Raspberry Pi, there is SpillPass-Pi2 which work automatically when you plug in. You only need a wifi dongle wlan0 which support mac spoof and a wired internet connection eth0.

My setup is slightly different because I don't have a wired connection to the home router. What I have is 2 wifi dongles, wlan0 and wlan1. The idea is still the same, but instead of eth0 bridge to wlan0, I have wlan1 connected to the internet and wlan0 as wifi AP. All the traffic are forwarded to/from wlan0 to wlan1.

Setup

I used Raspbian Jessie Lite image. I don't have external keyboard or monitor so desktop on Raspberry Pi is unnecessary. Installed the image on the SD card by either dd or Etcher, then added your wifi network to /etc/wpa_supplicant/wpa_supplicant.conf.2

#/etc/wpa_supplicant/wpa_supplicant.conf
network={
    ssid="testing"
    psk="testingPassword"
}

Updated and installed softwares:

sudo apt update && sudo apt upgrade
sudo apt -y install hostapd dnsmasq haveged iptable-persistent sqlite3

I used this wonderful guide to setup forwarding.

Interfaces

Set wlan0 to a static ip address 10.0.0.1.

#/etc/network/interfaces
auto lo
iface lo inet loopback

iface eth0 inet manual

# AP
allow-hotplug wlan0
iface wlan0 inet static
    address 10.0.0.1
    netmask 255.255.255.0

# wireless
allow-hotplug wlan1
iface wlan1 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

Tell DHCPCD to ignore wlan0.

#/ect/dhcpcd.conf
denyinterfaces wlan0

Hostapd

Hostapd is an user daemon to start up AP. In /etc/default/hostapd, uncomment or add the line DAEMON_CONF=/etc/hostapd/hostapd.conf.

#/etc/hostapd/hostapd.conf
#sample hostapd.conf
#overwrite by homepass.sh

ssid=attwifi
bssid=34:bd:c8:db:79:00

interface=wlan0
driver=nl80211

hw_mode=g
channel=6
auth_algs=3
wpa=0
rsn_pairwise=CCMP
beacon_int=100

macaddr_acl=0

wmm_enabled=0
eap_reauth_period=360000000

You can test if AP is working by running sudo hostapd /etct/hostapd/hostapd. You should be able to see attwifi.

I use dnsmasq to map IP addresses to MAC addresses. When 3DS connect to my hotspot, it will be assigned a dynamic IP address. It is also possible to bind 3DS MAC address to a static IP address.

#/etc/dnsmasq.conf
interface=wlan0
except-interface=wlan1
dhcp-range=10.0.0.2,10.0.0.255,12h

Port forwarding

In /etc/sysctl.conf, uncomment net.ipv4.ip_forward=1.

sudo iptables -t nat -A POSTROUTING -o wlan1 -j MASQUERADE
sudo iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o wlan1 -j ACCEPT
sudo sh -c 'iptables-save > /etc/iptables/rules.v4'

Start services sudo service hostapd start && sudo service dnsmasq start. Reboot Raspberry Pi and test if attwifi can be connected to the internet.

systemd service and timer

I use systemd to run my homepass.sh at boot time and the script will rerun every 5 minutes to change wlan0 to new SSID and MAC.

#/etc/systemd/system/homepass.service
[Unit]
Description=Homepass

[Service]
ExecStart=/home/pi/homepass.sh

[Install]
WantedBy=multi-user.target
#/etc/systemd/system/homepass.timer
[Unit]
Description=Run homepass.service every 5 minutes

[Timer]
OnStartupSec=10
OnUnitActiveSec=5min
Unit=homepass.service

[Install]
WantedBy=multi-user.target

Enable the timer by executing this command

systemctl enable homepass.timer
systemctl start homepass.timer

A nice feature of using systemd to run the script is we can access the logging easily for debugging

journalctl -u homepass

homepass.sh

This script was modified from orginal script by Semperverus. You can check out his guide for more details about HomePass. I took the idea of using sqlite3 to store MAC and SSID in a database from danielhoherd's script.

The script is rerun every 5 minutes by systemd. It stops current running hostapd service. A new /etc/hostapd/hostapd.conf is generated from querying MAC and SSID from a database. The hostapd service is then restarted with the new conf file.

#!/bin/bash
service hostapd stop

SLEEP_TIME=300
DB=/home/pi/homepass.db
CONFIG_FILE=/etc/hostapd/hostapd.conf

if [[ ! -e "$CONFIG_FILE" ]] ; then
  touch "$CONFIG_FILE"
fi

read -d '' query << EOF
SELECT mac, ssid
FROM aps
WHERE last_used < datetime('now', '-2 days') OR last_used IS NULL
ORDER BY random()
LIMIT 1;
EOF

result=$(sqlite3 "$DB" "$query")
resultArr=(${result//|/ })

MAC=${resultArr[0]}
SSID=${resultArr[1]}

if [[ -z "$MAC" ]] || [[ -z "$SSID" ]] ; then
  echo "missing MAC or SSID"
  exit 1
fi

sqlite3 "$DB" "UPDATE aps SET last_used = datetime('now') WHERE mac = '$MAC'"

cat > $CONFIG_FILE << EOF
ssid=$SSID
bssid=$MAC

interface=wlan0
driver=nl80211

hw_mode=g
channel=6
auth_algs=3
wpa=0
rsn_pairwise=CCMP
beacon_int=100

macaddr_acl=0

wmm_enabled=0
eap_reauth_period=360000000
EOF

echo "==========================================="
echo "SSID:" $SSID "- BSSID:" $MAC
echo "Time before next change:" $SLEEP_TIME "seconds"
echo "Current time:" $(date)
echo "==========================================="

service hostapd start

All files

You can find all my files at my github repo.

Games

Gaming is my hobby to pass the time.

Those days I mostly play mobile gatcha games instead of pc games. I usually purchase monthly packages so I'm not a f2p player. I used to balk at the idea of paying monthly subscription to MMOs, but now I do it without blinking for mobile games.

Playing

Girls' Frontline

Guns as anime girls.

Arknights

Tower defense with anime girls (80% of the roster) and some males.

Monster Train

I'm a big fan of Slay the Spire and the former game scratches the same itch. It combines deck building with tower defense, which are pretty cool.

Finished

Persona 4 Golden

I started playing Persona 4 back in 2008; I lost my save so never finished it. As the game came to PC, I finally had the chance and motivation to restart and beat it.

The gameplay is great, I'd describe it as traditional turn based JRPG combined with dating sim. IMO the story does overstay its welcome, the beginning feels too long and there are lot of downtimes in the middle. Moreover I prefer darker theme of Persona 3 to Persona 4. Persona 4 is still a great game though.

I got the golden ending on 7/5/2020. I'm missing a few achievements; I am not a completionist so I don't feel like starting new game + any time soon.

Thanks to the game, I became a longtime fan of SMT series and Atlus. I imported Demon's Souls, SMT: Strange Journey and SMT: Devil Survivor to UK when I was in college. Funny enough, I also lost my save to Strange Journey; maybe one day I'll attempt to complete Strange Journey Redux.

Books

I'm reading

  • Reverend Insanity: evil MC, cultivation story.
  • Lord of the Mysteries: steampunk setting, cool story. The first 100 chapters are tedious, but it keeps getting better after that.
  • Kumo: Japanese reincarnation light novel.
  • Tearmoon Empire: finished first book. Fun light-hearted story.
  • Bakarina: reading volume 3. It's not as good as the first 2 books.