среда, 2 марта 2016 г.

Архивация содержимого папки с последующим удалением

#!/bin/bash
#Purpose = Backup of Important Data
#Run this script on cron
#START
TIME=`date +%d%m%y`             # This Command will add date in Backup File Name.
FILENAME=configs_$TIME.tar.gz   # Here i define Backup file name format.
SRCDIR=/srv/ftp/cfg             # Location of Important Data Directory (Source of backup).
DESDIR=/srv/ftp                 # Destination of backup file.
/bin/tar -cpzf $DESDIR/$FILENAME $SRCDIR
if [ -f $DESDIR/$FILENAME ]; then
  /usr/bin/find $SRCDIR/* -delete
else
 echo "Archive whith name $FILENAME in folder $DESDIR not found!"
fi

#END

вторник, 23 февраля 2016 г.

Поиск сбежавшей памяти

RAM: ps -eo size,pid,user,command | awk '{ hr=$1/1024 ; printf("%13.6f Mb ",hr) } { for ( x=4 ; x<=NF ; x++ ) { printf("%s ",$x) } print "" }' | sort

SWAP:
root@sneaky-work:/home/kim# cat ./swap.sh SUM=0 OVERALL=0 for DIR in `find /proc/ -maxdepth 1 -type d -regex "^/proc/[0-9]+"` do PID=`echo $DIR | cut -d / -f 3` PROGNAME=`ps -p $PID -o comm --no-headers` for SWAP in `grep VmSwap $DIR/status 2>/dev/null | awk '{ print $2 }'` do let SUM=$SUM+$SWAP done if (( $SUM > 0 )); then echo "PID=$PID swapped $SUM KB ($PROGNAME)" fi let OVERALL=$OVERALL+$SUM SUM=0 done echo "Overall swap used: $OVERALL KB"

среда, 3 февраля 2016 г.

Instructions on how to monitor onions w/ Nagios

Requirements

Working Nagios setup and the following packages.
  • tor / torsocks
    • For Debian, follow Tor Project Debian Instructions summarized here:
      • echo deb http://deb.torproject.org/torproject.org jessie main > /etc/apt/sources.list.d/tor.list
      • echo deb-src http://deb.torproject.org/torproject.org jessie main >> /etc/apt/sources.list.d/tor.list
      • gpg --keyserver keys.gnupg.net --recv 886DDD89
      • gpg --export A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 | apt-key add -
      • apt-get update
      • apt-get install tor torsocks deb.torproject.org-keyring

Nagios setup

  • Add the following new command to your Nagios configuration to monitor various types of onions:
define command {
    command_name        check_http_tor
    command_line        /usr/bin/torsocks /usr/lib/nagios/plugins/check_http -H '$HOSTADDRESS$' -I  '$HOSTADDRESS$' '$ARG1$'
    }
define command {
    command_name        check_ssh_tor
    command_line        /usr/bin/torsocks /usr/lib/nagios/plugins/check_ssh -H '$HOSTADDRESS$' '$ARG1$'
    }

define command {
    command_name        check_tcp_tor
    command_line        /usr/bin/torsocks /usr/lib/nagios/plugins/check_tcp -H '$HOSTADDRESS$' '$ARG1$'
    }
  • Apply the service check to a host:
define host {
    use                 generic-host            ; Name of host template to use
    host_name           samplea8s7df23jh7.onion
    alias               Sample Fake Onion
    address             samplea8s7df23jh7.onion
    check_command       check_http_tor!-p 8080
}


define service {
    use                 generic-service     ; name of template to use
    host_name           samplea8s7df23jh7.onion
    service_description SSH
    check_command       check_ssh_tor!-p 8492
}

define service {
    use                 generic-service     ; name of template to use
    host_name           samplea8s7df23jh7.onion
    service_description XMPP
    check_command       check_tcp_tor!-p 5222
}

Источник https://github.com/coldhakca/monion

суббота, 30 января 2016 г.

SSH as a Hidden Service

SSH as a Hidden Service

It is relatively easy to make your SSH server available as a hidden service accessible only through the Tor network. There are several reasons you might want to do this.
  1. You can access your server anonymously.
  2. You can access your server from the open internet even if it is hidden behind a firewall and it has a dynamically assigned IP address.
The downside to using the Tor network to access your server is that the network is not particularly fast.

Tor

On a server, you can run tor as a always-on service. Typically tor acts as a socks proxy, allowing you anonymous access to the tor network from your server. Running it as an always-on service means that it is always available as an anonymous proxy. In this case, it will also be configured to provide access to your SSH server as a hidden service as well. In this case, your hidden service is always available.
Alternatively, you can run tor on demand. You typically do this on a workstation. In this case you would run tor whenever you want to hidden service to be available.

Tor as Service

To install tor on a Fedora system, as root run:
yum install tor
You would configure it by editing the file /etc/tor/torrc, but for now it can be left as is. Start tor with:
systemctl start tor
You should not be able to use it as a socks proxy. The default proxy port is 9050, so you should be able to configure your browser to use a socks5 proxy with address localhost:9050 to test it.
If you would like a GUI tool to monitor and control your tor server, install vidalia:
yum install vidalia
Normally vidalia will start and control its own copy of tor. If you want to use it to control the system tor, you will need to configure vidalia and tor accordingly (in /etc/tor/torrc you will need to set HashedControlPassword, and in ~/.vidalia/vidalia.conf you need to set ControlPassword).

Tor on Demand

If you instead plan to run tor on demand, install both tor and vidalia as root:
yum install tor vidalia
Once you do this, you no longer need be root, you can run vidalia and tor as a normal user.
You would start tor by running vidalia. When you do so, vidalia will open a window that shows the status of tor, but you can close it. You would reopen it as needed by clicking on the onion in your status bar.
You should not be able to use tor as a socks proxy now. The default proxy port is 9050, so you should be able to configure your browser to use a socks5 proxy with address localhost:9050 to test it.
In this situation, the tor configuration file, torrc, is found in ~/.vidalia.

Configuring Your Hidden Service

To configure SSH as a hidden service, simply add the following to your torrc file and restart tor:
HiddenServiceDir <directory>
HiddenServicePort 22 127.0.0.1:22
where <directory> should be set to something like /var/lib/tor/ssh if you are running tor as a service and should be set to something like .vidalia/ssh if you are running tor on demand.
Once you restart tor, you should visit the directory you specified. In it will find the file hostname and private_key. Keep private_key secure. If a bad guy got a hold of this file, they could spoof your hidden service. The address of your hidden service is contained in hostname.
Once you create a hidden service, it will be listed in a directory that is publicly available. If you want to keep it really hidden, so nobody else could possibly find or use it, add the following to you hidden service description:
HiddenServiceDir <directory>
HiddenServicePort 22 127.0.0.1:22
HiddenServiceAuthorizeClient stealth clientname1,clientname2,clientname3
In this case, you can specify as many clients as you wish. Each client will get its own address and a password that allows access from that client. These addresses are not published in to directory. They can be found in <directory>/hostname.

Using Your Hidden Service

Accessing your hidden service requires two things. First, you must be running tor on your client machine as well. Then, you must tell your ssh client to proxy through tor. Starting tor is as simple as running vidalia. To tell your ssh client to use tor as a proxy requires that you specify that it use:
ncat --proxy 127.0.0.1:9050 --proxy-type socks5 %h %p
as the proxy command. The easiest was of doing that is to configure a host entry in ~/.ssh/config for you hidden service. To do so, add something like the following:
# Media host as Tor hidden service
host hidden
   hostname 7ei66g5djlymzxqb.onion
   proxyCommand ncat --proxy 127.0.0.1:9050 --proxy-type socks5 %h %p
Then simply running:
ssh hidden
should get you access to your server.
If you took the extra step of hiding your hidden service using HiddenServiceAuthorizeClient, you will need to add an entry to your torrc file before you will allowed access:
HidServAuth 7ei66g5djlymzxqb.onion op6npnLTq2NtpQVZqLJilB
This line contains the address of your hidden service, and the authorization string that was found in <directory>/hostname.


Оригинал - http://www.nurdletech.com/linux-notes/ssh/hidden-service.html

четверг, 28 января 2016 г.

LTE E392 & linux cli

root@RPi2-mobile:/etc/ppp# cat /etc/ppp/peers/4g
connect "/usr/sbin/chat -f /etc/ppp/4g"
/dev/ttyUSB0
115200
crtscts
noauth
novj
novjccomp
nobsdcomp
nopcomp
noaccomp
noccp
receive-all
#debug

usepeerdns
defaultroute

user ""
password ""
root@RPi2-mobile:/etc/ppp# cat /etc/ppp/4g
TIMEOUT 35
ECHO ON
ABORT '\nBUSY\r'
ABORT '\nERROR\r'
ABORT '\nNO ANSWER\r'
ABORT '\nNO CARRIER\r'
ABORT '\nNO DIALTONE\r'
ABORT '\nRINGING\r\n\rRINGING\r'
ABORT '\nUsername/Password Incorrect\r'
'' \rAT
OK 'AT+CGDCONT=1,"IP","internet.mts.ru"'
OK ATD*99#
CONNECT ""

вторник, 12 января 2016 г.

проверка и автоматическая установка туннеля VPNC

root@RPi2-mobile:~# crontab -l
# Edit this file to introduce tasks to be run by cron.
* * * * *  /usr/local/sbin/vpnc-keepalive 10.X.X.1 10.Y.Y.1 &

root@RPi2-mobile:~# cat /usr/local/sbin/vpnc-keepalive
#!/bin/sh
#
# Restart VPNC if both of the specified hosts on the command line are unavailable

if ! [ $(ping -q -c 1 ${1} 2>&1 | grep "1 packets received" | sed "s/.*\(1\) packets received.*/\1/") ] ||
   ! [ $(ping -q -c 1 ${2} 2>&1 | grep "1 packets received" | sed "s/.*\(1\) packets received.*/\1/") ]; then
    echo Not alive $1 or $2, restarting VPNC
    /etc/init.d/vpnc restart
else
echo Alive $1 or $2
fi

понедельник, 13 апреля 2015 г.

Downloading an Entire Web Site with wget



If you ever need to download an entire Web site, perhaps for off-line viewing, wget can do the
job—for example:
$ wget \
     --recursive \
     --no-clobber \
     --page-requisites \
     --html-extension \
     --convert-links \
     --restrict-file-names=windows \
     --domains website.org \
     --no-parent \
         www.website.org/tutorials/html/
This command downloads the Web site www.website.org/tutorials/html/.
The options are:
  • --recursive: download the entire Web site.
  • --domains website.org: don't follow links outside website.org.
  • --no-parent: don't follow links outside the directory tutorials/html/.
  • --page-requisites: get all the elements that compose the page (images, CSS and so on).
  • --html-extension: save files with the .html extension.
  • --convert-links: convert links so that they work locally, off-line.
  • --restrict-file-names=windows: modify filenames so that they will work in Windows as well.
  • --no-clobber: don't overwrite any existing files (used in case the download is interrupted and
    resumed).

original: http://www.linuxjournal.com/content/downloading-entire-web-site-wget