Linux Programmer | RHCE | RHCSA

Search This Blog

Thursday, 29 December 2016

Receiving Brodcast Packets in Python

- Receive Brodcast Packets in Python Without Configuring Network (Network cable connection needed )

Sending Packets 

import os
import sys
import commands
from socket import *
macid = commands.getoutput('ifconfig | grep -i hwaddr | head -1')
os.system("echo '%s' | awk '{print$5}' >/tmp/.mac"%macid)
mac = commands.getoutput('cat /tmp/.mac')
hostname = commands.getoutput('hostname')
username = commands.getoutput('whoami')

info = "connect:"+'%s?%s?%s'%(username,mac,hostname)

s=socket(AF_INET, SOCK_DGRAM)
s.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
s.sendto(info,('255.255.255.255',12345))

Receiving Packets

from socket import *
count = 0
while (count < 100):

s=socket(AF_INET, SOCK_DGRAM)
s.bind(('',12345))
m=s.recvfrom(1024)
print m[0]
    count = count + 1


Wednesday, 28 December 2016

customize initrd in ubuntu

How to customize your initrd

The initrd contains all the programs and utilities the kernel needs in order to find the root partition. The initrd is "given" to the kernel by the boot loader (often isolinux on cds, or grub on hard drives).

Installed systems

The initrd used by an installed system is maintained by the mkinitramfs script, which is run automatically when for instance upgrading the kernel or any tool used inside the initrd. The correct and recommended way of modifying this initrd is to make hooks and scripts in the /etc/mkinitramfs directory tree. See /usr/share/initramfs for the scripts and hooks that are included by the system.

Live systems

You might find this information useful if you want to:
  • run the "Desktop" installer from a usb drive instead of from the cd
  • run the "Desktop" live system without using the cd player
  • debug and modify the live installer system
  • avoid burning all these cds
  • avoid using your slow and noisy cd player
The initrd used when booting a live cd ("Desktop CD") can be found in the casper directory of the cd. Below we will suppose you have downloaded an iso-file and mounted it with:  sudo mount -o loop edgy-desktop-i386.iso /mnt . If you otherwise have the burnt the cd inserted it, replace /mnt by /media/cdrom0

Modify the initrd

  1. Extract the contents of the initrd:
    •   mkdir initrd-tmp
        cd initrd-tmp
        gzip -dc /mnt/casper/initrd.gz | cpio -id
      or for Ubuntu 9.10 and later:
        lzma -dc -S .lz /mnt/casper/initrd.lz | cpio -id
  2. Modify the files
  3. Repack them into a new initrd:
    •   find . | cpio --quiet --dereference -o -H newc | gzip -9 > ~/new-initrd.gz
      or, if you want an initrd.lz (for Ubuntu 9.10 and later):
        find . | cpio --quiet --dereference -o -H newc | lzma -7 > ~/new-initrd.lz
You can now remaster a cd with this new initrd.gz replacing the old /casper/initrd.gz.
However, it is easier to put the initrd on one of your drives, and let a bootloader find it. The bootloader used by the Desktop/live cd, isolinux, is not able to look anywhere else than on the cd it is started from, so we will therefore use another boot loader, grub

Friday, 9 December 2016

Encrypt shell script using shc in linux


For shell script encryption you need to install shc package

1. install shc

https://drive.google.com/open?id=0BwPBGrPmbppAYm9JRmhwTEp4ck0

2. extract shc-3.8.7.tgz and compile

tar xvfz shc-3.8.7.tgz

cd shc-3.8.7/

 make

How To Encrypt Shell Script ??

Create a sample bash shell script that you like to encrypt using shc for testing purpose.
For testing purpose, let us create the following random.sh shell script which generates random numbers. You have to specify how many random numbers you like to generate.

$ nano random.sh
#!/bin/bash

echo -n "How many random numbers do you want to generate? "
read max

for (( start = 1; start <= $max; start++ ))
do
  echo -e $RANDOM
done

$ ./random.sh
How many random numbers do you want to generate? 3
24682
1678
491
shc -r -T -f random.sh
This will create the following two files:
$ ls -l random.sh*
-rwxrw-r--. 1 purval purval 149 Mar 27 01:09 random.sh
-rwx-wx--x. 1 purval purval 11752 Mar 27 01:12 random.sh.x
-rw-rw-r--. 1 purval purval 10174 Mar 27 01:12 random.sh.x.c


  • random.sh is the original unencrypted shell script
  • random.sh.x is the encrypted shell script in binary format
  • random.sh.x.c is the C source code of the random.sh file. This C source code is compiled to create the above encrypted random.sh.x file. The whole logic behind the shc is to convert the random.sh shell script to random.sh.x.c C program (and of course compile that to generate the random.sh.x executable)
$ file random.sh
random.sh: Bourne-Again shell script text executable

$ file random.sh.x
random.sh.x: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped

$ file random.sh.x.c
random.sh.x.c: ASCII C program text

Now, let us execute the encrypted shell script to make sure it works as expected.
$ ./random.sh.x
How many random numbers do you want to generate? 3
7489
10494
29627

Tuesday, 6 December 2016

install GtkDialog in ubuntu

Steps for installing GtkDialog in ubuntu 

1. Download tar from below link

https://drive.google.com/open?id=0BwPBGrPmbppAaHIzVWdPbU04RUE

2. install Gtk version 2.0

apt-get install gtk2.0

3. Extract tar file

tar -xf gtkdialog.tar

4. Configure Gtk Dialog

cd gtkdialog/

sudo ./configure

sudo make

sudo make install


Saturday, 3 December 2016

pressed ldap configuration

How To Pressed LDAP Configuration in non-interactive mode ?

LDAP Server Configuration :

1. install the following packages using apt-get 

 apt-get install -y aptitude
 apt-get install -y expect
 apt-get install -y debconf-utils

2. install slapd in noninteractive mode 

aptitude update
aptitude install expect

VAR=$(expect -c '
spawn aptitude -y install slapd
expect "New password for the slapd \"root\" user:"
send "123\r"
expect "Repeat password for the slapd \"root\" user:"
send "123\r"
expect eof
')

echo "$VAR"

aptitude -y install slapd

3. Configure slapd from backend 

debconf-get-selections | grep "slapd" (Displays all parameters of "slapd")


echo slapd slapd/no_configuration boolean false | sudo debconf-set-selections
echo slapd slapd/domain string ldap.com | sudo debconf-set-selections
echo slapd shared/organization string ldap.com | sudo debconf-set-selections
echo slapd slapd slapd/password1 password 123 | sudo debconf-set-selections
echo slapd slapd slapd/password2 password 123 | sudo debconf-set-selections
echo slapd slapd slapd/internal/adminpw password 123 | sudo debconf-set-selections
echo slapd slapd slapd/internal/generated_adminpw password 123 | sudo debconf-set-selections
echo slapd slapd/backend select HDB | sudo debconf-set-selections
echo slapd slapd/purge_database boolean false | sudo debconf-set-selections
echo slapd slapd/move_old_database boolean true | sudo debconf-set-selections
echo slapd slapd/allow_ldap_v2 boolean false | sudo debconf-set-selections

4. Change in file Configurations 

sed -i 's/#BASE/BASE/g'  /etc/ldap/ldap.conf
sed -i 's/dc=example/dc=ldap/g' /etc/ldap/ldap.conf

sed -i '9d' /etc/ldap/ldap.conf
sed -i "9i URI     ldap://localhost" /etc/ldap/ldap.conf


LDAP Client Configuration :



1. install Dependency packages

sudo apt-get install -y debconf-utils
sudo apt-get install -y aptitude

2. install ldap-auth-client package in noninteractive mode 

sudo DEBIAN_FRONTEND=noninteractive aptitude install -y -q ldap-auth-client

3. Configure ldap-auth client package from backend

echo ldap-auth-config ldap-auth-config/ldapns/ldap-server string ldap://192.168.1.1/ | sudo debconf-set-selections
echo ldap-auth-config ldap-auth-config/ldapns/base-dn string dc=ldap,dc=com | sudo debconf-set-selections
echo ldap-auth-config ldap-auth-config/ldapns/ldap_version select 3 | sudo debconf-set-selections
echo ldap-auth-config ldap-auth-config/dbrootlogin boolean true | sudo debconf-set-selections
echo ldap-auth-config ldap-auth-config/dblogin boolean false | sudo debconf-set-selections
echo ldap-auth-config ldap-auth-config/rootbinddn string cn=admin,dc=ldap,dc=com  | sudo debconf-set-selections

4. make changes in configuration files 

- set the ldap server ip  in ldap.conf

sed -i 's/uri ldapi:\/\/\//uri ldap:\/\/192.168.1.1\//g' /etc/ldap.conf

- set base dn in /etc/ldap.conf

sed -i 's/base dc=example,dc=net/base dc=ldap,dc=com/g' /etc/ldap.conf
sed -i 's/rootbinddn cn=manager,dc=example,dc=net/rootbinddn cn=admin,dc=ldap,dc=com/g' /etc/ldap.conf

- save password in /etc/ldap.secret file 
echo "123" >/etc/ldap.secret
sudo chmod 600 /etc/ldap.secret


SSH not working with password after upgrade ubuntu 22.04 or above

In recent upgrade of ubuntu 22.04 and above we are not able to login server with SSH password. but when we try to login with key then it all...