Click here

Sunday, January 23, 2022

Omicron - people gathers in crowd

Amidst omicron thread, people are gathered in crowd at markets and public places to buy their daily needs. Because of full lockdown at Sunday in Tamilnadu, people are standing in queues to buy fish and meat. 



Wednesday, December 16, 2020

org.gnome.Terminal: GDBus.Error:org.freedesktop.DBus.Error.Spawn.ChildExited: Process org.gnome.Terminal exited with status 9

 I have tried multiple options of setting locale to en.US.utf8 to solve the problem. But, it did not help out. Looks like something has corrupted in my server. I tried running vncserver as a root to solve the problem. If you get any error on running vncserver as a root, you need to execute this command "vncpasswd". Hope this post helps.

Sunday, April 26, 2020

Coronavirus - 3 days complete curfew announcement defeats the purpose of social distancing

After the recent announcement from Tamil Nadu CM E. Palanisamy about 3 days complete shutdown, people have gathered in masses at markets, shops and bakeries which defeats the whole purpose of social distancing and lockdown which had been done so far. I wouldn't blame government fully on this. I can say, people is not serious about Coronavirus. They think, if they all the basic needs stocked they don't need to go out but it should not come at the cost of breaking social distancing. Such a pathetic situation after koyambedu bus station incident.

Tuesday, October 2, 2018

Import private key and certificate into java keystore


From time to time you have to update your SSL keys and certificates. In some cases you may have a mixed infrastructure e.g. "normal" http servers and tomcat or other java based servers. In the latter case you'll have to import your shiny new certificate and key into your java keystore.
There are several methods that you can use but I found the following the most simple:
  1. Export your key, certificate and ca-certificate into a PKCS12 bundle via
    COPY
    % openssl pkcs12 -export -in my.crt -inkey my.key -chain -CAfile my-ca-file.crt -name "my-domain.com" -out my.p12
  2. Be sure to set an export password! (see further below for an explanation)
  3. If you get the following error message "Error unable to get issuer certificate getting chain." then you should concatenate the openssl ca-certs with your own ca-cert into one file and use that as parameter for -CAfile. Example:
    COPY
    % cat /etc/ssl/cert.pem my-ca-file.crt > ca-certs.pem % openssl pkcs12 -export -in my.crt -inkey my.key -chain -CAfile ca-certs.pem -name "my-domain.com" -out my.p12
  4. Import the PKCS12 file into a new java keystore via
    COPY
    % keytool -importkeystore -deststorepass MY-KEYSTORE-PASS -destkeystore my-keystore.jks -srckeystore my.p12 -srcstoretype PKCS12
Attention!
If you don't set an export password in the first step the import via keytool will most likely bail out with an NullPointerException.

Wednesday, September 19, 2018

Python - List comprehension

List comprehensions are a tool for transforming one list (any iterable actually) into another list. During this transformation, elements can be conditionally included in the new list and each element can be transformed as needed.

The basic syntax is
[ expression for item in list if conditional ]

This is equivalent to:

for item in list:
    if conditional:
        expression

Example
1)
x = 1
y = 1
z = 1

lis = []
lis = [ [i,j,k] for i in range(x+1) for j in range(y+1) for k in range(z+1) if (i+j+k) != N]
print lis

Output
[[0, 0, 0], [0, 0, 1], [0, 1, 0], [1, 0, 0], [1, 1, 1]]

Above is the nested for loop
2)
x = [i for i in range(10)]
print x

This will give the output:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Thursday, September 13, 2018

Python - Print without newline and space


In python , by default print inserts newline character at the end of an output

For example:



Output
1
2

1) To ignore the new line at the end of an output, you can do it multiple ways

In python 2.x



Output
1 2

2) To ignore the space in between



Output
12

Using backspace character replaces the space in between. Comma at the end replaces the newline character with an empty string.  If you use + operator , both the operators has to be in string format

3) To print without using string



Output
12

Comma at the end replaces the new line character. Printing an empty string suppresses the space in between

4) Python 3.x has an easy way of doing this



Using end statement, replaces the end terminator with an empty string.

print('a', 'b', 'c', sep='')
to suppress the white space separator between items.





Friday, April 20, 2018

ldconfig , to set library path in linux

LDCONFIG
( Where are the Libs ? )


Sometimes when you install a program from source it can complain that a certain library is missing . . . and still you know that the lib it is complaining about is actually installed on your system. But most likely it is not on the default place ( /usr/lib ) where the program looks for the lib.

There is a file on your system where all the paths to the libraries are mentioned: the /etc/ld.so.conf file. Here is an example of the /etc/ld.so.conf file on Slackware:
 
QUOTE
/usr/local/lib
/usr/X11R6/lib
/usr/i486-slackware-linux/lib
/usr/lib
/opt/kde/lib


So, what's the solution ?

1). First locate the lib the program is complaining about, maybe it is in /usr/lib/qt/lib or in /usr/include or any other odd location.

2). Next add the path to that lib in the /etc/ld.so.conf file. So, for our example the /etc/ld.so.conf file would look like:
 
QUOTE
/usr/local/lib
/usr/X11R6/lib
/usr/i486-slackware-linux/lib
/usr/lib
/opt/kde/lib
/usr/lib/qt/lib
/usr/include

3). Finally to let the system know that you updated the /etc/ld.so.conf file and make it use the new values give the command:
CODE
# ldconfig

Friday, March 23, 2018

Squid stats - Beginner's guide

Squidclient is a tool that can access the squid service, and retrieve statistics on the service. For example, to get some general performance statistic, run the following command on the squid server

Friday, March 9, 2018

Docker - Beginner's guide

1) What is docker?

A client program named Docker.

A server program that manages a Linux system[ listen for messages from the command line and manages the running system].

A program that builds container's from code

A service that distributes the containers across the internet

A company that makes containers


2) What is docker container?

Self contained sealed unit of software. Contains elements required to run the code. Includes batteries and operating system

Includes - Code, configs , processes, Networking[to allow the containers to talk to other containers],dependencies and operation system.

A container image is a lightweight, stand-alone, executable package of a piece of software that includes everything needed to run it: code, runtime, system tools, system libraries, settings. Available for both Linux and Windows based apps, containerized software will always run the same, regardless of the environment. Containers isolate software from its surroundings, for example differences between development and staging environments and help reduce conflicts between teams running different software on the same infrastructure.


3) What is docker engine?

"Docker engine" is the part of Docker which creates and runs Docker containers.

Because the Docker Engine daemon uses Linux-specific kernel features, you can’t run Docker Engine natively on Windows. Instead, you must use the Docker Machine command, docker-machine, to create and attach to a small Linux VM on your machine. This VM hosts Docker Engine for you on your Windows system

Basics
A Docker container is a live running instance of a Docker image.
A Docker image is a file you have created to run a specific service or program in a particular OS.So, for example, say I want a web proxy; I can create a Docker image which is a standard install of Ubuntu 14.04 with just the squid3 package installed, and some specific configuration that I want to enforce authentication to be used with that squid proxy. I've created the docker image, but it's just a file.To use it, I need to create a Docker container which uses that file to become a live running squid VM with the config of my choice.

"Docker engine" (or just "Docker") is the program which creates and runs the Docker container from the Docker image file

Basic docker commands


  1. docker run -ti debian bash[  start an debian image with bash prompt]
-i, --interactive Keep STDIN open even if not attached

-t allocate a Pseudo TTY
-ti - terminal interactive which causes it have a full  terminal within the image so that you can run the shell and get things like tab completion and formatting to work completely

  1. docker images [ shows images]

docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
debian              latest              1b3ec9d977fb        3 weeks ago         100MB
hello-world         latest              f2a91732366c        3 months ago        1.85kB

REPOSIROY - Where it came from
TAG - Version number
IMAGE ID - internal docker representation of the image


  1. docker ps - to find running containers
root@debian:/home/saravanan# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
0e512fe50c7b        debian              "bash"              14 seconds ago      Up 13 seconds                           gifted_mcclintock
  1. docker kill container-id  [ to kill the running container]
  2. Docker container ID and Image ID's are different
  3. docker ps -l = to display last stopped container

droot@debian:/home/saravanan# docker ps -l
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                       PORTS               NAMES
910bce8bfc26        debian              "bash"              9 minutes ago       Exited (127) 2 seconds ago                       elastic_curran

Status shows the exit status of the container

7. docker  ps -a ,  to display all the container's including stopped containers.  Suppose if you create a file and exited that container, it is called stopped container. The file created in that container will never get deleted . It's there in   a stopped container. If we execute a docker run command from an image , it will spawn a new instance of an image and it does not contain the file which was created in  another instance of an image.

8. Docker image ====>[ docker run] =====> Running container ==[exit]==> Stopped container=== [docker commit] =======> New image

9. docker commit container-id

To modify and save a container as an image

root@debian:/home/saravanan# docker  run -ti debian bash

root@70f0efed3d3f:/# ls 
bin  boot  dev        etc  home  lib        lib64  media  mnt  opt        proc  root  run  sbin  srv  sys  tmp  usr  var
root@70f0efed3d3f:/# touch HELLO-WORLD
root@70f0efed3d3f:/# exit
Exit

root@debian:/home/saravanan# docker ps -l , to list last exited container
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
70f0efed3d3f        debian              "bash"              15 seconds ago      Exited (0) 2 seconds ago                       competent_boyd

Method 1
root@debian:/home/saravanan# docker commit 70f0efed3d3f [ to commit a container, input -container ID]
sha256:56eaac55c9225df65d3907f56d2d0f807470bd06b4c67f6564ef7a555e339961

root@debian:/home/saravanan#

root@debian:/home/saravanan# docker tag  56eaac55c9225df65d3907f56d2d0f807470bd06b4c67f6564ef7a555e339961 my-image [ to tag an image]

Method 2
root@debian:/home/saravanan# docker ps -l
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
70f0efed3d3f        debian              "bash"              15 seconds ago      Exited (0) 2 seconds ago                       competent_boyd


root@debian:/home/saravanan# docker ps -l
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                        PORTS               NAMES
0355fd7bcf33        my-image            "bash"              4 minutes ago       Exited (127) 10 seconds ago                       heuristic_ptolemy

root@debian:/home/saravanan# docker commit competent_boyd my-image2  [ commit and tag an image, Input - container name and tag name]
sha256:496ecb935c3c72ec79381f5c89d7a4b48a9b409ddeab4ad6e1059e8862eaf444

root@debian:/home/saravanan# docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
my-image2           latest              496ecb935c3c        7 seconds ago       100MB
my-image            latest              56eaac55c922        7 minutes ago       100MB
debian              latest              1b3ec9d977fb        3 weeks ago         100MB
hello-world         latest              f2a91732366c        3 months ago        1.85kB
root@debian:/home/saravanan#


root@debian:/home/saravanan#
root@debian:/home/saravanan#
root@debian:/home/saravanan#
root@debian:/home/saravanan# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
my-image            latest              56eaac55c922        2 minutes ago       100MB
debian              latest              1b3ec9d977fb        3 weeks ago         100MB
hello-world         latest              f2a91732366c        3 months ago        1.85kB

root@debian:/home/saravanan#
root@debian:/home/saravanan#
root@debian:/home/saravanan# docker run -ti my-image
root@0355fd7bcf33:/# ls
HELLO-WORLD  bin  boot        dev  etc  home        lib  lib64  media  mnt        opt  proc  root  run  sbin  srv  sys  tmp  usr        var

root@0355fd7bcf33:/# 

Tuesday, March 6, 2018

Virtual box Full screen mode for debian

  1. Login as root;
  2. Update your APT database with apt-get update;
  3. Install the latest security updates with apt-get upgrade;
  4. Install required packages with apt-get install build-essential module-assistant;
  5. Configure your system for building kernel modules by running m-a prepare;
  6. Click on Install Guest Additions… from the Devices menu, then run mount /media/cdrom.
  7. Run sh /media/cdrom/VBoxLinuxAdditions.run, and follow the instructions on screen

Wednesday, May 31, 2017

Mercap/editcap: Files from that network type can't be saved in that format [solved]

Sometimes we do face problem in spilt/merge  packet captures taken in a different media. For example, if we capture packets in MAC operating system, we can't merge the capture files using mergecap utility. Because the files are not in libpcap format. When you try to merge/edit the files, you get the below error


Issue
mergecap  -w out.pcap VA123_00016_20170530202904 VA123_00016_20170530202905

mergecap: Can't open or create out.pcap: Files from that network type can't be saved in that format

file VA123_00016_20170530202904
VA989_00016_20170530202904: pcap-ng capture file - version 1.0


you can solve this issue with the help of tcpdump utility. With the help of tcpdump, you can convert the pcap-ng files to libpcap format 

tcpdump -r  VA123_00016_20170530202904  output.pcap

You can use the below script to merge the list of pcapng files into a single libpcap file

#!/bin/bash
for i in `ls`
do
    echo $i
    file=`echo $i | cut -d "." -f1`
    tcpdump -r $i -w $file.pcap
done
mergecap -w outputfile.pcap *.pcap

Tuesday, March 28, 2017

Install nodejs , npm and websocket in Debain wheezy

Installing npm and websocket is not so easy in Debian wheezy. You can make use of the below steps to install websocket and npm in Debian wheezy.

1) Install nodejs using the Debian package manager 

apt-get install nodejs

2) npm does not come with Debian package management system. Still there is a way 

curl https://www.npmjs.com/install.sh | sh

3) To install websocket, you need to upgrade to the latest version of nodejs and node-gyp package. You can install latest version of nodejs using nmp

npm cache clean -f
npm install -g n
n stable
n 4.7.2

4) Install node-gyp package using npm

npm install -g node-gyp

5) Finally install websocket using npm

npm install webscoket

P.S.
npm makes it easy for JavaScript developers to share and reuse code, and it makes it easy to update the code that you're sharing.

Tuesday, March 14, 2017

Debugging Signals- Log the PID of the sender

Suppose if your program randomly crashes  and you find that some process is sending SIGTERM to your program , you can find the process ID of the sender using "sigaction"


 You need to use sigaction call to set up your signal handler instead of signal. Doing so will let you set up a signal handler that takes three parameters:

  • An int, for the signal number (just like signal)
  • A siginfo_t *, which is a structure containing all sorts of information about the source of the signal, including the pid of the sender if applicable. (It also includes some information about the cause of the signal for automatic signals like SIGSEGV.)
  • A ucontext_t *, which has to do with which thread got the signal. Mostly ignorable


Example code and steps:

1) catchsignal.c

"/* Example of using sigaction() to setup a signal handler with 3 arguments
 * including siginfo_t.
 */
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
 
static void hdl (int sig, siginfo_t *siginfo, void *context)
{
 printf ("Sending PID: %ld, UID: %ld\n",
   (long)siginfo->si_pid, (long)siginfo->si_uid);
}
 
int main (int argc, char *argv[])
{
 struct sigaction act;
 
 memset (&act, '\0', sizeof(act));
 
 /* Use the sa_sigaction field because the handles has two additional parameters */
 act.sa_sigaction = &hdl;
 
 /* The SA_SIGINFO flag tells sigaction() to use the sa_sigaction field, not sa_handler. */
 act.sa_flags = SA_SIGINFO;
 
 if (sigaction(SIGTERM, &act, NULL) < 0) {
  perror ("sigaction");
  return 1;
 }
 
 while (1)
  sleep (10);
 
 return 0;
}

2) Compile the program 
    gcc -o catchsignal catchsignal.c


3) Shell script to trigger a signal 

sendsig.sh
#!/bin/sh
while [ 1 ]
do
    pidof=`ps -ef | grep catchsignal | grep -v "grep" | awk  '{print $2}'`
    if [ ! -z $pidof ]
    then
        kill $pidof
    fi
sleep 10
done

4) Execute the script
   sh sendsig.sh

5) Run the program 
    ./catchsignal


6) Output of the program


Sending PID: 18532, UID: 0 
Sending PID: 18532, UID: 0
Sending PID: 18532, UID: 0



Tuesday, January 24, 2017

Bash useful commands


1) To find the duplicates in a file

cat $filename | sort | uniq -c  | awk '$1 > 1 {print $2}'

sort  To sort contents of a file
uniq -c   Counts number of duplicates in a file
awk '$1 > 1 {print $2}'  Print values which has count greater than 1 (Duplicates)


2) Replace a text in vim editor

shift +R   To replace mode

3) Copy the entire file in vim editor

From top
shift + v  To enter visual mode
shift+gg  To Select the entire file

From bottom

shift + v  To enter visual mode
shift  + 1G To Select the entire file

Wednesday, October 12, 2016

Replay a tcp packet captured by wireshark

To replay a tcp packet cpatured by wireshark, you can use either tcpreplay/bittwist tools


Example1:

tcprewrite --infile=capturedtraffic.pcap --outfile=temp.pcap --srcipmap=0.0.0.0/0:192.168.1.15 --enet-smac=00:0c:29:de:78:42

tcpreplay --intf1=eth0 temp.pcap

sender source MAC is set to 00:0c:29:de:78:42


Example2:

bittwiste -I arp-packet.pcap -O fake-arp.pcap -T arp -o 2 -s 00:00:aa:bb:cc:dd -p 192.168.1.1 -t 00:08:55:64:65:6a -q 192.168.1.20

input file: arp-packet.pcap

output file: fake-arp.pcap

The sender MAC address is set to 00:00:aa:bb:cc:dd; a non-existent MAC address on the network.

bittwist -i vr0 fake-arp.pcap sending packets through vr0 trace file

Tuesday, October 11, 2016

Find the IP address of the client in an SSH session


1) SSH_CLIENT
shows the address of the client system, the outgoing port number on the client system and the incoming port on the server.

Ex:
echo $SSH_CLIENT
10.10.10.211 63956  22

2) SSH_CONNECTION

Identifies the client and server ends of the connection.
The variable contains four space-separated values: client IP address,
client port number, server IP address, and server port number.

Ex:
echo $SH_CONNECTION
10.10.10.211 63956 172.16.32.11 22

3) SSH_TTY

This is set to the name of the tty (path to the device) associated
with the current shell or command.  If the current session has no tty,
this variable is not set.

Ex:
echo $SSH_TTY
/dev/pts/22

4) Set your own .bashrc

userIP=`echo $SSH_CLIENT | awk '{ print $1}'`

 if [ "$userIP" = "x.x.x.x" ]
 then
        echo "It's my machine IP"
        source /home/bob/.bashrc
 fi

Using this feature you can set your own .bashrc





Fragmenation offset

Fragment Offset
The fragment offset field is measured in units of eight-byte blocks. It is 13 bits long and specifies the offset of a particular fragment relative to the beginning of the original fragmented IP datagram. The first fragment has an offset of zero. This allows a maximum offset of (213 – 1) × 8 = 65,528 bytes, which would exceed the maximum IP packet length of 65,535 bytes with the header length included (65,528 + 20 = 65,548 bytes).

From <https://en.wikipedia.org/wiki/IPv4#Header>

Why we need to divide fragment offset by 8?

Total length of the packet ( 2^16 -1) = 65535 bytes. If the fragment offset is 16 bits then we
Can keep  fragment offset as it's because 2^16 bytes is 65535 (Total length of the packet)..
We can only specify 8192 bytes (2^13) as maximum value of fragment offset. Only if we multiply 8192*8=65536 we will get the total length of the packet.

 So whenever we mention fragment offset we need to divide total size of the packet by 8.  Because in case if the packet size is 65535 byes we can't mention it because the maximum value of the fragment offset is 8192 bytes(2^13)

Tuesday, September 6, 2016

SVN useful commands

1) To see the list of files changed between 2 revisions

svn diff  -rX:Y 
svn log -v -rX:Y

X - Revision1
Y- Revision 2

Example:
 svn diff  -r11995:12159 

2) To checkout a branch

svn checkout  <branch name>

Example:

svn checkout https://xyz.com/testCode

3) To checkout a specific version

svn checkout -r "revisionNumber" "url"

Example:

svn checkout -r 12345 https://xyz.com/testCode


Monday, August 8, 2016

Windows shortcut to Mute/unMute volume

you can create a Master Volume Shortcut and also assign a Shortcut Key.

Right click on a empty area on desktop, and click on New and Shortcut. 

Paste the following in to the location of the item area:-

%windir%\System32\SndVol.exe -f 49825268

Click Next button and give a name to the Shortcut and click Finish.

Now You right click on it and select Properties.

Click Shortcut tab.

Assign your desired shortcut key like F8 or F9 in the Shortcut Key area.

Click OK/Apply.

Monday, August 1, 2016

Decoding Machine check register exception

Dump
CPU 0: Machine Check Exception: 0000000000000004
CPU 1: Machine Check Exception: 0000000000000005
      Bank 5: b200000802000e0f


Kernel Code snippet:

rdmsr (MSR_IA32_MC0_STATUS+i*4,low, high);  - reads the values of 64 bit machine check registers
        if (high & (1<<31)) {
            if (high & (1<<29))
                recover |= 1;
            if (high & (1<<25))
                recover |= 2;
            printk (KERN_EMERG "Bank %d: %08x%08x", i, high, low);
if (recover & 2)
        panic ("CPU context corrupt");

Decoding : 

( Reference Document)
You will need to browse to Intel’s website hosting Intel® 64 and IA-32 Architectures Software Developer Manuals. There, download a manual named “Intel 64 and IA-32 Architectures Software Developer’s Manual Combined Volumes 3A, 3B, and 3C: System Programming Guide”.

(Reference: https://vmxp.wordpress.com/2014/10/27/debugging-machine-check-errors-mces/comment-page-1/)

IA32_MCi_STATUS MSRS
Each IA32_MCi_STATUS MSR contains information related to a machine-check error if its VAL (valid) flag is set.

Bank 5: b200000802000e0f  - In hex format


63 62 61 60 59 58 57 56 55  54 53      52 - 38                37   36-32         31 - 16                     
1    0  1   1   0   0  1    0  0     00        000000000000000  0    01000   0000 0010 0000 0000   

 15  - 0
0000 1110 0000 1111  ( Bank value in binary format)


63 -  VAL -MCi_STATUS register valid
61 - Uncorrected error
60  - Error reporting enabled
57 - Processor context corrupt

Model specific errors   ( 16 – 31 bits) - Model-specific error code field, bits 31:16
27-25 bits - Bus queue error type

000 for BQ_ERR_HARD_TYPE error
001 for BQ_ERR_DOUBLE_TYPE error   --  It’s Double bit error detected on data read in our case
010 for BQ_ERR_AERR2_TYPE error
100 for BQ_ERR_SINGLE_TYPE error
101 for BQ_ERR_AERR1_TYPE error

0 -15 -  Specifies the machine-check architecture-
defined error code for the machine-check error condition detected
IA32_MCi_Status [15:0] Compound Error Code Encoding


Omicron - people gathers in crowd

Amidst omicron thread, people are gathered in crowd at markets and public places to buy their daily needs. Because of full lockdown at Sunda...