cobol

cobol

Thursday, May 7, 2015

Dos and DDoS


A denial of service (DoS) attack is a resource consumption attack that has the primary goal of preventing legitimate activity on a victimized system. A DoS attack renders the target unable to respond to legitimate traffic.
There are two basic forms of denial of service:
• Attacks exploiting a vulnerability in hardware or software. This exploitation of a weakness, error, or standard feature of software intends to cause a system to hang, freeze, consume all system resources, and so on. The end result is that the victimized computer is unable to process any legitimate tasks.
• Attacks that flood the victim’s communication pipeline with garbage network traffic. These attacks are sometimes called traffic generation or flooding attacks. The end result is that the victimized computer is unable to send or receive legitimate network communications.
In either case, the victim has been denied the ability to perform normal operations (services).
DoS isn’t a single attack but rather an entire class of attacks. Some attacks exploit flaws in operating system software, whereas others focus on installed applications, services, or protocols. Some attacks exploit specific protocols, including Internet Protocol (IP), Transmission Control Protocol (TCP), Internet Control Message Protocol (ICMP), and User Datagram Protocol (UDP).
DoS attacks typically occur between one attacker and one victim. However, they aren’t always that simple. Most DoS attacks employ some form of intermediary system (usually an unwilling and unknowing participant) to hide the attacker from the victim. For example, if an attacker sends attack packets directly to a victim, it’s possible for the victim to discover who the attacker is. This is made more difficult, although not impossible, through the use of spoofing.
Many DoS attacks begin by compromising or infiltrating one or more intermediary systems that then serve as launch points or attack platforms. These intermediary systems are commonly referred to as secondary victims. The attacker installs remote-control tools, often called bots, zombies, or agents, onto these systems. Then, at an appointed time or in response to a launch command from the attacker, the DoS attack is conducted against the victim. The victim may be able to discover zombied systems that are causing the DoS attack but probably won’t be able to track down the actual attacker. Attacks involving zombied systems are known as distributed denial-of-service (DDoS) attacks. Deployments of numerous bots or zombies across numerous unsuspecting secondary victims have become known as botnets.
Here are some countermeasures and safeguards against these attacks:
• Adding firewalls, routers, and intrusion detection systems (IDSs) that detect DoS traffic and automatically block the port or filter out packets based on the source or destination address
• Disabling echo replies on external systems
• Disabling broadcast features on border systems
• Blocking spoofed packets from entering or leaving your network
• Keeping all systems patched with the most current security updates from vendors.

Wednesday, April 8, 2015

 Java implement Data encryption standard (DES)

Program to implement Data encryption standard (DES)




import java.io.BufferedReader;
import java.io.InputStreamReader;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import javax.xml.bind.annotation.
adapters.HexBinaryAdapter;

public class DES {

  private Cipher cipher = null;
  private DESKeySpec keySpec = null;
  private SecretKeyFactory keyFactory = null;

  public String encrypt(String inputString,
        String commonKey) throws Exception {

    String encryptedValue = "";
    SecretKey key = getSecretKey(commonKey);
    cipher.init(Cipher.ENCRYPT_MODE, key);
    byte[] inputBytes = inputString.getBytes();
    byte[] outputBytes = cipher.doFinal(inputBytes);
    encryptedValue = new HexBinaryAdapter().marshal(outputBytes);
    return encryptedValue;
  }

  public String decrypt(String encryptedString,
        String commonKey) throws Exception {
    String decryptedValue = "";
    encryptedString = encryptedString.replace(' ', '+');
    SecretKey key = getSecretKey(commonKey);
    cipher.init(Cipher.DECRYPT_MODE, key);
    byte[] recoveredBytes = null;
    try {
      recoveredBytes =
          cipher.doFinal
            (new HexBinaryAdapter().unmarshal(encryptedString));
    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }
  
    decryptedValue = new String(recoveredBytes);
    return decryptedValue;
  }

  private SecretKey getSecretKey(String secretPassword) {
    SecretKey key = null;
    try {
      cipher = Cipher.getInstance("DES");
      keySpec = new DESKeySpec
          (secretPassword.getBytes("UTF8"));
      keyFactory = SecretKeyFactory.getInstance("DES");
      key = keyFactory.generateSecret(keySpec);
    } catch (Exception e) {
      e.printStackTrace();
      System.out.println
        ("Error in generating the secret Key");
    }
    return key;
  }

  public static void main(String[] args) {
    BufferedReader reader;
    reader = new BufferedReader
        (new InputStreamReader(System.in));
    DES des = new DES();
  
    try {
      System.out.println
      ("ENCRYPTION --------------------------------");
      System.out.print("Enter Plain Message: ");
      String input = reader.readLine();
    
      System.out.print("Enter Key: ");
      String key = reader.readLine();
      System.out.println();
    
      System.out.print("Encrypted Message: ");
      String encrypted = des.encrypt(input, key);
      System.out.println(encrypted);
      System.out.println();
      System.out.println();
    
      System.out.println
      ("DECRYPTION --------------------------------");
      System.out.print("Enter Encrypted Message: ");
      encrypted = reader.readLine();
    
      System.out.print("Enter Key: ");
      key = reader.readLine();
      System.out.println();

      System.out.print("Decrypted Message: ");
      String decrypted = des.decrypt(encrypted, key);
      System.out.println(decrypted);
      System.out.println();
    
    } catch (Exception e) {
      e.printStackTrace();
    }
  
  }

}


Output:
ENCRYPTION-----------------------------------------------------------------------------------------
enter plain message: hello world (f.e)
Enter key: DonkeyKongCountry
 Encrypted message: 18FCD0F55D04602E564E35C1BC1BC1107A

DECRYPTION:---------------------------------------------------------------------------------------
Enter Encrypted Message:
18FCD0F55D04602E564E35C1BC1BC1107A
Enter Key: DonkeyKongCountry
Decrypted Message: Hello World

Friday, April 3, 2015

Java program to implement AES (Advanced encryption standard) algorithm.




import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.security.spec.AlgorithmParameterSpec;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
public class AES {
  BufferedReader reader;
  final String IV = "AAAAAAAAAAAAAAAA";
  public static void main(String args[]) {
    AES aes = new AES();
    aes.go();
  }
  public AES() {
    reader = new BufferedReader
        (new InputStreamReader(System.in));
  }
  void go() {
    StringBuffer message = new StringBuffer();
    try {
      System.out.print("Enter Message: ");
      message.append(reader.readLine());
    
      while (message.length() % 16 != 0)
        message.append('\u0000');
    
    } catch (Exception e) {
      e.printStackTrace();
      return;
    }
  
    StringBuffer key = new StringBuffer();
    try {
      System.out.print("Enter Key: ");
      key.append(reader.readLine());
    
      while (key.length() % 16 != 0)
        key.append('\u0000');
    
    } catch (Exception e) {
      e.printStackTrace();
      return;
    }
  
    // Encryption
    byte[] cipher =
        encrypt(message.toString(), key.toString());
  
    System.out.print("Cipher: ");
    for (int i=0; i<cipher.length; i++)
      System.out.print((int)cipher[i]);
    System.out.println();
  
    // Invalid key
    //key.replace(0, 6, "ABCDEF");

  
    // Decryption
    String decrypted =
        decrypt(cipher, key.toString());
  
    System.out.println("Decrypted message: " + decrypted);
  }
  byte[] encrypt
    (String plain, String key) {
  
    byte[] encrypted = null;
  
    try {
      Cipher cipher =
          Cipher.getInstance
            ("AES/CBC/NoPadding", "SunJCE");
    
      SecretKeySpec sks =
          new SecretKeySpec(key.getBytes("UTF-8"), "AES");
    
      AlgorithmParameterSpec params;
      params = new IvParameterSpec(IV.getBytes("UTF-8"));
      cipher.init(Cipher.ENCRYPT_MODE, sks, params);
  
      encrypted = cipher.doFinal(plain.getBytes("UTF-8"));
    } catch (Exception e) {
      e.printStackTrace();
    }
  
    return encrypted;
  }
  String decrypt(byte[] ct, String key) {
    StringBuffer decrypted = new StringBuffer();
    try {
      Cipher cipher =
          Cipher.getInstance("AES/CBC/NoPadding", "SunJCE");
    
      SecretKeySpec sks =
          new SecretKeySpec(key.getBytes("UTF-8"), "AES");
    
      AlgorithmParameterSpec params;
      params = new IvParameterSpec(IV.getBytes("
UTF-8"));
      cipher.init(Cipher.DECRYPT_MODE, sks, params);
    
      String s = new String(cipher.doFinal(ct), "UTF-8");
      decrypted.append(s);
    } catch (Exception e) {
      e.printStackTrace();
    }
  
    for (int i=decrypted.length()-1; i>0; i--) {
      if (decrypted.charAt(i) == '\u0000')
        decrypted.deleteCharAt(i);
      else break;
    }
  
    return decrypted.toString();
  }
}



***F.E , Output:

Enter message: " Obeanie went up Tora Bora and ended up in Abotttabad, It took Yankee Doodle Doo and Big Brother 10 years and a fortune to figure it out. The singleness of purpose is imperative and the use of NSA's Prism doubtful. ."
 Enter key:JackRabbitMoab308

Cipher: 3224-48-107-24-112-6134-1234771101-48-82114-87-84-3512-19-117507-103427011567-3698-698248-548625587-25-56-65-69-546-5875-77563219

Decrypted message: Obeanie went up Tora Bora and ended up in Abotttabad, It took Yankee Doodle Doo and Big Brother 10 years and a fortune to figure it out. The singleness of purpose is imperative and the use of NSA's Prism doubtful.