Favourite C++ features

And wish list

C++17 Boost filesystem execution policy: parallel algorithm support for range-based for loops - potential for easily parallelsing existing code structured bindings clamp std::optional [[maybe_unused]] C++20 spaceship operator range based for loops with initialiser bit header coroutines ranges and views - a nod to strongly typed, const languages like Haskell https://en.cppreference.com/w/cpp/utility/source_location https://en.cppreference.com/w/cpp/numeric/constants Wish list See the compiler support matrix. std::format modules - wait for clang12, gcc11 Modules Look interesting but not available until clang-12. [Read More]

Linux CLI tricks

Send a string to an IP/port telnet 80 (echo hello; sleep 1) | telnet 80 echo hello > /dev/tcp/ echo hello | nc localhost 80 See also https://tldp.org/LDP/abs/html/x17974.html https://highon.coffee/blog/reverse-shell-cheat-sheet/ https://catonmat.net/bash-one-liners-explained-part-three http://docs.eggplantsoftware.com/epp/9.0.0/ePP/advovercoming_tcpip_connection_li.htm Target everything but one file git add !(unit.md) Print a random line from a file sed "$(( $RANDOM % $(cat readme.txt | wc -l) ))q;d" readme.txt shuf readme.txt | head -1 Epoch seconds From bash 5. [Read More]

Linux limits

See /usr/include/linux/limits.h.

/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */

#define NR_OPEN         1024

#define NGROUPS_MAX    65536    /* supplemental group IDs are available */
#define ARG_MAX       131072    /* # bytes of args + environ for exec() */
#define LINK_MAX         127    /* # links a file may have */
#define MAX_CANON        255    /* size of the canonical input queue */
#define MAX_INPUT        255    /* size of the type-ahead buffer */
#define NAME_MAX         255    /* # chars in a file name */
#define PATH_MAX        4096    /* # chars in a path name including nul */
#define PIPE_BUF        4096    /* # bytes in atomic write to a pipe */
#define XATTR_NAME_MAX   255    /* # chars in an extended attribute name */
#define XATTR_SIZE_MAX 65536    /* size of an extended attribute value (64k) */
#define XATTR_LIST_MAX 65536    /* size of extended attribute namelist (64k) */

#define RTSIG_MAX         32


C++ tricks/idioms

Get the file name out of a path Concise code to extract everything after the slash (if there is one) without checking std::string::npos. The +1 rounds a “not found” value up to zero if there’s no slash and then substr returns the original string. #include <iostream> int main() { const std::string full_path = "one/two.jpg"; const std::string just_the_file_name = full_path.substr(full_path.find_last_of('/') + 1); std::cout << "\"" << just_the_file_name << "\"\n"; } There can only be one – call a routine only once Using IIFE. [Read More]

Decrypting TLS traffic

In Firefox

A Docker image that runs Chromium headless with SSLKEYLOGFILE set, opens an HTTPS page and dumps the decrypted TLS traffic to the terminal. Also runs in Play with Docker. Pull and run docker run --net host deanturpin/ssldump Dockerfile FROMkalilinux/kali-linux-dockerRUN apt updateRUN apt install -y chromiumRUN apt install -y ssldumpRUN apt install -y psmiscCMD \ # Kill the ssldump in the future or the container won't terminate ((sleep 10s && killall ssldump && cat ~/dump. [Read More]

Simple Python web server

To report browser headers

My work Firefox ESR browser seemed to be giving up my username (I.e., half of my login credentials) in its HTTP headers so I wrote simple Python-based webserver that mirrors the browser HTTP headers back to the browser. The script is encapsulated in a Docker image and could be deployed to an AWS instance. Here the server is started on common HTTP ports. docker run --rm -d -p 80:8080 deanturpin/http docker run --rm -d -p 443:8080 deanturpin/http docker run --rm -d -p 8080:8080 deanturpin/http Dockerfile FROMubuntuRUN apt update --yesRUN apt install --yes pythonCOPY . [Read More]

The lighthouse keeper's son

John James Turpin’s memories of growing up in occupied Jersey at La Corbière lighthouse. Born in 1930. Chapter 1 My father was a full time naval man. Having served before the First World War up until the late twenties, he joined the lighthouse service. He was then in a position to bring his family to the lighthouse cottage which consisted of my mother, my two brothers, my sister and of course myself. [Read More]