Skip to content

Guide to Server Security Reinforcement

BlockGeek edited this page Apr 24, 2019 · 3 revisions

-- V0.3

Version number Revision time Revision content
V0.1 20181016 first draft
V0.2 20181020 one check item added, format modified;
V0.3 20181022 one check item added, format modified;

Chapter 1: Overview

1.1 Scope of Application

In order to improve the security level of its node servers, HPB has decided to adopt the server security strengthening schemes of security audit companies , which apply to HPB node servers running Linux. This guide is intended to guide node server users to check and configure the security compliance of their servers.

1.2 Reading suggestions

Number Content Description
1 Guide to Server Security Detection Script Instruct node users to download and run the server security detection script so as to check the servers’ security configuration. See Chapter 2 for details.
2 Check Item Details Details the 22 check items involved in the script and their configuration modification steps. Refer to Chapter 3 for details.

Chapter 2 A Guide to Server Security Monitoring Script

2.1 Steps of Use

To simplify steps of operation for its users, HPB provides a server security detection script, allowing user to automatically perform security configuration check on the servers’ Linux system.

Number Steps Description
1 Download Script Command: "git clone https://github.com/hpb-project/systemcheck"
2 Set Permissions Command: "cd systemcheck"
Command: "chmod +x systemcheck.sh"
3 Run script Command: "sudo ./systemcheck.sh"
Tip: enter the login password of the current account as prompted;
Should “not installed chkconfig, whether to install (y/n)” appear, enter "y".
4 View the results Command: " vi servercheck.txt"
Tip: Passed check is prompted with "safe", failed check is prompted "unsafe".
If you need to modify the configuration, please refer to Chapter 3 for details.
The nth check item corresponds to Chapter 3 Section n.

The HPB chain recommends that the user change the unchecked items of the running result to the security configuration. For details, see Chapter 3.

Usage examples

(1) Step 1: Download the server security detection script

Open command prompt window,enter” git clone https://github.com/hpb-project/systemcheck*";

hpb@dell-PowerEdge-R730:~$ git clone https://github.com/hpb-project/systemcheck
Cloning into 'systemcheck'...
remote: Enumerating objects: 8, done.
remote: Counting objects: 100% (8/8), done.
remote: Compressing objects: 100% (6/6), done.
Unpacking objects: 100% (8/8), done.
remote: Total 8 (delta 2), reused 8 (delta 2), pack-reused 0
Checking connectivity... done.
hpb@dell-PowerEdge-R730:~$

(2) Step 2: Set file permissions

Enter” cd systemcheck"

hpb@dell-PowerEdge-R730:~$ cd systemcheck
hpb@dell-PowerEdge-R730:~/systemcheck$

Continue setting file permissions

Enter” chmod +x systemcheck.sh"

hpb@dell-PowerEdge-R730:~$ cd systemcheck
hpb@dell-PowerEdge-R730:~/systemcheck$

(3) Step 3: Run the script

Enter” sudo ./systemcheck.sh", enter the current user's login password as prompted, and the file will automatically detect the server configuration.;

hpb@dell-PowerEdge-R730:~/systemcheck$ sudo ./systemcheck.sh
[sudo] password for hpb:
Start checking...
  1. Check the password validity setting
  2. Check the password strength configuration
  3. Check the empty password account
  4. Check the account lockout configuration
  5. Check the UID of the accounts (other than root) to be 0.
  6. Check the environment variables (including the parent directory)
  7. Check the environment variables (including directory with the group permission of 777).
……

The user has to wait for a while. When prompted "chkconfig not installed, whether to install (y/n):", enter "y" to install chkconfig; "Check completed, please read the servercheck.txt file carefully" indicates that the security check has been completed.

Check the running service
Chkconfig is not installed, whether to install (y/n) :y
Reading package lists... Done
Building dependency tree
Reading state information... Done
......
Setting up sysv-rc-conf (0.99-7) ...
Successful installation
Check status of the core dump 
Check is completed, please read servercheck.txt carefully

(4) Step 4: View the running results

Enter “vi servercheck.txt",running results will be displayed, with 22 check items involved. Passed check items are prompted "safe”, failed check items are prompted “unsafe”. HPB recommends users change failed check items into safe. For modification steps for specific items, please refer to Chapter 3. Tip : The nth check item corresponds to Chapter 3 Section n. There are 22 check items involved.

hpb@dell-PowerEdge-R730:~/systemcheck$ vi servercheck.txt
1. Password timeout not configured, unsafe.
Suggestion:
   Execute sed -i '/PASS_MAX_DAYS/s/99999/90/g' /etc/login.defs Set the password to be valid for 90 days.
2. Password strength check not configured, unsafe
Suggestion:
   Execute echo "passwd requisite pam_cracklib.so difok=3 minlen=8 ucrediit=-1 lcredit=-1 dcredit=-1">> /etc/pam.d/
Systemd-auth to configure the password to include uppercase and lowercase letters, numbers and at least 8 characters. 
3. No empty password account found, safe
……

Chapter 3; Check item details

3.1 Set password expiration date

Modification steps

Number Step Description
1 Switch to root user Command:" su root"
Tip: User should enter the root account password as prompted.
2 Set password expiration date (90 days) Command:" sed -i '/PASS_MAX_DAYS/s/99999/90/g' /etc/login.defs"

Modification example

(1) Step 1: switch to root user Open command prompt,enter ”su root”,type in rooter account password as prompted;

hpb@dell-PowerEdge-R730:~$ su root
Password:
root@dell-PowerEdge-R730:/home/hpb#

(2) Step 2: Set expiration date
Enter "sed -i '/PASS_MAX_DAYS/s/99999/90/g' /etc/login.defs" to set the password to be valid for 90 days. No returned message for this command.

root@dell-PowerEdge-R730:/home/hpb# sed -i '/PASS_MAX_DAYS/s/99999/90/g' /etc/login.defs

3.2 Password Strength Evaluation Configuration

  ### Configuration Modification steps

Number Step Description
1 Switch to root (already-switched user can skip this) Command: " su root"
Tip: User should enter the root account password as prompted
2 Set Password Strength Check Command:"echo "passwd requisite pam_cracklib.so difok=3 minlen=8 ucrediit=-1 lcredit=-1 dcredit=-1">> /etc/pam.d/systemd-auth"

Configuration Modification Example:

(1) Step 1: Switch to root account Open command prompt,enter “su root",enter root account password as prompted ; Tip: if already switched to root account, skip this step.

hpb@dell-PowerEdge-R730:~$ su root
Password:
root@dell-PowerEdge-R730:/home/hpb#

(2) Step 2: Set password strength check Enter” echo "passwd requisite pam_cracklib.so difok=3 minlen=8 ucrediit=-1 lcredit=-1 dcredit=-1">> /etc/pam.d/systemd-auth" to configure the password to include uppercase and lowercase letters, numbers and at least 8 characters, no returned message for this command.

root@dell-PowerEdge-R730:/home/hpb#  echo "passwd requisite pam_cracklib.so difok=3 minlen=8 ucrediit=-1 lcredit=-1 dcredit=-1">> /etc/pam.d/systemd-auth
root@dell-PowerEdge-R730:/home/hpb#

3.3 Empty password account

Configuration modifying steps

编号 步骤 说明
1 switch to root account (already-switched users can skip) command:” su root"
tip:enter root account password as prompted
2 Set password Command:”passwd account name
Tip:User should switch their account ID to the one in need of a password;
Type in the new password twice as prompted.

Configuration modifying example:

(1) Step 1: Switch to Root Account Open command prompt window,enter”su root”,enter root account password as prompted; Tip:Users already switched to root can skip this step.

hpb@dell-PowerEdge-R730:~$ su root
Password:
root@dell-PowerEdge-R730:/home/hpb#

(2) Step 2: Set Password Enter”passwd account name”,enter new password as prompted, repeat entering the new password for a second time to complete the process. Tip:User should switch to the account name for which he has yet to set a password, such as “test” in the following example.

root@dell-PowerEdge-R730:/home/hpb# passwd test
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

3.4 Account Lockout Configuration

Configuration modifying steps

Number Step Descriptions
1 Switch to root account (skip if already switched) Command:” su root"
Tip: enter root account password as prompted
2 Set account lockout policy Command:”echo "auth required pam_tally.so onerr=fail deny=10 unlock_time=300" >> /etc/pam.d/systemd-auth"

Configuration modifying example

(1) Step one: switch to root account

Open Command Prompt,type in“su root”,enter password as prompted;

Tip: skip this step if already switched to root account.

hpb@dell-PowerEdge-R730:~$ su root
Password:
root@dell-PowerEdge-R730:/home/hpb#

(2) Step two: set account lockout policy

Type in “ echo "auth required pam_tally.so onerr=fail deny=10 unlock_time=300" >> /etc/pam.d/systemd-auth" to set the consecutive error limit at 10 times max over which the account would be locked automatically, no return code for this command;

Tip:command to unlock the account:" faillog -u <user> -r"。

root@dell-PowerEdge-R730:/home/hpb#  echo "auth required pam_tally.so onerr=fail deny=10 unlock_time=300" >> /etc/pam.d/systemd-auth
root@dell-PowerEdge-R730:/home/hpb#

3.5 Account with UID 0

Configuration Modifying Steps

Number Step Description
1 Switch to root account (skip if already switched) Command:” su root"
Tip: enter root account password as prompted
2 Modify account with UID 0 command:” usermod -u <new-uid> <user>"
command:”groupmod -g <new-gid> <user>"

Configuration Modifying Example

(1) Step one: switch to root account

Open Command Prompt,type in“su root”,enter password as prompted;

Tip: skip this step if already switched to root account.

hpb@dell-PowerEdge-R730:~$ su root
Password:
root@dell-PowerEdge-R730:/home/hpb#

(2) Step two: change into the account with UID 0

Type in " usermod -u <new-uid> <user>";continue to type in”groupmod -g <new-gid> <user>"。

Tip:<user>refers to the account name,which should be changed into the account with UID 0;<new-uid> refers to the new uid;<new-gid> refers to the parameters.

3.6 Environmental Variables Containing Parent Directory

Should a parent directory exist in the environmental variables, it is recommended that the user modify the configuration to remove the parent directory from environment variables.

3.7 Environment Variables Containing Directory with Group Permission of 777

Should the environment variables contain a directory with a group permission of 777, it is recommended that the user run the chmod command to modify the permission of the directory in the running result.

3.8 Remote Connection Security

Should the server fail the remote connection security test, it is recommended that the user contact the administrator to confirm the necessity of the files in the running results. Once found unnecessary, the files in question should be deleted.

3.9 Umask Configuration

Configuration Modifying Steps

Number Step Description
1 Switch to root account (skip if already switched) Command:” su root"
Tip: enter root account password as prompted
2 umask not configured command:”echo "umask 027" >> /etc/profile"
command:”echo "umask 027" >> /etc/bash.bashrc"
2' umask configuration not safe command:”vi /etc/profile"
move the cursor to locate the umask parameter, and change the subsequent number to "027"
命令:"vi /etc/bash.bashrc"
move the cursor to locate the umask parameter, and change the subsequent number to "027"

Configuration Modifying Example

(1) Step one: switch to root account

Start Command Prompt, type in "su root”,and enter root account password as prompted;

Tip: skip if already switched to root account.

hpb@dell-PowerEdge-R730:~$ su root
Password:
root@dell-PowerEdge-R730:/home/hpb#

(2) Step two: umask not configured

Type in” echo "umask 027" >> /etc/profile",no return code for this command; Type in” echo "umask 027" >> /etc/bash.bashrc”,no return code for this command;

root@dell-PowerEdge-R730:/home/hpb#  echo "umask 027" >> /etc/profile 
root@dell-PowerEdge-R730:/home/hpb# echo "umask 027" >> /etc/bash.bashrc

(3) Step two: ‘ umask configuration not safe

Type in “ vi /etc/profile"; press the “↓”key to move the cursor to the umask parameter and change the immediately following number to "027"; ''root@dell-PowerEdge-R730:/home/hpb# vi /etc/profile

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
  done
  unset i
fi
umask 027
TMOUT=180

:wq(Press the “ESC” key and type in ":wq" to save the file and exit)

Type in “ vi /etc/bash.bashrc"; press the “↓” key to move the cursor to the umask parameter and change the immediately following number to “027”;

root@dell-PowerEdge-R730:/home/hpb# vi /etc/bash.bashrc
if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
  done
  unset i
fi
umask 027
TMOUT=180

:wq(Press the “ESC” key and type in ":wq" to save the file and exit)

3.10 Permissions for Important Files and Directories

Carefully check the permissions of the files and directories in the running results. If the permissions are too low, please modify them in time.

3.11 Unauthorized SUID/SGID Files

Check for suspicious files in the running results and delete them in time.

3.12 Directories with Universal Write Permission

Check the necessity of such permission set-up in all directories in the running results. If not necessary, modify the permission level in time.

3.13 Files with Universal Write Permission

Check the necessity of such permission set-up in all the files in the running results. If found unnecessary, modify the permission level in time.

3.14 Files without Owner

Should there exist files without owners in the running results, add owners to the files. Should there exist suspicious files, delete them in time.

3.15 Unusual Hidden Files

Check for suspicious files in the running results and delete in time.

3.16 Login Timeout Configuration

Configuration Modifying Steps

Number Step Description
1 Switch to root account ( skip if already switched) Command: " su root"
Tip: enter the root account password as prompted
2 Increase the login timeout configuration Command: "echo "TMOUT=180" >> /etc/profile"

Configuration Modifying Example

(1) Step 1: Switch to root account

Start command prompt, type in "su root”,and enter root account password as prompted;

Tip: Skip this step if already switched to root account.

hpb@dell-PowerEdge-R730:~$ su root
Password:
root@dell-PowerEdge-R730:/home/hpb#

(2) Step 2: Increase the login timeout configuration

Type in” echo "TMOUT=180" >> /etc/profile" no return code for this command;

root@dell-PowerEdge-R730:/home/hpb#  echo "TMOUT=180" >> /etc/profile
root@dell-PowerEdge-R730:/home/hpb#

3.17 Running Status of ssh and telnet

If ssh is not running, the user is advised to install and start the ssh service.

If telnet is running, the user is advise to stop the telnet service.

3.18 Root Remote Login Configuration

Configuration Modifying Steps

Number Step Description
1 Switch to root account (skip if already switched) command:” su root"
tip: enter root account password as prompted
2 Forbid root remote login command:" vi /etc/ssh/sshd_config"
Move the cursor to find the parameters of “PermitRootLogin”,change the following “yes” to “no”.
Tip: If the parameter is followed by other values other than "yes", no modification is required.

Configuration Modifying Example

(1) Step 1: Switch to root account

Start Command Prompt, type in "su root”,enter root account password as prompted;

Tip: skip this step if already switched to root account.

hpb@dell-PowerEdge-R730:~$ su root
Password:
root@dell-PowerEdge-R730:/home/hpb#

(2) Step 2: Forbid remote login for root account

Type in” vi /etc/ssh/sshd_config",move the cursor to PermitRootLogin,if the following value is “yes”, change it to "no”.

Tip: If the parameter is followed by other values other than "yes", no modification is required.

root@dell-PowerEdge-R730:/home/hpb# vi /etc/ssh/sshd_config

# Authentication:
LoginGraceTime 120
PermitRootLogin prohibit-password
StrictModes yes

:wq(press the ”ESC” key and type in ”:wq” to save the file and exit)

3.19 Running Services

Check all the running services in the running results and turn off unnecessary ones.

Tip: command to turn off services “chkconfig --level $level <service name> "

3.20 Core dupm Status

Configuration Modifying Steps

Number Step Description
1 Switch to root account (skip if already switched) command:” su root"
Tip: enter root account password as prompted
2 Modify limits files command:”vi /etc/security/limits.conf"
type in the following command before ”End of file":
"* soft core 0
* hard core 0"

Configuration Modifying Example

(1) Step 1: Switch to root account

Open Command Prompt, type in "su root”,enter root account password as prompted;

Tip: skip this step if already switched to root account.

hpb@dell-PowerEdge-R730:~$ su root
Password:
root@dell-PowerEdge-R730:/home/hpb#

(2) Step2: modify limits files

Type in “vi /etc/security/limits.conf";

Move the cursor to the last but two line, just before “End of file”, and type in"* soft core 0

​ * hard core 0"。

Tip: if unable to type in, press the key for letter “I” to activate “INSERT” mode.

root@dell-PowerEdge-R730:/home/hpb#

#ftp             hard    nproc           0
#ftp             -       chroot          /ftp
#@student        -       maxlogins       4
* soft core 0
* hard core 0
# End of file
:wq(press the ”ESC” key and type in ”:wq” to save the file and exit)

3.21 rsyslog Status

### Configuration Modifying Steps

Number Step Description
1 Switch to root account (skip if already switched) command:” su root"
Tip: enter root account password as prompted
2 Configure and start rsyslog command:”vi /etc/rsyslog.conf";
enter at the end of file:
"*.err;kern.debug;daemon.notice /var/adm/messages"
command:”sudo mkdir /var/adm"
command:”sudo touch /var/adm/messages"
command:”sudo chmod 666 /var/adm/messages"
command:”sudo systemctl restart rsyslog"

Configuration Modifying Example:

(1) Step One: Switch to Root User Account: Open Command Prompt, type in "su root", and enter the password for the root account as prompted; Tip: skip this step if you have already switched to the root account.

hpb@dell-PowerEdge-R730:~$ su root
Password:
root@dell-PowerEdge-R730:/home/hpb#

(2) Step Two: Configure and Launch rsyslog Type in "vi /etc/rsyslog.conf" to open the rsyslog.conf file. Press the key for letter "I" to activate the "INSERT" mode; Press the "↓" key to move the cursor to the last line of the file and type in:

"*.err;kern.debug;daemon.notice /var/adm/messages";

Press the “ESC” key and type in ":wq" to save the file and exit;

root@dell-PowerEdge-R730:/home/hpb# vi /etc/rsyslog.conf 

#
# Include all config files in /etc/rsyslog.d/
#
$IncludeConfig /etc/rsyslog.d/*.conf
*.err;kern.debug;daemon.notice /var/adm/messages

:wq(press the ”ESC” key and type in ”:wq” to save the file and exit)

Continue to type in”sudo mkdir /var/adm”,no return code for this command; Continue to type in“sudo touch /var/adm/messages" , no return code for this command; Continue to type in“sudo chmod 666 /var/adm/messages" ,no return code for this command; Continue to type in”sudo systemctl restart rsyslog" ,no return code for this command.

root@dell-PowerEdge-R730:/home/hpb# sudo mkdir /var/adm
root@dell-PowerEdge-R730:/home/hpb# sudo touch /var/adm/messages
root@dell-PowerEdge-R730:/home/hpb# sudo chmod 666 /var/adm/messages
root@dell-PowerEdge-R730:/home/hpb# sudo systemctl restart rsyslog

3.22 Boe function compatibility test

Servers that do not have BOE boards installed can skip this check item. When servers fail this check item, the user needs to provide the system information displayed in the results and contact HPB staff through "Appendix Tech-Support" for assistance.

Appendix: Tech Support

Should you need any help, feel free to contact HPB staff for tech support:

Tech support mailbox: node@hpb.io

HPB Tech Forum:http://blockgeek.org/c/hpb

HPB Official Website:http://www.hpb.io/

Telegram:https://t.me/hpbglobal

Facebook:HPB Blockchain

Twitter: @HPBGlobal

Reddit: r/HPBGlobal

Clone this wiki locally