Skip to content

Instantly share code, notes, and snippets.

@iptoux
Last active February 21, 2023 23:55
Show Gist options
  • Save iptoux/687a8f5e8d3be1eade2ca9ecdcf6104a to your computer and use it in GitHub Desktop.
Save iptoux/687a8f5e8d3be1eade2ca9ecdcf6104a to your computer and use it in GitHub Desktop.
pshitt content (json) to influxdb 2
#!/bin/bash
#
# User Pass IP PORT TIME SW CIPHER MAC TRY
# CMD call: send2flux.sh root lol 10.10.3.103 2222 3422323232 openssl shdgetw 12:32:FF:34:76 1
#
# You can set fix variables here, script will set
# environment variables if available.
#
### PLEASE EDIT YOUR SETTINGS HERE ###
FLX_HOST="IP" || "${EFLX_HOST}"
FLX_PORT="PORT" || "${EFLX_PORT}"
FLX_ORG="ORG" || "${EFLX_ORG}"
FLX_BUCKET="BUCKET" || "${EFLX_BUCKET}"
FLX_TOKEN="YOUR_TOKEN_HERE" || "${EFLX_TOKEN}"
FLX_NAME="ssh_honey"
FLX_TAG=",host=NODENAME"
### SCRIPT SETTINGS
#
FLX_ARGS="-X POST --insecure"
unset DATA DATA_SEND
declare -a DATA
declare -A DATA_SEND
declare -g FLX_URL
for item in ${@}
do
DATA+=("$item")
done
function build_url {
FLX_URL="https://$FLX_HOST:$FLX_PORT/api/v2/write?bucket=${FLX_BUCKET}&org=${FLX_ORG}"
return
}
function build_cmd {
DATA_RAW="${FLX_NAME}${FLX_TAG} "
DATA_RAW+="username=\\\"${DATA[0]}\\\","
DATA_RAW+="password=\\\"${DATA_SEND['password']}\\\","
DATA_RAW+="src_ip=\\\"${DATA_SEND['src_ip']}\\\","
DATA_RAW+="src_pt=\\\"${DATA_SEND['src_pt']}\\\","
DATA_RAW+="time=\\\"${DATA_SEND['time']}\\\","
DATA_RAW+="sw=\\\"${DATA_SEND['sw']}\\\","
DATA_RAW+="cipher=\\\"${DATA_SEND['cipher']}\\\","
DATA_RAW+="mac=\\\"${DATA_SEND['mac']}\\\","
DATA_RAW+="try=\\\"${DATA_SEND['try']}\\\""
#DATA_RAW+=" 1677012967000000000"
CMD="curl ${FLX_ARGS} --data-raw "\"${DATA_RAW}"\" -H \"${FLX_HEAD}\" \"Content-Type:text/plain\" \"${FLX_URL}\""
#echo "${CMD}"
return
}
function strip_data {
DATA_SEND["username"]="${DATA[0]}"
DATA_SEND["password"]="${DATA[1]}"
DATA_SEND["src_ip"]="${DATA[2]}"
DATA_SEND["src_pt"]="${DATA[3]}"
DATA_SEND["time"]="${DATA[4]}"
DATA_SEND["sw"]="${DATA[5]}"
DATA_SEND["cipher"]="${DATA[6]}"
DATA_SEND["mac"]="${DATA[7]}"
DATA_SEND["try"]="${DATA[8]}"
return
}
function build_header {
declare -g FLX_HEAD
FLX_HEAD="Authorization: "
FLX_HEAD+="Token ${FLX_TOKEN}"
return
}
function send_data {
eval "$CMD 2> /dev/null"
return
}
strip_data
build_header
build_url
build_cmd
send_data
@iptoux
Copy link
Author

iptoux commented Feb 21, 2023

Update some typo and removed old none working stuff from testing. Script is now ready to use, just call it from pshitt.py.
You can add the following lines on line 77 in pshitt.py

# calling external script to send data to influxdb 2
os.system('./send2flux.sh ' + username + ' ' + password + ' ' + str(data['src_ip']) + ' ' + str(data['src_port']) + ' ' + str(data['timestamp']) + ' ' + str(data['software_version']) + ' ' + str(data['cipher']) + ' ' + str(data['mac']) + ' ' + str(data['try']))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment