Thursday, December 30, 2010

Add color to shell prompt

$ vi .bash_profile

add this column into it
# add color to shell prompt
export PS1="\e[0;31m[\u@\h \W]\$ \e[m"


Here is the description 
\e = start color scheme
0;31 = choice of color
\u = Display the current username
\h = Display the hostname
\W = Print the current working directory
\e[m = Stop color scheme 

$PS1 is your shell prompt

additional
\H = Display FQDN hostname
\@ = Display current time in 12-hour am/pm format

List of Color code

Color Code
Black 0;30
Blue 0;34
Green 0;32
Cyan 0;36
Red 0;31
Purple 0;35
Brown 0;33


Replace digit 0 with 1 to get light color version.

Monday, December 13, 2010

Prevent Accident Shutdown/Reboot

In order to prevent root or super users accidentally shutdown or reboot the Linux server, you can apply the follow method:
  1. Login to root, and edit /etc/profile with vi
  2. Add the following to the end of file /etc/profile
safereboot () {
      echo -e "\033[32;1m\ \      / / \  |  _ \| \ | |_ _| \ | |/ ___| |\033[0m"
      echo -e "\033[32;1m \ \ /\ / / _ \ | |_) |  \| || ||  \| | |  _| |\033[0m"
      echo -e "\033[32;1m  \ V  V / ___ \|  _ <| |\  || || |\  | |_| |_|\033[0m"
      echo -e "\033[32;1m   \_/\_/_/   \_\_| \_\_| \_|___|_| \_|\____(_)\033[0m"
      echo -e "Are you sure you wanna \033[31;1mSHUTDOWN\033[0m? (Type HOSTNAME to confirm)"
      read confirm
      if [ "$HOSTNAME" == "$confirm" ]; then
              sudo /sbin/shutdown -r +1
      else
              echo "SHUTDOWN aborted..."
      fi
  }
  alias reboot='safereboot'
  alias shutdown='safereboot'
  alias poweroff='safereboot'
 
 
 
eight basic EGA colors are defined as follows: 

30    black foreground
31    red foreground
32    green foreground
33    brown foreground
34    blue foreground
35    magenta (purple) foreground
36    cyan (light blue) foreground
37    gray foreground
 

How to Sniff Network Traffic

How-to

We will use WireShark to sniff the network traffic
so we will need to install the WireShark by
yum instal wireshark
Due to Wireshark is GUI base, we only eed to use one of its Wireshark function which is Tshark
tshark -V -R "filter"
-V will show all the details
-R “filter” will apply the filter rule

Example
If you want to sniff MSN chat, then you need to input:
tshark -V -R "msnms"
If you want to sniff google talk chat, then you need to input:
tshark -V -R "jabber"
If you want to capture all the traffic in the network, then you need to input:
tshark -V
If you want to capture traffic only to a specific destination such as talk.google.com, then you need to input:
tshark -V -R "ip.dst == talk.google.com"
  
due to a lot of traffic, it will be very hard to see so fast, so you will need to record it down to a document for easy reading
tshark -V -R "msnms" > data
vi data

Note

If the chat message is encrypted, it will show as encrypted or truncated
Please refer to the reference below for more filter list

Reference

OpenVPN for PfSense

First of all you need to have keys and certificates generated in order to configure the pfSense OpenVPN service;
  1. Download and install the most recent software from http://openvpn.net/download.html
    If you plan to connect from a PC with Windows Vista you should get version 2.1 or newer.
  2. Use the default options
    Start a command prompt with administrator-rights!
  3. Change directory to c:\programfiles\openvpn\easy-rsa
  4. run the “init-config.bat” file
  5. Edit 'vars.bat' file.
    The following things need to be edited:
    set KEY_COUNTRY=MY
    set KEY_PROVINCE=na
    set KEY_CITY=KL
    set KEY_ORG=OffGamers
    set KEY_EMAIL=youremail@my.offgamers.com
    Save the file
  6. Run “vars.bat
  7. Run “clean-all.bat
  8. Run “build-ca.bat
    Then you are prompted for some different things; Leave them at default, except “Common Name” - put something like “Soekris
  9. Run “build-key-server.bat server
    Again you are prompted; leave them on default except “Common Name” - use “server
    Run build-dh.bat
Client
Now its time to generate keys and certificates for the client(s)
  • Run “build-key.bat client1
    Again you are prompted; leave them on default except “Common Name” - here you should put in “client1” (or whatever you have called it)
    The client1 will be the name of the keys, certificate and the name you identify the connection on later. You can use whatever name you like, and generate as many as you want (with different names).
  • The following files should now be copied from c:\Program Files\openvpn\ to c:\Program Files\openvpn\config
    easy-rsa\keys\ca.crt
    client1.key
    client1.crt
    (if you dont see a .crt file but only a .csr file, chances are that you dont have admin priviligies. Worst case generate the keys and certificates on a NON-Vista machine)
  • Make a file in the c:\Program Files\openvpn\config called “client1.ovpn” and the file should contain
client
dev tun
proto udp
remote 203.223.138.226
ping 10
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
cert client1.crt
key client1.key
ns-cert-type server
comp-lzo
pull
verb 3
  • Put your soekris public IP after the 'remote' attribute

pfsense

  • Log into the web-gui of pfSense
  • Select VPN > OpenVPN and add an entry in the 'server' page
    Use the following settings:
Protocol: UDP
Local port: 1194
Address pool: 172.30.13.0/24 
(it should be a network that you DONT currently use)
Local Network: 172.30.10.0/24 
!!UPDATE: Note to add this value, you need to first save the setting and EDIT the settings again!!
Remote Network: blank
Cryptography: BF-CBC (128 bit) - or use what you want
Authentication Method: PKI
Now you need to have access to some of the files created in **c:\Program Files\openvpn\easy-rsa\keys** (mentioned in #12)
* Copy the WHOLE content of ca.crt into the "CA certificate" window
* Copy the WHOLE content of server.crt into the "Server Certificate" window
* Copy the WHOLE content of server.key into the "Server Key" window
* Copy the WHOLE content of dh1024.pem into the "DH parameters" window
  • Tick DHCP-Opt: Disable NetBIOS (I dont use it anyway)
  • Tick LZO Compression
— Now we need a few simple rules in the firewall —
  • Go to Firewall > rules
  • On the WAN interface you should make a rule that;
PASS
WAN
Protocol: UDP
source: any
OS type: any
Destination: any
Destination port range from: OpenVPN
Destination port range to: OpenVPN
Tick in the LOG
Leave the rest at default.
  • and another rule on the interface called LAN
PASS
Any protocol
Source: LAN