Skip to content

Instantly share code, notes, and snippets.

@raresteak
raresteak / keyPress.ps1
Created January 22, 2021 13:23
Simulate key press - keep screen from locking
$WShell = New-Object -com "Wscript.Shell"
while ($true)
{
Echo "Key press"
$WShell.sendkeys("{SCROLLLOCK}")
Start-Sleep -Milliseconds 100
$WShell.sendkeys("{SCROLLLOCK}")
Start-Sleep -Seconds 300
}
@raresteak
raresteak / pythonWget.py
Last active January 22, 2021 20:39
Python3 one liner to download file - like wget
python3 -c "import urllib.request;urllib.request.urlretrieve('https://example.com/spam.tar', filename='spam.tar')"
@raresteak
raresteak / findWriteFiles.sh
Last active January 22, 2021 20:40
Find files you have write access to through Unix group membership which you are not the owner
for i in $(id -G); do find / -type f \! -user $(whoami) -gid $i -perm /g+w -exec ls -l {} \; 2>/dev/null | grep -v proc\/ ; done
@raresteak
raresteak / html_picture_embed.sh
Last active March 5, 2020 14:43
Create self contained html files with embedded images
#!/bin/bash
# Create self contained html files with embedded images
# Usage
# ./html_picture_embed.sh picture.png > html_file.html
# Example https://pastebin.com/K3dDXjfA
PIC=$1
echo -n '<html><img src="data:image/png;base64,'
base64 $PIC | tr -d '\n'
echo '"></html>'
@raresteak
raresteak / wipeFreeSpace.sh
Last active January 22, 2021 20:40
Linux: Wiping free space
# requires shred
dd if=/dev/urandom of=junk bs=1M; shred -v -u -n 1 junk
@raresteak
raresteak / gist:219578890310acaf7cc472589461c1a4
Last active February 6, 2020 20:36
Wiping out your bash session history
export HISTSIZE=0
export HISTFILE=/dev/null
@raresteak
raresteak / gist:69d9057cbcc0c848aa685843bbdfdf45
Created February 6, 2020 18:58
Tail a file and perform some action when keyword is found
tail --retry -s 2 -f /var/log/apache2/access.log | grep --line-buffered 404 | while read ; do echo "404 keyword found, $(doSomeCommand)" ; done
@raresteak
raresteak / generate_random_time.ps1
Created December 13, 2019 11:38
Generate a random time using Powershell
<#
.SYNOPSIS
Create a random time in 24 hour format
.OUTPUTS
Outputs time to standard out.
.NOTES
Version: .1
Author: raresteak
@raresteak
raresteak / udp_listener.sh
Created November 15, 2019 21:38
Persistent UDP listener
#!/bin/bash
# Create a persistent self restarting udp listener to recover from client disconnects
# Usage:
# nohup /path/to/udp_listener.sh &
PORT=60000
RESTART=600
while : ; do
/bin/netcat -u -l ${PORT} >> /path/to/output/file &
@raresteak
raresteak / gen_random_time.sh
Created November 15, 2019 14:55
A short Bash script to generate a random time in 24 hour format.
#!/bin/bash
# Generate a random time in 24H format
# Requires Bash because using builtin Random function
# Author: raresteak
HOUR=$(echo $(($RANDOM % 124)) )
while [ $HOUR -lt "100" ]; do
HOUR=$(echo $(($RANDOM % 124)) )
done
RHOUR=$(echo $HOUR | sed 's/^1//g')