๐ง HMAS TIP
May 21, 2025โข370 words
๐ง Hacker-Style Linux System Reporter using HMAS API
โ Overview
This project provides a Bash script to send system status reports.
It avoids input errors by using the send= or share= endpoints, and it provides
flexibility to send messages either to another user (via API key) or to an email address.
๐ Bash Script: sys_report.sh
#!/bin/bash
# === CONFIGURATION ===
API_KEY="your_api_key"
API_URL="https://carlostkd.ch/hmas/api.php"
RECIPIENT_KEY="recipient_api_key" # Can be your own API key too
EMAIL_RECIPIENT="admin@example.com" # Optional: for `share=`
USE_EMAIL=0 # Set to 1 to use email sharing, 0 to use API key
# === COLLECT SYSTEM INFO ===
UPTIME=$(uptime -p)
DISK=$(df -h / | awk 'NR==2 {print $5 " used on " $6}')
MEMORY=$(free -h | awk '/Mem:/ {print $3 "/" $2}')
USERS=$(who | wc -l)
HOST=$(hostname)
TIME=$(date)
# === FORMAT MESSAGE ===
MESSAGE="System Report from $HOST on $TIME
"
MESSAGE+="โข Uptime: $UPTIME
"
MESSAGE+="โข Disk Usage: $DISK
"
MESSAGE+="โข Memory: $MEMORY
"
MESSAGE+="โข Logged-in Users: $USERS"
# === URL-ENCODE MESSAGE ===
ENCODED_MSG=$(echo -e "$MESSAGE" | jq -sRr @uri)
# === SEND VIA API ===
if [ "$USE_EMAIL" -eq 1 ]; then
echo "[+] Sending report via email to $EMAIL_RECIPIENT..."
curl -G "$API_URL" \
--data-urlencode "share=$EMAIL_RECIPIENT" \
--data-urlencode "msg=$ENCODED_MSG" \
--data-urlencode "apikey=$API_KEY"
else
echo "[+] Sending encrypted message to $RECIPIENT_KEY..."
curl -G "$API_URL" \
--data-urlencode "send=$ENCODED_MSG" \
--data-urlencode "rec=$RECIPIENT_KEY" \
--data-urlencode "selfdestruct=1" \
--data-urlencode "apikey=$API_KEY"
fi
โ๏ธ How It Works
- Gathers:
uptime, disk usage, memory use, login count. - Formats: Multi-line string report.
- Encodes: URL-encodes full message using
jqto prevent API validation errors. - Sends: Either:
- Via
send=: Encrypted, self-destructing message to another user. - Via
share=: Email message to a recipient.
- Via
๐งช Requirements
jq(for URL encoding):bash sudo apt install jq
๐ก Example Use Cases
๐ Cronjob: Auto-send system reports every hour:
and you dont need to set any email configurations0 * * * * /home/user/scripts/sys_report.sh๐จโ๐ป Manual Use:
./sys_report.sh๐ฌ Use for Monitoring:
Trigger alerts for high disk usage or login activity via custom logic.๐ Secure Messaging:
Message disappears after read usingselfdestruct=1.