2022年2月28日 星期一

Ubuntu 20 C++ Project Init

 

Dockerfile

FROM ubuntu:focal-20220113

USER root

RUN apt-get update

RUN apt-get -y install ninja-build clang file make cmake gdb

RUN apt-get -y install git

CMD tail -F /dev/null  # so that it will not close



Raspberry Pi Stretch to Bullseye (2017 to 2021)
sudo nano /etc/apt/sources.list
change
deb http://raspbian.raspberrypi.org/raspbian/ stretch main contrib non-free rpi
to
deb http://raspbian.raspberrypi.org/raspbian/ bullseye main contrib non-free rpi
sudo apt update  # 950 packages can be upgraded
sudo apt upgrade
sudo reboot
lsb_rebease -d  # Linux 11 (bullseye) not Linux 8 (stretch)
cat /etc/debian_release  # Linux 11 (bullseye) not Linux 8 (stretch)

Raspberry Pi Gcc
sudo apt-get -y install gcc g++ ninja-build clang file make cmake gdb git
gcc --version  # version 10 not version 6
g++ -v # version 10 not version 6
clang --version  # version 11 not version 4
cmake --version # version 3.18, not so nice
# if see <optional> not found, likely g++ version 6 too old, need version 10 newer





2022年2月25日 星期五

WSL Windows Subsystem for Linux, Docker and Clion

Clion with Docker

https://youtu.be/h69XLiMtCT8


CLion Plugins

GitToolBox


Windows Subsystem for Linux WSL

https://docs.microsoft.com/en-us/windows/wsl/install


Upgrade from WSL 1 to WSL 2

https://pureinfotech.com/upgrade-wsl2-wsl1-windows-10/

Enter username and password (this account is Linux Admin, can sudo ls)

Windows 10 > Start > Ubuntu


Windows Terminal

https://github.com/microsoft/terminal

release page, download Microsoft.WindowsTerminal_1.12.10393.0_8wekyb3d8bbwe.msixbundle

Windows 10 > Start > Terminal > ubuntu

Command Pallatte: CTRL SHIFT P
New tab: CTRL SHIFT T
New pane: ALT SHIFT + or - or D

Settings JSON: SHIFT click "settings"

WSL File Storage

explorer.exe > \\wsl$\Ubuntu\home\ricky


Visual Studio Code

https://docs.microsoft.com/en-us/windows/wsl/tutorials/wsl-vscode

Install "Remote Development" from https://marketplace.visualstudio.com/, so that GUI as client, GIT and files on server

Windows Terminal > Ubuntu:

sudo apt-get update
sudo apt-get install wget ca-certificates
code .

Windows > Start > Visual Studio Code:

CTRL SHIFT P (single hand rightmost) >  wsl (Remote New WSL Windows)


Visual Studio (TBC)

// Visual Studio offers native WSL support for C++ cross-platform development

https://docs.microsoft.com/en-us/cpp/linux/download-install-and-setup-the-linux-development-workload (easy)
https://docs.microsoft.com/en-us/cpp/linux/create-a-new-linux-project (easy)
https://docs.microsoft.com/en-us/cpp/linux/cmake-linux-project (easy)
https://docs.microsoft.com/en-us/cpp/linux/cmake-linux-configure


https://docs.microsoft.com/en-us/cpp/build/walkthrough-build-debug-wsl2?view=msvc-170 (not read yet)


Powershell

C:\Users\ricky\wsl ls -la

wsl ls -la | findstr "git"

dir | wsl grep git

notepad.exe .bashrc


Windows 11 with Ubuntu GUI app (TBC, use gen 6 not gen5)

https://docs.microsoft.com/en-us/windows/wsl/tutorials/gui-apps (not read)


End

Ubuntu 20.04 on Windows 10 Hyper V HyperV not VirtualBox Virtual Box

 https://dellwindowsreinstallationguide.com/ubuntu-20-04-lts-hyper-v/


1. Generation 2

2. 2CPU, 4GB RAM

3. Secure Boot, Microsoft UEFI Certificate Authority, Trusted Platform Module

4. Guest services, disable check point


2022年2月23日 星期三

Clang 9 on Ubuntu 20 (2022)

 First



sudo apt-get install cmake

sudo apt-get install ninja-build

sudo apt install clang-9

sudo apt install clang-format-12

sudo apt install clang-format (or sudo apt install clang-format-9.0)




$ ninja --version
1.10.0

$ cmake --version
cmake version 3.16.3

$ clang-9 --version
clang version 9.0.1-12 
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

$ clang-format --version
clang-format version 10.0.0-4ubuntu1 


End

2022年2月18日 星期五

Wireshark Dissector WSGD 2022

https://wintermade.it/blog/posts/how-to-write-generic-dissectors-in-wireshark.html

2022-02-16


OS

Ubuntu 20 using apt-get install wireshark with version 3.2

Windows 10 with Wireshark 3.6.2 64 bit

C:\Program Files\Wireshark\plugins\3.6\epan\

Or Linux

sudo cp generic.so /usr/lib/x86_64-linux-gnu/wireshark/plugins/3.2/epan

sudo cp custom.wsgd /usr/lib/x86_64-linux-gnu/wireshark/plugins/3.2/epan

sudo cp custom.fdesc /usr/lib/x86_64-linux-gnu/wireshark/plugins/3.2/epan


# udp_server.py

import socketserver

class CustomHandler(socketserver.DatagramRequestHandler):
def handle(self):
data = self.request[0].strip()
print(data)

if __name__ == "__main__":
print("server starting")
serv = socketserver.UDPServer(("127.0.0.1", 8756), CustomHandler)
serv.serve_forever()


udp_client.py

import socket
import struct
import random
import string
import time

HOST, PORT = "localhost", 8756

# SOCK_DGRAM is the socket type to use for UDP sockets
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

# refer to `pydoc struct`
HEADER_STRUCT = "".join([
">", # network byte order
"L", # counter
"B", # message size
"B", # message type (0: word, 1: number)
])

PAYLOAD_WORD_TYPE = HEADER_STRUCT + "".join([
"B", # word length
"100s", # string (at most 100 characters)
])
word_struct = struct.Struct(PAYLOAD_WORD_TYPE)

PAYLOAD_NUMBER_TYPE = HEADER_STRUCT + "".join([
"B", # number
"B", # 0: even, 1: odd
"B", # unsigned char
"H", # unsigned short
"I", # unsigned int
"Q", # unsigned long long
])
number_struct = struct.Struct(PAYLOAD_NUMBER_TYPE)

msg_counter = 0
for _ in range(3):
msg_counter += 1

# prepare data to send
if random.random() < 0.99:
num = random.choice(range(256))
is_even = num & 1
ui8 = pow(2,8)-1 # 255
ui16 = pow(2,16)-1 # 65535
ui32 = pow(2,32)-1 # 4294967295
i64 = pow(2,63)-1 # 9223372036854775807 ok
i64 = pow(2,63) # 9223372036854775808 become -9223372036854775808:int64
data = number_struct.pack(msg_counter, 2, 1, num, is_even, ui8, ui16, ui32, i64)
#data = number_struct.pack(msg_counter, 2, 1, num, is_even)
else:
string_len = random.choice(range(100))
the_string = bytes("".join(random.choice(string.ascii_letters+" ") for i in range(string_len)), "ascii")
data = word_struct.pack(msg_counter, 101, 0, string_len, the_string)

# send the message
sock.sendto(data, (HOST, PORT))

# wait 200ms
time.sleep(0.2)

# file custom.wsgd

# protocol metadata

PROTONAME Custom Protocol over UDP

PROTOSHORTNAME Custom

PROTOABBREV custom


# conditions on which the dissector is applied:

# the protocol will be applied on all UDP messages with port = 8756

PARENT_SUBFIELD udp.port

PARENT_SUBFIELD_VALUES 8756


# the name of the header structure

MSG_HEADER_TYPE                    T_custom_header

# field which permits to identify the message type.

MSG_ID_FIELD_NAME                  msg_id

# the main message type - usually it is a fake message, built of one

#    of the possible messages

MSG_MAIN_TYPE                      T_custom_switch(msg_id)


# this token marks the end of the protocol description

PROTO_TYPE_DEFINITIONS


# refer to the description of the data format

include custom.fdesc;



# file custom.fdesc

# here, we define an enumerated type to list the type of messages

#   defined in our protocol

enum8 T_custom_msg_type

{

    word_message   0

    number_message 1

}


# here, we define the structure of the header.

# The header (the same for each message type) must...

struct T_custom_header

{

    # ... define the order of the data

    byte_order big_endian;

    uint32 counter;

    uint8  size_after_header;

    # ... contain the field defined as MSG_ID_FIELD_NAME

    T_custom_msg_type msg_id;

}


struct T_word_message

{

    T_custom_header header;

    uint8           word_len;

    # array of characters

    char[word_len]  word;

    # "word" messages will always have some unused trailing bytes:

    #   they can be marked as raw(*) - the size is calculated at runtime

    raw(*)          spare;

}


struct T_number_message

{

    T_custom_header header;

    uint8           number;

    bool8           is_even;

uint8           uint8;

uint16           uint16;

uint32           uint32;

int64{min=0:max=9223372036854775807}           int64;

}


# T_custom_switch is the main message (as defined in the protocol description)

# according to the parameter msg_id (of type T_custom_msg_type), we define

# the main message to be defined by a single message: either T_word_message or T_number_message.

switch T_custom_switch T_custom_msg_type

{

case T_custom_msg_type::word_message :   T_word_message "";

case T_custom_msg_type::number_message : T_number_message "";

}

Result














more

Multicast

Ubuntu
# route add -net 224.0.0.0 netmask 240.0.0.0 dev lo
# ifconfig lo multicast

# multicast_server.py

import socket
import struct

MCAST_GRP = '224.1.1.1'
MCAST_PORT = 8756
IS_ALL_GROUPS = True

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
if IS_ALL_GROUPS:
# on this port, receives ALL multicast groups
sock.bind(('', MCAST_PORT))
else:
# on this port, listen ONLY to MCAST_GRP
sock.bind((MCAST_GRP, MCAST_PORT))
mreq = struct.pack("4sl", socket.inet_aton(MCAST_GRP), socket.INADDR_ANY)

sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)

while True:
# For Python 3, change next line to "print(sock.recv(10240))"
print(sock.recv(10240))

# multicast_client.py

import socket
import struct
import random
import string
import time

# Ubuntu: add a new route
# route add -net 224.0.0.0 netmask 240.0.0.0 dev lo
# ifconfig lo multicast

MCAST_GRP = '224.1.1.1'
MCAST_PORT = 8756
# regarding socket.IP_MULTICAST_TTL
# ---------------------------------
# for all packets sent, after two hops on the network the packet will not
# be re-sent/broadcast (see https://www.tldp.org/HOWTO/Multicast-HOWTO-6.html)
MULTICAST_TTL = 2

# refer to `pydoc struct`
HEADER_STRUCT = "".join([
">", # network byte order
"L", # counter
"B", # message size
"B", # message type (0: word, 1: number)
])

PAYLOAD_WORD_TYPE = HEADER_STRUCT + "".join([
"B", # word length
"100s", # string (at most 100 characters)
])
word_struct = struct.Struct(PAYLOAD_WORD_TYPE)

PAYLOAD_NUMBER_TYPE = HEADER_STRUCT + "".join([
"B", # number
"B", # 0: even, 1: odd
"B", # unsigned char
"H", # unsigned short
"I", # unsigned int
"Q", # unsigned long long
])
number_struct = struct.Struct(PAYLOAD_NUMBER_TYPE)

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, MULTICAST_TTL)

msg_counter = 0
for _ in range(3):
msg_counter += 1

# prepare data to send
if random.random() < 0.99:
num = random.choice(range(256))
is_even = num & 1
ui8 = pow(2,8)-1 # 255
ui16 = pow(2,16)-1 # 65535
ui32 = pow(2,32)-1 # 4294967295
i64 = pow(2,63)-1 # 9223372036854775807 ok
i64 = pow(2,63) # 9223372036854775808 become -9223372036854775808:int64
data = number_struct.pack(msg_counter, 2, 1, num, is_even, ui8, ui16, ui32, i64)
#data = number_struct.pack(msg_counter, 2, 1, num, is_even)
else:
string_len = random.choice(range(100))
the_string = bytes("".join(random.choice(string.ascii_letters+" ") for i in range(string_len)), "ascii")
data = word_struct.pack(msg_counter, 101, 0, string_len, the_string)

# send the message
sock.sendto(data, (MCAST_GRP, MCAST_PORT))

# wait 200ms
time.sleep(0.2)

Wireshark (multicast)





















more







2022年2月16日 星期三

Wireshark Build from source and dissector

https://gist.github.com/syneart/2d30c075c140624b1e150c8ea318a978


apt-get

sudo apt-get -y update
sudo apt-get -y upgrade
sudo apt-get -y autoremove
sudo apt-get install -y build-essential git cmake
sudo apt-get install -y cmake3
sudo apt-get install -y qttools5-dev qttools5-dev-tools libqt5svg5-dev qtmultimedia5-dev
sudo apt-get install -y libpcap-dev
sudo apt-get install -y libc-ares-dev
sudo apt-get install -y libgcrypt20-dev
sudo apt-get install -y libglib2.0-dev
sudo apt-get install -y flex bison
sudo apt-get install -y libpcre2-dev

build

git clone https://github.com/wireshark/wireshark ~/wireshark
cd ~/wireshark
mkdir build
cd build
cmake ../
make -j`nproc` && {
  echo "\nBuild Success!"
  echo "You can execute the Wireshark by command \"sudo ./wireshark\""
  echo "at \"`pwd`/run\""
}

run

cd ~/wireshark/build/run
./wireshark
GUI > Help > About Wireshark > Version 3.7.0 (v3.7.0rc0-1344-g8cb519153c2f)
GUI > Help > About Wireshark > Plugins > ~/wireshark/build/run/plugins/3.7/epan
http://wsgd.free.fr/download.html > Linux 64 bits build on Ubuntu > 3.6.X 64 bit


https://wintermade.it/blog/posts/how-to-write-generic-dissectors-in-wireshark.html


Note about heuristic

For the below .wsgf content
PARENT_SUBFIELD tcp.port
PARENT_SUBFIELD_VALUES 8000
PARENT_HEURISTIC tcp
HEURISTIC_FUNCTION heuristic_function

Protocol will be identified either "tcp.port==8000" or "bool heuristic_function". This means is the tcp.port was set incorrectly then there will be a lot of wrong data being identified as the same protocol.


asdasdasas

asdasdasas

more

2022年2月15日 星期二

Telegram sms 2022

On new android phone (Sony Xperia XZ F8332)
Insert sim card 6631xxxx
download telegram from play store
Login to telegram
Use main telegram to add 6631xxxx using telegram
Download github telegram-sms release app-release.apk
需要允許來自此源
主號碼TG將機械人令牌(token)以及會話ID(chat id)例如160833123:AAE以及-526912345發送到副號碼
關於選項:
轉寄簡信到新任電話號碼:選取
監視電池電量變化:選取
監控充電器變化:選取
取得聊天指令:選取
驗證碼自動提取:No
顯示sim卡別名:選取
僅回應包含機械人使用者的指令:No
使用安全化域名:選取
測試並儲存
是否讓app永遠在背景執行?允許
選取測試並且儲存,收到TG信息,搞掂

指令:
主號可以在chat group裡面發送「/sendussd1 *#149*888#」,得到「[SIM1(MORE Mobile) 收到簡訊] 來自: 85263974313 內容: 帳戶結餘,$0.01,電話號碼:52094052,最後使用日期:2022/04/30 23:59」
發送/getinfo,得到「[系統訊息] 電池電量: 79% 網路狀態: WIFI SIM1: MORE Mobile SIM2: MORE Mobile」

測試:
第一:重啟Android,確保可以轉發短信。估計重啟之後Telegram-sms沒有自動運行因此不可以處理/getinfo等指令,需要手動啟動telegram-sms一次才可以處理指令,未能處理指令的影響不大。
第二:預設短信處理程序使用內置app而非telegram-sms的話,重啟android之後也是可以成功轉發短信的。在Sony XZ上面試過成功!


2023 Promox on Morefine N6000 16GB 512GB

2023 Promox on Morefine N6000 16GB 512GB Software Etcher 100MB (not but can be rufus-4.3.exe 1.4MB) Proxmox VE 7.4 ISO Installer (1st ISO re...