Friday 2 December 2016

Password less authentication in linux

Source : host A
Destination: host B


1. Run the below command for generating public and private key( host A)

ssh-keygen -t rsa

/home/username/id_rsa (private key)
/home/username/id_rsa.pub (public key)

2. ssh-copy-id -i  /home/username/id_rsa.pub host_B_ip_address



Alternate way:

* Copy the text inside id_rsa.pub file .

* Login into host B and go to /root/username/

and create new file "authorized_keys" and paste text copied from step 2.

*  Login into Host A to Host B password less.(ssh host B)


Simple:

Put public key(host A) to authorized_keys(host B)

Now Host A can login into host B without any password.



Tuesday 18 October 2016

ffmpeg merge audio video

ffmpeg merge audio video:

Input file : song.mp3 , video.mp4
Output file : output.mp4


ffmpeg -i song.mp3 -i video.mp4 -acodec copy -vcodec copy -f mp4 output.mp4


If your audio or video stream is longer, you can add the -shortest option so that ffmpeg will stop encoding once one file ends.

ffmpeg -i song.mp3 -i video.mp4 -acodec copy -vcodec copy -f mp4 -shortest output.mp4

Wednesday 21 September 2016

Linux user management commands

Create user in linux :

root@test2:~# useradd test1
root@test2:~# passwd test1
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

Note : we can also create user with adduser command.

-Whenever user is created in linux the default access is assigned to user via /etc/profile file.
-Username is added to /etc/passwd file.
-Same as username one group is created in /etc/group file.
-Encrypted password save into /etc/shadow file.


Delete user in linux:

root@test2:~# userdel test1


Lock user account in linux:

root@test2:~# passwd -l test1
passwd: password expiry information changed.

when user will try to login he will get below message.

login as: test1
test1@192.168.0.10's password:
Access denied

When the user account is locked we can see sign after username in /etc/shadow file.

root@test2:~# cat /etc/shadow | grep test
test1:!$6$prWdpshs$A0WNBzbHC5sEke7hatNq8lFaB/Ux.SQ3vRc1.If4joDTD/AMpsuPYT.1mCmfBDUCoh6ND7izfcT9buo1wiZ581:17066:0:99999:7:::


Unlock user account in linux:

root@test2:~# passwd -u test1

passwd: password expiry information changed.

You can also unlock by editing /etc/sadow file. remove the ! sign from locked account.


Linux user account details :

root@test2:~# chage -l test1
Last password change                                    : Sep 22, 2016
Password expires                                        : never
Password inactive                                       : never
Account expires                                         : never
Minimum number of days between password change          : 0
Maximum number of days between password change          : 99999
Number of days of warning before password expires       : 7

See process run by user :

root@test2:~# ps  -u test1
  PID TTY          TIME CMD
 2442 ?        00:00:00 systemd
 2443 ?        00:00:00 (sd-pam)
 2463 ?        00:00:00 sshd
 2464 pts/0    00:00:00 sh

Root access to test1 user :

Edit the /etc/sudoers and add the below line.

%test1  ALL=(ALL:ALL) ALL

Switch to another user :

sudo su - username

root@test2:~# sudo su - test1
No directory, logging in with HOME=/
$ bash
test1@test2:/$




Monday 5 September 2016

Simple linux boot process

When you press the power button of linux system these six steps are followed by linux system.

1. BIOS
  • BIOS stands for Basic Input/Output System
  • Performs some system integrity checks
  • Searches, loads, and executes the boot loader program.
  • It looks for boot loader in floppy, cd-rom, or hard drive. You can press a key (typically F12, F2, DEL,  but it depends on your motherboard) during the BIOS startup to change the boot sequence.
  • Once the boot loader program is detected and loaded into the memory, BIOS gives the control to it.
  • So, in simple terms BIOS loads and executes the MBR boot loader.

2. MBR

  • MBR stands for Master Boot Record.
  • It is located in the 1st sector of the bootable disk. Typically /dev/hda, or /dev/sda
  • MBR is 512 bytes in size. It has three components 1) primary boot loader info in 1st 446 bytes 2) partition table info in next 64 bytes 3) MBR validation check in last 2 bytes.
  • It contains information about GRUB (or LILO in old systems).
  • MBR loads and executes the GRUB boot loader.

3. GRUB

  • GRUB stands for Grand Unified Bootloader.
  • If you have multiple kernel images installed on your system, you can choose which one to be executed.
  • GRUB displays a splash screen, waits for few seconds, if you don’t enter anything, it loads the default kernel image as specified in the grub configuration file.
  • GRUB has the knowledge of the filesystem (the older Linux loader LILO didn’t understand filesystem).
  • Grub configuration file is /boot/grub/grub.conf (/etc/grub.conf is a link to this). The following is sample grub.conf of CentOS.
  • #boot=/dev/sda
    default=0
    timeout=5
    splashimage=(hd0,0)/boot/grub/splash.xpm.gz
    hiddenmenu
    title CentOS (2.6.18-194.el5PAE)
              root (hd0,0)
              kernel /boot/vmlinuz-2.6.18-194.el5PAE ro root=LABEL=/
              initrd /boot/initrd-2.6.18-194.el5PAE.img
  • As you notice from the above info, it contains kernel and initrd image.
  • GRUB just loads and executes Kernel and initrd images.

4. Kernel

  • Mounts the root file system as specified in the “root=” in grub.conf
  • Kernel executes the /sbin/init program
  • Since init was the 1st program to be executed by Linux Kernel, it has the process id (PID) of 1. Do a ‘ps -ef | grep init’ and check the pid.
  • initrd stands for Initial RAM Disk.
  • initrd is used by kernel as temporary root file system until kernel is booted and the real root file system is mounted. It also contains necessary drivers compiled inside, which helps it to access the hard drive partitions, and other hardware.

5. Init

  • Looks at the /etc/inittab file to decide the Linux run level.
  • Following are the available run levels
    • 0 – halt
    • 1 – Single user mode
    • 2 – Multiuser, without NFS
    • 3 – Full multiuser mode(mostly default)
    • 4 – unused
    • 5 – X11
    • 6 – reboot
  • Init identifies the default initlevel from /etc/inittab and uses that to load all appropriate program.
  • Run ‘grep initdefault /etc/inittab’ on your system to identify the default run level
  • If you want to get into trouble, you can set the default run level to 0 or 6. Since you know what 0 and 6 means, probably you might not do that.
  • Typically you would set the default run level to either 3 or 5.

6. Runlevel programs

  • When the Linux system is booting up, you might see various services getting started. For example, it might say “starting sendmail …. OK”. Those are the runlevel programs, executed from the run level directory as defined by your run level.
  • Depending on your default init level setting, the system will execute the programs from one of the following directories.
    • Run level 0 – /etc/rc.d/rc0.d/
    • Run level 1 – /etc/rc.d/rc1.d/
    • Run level 2 – /etc/rc.d/rc2.d/
    • Run level 3 – /etc/rc.d/rc3.d/
    • Run level 4 – /etc/rc.d/rc4.d/
    • Run level 5 – /etc/rc.d/rc5.d/
    • Run level 6 – /etc/rc.d/rc6.d/
  • Please note that there are also symbolic links available for these directory under /etc directly. So, /etc/rc0.d is linked to /etc/rc.d/rc0.d.
  • Under the /etc/rc.d/rc*.d/ directories, you would see programs that start with S and K.
  • Programs starts with S are used during startup. S for startup.
  • Programs starts with K are used during shutdown. K for kill.
  • There are numbers right next to S and K in the program names. Those are the sequence number in which the programs should be started or killed.
  • For example, S12syslog is to start the syslog deamon, which has the sequence number of 12. S80sendmail is to start the sendmail daemon, which has the sequence number of 80. So, syslog program will be started before sendmail.
  • First it Kills the Program then Start the Program

Monday 1 August 2016

Iptables linux firewall simple command

What is Iptables ?

Iptables is a rule based firewall and it is pre-installed on Linux operating system which control the incoming and outgoing traffic. We can create chain rule and block black listed IP.

For example:

Block IP:

If we got DDOS attack on web server from 192.168.1.10 now we can block the inbound traffic from this IP using Iptabes.

iptables -D INPUT -s 192.168.1.10 -j DROP

or range of IP

iptables -A INPUT -s 192.168.0.0/24 -j DROP

Now from 192.168.1.10 will not able to access anything on your server.

Restricting access with mac address :

iptables -A INPUT -m mac --mac-source 0E:0F:EA:91:04:08 -j DROP

iptables -A INPUT -m mac --mac-source 0E:0F:EA:91:04:08 -j ACCEPT


Restricting access on port:

iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 22 -j ACCEPT

iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 25-j ACCEPT

Port 22(SSH) and 25(SMTP)  is accessible only from 192.168.1.0/24

List of rule :

iptables -L -n -v

-L : List rules.
-v : Display detailed information. 
-n : Display IP address and port in numeric format.

Deleting rule :

iptables -D INPUT -s 192.168.0.10 -j DROP

iptables -D INPUT -m mac --mac-source 0E:0F:EA:91:04:08 -j DROP

iptables -D INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 22 -j ACCEPT







Monday 4 July 2016

Run sudo command with php or Apache in linux

Ubuntu run apache as the www-data user and sudo command ask for password everytime you run sudo command. If you want to use sudo without a password from a web page, you need to allow www-data user to run sudo command with no password.

Steps:

1. Run  sudo visudo  command.

2. add below lines at the end of the file.

www-data ALL=NOPASSWD: ALL

3. or you can specify only for specific program.

www-data ALL=NOPASSWD: /sbin/iptables


Below PHP code to ban ip using ufw firewall in Linux ubuntu.


 <form action="" method="post">  
 Enter IP : <input type="text" name="ip">  
 <input type="submit" value="Ban IP">  
 </form>  
   
 <?php  
   
 if(isset($_POST["ip"]))  
 {  
 $ip= $_POST["ip"];  
 echo "$ip";  
 $ban = shell_exec("sudo ufw deny from $ip");  
 echo "Banned".$ban;  
 }  
   
 ?>

4. Done 

Thursday 23 June 2016

Types of Hackers

There are different types of hackers some do for money some do for fun.

White hat :

white hat hacker breaks security for non-malicious reasons, either to test their own security system, perform penetration tests or vulnerability assessments for a client - or while working for a security company which makes security software. The term is generally synonymous with ethical hacker, and the EC-Council,[17] among others, have developed certifications, courseware, classes, and online training covering the diverse arena of ethical hacking.
White hat hackers are usually seen as hackers who use their skills to benefit society. They may be reformed black hat hackers or they may simply be well-versed in the methods and techniques used by hackers. An organization can hire these consultants to do tests and implement best practices that make them less vulnerable to malicious hacking attempts in the future.

Black hat :

A "black hat" hacker is a hacker who "violates computer security for little reason beyond maliciousness or for personal gain" (Moore, 2005). The term was coined by Richard Stallman, to contrast the maliciousness of a criminal hacker versus the spirit of playfulness and exploration of hacker culture, or the ethos of the white hat hacker who performs hacking duties to identify places to repair.[19] Black hat hackers form the stereotypical, illegal hacking groups often portrayed in popular culture, and are "the epitome of all that the public fears in a computer criminal".
A black hat hacker is an individual with extensive computer knowledge whose purpose is to breach or bypass internet securityBlack hat hackers are also known as crackers or dark-side hackers. The general view is that, while hackers build things, crackers break things. They are computer security hackers that break into computers and networks or also create computer viruses. The term “black hat” comes from old westerns where the bad guys usually wore black hats and the good guys wore white ones.

Grey hat :

A grey hat hacker lies between a black hat and a white hat hacker. A grey hat hacker may surf the Internet and hack into a computer system for the sole purpose of notifying the administrator that their system has a security defect, for example. They may then offer to correct the defect for a fee.[20] Grey hat hackers sometimes find the defect of a system and publish the facts to the world instead of a group of people. Even though grey hat hackers may not necessarily perform hacking for their personal gain, unauthorized access to a system can be considered illegal and unethical.

Elite hacker :

social status among hackers, elite is used to describe the most skilled. Newly discovered exploits circulate among these hackers. Elite groups such as Masters of Deceptionconferred a kind of credibility on their members.

Script kiddie :

script kiddie (also known as a skid or skiddie) is an unskilled hacker who breaks into computer systems by using automated tools written by others (usually by other black hat hackers), hence the term script  kiddie usually with little understanding of the underlying concept.

Neophyte(hacking start here) :

A neophyte ("newbie", or "noob") is someone who is new to hacking or phreaking and has almost no knowledge or experience of the workings of technology and hacking.

Blue hat :

blue hat hacker is someone outside computer security consulting firms who is used to bug-test a system prior to its launch, looking for exploits so they can be closed. Microsoftalso uses the term BlueHat to represent a series of security briefing events.

Hacktivist :

A hacktivist is a hacker who utilizes technology to publicize a social, ideological, religious or political message.
Hacktivism can be divided into two main groups:

Nation state :

Intelligence agencies and cyberwarfare operatives of nation states.

Organized criminal gangs :

Groups of hackers that carry out organized criminal activities for profit.

Monday 1 February 2016

How to change pc mac address

What is MAC address?

MAC(media access control address) is physical address of your computer system. Each device have unique MAC address. MAC address is assigned by manufacture into NIC(network interface controller)

Why to change MAC address?

1. Motherboard, router is changed and your ISP is using the previous MAC address.
2. If MAC address is blocked by the firewall or router
3. Safety

Watch Video : https://www.youtube.com/watch?v=2HwVB2XlQfk(audio+video  mixing with ffmpeg)
ffmpeg.exe -ss 00:00:00  -t 116 -i "mac2.avi" -ss 0:00:00 -t 116 -i "mac2.mp3" -map 0:v:0 -map 1:a:0 -y out.mp4

More about ffmpeg :http://hackfi.blogspot.in/2015/10/slow-motion-video-using-ffmpeg.html

How to change MAC address in windows:

1. Generate random MAC address.

2. Go to Control panel >> Network and Internet >> Network connection.




3. Right Click on Local Area Connection >> Configure.



4. Advanced >> select Network Address >> enter "MAC address" into value>> Ok

5. To check MAC address "ipconfig -all"







Sunday 10 January 2016

Schedule,abort,reboot,shutdown in windows with cmd

Sometime after the software update windows automatically restart the system.(system will restart in 10 minutes) Or you may want to schedule shutdown or reboot of system.


To abort this shutdown: (before you know how to shutdown you should know how to abort)

shutdown -a or shutdown /a

Scheduling shutdown, reboot time for windows:

shutdown -s -t 30  (Shutdown will be in 30 sec)

shutdown -r -t 30 (Reboot will be in 30 sec)



Create batch file off above command:

shutdown.bat ( open notepad and write below save as shudown.bat file)

shutdown.exe -s -t -60

abort.bat ( open notepad and write below save as abort.bat file)

shutdown.exe -a

HackTips with shutdown.bat file:(first read solution)

If the shutdown.bat file is copied to "startup" folder of windows then whenever the system will start
the shutdown.bat file  command will run and system will shutdown. This will create shutdown loop the system will never start.

Where is startup folder(startup folder path)

Solution: 

Need to start windows in safe mode by pressing F8 key from your keyboard and we need to delete the shutdown.bat file from the startup folder.(in safe mode only basic programs are loaded)

Fun stuff:

Create shutdown.bat(with -t 00) file and send your friend and tell them to double click on that file to see magic or whatever.

Schedule shutdown time in some system.


Wednesday 6 January 2016

simple caesar cipher code in java

simple Caesar cipher code in java(encryption,decryption)

import java.io.*;
class cipher
{
 public static void main(String a[])
 {

  String s1,s2,cipher,alpha;
  int count=0;
  alpha="abcdefghijklmnopqrstuvwxyz";
  Console c=System.console();


  System.out.println("-----cipher----");
  s1=c.readLine("Enter the plain text :");
  s2=c.readLine("Enter the key(in number) :");
  System.out.println("---decryption---");
  int key=Integer.parseInt(s2);
  cipher="";

  for(int i=0;i<s1.length();i++)
      {
   for(int j=0;j<26;j++)
   {
     if(s1.charAt(i)==alpha.charAt(j))
      {
       cipher=""+alpha.charAt(j+key);
    System.out.print(cipher);
    }
   }

   }
   System.out.println("");
System.out.println("");
System.out.print(cipher);
System.out.println("");
System.out.println("");

   System.out.println("---decryption---");
 
   for(int i=0;i<cipher.length();i++)
      {
    for(int j=0;j<26;j++)
   {
     if(cipher.charAt(i)==alpha.charAt(j))
      {
       cipher=""+alpha.charAt(j-key);
    System.out.print(cipher);
    }
   }
   }
}
}