From d8abc8164ccf462fd762e7b9d13433b83091074a Mon Sep 17 00:00:00 2001 From: Andrew Rogers Date: Fri, 20 Oct 2023 05:01:40 -0500 Subject: [PATCH] Blog: Add old blog posts --- blog/2019-03-10_new-site.md | 4 + blog/2019-03-11_introduction-to-qemu.md | 108 +++++++++++++++ blog/2022-02-04_inkscape-eps.md | 22 +++ blog/2022-03-28_FFmpeg-Window-Capture.md | 164 +++++++++++++++++++++++ 4 files changed, 298 insertions(+) create mode 100644 blog/2019-03-10_new-site.md create mode 100644 blog/2019-03-11_introduction-to-qemu.md create mode 100644 blog/2022-02-04_inkscape-eps.md create mode 100644 blog/2022-03-28_FFmpeg-Window-Capture.md diff --git a/blog/2019-03-10_new-site.md b/blog/2019-03-10_new-site.md new file mode 100644 index 0000000..9570f20 --- /dev/null +++ b/blog/2019-03-10_new-site.md @@ -0,0 +1,4 @@ +# New Blog + +This is a new blog that will serve as my central hub for sharing ideas, +tutorials, and thoughts. diff --git a/blog/2019-03-11_introduction-to-qemu.md b/blog/2019-03-11_introduction-to-qemu.md new file mode 100644 index 0000000..ec8e2dc --- /dev/null +++ b/blog/2019-03-11_introduction-to-qemu.md @@ -0,0 +1,108 @@ +# Introduction to QEMU for Hackers + +One of the things that I've noticed in the infosec community is the tendency to +stick to the proprietary virtualization tools that are familiar. +People often are quick discount tools that they don't already know, so I have +written this blog post in an attempt to foster an interest in exploring other +virtualization options. My hope is that, even if you don't come away wanting to +use QEMU in your CTF lab or malware analysis playpen, you will at least be more +open to looking into other forms of emulation and virtualization. + +## The Case for QEMU +Many hacking event organizers spend ample time pointing and clicking through +their VirtualBox and VMware configuration wizards to setup their hacking labs. +What if I told you there was a better way that works on Linux, macOS, Windows, +and Xen? + +### Enter QEMU +With [QEMU](https://www.qemu.org/) your VMs are defined as the arguments passed +to QEMU on its invocation at the command line. For example, you might invoke a +VM as such (note that **`>`** is a +[**$PS2** prompt](http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x157.html)): +``` +$ qemu-system-x86_64 -machine type=q35 --enable-kvm -cpu host -smp cpus=8 \ +> -m 512M -netdev user,id=net0 -device e1000,netdev=net0 -hda dsk/vm-hdd.qcow +``` + +### Shell Scripts as VM Templates + +Obviously this isn't a good long-term way to run your VM, but fear not, as there +is a better way! All you have to do is save your VM arguments to an executable +shell script like the following: +``` +#!/usr/bin/env bash + +# image creation command: +# qemu-img create -f qcow2 -o preallocation=metadata dsk/vm-hdd.qcow 20G + +qemu-system-x86_64 \ + -machine type=q35 \ + --enable-kvm \ + -cpu host \ + -smp cpus=8 \ + -m 512M + -netdev user,id=net0 \ + -device e1000,netdev=net0 \ + -hda dsk/vm-hdd.qcow \ +; +``` + +Don't forget to make your script executable! +``` +$ chmod +x vm-foo +``` + +The nice thing about these scripts is that you can freely copy and edit them +with the standard UNIX command-line tools that you are used to, meaning that +you can use one VM script as a template for another virtual machine. Making a +VM based on a template then becomes as simple as copying a bash script: +``` +$ cp vm-foo vm-bar +``` + +For more information on creating QEMU disk images, see the +[qemu-img(1)](https://linux.die.net/man/1/qemu-img) man page. + +### QEMU's Advanced Features +QEMU is a capable of emulating foreign CPU architectures, as well as working in +conjunction with a hypervisor to perform fully-accelerated, near +native-performance virtualization. Some of the supported architectures for +full-system emulation are: + +- Alpha +- Altera Nios II +- ARM +- Axis ETRAX CRIS +- HP PA-RISC +- i386/x86 +- IBM System/390 +- Microblaze (big and little endian) +- MIPS (big and little) +- MIPS64 (big and little) +- Motorola 68000 +- Moxie +- OpenRISC 1k (IP core for FPGAs) +- PowerPC +- PowerPC 64 (big and little) +- RISC V +- RISC V 64 +- SuperH SH-4 +- SPARC and SPARC32 Plus +- SPARC64 +- TILE-Gx +- Xtensa + +Some of its other features include: + +- Support for the Intel HAXM, Linux KVM, and Xen hypervisors +- PCIe passthrough +- attaching physical disks to VMs +- USB passthrough +- network block devices +- importing and converting disks from other formats +- command-line interactive monitor +- VNC support +- multiple virtual VGA adapters and video modes +- tap/tun support (bridging to actual network interfaces on the host) + +*Stay tuned for more!* diff --git a/blog/2022-02-04_inkscape-eps.md b/blog/2022-02-04_inkscape-eps.md new file mode 100644 index 0000000..b48203c --- /dev/null +++ b/blog/2022-02-04_inkscape-eps.md @@ -0,0 +1,22 @@ +# Inkscape Postscript Export in 2022 + +A lot of older guides using Inkscape to convert SVG images to PostScript +use a `-E` CLI flag that no longer exists in the Inkscape CLI: +~~`inkscape input.svg -E out.eps`~~. + +**The correct way to do this in the *current* year:** +``` +inkscape --export-type=eps -o out.eps in.svg +``` + +If you want to automatically convert all of the `.svg` files in your current +working directory to `.eps` files, you can use something like this script: +```bash +#!/usr/bin/env bash +for svg in *.svg; do + bname=$(basename "$svg" | sed 's/\.svg$//g') + echo "Converting \""$bname"\"..." + echo -e "\tinkscape --export-type=eps -o \"$bname.eps\" \"$svg\"" + inkscape --export-type=eps -o "$bname.eps" "$svg" +done +``` diff --git a/blog/2022-03-28_FFmpeg-Window-Capture.md b/blog/2022-03-28_FFmpeg-Window-Capture.md new file mode 100644 index 0000000..d2f84d8 --- /dev/null +++ b/blog/2022-03-28_FFmpeg-Window-Capture.md @@ -0,0 +1,164 @@ +# FFmpeg Window Capture + +If you've read the FFmpeg website's +[Capture/Desktop](https://trac.ffmpeg.org/wiki/Capture/Desktop) page +or another similar tutorial about screen recording, you may have learned +that the `x11grab` device can be used to capture a specific region of your +screen, but did you know that you can also record a window by it's ID just +like OBS does? + +First, you'll need to find the ID of the window that you want to capture +with `xwininfo`: + +
+ +
+ +Now we can use the `-window_id` parameter of the `x11grab` device with +FFmpeg to capture the window. Here's an example of a "nearly lossless" +MP4 capture at 60 frames per second with a constant quality of `10`: +```bash +ffmpeg -f x11grab -thread_queue_size 4096 -framerate 60 -window_id 0x940000a \ + -c:v libx264 -crf 10 output.mp4 +``` + +### Recording With NVENC + +If you're using an NVIDIA card with proprietary drivers, you can encode with +NVENC: +```bash +ffmpeg -f x11grab -thread_queue_size 4096 -framerate 60 -window_id 0x940000a \ + -c:v hevc_nvenc -preset slow -tune hq -tier high -cq 10 output.mp4 +``` + +## Recording Desktop Audio + +If you'd like to record desktop audio with Pulse or PipeWire, you can find +the name of your audio card with `pactl` (line-wrapped to 80 columns): +``` +$ pactl list short | grep monitor +75 alsa_output.usb-Focusrite_Scarlett_2i2_USB_Y8QUZ0C9981932-00.analog-ster +eo.monitor PipeWire s32le 2ch 48000Hz RUNNING +77 alsa_output.pci-0000_2d_00.1.hdmi-stereo-extra2.monitor PipeWi +e s32le 2ch 48000Hz RUNNING +79 alsa_output.usb-C-Media_Electronics_Inc._USB_Multimedia_Audio_Device-00. +analog-stereo.monitor PipeWire s16le 2ch 48000Hz RUNNING +81 alsa_output.pci-0000_2f_00.4.iec958-stereo.monitor PipeWire +s32le 2ch 48000Hz RUNNING +212 easyeffects_sink.monitor PipeWire float32le 2ch 48000Hz +RUNNING +448 alsa_output.usb-SmartAction_FiiO_USB_Audio_Class_2.0_DAC_0007-00.analog- +stereo.monitor PipeWire s32le 2ch 48000Hz RUNNING +858 soundux_sink.monitor PipeWire float32le 2ch 48000Hz RUNNING +``` + +You can then record audio and video together with FFmpeg like so: +```bash +ffmpeg -f x11grab -thread_queue_size 4096 -framerate 60 -window_id 0x940000a \ + -f pulse -thread_queue_size 8192 -ac 2 \ + -i alsa_output.usb-SmartAction_FiiO_USB_Audio_Class_2.0_DAC_0007-00.analog-stereo.monitor \ + -c:a aac -b:a 256k \ + -c:v libx264 -crf 10 output.mp4 +``` + +## Putting It All Together in a Script + +Below is a script that automates this somewhat. Note that you will +need to edit the `audio_device` variable for the `-a` flag to work. You may +also want to edit the `recording_dir` as well. +```bash +#!/usr/bin/env bash + +recording_dir='.' +date=$(date +%Y-%m-%d_%s) +show_cursor=0 +show_region=0 +record_audio=0 +use_nvenc=0 +prefix="" +audio_device='' + +read -d '' usage <