Tuesday, February 17, 2015

Scanning open ports in linux using nmap

nmap - Network exploration tool and security / port scanner

Syntax:
nmap [options] target

Scan all the open ports
$ nmap localhost       use: -F for fast scan, -p [port number] for particular port
Output:
Not shown: 993 closed ports
PORT     STATE SERVICE
21/tcp   open  ftp
22/tcp   open  ssh
25/tcp   open  smtp
80/tcp   open  http
111/tcp  open  rpcbind
631/tcp  open  ipp
3306/tcp open  mysql

Scan remote ip/host

$ nmap google.com

Starting Nmap 5.51 ( http://nmap.org ) at 2015-02-17 15:35 IST
Nmap scan report for google.com (74.125.236.36)
Host is up (0.00095s latency).
Other addresses for google.com (not scanned): 74.125.236.41 74.125.236.39 74.125.236.34 74.125.236.32 74.125.236.46 74.125.236.37 74.125.236.40 74.125.236.33 74.125.236.38 74.125.236.35
rDNS record for 74.125.236.36: maa03s04-in-f4.1e100.net
Not shown: 942 closed ports, 56 filtered ports
PORT    STATE SERVICE
80/tcp  open  http
443/tcp open  https

Scan only TCP (T) or UDP (U) or Other(O) open ports

nmap -sT localhost


Saturday, February 14, 2015

Freeswitch installation on CentOs, Amazon, Google Compute Engine

First check the dependencies on Freeswitch wiki if not go with this!

$ yum install git gcc-c++ autoconf automake libtool wget python ncurses-devel
zlib-devel libjpeg-devel openssl-devel e2fsprogs-devel sqlite-devel libcurl-devel 
pcre-devel speex-devel ldns-devel libedit-devel

Allow the default 
RTP 10000-20000 UDP port
SIP port 5060-5061, 5080-5081
websocket ws and wss port maybe 5066 or 8081, 7334
in IPtables and Firewalls


Choose a location to install

$ cd /usr/src/

Install git command and take the latest source from git hub

$ git clone https://freeswitch.org/stash/scm/fs/freeswitch.git

$ cd /usr/src/freeswitch

# The -j argument spawns multiple threads to speed the build process$ ./bootstrap.sh -j

# if you want to add or remove modules from the build, edit modules.conf
vi modules.conf
# add a module by removing '#' comment character at the beginning of the line
# remove a module by inserting the '#' comment character at the beginning of the line containing the name of the module to be skipped
 
$ ./configure -C

make && make install



Install Sounds
CD-Quality Sounds
$ make cd-sounds-install
$ make cd-moh-install

Set Owner and Permissions
# create user 'freeswitch'
# add it to group 'daemon'
# change owner and group of the freeswitch installation
$cd /usr/local
$useradd --system --home-dir /usr/local/freeswitch -G daemon freeswitch
$passwd -l freeswitch

$chown -R freeswitch:daemon /usr/local/freeswitch/
$chmod -R 770 /usr/local/freeswitch/
$chmod -R 750 /usr/local/freeswitch/bin/*

$mkdir /var/run/freeswitch
$chown -R freeswitch:daemon  /var/run/freeswitch


Start FreeSWITCH

$cd /usr/local/freeswitch/bin
$./freeswitch

or

EXPORT the path to
vim ~/.bash_profile

PATH=$PATH:$HOME/bin:/usr/local/bin:/usr/local/freeswitch/bin

Now start it by
$freeswitch -ncwait 
Connect back again to console using
$fs_cli

Configuration Edits
$ cd /usr/local/freeswitch/conf/sip_profiles

remove vp6 files and dir if you don't use it

Just leave external  external.xml  internal.xml  files alone

Internal xml is the sip user reg place
go to fs_cli
cli>reload mod_sofia   ---> to show internal profile in sofia status

$ vim internal.xml
change below tags

<param name="context" value="default"/>  to route all the SIP invites to user agent directory in directory

<param name="apply-nat-acl" value="rfc1918"/>

<param name="aggressive-nat-detection" value="true"/>
<param name="apply-inbound-acl" value="domains"/>
<param name="presence-hosts" value="your-external-ip"/>
<param name="multiple-registrations" value="true"/>
<param name="inbound-zrtp-passthru" value="true"/>
<param name="NDLB-broken-auth-hash" value="true"/>
<param name="NDLB-broken-auth-hash" value="true"/>
<param name="NDLB-received-in-nat-reg-contact" value="true"/>
<param name="auth-calls" value="true"/>
<param name="ext-rtp-ip" value="$${external_rtp_ip}"/>
<param name="ext-sip-ip" value="$${external_sip_ip}"/>
        
<param name="force-register-domain" value="your-external-ip"/>
<!--force the domain in subscriptions to this value -->
<param name="force-subscription-domain" value="your-external-ip"/>
<!--all inbound reg will stored in the db using this domain -->
<param name="force-register-db-domain" value="your-external-ip"/>

<!-- uncomment for sip over websocket and webrtc support --
<param name="ws-binding"  value=":8081"/>


Now change external sip and rtp ips in var..xml
$ cd /usr/local/freeswitch/conf/vars.xml 
 <X-PRE-PROCESS cmd="set" data="default_password=yourwish"/>
 <X-PRE-PROCESS cmd="set" data="bind_server_ip=your-external-ip"/>
 <X-PRE-PROCESS cmd="set" data="external_rtp_ip=your-external-ip"/>
 <X-PRE-PROCESS cmd="set" data="external_sip_ip=your-external-ip"/>
         

then comment all the default values in
data="default_provider

Change the PRT ports range if needed in 
$ vim /usr/local/freeswitch/conf/autoload_configs/switch.conf.xml

<!-- RTP port range -->
    <param name="rtp-start-port" value="10000"/>
    <param name="rtp-end-port" value="20000"/>


Change the domains in acl.xml in autolaod dir if needed!

Finally relaodxml and restart the server to take effect

use Freeswitch Rosetta Stone guide if you're familiar with asterisk cli commands

use eval command to check the variable values in fs_cli
   cli> eval $${domain}

user sofia commad to see all profile related queires
  cli> sofia show profile internal   ---> to see the full profile status
  cli> sofia show profile internal reload --->to reload the profile
  cli> sofia show profile internal reg  ---> to see the sip registered
  cli> shutdown     ---> to shutdown the server
  cli>reloadxml     ---> to check and save the edited xml files
  cli>load or unload or reload mod_ sofia    ---> to fix SIP reg errors
 




SCP copy files between servers

SCP files from local to server

Just a file

$ scp /path-file user@server:/path/

copy a directory
$ scp -r /path-dir user@server:/path/


SCP files from server to local
  On the same local machine

$ scp user@server:/path-file-located /path-to-save-in-local

Command line to execute ssh with password authentication

$ ssh user@server
  output:
  user@server's password: []

Install sshpass and can try this

sshpass -p "server-password" user@server

Copy files, SCP files without prompting for password or 
Command line to execute scp with password authentication

SCP files from local to server
$ sshpass -p "server-password" scp /path-file-to-copy user@server:/path-to-saveon'

Who own this number?

US
Local: http://fonefinder.net/
Tollfree: http://www.800forall.com/

Reverse look up
http://www.whitepages.com/

UK: 
Local: http://www.ttnc.co.uk/other-services/number-lookup/

PDF editors and converters free

Split the PDF pages
http://www.splitpdf.com/
Pic to PDF
http://www.convert-jpg-to-pdf.net/
http://www.online-convert.com

PDF editor
http://www.pdfescape.com/

Port forwarding or Virtual box to Local machine/Mac

Connecting VIRTUAL box on mac

The best way to login to a guest Linux VirtualBox VM is port forwarding. By default, you should have one interface already which is using NAT. Then go to the Network settings and click the Port Forwarding button. Add a new Rule:

Host port 3022, guest port 22, name ssh, other left blank.

or from command line

VBoxManage modifyvm myserver --natpf1 "ssh,tcp,,3022,,22"

where 'myserver' is the name of the created VM. Check the added rules:

VBoxManage showvminfo myserver | grep 'Rule'

Please be sure you don't forget to install an SSH server:

sudo apt-get install openssh-server
To SSH into the guest VM, write:

ssh -p 3022 user@127.0.0.1
Where user is your username within the VM.

Remove or Skip invalid locale warning in Ubuntu

WARNING! Your environment specifies an invalid locale.
 This can affect your user experience significantly, including the
 ability to manage packages. You may install the locales by running:

   sudo apt-get install language-pack-UTF-8
     or
   sudo locale-gen UTF-8

To see all available language packs, run:
   apt-cache search "^language-pack-[a-z][a-z]$"
To disable this message for all users, run:
   sudo touch /var/lib/cloud/instance/locale-check.skip

How to cut, grep, remove, print characters or files in linux

awk

Print characters less than 3
................
$ ls 
Applications    Network        Users        bin        dev        home        net        private        tmp        var
Library        System        Volumes        cores        etc        mach_kernel    opt        sbin        usr

$ ls | awk 'length($0) < 4'
bin
dev
etc
net
opt
tmp
usr
var
................

Print or cut only selected column

$ ls -l
total 16
-rw-r--r--+ 1 sasi  staff  39 Feb 18  2014 index.html.en
-rw-r--r--+ 1 sasi  staff  40 Feb 18  2014 ip.php

$ ls -l | awk '{print $2}'
16
1
1

$ ls -l | awk '{print $2, $4}'
16
1 staff
1 staff

Xargs:

Find and remove / copy / move 

$ find /path -iname 'search string' | xargs 'action'

i- ignore case

Example:
$ find /root -iname 'asterisk' | xargs rm -rf 

This will find and remove all the files and dir matching with asterisk




 

Download your applications / app from your appengine

 Make sure you have google's python dependencies and try

Mac:
$appcfg.py -A yourappid -V yourversionnumber download_app.py /path-to-save

Windows:
appcfg -A yourappid -V yourversionnumber download_app 
c:\path\to\download\directory

Javascript, remove extra characters in a string

Trim test Get only numbers:
Get only LowerCase:
Get only Alpha chars:
Code:
function onlyNumbers(x){
 x.value = x.value.replace(/[^0-9]/g,'');
}

function onlyLowercase (x){

x.value = x.value.replace(/[^a-z]/g,'');
}

function onlyAlhpa (x){
x.value = x.value.replace(/[^aA-zZ]/g,'');
}

Get file permission chmod in Octal modes

In Mac
Syntax: stat -f "%A%N"

try
$ls -la

Output:
total 8
drwxr-xr-x+  6 sasi  staff   204 Feb 14 00:17 .
drwxr-xr-x+ 36 sasi  staff  1224 Feb 14 00:17 ..
drwxr-xr-x+  3 sasi  staff   102 Feb 14 00:17 css
drwxr-xr-x+  5 sasi  staff   170 Feb 14 00:17 img
-rw-r--r--+  1 sasi  staff  2303 Feb 14 00:17 index.html
drwxr-xr-x+  4 sasi  staff   136 Feb 14 00:17 js

then try:
$stat -f "%A %N" *   

Output:
755 css
755 img
644 index.html
755 js


Ubuntu, Cent os
stat -c %a

CSS tricks

Mixed paint in background: background: linear-gradient(to right, #b6e358, #38b143) Grid view: display: grid; grid-template-columns: a...