Browse Source

init

master
youys 2 years ago
commit
83c6e7627d
32 changed files with 827 additions and 0 deletions
  1. BIN
      Buffer Copy Without Checking Size of Input/Buffer Copy Without Checking Size of Input.docx
  2. +20
    -0
      Buffer Copy Without Checking Size of Input/code files/mitigated.cpp
  3. +16
    -0
      Buffer Copy Without Checking Size of Input/code files/vulnerable.cpp
  4. BIN
      Improper restriction of excessive authentication attemps/Improper restriction of excessive authentication attempts.docx
  5. +44
    -0
      Improper restriction of excessive authentication attemps/Mitigated/LogIn.java
  6. +41
    -0
      Improper restriction of excessive authentication attemps/Vulnerable/LogIn.java
  7. BIN
      Integer Overflow/Integer Overflow.docx
  8. +26
    -0
      Integer Overflow/code files/mitigated.java
  9. +26
    -0
      Integer Overflow/code files/vulnerable.java
  10. BIN
      Missing Encryption of Sensitive Data/Missing Encryption of Sensitive Data.docx
  11. +29
    -0
      Missing Encryption of Sensitive Data/code files/Mitigated/Password.java
  12. +22
    -0
      Missing Encryption of Sensitive Data/code files/Vulnerable/Password.java
  13. +2
    -0
      README.md
  14. BIN
      SQL Injection/SQL Injection.docx
  15. +71
    -0
      SQL Injection/code files/Mitigated/SQL_Injection.php
  16. +27
    -0
      SQL Injection/code files/Mitigated/index.php
  17. +77
    -0
      SQL Injection/code files/Vulnerable/SQL_Injection.php
  18. +27
    -0
      SQL Injection/code files/Vulnerable/index.php
  19. BIN
      Unrestricted Upload/Unrestriced Upload.docx
  20. +5
    -0
      Unrestricted Upload/code files/example files to be uploaded/malicious_code.php
  21. +1
    -0
      Unrestricted Upload/code files/example files to be uploaded/sdev325notes.txt
  22. +54
    -0
      Unrestricted Upload/code files/mitigated/upload_picture.php
  23. +40
    -0
      Unrestricted Upload/code files/vulnerable/upload_picture.php
  24. BIN
      Use of Hard-Coded Credentials/Use of Hard-Coded Credentials.docx
  25. +63
    -0
      Use of Hard-Coded Credentials/code files/Mitigated/SQL_Injection.php
  26. +6
    -0
      Use of Hard-Coded Credentials/code files/Mitigated/db.php
  27. +27
    -0
      Use of Hard-Coded Credentials/code files/Mitigated/index.php
  28. +66
    -0
      Use of Hard-Coded Credentials/code files/Vulnerable/SQL_Injection.php
  29. +27
    -0
      Use of Hard-Coded Credentials/code files/Vulnerable/index.php
  30. +66
    -0
      Use of a broken or risky Cryptographic algorithm/Mitigated/AES.java
  31. BIN
      Use of a broken or risky Cryptographic algorithm/Use of a broken or risky cryptographic algorithm.docx
  32. +44
    -0
      Use of a broken or risky Cryptographic algorithm/Vulnerable/DES.java

BIN
Buffer Copy Without Checking Size of Input/Buffer Copy Without Checking Size of Input.docx View File


+ 20
- 0
Buffer Copy Without Checking Size of Input/code files/mitigated.cpp View File

@@ -0,0 +1,20 @@
#include <iostream>
using namespace std;
int main() {
char UserType[11]; // need one more than 10 for the end marker
std::cout << "Please enter your name (less than 10 characters): " << '\n';
std::cin.getline(UserType, 11); // limit input to 10
std::cout << UserType << '\n';
}

+ 16
- 0
Buffer Copy Without Checking Size of Input/code files/vulnerable.cpp View File

@@ -0,0 +1,16 @@
#include <iostream>
using namespace std;
int main() {
char name[10];
cout << "Please enter your name: ";
cin >> name;
cout << "Your name is: " << name << endl;
}

BIN
Improper restriction of excessive authentication attemps/Improper restriction of excessive authentication attempts.docx View File


+ 44
- 0
Improper restriction of excessive authentication attemps/Mitigated/LogIn.java View File

@@ -0,0 +1,44 @@
import java.util.Scanner;
public class LogIn {
public static void main(String[] args) {
//declare variables
String username, password;
int n = 0;
Scanner scanner = new Scanner (System.in);
while (n<3) {
//prompt user for their username
System.out.print("Enter your username: ");
username = scanner.nextLine();
//prompt user for their password
System.out.print("Enter your password: ");
password = scanner.nextLine();
if ("Justinfromcharleston@gmail.com".equals(username) && "secret17".equals(password))
{ System.out.println("Welcome " + username + "!!!");
break;
}
else if(!"secret17".equals(password) || !"Justinfromcharleston@gmail.com".equals(username)) {
System.out.println("Incorrect login. Please try again.");
n++;
if (n==3){
System.out.print("Maximum login attemps exceeded.");
break;
}
}
}
}
}

+ 41
- 0
Improper restriction of excessive authentication attemps/Vulnerable/LogIn.java View File

@@ -0,0 +1,41 @@
package homework.pkg5;
import java.util.Scanner;
public class LogIn{
public static void main(String[] args) {
//declare variables
String username, password;
int n = 0;
Scanner scanner = new Scanner (System.in);
while (n<3) {
//prompt user for their username
System.out.print("Enter your username: ");
username = scanner.nextLine();
//prompt user for their password
System.out.print("Enter your password: ");
password = scanner.nextLine();
if ("Justinfromcharleston@gmail.com".equals(username) && "secret17".equals(password))
{ System.out.println("Welcome " + username + "!!!");
break;
}
else if(!"secret17".equals(password) || !"Justinfromcharleston@gmail.com".equals(username)) {
System.out.println("Incorrect login. Please try again.");
}
}
}
}

BIN
Integer Overflow/Integer Overflow.docx View File


+ 26
- 0
Integer Overflow/code files/mitigated.java View File

@@ -0,0 +1,26 @@
package integer.overflow;
/**
*
* @author justi
*/
public class IntegerOverflow_Mitigated {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
//int a is equal to the largest int available
int a = Integer.MAX_VALUE;
int b = 1;
//calculation will result in integer overflow
int c = a + b;
System.out.println("Before: " + a + " + " + b + " = " + c);
System.out.println("After: " + Math.addExact( a, b ));
}
}

+ 26
- 0
Integer Overflow/code files/vulnerable.java View File

@@ -0,0 +1,26 @@
package integer.overflow;
/**
*
* @author justi
*/
public class IntegerOverflow {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
//int a is equal to the largest int available
int a = Integer.MAX_VALUE;
int b = 1;
//calculation will result in integer overflow
int c = a + b;
System.out.println(a + " + " + b + " = " + c);
}
}

BIN
Missing Encryption of Sensitive Data/Missing Encryption of Sensitive Data.docx View File


+ 29
- 0
Missing Encryption of Sensitive Data/code files/Mitigated/Password.java View File

@@ -0,0 +1,29 @@
package homework.pkg4;
import java.security.MessageDigest;
import java.util.Scanner;
import javax.xml.bind.DatatypeConverter;
public class Password {
public static void main( String[] args ) throws Exception {
Scanner keyboard = new Scanner(System.in);
String un, pw, encrypt_psswrd;
MessageDigest digest = MessageDigest.getInstance("SHA-256");
System.out.print("Please create a username: ");
un = keyboard.nextLine();
System.out.print("Please create a password: ");
pw = keyboard.nextLine();
digest.update( pw.getBytes("UTF-8") );
encrypt_psswrd = DatatypeConverter.printHexBinary( digest.digest() );
//overwrites user's original input so it is not visible to hackers.
pw = "empty";
System.out.println( "Your username is: " + un + ". Your password has been encryped for security purposes: " + encrypt_psswrd );
}
}

+ 22
- 0
Missing Encryption of Sensitive Data/code files/Vulnerable/Password.java View File

@@ -0,0 +1,22 @@
package homework.pkg4;
import java.security.MessageDigest;
import java.util.Scanner;
public class Password {
public static void main( String[] args ) throws Exception {
Scanner keyboard = new Scanner(System.in);
String un, pw, encrypt_psswrd;
MessageDigest digest = MessageDigest.getInstance("SHA-256");
System.out.print("Please create a username: ");
un = keyboard.nextLine();
System.out.print("Please create a password: ");
pw = keyboard.nextLine();
System.out.println( "Your username is: " + un + ". Your password is: " + pw);
}
}

+ 2
- 0
README.md View File

@@ -0,0 +1,2 @@
# Software-Vulnerability-Demonstrations
Software Vulnerability Demonstrations Unique and complete demonstrations of software vulnerabilities found in the CWE/SANS Top 25 vulnerabilities list. Each example contains executable code with both a vulnerable version showing the weakness and a mitigated version showing how eliminate it. Each is well-documented and includes screenshots showing the application executing step by step. These are part of what would be a much larger application.

BIN
SQL Injection/SQL Injection.docx View File


+ 71
- 0
SQL Injection/code files/Mitigated/SQL_Injection.php View File

@@ -0,0 +1,71 @@
<?php
// 1. Create a database connection
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "dakota02";
$dbname = "UMUC";
$connection = mysqli_connect($dbhost, $dbuser, $dbpass,
$dbname);
//you could just place the variables directly into the arugments also, but
//it's easier to understand this way.
//Once we call the mysqli_connect function, the value that it returns is what we
//have assigned to the variable $connection. It is what is referred to as a handle for the connection.
//will see if connected, if not will quit and display error messages with error.
//test if connection occured.
if(mysqli_connect_errno()){
die("Database connection failed: " .
mysqli_connect_error() .
"(" . mysqli_connect_errno() . ")"
);
}
?>
<?php
if (isset($_POST['submit'])){
//assign post data to variables
$first_name = $_POST["first_name"];
$last_name = $_POST ["last_name"];
$student_id = $_POST["student_id"];
}
$stmt = $connection->prepare("INSERT INTO students (first_name, last_name, student_id) VALUES (?, ?, ?)");
$stmt->bind_param('sss', $_POST['first_name'], $_POST['last_name'], $_POST['student_id']);
$stmt->execute();
$stmt->close();
//test if there was a query error
if($stmt){
//success
echo "Success! Student added to database!";
}else{
//failure
die("Database query failed. " . mysqli_error($connection));
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<title>SQL Injection</title>
</head>
<body>
</body>
</html>
<?php
//5.close database connection
mysqli_close($connection);
?>

+ 27
- 0
SQL Injection/code files/Mitigated/index.php View File

@@ -0,0 +1,27 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<title>Form</title>
</head>
<br />
<form action="SQL_Injection.php" method="post">
First name: <input type="text" name="first_name" value ="" /> <br />
Last name: <input type="text" name="last_name" value ="" /> <br />
Student ID: <input type="text" name="student_id" value ="" /> <br />
<br />
<input type="submit" name="submit" value ="Submit" /> <br />
</form>
</html>

+ 77
- 0
SQL Injection/code files/Vulnerable/SQL_Injection.php View File

@@ -0,0 +1,77 @@
<?php
// 1. Create a database connection
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "dakota02";
$dbname = "UMUC";
$connection = mysqli_connect($dbhost, $dbuser, $dbpass,
$dbname);
//you could just place the variables directly into the arugments also, but
//it's easier to understand this way.
//Once we call the mysqli_connect function, the value that it returns is what we
//have assigned to the variable $connection. It is what is referred to as a handle for the connection.
//will see if connected, if not will quit and display error messages with error.
//test if connection occured.
if(mysqli_connect_errno()){
die("Database connection failed: " .
mysqli_connect_error() .
"(" . mysqli_connect_errno() . ")"
);
}
?>
<?php
if (isset($_POST['submit'])){
//assign post data to variables
$first_name = $_POST["first_name"];
$last_name = $_POST["last_name"];
$student_id = $_POST["student_id"];
}
//2. perform database query
//This way is called assembling a query. Easier to read and work with.
//could also wrap parts in if statements. ex. if something is true,
//append the WHERE clause.
$query = "INSERT INTO students (";
$query .= " first_name, last_name, student_id";
$query .= ") VALUES (";
$query .= " '{$first_name}', '{$last_name}', '{$student_id}' ";
$query .= ")";
$result = mysqli_query($connection, $query);
//test if there was a query error
if($result){
//success
//could do a redirect. ex redirect to("somepage.php");
echo "Success! Student added to database!";
}else{
//failure
//$message = "Student creation failed";
die("Database query failed. " . mysqli_error($connection));
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<title>SQL Injection</title>
</head>
<body>
</body>
</html>
<?php
//5.close database connection
mysqli_close($connection);
?>

+ 27
- 0
SQL Injection/code files/Vulnerable/index.php View File

@@ -0,0 +1,27 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<title>Form</title>
</head>
<br />
<form action="SQL_Injection.php" method="post">
First name: <input type="text" name="first_name" value ="" /> <br />
Last name: <input type="text" name="last_name" value ="" /> <br />
Student ID: <input type="text" name="student_id" value ="" /> <br />
<br />
<input type="submit" name="submit" value ="Submit" /> <br />
</form>
</html>

BIN
Unrestricted Upload/Unrestriced Upload.docx View File


+ 5
- 0
Unrestricted Upload/code files/example files to be uploaded/malicious_code.php View File

@@ -0,0 +1,5 @@
<?php
//malicious script goes here.
?>

+ 1
- 0
Unrestricted Upload/code files/example files to be uploaded/sdev325notes.txt View File

@@ -0,0 +1 @@
blah blah blah

+ 54
- 0
Unrestricted Upload/code files/mitigated/upload_picture.php View File

@@ -0,0 +1,54 @@
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<meta charset="UTF-8">
<title>Upload</title>
</head>
<body>
<?php
if (isset($_FILES["file"]["name"])) {
$name = $_FILES["file"]["name"];
$temp_file = $_FILES['file']['tmp_name'];
$error = $_FILES['file']['error'];
$imginfo_array = getimagesize($temp_file); // returns a false if not a valid image file
if ($imginfo_array !== false) {
$mime_type = $imginfo_array['mime'];
switch($mime_type) {
case "image/jpeg" ||"image/gif" || "image/png":
$location = 'pictures/';
move_uploaded_file($temp_file, $location.$name);
echo 'Uploaded successfully.';
}
}
else {
echo "This is not a valid image file";
}
}
?>
<form action="upload_picture.php" method="POST" enctype="multipart/form-data">
<input type="file" name="file"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>

+ 40
- 0
Unrestricted Upload/code files/vulnerable/upload_picture.php View File

@@ -0,0 +1,40 @@
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<meta charset="UTF-8">
<title>Upload</title>
</head>
<body>
<?php
if (isset($_FILES["file"]["name"])) {
$name = $_FILES["file"]["name"];
$tmp_name = $_FILES['file']['tmp_name'];
$error = $_FILES['file']['error'];
if (!empty($name)) {
$location = 'pictures/';
if (move_uploaded_file($tmp_name, $location.$name)){
echo 'Uploaded';
}
} else {
echo 'please choose a file';
}
}
?>
<form action="upload_picture.php" method="POST" enctype="multipart/form-data">
<input type="file" name="file"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>

BIN
Use of Hard-Coded Credentials/Use of Hard-Coded Credentials.docx View File


+ 63
- 0
Use of Hard-Coded Credentials/code files/Mitigated/SQL_Injection.php View File

@@ -0,0 +1,63 @@
<?php
require 'db.php';
//will see if connected, if not will quit and display error messages with error.
//test if connection occured.
if(mysqli_connect_errno()){
die("Database connection failed: " .
mysqli_connect_error() .
"(" . mysqli_connect_errno() . ")"
);
}
?>
<?php
if (isset($_POST['submit'])){
//assign post data to variables
$first_name = $_POST["first_name"];
$last_name = $_POST ["last_name"];
$student_id = $_POST["student_id"];
}
$stmt = $connection->prepare("INSERT INTO students (first_name, last_name, student_id) VALUES (?, ?, ?)");
$stmt->bind_param('sss', $_POST['first_name'], $_POST['last_name'], $_POST['student_id']);
$stmt->execute();
$stmt->close();
//test if there was a query error
if($stmt){
//success
echo "Success! Student added to database!";
}else{
//failure
die("Database query failed. " . mysqli_error($connection));
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<title>SQL Injection</title>
</head>
<body>
</body>
</html>
<?php
//5.close database connection
mysqli_close($connection);
?>

+ 6
- 0
Use of Hard-Coded Credentials/code files/Mitigated/db.php View File

@@ -0,0 +1,6 @@
<?php
// 1. Create a database connection
$connection = mysqli_connect('localhost', 'root', 'dakota02', 'UMUC');
?>

+ 27
- 0
Use of Hard-Coded Credentials/code files/Mitigated/index.php View File

@@ -0,0 +1,27 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<title>Form</title>
</head>
<br />
<form action="SQL_Injection.php" method="post">
First name: <input type="text" name="first_name" value ="" /> <br />
Last name: <input type="text" name="last_name" value ="" /> <br />
Student ID: <input type="text" name="student_id" value ="" /> <br />
<br />
<input type="submit" name="submit" value ="Submit" /> <br />
</form>
</html>

+ 66
- 0
Use of Hard-Coded Credentials/code files/Vulnerable/SQL_Injection.php View File

@@ -0,0 +1,66 @@
<?php
// 1. Create a database connection
// 1. Create a database connection
$connection = mysqli_connect('localhost', 'root', 'dakota02', 'UMUC');
//Once we call the mysqli_connect function, the value that it returns is what we
//have assigned to the variable $connection. It is what is referred to as a handle for the connection.
//will see if connected, if not will quit and display error messages with error.
//test if connection occured.
if(mysqli_connect_errno()){
die("Database connection failed: " .
mysqli_connect_error() .
"(" . mysqli_connect_errno() . ")"
);
}
?>
<?php
if (isset($_POST['submit'])){
//assign post data to variables
$first_name = $_POST["first_name"];
$last_name = $_POST ["last_name"];
$student_id = $_POST["student_id"];
}
$stmt = $connection->prepare("INSERT INTO students (first_name, last_name, student_id) VALUES (?, ?, ?)");
$stmt->bind_param('sss', $_POST['first_name'], $_POST['last_name'], $_POST['student_id']);
$stmt->execute();
$stmt->close();
//test if there was a query error
if($stmt){
//success
echo "Success! Student added to database!";
}else{
//failure
die("Database query failed. " . mysqli_error($connection));
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<title>SQL Injection</title>
</head>
<body>
</body>
</html>
<?php
//5.close database connection
mysqli_close($connection);
?>

+ 27
- 0
Use of Hard-Coded Credentials/code files/Vulnerable/index.php View File

@@ -0,0 +1,27 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<title>Form</title>
</head>
<br />
<form action="SQL_Injection.php" method="post">
First name: <input type="text" name="first_name" value ="" /> <br />
Last name: <input type="text" name="last_name" value ="" /> <br />
Student ID: <input type="text" name="student_id" value ="" /> <br />
<br />
<input type="submit" name="submit" value ="Submit" /> <br />
</form>
</html>

+ 66
- 0
Use of a broken or risky Cryptographic algorithm/Mitigated/AES.java View File

@@ -0,0 +1,66 @@
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.xml.bind.DatatypeConverter;
public class AES {
public static void main(String[] args) throws Exception {
String plainText = "Secret Message";
SecretKey secKey = getSecretEncryptionKey();
byte[] cipherText = encryptText(plainText, secKey);
String decryptedText = decryptText(cipherText, secKey);
System.out.println("Original Text:" + plainText);
System.out.println("AES Key (Hex Form):"+bytesToHex(secKey.getEncoded()));
System.out.println("Encrypted Text (Hex Form):"+bytesToHex(cipherText));
System.out.println("Descrypted Text:"+decryptedText);
}
//End of main class
//Gets encryption key. Would normally be stored differently in a real world situation.
public static SecretKey getSecretEncryptionKey() throws Exception{
KeyGenerator generator = KeyGenerator.getInstance("AES");
generator.init(128); // AES key size. More secure than the 56 bit DES
SecretKey secKey = generator.generateKey();
return secKey;
}
//ENCRYPT our text using the secret key to byte array
public static byte[] encryptText(String plainText,SecretKey secKey) throws Exception{
Cipher aesCipher = Cipher.getInstance("AES");
aesCipher.init(Cipher.ENCRYPT_MODE, secKey);
byte[] byteCipherText = aesCipher.doFinal(plainText.getBytes());
return byteCipherText;
}
//DECRYPTS the byte array using the key
public static String decryptText(byte[] byteCipherText, SecretKey secKey) throws Exception {
Cipher aesCipher = Cipher.getInstance("AES");
aesCipher.init(Cipher.DECRYPT_MODE, secKey);
byte[] bytePlainText = aesCipher.doFinal(byteCipherText);
return new String(bytePlainText);
}
//Converts binary byte array into readable hex
private static String bytesToHex(byte[] hash) {
return DatatypeConverter.printHexBinary(hash);
}
}

BIN
Use of a broken or risky Cryptographic algorithm/Use of a broken or risky cryptographic algorithm.docx View File


+ 44
- 0
Use of a broken or risky Cryptographic algorithm/Vulnerable/DES.java View File

@@ -0,0 +1,44 @@
import java.io.*;
import javax.crypto.*;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
public class DES {
public static void main(String[] args) {
try{
String st = "Hello";
System.out.println("Real String: " + st);
byte str[]= st.getBytes();
Cipher c= Cipher.getInstance("DES");
KeyGenerator kg =KeyGenerator.getInstance("DES");
SecretKey sk= kg.generateKey();
//encrypt mode
c.init(Cipher.ENCRYPT_MODE, sk);
byte ct[]= c.doFinal(str);
System.out.println("ENCRYPT_MODE DATA : " + new String(ct));
//decrypt mode
c.init(Cipher.DECRYPT_MODE, sk);
byte ct1[]= c.doFinal(ct);
System.out.println("DECRYPT_MODE DATA : " + new String(ct1));
}
catch(Exception e)
{
System.out.println(e);
}
}
}

Loading…
Cancel
Save