Monday, November 8, 2021

Good SAML vs SSO article

SAML explained: How this open standard enables single sign on

Friday, July 23, 2021

Download Part of Youtube video instead of whole

 This is a way to download selective frame of the youtube video that you need rather than downloading the whole video and trim it locally.

The sample command below start downloading at 00:06:40.00 and for the duration of 40 secs then output it to a file with filename of out.mp4.  

-f 22 is setting the resolution of the video to 720p. You can also use -f 18 for 360p mp4 resolution or -f 137 for 1080p mp4 resolution.

ffmpeg -ss 00:06:40.00 -t 40 -i $(youtube-dl -f 22 -g "") -acodec copy -vcodec copy -c copy out.mp4

Tuesday, May 4, 2021

CLI Ways to Transfer file Part I

 CLI options:

Easy to use API

Try it out:

$ curl -F "file=@test.txt"
{"success":true,"key":"2ojE41","link":"","expiry":"14 days"}
$ curl
This is a test
$ curl
{"success":false,"error":404,"message":"Not Found"}

Or set an expiration:

$ curl -F "file=@test.txt"
{"success":true,"key":"aQbnDJ","link":"","expiry":"7 days"}
$ sleep 604801
$ curl
{"success":false,"error":404,"message":"Not Found"}

The query param expires must be a positive integer which, by default, represents the number of days until the file will be deleted (defaults to 14 days). If you follow it with w, it will be the number of weeks. m for months and y for years.

You can also send direct text to

$ curl --data "text=this is a secret pw"
{"success":true,"key":"pgiPc2","link":"","expiry":"14 days"}
$ curl
this is a secret pw
$ curl
{"success":false,"error":404,"message":"Not Found"}

Sample use cases

How to upload

# Uploading is easy using curl $ curl --upload-file ./hello.txt $ curl -H "Max-Downloads: 1" -H "Max-Days: 5" --upload-file ./hello.txt # Download the file $ curl -o hello.txt

Add shell function to .bashrc or .zshrc

# Add this to .bashrc or .zshrc or its equivalent transfer(){ if [ $# -eq 0 ];then echo "No arguments specified.\nUsage:\n transfer <file|directory>\n ... | transfer <file_name>">&2;return 1;fi;if tty -s;then file="$1";file_name=$(basename "$file");if [ ! -e "$file" ];then echo "$file: No such file or directory">&2;return 1;fi;if [ -d "$file" ];then file_name="$" ,;(cd "$file"&&zip -r -q - .)|curl --progress-bar --upload-file "-" "$file_name"|tee /dev/null,;else cat "$file"|curl --progress-bar --upload-file "-" "$file_name"|tee /dev/null;fi;else file_name=$1;curl --progress-bar --upload-file "-" "$file_name"|tee /dev/null;fi;} # Now you can use transfer function $ transfer hello.txt

More examples

Upload multiple files at once

$ curl -i -F filedata=@/tmp/hello.txt -F filedata=@/tmp/hello2.txt # Combining downloads as zip or tar archive $ curl,15HKz/hello.txt).tar.gz $ curl,15HKz/hello.txt).zip

Encrypt your files with gpg before the transfer

# Encrypt files with password using gpg $ cat /tmp/hello.txt|gpg -ac -o-|curl -X PUT --upload-file "-" # Download and decrypt $ curl|gpg -o- > /tmp/hello.txt

Scan for malware

# Scan for malware or viruses using Clamav $ wget $ curl -X PUT --upload-file ./ # Upload malware to VirusTotal, get a permalink in return $ curl -X PUT --upload-file nhgbhhj

Backup mysql database, encrypt and transfer

# Backup, encrypt and transfer $ mysqldump --all-databases|gzip|gpg -ac -o-|curl -X PUT --upload-file "-"

Send email with transfer link (uses shell function)

# Transfer and send email with link (uses shell function) $ transfer /tmp/hello.txt | mail -s "Hello World"


# Import keys from keybase $ keybase track [them] # Encrypt for recipient(s) $ cat somebackupfile.tar.gz | keybase encrypt [them] | curl --upload-file '-' # Decrypt $ curl |keybase decrypt

wget uploads also supported

# wget $ wget --method PUT --body-file=/tmp/file.tar -O - -nv

Transfer pound logs

# grep syslog for pound and transfer $ cat /var/log/syslog|grep pound|curl --upload-file -

Upload a file using Powershell

# Upload using Powershell PS H:\> invoke-webrequest -method put -infile .\file.txt

Upload a file using HTTPie

# HTTPie $ http -vv < /tmp/test.log

Upload a file using Unofficially client in Python

# transfersh-cli ( $ transfersh # Uploading file # Download from here: # It has also been copied to the clipboard!

Encrypt your files with openssl before the transfer

# Encrypt files with password using openssl $ cat /tmp/hello.txt|openssl aes-256-cbc -pbkdf2 -e|curl -X PUT --upload-file "-" # Download and decrypt $ curl|openssl aes-256-cbc -pbkdf2 -d > /tmp/hello.txt

Upload a file or directory in Windows

#Save this as transfer.cmd in Windows 10 (which has curl.exe) @echo off setlocal EnableDelayedExpansion EnableExtensions goto main :usage echo No arguments specified. >&2 echo Usage: >&2 echo transfer ^<file^|directory^> >&2 echo ... ^| transfer ^<file_name^> >&2 exit /b 1 :main if "%~1" == "" goto usage timeout.exe /t 0 >nul 2>nul || goto not_tty set "file=%~1" for %%A in ("%file%") do set "file_name=%%~nxA" if exist "%file_name%" goto file_exists echo %file%: No such file or directory >&2 exit /b 1 :file_exists if not exist "%file%\" goto not_a_directory set "" pushd "%file%" || exit /b 1 set "full_name=%temp%\%file_name%" powershell.exe -Command "Get-ChildItem -Path . -Recurse | Compress-Archive -DestinationPath ""%full_name%""" curl.exe --progress-bar --upload-file "%full_name%" "" popd goto :eof :not_a_directory curl.exe --progress-bar --upload-file "%file%" "" goto :eof :not_tty set "file_name=%~1" curl.exe --progress-bar --upload-file - "" goto :eof

Monday, May 3, 2021

How to update -grub from live-CD

 In order to update the grub configuration of the machine that you might be misconfigured and unable to boot up properly you could use live CD to boot into the machine, however, even if you are able to update the /etc/default/grub file, you will need to perform the "sudo update-grub" command to effect the change. if you are using Live CD to login, you need to perform the following steps:

First mount the root directory in question for my case it is my /dev/sda so it is it will be /dev/sda2 as mostly sda1 is for the /boot/efi partition.

You will mount the root partition as follow:

sudo mount /dev/sda2 /mnt

Then mount a few more directories that are needed:

sudo mount --bind /dev /mnt/dev
sudo mount --bind /sys /mnt/sys
sudo mount --bind /proc /mnt/proc
How can you tell if you have a boot partition?

Once you have your Ubuntu partition mounted, open /mnt/etc/fstab. If you see an entry for /boot, note which device it is pointing to (/dev/sda4 maybe?). This is the one you have to mount.

Once these are mounted, do chroot to start using the mounted directory as the root partition:

sudo chroot /mnt

You'll get a #/ prompt. First thing to do is confirm that you're using the correct /boot directory. Go to /boot/grub and look at the files there. There should be a bunch of .mod files and a grub.cfg file. If the directory is empty, don't continue, because it means this is NOT your actual boot directory. Look above to see how to determine if you need to mount an additional boot directory.

Once you've confirmed that /boot/ contains the correct files, meaning that it is the correct location, type:

sudo update-grub

This should rebuild your /boot/grub/grub.cfg file with the menu entries.

Then exit the chroot:


At this point you may want to check that things were correctly updated. For this, cd /mnt/boot/grub and check that grub's files are there, there should be a bunch of .mod files and grub.cfg, the latter should have entries for your Ubuntu kernels. If you only see grub.cfg and no .mod files, it means that this is NOT the correct boot directory, look above for how to mount a separate boot partition.

Unmount the filesystems:

sudo umount /mnt/dev
sudo umount /mnt/sys
sudo umount /mnt/proc
sudo umount /mnt/

And then reboot, hopefully your Grub menu will be restored.