Skip to content

Instantly share code, notes, and snippets.

@mmv-ru
Last active June 25, 2022 23:27
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmv-ru/98c435f591355741f0c4 to your computer and use it in GitHub Desktop.
Save mmv-ru/98c435f591355741f0c4 to your computer and use it in GitHub Desktop.
burp backup on qnap nas

BURP

ipkg dependencies

ipkg install openssl-dev librsync zlib

ipkg install gcc ipkg install make automake autoconf libtool binutils autoconf

ipkg install optware-devel

ipkg install crosstool-native

uthash

download uthash header files https://github.com/troydhanson/uthash/tree/master/src and put it in /opt/include

awk error

export PATH=/opt/bin:$PATH

libacl compilation error

try --disable-acl to avoid

acl.c:15:21: error: sys/acl.h: No such file or directory acl.c:19:24: error: acl/libacl.h: No such file or directory acl.c:24: error: 'acl_t' was not declared in this scope acl.c:25: error: expected ',' or ';' before '{' token make[1]: *** [acl.o] Error 1 make[1]: Leaving directory `/share/HDA_DATA/Public/burp/src'

conigure

export PATH=/opt/bin:$PATH; ./configure --disable-acl

make

make

library not found

Add /opt/lib to /etc/ld.so.conf

yum install openssl-perl

where c_rehash? Install manually from https://github.com/ChatSecure/OpenSSL/blob/master/tools/c_rehash to /opt/sbin/ and fix path to perl in header

alternative solution of acl problem

to make possible make test acl.h and libacl.h from http://mirrors.zerg.biz/nongnu/acl/ As adviced http://blog.softwaredemo.com/2011/12/21/qnap-nas-configure-rsyncdrsync-with-extended-acl-rights/

awk and find syntax error in make test

Play with PATH not help somehow. I just remove awk and find in /bin (it just symlink to busybox) so GNU tools in /opt/bin used

make autostart

http://wiki.qnap.com/wiki/Running_Your_Own_Application_at_Startup

install in /opt or in /share/MD0_DATA/.qpkg/burp (HDD) to not use Flash

build and install to permanent place to survive reboot

export PATH=/opt/bin:$PATH; ./configure --disable-acl --prefix=/share/HDA_DATA/.qpkg/burp make install

create service control file /share/HDA_DATA/.qpkg/burp/burp-server.sh add to /etc/config/qpkg.conf Section [BURP] It MUST be after [Optware] section, because it depend on Optiware ipkg /opt hierarhy

add crontab

http://wiki.qnap.com/wiki/Add_items_to_crontab combine Method 2 and Method 1 bis add to burp-server.sh

detect outdated backup on server

burp -a S -c /etc/burp/burp-server.conf | grep -v -e "$(date -d 'yesterday' +%F)" -e "$(date +%F)" -e "^[[:space:]]*$" grke/burp#151

burp-ui

http://git.ziirish.me/ziirish/burp-ui/tree/master

From 0.0.7.1 it support ACL and both burp lines 1 and 2 It really amazing.

pip

http://gleenders.blogspot.ru/2014/04/install-python-pip-on-qnap-nas.html but change versions to latest

Install Python from QNAP App center. (It should be the most easy way) Access your NAS through SSH, ex. ssh admin@192.168.1.2 Install setuptools

$ wget https://pypi.python.org/packages/source/s/setuptools/setuptools-3.4.4.tar.gz --no-check-certificate
$ tar xf setuptools-3.4.4.tar.gz
$ cd setuptools-3.4.4
$ python setup.py build $ python setup.py install

Install pip

$ curl -O https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz -k $ tar xf pip-1.5.4.tar.gz $ cd pip-1.5.4 $ python setup.py install

v Add symbolic links

$ vim /share/MD0_DATA/.qpkg/Python/python.sh

Note: you can find a cheatsheet on how to use vim here. v v Insert the following two statements under the “#create symbolic links” section

/bin/ln -sf ${QPKG_BASE}/.qpkg/Python/bin/pip /usr/bin/pip /bin/ln -sf ${QPKG_BASE}/.qpkg/Python/bin/pip2.7 /usr/bin/pip2.7

Save and exit.

/share/MD0_DATA/.qpkg/Python/python.sh restart

SSL error when using pip

When running pip install you’ll get the following SSL error (run with -v option):

SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed Workaround: Install libraries manually

Example:

Download the archive:

curl -o boto-2.27.0.tar.gz https://pypi.python.org/packages/source/b/boto/boto-2.27.0.tar.gz#md5=47a4d81554380b21d85005f91d12a585 -k

Install the archive:

pip install boto-2.27.0.tar.gz

Manual install burp-ui dependencies

download from https://pypi.python.org/pypi with wgtet --no-check-certificate

pip install

Change in burpui.cfg

Avoid bound to IPv6. Unsupported on NAS now

bound: 0.0.0.0

[BASE] admin: password

#!/bin/sh
CONF=/etc/config/qpkg.conf
QPKG_NAME="BURP"
_exit()
{
/bin/echo -e "Error: $*"
/bin/echo
exit 1
}
case "$1" in
start)
ENABLED=$(/sbin/getcfg $QPKG_NAME Enable -u -d FALSE -f $CONF)
if [ "$ENABLED" != UNKNOWN ]; then
/sbin/setcfg ${QPKG_NAME} Enable TRUE -f $CONF
elif [ "$ENABLED" != TRUE ]; then
_exit "$QPKG_NAME is disabled."
fi
OPTWARE_DIR=$(/sbin/getcfg $QPKG_NAME Install_Path -d "" -f $CONF)
if [ -d "$OPTWARE_DIR" ]; then
/bin/echo "Enable BURP"
/bin/rm -f /etc/burp
/bin/ln -s $OPTWARE_DIR/etc /etc/burp
# add path to librsync
if ! grep /opt/lib /etc/ld.so.conf; then
echo /opt/lib >> /etc/ld.so.conf
fi
/sbin/ldconfig
ln -s $OPTWARE_DIR/usr/sbin/* /usr/sbin
ln -s $OPTWARE_DIR/share/man/man8/* /opt/share/man/man8
# add burp client cron task
if ! grep -qi "burp -a t" /etc/config/crontab ; then
sed -i "\$a10 * * * * /usr/sbin/burp -a t > /dev/null 2>/dev/null" /etc/config/crontab
crontab /etc/config/crontab
/etc/init.d/crond.sh restart
fi
# add burp dedupcication cron task
if ! grep -qi "/usr/sbin/bedup -l -c" /etc/config/crontab ; then
sed -i "\$a0 12 * * 6 /usr/sbin/bedup -l -c /etc/burp/burp-server.conf >>/var/log/burp-bedup 2>&1" /etc/config/crontab
crontab /etc/config/crontab
/etc/init.d/crond.sh restart
fi
# add burp outdated and ok e-mail notification cron task
if ! grep -qi "/usr/sbin/out_of_date_report_script" /etc/config/crontab ; then
sed -i "\$a0 13 12 * * /usr/sbin/out_of_date_report_script >/dev/null 2>&1" /etc/config/crontab
crontab /etc/config/crontab
/etc/init.d/crond.sh restart
fi
# add path to c_rehash
# export PATH=/usr/sbin:/opt/sbin/:$PATH
export PATH=/opt/sbin/:$PATH
# start server
$OPTWARE_DIR/usr/sbin/burp -c /etc/burp/burp-server.conf >>/var/log/burp-server.log 2>&1
cd $OPTWARE_DIR/burp-ui.git
python ./burpui -l $OPTWARE_DIR/burp-ui.log >/dev/null 2>&1 &
else
_exit "$OPTWARE_DIR: no such directory"
fi
;;
stop)
/bin/echo "Disable BURP"
#export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
# FIXME: need to remove cron
#/usr/bin/killall burp
ps -e |grep burp|grep -v grep|awk '{print $1}'|xargs -r kill
/bin/sync
/bin/sleep 1
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit 0
#!/opt/bin/perl
# Perl c_rehash script, scan all files in a directory
# and add symbolic links to their hash values.
my $openssl;
my $dir = "/usr/local/ssl";
my $prefix = "/usr/local/ssl";
if(defined $ENV{OPENSSL}) {
$openssl = $ENV{OPENSSL};
} else {
$openssl = "openssl";
$ENV{OPENSSL} = $openssl;
}
my $pwd;
eval "require Cwd";
if (defined(&Cwd::getcwd)) {
$pwd=Cwd::getcwd();
} else {
$pwd=`pwd`; chomp($pwd);
}
my $path_delim = ($pwd =~ /^[a-z]\:/i) ? ';' : ':'; # DOS/Win32 or Unix delimiter?
$ENV{PATH} = "$prefix/bin" . ($ENV{PATH} ? $path_delim . $ENV{PATH} : ""); # prefix our path
if(! -x $openssl) {
my $found = 0;
foreach (split /$path_delim/, $ENV{PATH}) {
if(-x "$_/$openssl") {
$found = 1;
$openssl = "$_/$openssl";
last;
}
}
if($found == 0) {
print STDERR "c_rehash: rehashing skipped ('openssl' program not available)\n";
exit 0;
}
}
if(@ARGV) {
@dirlist = @ARGV;
} elsif($ENV{SSL_CERT_DIR}) {
@dirlist = split /$path_delim/, $ENV{SSL_CERT_DIR};
} else {
$dirlist[0] = "$dir/certs";
}
if (-d $dirlist[0]) {
chdir $dirlist[0];
$openssl="$pwd/$openssl" if (!-x $openssl);
chdir $pwd;
}
foreach (@dirlist) {
if(-d $_ and -w $_) {
hash_dir($_);
}
}
sub hash_dir {
my %hashlist;
print "Doing $_[0]\n";
chdir $_[0];
opendir(DIR, ".");
my @flist = readdir(DIR);
# Delete any existing symbolic links
foreach (grep {/^[\da-f]+\.r{0,1}\d+$/} @flist) {
if(-l $_) {
unlink $_;
}
}
closedir DIR;
FILE: foreach $fname (grep {/\.pem$/} @flist) {
# Check to see if certificates and/or CRLs present.
my ($cert, $crl) = check_file($fname);
if(!$cert && !$crl) {
print STDERR "WARNING: $fname does not contain a certificate or CRL: skipping\n";
next;
}
link_hash_cert($fname) if($cert);
link_hash_crl($fname) if($crl);
}
}
sub check_file {
my ($is_cert, $is_crl) = (0,0);
my $fname = $_[0];
open IN, $fname;
while(<IN>) {
if(/^-----BEGIN (.*)-----/) {
my $hdr = $1;
if($hdr =~ /^(X509 |TRUSTED |)CERTIFICATE$/) {
$is_cert = 1;
last if($is_crl);
} elsif($hdr eq "X509 CRL") {
$is_crl = 1;
last if($is_cert);
}
}
}
close IN;
return ($is_cert, $is_crl);
}
# Link a certificate to its subject name hash value, each hash is of
# the form <hash>.<n> where n is an integer. If the hash value already exists
# then we need to up the value of n, unless its a duplicate in which
# case we skip the link. We check for duplicates by comparing the
# certificate fingerprints
sub link_hash_cert {
my $fname = $_[0];
$fname =~ s/'/'\\''/g;
my ($hash, $fprint) = `"$openssl" x509 -hash -fingerprint -noout -in "$fname"`;
chomp $hash;
chomp $fprint;
$fprint =~ s/^.*=//;
$fprint =~ tr/://d;
my $suffix = 0;
# Search for an unused hash filename
while(exists $hashlist{"$hash.$suffix"}) {
# Hash matches: if fingerprint matches its a duplicate cert
if($hashlist{"$hash.$suffix"} eq $fprint) {
print STDERR "WARNING: Skipping duplicate certificate $fname\n";
return;
}
$suffix++;
}
$hash .= ".$suffix";
print "$fname => $hash\n";
$symlink_exists=eval {symlink("",""); 1};
if ($symlink_exists) {
symlink $fname, $hash;
} else {
open IN,"<$fname" or die "can't open $fname for read";
open OUT,">$hash" or die "can't open $hash for write";
print OUT <IN>; # does the job for small text files
close OUT;
close IN;
}
$hashlist{$hash} = $fprint;
}
# Same as above except for a CRL. CRL links are of the form <hash>.r<n>
sub link_hash_crl {
my $fname = $_[0];
$fname =~ s/'/'\\''/g;
my ($hash, $fprint) = `"$openssl" crl -hash -fingerprint -noout -in '$fname'`;
chomp $hash;
chomp $fprint;
$fprint =~ s/^.*=//;
$fprint =~ tr/://d;
my $suffix = 0;
# Search for an unused hash filename
while(exists $hashlist{"$hash.r$suffix"}) {
# Hash matches: if fingerprint matches its a duplicate cert
if($hashlist{"$hash.r$suffix"} eq $fprint) {
print STDERR "WARNING: Skipping duplicate CRL $fname\n";
return;
}
$suffix++;
}
$hash .= ".r$suffix";
print "$fname => $hash\n";
$symlink_exists=eval {symlink("",""); 1};
if ($symlink_exists) {
symlink $fname, $hash;
} else {
system ("cp", $fname, $hash);
}
$hashlist{$hash} = $fprint;
}
#!/usr/bin/env bash
#
# This script will generate list of outdated clients
# Create folders /usr/local/share/burp-custom and /var/log/burp-custom
# chmod +x the sh file
# Locate this file in /usr/local/share/burp-custom/burp-custom-reports.sh
# link to if desired ln -s /usr/local/share/burp-custom/burp-custom-reports.sh /usr/local/bin/bur-custom-reports.sh
OPTWARE_DIR=$(/sbin/getcfg BURP Install_Path -d "" -f $CONF)
outdated=`date -d "3 days ago" +%F`
sendto=mmv.rus@gmail.com
sendfrom=qnapnas.mmv.rus@gmail.com
timestamp=`date +%F-%H-%M`
logfolder=/tmp/outdated-log
#Variable to use on outdated hosts function
repoutdfile=$logfolder/burp-outdated.$outdated.$timestamp.log
#Variable to use for not outdated hosts function
repokfile=$logfolder/burp-ok.$outdated.$timestamp.log
logsclean(){
find $logfolder -name "*.log" -type f -mtime +30 -print|xargs -r rm
# find $logfolder -name "*.log" -type f -print |xargs -r -t rm
}
make_dirs() {
if [[ ! -d $1 ]] ; then mkdir -p $1 ; fi
}
make_dirs "$logfolder"
report_outdated(){
date_backup=`echo $1 | sed -e 's/\s\+/ /g' | cut -d' ' -f6`
echo "line is $1"
echo "date_backup is $date_backup"
if [[ "$date_backup" < "$outdated" ]] ; then
echo "$1" >> $repoutdfile
else
echo "$1" >> $repokfile
fi
}
reports(){
report_outdated "$1"
}
send_mail()
# Send a mail message
# $1 = subject
# $2 = to
# $3 = from
# $4 = msg
{
local tmpfile="/tmp/sendmail.tmp"
/bin/echo -e "Subject: $1\r" > "$tmpfile"
/bin/echo -e "To: $2\r" >> "$tmpfile"
/bin/echo -e "From: $3\r" >> "$tmpfile"
/bin/echo -e "\r" >> "$tmpfile"
if [ -f "$4" ]; then
cat "$4" >> "$tmpfile"
/bin/echo -e "\r\n" >> "$tmpfile"
else
/bin/echo -e "$4\r\n" >> "$tmpfile"
fi
/usr/sbin/sendmail -t < "$tmpfile"
rm $tmpfile
}
send_email_report(){
if type -P mail 2>/dev/null; then
cat $1 | mail -s "$2" $sendto -aFrom:$sendfrom
else
# alternative for QNAP
send_mail "$2" "$sendto" "$sendfrom" $1
fi
}
# example output line:
# hosname idle last backup: 0000023 2015-04-10 16:04:01
# read by line report from burp
burp -a S -c /etc/burp/burp-server.conf | grep -i "last backup" | while read -r line; do reports "$line" ; done
echo "finishing and sending email"
#Send email using function, parse file and then subject inside "subject line"
send_email_report $repoutdfile "Outdated hosts older than $outdated on $HOSTNAME"
send_email_report $repokfile "Burp Hosts ok newer than $outdated on $HOSTNAME"
#Clean old logs
logsclean
[BURP]
Name = BURP
Version = 1.4.20
Author = grke
Date = 2014-07-26
Shell = /share/HDA_DATA/.qpkg/burp/burp-server.sh
Install_Path = /share/HDA_DATA/.qpkg/burp
QPKG_File = burp.qpkg
Enable = TRUE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment