How to check weakness in linux

less than 1 minute read

Almost all companies should check the weakness of server and report to the supervisory authority. We suggest simple scripts for checking world writable files, hidden files and ownerless files. You can easily find them and remove all weakness by using scripts.

Check weakness in linux

#!/bin/bash

FNAME="weakness"
CDATE=`date +%Y-%m-%d`
CTIME=`date +%H:%M:%S`

echo "====================================="
echo " START : $CDATE $CTIME"
echo "====================================="

echo "-------------------------------------"
echo " 1. World writablefiles"
echo "-------------------------------------"
find . -type f -perm -2 -exec ls -l {} \;

echo "-------------------------------------"
echo " 2. Hidden files and directories"
echo "-------------------------------------"
find . -type f -name "*.*" -ls

echo "-------------------------------------"
echo " 3. Ownerless files and directories"
echo "-------------------------------------"
find . -type f -a -nouser -nogroup -exec ls -alLd {} \;

echo ""

Remove the write permission

# Before
find . -type f -perm -2 -exec ls -l {} \;

# Change
find . -name "*.dat" | xargs chmod -R o-w

# After
find . -type f -perm -2 -exec ls -l {} \;

Leave a comment