#!/usr/bin/env python

import subprocess,sys

print "RUN AS NORMAL USER that your testing app is running on."

# Check 1 : World writable files
# Check 2 : Group [ANY Group] user writable files
# Check 3 : All symbolic links
# Check 4 : List files that file owner can execute
# Check 5 : List files that file group users can execute
# Check 6 : List files that any user can execute
# Check 7 : List files having SUID bit
# Check 8 : List files having GUID bit


print("Usage : run.py ProgramPath")
path=sys.argv[1]

stderr=' 2>/dev/null ; echo  ;' # echo is important to return exit code 0
test_file_o="find $PWD -perm -o+w -type f "
test_file_g="find $PWD -perm -g+w -type f "
test_symlinks="find $PWD -type l "
test_file_executable_u="find $PWD -type f -perm -u+x " # all files having o+x set (binary, scripts, etc)
test_file_executable_g="find $PWD -type f -perm -g+x " # all files having g+x set (binary, scripts, etc)
test_file_executable_o="find $PWD -type f -perm -o+x " # all files having u+x set (binary, scripts, etc)

test_suid="find $PWD -type f -perm -u+s  " # all files having u+s set (binary, scripts, etc)
test_guid="find $PWD -type f -perm -g+s  " # all files having g+s set (binary, scripts, etc)


print "\nRunning on path : "+path+"\n\n"

def execute(msg,cmd):
	cmd=cmd.replace("$PWD",path)
	print(msg)
	output=subprocess.check_output(cmd,shell=True)
	print(output)

execute("Any user can write to this files :",test_file_o+stderr)
execute("Same group user can write to this files :",test_file_g+stderr)
execute("Symbolic link files :",test_symlinks+stderr)
execute("User can execute :",test_file_executable_u+stderr)
execute("Group User can execute :",test_file_executable_g+stderr)
execute("Any user can execute :",test_file_executable_o+stderr)
execute("SUID files :",test_suid+stderr)
execute("GUID files :",test_guid+stderr)


