Showing posts with label shell. Show all posts
Showing posts with label shell. Show all posts

Monday, September 13, 2021

General Purpose Randomizer

I've decided to introduce some noise into the fingerprints collected on me by various unnecessarily curious services and people, so I've written a simple randomizer for selecting a string from a list of strings. The idea was to remove patterns from server selection process when using vpn. Not sure it'll work for obfuscation, but it is a functioning piece of code. Life will prove the rest.

Known to be working with Ubuntu+bash+ExpressVPN

#!/bin/bash
vpnservers=$(expressvpn list all | cut -d" " -f 1 | tr "\n" " ")
list=${vpnservers}

# using just a big value for length
# syntax ${parameter:offset:length}

vpnservers=${list:12:1500}
printf "Available vpn servers:\n${vpnservers}\n"

read -a arrayofservers <<< ${vpnservers}

length=${#arrayofservers[@]}
printf "Actual array length:\n$length \n\n"

randomvalue=$((1 + $RANDOM % ${length-1}))
printf "Your random value:\n$randomvalue \n\n"

printf "Your server id:\n${arrayofservers[randomvalue]} \n"



Wednesday, February 26, 2020

Docker commands vs Docker life cycle - Basic level

Earlier I noticed that there's one problem with Docker support documentation. Unfortunately, while it is possible to find out the very basic scenarios in its Get Started section, you need to dig through the Internet for hours to find information about use cases. Use cases is an answer to the question "What are we trying to do here, anyway?".

So, I started to collect this information for myself and pair it with command sets. Below you can find a use case for setting up a docker image and performing some basic commands on it. I shall extend this collection later, if I'm lucky.

Tuesday, July 23, 2019

Troubleshooting Citrix Client for Linux and Fixing Mike Support

Sometimes you find yourself in one of those situations when nobody seems to have an easy solution, so you have to find one for yourself. For instance, you may need to connect to your VDI, and start your Skype meeting only to find that your microphone is disabled (in Skype, in Control Panel > Device manager).

And the answer is
to add AllowAudioInput=True
to the section [WFClient]
of wfclient.ini file
of your Citrix client configuration

So, here is how to fix it in slightly more detail:

Friday, June 7, 2019

Bash - Bulk file update with find and sed

Doing bulk file update (mind escapes when using complicated patterns):

#!/bin/bash

if [ -z $1 ] || [ -z $2 ]  || [ -z $3 ] || [ -z $4 ]; then
        printf "\nPlease enter:\n
        1. file command-compatible filename pattern
        2. backup suffix for affected files
        3. pattern to replace
        4. replacement\n\n
        For instance, $0 *.txt .xml-backup blue red\n
        This should replace blue with red in all txt files\n\n"
        exit
fi


filename_pattern=$1
backup_suffix=$2
pattern_to_replace=$3
replace_with=$4

find . -type f -name ${filename_pattern} -exec sed -i${backup_suffix} "s|${pattern_to_replace}|$replace_with|g" {} \+

Bash - Cut a fragment of a log by some criteria (like timestamp)

Here is how to cut out a piece of a log between two unique strings (like timestamps):

#!/bin/bash

printf "\nResults are returned *inclusive*\n\n"

if [ -z $1 ] || [ -z $2 ] || [ -z $3 ]; then
        printf "\nPlease enter SUBSTRSTART SUBSTREND and LOGPATH\nFor instance, $0 11:59:17,206 12:02:14,606 test.log\n\n"
        exit
fi

substrstart=$1
substrend=$2
logpath=$3

sed -n "/${substrstart}/,/${substrend}/p" ${logpath} | tee log_excerpt-$(date +%F_%H-%M-%S) | cat

Bash - Getting network data for the port (localhost only)

Getting network data:

#!/bin/bash

printf "\nCurrently for localhost only\n\n"

if [ -z $1 ]; then
    printf "Please enter port and [host]\n\n"
    exit
fi

port=$1
host=localhost

printf '========= lsof -i ============\n\n'

lsof -i :${port}

printf '========= netstat -lnt | grep $port ============\n\n'

netstat -lnt | grep ${port}

printf '========= nc -z $host $port  ============\n\n'

nc -z ${host} ${port}


Bash - kill everything with a matching name

Just a small script for killing matching processes by name:

#!/bin/bash

if [ -z $1 ]
then
    printf "keyword is empty\n\n"
    exit
fi

let k=0
let min=1

# mind the double brakets in do part
for i in $(ps -e | grep "$1"); do ((k++)); done

if [ "${k}" -lt "${min}" ]
then
    printf "no such process to kill\n\n"
    exit
fi


for i in $(ps -e | grep $1 | cut -s -f1 -d\t); do kill -9 ${i}; done

Thursday, June 6, 2019

Password generator with bash

Looks like the best way to handle your passwords strongly depends on which password breaking approach is the most effective at the moment, and apparently those ways are changing as quickly as technology develops. Which is why it's unlikely that there will ever be a perfect way to avoid all the risks, but we can design an optimal one.

It occurred to me that first we need to select between two strategies: storing generated password or memorizing them with mnemonics. I don't think it would be a good idea to store memorizable data cause it's too easy to break the pattern, or to try to remember a generated one. As I already can do mnemonics, so I decided to write my own password generator (I like having my own collection of tools).

Solution is based on LINK. Stuff in use: cat, tr, fold, head, /dev/urandom, echo, printf, for each and parameters testing

Sunday, May 19, 2019

Know your round numbers or how to get 2^X with bash

Since I haven't written anything valuable for a long time and still have no ideas how to fix it, here is an example of how bash can actually help you quickly get values of two to the power of something. So, here we go

pg@dana:~$ for i in {1..100}; do calc "2^$i" | xargs echo; done
2
4
8
16
32
64
128
256
512
1024
2048
4096
8192
16384
32768
65536
<...>
1267650600228229401496703205376


Just in case you want to get to the bottom of it, this mini-script uses:
-- my favorite calc application (package name apcalc)
-- cycles (for ... ; do... ; done)
-- ranges ({1..100})
-- redirection with xargs ( | xargs echo)

Enjoy your Linux!

PS: 'Round numbers' in relation to 2^X is actually an inside joke from the times when I couldn't afford to rent my own flat and had to share