This custom script literally saved me from failing OSCP

Just feels wrong to keep it to myself.

This custom script literally saved me from failing OSCP

I almost failed the OSCP exam because I was missing 2 screenshots for the report.

And the proofs were gone after I closed the terminal windows.

But since I've logged everything using this script,

I was able to recover the proof and re-take the screenshots.

Crisis averted.


It only takes a single step to set up:

  1. Copy-and-paste the following script to the end of ~/.zshrc.

# Helper script by @sechurity
# Create a log directory, a log file and start logging
if [ -z "${UNDER_SCRIPT}" ]; then
    logdir=${HOME}/logs
    logfile=${logdir}/$(date +%F.%H-%M-%S).$$.log

    mkdir -p ${logdir}
    export UNDER_SCRIPT=${logfile}
    echo "The terminal output is saving to $logfile"
    script -f -q ${logfile}

    exit
fi

That's it. Now every command's input and output will be recorded and saved in a safe place under ~/logs/ with a timestamp.

These changes will be effective in new windows/tabs.

Demo:

Whenever a new shell session is created, the log path of that session is displayed.

View the logs by using cat.

It will show the log content including the colors of previous inputs and outputs.

But I hope everything goes well so you won't have to use it.