Databases [SQL]

Flat-File Databases A “table” written into a single file. The most common file type for this purpose is CSV. The CSV format reads each line as a row, and each comma-separated value as a column. The first row on a CSV file is used to describe the data in each column. If a , is present on the dataset, surround that entry with " to ’escape’ it. These files can be read and written to using languages like c-language and python. ...

7 min · 1378 words · TrudeEH

Debugging [GDB]

GDB Debugging Compile with Debug Information To allow gdb access to the source code (Provides debug symbols - Do not share publicly as it contains the source code). gcc -g <file> Look for / Fix Bugs First, initialize gdb with the executable to debug. gdb ./<executable> --tui After gdb is ready, we can use the following commands: Command Description lay next Switch to the next layout (Enables TUI mode if disabled - Allows for reading the code while debugging both in C and ASM). ref Refresh (if a program prints to the terminal, it can break gdb’s interface).` q Quit gdb. b main Add a breakpoint at the main function. b Place a breakpoint at the current line. b <N> Place a breakpoint at line N. b +<N> Place a breakpoint N lines down. b <fn> Place a breakpoint at fn function. d Delete all breakpoints. d <N> Delete breakpoint number N. clear <fn> Clear the breakpoint set to fn function. n Execute up to the next line in C. If a function call is found, execute the function completely. s Execute up to the next line in C. (Jump over) s <N> Run N lines. u Same as n, but if in a loop, execute until the loop exits. nexti Execute up to the next instruction (line in ASM). r Run the program until a breakpoint or error is reached. c Continue running the program until a breakpoint or error is reached. x/i $pc Examine the previous instruction (View memory). info registers Read the CPU registers used by the program. bt See the call stack up to the current line. (How we got here, so to speak) print sizeof(<variable>) Check the size of a struct/variable/pointer. p <var> Print variable var value. info break List breakpoints. Check for Memory Leaks Use valgrind to check for lost memory. ...

2 min · 310 words · TrudeEH

Encryption [GPG]

Symmetric Encryption User A sends a password to user B. The password is used to encrypt the messages. A secure way to share the password is required. Asymmetric Encryption Users A and B have a public key and a private key. The public keys are shared, and they are used to encrypt the messages. The users can use their private keys to decrypt the messages. GPG Create a Set of Keys gpg --full-gen-key Select ECC (sign and encrypt) - The most secure option Select default curve Encrypt a File gpg --encrypt -r email@example.org <file> # Encrypt with the recipient (-r) key. Decrypt a File gpg --decrypt --output <file-output> <file> # Use the private key to decrypt a file. Encrypt a Message echo "Very safe message" | --encrypt --armor -r email@example.org -armor Saves the encrypted info in plain text. (Great for blog posts or copying/pasting) Decrypt a Message GPG automatically figures out which private key to use. The encrypted file includes some metadata. ...

2 min · 297 words · TrudeEH

Firewall [UFW]

A firewall monitors and controls all incoming and outgoing network traffic, and can be implemented in the hardware or software level. See All Open Ports All ports opened by a program, including those blocked by a firewall. sudo ss -tupln Software Firewall (UFW) # Enable the SSH port if it is being used sudo ufw limit 22/tcp # `limit` is used to prevent bruteforce # Set default connection settings sudo ufw default deny incoming sudo ufw default allow outgoing # Open ports for the services running sudo ufw allow 80/tcp # Web server 1 sudo ufw allow 443/tcp # Web server 2 # Check if UFW is running and is configurations sudo ufw status numbered # Delete an entry sudo ufw delete 2 # Number given by `status numbered` # Enable UFW sudo ufw enable Block Pings Blocking pings prevents hackers from quickly discovering the server. It is still possible to scan all ports on the server and eventually find any open one, but it adds another layer of security. ...

2 min · 282 words · TrudeEH

Flask

Flask is a web framework for Python. It facilitates the creation of web apps (dynamic web pages). Run Flask Flask comes with its own server for debugging purposes, which can be started with: flask run Folder Structure app.py # main code requirements.txt # required libraries static/ # files that never change templates/ # dynamic files “Hello, name” — Example App templates/index.html <!DOCTYPE html> <html lang="en"> <head> <meta name = "viewport" content="initial-scale=1, width=device-width"> <title>Hello</title> </head> <body> hello, {{ name_placeholder }} <!-- Jinja template --> </body> </html> app.py http://website.domain/?name=Trude ...

4 min · 796 words · TrudeEH