Skip to content

Commit

Permalink
Start working on audit code (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChillerDragon committed Aug 12, 2021
1 parent 7a2904c commit 7c1a6db
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
71 changes: 71 additions & 0 deletions lib/include/audit_code.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/bin/bash

function audit_wrn() {
echo -e "[${Yellow}code-audit${Reset}] $1"
}

function audit_code_popen() {
local match
match="$(grep -rPn 'popen' src)"
if [ "$match" != "" ]
then
audit_wrn "$(tput bold)WARNING$(tput sgr0): found popen"
echo "$match" | awk '{ print "\t" $0}'
fi
}

function audit_code_system() {
local match
match="$(grep -rPn '(system[\s]*$|system\()' src | grep -v '//.*system')"
if [ "$match" != "" ]
then
audit_wrn "$(tput bold)WARNING$(tput sgr0): found system call"
echo "$match" | awk '{ print "\t" $0}'
fi
}

function audit_code_exec() {
local match
match="$(grep -Prn '(execl|execle|execlp|execv(?!e\(\))|execve(?!\(\))|execvp|fexecve)' src)"
if [ "$match" != "" ]
then
audit_wrn "$(tput bold)WARNING$(tput sgr0): found exec call"
echo "$match" | awk '{ print "\t" $0}'
fi
}

function audit_code_shell() {
local match
match="$(grep -iErn '(bin/|env )(sh|bash|fish|zsh|csh)' src)"
if [ "$match" != "" ]
then
audit_wrn "$(tput bold)WARNING$(tput sgr0): found possible reverse shell"
echo "$match" | awk '{ print "\t" $0}'
fi
}

function audit_code_rcon() {
local match
match="$(grep -iErn '(print|log|say|sendchat|broadcast).*config.*SvRconPassword' src)"
if [ "$match" != "" ]
then
audit_wrn "$(tput bold)WARNING$(tput sgr0): found possible rcon password leak"
echo "$match" | awk '{ print "\t" $0}'
fi
}

function audit_code() {
if [ ! -d "$CFG_GIT_PATH_MOD" ]
then
return
fi
(
cd "$CFG_GIT_PATH_MOD" || exit 1
audit_code_rcon
audit_code_shell
audit_code_exec
audit_code_system
audit_code_popen
)
}

1 change: 1 addition & 0 deletions lib/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ source lib/include/settings.sh
source lib/include/git.sh
source lib/include/logs.sh
source lib/include/screen.sh
source lib/include/audit_code.sh

function get_player_ips() {
if [ ! "$(command -v rg)" ]
Expand Down
1 change: 1 addition & 0 deletions status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ fi
source lib/lib.sh

check_warnings
audit_code

if pgrep -f "$SERVER_UUID" > /dev/null
then
Expand Down

0 comments on commit 7c1a6db

Please sign in to comment.