Blog: Add old blog posts
This commit is contained in:
parent
8303410a25
commit
d8abc8164c
4 changed files with 298 additions and 0 deletions
4
blog/2019-03-10_new-site.md
Normal file
4
blog/2019-03-10_new-site.md
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
# New Blog
|
||||||
|
|
||||||
|
This is a new blog that will serve as my central hub for sharing ideas,
|
||||||
|
tutorials, and thoughts.
|
||||||
108
blog/2019-03-11_introduction-to-qemu.md
Normal file
108
blog/2019-03-11_introduction-to-qemu.md
Normal file
|
|
@ -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!*
|
||||||
22
blog/2022-02-04_inkscape-eps.md
Normal file
22
blog/2022-02-04_inkscape-eps.md
Normal file
|
|
@ -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
|
||||||
|
```
|
||||||
164
blog/2022-03-28_FFmpeg-Window-Capture.md
Normal file
164
blog/2022-03-28_FFmpeg-Window-Capture.md
Normal file
|
|
@ -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`:
|
||||||
|
|
||||||
|
<center>
|
||||||
|
<video height="100%" width="700vmin" autoplay loop>
|
||||||
|
<source src="/media/xwininfo.mp4" type="video/mp4" />
|
||||||
|
</video>
|
||||||
|
</center>
|
||||||
|
|
||||||
|
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 <<EOF
|
||||||
|
USAGE
|
||||||
|
window-capture [OPTIONS]
|
||||||
|
|
||||||
|
OPTIONS
|
||||||
|
-h Show this help.
|
||||||
|
-a Capture audio. Make sure you modify the "audio_device" in the script!
|
||||||
|
-n Encode with NVENC.
|
||||||
|
-c Capture X cursor (disabled by default).
|
||||||
|
-s Show capture region.
|
||||||
|
-p Filename prefix (override default from window title).
|
||||||
|
-d Capture directory (override "$recording_dir").
|
||||||
|
EOF
|
||||||
|
|
||||||
|
chomp(){ sed 's/^\s\+//' | sed 's/\s\+$//' ; }
|
||||||
|
|
||||||
|
while getopts ':hcsp:d:an' opt; do
|
||||||
|
case ${opt} in
|
||||||
|
h)
|
||||||
|
cat <<<"$usage"
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
c)
|
||||||
|
show_cursor=1
|
||||||
|
;;
|
||||||
|
s)
|
||||||
|
show_region=1
|
||||||
|
;;
|
||||||
|
p)
|
||||||
|
prefix="$OPTARG"
|
||||||
|
;;
|
||||||
|
d)
|
||||||
|
recording_dir="$OPTARG"
|
||||||
|
;;
|
||||||
|
a)
|
||||||
|
[ -z "$audio_device" ] \
|
||||||
|
&& echo 'ERROR: Set "audio_device" first!' \
|
||||||
|
&& exit 1
|
||||||
|
record_audio=1
|
||||||
|
;;
|
||||||
|
n)
|
||||||
|
use_nvenc=1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
cat <<<"$usage"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
window_info=$(xwininfo)
|
||||||
|
winid_line=$(grep '^xwininfo:\s\+[wW]indow\s\+[iI][dD]:\s\+' <<<"$window_info")
|
||||||
|
window_id=$(awk '{print $4}' <<<"$winid_line")
|
||||||
|
if [ -z "$prefix" ]; then
|
||||||
|
prefix=$( \
|
||||||
|
sed 's/^xwininfo:\s\+[wW]indow\s\+[iI][dD]:\s\+[0-9xXa-fA-F\]\+\s\+"\(.*\)"\s*$/\1/' \
|
||||||
|
<<<"$winid_line" \
|
||||||
|
| sed 's/\s/_/g' | sed 's/\~/home/g' | sed 's/\//-/g' | sed 's/@/_/g' | chomp)
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $record_audio -eq 1 ]; then
|
||||||
|
audio_opts="-f pulse -thread_queue_size 8192 -ac 2 -i $audio_device -c:a aac -b:a 256k"
|
||||||
|
else
|
||||||
|
audio_opts="-an"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $use_nvenc -eq 1 ]; then
|
||||||
|
enc_opts='-c:v hevc_nvenc -preset slow -tune hq -tier high -cq 10'
|
||||||
|
else
|
||||||
|
enc_opts='-c:v libx265 -crf 10'
|
||||||
|
fi
|
||||||
|
|
||||||
|
ffmpeg \
|
||||||
|
-f x11grab -thread_queue_size 8192 -framerate 60 -window_id $window_id \
|
||||||
|
-show_region $show_region -draw_mouse $show_cursor -i :0.0 \
|
||||||
|
$audio_opts \
|
||||||
|
$enc_opts \
|
||||||
|
"$recording_dir/$prefix"_"$date.mkv" \
|
||||||
|
;
|
||||||
|
```
|
||||||
|
|
||||||
|
[DOWNLOAD](/blob/window-capture)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue