úterý 23. září 2014

Open-AudIT on CentOS 7 linux

Adapted form http://sathisharthars.wordpress.com/2014/03/19/installing-open-audit-in-centos-6/
The new versions of Open-AudIT require usage of it's "installator". That does not support CentOS 7.

Check dependency: 
Check hostname and timezone: 
uname -n
ls -l /etc/localtime 

epel-release is necessary
yum -y install epel-release

Install components:
Apache, mysql (MariaDB is default in CentOS 7). Set root password of mysql to 'PASSWORD'
yum -y install mariadb-server mariadb httpd
systemctl start mariadb.service
systemctl enable mariadb.service
systemctl start httpd.service
systemctl enable httpd.service
mysql_secure_installation 

yum -y install php php-cli php-mysql php-ldap php-mbstring php-mcrypt php-snmp \
               php-xml nmap zip curl wget sshpass screen samba-client          \
               perl-version php-process perl-Time-modules

We also need to install winexe. It is not in repositiories, but available for most distributions via the SuSe Build Server. Go to the URL http://download.opensuse.org/repositories/home:/ahajda:/winexe/ and download the relevant package for your distribution.
I am not sure, if it is necessary.  There is no CentOS 7 version available, but older version installs without complaints
wget http://download.opensuse.org/repositories/home:/ahajda:/winexe/CentOS_CentOS-6/x86_64/winexe-1.00-2.4.x86_64.rpm
rpm -ivh winexe-1.00-2.4.x86_64.rpm
setup php.ini:
TIMEZONE=`ll /etc/localtime |sed -e 's+.*/\([^/]*/[^/]*$\)+\1+'`
sed -i -e 's/memory_limit/;memory_limit/g' /etc/php.ini
echo "memory_limit = 512M" >> /etc/php.ini
sed -i -e 's/max_execution_time/;max_execution_time/g' /etc/php.ini
echo "max_execution_time = 300" >> /etc/php.ini
sed -i -e 's/max_input_time/;max_input_time/g' /etc/php.ini
echo "max_input_time = 600" >> /etc/php.ini
sed -i -e 's/error_reporting/;error_reporting/g' /etc/php.ini
echo "error_reporting = E_ALL" >> /etc/php.ini
sed -i -e 's/display_errors/;display_errors/g' /etc/php.ini
echo "display_errors = On" >> /etc/php.ini
sed -i -e 's/upload_max_filesize/;upload_max_filesize/g' /etc/php.ini
echo "upload_max_filesize = 10M" >> /etc/php.ini
sed -i -e 's/date.timezone/;date.timezone/g' /etc/php.ini
echo "date.timezone = $TIMEZONE" >> /etc/php.ini

Set the server name and shell (used for scripts) for Apache and restart daemon
HOSTNAME=`uname -n`
echo "ServerName $HOSTNAME" >> /etc/httpd/conf/httpd.conf
chsh -s /bin/bash apache
systemctl restart httpd.service

Set the SUID for the nmap binary (so we can use the apache front end to run scripts which call nmap).
chmod u+s /usr/bin/nmap

You should be able to determine the IP Address of your Open-AudIT server via the following command:
ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'

Install OpenAudit using standard installer. The errors are normal in this case.
wget http://dl-openaudit.opmantek.com/OAE-Linux-x86_64-release_1.4.1.tar.gz
tar xvf OAE-Linux-x86_64-release_1.4.1.tar.gz 
cd Open-AudIT*
./installer -t /var/www/oa
Note that the installed software resides in three separate places:
/var/www/oa ,
/var/www/html/open-audit,
/usr/local/open-audit
It seems to be better to let open-audIT to install to the default location: /usr/local.

Open ports 80, 443, 8042 in firewall or disable it completely. Disable selinux.
systemctl stop firewalld
setenforce 0

Selinux experiments:
enable httpd to exec scripts:
semanage fcontext -a -t httpd_sys_script_exec_t '/usr/local/open-audit(/.*)?'

restore context
restorecon -R /usr/local/open-audit/

set:
setsebool -P nis_enabled 1
setsebool -P httpd_can_network_connect 1

Let the selinux to to teach itselves:
setenforce permissive
 

do some work...
 
grep httpd /var/log/audit/audit.log | audit2allow -m httpdopenaudit > httpdopenaudit.te
less httpdopenaudit.te 
 
grep httpd /var/log/audit/audit.log | audit2allow -M httpdopenaudit 
semodule -i httpdopenaudit.pp

and enable selinux:
setenforce enforcing

 
 


SSH based VPN for virtual machine

My virtual machine is hidden behind a host-based NAT.  It should work as a (headless) test server. I need to see and access all its ports. The virtual machine is a fresh system, accessible via ssh (VirtualBox port forwarding: host:2222 -> guest:22 ).

1. virtual (as root):
vi /etc/ssh/sshd_config 
PermitTunnel yes
:wq

systemctl restart sshd
systemctl stop firewalld

2. host (as root):
ssh -w5:5 -p 2222 root@localhost ifconfig tun5 10.0.1.1 netmask 255.255.255.252 up &
sleep 3
ifconfig tun5 10.0.1.2 netmask 255.255.255.252 up
ping 10.0.1.1

Links:
Thanks to: http://sleepyhead.de/howto/?href=vpn


pondělí 15. září 2014

CentOs: rsyncd + selinux

Preliminary info - not sure if all steps are necessary.
symptoms: client cannot connect with @ERROR: chroot failed
rsyncd.log on server:
 rsync: chdir /data/rsync_direcory failed: Permission denied (13)


first try (no visible effect):
setsebool -P allow_rsync_anon_write on

next (agaiin, no effect):
semanage fcontext -a -t public_content_t /data/rsync_directory

does not make sense, as we are on server:
setsebool -P rsync_client on

finally - after this it works:
cat /var/log/audit/audit.log | audit2allow -M rsync
semodule -i rsync-.pp


středa 7. května 2014

grub repair

1. boot CentOS rescue USB/CD

2. allow the rescue manager to mount root (and boot) partition (as /mnt/sysimage) - not necessary.
The disk setup is as follows:
/dev/sda = (hd0) = usb boot drive 
/dev/sdb = (hd1) = normal boot drive with failed grub.

3. start grub
server:# grub

4. I have separate boot and root partitions: /dev/sda1 (boot), /dev/sda3 (root). In a single root/boot partition setup try to find /boot/grub/stage1
grub> find /grub/stage1
(hd1,0)
grub> root (hd1,0)
grub> setup (hd1)
grub> quit
In this case grub uses grub/menu.lstto setup the configuration. Even if it refers to (HD0)

5. exit, reboot

pátek 25. dubna 2014

hardware testing

1. memory

Use either
  • standalone memtest86+, running from USB or CD, or a free version of Memtest 5.
  • user space program memtester (available as RPM):
    memtester 1024

    This command tests 1G of ram. Run as root.

2. CPU

use Mprime under torture test mode
./mprime -d -t

3. disk

use Bonnie++ package, perhaps several times concurrently
bonnie++ -p 3
bonnie++ -y 1 -s $((512*1024)) > out1 &
bonnie++ -y 1 -s $((512*1024)) > out2 &
bonnie++ -y 1 -s $((512*1024)) > out3 &

The first command creates semaphores for three synchronous tests. Use "-p -1" to clear the semaphores.

4. LAN 

ssh connection between two machines
dd if=/dev/zero |ssh  -c blowfish remote "dd=/dev/null"
Choice of encryption depends on capabilities of CPUs. This can generate higher throughput on certain CPU (e.g. without AES_NI)
dd if=/dev/zero bs=16M |ssh -c arcfour  remote "cat > /dev/null "

To test the raw connection:
nc -l  4671 >/dev/null & ssh  remote_comp "dd if=/dev/zero | nc  local_comp 4671 "; fg

or using iperf:
server:~> iperf -s  -p 4671
client:~> iperf -c server -p 4671 -d -L 4672 -t $((10*60*60)) -i 5
(connect to port 4671, listen on port 4672, run test  for 10 hours, each 5 seconds show the bandwidth report)

grub2 repair

1. boot rescue

2. mount root (and boot) partition

3.
mount --bind /proc /mnt/sda2/proc
mount --bind /sys /mnt/sda2/sys
mount --bind /dev /mnt/sda2/dev

4.
chroot /mnt

5. Then, inside 'chroot'ed  environment (not necessary if grub.cfg exists)
grub2-mkconfig -o /boot/grub2/grub.cfg 

6.
grub2-install /dev/sda
(resp. grub2-install --force --debug /dev/sda )

7. exit, reboot

čtvrtek 17. dubna 2014

rsync backup command

spravne reseni:
viz http://stackoverflow.com/questions/21148145/rsync-command-with-filter-in-a-bash-variable

 RSYNCCMD=rsync
RSYNCOPTS=(-aHx --delete            \
 --exclude '*/.beagle*'          \
 --exclude '*/.gvfs/*'          \
 --exclude '*/.google/*'          \
 --exclude '*.gconf*'           \
 --exclude '*/[Cc]ache/*'       \
 --exclude '*/.[Cc]ache/*'       \
 --exclude '*/sysel*/*'       \
 --exclude '*/[Tt]rash/*'       \
 --exclude 'cyril/tmp/*'       \
 --exclude 'cyril/.thumbnails/*'       \
 --exclude 'cyril/.opera/images/*'  \
 --exclude 'cyril/.opera/opcache/*'  \
 --exclude 'cyril/.nautilus/metafiles/*')


  $RSYNCCMD "${RSYNCOPTS[@]}" /home/cyril "$TGT"


problem s .gvfs:


reseni 1 :

RSYNCCMD="rsync -aHP --delete --max-size=4G \
 --exclude 'tmp/*'          \
 --exclude 'var/tmp/*'          \
 --exclude 'var/lock/*'          \
 --exclude 'var/lib/ntp/proc*'          \
 --exclude 'var/crash/*'          \
 --exclude '*/[Cc]ache/*'       \
 --exclude '*/.opera/opcache/*'       \
 --exclude '*/.[Cc]ache/*'       \
 --exclude '.[Cc]ache/*'       \
 --exclude '*/.gvfs' \
 --exclude '.gvfs' \
 --exclude '*/.opera/icons/*'       \
 --exclude '*/.thumbnails/*'       \
 --exclude '.thumbnails/*'       \
 --exclude '*.beagle*'          \
 --one-file-system "


eval $RSYNCCMD / "$TGT" && tgt1="ok"
 eval $RSYNCCMD /opt/ "$TGT"/opt && tgt2="ok"


 for i in `ls /home` ; do 
    if  grep -q $i /etc/passwd ;
     then # echo $i je uzivatel ;
       sudo -u $i $RSYNCCMD /home/$i/ "$TGT"/home/$i &&  tgt3="$tgt3 + $i ok" && echo zaloha $i provedena `date`
     else #echo $i neni ;
       eval $RSYNCCMD /home/$i/ "$TGT"/home/$i && tgt3="$tgt3 + $i ok" && echo zaloha $i provedena `date`
    fi ;
  done

ale proste v RSYNCCMD se --exclude=*/.gvfs   neprovede.


Resni 2:
(sysel 10.3. 2014)
 $RSYNCCMD --exclude='*/.gvfs'  / "$TGT" && STATUS1=OK


Nicmene,  RSYNCCMD je podle me definovan spatne.

========================

skript /root/rsync-zaloha.sh , kde v root jsou externi filesystemy namountovane /maiboxes a /data:

#!/bin/bash
LOCKF=/var/lock/rsync-zaloha.lock
TGT="sever.cz::modul"


# Create empty lock file if none exists
touch $LOCKF
# Read the content of the lockfile into a variable
read lastPID < $LOCKF
# If lastPID is not null and a process with that pid exists, exit the script
[ ! -z "$lastPID" -a -d /proc/$lastPID ] && { echo 'Locked: Another process is running' ; exit 1; }
# Write the PID of the current running script to the lock file

echo $$ > $LOCKF
echo :::: `date` start ::::::::::::::::::::::::::::::::::::::::::::::::

OPTS="-aHx --delete"
EXCL=(--exclude '/tmp/' --exclude '/var/tmp/' --exclude '/mailboxes/' --exclude '/data/')

 echo `date`" rsync $OPTS "${EXCL[@]}" / ${TGT}/"
nice /usr/bin/rsync $OPTS "${EXCL[@]}" / ${TGT}/

 echo `date`" rsync $OPTS /mailboxes/ ${TGT}/mailboxes/"
nice /usr/bin/rsync $OPTS /mailboxes/ ${TGT}/mailboxes/

 echo `date`" rsync $OPTS /data/ ${TGT}/data/"
nice /usr/bin/rsync $OPTS /data/ ${TGT}/data/


rm -f $LOCKF
echo :::: `date` stop ::::::::::::::::::::::::::::::::::::::::::::::::