diff --git a/.gitignore b/.gitignore index e83aec7..5f83b9f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,4 @@ logs/ # editor configs .vscode -.idea \ No newline at end of file +.idea diff --git a/moshell.sh/lib/.keep b/moshell.sh/core/.keep similarity index 100% rename from moshell.sh/lib/.keep rename to moshell.sh/core/.keep diff --git a/moshell.sh/lib/banner.sh b/moshell.sh/core/banner.sh similarity index 100% rename from moshell.sh/lib/banner.sh rename to moshell.sh/core/banner.sh diff --git a/moshell.sh/lib/cli.sh b/moshell.sh/core/cli.sh similarity index 61% rename from moshell.sh/lib/cli.sh rename to moshell.sh/core/cli.sh index 9cd568d..9e03ff1 100644 --- a/moshell.sh/lib/cli.sh +++ b/moshell.sh/core/cli.sh @@ -3,30 +3,6 @@ ## Utility functions -# usage: -# _moshell::log error "lorem ipsum" -function _moshell::log { - # if promptsubst is set, a message with `` or $() - # will be run even if quoted due to `print -P` - setopt localoptions nopromptsubst - - # $1 = info|warn|error|debug - # $2 = text - # $3 = (optional) name of the logger - - local logtype="$1" - local logname="" # TODO: inpired in OhMyZSH - - # Choose coloring based on log type - case "$logtype" in - prompt) print -Pn "%S%F{blue}$logname%f%s: $2" ;; - debug) print -P "%F{white}$logname%f: $2" ;; - info) print -P "%F{green}$logname%f: $2" ;; - warn) print -P "%S%F{yellow}$logname%f%s: $2" ;; - error) print -P "%S%F{red}$logname%f%s: $2" ;; - esac >&2 -} - function _moshell::confirm { # If question supplied, ask it before reading the answer # NOTE: uses the logname of the caller function @@ -54,16 +30,24 @@ Available commands: help Print this help message edit Edit moshell configurations reload Reload the configuration - update Update Moshell.sh + update TODO: Update Moshell.sh version Show the version EOF } +function _moshell::edit { + local msg="Openning in your prefered editor: $EDITOR... " + _moshell::log info $msg + sleep 1 + $EDITOR $_MOSHEL_DIR_BASE + return 0 +} + function _moshell::reload { - # TODO: source moshell index - echo "[INFO] Recharged Settings" + _moshell::log info $msg source "$_MOSHEL_DIR_BASE/moshell.sh" + return 0 } function _moshell::version { @@ -74,17 +58,19 @@ function _moshell::version { # 1) try tag-like version # 2) try branch name # 3) try name-rev (tag~ or branch~) - local version - version=$(command git describe --tags HEAD 2>/dev/null) || - version=$(command git symbolic-ref --quiet --short HEAD 2>/dev/null) || - version=$(command git name-rev --no-undefined --name-only --exclude="remotes/*" HEAD 2>/dev/null) || - version="" + local remote_version + remote_version=$(command git describe --tags HEAD 2>/dev/null) || + remote_version=$(command git symbolic-ref --quiet --short HEAD 2>/dev/null) || + remote_version=$(command git name-rev --no-undefined --name-only --exclude="remotes/*" HEAD 2>/dev/null) || + remote_version="" # Get short hash for the current HEAD local commit=$(command git rev-parse --short HEAD 2>/dev/null) + local local_version=$(cat $_MOSHEL_DIR_BASE/version) + # Show version and commit hash - printf "%s (%s)\n" "$version" "$commit" + printf "[%s] %s (%s)\n" "$local_version" "$remote_version" "$commit" ) } diff --git a/moshell.sh/core/flags.sh b/moshell.sh/core/flags.sh new file mode 100644 index 0000000..edf9ba6 --- /dev/null +++ b/moshell.sh/core/flags.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +# -*- coding: utf-8 -*- + +# Glossary +# 0=no +# 1=yes + +export _MOSHELL_LOGGING=1 # log to file +export _MOSHELL_VERBOSE=0 # log to shell + diff --git a/moshell.sh/lib/index.sh b/moshell.sh/core/index.sh similarity index 73% rename from moshell.sh/lib/index.sh rename to moshell.sh/core/index.sh index 583ba24..15cc51d 100644 --- a/moshell.sh/lib/index.sh +++ b/moshell.sh/core/index.sh @@ -1,4 +1,4 @@ -moshell::lib::index() { +_moshell::core::index() { echo '# This is a index file to import (and export to shell) all files required by Moshell.sh.' } @@ -6,5 +6,8 @@ BASE_PATH="$(dirname "$(realpath "$0")")" # NOTE: The order matters source "$BASE_PATH/flags.sh" -source "$BASE_PATH/cli.sh" source "$BASE_PATH/banner.sh" +source "$BASE_PATH/logger.sh" +source "$BASE_PATH/cli.sh" + +_moshell::log success "Loaded core." diff --git a/moshell.sh/core/logger.sh b/moshell.sh/core/logger.sh new file mode 100644 index 0000000..916eb82 --- /dev/null +++ b/moshell.sh/core/logger.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +# Log messages with different colors based on log level and save to a log file +# Usage: _moshell::log_and_save log_level message +function _moshell::log { + local logtype="$1" + local message="$2" + + local log_colors + local word_colors="\e[30m" # Black text color + local log_reset="\e[0m" + + # Transform to lowercase + logtype=$(echo "$logtype" | tr '[:upper:]' '[:lower:]') + + case "$logtype" in + prompt) log_colors="\e[45m" ;; # Magenta background + success) log_colors="\e[42m" ;; # Green background + info) log_colors="\e[44m" ;; # Blue background + debug) log_colors="\e[47m" ;; # White background + warn) log_colors="\e[43m" ;; # Yellow background + error) log_colors="\e[41m" ;; # Red background + *) + # Default to red background for unknown log levels + logtype="info" + log_colors="\e[41m" + ;; + esac + + # Transform to uppercase + logtype=$(echo "$logtype" | tr '[:lower:]' '[:upper:]') + + # Log to the terminal with colors + if [[ "$_MOSHELL_VERBOSE" == 1 ]]; then + printf "${log_colors}${word_colors}[%s]${log_reset}:%s\n" "$logtype" "$message" >&2 + fi + + if [[ "$_MOSHELL_LOGGING" == 1 ]]; then + # Save to log file + local logfile="$(date +%F)_moshell.sh.log" + local logpath="$_MOSHEL_DIR_BASE/logs/$logfile" + echo "[$(date --iso-8601=ns)] [$logtype] $message" >>"$logpath" + fi +} + +# # Usage examples: +# _moshell::log prompt "This is a prompt message" +# _moshell::log success "This is a success message" +# _moshell::log info "This is an info message" +# _moshell::log debug "This is a debug message" +# _moshell::log warn "This is a warning message" +# _moshell::log error "This is an error message" diff --git a/moshell.sh/custom/andersonbosa/generators.sh b/moshell.sh/custom/andersonbosa/generators.sh index 1e6b6a4..52248d6 100644 --- a/moshell.sh/custom/andersonbosa/generators.sh +++ b/moshell.sh/custom/andersonbosa/generators.sh @@ -1,4 +1,4 @@ -function poc_init_python() { +function create_poc_python() { create_venv pysource @@ -11,3 +11,17 @@ function poc_init_python() { git add . git commit -m 'init python project' } + +function create_makefile_python() { + cat <./Makefile + +setup-env: + python3 -m venv .venv + source .venv/bin/activate + pip install -r requeriments.txt + +run: + python main.py + +EOF +} diff --git a/moshell.sh/custom/index.sh b/moshell.sh/custom/index.sh index aaaca7d..81f9714 100644 --- a/moshell.sh/custom/index.sh +++ b/moshell.sh/custom/index.sh @@ -1,4 +1,4 @@ -moshell::custom::index() { +_moshell::custom::index() { echo '# This is a index file to import (and export to shell) all files wanted. For better organization it was separeted by username.' } @@ -11,3 +11,5 @@ source "$BASE_PATH/andersonbosa/generators.sh" source "$BASE_PATH/andersonbosa/randoms.sh" source "$BASE_PATH/andersonbosa/termbin.sh" source "$BASE_PATH/andersonbosa/workrounds.sh" + +_moshell::log success "Loaded customizations." diff --git a/moshell.sh/lib/flags.sh b/moshell.sh/lib/flags.sh deleted file mode 100644 index e8525d5..0000000 --- a/moshell.sh/lib/flags.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -# -*- coding: utf-8 -*- - -export _MOSHELL_DEBUG=0 diff --git a/moshell.sh/moshell.sh b/moshell.sh/moshell.sh index 49c8bb6..1f81568 100755 --- a/moshell.sh/moshell.sh +++ b/moshell.sh/moshell.sh @@ -2,9 +2,9 @@ # -*- coding: utf-8 -*- export _MOSHEL_DIR_BASE="$(dirname "$(realpath "$0")")" -export _MOSHEL_DIR_LIB="$_MOSHEL_DIR_BASE/lib" +export _MOSHEL_DIR_CORE="$_MOSHEL_DIR_BASE/core" +export _MOSHEL_DIR_PLUGINS="$_MOSHEL_DIR_BASE/plugins" export _MOSHEL_DIR_CUSTOM="$_MOSHEL_DIR_BASE/custom" -export _MOSHEL_DIR_LOGS_FILE="$_MOSHEL_DIR_BASE/logs/$(date +%s).log" # ============================================================================= @@ -22,17 +22,20 @@ export _MOSHEL_DIR_LOGS_FILE="$_MOSHEL_DIR_BASE/logs/$(date +%s).log" # source $script_file 2>&1 | tee -a "$_MOSHEL_DIR_LOGS_FILE" # # Verbose if flag is diff 0 -# [[ "$_MOSHELL_DEBUG" == "1" ]] && echo "[DEBUG] loaded: $script_file" +# [[ "$_MOSHELL_LOGGING" == "1" ]] && echo "[DEBUG] loaded: $script_file" # fi # done # } # -# moshell::import_libs $_MOSHEL_DIR_LIB 2>&1 | tee -a "$_MOSHEL_DIR_LOGS_FILE" +# moshell::import_libs $_MOSHEL_DIR_CORE 2>&1 | tee -a "$_MOSHEL_DIR_LOGS_FILE" # moshell::import_libs $_MOSHEL_DIR_CUSTOM 2>&1 | tee -a "$_MOSHEL_DIR_LOGS_FILE" # # ============================================================================= # To infinity and beyond! -source $_MOSHEL_DIR_LIB/index.sh +source $_MOSHEL_DIR_CORE/index.sh +source $_MOSHEL_DIR_PLUGINS/index.sh source $_MOSHEL_DIR_CUSTOM/index.sh + +_moshell::log success "Moshell.sh initialized with success!" diff --git a/moshell.sh/plugins/howtos/_index.sh b/moshell.sh/plugins/howtos/_index.sh new file mode 100644 index 0000000..80bf046 --- /dev/null +++ b/moshell.sh/plugins/howtos/_index.sh @@ -0,0 +1,3 @@ +_HOWTOS_CURRENT_PATH="$(dirname "$(realpath "$0")")" + +source $_HOWTOS_CURRENT_PATH/all.sh diff --git a/moshell.sh/plugins/howtos/all.sh b/moshell.sh/plugins/howtos/all.sh new file mode 100644 index 0000000..119a3a4 --- /dev/null +++ b/moshell.sh/plugins/howtos/all.sh @@ -0,0 +1,200 @@ +#!/usr/bin/env bash +# -*- coding: utf-8 -*- + +function howto_convert_svg_to_ico() { + echo -e ''' + convert -density 300 -define icon:auto-resize=64 -background none favicon.svg favicon.ico +''' +} + +function howto_ssh_open_socks_tunnel() { + cat </dev/null + docker run --rm \\ + --name postgres \\ + --network my-network \\ + -p 5432:5432 \\ + -e POSTGRES_PASSWORD=supremepassword987123 \\ + -v /opt/postgres/data:/var/lib/postgresql/data \\ + postgres:14 + + +# GET SHELL + docker exec -it postgres psql -U postgres +''' +} + +function howto_ffmpeg_convert_media() { + echo -e ''' + + ffmpeg -i input.mp4 output.webm +''' +} + +function howto_ffmpeg_screen_record() { + echo -e ''' + + ffmpeg -video_size 2560x1080 -framerate 25 -f x11grab -i :0.0 /tmp/test.mp4 + + ffmpeg -video_size 2560x1080 -framerate 25 -f x11grab -i :0.0 -f pulse -ac 2 -i default /tmp/test.mkv + + ffmpeg -video_size 2560x1080 -framerate 25 -f x11grab -i :0.0 -f alsa -ac 2 -i hw:0 /tmp/test.mkv +''' +} +function howto_gen_random_bytes() { + echo -e ''' +# https://www.baeldung.com/linux/random-numbers + + dd if=/dev/urandom of=/tmp/random_file2.txt count=1 bs=500MB + ''' +} + +function howto_reverse_mobile() { + echo -e ''' + apktool -d APK_FILEPATH + d2jx-dex2jar.sh APK_FILEPATH +[INF] open the generated .jar with JD-Gui and save all resources. +''' +} + +function howto_tar_encrypt_decrypt() { + # https://stackoverflow.com/questions/57817073/how-to-encrypt-after-creating-tar-archive + echo -e ''' + encrypt: +tar zcvfp - /tmp/test | gpg --symmetric --cipher-algo AES256 -o /tmp/test.tar.gz + + decrypt: +gpg -d myarchive.tar.gz.gpg | tar xzvf - +''' +} + +function howto_ffuf_param() { + echo ''' +ffuf -u https://W2/W1 -w ./wordlist.txt:W1 -w ./domains.txt:W2 + ''' +} + +function howto_crunch_template() { + echo -e ''' + -t @,%^ + Specifies a pattern, eg: @@god@@@@ where the only the + @'s, ,'s, %'s, and ^'s will change. + @ will insert lower case characters + , will insert upper case characters + % will insert numbers + ^ will insert symbols + +''' +} + +function howto_shell_upgrade_session() { + echo ''' +SHELL=/bin/bash script -q /dev/null; +export TERM=xterm-256color +''' +} + +function howto_shell_reverse() { + echo ''' +# note: the request should be generated from burp +''' +} + +function howto_vim() { + echo -e ''' +# CUSTOM FUNCTIONS & SHORTCUTS + +wr " toggle wrap + +# USEFUL + ++y system clipcopy ++x system cut + +''' +} + +function howto_irc() { + echo ''' +# USEFUL COMMANDS + + /msg NickServ IDENTIFY $USER ${IRC_PASSWORD} Identifing to nickserv + /server serverurl Joining a server + /join #Channel Joining a channel + /away Setting yourself away + /msg ChanServ op #channel [] Opping + /mode #channel +o NICKNAME Opping another person (when opped) + /whois USERNAME Get more information on another user + /set irc.server.libera.command '/msg nickserv identify xxxxxxx' add autologin + + +# USEFUL LINKS: + + https://duckduckgo.com/?q=irc+cheat+sheet&t=brave&ia=cheatsheet + http://ircbeginner.com/ircinfo/ircc-commands.html + http://www.geekshed.net/commands/nickserv/ + https://weechat.org/files/doc/stable/weechat_quickstart.en.html +''' +} + +function howto_jq() { + cat </tmp/howto_jq +# find item by id +cat .json | jq 'select(.id == "") | .' + +# find item by sku +cat .json | jq 'select(.skus[].sku == "") | .' + + +# links to get help +https://lzone.de/cheat-sheet/jq +https://cameronnokes.com/blog/jq-cheatsheet/ +https://jqplay.org/jq?q=.a%20%2B%201&j=%7B%22a%22%3A%207%7D# + +EOF + cat /tmp/howto_jq +} + +function howto_clean_journal_logs() { + echo -e ''' +You can remove the journal files using the following steps: + +Open a terminal or command prompt with administrative privileges. Run the following command to stop the systemd-journald service: +``` +bash +sudo systemctl stop systemd-journald +``` + +Once the service is stopped, you can delete the journal files. You can either delete all the files +or selectively delete files based on your requirements. Use one of the following commands: + +To delete all journal files: +``` +bash +sudo rm -rf /var/log/journal/* +``` + +To delete journal files older than a specific date (for example, files older than 7 days): +``` +bash +sudo journalctl --vacuum-time=7d +``` + +This command will remove journal files older than the specified time. +After deleting the files, you can start the systemd-journald service again using the following command: +``` +bash +sudo systemctl start systemd-journald +``` +''' +} diff --git a/moshell.sh/plugins/index.sh b/moshell.sh/plugins/index.sh new file mode 100644 index 0000000..b6ac9f3 --- /dev/null +++ b/moshell.sh/plugins/index.sh @@ -0,0 +1,19 @@ +moshell::plugins::index() { + echo '# This is a index file to import Moshell.sh plugins.' +} + +PLUGINS_BASE_PATH="$(dirname "$(realpath "$0")")" +PLUGINS_FOUND=$(ls $PLUGINS_BASE_PATH/*/index.sh $PLUGINS_BASE_PATH/*/_index.sh) +PLUGINS_PATH=($(echo $PLUGINS_FOUND | sort -n | uniq)) + +# Loop through and source each file in the "plugins" directory +for script_file in ${PLUGINS_PATH[*]}; do + if [ -f "$script_file" ]; then + # Import script + source $script_file + + _moshell::log success "Loaded plugin: $script_file" + fi +done + +_moshell::log success "Loaded plugins" diff --git a/moshell.sh/plugins/secrets/README.md b/moshell.sh/plugins/secrets/README.md new file mode 100644 index 0000000..7e5b7bb --- /dev/null +++ b/moshell.sh/plugins/secrets/README.md @@ -0,0 +1,21 @@ +# secrets + +Store your secrets, api-keys and etc in a protected place and keep using them in your shell, without exposing anything! + +### Dependencies + +- [Github CLI](https://cli.github.com/) +- For correct use, the repository is expected to have "index.sh" file with desired content. + +### Gettings started + +1. Create a private git repository, for example, moshell-secrets +```bash +# Example of how start your secret repository: +cd ~ +gh repo create moshell-secrets --private --clone +``` +2. Configure the following variables (check [./secrets/index.sh](./index.sh)) + - `GIT_OWNER` - your git username + - `GIT_REPO` - your repository name +3. And it's ready to be used! The next time you start Shell the repository will be cloned and Moshell.sh will import your "index.sh". diff --git a/moshell.sh/plugins/secrets/index.sh b/moshell.sh/plugins/secrets/index.sh new file mode 100644 index 0000000..f38f362 --- /dev/null +++ b/moshell.sh/plugins/secrets/index.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +# +# It should load secrets of a previously configured versed repository. +# + +# Setup your repository to download your secrets +GIT_OWNER="andersonbosa" +GIT_REPO="moshell-secrets" + +# Constants +GIT_REPO_REFERENCE="$GIT_OWNER/$GIT_REPO" +LOCAL_PATH="$HOME/.$GIT_REPO" + +# Import according to the standard, source index.sh +function load_secrets { + source $LOCAL_PATH/index.sh + _moshell::log success "$LOCAL_PATH loaded" +} + +function setup_secrets { + gh repo clone $GIT_REPO_REFERENCE $LOCAL_PATH &>/dev/null + if [[ $? -eq 0 ]]; then + load_secrets + else + _moshell::log error "Failed to clone repository." + fi +} + +if [[ -d "$LOCAL_PATH" ]]; then + load_secrets +else + setup_secrets +fi diff --git a/moshell.sh/version b/moshell.sh/version new file mode 100644 index 0000000..7f20734 --- /dev/null +++ b/moshell.sh/version @@ -0,0 +1 @@ +1.0.1 \ No newline at end of file