Monday, May 27, 2013

Bash Scripts

Bash Scripts

Install the latest MetasPloit in Ubuntu Desktop

Install the latest MetasPloit in Ubuntu Desktop

Install the latest MetasPloit in Ubuntu:

1. Download Metasploit framework from :
wget http://downloads.metasploit.com/data/releases/metasploit-latest-linux-installer.run

2. Make installer executable:
chmod +x metasploit-latest-linux-xxx-installer.run

3. Run installer:
./metasploit-latest-linux-xxx-installer.run
4. Follow setup wizard to complete Metasploit installation.

5. To get latest Metasploit updates execute:
sudo msfupdate
6. Run Metasploit:
msfconsole

Command - Find

Command - find


find  a folder name .svn in a folder/subfolder and delete all
# rm -rf `find . -type d -name .svn`
find a file with extension .sh .Sh .sH with -iname
# find -iname *.SH 
find file with extension .tar.gz
# fine -name  *.tar.gz 

Command - SED

Command - SED


Insert the # sign from a specific line to the last
# sed -i '4,$ s/^/#/' file-name.sh
Add special sign with sed
# sed -i -e 's/$/ \&>> $STATUS/g' file-name.sh
Add Variable with sed
# sed -i 's/&> $STATUS//g' file-name.sh

Web tools

http://rubular.com/
http://rubyxp.com/

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions?redirectlocale=en-US&redirectslug=JavaScript%2FGuide%2FRegular_Expressions

Linux Command

Linux Command

find

check linux system info:
# lsb_release -a

get the key in ubuntu:
# apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 16126D3A3E5C1192

scan IP in the network
# arp-scan --interface=eth1 10.0.0.0/8
# arp-scan -I wlan1 10.0.0.0/8

List process user
# ps -o ruser,pid
List process with the pid
lsof -p pid

Command scp with key file copy file application.tar.gz to server001 and put in /home/user
sudo scp -i /home/vannak/server-key.pem application.tar.gz user@server001:/home/user

List Mount Device and Mount Informations:
lsblk

Download with Aria2c
aria2c -s 10 http://web-site.com/applications.tar.gz -d /where/to/store
or write down in a script:
#!/bin/bash
# download
    if (! test $1)
         then
              echo "Usage: $0 link-download"
         exit 1
    fi
aria2c -s10 $1 -d /where/to/store >/dev/null 2>&1 &


RSYNC
rsync from other server to keep in our computer
rsync -avz user@server001:/path/to/sync/file001.tar.gz /where/to/keep/
rsync from our computer to server
rsync -avz /what/we/to/sync/ user@server001:/path/to/keep/on/server

SSHPASS
sshpass -p 'sshpassword' scp -r user@server001:/part/of/folder/ /local/path/folder

How to Get Mail when the system restart by add this line in cronjob in the system (crontab -e)
@reboot  echo "Server has restarted "`hostname` | mail -s "System Restart" vannakk@gmail.com

Play Music Via Command Line

HowTo: Play Music Via Command Line

1. Install SoX - Sound eXchange, the Swiss Army knife of audio manipulation

which can be play with .mp3,wav,mpg,ogg,flac ..
2. Start to Play

3. See more options "man play"


Install Conky In Ubuntu Desktop

Howto: Install Conky In Ubuntu Desktop

1. Install conky
sudo apt-get install conky-all
2. Install extract package
sudo apt-get install unace unrar zip unzip p7zip-full p7zip-rar sharutils rar uudeviwe mpack lha arj cabextract file-roller
3.  Download Infinity conky and keep in /home/user-name
Change the name of file conkyrc to .conkyrc
Change the name of folder lua to .lua
Change the name of folder conky to .conky
4. Change the resolutions depend on your desktop screen
open file .conkyrc and adjust as yours (line 40)

## This Resolution is set according to the sreen resolution of 1366x768 
1600x900
## Adjust Accoring to yours
minimum_size 800 560
maximum_width 1366
5. Start your  Conky via terminal by:
# chmod a+x ~/.conky/startconky.sh# sh ~/.conky/startconky.sh
Wait a few seconds ... and Smile with ... Awesome Desktop ...



Install TeamViewer in Ubuntu Desktop



1. Dowload teamview from: http://www.teamviewer.com/download
via command line:
wget http://www.teamviewer.com/download/version_8x/teamviewer_linux_x64.deb

Next, run the commands below to install TeamViewer 8 in Ubuntu
sudo apt-get update
sudo apt-get install -f
sudo dpkg -i teamviewer* 


dpkg: dependency problems prevent configuration of teamviewer:
 teamviewer depends on libc6-i386 (>= 2.4); however:
  Package libc6-i386 is not installed.
 teamviewer depends on lib32asound2; however:
  Package lib32asound2 is not installed.
 teamviewer depends on lib32z1; however:
  Package lib32z1 is not installed.
 teamviewer depends on ia32-libs; however:
  Package ia32-libs is not installed.

dpkg: error processing teamviewer (--install):
 dependency problems - leaving unconfigured
Errors were encountered while processing:

run this command is you meet the above error:
sudo apt-get install -f

Disable - System Program Problem Detected in Ubuntu Desktop



Here is How to :

Disable - System Program Problem Detected in Ubuntu Desktop
with this error picture below:




gksu gedit /etc/default/apport
Change value of "enabled" from 1 to 0

OR

sudo sed -i 's/enabled=1/enabled=0/g' /etc/default/apport


sudo rm /var/crash/*

Saturday, May 11, 2013

Install Server Send Mail - SSMTP - Ubuntu


1. Install ssmtp
sudo apt-get install ssmtp heirloom-mailx mailutils

2. Configure ssmtp
Edit /etc/ssmtp/ssmtp.conf
#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=vannakk2013@gmail.com

# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named mail.domain.com
mailhub=smtp.gmail.com:587

# Where will the mail seem to come from?
#rewriteDomain=

# The full hostname
hostname=vannakk2013@gmail.com

# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
FromLineOverride=YES
FromLineOverride=YES

UseSTARTTLS=YES
AuthUser=vannakk2013@gmail.com
AuthPass=VannakPassw0rd
3. Setup Account
Edit /etc/ssmtp/revaliases
# sSMTP aliases
#
# Format:       local_account:outgoing_address:mailhub
#
# Example: root:your_login@your.domain:mailhub.your.domain[:port]
# where [:port] is an optional port number that defaults to 25.
root:vannakk2013@gmail.com:smtp.gmail.com:587
localusername:vannakk2013@gmail.com:smtp.gmail.com:587